Commit f92a7febf3415c2cd0fd7254cd5e4e7aabf18222

Authored by michael
1 parent b6e51ea6

moved searching capability from the pattern

passing document objects
inserted hook for user notification on document restoration


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2082 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/archivedDocumentsUI.inc
... ... @@ -107,20 +107,18 @@ function renderSearchPage($aMetaTagIDs = array()) {
107 107 /**
108 108 * Performs the search and displays the results
109 109 */
110   -function renderArchivedDocumentsResultsPage($sDocumentIDs) {
  110 +function renderArchivedDocumentsResultsPage($aDocuments) {
111 111 global $default;
112 112  
113   - $aDocumentIDs = explode(",", $sDocumentIDs);
114 113 $sToRender = renderHeading("Archived Documents Search Results");
115 114 $sToRender .= "<table>";
116 115 $sToRender .= "<tr><td>Select the archived documents you'd like to restore, and click 'Restore', or 'Cancel' to abort</td></tr>\n";
117   - for ($i=0; $i<count($aDocumentIDs); $i++) {
  116 + for ($i=0; $i<count($aDocuments); $i++) {
118 117 // and print document paths with checkboxes
119   - $oDocument = Document::get($aDocumentIDs[$i]);
120 118 $sToRender .= "\t<tr>\n";
121 119 $sToRender .= "\t\t<td bgcolor=\"" . getColour($i) . "\">\n";
122   - $sToRender .= "<input type=\"checkbox\" name=\"fDocumentIDs[]\" value=\"" . $oDocument->getID() . "\"/>\n";
123   - $sToRender .= $oDocument->getDisplayPath() . "\n";
  120 + $sToRender .= "<input type=\"checkbox\" name=\"fDocumentIDs[]\" value=\"" . $aDocuments[$i]->getID() . "\"/>\n";
  121 + $sToRender .= $aDocuments[$i]->getDisplayPath() . "\n";
124 122 $sToRender .= "\t\t</td>\n";
125 123 $sToRender .= "\t</tr>\n";
126 124 }
... ...
presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageArchivedDocumentsBL.php
... ... @@ -36,10 +36,10 @@ if (checkSession()) {
36 36 $sMetaTagIDs = getChosenMetaDataTags();
37 37 if (strlen($sMetaTagIDs) > 0) {
38 38 $sSQLSearchString = getSQLSearchString($fSearchString);
39   - $sDocumentIDs = getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString, "Archived");
40   - if (strlen($sDocumentIDs) > 0) {
  39 + $aDocuments = searchForDocuments($sMetaTagIDs, $sSQLSearchString, "Archived");
  40 + if (count($aDocuments) > 0) {
41 41 // display the documents
42   - $oContent->setHtml(renderArchivedDocumentsResultsPage($sDocumentIDs));
  42 + $oContent->setHtml(renderArchivedDocumentsResultsPage($aDocuments));
43 43 } else {
44 44 $oContent->setHtml(getSearchPage($fSearchString, explode(",",$sMetaTagIDs), "Archived Documents Search", true));
45 45 $sErrorMessage = "No documents matched your search criteria";
... ... @@ -64,6 +64,10 @@ if (checkSession()) {
64 64 $aSuccessDocuments = array();
65 65 for ($i = 0; $i < count($aDocuments); $i++) {
66 66 if ($aDocuments[$i]) {
  67 + // TODO: check if there are requests for this document to be archived
  68 + // and email them
  69 + // FIXME: refactor notification
  70 +
67 71 // set the status to live
68 72 $aDocuments[$i]->setStatusID(lookupStatusID("Live"));
69 73 if ($aDocuments[$i]->update()) {
... ... @@ -88,7 +92,6 @@ if (checkSession()) {
88 92 }
89 93 } else {
90 94 // display the advanced search form, but specify that only archived documents must be returned
91   - //getSearchPage($sSearchString = "", $aMetaTagIDs = array(), $sHeading = "Advanced Search", $bSearchArchive = false) {
92 95 $oContent->setHtml(getSearchPage("", array(), "Archived Documents Search", true));
93 96 }
94 97  
... ... @@ -101,5 +104,32 @@ if (checkSession()) {
101 104 $main->setFormAction($_SERVER['PHP_SELF']);
102 105 $main->setHasRequiredFields(true);
103 106 $main->render();
104   -}
  107 +}
  108 +
  109 +
  110 +/**
  111 +* Generate a string consisting of all documents that match the search criteria
  112 +* and that the user is allowed to see
  113 +*/
  114 +function searchForDocuments($sMetaTagIDs, $sSQLSearchString, $sStatus = "Live") {
  115 + global $default;
  116 + $aDocuments = array();
  117 + $sQuery = "SELECT DISTINCT D.id " .
  118 + "FROM documents AS D INNER JOIN document_fields_link AS DFL ON DFL.document_id = D.id " .
  119 + "INNER JOIN document_fields AS DF ON DF.id = DFL.document_field_id " .
  120 + "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.ID " .
  121 + "INNER JOIN status_lookup AS SL on D.status_id=SL.id " .
  122 + "WHERE DF.ID IN ($sMetaTagIDs) " .
  123 + "AND (" . $sSQLSearchString . ") " .
  124 + "AND SL.name='$sStatus' " .
  125 + "AND SDUL.user_id = " . $_SESSION["userID"];
  126 + $default->log->info("searchForDocuments $sQuery");
  127 + $sql = $default->db;
  128 + $sql->query($sQuery);
  129 + while ($sql->next_record()) {
  130 + $aDocuments[] = & Document::get($sql->f("id"));
  131 + }
  132 +
  133 + return $aDocuments;
  134 +}
105 135 ?>
106 136 \ No newline at end of file
... ...