Commit a07f052ea305d9058a2ae890f6e6ea51b7505ae5

Authored by Neil Blakey-Milner
1 parent ac96c540

Share search code with archive search via advancedSearchUtil, and update

and simplify the restoration code.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3348 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageArchivedDocumentsBL.php
1 1 <?php
2   -
3   -require_once("../../../../../config/dmsDefaults.php");
4   -
5   -KTUtil::extractGPC('fConfirm', 'fDocumentIDs', 'fSearchString');
6   -
7   -require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
8   -require_once("$default->fileSystemRoot/lib/archiving/ArchiveRestorationRequest.inc");
9   -require_once("$default->fileSystemRoot/lib/email/Email.inc");
10   -require_once("$default->fileSystemRoot/lib/users/User.inc");
11   -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc");
12   -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
13   -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc");
14   -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc");
15   -require_once("$default->uiDirectory/documentmanagement/documentUI.inc");
16   -require_once("$default->uiDirectory/search/advancedSearchUI.inc");
17   -require_once("$default->uiDirectory/search/advancedSearchUtil.inc");
18   -require_once("archivedDocumentsUI.inc");
19   -require_once("$default->fileSystemRoot/presentation/Html.inc");
20 2 /**
21 3 * $Id$
22 4 *
... ... @@ -43,139 +25,108 @@ require_once(&quot;$default-&gt;fileSystemRoot/presentation/Html.inc&quot;);
43 25 * @package administration.documentmanagement
44 26 */
45 27  
46   -if (checkSession()) {
47   - global $default;
48   -
49   - // instantiate my content pattern
50   - $oContent = new PatternCustom();
  28 +require_once("../../../../../config/dmsDefaults.php");
  29 +
  30 +require_once("$default->fileSystemRoot/presentation/Html.inc");
  31 +
  32 +KTUtil::extractGPC('fConfirm', 'fDocumentIDs', 'fForSearch', 'fSearchString', 'fShowSection', 'fStartIndex', 'fToSearch');
  33 +
  34 +if (checkSession()) {
  35 + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc");
  36 + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc");
  37 + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
  38 + require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
  39 + require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
  40 + require_once("$default->fileSystemRoot/lib/security/Permission.inc");
  41 + require_once("$default->fileSystemRoot/lib/archiving/ArchiveRestorationRequest.inc");
  42 + require_once("$default->fileSystemRoot/presentation/Html.inc");
  43 + require_once(KT_DIR . "/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc");
  44 + require_once(KT_DIR . "/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUI.inc");
  45 + require_once("archivedDocumentsUI.inc");
  46 +
  47 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
51 48  
52   - if (strlen($fSearchString) > 0) {
53   - // perform the search and display the results
54   - $sMetaTagIDs = getChosenMetaDataTags($_GET);
55   - if (strlen($sMetaTagIDs) > 0) {
56   - $sSQLSearchString = getSQLSearchString($fSearchString);
57   - $aDocuments = searchForDocuments($sMetaTagIDs, $sSQLSearchString, "Archived");
58   - if (count($aDocuments) > 0) {
59   - // display the documents
60   - $oContent->setHtml(renderArchivedDocumentsResultsPage($aDocuments));
61   - } else {
62   - $oContent->setHtml(getSearchPage($fSearchString, explode(",",$sMetaTagIDs), _("Archived Documents Search"), true));
63   - $sErrorMessage = _("No documents matched your search criteria");
64   - }
65   - } else {
66   - $oContent->setHtml(getSearchPage($fSearchString, array(), _("Archived Documents Search"), true));
67   - $sErrorMessage = _("Please select at least one criteria to search by");
68   - }
69   - } else if ($fDocumentIDs) {
70   - // got some documents to restore
  49 + $main->setFormAction($_SERVER["PHP_SELF"]);
71 50  
72   - // instantiate document objects
73   - $aDocuments = array();
  51 + if (!isset($fStartIndex)) {
  52 + $fStartIndex = 1;
  53 + }
  54 +
  55 + $oContent = new PatternCustom;
  56 +
  57 + if (strlen($fForSearch)) {
  58 + dealWithAdvancedSearch($_REQUEST, $fStartIndex);
  59 + } else if ($fDocumentIDs) {
  60 + // got some documents to restore
  61 +
  62 + // instantiate document objects
  63 + $aDocuments = array();
74 64 for ($i = 0; $i < count($fDocumentIDs); $i++) {
75   - $aDocuments[] = & Document::get($fDocumentIDs[$i]);
  65 + $aDocuments[] = & Document::get($fDocumentIDs[$i]);
76 66 }
77   -
78   - if ($fConfirm) {
79   - // restore the specified documents
80   -
81   - $aErrorDocuments = array();
82   - $aSuccessDocuments = array();
83   - for ($i = 0; $i < count($aDocuments); $i++) {
84   - if ($aDocuments[$i]) {
85   -
86   - // set the status to live
87   - $aDocuments[$i]->setStatusID(LIVE);
88   - if ($aDocuments[$i]->update()) {
89   - // success
90   - $default->log->info("manageArchivedDocumentsBL.php set status for document id=" . $fDocumentIDs[$i]);
91   - $aSuccessDocuments[] = $aDocuments[$i];
92   -
93   - // check if there are requests for this document to be archived
94   - $aRequests = ArchiveRestorationRequest::getList(array("document_id = ?", $aDocuments[$i]->getID()));/*ok*/
95   - $default->log->info("manageArchivedDocumentsBL.php about to send notification for " . count($aRequests) . " restoration requests for document id " . $aDocuments[$i]->getID());
96   - for ($j=0; $j<count($aRequests); $j++) {
97   - // email the users
98   - // FIXME: refactor notification
99   - // TODO: check email notification and valid email address
100   - $oRequestUser = User::get($aRequests[$j]->getRequestUserID());
101   - $sBody = "The document '" . generateControllerLink("viewDocument", "fDocumentID=" . $aDocuments[$i]->getID(), $aDocuments[$i]->getName()) . "'";
102   - $sBody .= " has been restored from the archive.";
103   - $oEmail = & new Email();
104   - if ($oEmail->send($oRequestUser->getEmail(), _("Archived Document Restored"), $sBody)) {
105   - $default->log->info("manageArchivedDocumentsBL.php sent email to " . $oRequestUser->getEmail());
106   - // now delete the request
107   - $iRequestID = $aRequests[$j]->getID();
108   - if ($aRequests[$j]->delete()) {
109   - $default->log->info("manageArchivedDocumentsBL.php removing restoration request $iRequestID");
110   - } else {
111   - $default->log->error("manageArchivedDocumentsBL.php error removing request $iRequestID");
112   - }
113   - } else {
114   - $default->log->error("manageArchivedDocumentsBL.php error notifying " . arrayToString($oEmail) . " for document id " . $aDocuments[$i]->getID() . " restoration");
115   - }
116   - }
117   - } else{
118   - // error updating status change
119   - $default->log->error("manageArchivedDocumentsBL.php couldn't retrieve document id=" . $fDocumentIDs[$i]);
120   - $aErrorDocuments[] = $aDocuments[$i];
121   - }
  67 +
  68 + if ($fConfirm) {
  69 + // restore the specified documents
  70 +
  71 + $aErrorDocuments = array();
  72 + $aSuccessDocuments = array();
  73 + for ($i = 0; $i < count($aDocuments); $i++) {
  74 + if ($aDocuments[$i]) {
  75 + // set the status to live
  76 + $aDocuments[$i]->setStatusID(LIVE);
  77 + if ($aDocuments[$i]->update()) {
  78 + // success
  79 + $default->log->info("manageArchivedDocumentsBL.php set status for document id=" . $fDocumentIDs[$i]);
  80 + $aSuccessDocuments[] = $aDocuments[$i];
  81 +
  82 + // check if there are requests for this document to be archived
  83 + $aRequests = ArchiveRestorationRequest::getList(array("document_id = ?", $aDocuments[$i]->getID()));/*ok*/
  84 + $default->log->info("manageArchivedDocumentsBL.php about to send notification for " . count($aRequests) . " restoration requests for document id " . $aDocuments[$i]->getID());
  85 + for ($j=0; $j<count($aRequests); $j++) {
  86 + // email the users
  87 + // FIXME: refactor notification
  88 + // TODO: check email notification and valid email address
  89 + $oRequestUser = User::get($aRequests[$j]->getRequestUserID());
  90 + $sBody = "The document '" . generateControllerLink("viewDocument", "fDocumentID=" . $aDocuments[$i]->getID(), $aDocuments[$i]->getName()) . "'";
  91 + $sBody .= " has been restored from the archive.";
  92 + $oEmail = & new Email();
  93 + if ($oEmail->send($oRequestUser->getEmail(), _("Archived Document Restored"), $sBody)) {
  94 + $default->log->info("manageArchivedDocumentsBL.php sent email to " . $oRequestUser->getEmail());
  95 + // now delete the request
  96 + $iRequestID = $aRequests[$j]->getID();
  97 + if ($aRequests[$j]->delete()) {
  98 + $default->log->info("manageArchivedDocumentsBL.php removing restoration request $iRequestID");
  99 + } else {
  100 + $default->log->error("manageArchivedDocumentsBL.php error removing request $iRequestID");
  101 + }
  102 + } else {
  103 + $default->log->error("manageArchivedDocumentsBL.php error notifying " . arrayToString($oEmail) . " for document id " . $aDocuments[$i]->getID() . " restoration");
  104 + }
  105 + }
  106 + } else {
  107 + // error updating status change
  108 + $default->log->error("manageArchivedDocumentsBL.php couldn't retrieve document id=" . $fDocumentIDs[$i]);
  109 + $aErrorDocuments[] = $aDocuments[$i];
  110 + }
122 111 } else {
123 112 // error retrieving document object
124 113 $default->log->error("manageArchivedDocumentsBL.php couldn't retrieve document id=" . $fDocumentIDs[$i]);
125   - }
126   - }
  114 + }
  115 + }
127 116 // display status page.
128   - $oContent->setHtml(renderStatusPage($aSuccessDocuments, $aErrorDocuments));
129   - } else {
130   - // ask for confirmation before restoring the documents
131   - $oContent->setHtml(renderRestoreConfirmationPage($aDocuments));
132   - }
133   - } else {
134   - // display the advanced search form, but specify that only archived documents must be returned
  117 + $oContent->setHtml(renderStatusPage($aSuccessDocuments, $aErrorDocuments));
  118 + } else {
  119 + // ask for confirmation before restoring the documents
  120 + $oContent->setHtml(renderRestoreConfirmationPage($aDocuments));
  121 + }
  122 + } else {
  123 + //display search criteria
135 124 $oContent->setHtml(getSearchPage("", array(), _("Archived Documents Search"), true));
136   - }
137   -
138   - // build the page
139   - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
140   - if (isset($sErrorMessage)) {
141   - $main->setErrorMessage($sErrorMessage);
142   - }
143   - $main->setCentralPayload($oContent);
144   - $main->setFormAction($_SERVER['PHP_SELF']);
145   - $main->setHasRequiredFields(true);
146   - $main->setSubmitMethod("GET");
147   - $main->render();
  125 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForSearch=1");
  126 + }
  127 + $main->setHasRequiredFields(true);
  128 + $main->setCentralPayload($oContent);
  129 + $main->render();
148 130 }
149 131  
150   -
151   -/**
152   -* Generate a string consisting of all documents that match the search criteria
153   -* and that the user is allowed to see
154   -*/
155   -function searchForDocuments($sMetaTagIDs, $sSQLSearchString, $sStatus = "Live") {
156   - global $default;
157   - $aDocuments = array();
158   - $aMetaTagIDs = split(',', $sMetaTagIDs);
159   - $sQms = DBUtil::paramArray($aMetaTagIDs);
160   - /*ok*/ $sQuery = "SELECT DISTINCT D.id " .
161   - "FROM $default->documents_table AS D INNER JOIN document_fields_link AS DFL ON DFL.document_id = D.id " .
162   - "INNER JOIN $default->document_fields_table AS DF ON DF.id = DFL.document_field_id " .
163   - "INNER JOIN $default->search_permissions_table AS SDUL ON SDUL.document_id = D.ID " .
164   - "INNER JOIN $default->status_table AS SL on D.status_id=SL.id " .
165   - "WHERE DF.ID IN ($sQms) " .
166   - "AND (" . $sSQLSearchString . ") " .
167   - "AND SL.name = ? " .
168   - "AND SDUL.user_id = ?";
169   - $default->log->info("searchForDocuments $sQuery");
170   - $aParams = $aMetaTagIDs;
171   - $aParams[] = $sStatus;
172   - $aParams[] = $_SESSION["userID"];
173   - $sql = $default->db;
174   - $sql->query($sQuery);
175   - while ($sql->next_record()) {
176   - $aDocuments[] = & Document::get($sql->f("id"));
177   - }
178   -
179   - return $aDocuments;
180   -}
181 132 ?>
... ...
presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php
... ... @@ -27,124 +27,10 @@
27 27 */
28 28  
29 29 require_once("../../../../config/dmsDefaults.php");
  30 +require_once(KT_DIR . '/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc');
30 31  
31 32 KTUtil::extractGPC('fForSearch', 'fSearchString', 'fShowSection', 'fStartIndex', 'fToSearch');
32 33  
33   -function searchCriteria ($var) {
34   - return preg_match('/^bmd(_?\d+)/', $var);
35   -}
36   -
37   -function criteriaNumber ($var) {
38   - $res = preg_replace('/^bmd(_?\d+)(\D.*)?/', '\\1', $var);
39   - if ($res !== false) {
40   - $res = strtr($res, '_', '-');
41   - }
42   - return $res;
43   -}
44   -
45   -function getAdvancedSearchResults($aOrigReq, $iStartIndex) {
46   - global $default;
47   -
48   - $sRefreshMessage = "<table><tr><td align=\"center\">" . _("If your browser displays a 'Warning: Page has Expired' message when you attempt to return to these search results, please click your browser's 'Refresh' button") . "</td></tr></table>";
49   -
50   - $aReq = array();
51   - foreach ($aOrigReq as $k => $v) {
52   - if (searchCriteria($k) === 1) {
53   - $v = trim($v);
54   - if ($v === "") {
55   - continue;
56   - }
57   - if ($v === "-1") {
58   - continue;
59   - }
60   - $aReq[$k] = $v;
61   - }
62   - }
63   -
64   - $aIDs = array_unique(array_map("criteriaNumber", array_keys($aReq)));
65   - $aSQL = array();
66   - $aJoinSQL = array();
67   - foreach ($aIDs as $iID) {
68   - $oCriterion =& Criteria::getCriterionByNumber($iID);
69   - $res = $oCriterion->searchSQL($aReq);
70   - if (!is_null($res)) {
71   - $aSQL[] = $res;
72   - }
73   - $res = $oCriterion->searchJoinSQL();
74   - if (!is_null($res)) {
75   - $aJoinSQL[] = $res;
76   - }
77   - }
78   - $aCritParams = array();
79   - $aCritQueries = array();
80   - foreach ($aSQL as $sSQL) {
81   - if (is_array($sSQL)) {
82   - $aCritQueries[] = $sSQL[0];
83   - $aCritParams = array_merge($aCritParams , $sSQL[1]);
84   - } else {
85   - $aCritQueries[] = $sSQL;
86   - }
87   - }
88   -
89   - if (count($aCritQueries) == 0) {
90   - return "No search criteria were specified";
91   - }
92   -
93   - $sSQLSearchString = join(" AND ", $aCritQueries);
94   - $sJoinSQL = join(" ", $aJoinSQL);
95   -
96   - $sToSearch = KTUtil::arrayGet($aOrigReq, 'fToSearch', 'Live');
97   -
98   - $sQuery = DBUtil::compactQuery("
99   -SELECT
100   - F.name AS folder_name, F.id AS folder_id, D.id AS document_id,
101   - D.name AS document_name, D.filename AS file_name, COUNT(D.id) AS doc_count, 'View' AS view
102   -FROM
103   - $default->documents_table AS D
104   - INNER JOIN $default->folders_table AS F ON D.folder_id = F.id
105   - $sJoinSQL
106   - INNER JOIN $default->search_permissions_table AS SDUL ON SDUL.document_id = D.id
107   - INNER JOIN $default->status_table AS SL on D.status_id=SL.id
108   -WHERE
109   - (F.is_public OR
110   - SDUL.user_id = ?)
111   - AND SL.name = ?
112   - AND ($sSQLSearchString)
113   -GROUP BY D.id
114   -ORDER BY doc_count DESC");
115   -
116   - $aParams = array();
117   - $aParams[] = $_SESSION["userID"];
118   - $aParams[] = $sToSearch;
119   - $aParams = array_merge($aParams, $aCritParams);
120   -
121   - //var_dump(DBUtil::getResultArray(array($sQuery, $aParams)));
122   - //exit(0);
123   -
124   - $aColumns = array("folder_name", "file_name", "document_name", "doc_count", "view");
125   - $aColumnTypes = array(3,3,3,1,3);
126   - $aColumnHeaders = array("<font color=\"ffffff\"><img src=$default->graphicsUrl/widgets/dfolder.gif>" . _("Folder") . "</font>", "<font color=\"ffffff\">" . _("Name") . "</font>", "<font color=\"ffffff\">" . _("Title") . "</font>", "<font color=\"ffffff\">" . _("Matches") . "</font>", "<font color=\"ffffff\">" . _("View") . "</font>");
127   - $aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument", "$default->rootUrl/control.php?action=viewDocument", null, "$default->rootUrl/control.php?action=downloadDocument");
128   - $aDBQueryStringColumns = array("document_id","folder_id");
129   - $aQueryStringVariableNames = array("fDocumentID", "fFolderID");
130   -
131   - $oPatternBrowse = & new PatternBrowseableSearchResults(array($sQuery, $aParams), 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames);
132   - $oPatternBrowse->setStartIndex($iStartIndex);
133   - $oPatternBrowse->setSearchText("");
134   - $oPatternBrowse->setRememberValues($aReq);
135   - $sForSearch = "<input type=\"hidden\" name=\"fForSearch\" value=\"1\" />";
136   -
137   - return renderHeading(_("Advanced Search")) . $oPatternBrowse->render() . $sForSearch . $sRefreshMessage;
138   -}
139   -
140   -function dealWithAdvancedSearch($aReq, $iStartIndex) {
141   - global $main;
142   - $oPatternCustom = & new PatternCustom();
143   - $oPatternCustom->setHtml(getAdvancedSearchResults($aReq, $iStartIndex));
144   - $main->setCentralPayload($oPatternCustom);
145   - $main->render();
146   -}
147   -
148 34 if (checkSession()) {
149 35 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc");
150 36 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc");
... ...
presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc
... ... @@ -5,7 +5,7 @@
5 5 * Business logic used to perform advanced search. Advanced search allows
6 6 * users to search by meta data types.
7 7 *
8   - * Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com
  8 + * Copyright (c) 2005 Jam Warehouse http://www.jamwarehouse.com
9 9 *
10 10 * This program is free software; you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ... @@ -22,47 +22,123 @@
22 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 23 *
24 24 * @version $Revision$
25   - * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
  25 + * @author Neil Blakey-Milner, Jam Warehouse (Pty) Ltd, South Africa
26 26 * @package search
27 27 */
28 28  
29   -/**
30   - * Interrogates the posted variables for the chosen metadata tags
31   - */
32   -function getChosenMetaDataTags($aVariables) {
33   - $aKeys = array_keys($aVariables);
34   - $aTagIDs = array();
35   - for ($i = 0; $i < count($aKeys); $i++) {
36   - $sRowStart = $aKeys[$i];
37   - $pos = strcmp("adv_search_start", $sRowStart);
38   - if ($pos == 0) {
39   - $i++;
40   - $sRowStart = $aKeys[$i];
41   - while ((strcmp("adv_search_end", $sRowStart) != 0) && ($i < count($aKeys))) {
42   - $aTagIDs[count($aTagIDs)] = $aVariables[$aKeys[$i]];
43   - $i++;
44   - $sRowStart = $aKeys[$i];
45   - }
46   -
47   - }
48   - }
49   - if (count($aTagIDs) > 1) {
50   - return implode(",",$aTagIDs);
51   - }
52   - return $aTagIDs[0];
  29 +function searchCriteria ($var) {
  30 + return preg_match('/^bmd(_?\d+)/', $var);
53 31 }
54 32  
55   -/*
56   -* Generate a string that can be used in a SQL query
57   -* from the list of documents the user is allowed to see
58   -*/
59   -function getSQLSearchString($sSearchString) {
60   - $aWords = explode(" ", $sSearchString);
61   - $sSQLSearchString;
62   - for ($i = 0; $i < count($aWords) - 1; $i++) {
63   - $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[$i] . "%') OR ";
64   - }
65   - $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[count($aWords) -1] . "%')";
66   - return $sSQLSearchString;
  33 +function criteriaNumber ($var) {
  34 + $res = preg_replace('/^bmd(_?\d+)(\D.*)?/', '\\1', $var);
  35 + if ($res !== false) {
  36 + $res = strtr($res, '_', '-');
  37 + }
  38 + return $res;
67 39 }
68   -?>
69 40 \ No newline at end of file
  41 +
  42 +function getAdvancedSearchResults($aOrigReq, $iStartIndex) {
  43 + global $default;
  44 +
  45 + $sRefreshMessage = "<table><tr><td align=\"center\">" . _("If your browser displays a 'Warning: Page has Expired' message when you attempt to return to these search results, please click your browser's 'Refresh' button") . "</td></tr></table>";
  46 +
  47 + $aReq = array();
  48 + foreach ($aOrigReq as $k => $v) {
  49 + if (searchCriteria($k) === 1) {
  50 + $v = trim($v);
  51 + if ($v === "") {
  52 + continue;
  53 + }
  54 + if ($v === "-1") {
  55 + continue;
  56 + }
  57 + $aReq[$k] = $v;
  58 + }
  59 + }
  60 +
  61 + $aIDs = array_unique(array_map("criteriaNumber", array_keys($aReq)));
  62 + $aSQL = array();
  63 + $aJoinSQL = array();
  64 + foreach ($aIDs as $iID) {
  65 + $oCriterion =& Criteria::getCriterionByNumber($iID);
  66 + $res = $oCriterion->searchSQL($aReq);
  67 + if (!is_null($res)) {
  68 + $aSQL[] = $res;
  69 + }
  70 + $res = $oCriterion->searchJoinSQL();
  71 + if (!is_null($res)) {
  72 + $aJoinSQL[] = $res;
  73 + }
  74 + }
  75 + $aCritParams = array();
  76 + $aCritQueries = array();
  77 + foreach ($aSQL as $sSQL) {
  78 + if (is_array($sSQL)) {
  79 + $aCritQueries[] = $sSQL[0];
  80 + $aCritParams = array_merge($aCritParams , $sSQL[1]);
  81 + } else {
  82 + $aCritQueries[] = $sSQL;
  83 + }
  84 + }
  85 +
  86 + if (count($aCritQueries) == 0) {
  87 + return "No search criteria were specified";
  88 + }
  89 +
  90 + $sSQLSearchString = join(" AND ", $aCritQueries);
  91 + $sJoinSQL = join(" ", $aJoinSQL);
  92 +
  93 + $sToSearch = KTUtil::arrayGet($aOrigReq, 'fToSearch', 'Live');
  94 +
  95 + $sQuery = DBUtil::compactQuery("
  96 +SELECT
  97 + F.name AS folder_name, F.id AS folder_id, D.id AS document_id,
  98 + D.name AS document_name, D.filename AS file_name, COUNT(D.id) AS doc_count, 'View' AS view
  99 +FROM
  100 + $default->documents_table AS D
  101 + INNER JOIN $default->folders_table AS F ON D.folder_id = F.id
  102 + $sJoinSQL
  103 + INNER JOIN $default->search_permissions_table AS SDUL ON SDUL.document_id = D.id
  104 + INNER JOIN $default->status_table AS SL on D.status_id=SL.id
  105 +WHERE
  106 + (F.is_public OR
  107 + SDUL.user_id = ?)
  108 + AND SL.name = ?
  109 + AND ($sSQLSearchString)
  110 +GROUP BY D.id
  111 +ORDER BY doc_count DESC");
  112 +
  113 + $aParams = array();
  114 + $aParams[] = $_SESSION["userID"];
  115 + $aParams[] = $sToSearch;
  116 + $aParams = array_merge($aParams, $aCritParams);
  117 +
  118 + //var_dump(DBUtil::getResultArray(array($sQuery, $aParams)));
  119 + //exit(0);
  120 +
  121 + $aColumns = array("folder_name", "file_name", "document_name", "doc_count", "view");
  122 + $aColumnTypes = array(3,3,3,1,3);
  123 + $aColumnHeaders = array("<font color=\"ffffff\"><img src=$default->graphicsUrl/widgets/dfolder.gif>" . _("Folder") . "</font>", "<font color=\"ffffff\">" . _("Name") . "</font>", "<font color=\"ffffff\">" . _("Title") . "</font>", "<font color=\"ffffff\">" . _("Matches") . "</font>", "<font color=\"ffffff\">" . _("View") . "</font>");
  124 + $aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument", "$default->rootUrl/control.php?action=viewDocument", null, "$default->rootUrl/control.php?action=downloadDocument");
  125 + $aDBQueryStringColumns = array("document_id","folder_id");
  126 + $aQueryStringVariableNames = array("fDocumentID", "fFolderID");
  127 +
  128 + $oPatternBrowse = & new PatternBrowseableSearchResults(array($sQuery, $aParams), 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames);
  129 + $oPatternBrowse->setStartIndex($iStartIndex);
  130 + $oPatternBrowse->setSearchText("");
  131 + $oPatternBrowse->setRememberValues($aReq);
  132 + $sForSearch = "<input type=\"hidden\" name=\"fForSearch\" value=\"1\" />";
  133 +
  134 + return renderHeading(_("Advanced Search")) . $oPatternBrowse->render() . $sForSearch . $sRefreshMessage;
  135 +}
  136 +
  137 +function dealWithAdvancedSearch($aReq, $iStartIndex) {
  138 + global $main;
  139 + $oPatternCustom = & new PatternCustom();
  140 + $oPatternCustom->setHtml(getAdvancedSearchResults($aReq, $iStartIndex));
  141 + $main->setCentralPayload($oPatternCustom);
  142 + $main->render();
  143 +}
  144 +
  145 +?>
... ...