Commit 9a5fdf91e08223302f146c388f2673d4a7ac1aa8
1 parent
951b4a50
Initial revision. functionality for performing advanced searches
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1144 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
180 additions
and
0 deletions
presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | +* Business logic used to perform advanced search. Advanced search allows | ||
| 4 | +* users to search by meta data types | ||
| 5 | +* | ||
| 6 | +* @author Rob Cherry, Jam Warehouse South Africa (Pty) Ltd | ||
| 7 | +* @date 26 February 2003 | ||
| 8 | +* @package presentation.knowledgeTree.search | ||
| 9 | +*/ | ||
| 10 | + | ||
| 11 | +require_once("../../../../config/dmsDefaults.php"); | ||
| 12 | + | ||
| 13 | +if (checkSession()) { | ||
| 14 | + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternBrowsableSearchResults.inc"); | ||
| 15 | + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); | ||
| 16 | + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | ||
| 17 | + require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 18 | + require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | ||
| 19 | + require_once("$default->fileSystemRoot/lib/security/permission.inc"); | ||
| 20 | + require_once("advancedSearchUI.inc"); | ||
| 21 | + | ||
| 22 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 23 | + | ||
| 24 | + if (isset($fForSearch)) { | ||
| 25 | + if (strlen($fSearchString) > 0) { | ||
| 26 | + //display search results | ||
| 27 | + $sMetaTagIDs = getChosenMetaDataTags(); | ||
| 28 | + | ||
| 29 | + if (strlen($sMetaTagIDs) > 0) { | ||
| 30 | + $sSQLSearchString = getSQLSearchString($fSearchString); | ||
| 31 | + $sDocument = getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString); | ||
| 32 | + echo $sDocument; | ||
| 33 | + | ||
| 34 | + } else { | ||
| 35 | + $oPatternCustom = & new PatternCustom(); | ||
| 36 | + $oPatternCustom->setHtml(getSearchPage($fSearchString)); | ||
| 37 | + $main->setCentralPayload($oPatternCustom); | ||
| 38 | + $main->setErrorMessage("Please select at least one criteria to search by"); | ||
| 39 | + $main->setFormAction("advancedSearchBL.php?fForSearch=1"); | ||
| 40 | + $main->render(); | ||
| 41 | + } | ||
| 42 | + } else { | ||
| 43 | + $sMetaTagIDs = getChosenMetaDataTags(); | ||
| 44 | + $aMetaTagIDs = explode(",", $sMetaTagIDs); | ||
| 45 | + $oPatternCustom = & new PatternCustom(); | ||
| 46 | + $oPatternCustom->setHtml(getSearchPage($fSearchString, $aMetaTagIDs)); | ||
| 47 | + $main->setCentralPayload($oPatternCustom); | ||
| 48 | + $main->setErrorMessage("Please enter text to search on"); | ||
| 49 | + $main->setFormAction("advancedSearchBL.php?fForSearch=1"); | ||
| 50 | + $main->render(); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + } else { | ||
| 54 | + //display search criteria | ||
| 55 | + $oPatternCustom = & new PatternCustom(); | ||
| 56 | + $oPatternCustom->setHtml(getSearchPage($fSearchString)); | ||
| 57 | + $main->setCentralPayload($oPatternCustom); | ||
| 58 | + $main->setFormAction("advancedSearchBL.php?fForSearch=1"); | ||
| 59 | + $main->render(); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +function getChosenMetaDataTags() { | ||
| 66 | + $aKeys = array_keys($_POST); | ||
| 67 | + $aTagIDs = array(); | ||
| 68 | + for ($i = 0; $i < count($aKeys); $i++) { | ||
| 69 | + $sRowStart = $aKeys[$i]; | ||
| 70 | + $pos = strcmp("adv_search_start", $sRowStart); | ||
| 71 | + if ($pos == 0) { | ||
| 72 | + $i++; | ||
| 73 | + $sRowStart = $aKeys[$i]; | ||
| 74 | + while ((strcmp("adv_search_end", $sRowStart) != 0) && ($i < count($aKeys))) { | ||
| 75 | + $aTagIDs[count($aTagIDs)] = $_POST[$aKeys[$i]]; | ||
| 76 | + $i++; | ||
| 77 | + $sRowStart = $aKeys[$i]; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + return implode(",",$aTagIDs); | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +function getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString) { | ||
| 86 | + global $default; | ||
| 87 | + $aApprovedDocumentIDs = array(); | ||
| 88 | + $sQuery = "SELECT DISTINCT D.id " . | ||
| 89 | + "FROM documents AS D INNER JOIN document_fields_link AS DFL ON DFL.document_id = D.id " . | ||
| 90 | + "INNER JOIN document_fields AS DF ON DF.id = DFL.document_field_id " . | ||
| 91 | + "WHERE DF.ID IN (1,2,3,4) " . | ||
| 92 | + "AND " . $sSQLSearchString; | ||
| 93 | + | ||
| 94 | + $sql = $default->db; | ||
| 95 | + $sql->query($sQuery); | ||
| 96 | + while ($sql->next_record()) { | ||
| 97 | + if (Permission::userHasDocumentReadPermission($sql->f("id"))) { | ||
| 98 | + $aApprovedDocuments[count($aApprovedDocuments)] = $sql->f("id"); | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + return implode(",",$aApprovedDocuments); | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +function getSQLSearchString($sSearchString) { | ||
| 105 | + $aWords = explode(" ", $sSearchString); | ||
| 106 | + $sSQLSearchString; | ||
| 107 | + for ($i = 0; $i < count($aWords) - 1; $i++) { | ||
| 108 | + $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[$i] . "%') OR "; | ||
| 109 | + } | ||
| 110 | + $sSQLSearchString .= "(DFL.value LIKE '%" . $aWords[count($aWords) -1] . "%')"; | ||
| 111 | + return $sSQLSearchString; | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +?> |
presentation/lookAndFeel/knowledgeTree/search/advancedSearchUI.inc
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | +* Presentation logic used by advancedSearchBL.php | ||
| 5 | +* | ||
| 6 | +* @author Rob Cherry, Jam Warehouse South Africa (Pty) Ltd | ||
| 7 | +* @date 26 February 2003 | ||
| 8 | +* @package presentation.lookAndFeel.knowledgeTree.search | ||
| 9 | +* | ||
| 10 | +*/ | ||
| 11 | + | ||
| 12 | +function getMetaData($aMetaTagIDs) { | ||
| 13 | + global $default; | ||
| 14 | + $sQuery = "SELECT name, id FROM $default->owl_fields_table ORDER BY name ASC"; | ||
| 15 | + | ||
| 16 | + $sql = $default->db; | ||
| 17 | + $sql->query($sQuery); | ||
| 18 | + | ||
| 19 | + $sToRender = "<table border=\"0\">\n"; | ||
| 20 | + $sToRender .= "<input type=\"hidden\" name=\"adv_search_start\" value=\"\" />\n"; | ||
| 21 | + | ||
| 22 | + while ($sql->next_record()) { | ||
| 23 | + $sToRender .= "<tr><td><input type=\"checkbox\" " . wasSelected($sql->f("id"), $aMetaTagIDs) . " name=\"f_adv_" . $sql->f("name") . "\" value=\"" . $sql->f("id") . "\"></td><td>" . $sql->f("name") . "</td></tr>\n"; | ||
| 24 | + | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + $sToRender .= "<input type=\"hidden\" name=\"adv_search_end\" value=\"\" />\n"; | ||
| 28 | + $sToRender .= "</table>\n"; | ||
| 29 | + | ||
| 30 | + return $sToRender; | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +function getSearchPage($sSearchString = "", $aMetaTagIDs = array()) { | ||
| 34 | + global $default; | ||
| 35 | + $sToRender = "<table>\n"; | ||
| 36 | + $sToRender .= "<tr>\n"; | ||
| 37 | + $sToRender .= "<td>Search text: <input type=\"text\" size=\"60\" name=\"fSearchString\" value=\"$sSearchString\" /></td>\n"; | ||
| 38 | + $sToRender .= "<td><input type=\"image\" src=\"$default->graphicsUrl/search.gif\" /></td>\n"; | ||
| 39 | + $sToRender .= "</tr>\n"; | ||
| 40 | + $sToRender .= "<tr>\n"; | ||
| 41 | + $sToRender .= "<td> </td>\n"; | ||
| 42 | + $sToRender .= "</tr>\n"; | ||
| 43 | + $sToRender .= "<tr>\n"; | ||
| 44 | + $sToRender .= "<td>" . getMetaData($aMetaTagIDs) . "</td>\n"; | ||
| 45 | + $sToRender .= "</tr>\n"; | ||
| 46 | + $sToRender .= "<tr>\n"; | ||
| 47 | + $sToRender .= "<td> </td>\n"; | ||
| 48 | + $sToRender .= "</tr>\n"; | ||
| 49 | + $sToRender .= "</table>\n"; | ||
| 50 | + | ||
| 51 | + return $sToRender; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +function getSearchResults($sFolderIDs,$sSQLSearchString, $iStartIndex) { | ||
| 55 | + | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +function wasSelected($iID, $aMetaTagIDs) { | ||
| 59 | + if (in_array($iID, $aMetaTagIDs)) { | ||
| 60 | + return "CHECKED"; | ||
| 61 | + } | ||
| 62 | + return ""; | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +?> | ||
| 66 | + |