Commit 5ec66b2883bdd52f5e692df480027ca13144f324

Authored by Michael Joseph
1 parent 45852dba

added archiving options to getPage

refactored metadata tag routines to advancedSearchUtil.inc


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2042 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php
... ... @@ -21,6 +21,7 @@ if (checkSession()) {
21 21 require_once("$default->fileSystemRoot/lib/security/permission.inc");
22 22 require_once("$default->fileSystemRoot/presentation/Html.inc");
23 23 require_once("advancedSearchUI.inc");
  24 + require_once("advancedSearchUtil.inc");
24 25  
25 26 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
26 27  
... ... @@ -31,18 +32,18 @@ if (checkSession()) {
31 32  
32 33 if (strlen($sMetaTagIDs) > 0) {
33 34 $sSQLSearchString = getSQLSearchString($fSearchString);
34   - $sDocument = getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString);
  35 + $sDocument = getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString, (isset($fSearchArchive) ? "Archived" : "Live"));
35 36 if (strlen($sDocument) > 0) {
36 37 //if there are documents to view
37 38 $oPatternCustom = & new PatternCustom();
38 39 if (!isset($fStartIndex)) {
39 40 $fStartIndex = 0;
40   - }
  41 + }
41 42 $oPatternCustom->setHtml(getSearchResults($sMetaTagIDs,$sSQLSearchString, $fStartIndex));
42 43 $main->setCentralPayload($oPatternCustom);
43 44 $main->render();
44 45 } else {
45   - $oPatternCustom = & new PatternCustom();
  46 + $oPatternCustom = & new PatternCustom();
46 47 $oPatternCustom->setHtml(getSearchPage($fSearchString, explode(",",$sMetaTagIDs)));
47 48 $main->setCentralPayload($oPatternCustom);
48 49 $main->setErrorMessage("No documents matched your search criteria");
... ... @@ -76,73 +77,6 @@ if (checkSession()) {
76 77 $main->setCentralPayload($oPatternCustom);
77 78 $main->setFormAction("advancedSearchBL.php?fForSearch=1");
78 79 $main->render();
79   - }
80   -
81   -
82   -}
83   -
84   -function getChosenMetaDataTags() {
85   - $aKeys = array_keys($_POST);
86   - $aTagIDs = array();
87   - for ($i = 0; $i < count($aKeys); $i++) {
88   - $sRowStart = $aKeys[$i];
89   - $pos = strcmp("adv_search_start", $sRowStart);
90   - if ($pos == 0) {
91   - $i++;
92   - $sRowStart = $aKeys[$i];
93   - while ((strcmp("adv_search_end", $sRowStart) != 0) && ($i < count($aKeys))) {
94   - $aTagIDs[count($aTagIDs)] = $_POST[$aKeys[$i]];
95   - $i++;
96   - $sRowStart = $aKeys[$i];
97   - }
98   -
99   - }
100   - }
101   - if (count($aTagIDs) > 1) {
102   - return implode(",",$aTagIDs);
103   - }
104   - return $aTagIDs[0];
105   -}
106   -
107   -/**
108   -* Generate a string onsisting of all documents that match the search criteria
109   -* and that the user is allowed to see
110   -*/
111   -function getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString) {
112   - global $default;
113   - $aApprovedDocumentIDs = array();
114   - $sQuery = "SELECT DISTINCT D.id " .
115   - "FROM documents AS D INNER JOIN document_fields_link AS DFL ON DFL.document_id = D.id " .
116   - "INNER JOIN document_fields AS DF ON DF.id = DFL.document_field_id " .
117   - "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.ID " .
118   - "INNER JOIN status_lookup AS SL on D.status_id=SL.id " .
119   - "WHERE DF.ID IN ($sMetaTagIDs) " .
120   - "AND " . $sSQLSearchString . " " .
121   - "AND SL.name='Live' " .
122   - "AND SDUL.user_id = " . $_SESSION["userID"];
123   - $sql = $default->db;
124   - $sql->query($sQuery);
125   - while ($sql->next_record()) {
126   - $aApprovedDocuments[count($aApprovedDocuments)] = $sql->f("id");
127   - }
128   - if (count($aApprovedDocuments) > 1) {
129   - return implode(",",$aApprovedDocuments);
130   - }
131   - return $aApprovedDocuments[0];
132   -
133   -}
134   -
135   -/*
136   -* Generate a string that can be used in a SQL query
137   -* from the list of documents the user is allowed to see
138   -*/
139   -function getSQLSearchString($sSearchString) {
140   - $aWords = explode(" ", $sSearchString);
141   - $sSQLSearchString;
142   - for ($i = 0; $i < count($aWords) - 1; $i++) {
143   - $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[$i] . "%') OR ";
144   - }
145   - $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[count($aWords) -1] . "%')";
146   - return $sSQLSearchString;
  80 + }
