Commit 517d9827f5b0939f685851f674ca9cf549f1cd07

Authored by rob
1 parent 337c6994

Functionaltiy to search by folder and category complete


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1137 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/search/standardSearchBL.php
... ... @@ -16,36 +16,82 @@ require_once("../../../../config/dmsDefaults.php");
16 16  
17 17 if (checkSession()) {
18 18 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc");
  19 + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
19 20 require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
  21 + require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
20 22 require_once("standardSearchUI.inc");
  23 +
  24 + if (!isset($fStartIndex)) {
  25 + $fStartIndex = 0;
  26 + }
  27 +
21 28 if (strlen($fBrowseType) > 0) {
22 29 //the user was browsing by a specific type
23 30 switch ($fBrowseType) {
24 31 case "folder" :
25 32 //user was browsing a specific folder - search that folder
26 33 if (!$fFolderID) {
27   -
28   -
  34 + //start at the root folder
  35 + $fFolderID = 0;
  36 + $sFolderString = getApprovedFolderString($fFolderID);
  37 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  38 + $oPatternCustom = & new PatternCustom();
  39 + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
  40 + $main->setCentralPayload($oPatternCustom);
  41 + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
  42 + $main->setHasRequiredFields(true);
  43 + $main->render();
29 44 } else {
30   - $sChildString = implode(",", Folder::getChildren($fFolderID));
  45 + $sFolderString = getApprovedFolderString($fFolderID);
  46 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  47 + $oPatternCustom = & new PatternCustom();
  48 + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
  49 + $main->setCentralPayload($oPatternCustom);
  50 + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
  51 + $main->setHasRequiredFields(true);
  52 + $main->render();
31 53 }
32 54 break;
33   -
34 55 case "category" :
35 56 //user was browsing by category - search all documents in that category
36 57 if (!$fCategoryName) {
37   -
38   - } else {
39   -
  58 + //no category name specified, so just start at the root folder
  59 + $fFolderID = 0;
  60 + $sFolderString = getApprovedFolderString($fFolderID);
  61 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  62 + $oPatternCustom = & new PatternCustom();
  63 + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
  64 + $main->setCentralPayload($oPatternCustom);
  65 + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
  66 + $main->setHasRequiredFields(true);
  67 + $main->render();
  68 + } else {
  69 + $sFolderString = getApprovedFolderStringFromCategory($fCategoryName);
  70 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  71 + $oPatternCustom = & new PatternCustom();
  72 + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
  73 + $main->setCentralPayload($oPatternCustom);
  74 + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
  75 + $main->setHasRequiredFields(true);
  76 + $main->render();
40 77 }
41 78 break;
42 79  
43 80 case "documentType" :
44 81 //user was browsing by document type - search all documents in that doc type
45 82 if (!$fDocumentTypeID) {
46   -
  83 + //no document type specified, so just start at the root folder
  84 + $fFolderID = 0;
  85 + $sFolderString = getApprovedFolderString($fFolderID);
  86 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  87 + $oPatternCustom = & new PatternCustom();
  88 + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
  89 + $main->setCentralPayload($oPatternCustom);
  90 + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
  91 + $main->setHasRequiredFields(true);
  92 + $main->render();
47 93 } else {
48   -
  94 + //TODO ONCE DOC TYPE/FOLDERS HAVE BEEN CHANGED
49 95 }
50 96 break;
51 97 default:
... ... @@ -59,10 +105,26 @@ if (checkSession()) {
59 105  
60 106 } else if (strlen($fDocumentID) > 0) {
61 107 //the user was viewing a document, search in that document's folder
62   -
  108 + $oDocument = Document::get($fDocumentID);
  109 + $sFolderString = getApprovedFolderString($oDocument->getFolderID());
  110 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  111 + $oPatternCustom = & new PatternCustom();
  112 + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
  113 + $main->setCentralPayload($oPatternCustom);
  114 + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
  115 + $main->setHasRequiredFields(true);
  116 + $main->render();
63 117 } else {
64 118 //search from the root folder down i.e. all documents
65   -
  119 + $fFolderID = 0;
  120 + $sFolderString = getApprovedFolderString($fFolderID);
  121 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  122 + $oPatternCustom = & new PatternCustom();
  123 + $oPatternCustom->setHtml(getPage($fSearchText, $fBrowseType, $fFolderID, $fDocumentID, $fCategoryName, $fDocType, $sFolderString, $fStartIndex, getSQLSearchString($fSearchText)));
  124 + $main->setCentralPayload($oPatternCustom);
  125 + $main->setFormAction("addFolderBL.php?fFolderID=$fFolderID");
  126 + $main->setHasRequiredFields(true);
  127 + $main->render();
66 128 }
67 129 }
68 130  
... ... @@ -76,6 +138,105 @@ function searchByFolder($iFolderID, $sSearchText) {
76 138  
77 139 }
78 140  
  141 +function getApprovedFolderString($iFolderID) {
  142 + $aChildren = Folder::getChildren($iFolderID);
  143 + $aApprovedChildren = array();
  144 + //filter out all the folders the user does
  145 + //not have permission to see
  146 + for ($i = 0; $i < count($aChildren); $i++) {
  147 + $oFolder = Folder::get($aChildren[$i]);
  148 +
  149 + //if the folder is already approved, continue
  150 + if (in_array($oFolder->getID(), $aApprovedChildren)) {
  151 + //echo "Already in: " . $oFolder->getID() . "<br>";
  152 + continue;
  153 + }
  154 +
  155 + $aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs());
  156 +
  157 + //if one of the folder's parents is already approved, add the folder
  158 + for ($j = 0; $j < count($aParentFolderIDs); $j++) {
  159 + if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) {
  160 + if (in_array($oFolder->getID(), $aApprovedChildren)) {
  161 + $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
  162 + }
  163 + continue;
  164 + }
  165 + }
  166 +
  167 + //check if the user has read permission for this folder
  168 + if (Permission::userHasFolderReadPermission($oFolder->getID())) {
  169 + $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
  170 + continue;
  171 + }
  172 +
  173 + }
  174 + return implode(",", $aApprovedChildren);
  175 +}
  176 +
  177 +function getApprovedFolderStringFromCategory($sCategory) {
  178 + global $default;
  179 + $sQuery = "SELECT DISTINCT D.folder_id " .
  180 + "FROM $default->owl_documents_table AS D inner join $default->owl_document_fields_table AS DFL ON D.id = DFL.document_id " .
  181 + "INNER JOIN $default->owl_fields_table AS DF ON DF.id = DFL.document_field_id " .
  182 + "WHERE DF.name LIKE 'Category' " .
  183 + "AND DFL.value LIKE '$sCategory'";
  184 +
  185 + $sql = $default->db;
  186 + $sql->query($sQuery);
  187 + if ($sql->next_record()) {
  188 + //get all the folders in the category
  189 + $aFolders = array($sql->f("folder_id"));
  190 + while ($sql->next_record()) {
  191 + $aFolders[count($aFolders)] = $sql->f("folder_id");
  192 + }
  193 +
  194 + $aApprovedChildren = array();
  195 + //filter out all the folders the user does
  196 + //not have permission to see
  197 + for ($i = 0; $i < count($aFolders); $i++) {
  198 + $oFolder = Folder::get($aFolders[$i]);
  199 +
  200 + //if the folder is already approved, continue
  201 + if (in_array($oFolder->getID(), $aApprovedChildren)) {
  202 + //echo "Already in: " . $oFolder->getID() . "<br>";
  203 + continue;
  204 + }
  205 +
  206 + $aParentFolderIDs = explode(",",$oFolder->getParentFolderIDs());
  207 +
  208 + //if one of the folder's parents is already approved, add the folder
  209 + for ($j = 0; $j < count($aParentFolderIDs); $j++) {
  210 + if (in_array($aParentFolderIDs[$j], $aApprovedChildren)) {
  211 + if (in_array($oFolder->getID(), $aApprovedChildren)) {
  212 + $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
  213 + }
  214 + continue;
  215 + }
  216 + }
  217 +
  218 + //check if the user has read permission for this folder
  219 + if (Permission::userHasFolderReadPermission($oFolder->getID())) {
  220 + $aApprovedChildren[count($aApprovedChildren)] = $oFolder->getID();
  221 + continue;
  222 + }
  223 +
  224 + }
  225 + return implode(",", $aApprovedChildren);
  226 + }
  227 + return "0";
  228 +}
  229 +
  230 +function getSQLSearchString($sSearchString) {
  231 + $aWords = explode(" ", $sSearchString);
  232 + $sSQLSearchString;
  233 + for ($i = 0; $i < count($aWords) - 1; $i++) {
  234 + $sSQLSearchString .= "(WL.word LIKE '%" . $aWords[$i] . "%') OR ";
  235 + }
  236 + $sSQLSearchString .= "(WL.word LIKE '%" . $aWords[count($aWords) -1] . "%')";
  237 + return $sSQLSearchString;
  238 +}
  239 +
