diff --git a/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageArchivedDocumentsBL.php b/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageArchivedDocumentsBL.php index afe9aa2..b4bb0f7 100644 --- a/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageArchivedDocumentsBL.php +++ b/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageArchivedDocumentsBL.php @@ -1,22 +1,4 @@ fileSystemRoot/lib/documentmanagement/Document.inc"); -require_once("$default->fileSystemRoot/lib/archiving/ArchiveRestorationRequest.inc"); -require_once("$default->fileSystemRoot/lib/email/Email.inc"); -require_once("$default->fileSystemRoot/lib/users/User.inc"); -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc"); -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc"); -require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc"); -require_once("$default->uiDirectory/documentmanagement/documentUI.inc"); -require_once("$default->uiDirectory/search/advancedSearchUI.inc"); -require_once("$default->uiDirectory/search/advancedSearchUtil.inc"); -require_once("archivedDocumentsUI.inc"); -require_once("$default->fileSystemRoot/presentation/Html.inc"); /** * $Id$ * @@ -43,139 +25,108 @@ require_once("$default->fileSystemRoot/presentation/Html.inc"); * @package administration.documentmanagement */ -if (checkSession()) { - global $default; - - // instantiate my content pattern - $oContent = new PatternCustom(); +require_once("../../../../../config/dmsDefaults.php"); + +require_once("$default->fileSystemRoot/presentation/Html.inc"); + +KTUtil::extractGPC('fConfirm', 'fDocumentIDs', 'fForSearch', 'fSearchString', 'fShowSection', 'fStartIndex', 'fToSearch'); + +if (checkSession()) { + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc"); + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); + require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); + require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); + require_once("$default->fileSystemRoot/lib/security/Permission.inc"); + require_once("$default->fileSystemRoot/lib/archiving/ArchiveRestorationRequest.inc"); + require_once("$default->fileSystemRoot/presentation/Html.inc"); + require_once(KT_DIR . "/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc"); + require_once(KT_DIR . "/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUI.inc"); + require_once("archivedDocumentsUI.inc"); + + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - if (strlen($fSearchString) > 0) { - // perform the search and display the results - $sMetaTagIDs = getChosenMetaDataTags($_GET); - if (strlen($sMetaTagIDs) > 0) { - $sSQLSearchString = getSQLSearchString($fSearchString); - $aDocuments = searchForDocuments($sMetaTagIDs, $sSQLSearchString, "Archived"); - if (count($aDocuments) > 0) { - // display the documents - $oContent->setHtml(renderArchivedDocumentsResultsPage($aDocuments)); - } else { - $oContent->setHtml(getSearchPage($fSearchString, explode(",",$sMetaTagIDs), _("Archived Documents Search"), true)); - $sErrorMessage = _("No documents matched your search criteria"); - } - } else { - $oContent->setHtml(getSearchPage($fSearchString, array(), _("Archived Documents Search"), true)); - $sErrorMessage = _("Please select at least one criteria to search by"); - } - } else if ($fDocumentIDs) { - // got some documents to restore + $main->setFormAction($_SERVER["PHP_SELF"]); - // instantiate document objects - $aDocuments = array(); + if (!isset($fStartIndex)) { + $fStartIndex = 1; + } + + $oContent = new PatternCustom; + + if (strlen($fForSearch)) { + dealWithAdvancedSearch($_REQUEST, $fStartIndex); + } else if ($fDocumentIDs) { + // got some documents to restore + + // instantiate document objects + $aDocuments = array(); for ($i = 0; $i < count($fDocumentIDs); $i++) { - $aDocuments[] = & Document::get($fDocumentIDs[$i]); + $aDocuments[] = & Document::get($fDocumentIDs[$i]); } - - if ($fConfirm) { - // restore the specified documents - - $aErrorDocuments = array(); - $aSuccessDocuments = array(); - for ($i = 0; $i < count($aDocuments); $i++) { - if ($aDocuments[$i]) { - - // set the status to live - $aDocuments[$i]->setStatusID(LIVE); - if ($aDocuments[$i]->update()) { - // success - $default->log->info("manageArchivedDocumentsBL.php set status for document id=" . $fDocumentIDs[$i]); - $aSuccessDocuments[] = $aDocuments[$i]; - - // check if there are requests for this document to be archived - $aRequests = ArchiveRestorationRequest::getList(array("document_id = ?", $aDocuments[$i]->getID()));/*ok*/ - $default->log->info("manageArchivedDocumentsBL.php about to send notification for " . count($aRequests) . " restoration requests for document id " . $aDocuments[$i]->getID()); - for ($j=0; $jgetRequestUserID()); - $sBody = "The document '" . generateControllerLink("viewDocument", "fDocumentID=" . $aDocuments[$i]->getID(), $aDocuments[$i]->getName()) . "'"; - $sBody .= " has been restored from the archive."; - $oEmail = & new Email(); - if ($oEmail->send($oRequestUser->getEmail(), _("Archived Document Restored"), $sBody)) { - $default->log->info("manageArchivedDocumentsBL.php sent email to " . $oRequestUser->getEmail()); - // now delete the request - $iRequestID = $aRequests[$j]->getID(); - if ($aRequests[$j]->delete()) { - $default->log->info("manageArchivedDocumentsBL.php removing restoration request $iRequestID"); - } else { - $default->log->error("manageArchivedDocumentsBL.php error removing request $iRequestID"); - } - } else { - $default->log->error("manageArchivedDocumentsBL.php error notifying " . arrayToString($oEmail) . " for document id " . $aDocuments[$i]->getID() . " restoration"); - } - } - } else{ - // error updating status change - $default->log->error("manageArchivedDocumentsBL.php couldn't retrieve document id=" . $fDocumentIDs[$i]); - $aErrorDocuments[] = $aDocuments[$i]; - } + + if ($fConfirm) { + // restore the specified documents + + $aErrorDocuments = array(); + $aSuccessDocuments = array(); + for ($i = 0; $i < count($aDocuments); $i++) { + if ($aDocuments[$i]) { + // set the status to live + $aDocuments[$i]->setStatusID(LIVE); + if ($aDocuments[$i]->update()) { + // success + $default->log->info("manageArchivedDocumentsBL.php set status for document id=" . $fDocumentIDs[$i]); + $aSuccessDocuments[] = $aDocuments[$i]; + + // check if there are requests for this document to be archived + $aRequests = ArchiveRestorationRequest::getList(array("document_id = ?", $aDocuments[$i]->getID()));/*ok*/ + $default->log->info("manageArchivedDocumentsBL.php about to send notification for " . count($aRequests) . " restoration requests for document id " . $aDocuments[$i]->getID()); + for ($j=0; $jgetRequestUserID()); + $sBody = "The document '" . generateControllerLink("viewDocument", "fDocumentID=" . $aDocuments[$i]->getID(), $aDocuments[$i]->getName()) . "'"; + $sBody .= " has been restored from the archive."; + $oEmail = & new Email(); + if ($oEmail->send($oRequestUser->getEmail(), _("Archived Document Restored"), $sBody)) { + $default->log->info("manageArchivedDocumentsBL.php sent email to " . $oRequestUser->getEmail()); + // now delete the request + $iRequestID = $aRequests[$j]->getID(); + if ($aRequests[$j]->delete()) { + $default->log->info("manageArchivedDocumentsBL.php removing restoration request $iRequestID"); + } else { + $default->log->error("manageArchivedDocumentsBL.php error removing request $iRequestID"); + } + } else { + $default->log->error("manageArchivedDocumentsBL.php error notifying " . arrayToString($oEmail) . " for document id " . $aDocuments[$i]->getID() . " restoration"); + } + } + } else { + // error updating status change + $default->log->error("manageArchivedDocumentsBL.php couldn't retrieve document id=" . $fDocumentIDs[$i]); + $aErrorDocuments[] = $aDocuments[$i]; + } } else { // error retrieving document object $default->log->error("manageArchivedDocumentsBL.php couldn't retrieve document id=" . $fDocumentIDs[$i]); - } - } + } + } // display status page. - $oContent->setHtml(renderStatusPage($aSuccessDocuments, $aErrorDocuments)); - } else { - // ask for confirmation before restoring the documents - $oContent->setHtml(renderRestoreConfirmationPage($aDocuments)); - } - } else { - // display the advanced search form, but specify that only archived documents must be returned + $oContent->setHtml(renderStatusPage($aSuccessDocuments, $aErrorDocuments)); + } else { + // ask for confirmation before restoring the documents + $oContent->setHtml(renderRestoreConfirmationPage($aDocuments)); + } + } else { + //display search criteria $oContent->setHtml(getSearchPage("", array(), _("Archived Documents Search"), true)); - } - - // build the page - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - if (isset($sErrorMessage)) { - $main->setErrorMessage($sErrorMessage); - } - $main->setCentralPayload($oContent); - $main->setFormAction($_SERVER['PHP_SELF']); - $main->setHasRequiredFields(true); - $main->setSubmitMethod("GET"); - $main->render(); + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForSearch=1"); + } + $main->setHasRequiredFields(true); + $main->setCentralPayload($oContent); + $main->render(); } - -/** -* Generate a string consisting of all documents that match the search criteria -* and that the user is allowed to see -*/ -function searchForDocuments($sMetaTagIDs, $sSQLSearchString, $sStatus = "Live") { - global $default; - $aDocuments = array(); - $aMetaTagIDs = split(',', $sMetaTagIDs); - $sQms = DBUtil::paramArray($aMetaTagIDs); - /*ok*/ $sQuery = "SELECT DISTINCT D.id " . - "FROM $default->documents_table AS D INNER JOIN document_fields_link AS DFL ON DFL.document_id = D.id " . - "INNER JOIN $default->document_fields_table AS DF ON DF.id = DFL.document_field_id " . - "INNER JOIN $default->search_permissions_table AS SDUL ON SDUL.document_id = D.ID " . - "INNER JOIN $default->status_table AS SL on D.status_id=SL.id " . - "WHERE DF.ID IN ($sQms) " . - "AND (" . $sSQLSearchString . ") " . - "AND SL.name = ? " . - "AND SDUL.user_id = ?"; - $default->log->info("searchForDocuments $sQuery"); - $aParams = $aMetaTagIDs; - $aParams[] = $sStatus; - $aParams[] = $_SESSION["userID"]; - $sql = $default->db; - $sql->query($sQuery); - while ($sql->next_record()) { - $aDocuments[] = & Document::get($sql->f("id")); - } - - return $aDocuments; -} ?> diff --git a/presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php b/presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php index 7de17c2..ee06d48 100644 --- a/presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php +++ b/presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php @@ -27,124 +27,10 @@ */ require_once("../../../../config/dmsDefaults.php"); +require_once(KT_DIR . '/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc'); KTUtil::extractGPC('fForSearch', 'fSearchString', 'fShowSection', 'fStartIndex', 'fToSearch'); -function searchCriteria ($var) { - return preg_match('/^bmd(_?\d+)/', $var); -} - -function criteriaNumber ($var) { - $res = preg_replace('/^bmd(_?\d+)(\D.*)?/', '\\1', $var); - if ($res !== false) { - $res = strtr($res, '_', '-'); - } - return $res; -} - -function getAdvancedSearchResults($aOrigReq, $iStartIndex) { - global $default; - - $sRefreshMessage = "
" . _("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") . "
"; - - $aReq = array(); - foreach ($aOrigReq as $k => $v) { - if (searchCriteria($k) === 1) { - $v = trim($v); - if ($v === "") { - continue; - } - if ($v === "-1") { - continue; - } - $aReq[$k] = $v; - } - } - - $aIDs = array_unique(array_map("criteriaNumber", array_keys($aReq))); - $aSQL = array(); - $aJoinSQL = array(); - foreach ($aIDs as $iID) { - $oCriterion =& Criteria::getCriterionByNumber($iID); - $res = $oCriterion->searchSQL($aReq); - if (!is_null($res)) { - $aSQL[] = $res; - } - $res = $oCriterion->searchJoinSQL(); - if (!is_null($res)) { - $aJoinSQL[] = $res; - } - } - $aCritParams = array(); - $aCritQueries = array(); - foreach ($aSQL as $sSQL) { - if (is_array($sSQL)) { - $aCritQueries[] = $sSQL[0]; - $aCritParams = array_merge($aCritParams , $sSQL[1]); - } else { - $aCritQueries[] = $sSQL; - } - } - - if (count($aCritQueries) == 0) { - return "No search criteria were specified"; - } - - $sSQLSearchString = join(" AND ", $aCritQueries); - $sJoinSQL = join(" ", $aJoinSQL); - - $sToSearch = KTUtil::arrayGet($aOrigReq, 'fToSearch', 'Live'); - - $sQuery = DBUtil::compactQuery(" -SELECT - F.name AS folder_name, F.id AS folder_id, D.id AS document_id, - D.name AS document_name, D.filename AS file_name, COUNT(D.id) AS doc_count, 'View' AS view -FROM - $default->documents_table AS D - INNER JOIN $default->folders_table AS F ON D.folder_id = F.id - $sJoinSQL - INNER JOIN $default->search_permissions_table AS SDUL ON SDUL.document_id = D.id - INNER JOIN $default->status_table AS SL on D.status_id=SL.id -WHERE - (F.is_public OR - SDUL.user_id = ?) - AND SL.name = ? - AND ($sSQLSearchString) -GROUP BY D.id -ORDER BY doc_count DESC"); - - $aParams = array(); - $aParams[] = $_SESSION["userID"]; - $aParams[] = $sToSearch; - $aParams = array_merge($aParams, $aCritParams); - - //var_dump(DBUtil::getResultArray(array($sQuery, $aParams))); - //exit(0); - - $aColumns = array("folder_name", "file_name", "document_name", "doc_count", "view"); - $aColumnTypes = array(3,3,3,1,3); - $aColumnHeaders = array("graphicsUrl/widgets/dfolder.gif>" . _("Folder") . "", "" . _("Name") . "", "" . _("Title") . "", "" . _("Matches") . "", "" . _("View") . ""); - $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"); - $aDBQueryStringColumns = array("document_id","folder_id"); - $aQueryStringVariableNames = array("fDocumentID", "fFolderID"); - - $oPatternBrowse = & new PatternBrowseableSearchResults(array($sQuery, $aParams), 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames); - $oPatternBrowse->setStartIndex($iStartIndex); - $oPatternBrowse->setSearchText(""); - $oPatternBrowse->setRememberValues($aReq); - $sForSearch = ""; - - return renderHeading(_("Advanced Search")) . $oPatternBrowse->render() . $sForSearch . $sRefreshMessage; -} - -function dealWithAdvancedSearch($aReq, $iStartIndex) { - global $main; - $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getAdvancedSearchResults($aReq, $iStartIndex)); - $main->setCentralPayload($oPatternCustom); - $main->render(); -} - if (checkSession()) { require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc"); require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); diff --git a/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc b/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc index 2e3fe66..ed29ec3 100644 --- a/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc +++ b/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUtil.inc @@ -5,7 +5,7 @@ * Business logic used to perform advanced search. Advanced search allows * users to search by meta data types. * - * Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com + * Copyright (c) 2005 Jam Warehouse http://www.jamwarehouse.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,47 +22,123 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @version $Revision$ - * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa + * @author Neil Blakey-Milner, Jam Warehouse (Pty) Ltd, South Africa * @package search */ -/** - * Interrogates the posted variables for the chosen metadata tags - */ -function getChosenMetaDataTags($aVariables) { - $aKeys = array_keys($aVariables); - $aTagIDs = array(); - for ($i = 0; $i < count($aKeys); $i++) { - $sRowStart = $aKeys[$i]; - $pos = strcmp("adv_search_start", $sRowStart); - if ($pos == 0) { - $i++; - $sRowStart = $aKeys[$i]; - while ((strcmp("adv_search_end", $sRowStart) != 0) && ($i < count($aKeys))) { - $aTagIDs[count($aTagIDs)] = $aVariables[$aKeys[$i]]; - $i++; - $sRowStart = $aKeys[$i]; - } - - } - } - if (count($aTagIDs) > 1) { - return implode(",",$aTagIDs); - } - return $aTagIDs[0]; +function searchCriteria ($var) { + return preg_match('/^bmd(_?\d+)/', $var); } -/* -* Generate a string that can be used in a SQL query -* from the list of documents the user is allowed to see -*/ -function getSQLSearchString($sSearchString) { - $aWords = explode(" ", $sSearchString); - $sSQLSearchString; - for ($i = 0; $i < count($aWords) - 1; $i++) { - $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[$i] . "%') OR "; - } - $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[count($aWords) -1] . "%')"; - return $sSQLSearchString; +function criteriaNumber ($var) { + $res = preg_replace('/^bmd(_?\d+)(\D.*)?/', '\\1', $var); + if ($res !== false) { + $res = strtr($res, '_', '-'); + } + return $res; } -?> \ No newline at end of file + +function getAdvancedSearchResults($aOrigReq, $iStartIndex) { + global $default; + + $sRefreshMessage = "
" . _("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") . "
"; + + $aReq = array(); + foreach ($aOrigReq as $k => $v) { + if (searchCriteria($k) === 1) { + $v = trim($v); + if ($v === "") { + continue; + } + if ($v === "-1") { + continue; + } + $aReq[$k] = $v; + } + } + + $aIDs = array_unique(array_map("criteriaNumber", array_keys($aReq))); + $aSQL = array(); + $aJoinSQL = array(); + foreach ($aIDs as $iID) { + $oCriterion =& Criteria::getCriterionByNumber($iID); + $res = $oCriterion->searchSQL($aReq); + if (!is_null($res)) { + $aSQL[] = $res; + } + $res = $oCriterion->searchJoinSQL(); + if (!is_null($res)) { + $aJoinSQL[] = $res; + } + } + $aCritParams = array(); + $aCritQueries = array(); + foreach ($aSQL as $sSQL) { + if (is_array($sSQL)) { + $aCritQueries[] = $sSQL[0]; + $aCritParams = array_merge($aCritParams , $sSQL[1]); + } else { + $aCritQueries[] = $sSQL; + } + } + + if (count($aCritQueries) == 0) { + return "No search criteria were specified"; + } + + $sSQLSearchString = join(" AND ", $aCritQueries); + $sJoinSQL = join(" ", $aJoinSQL); + + $sToSearch = KTUtil::arrayGet($aOrigReq, 'fToSearch', 'Live'); + + $sQuery = DBUtil::compactQuery(" +SELECT + F.name AS folder_name, F.id AS folder_id, D.id AS document_id, + D.name AS document_name, D.filename AS file_name, COUNT(D.id) AS doc_count, 'View' AS view +FROM + $default->documents_table AS D + INNER JOIN $default->folders_table AS F ON D.folder_id = F.id + $sJoinSQL + INNER JOIN $default->search_permissions_table AS SDUL ON SDUL.document_id = D.id + INNER JOIN $default->status_table AS SL on D.status_id=SL.id +WHERE + (F.is_public OR + SDUL.user_id = ?) + AND SL.name = ? + AND ($sSQLSearchString) +GROUP BY D.id +ORDER BY doc_count DESC"); + + $aParams = array(); + $aParams[] = $_SESSION["userID"]; + $aParams[] = $sToSearch; + $aParams = array_merge($aParams, $aCritParams); + + //var_dump(DBUtil::getResultArray(array($sQuery, $aParams))); + //exit(0); + + $aColumns = array("folder_name", "file_name", "document_name", "doc_count", "view"); + $aColumnTypes = array(3,3,3,1,3); + $aColumnHeaders = array("graphicsUrl/widgets/dfolder.gif>" . _("Folder") . "", "" . _("Name") . "", "" . _("Title") . "", "" . _("Matches") . "", "" . _("View") . ""); + $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"); + $aDBQueryStringColumns = array("document_id","folder_id"); + $aQueryStringVariableNames = array("fDocumentID", "fFolderID"); + + $oPatternBrowse = & new PatternBrowseableSearchResults(array($sQuery, $aParams), 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames); + $oPatternBrowse->setStartIndex($iStartIndex); + $oPatternBrowse->setSearchText(""); + $oPatternBrowse->setRememberValues($aReq); + $sForSearch = ""; + + return renderHeading(_("Advanced Search")) . $oPatternBrowse->render() . $sForSearch . $sRefreshMessage; +} + +function dealWithAdvancedSearch($aReq, $iStartIndex) { + global $main; + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getAdvancedSearchResults($aReq, $iStartIndex)); + $main->setCentralPayload($oPatternCustom); + $main->render(); +} + +?>