147 81 }
148 82 ?>
149 83 \ No newline at end of file
... ...
presentation/lookAndFeel/knowledgeTree/search/advancedSearchUI.inc
... ... @@ -37,14 +37,14 @@ function getMetaData($aMetaTagIDs) {
37 37  
38 38 return $sToRender;
39 39 }
40   -
41   -function getSearchPage($sSearchString = "", $aMetaTagIDs = array()) {
  40 +function getSearchPage($sSearchString = "", $aMetaTagIDs = array(), $sHeading = "Advanced Search", $bSearchArchive = false) {
42 41 global $default;
43   - $sToRender = renderHeading("Advanced Search");
  42 + $sToRender = renderHeading($sHeading);
44 43 $sToRender .= "<table width=\"600\">\n";
45 44 $sToRender .= "<tr>\n";
46 45 $sToRender .= "<td>Search text: <input type=\"text\" size=\"60\" name=\"fSearchString\" value=\"$sSearchString\" />\n";
47 46 $sToRender .= "<input type=\"button\" value=\"search\" onClick=\"validateAdvancedSearch()\"/></td>\n";
  47 + $sToRender .= ($bSearchArchive ? "<input type=\"hidden\" name=\"fSearchArchive\" value=\"1\"" : "");
48 48 $sToRender .= "</tr>\n";
49 49 $sToRender .= "<tr>\n";
50 50 $sToRender .= "<td>&nbsp</td>\n";
... ...
presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc 0 → 100644
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * Business logic used to perform advanced search. Advanced search allows
  6 + * users to search by meta data types
  7 + *
  8 + * @author Rob Cherry, Jam Warehouse South Africa (Pty) Ltd
  9 + * @date 26 February 2003
  10 + * @package presentation.knowledgeTree.search
  11 + */
  12 +
  13 +/**
  14 + * Interrogates the posted variables for the chosen metadata tags
  15 + */
  16 +function getChosenMetaDataTags() {
  17 + $aKeys = array_keys($_POST);
  18 + $aTagIDs = array();
  19 + for ($i = 0; $i < count($aKeys); $i++) {
  20 + $sRowStart = $aKeys[$i];
  21 + $pos = strcmp("adv_search_start", $sRowStart);
  22 + if ($pos == 0) {
  23 + $i++;
  24 + $sRowStart = $aKeys[$i];
  25 + while ((strcmp("adv_search_end", $sRowStart) != 0) && ($i < count($aKeys))) {
  26 + $aTagIDs[count($aTagIDs)] = $_POST[$aKeys[$i]];
  27 + $i++;
  28 + $sRowStart = $aKeys[$i];
  29 + }
  30 +
  31 + }
  32 + }
  33 + if (count($aTagIDs) > 1) {
  34 + return implode(",",$aTagIDs);
  35 + }
  36 + return $aTagIDs[0];
  37 +}
  38 +
  39 +/**
  40 +* Generate a string consisting of all documents that match the search criteria
  41 +* and that the user is allowed to see
  42 +*/
  43 +function getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString, $sStatus = "Live") {
  44 + global $default;
  45 + $aApprovedDocumentIDs = array();
  46 + $sQuery = "SELECT DISTINCT D.id " .
  47 + "FROM documents AS D INNER JOIN document_fields_link AS DFL ON DFL.document_id = D.id " .
  48 + "INNER JOIN document_fields AS DF ON DF.id = DFL.document_field_id " .
  49 + "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.ID " .
  50 + "INNER JOIN status_lookup AS SL on D.status_id=SL.id " .
  51 + "WHERE DF.ID IN ($sMetaTagIDs) " .
  52 + "AND " . $sSQLSearchString . " " .
  53 + "AND SL.name='$sStatus' " .
  54 + "AND SDUL.user_id = " . $_SESSION["userID"];
  55 + $sql = $default->db;
  56 + $sql->query($sQuery);
  57 + while ($sql->next_record()) {
  58 + $aApprovedDocuments[count($aApprovedDocuments)] = $sql->f("id");
  59 + }
  60 + if (count($aApprovedDocuments) > 1) {
  61 + return implode(",",$aApprovedDocuments);
  62 + }
  63 + return $aApprovedDocuments[0];
  64 +
  65 +}
  66 +
  67 +/*
  68 +* Generate a string that can be used in a SQL query
  69 +* from the list of documents the user is allowed to see
  70 +*/
  71 +function getSQLSearchString($sSearchString) {
  72 + $aWords = explode(" ", $sSearchString);
  73 + $sSQLSearchString;
  74 + for ($i = 0; $i < count($aWords) - 1; $i++) {
  75 + $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[$i] . "%') OR ";
  76 + }
  77 + $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[count($aWords) -1] . "%')";
  78 + return $sSQLSearchString;
  79 +}
  80 +?>
0 81 \ No newline at end of file
... ...