79 240 function searchByCategory($sCategoryName) {
80 241  
81 242 }
... ... @@ -86,5 +247,7 @@ function searchByDocType($iDocTypeID) {
86 247  
87 248  
88 249  
  250 +
  251 +
89 252 ?>
90 253  
... ...
presentation/lookAndFeel/knowledgeTree/search/standardSearchUI.inc
... ... @@ -36,4 +36,40 @@ function getSearchByFolderPage($iFolderID, $sSearchText) {
36 36 return $oPatternTableSqlQuery->render();
37 37 }
38 38  
  39 +function getPage($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType, $sFolderIDs, $iStartIndex, $sSQLSearchString) {
  40 + return getSearchResults($sFolderIDs, $sSQLSearchString, $iStartIndex) . getSearchVariablesHtml($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType);
  41 +}
  42 +
  43 +function getSearchResults($sFolderIDs,$sSQLSearchString, $iStartIndex) {
  44 + global $default;
  45 + $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 " .
  46 + "FROM $default->owl_documents_table AS D INNER JOIN $default->owl_folders_table AS F ON D.folder_id = F.id " .
  47 + "INNER JOIN $default->owl_document_words_table AS DWL ON DWL.document_id = D.id " .
  48 + "INNER JOIN $default->owl_words_lookup_table AS WL ON WL.id = DWL.word_id " .
  49 + "WHERE F.id IN ($sFolderIDs) " .
  50 + "AND ($sSQLSearchString)";
  51 + "ORDER BY D.name ASC";
  52 + $aColumns = array("folder_image_url", "document_name");
  53 + $aColumnTypes = array(4,3);
  54 + $aColumnHeaders = array("","Document");
  55 + $aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument");
  56 + $aDBQueryStringColumns = array("document_id","folder_id");
  57 + $aQueryStringVariableNames = array("fDocumentID", "fFolderID");
  58 +
  59 +
  60 + $oPatternBrowse = & new PatternBrowseableSearchResults($sQuery, 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames);
  61 + $oPatternBrowse->setStartIndex($iStartIndex);
  62 + return $oPatternBrowse->render();
  63 +}
  64 +
  65 +function getSearchVariablesHtml($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType) {
  66 + $sToRender = "<input type=\"hidden\" name=\"fSearchText\" value=\"$sSearchText\" />\n";
  67 + $sToRender .= "<input type=\"hidden\" name=\"fBrowseType\" value=\"$sBrowseType\" />\n";
  68 + $sToRender .= "<input type=\"hidden\" name=\"fFolderID\" value=\"$iFolderID\" />\n";
  69 + $sToRender .= "<input type=\"hidden\" name=\"fDocumentID\" value=\"$iDocumentID\" />\n";
  70 + $sToRender .= "<input type=\"hidden\" name=\"fCategoryName\" value=\"$sCategoryName\" />\n";
  71 + $sToRender .= "<input type=\"hidden\" name=\"fDocType\" value=\"$iDocType\" />\n";
  72 + return $sToRender;
  73 +}
  74 +
39 75 ?>
... ...