From 517d9827f5b0939f685851f674ca9cf549f1cd07 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 26 Feb 2003 12:33:39 +0000 Subject: [PATCH] Functionaltiy to search by folder and category complete --- presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+), 11 deletions(-) diff --git a/presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php b/presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php index 01799f2..7234381 100644 --- a/presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php +++ b/presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php @@ -16,36 +16,82 @@ require_once("../../../../config/dmsDefaults.php"); if (checkSession()) { require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.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("standardSearchUI.inc"); + + if (!isset($fStartIndex)) { + $fStartIndex = 0; + } + if (strlen($fBrowseType) > 0) { //the user was browsing by a specific type switch ($fBrowseType) { case "folder" : //user was browsing a specific folder - search that folder if (!$fFolderID) { - - + //start at the root folder + $fFolderID = 0; + $sFolderString = getApprovedFolderString($fFolderID); + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText))); + $main->setCentralPayload($oPatternCustom); + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID"); + $main->setHasRequiredFields(true); + $main->render(); } else { - $sChildString = implode(",", Folder::getChildren($fFolderID)); + $sFolderString = getApprovedFolderString($fFolderID); + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText))); + $main->setCentralPayload($oPatternCustom); + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID"); + $main->setHasRequiredFields(true); + $main->render(); } break; - case "category" : //user was browsing by category - search all documents in that category if (!$fCategoryName) { - - } else { - + //no category name specified, so just start at the root folder + $fFolderID = 0; + $sFolderString = getApprovedFolderString($fFolderID); + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText))); + $main->setCentralPayload($oPatternCustom); + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID"); + $main->setHasRequiredFields(true); + $main->render(); + } else { + $sFolderString = getApprovedFolderStringFromCategory($fCategoryName); + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText))); + $main->setCentralPayload($oPatternCustom); + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID"); + $main->setHasRequiredFields(true); + $main->render(); } break; case "documentType" : //user was browsing by document type - search all documents in that doc type if (!$fDocumentTypeID) { - + //no document type specified, so just start at the root folder + $fFolderID = 0; + $sFolderString = getApprovedFolderString($fFolderID); + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText))); + $main->setCentralPayload($oPatternCustom); + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID"); + $main->setHasRequiredFields(true); + $main->render(); } else { - + //TODO ONCE DOC TYPE/FOLDERS HAVE BEEN CHANGED } break; default: @@ -59,10 +105,26 @@ if (checkSession()) { } else if (strlen($fDocumentID) > 0) { //the user was viewing a document, search in that document's folder - + $oDocument = Document::get($fDocumentID); + $sFolderString = getApprovedFolderString($oDocument->getFolderID()); + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText))); + $main->setCentralPayload($oPatternCustom); + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID"); + $main->setHasRequiredFields(true); + $main->render(); } else { //search from the root folder down i.e. all documents - + $fFolderID = 0; + $sFolderString = getApprovedFolderString($fFolderID); + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText))); + $main->setCentralPayload($oPatternCustom); + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID"); + $main->setHasRequiredFields(true); + $main->render(); } } @@ -76,6 +138,105 @@ function searchByFolder($iFolderID, $sSearchText) { } +function getApprovedFolderString($iFolderID) { + $aChildren = Folder::getChildren($iFolderID); + $aApprovedChildren = array(); + //filter out all the folders the user does + //not have permission to see + for ($i = 0; $i < count($aChildren); $i++) { + $oFolder = Folder::get($aChildren[$i]); + + //if the folder is already approved, continue + if (in_array($oFolder->getID(), $aApprovedChildren)) { + //echo "Already in: " . $oFolder->getID() . "
"; + continue; + } + + $aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs()); + + //if one of the folder's parents is already approved, add the folder + for ($j = 0; $j < count($aParentFolderIDs); $j++) { + if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) { + if (in_array($oFolder->getID(), $aApprovedChildren)) { + $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID(); + } + continue; + } + } + + //check if the user has read permission for this folder + if (Permission::userHasFolderReadPermission($oFolder->getID())) { + $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID(); + continue; + } + + } + return implode(",", $aApprovedChildren); +} + +function getApprovedFolderStringFromCategory($sCategory) { + global $default; + $sQuery = "SELECT DISTINCT D.folder_id " . + "FROM $default->owl_documents_table AS D inner join $default->owl_document_fields_table AS DFL ON D.id = DFL.document_id " . + "INNER JOIN $default->owl_fields_table AS DF ON DF.id = DFL.document_field_id " . + "WHERE DF.name LIKE 'Category' " . + "AND DFL.value LIKE '$sCategory'"; + + $sql = $default->db; + $sql->query($sQuery); + if ($sql->next_record()) { + //get all the folders in the category + $aFolders = array($sql->f("folder_id")); + while ($sql->next_record()) { + $aFolders[count($aFolders)] = $sql->f("folder_id"); + } + + $aApprovedChildren = array(); + //filter out all the folders the user does + //not have permission to see + for ($i = 0; $i < count($aFolders); $i++) { + $oFolder = Folder::get($aFolders[$i]); + + //if the folder is already approved, continue + if (in_array($oFolder->getID(), $aApprovedChildren)) { + //echo "Already in: " . $oFolder->getID() . "
"; + continue; + } + + $aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs()); + + //if one of the folder's parents is already approved, add the folder + for ($j = 0; $j < count($aParentFolderIDs); $j++) { + if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) { + if (in_array($oFolder->getID(), $aApprovedChildren)) { + $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID(); + } + continue; + } + } + + //check if the user has read permission for this folder + if (Permission::userHasFolderReadPermission($oFolder->getID())) { + $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID(); + continue; + } + + } + return implode(",", $aApprovedChildren); + } + return "0"; +} + +function getSQLSearchString($sSearchString) { + $aWords = explode(" ", $sSearchString); + $sSQLSearchString; + for ($i = 0; $i < count($aWords) - 1; $i++) { + $sSQLSearchString .= "(WL.word LIKE '%" . $aWords[$i] . "%') OR "; + } + $sSQLSearchString .= "(WL.word LIKE '%" . $aWords[count($aWords) -1] . "%')"; + return $sSQLSearchString; +} + function searchByCategory($sCategoryName) { } @@ -86,5 +247,7 @@ function searchByDocType($iDocTypeID) { + + ?> diff --git a/presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc b/presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc index b51c1a6..15b2b7c 100644 --- a/presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc @@ -36,4 +36,40 @@ function getSearchByFolderPage($iFolderID, $sSearchText) { return $oPatternTableSqlQuery->render(); } +function getPage($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType, $sFolderIDs, $iStartIndex, $sSQLSearchString) { + return getSearchResults($sFolderIDs, $sSQLSearchString, $iStartIndex) . getSearchVariablesHtml($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType); +} + +function getSearchResults($sFolderIDs,$sSQLSearchString, $iStartIndex) { + global $default; + $sQuery = "SELECT DISTINCT '" . "$default->graphicsUrl/widgets/dfolder.gif" . "' AS folder_image_url, F.id folder_id, D.id document_id, D.name AS document_name " . + "FROM $default->owl_documents_table AS D INNER JOIN $default->owl_folders_table AS F ON D.folder_id = F.id " . + "INNER JOIN $default->owl_document_words_table AS DWL ON DWL.document_id = D.id " . + "INNER JOIN $default->owl_words_lookup_table AS WL ON WL.id = DWL.word_id " . + "WHERE F.id IN ($sFolderIDs) " . + "AND ($sSQLSearchString)"; + "ORDER BY D.name ASC"; + $aColumns = array("folder_image_url", "document_name"); + $aColumnTypes = array(4,3); + $aColumnHeaders = array("","Document"); + $aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument"); + $aDBQueryStringColumns = array("document_id","folder_id"); + $aQueryStringVariableNames = array("fDocumentID", "fFolderID"); + + + $oPatternBrowse = & new PatternBrowseableSearchResults($sQuery, 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames); + $oPatternBrowse->setStartIndex($iStartIndex); + return $oPatternBrowse->render(); +} + +function getSearchVariablesHtml($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType) { + $sToRender = "\n"; + $sToRender .= "\n"; + $sToRender .= "\n"; + $sToRender .= "\n"; + $sToRender .= "\n"; + $sToRender .= "\n"; + return $sToRender; +} + ?> -- libgit2 0.21.4