Commit 7dc7849dbf82b2b853216acfd8dc2c415333c0d5

Authored by Michael Joseph
1 parent 19dc35a3

added restore archived documents pages


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1982 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/archivedDocumentsUI.inc 0 → 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id$
  5 + *
  6 + * This page holds all presentation code for displaying document archiving searching.
  7 + *
  8 + * Licensed under the GNU GPL. For full terms see the file DOCS/COPYING.
  9 + *
  10 + * @version $Revision$
  11 + * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa
  12 + * @package presentation.lookAndFeel.knowledgeTree.administration.dopcumentmanagement
  13 + */
  14 +
  15 +/**
  16 + * Displays the status of restored documents
  17 + */
  18 +function renderStatusPage($aSuccessDocuments, $aErrorDocuments) {
  19 + global $default;
  20 +
  21 + $sToRender = renderHeading("Archived Documents Restoration Status");
  22 + $sToRender .= "<table>";
  23 + if (count($aSuccessDocuments) > 0) {
  24 + $sToRender .= "<tr><td>The following documents were successfully restored:</td></tr>\n";
  25 + $sToRender .= "<tr/><tr/>";
  26 + for ($i=0; $i<count($aSuccessDocuments); $i++) {
  27 + $sToRender .= "<tr><td>" . $aSuccessDocuments[$i]->getDisplayPath() . "</td></tr>\n";
  28 + }
  29 + }
  30 + if (count($aErrorDocuments) > 0) {
  31 + $sToRender .= "<tr><td>There were errors restoring the following documents:</td></tr>\n";
  32 + $sToRender .= "<tr/><tr/>";
  33 + for ($i=0; $i<count($aErrorDocuments); $i++) {
  34 + $sToRender .= "<tr><td>" . $aErrorDocuments[$i]->getDisplayPath() . "</td></tr>\n";
  35 + }
  36 + }
  37 + $sToRender .= "<tr/><tr/>";
  38 + $sToRender .= "<tr><td>" . generateControllerLink("archivedDocuments", "", "<img src=\"$default->graphicsUrl/widgets/back.gif\" border=\"0\"></td></tr>");
  39 + $sToRender .= "</table>";
  40 + return $sToRender;
  41 +}
  42 +
  43 +/**
  44 + * Gives the user a last chance to bail out before restoring the documents
  45 + */
  46 +function renderRestoreConfirmationPage($aDocuments) {
  47 + global $default;
  48 +
  49 + $sToRender = renderHeading("Restore Archived Documents");
  50 + $sToRender .= "<table>";
  51 + $sToRender .= "<tr><td>The documents and folders you have chosen to restore from the archive are listed below.</td></tr>\n";
  52 + $sToRender .= "<tr><td>Click 'Restore' to confirm restoration, or 'Cancel' to abort.</td></tr>\n";
  53 + $sToRender .= "<tr/><tr/>";
  54 +
  55 + // loop through them
  56 + for ($i = 0; $i < count($aDocuments); $i++) {
  57 + $sToRender .= "\t<tr>\n";
  58 + $sToRender .= "\t\t<td bgcolor=\"" . getColour($i) . "\">\n";
  59 + $sToRender .= "<input type=\"hidden\" name=\"fDocumentIDs[]\" value=\"" . $aDocuments[$i]->getID() . "\"/>\n";
  60 + $sToRender .= $aDocuments[$i]->getDisplayPath() . "\n";
  61 + $sToRender .= "\t\t</td>\n";
  62 + $sToRender .= "\t</tr>\n";
  63 + }
  64 + $sToRender .= "<tr/><tr/>";
  65 + $sToRender .= "<input type=\"hidden\" name=\"fConfirm\" value=\"1\">";
  66 + $sToRender .= "<tr><td><input type=\"image\" src=\"$default->graphicsUrl/widgets/restore.gif\" border=\"0\"/></a>\n";
  67 + $sToRender .= generateControllerLink("archivedDocuments", "", "<img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"></td></tr>");
  68 + $sToRender .= "</table>";
  69 + return $sToRender;
  70 +}
  71 +
  72 +/**
  73 + * Displays the archived document search form
  74 + */
  75 +function renderSearchPage() {
  76 + global $default;
  77 + $sToRender = renderHeading("Archived Documents Search");
  78 + $sToRender .= "<table width=\"600\">\n";
  79 + $sToRender .= "<tr>\n";
  80 + $sToRender .= "<tr><td>Search for archived documents by entering the document name:</td></tr>\n";
  81 + $sToRender .= "<td>Document name: <input type=\"text\" size=\"60\" name=\"fSearchString\" value=\"$sSearchString\" />\n";
  82 + $sToRender .= "<input type=\"image\" src=\"$default->graphicsUrl/widgets/submit.gif\" border=\"0\"></td>\n";
  83 + $sToRender .= "</tr>\n";
  84 + $sToRender .= "<tr>\n";
  85 + $sToRender .= "<td>&nbsp</td>\n";
  86 + $sToRender .= "</tr>\n";
  87 + $sToRender .= "</table>\n";
  88 +
  89 + $sToRender .= "\n\n<SCRIPT LANGUAGE=\"javascript\">\n ";
  90 + $sToRender .= "<!--\n";
  91 + $sToRender .= "function validateForm() {\n";
  92 + $sToRender .= "\tif (!(validRequired(document.MainForm.fSearchString, 'Search text'))) {\n";
  93 + $sToRender .= "\t\treturn false;\n\t}\n";
  94 + $sToRender .= "\treturn true;\n}\n";
  95 + $sToRender .= "-->\n";
  96 + $sToRender .= "</SCRIPT>\n\n";
  97 +
  98 + return $sToRender;
  99 +}
  100 +
  101 +/**
  102 + * Performs the search and displays the results
  103 + */
  104 +function renderArchivedDocumentsResultsPage($sKeywords, $iStartIndex) {
  105 + global $default;
  106 + $sQuery = "SELECT DISTINCT D.id AS document_id, D.name AS document_name " .
  107 + "FROM search_document_user_link AS SDUL " .
  108 + "INNER JOIN documents AS D ON D.id = SDUL.document_id " .
  109 + "INNER JOIN status_lookup AS SL ON D.status_id = SL.id " .
  110 + "WHERE SDUL.user_id = " . $_SESSION["userID"] . " " .
  111 + "AND SL.name='Archived' " .
  112 + "AND (D.name like '%$sKeywords%' " .
  113 + "OR D.filename like '%$sKeywords%')";
  114 +
  115 + $sToRender = renderHeading("Archived Documents Search Results");
  116 + $sToRender .= "<table>";
  117 + $sql = $default->db;
  118 + // perform query
  119 + if ($sql->query($sQuery)) {
  120 + if ($sql->num_rows() > 0) {
  121 + $sToRender .= "<tr><td>The following archived documents meet your search string.";
  122 + $sToRender .= "<tr><td>Select the documents you'd like to restore, and click 'Restore', or 'Cancel' to abort</td></tr>\n";
  123 +
  124 + while ($sql->next_record()) {
  125 + // and print document paths with checkboxes
  126 + $oDocument = Document::get($sql->f("document_id"));
  127 + $sToRender .= "\t<tr>\n";
  128 + $sToRender .= "\t\t<td bgcolor=\"" . getColour($i) . "\">\n";
  129 + $sToRender .= "<input type=\"checkbox\" name=\"fDocumentIDs[]\" value=\"" . $oDocument->getID() . "\"/>\n";
  130 + $sToRender .= $oDocument->getDisplayPath() . "\n";
  131 + $sToRender .= "\t\t</td>\n";
  132 + $sToRender .= "\t</tr>\n";
  133 + }
  134 + $sToRender .= "<tr><td><input type=\"image\" src=\"$default->graphicsUrl/widgets/restore.gif\" border=\"0\"/></a>\n";
  135 + $sToRender .= generateControllerLink("archivedDocuments", "", "<img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"></td></tr>");
  136 + } else {
  137 + $sToRender .= "<tr><td>Your query did not return any archived documents.";
  138 + $sToRender .= "<tr><td>" . generateControllerLink("archivedDocuments", "", "<img src=\"$default->graphicsUrl/widgets/back.gif\" border=\"0\">") . "</td></tr>\n";
  139 + }
  140 + } else {
  141 + // query failed
  142 + $sToRender .= "<tr><td>There was an error processing your query- please try again later.";
  143 + $sToRender .= "<tr><td>" . generateControllerLink("archivedDocuments", "", "<img src=\"$default->graphicsUrl/widgets/back.gif\" border=\"0\">") . "</td></tr>\n";
  144 + }
  145 + $sToRender .= "</table>";
  146 +
  147 + return $sToRender;
  148 +}
  149 +?>
0 150 \ No newline at end of file
... ...
presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageArchivedDocumentsBL.php 0 → 100644
  1 +<?php
  2 +
  3 +require_once("../../../../../config/dmsDefaults.php");
  4 +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
  5 +
  6 +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc");
  7 +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
  8 +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc");
  9 +require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc");
  10 +require_once("$default->uiDirectory/documentmanagement/documentUI.inc");
  11 +require_once("archivedDocumentsUI.inc");
  12 +require_once("$default->fileSystemRoot/presentation/Html.inc");
  13 +
  14 +/**
  15 + * $Id$
  16 + *
  17 + * Business logic for searching archived documents
  18 + *
  19 + * Licensed under the GNU GPL. For full terms see the file DOCS/COPYING.
  20 + *
  21 + * @version $Revision$
  22 + * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa
  23 + * @package presentation.lookAndFeel.knowledgeTree.administration.documentmanagement
  24 + */
  25 +
  26 +if (checkSession()) {
  27 + global $default;
  28 +
  29 + // instantiate my content pattern
  30 + $oContent = new PatternCustom();
  31 +
  32 + if (strlen($fSearchString) > 0) {
  33 + // perform the search and display the results
  34 + $fStartIndex = isset($fStartIndex) ? $fStartIndex : 0;
  35 + $oContent->setHtml(renderArchivedDocumentsResultsPage($fSearchString, $fStartIndex));
  36 + } else if ($fDocumentIDs) {
  37 + // got some documents to restore
  38 +
  39 + // instantiate document objects
  40 + $aDocuments = array();
  41 + for ($i = 0; $i < count($fDocumentIDs); $i++) {
  42 + $aDocuments[] = & Document::get($fDocumentIDs[$i]);
  43 + }
  44 +
  45 + if ($fConfirm) {
  46 + // restore the specified documents
  47 +
  48 + $aErrorDocuments = array();
  49 + $aSuccessDocuments = array();
  50 + for ($i = 0; $i < count($aDocuments); $i++) {
  51 + if ($aDocuments[$i]) {
  52 + // set the status to live
  53 + $aDocuments[$i]->setStatusID(lookupStatusID("Live"));
  54 + if ($aDocuments[$i]->update()) {
  55 + // success
  56 + $default->log->info("manageArchivedDocumentsBL.php set status for document id=" . $fDocumentIDs[$i]);
  57 + $aSuccessDocuments[] = $aDocuments[$i];
  58 + } else{
  59 + // error updating status change
  60 + $default->log->error("manageArchivedDocumentsBL.php couldn't retrieve document id=" . $fDocumentIDs[$i]);
  61 + $aErrorDocuments[] = $aDocuments[$i];
  62 + }
  63 + } else {
  64 + // error retrieving document object
  65 + $default->log->error("manageArchivedDocumentsBL.php couldn't retrieve document id=" . $fDocumentIDs[$i]);
  66 + }
  67 + }
  68 + // display status page.
  69 + $oContent->setHtml(renderStatusPage($aSuccessDocuments, $aErrorDocuments));
  70 + } else {
  71 + // ask for confirmation before restoring the documents
  72 + $oContent->setHtml(renderRestoreConfirmationPage($aDocuments));
  73 + }
  74 + } else {
  75 + // display the search form
  76 + $oContent->setHtml(renderSearchPage());
  77 + }
  78 +
  79 + // build the page
  80 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  81 + $main->setCentralPayload($oContent);
  82 + $main->setFormAction($_SERVER['PHP_SELF']);
  83 + $main->setHasRequiredFields(true);
  84 + $main->render();
  85 +}
  86 +?>
0 87 \ No newline at end of file
... ...