diff --git a/presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php b/presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php index 9e673ec..de1ac17 100644 --- a/presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php +++ b/presentation/lookAndFeel/knowledgeTree/search/advancedSearchBL.php @@ -21,6 +21,7 @@ if (checkSession()) { require_once("$default->fileSystemRoot/lib/security/permission.inc"); require_once("$default->fileSystemRoot/presentation/Html.inc"); require_once("advancedSearchUI.inc"); + require_once("advancedSearchUtil.inc"); require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); @@ -31,18 +32,18 @@ if (checkSession()) { if (strlen($sMetaTagIDs) > 0) { $sSQLSearchString = getSQLSearchString($fSearchString); - $sDocument = getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString); + $sDocument = getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString, (isset($fSearchArchive) ? "Archived" : "Live")); if (strlen($sDocument) > 0) { //if there are documents to view $oPatternCustom = & new PatternCustom(); if (!isset($fStartIndex)) { $fStartIndex = 0; - } + } $oPatternCustom->setHtml(getSearchResults($sMetaTagIDs,$sSQLSearchString, $fStartIndex)); $main->setCentralPayload($oPatternCustom); $main->render(); } else { - $oPatternCustom = & new PatternCustom(); + $oPatternCustom = & new PatternCustom(); $oPatternCustom->setHtml(getSearchPage($fSearchString, explode(",",$sMetaTagIDs))); $main->setCentralPayload($oPatternCustom); $main->setErrorMessage("No documents matched your search criteria"); @@ -76,73 +77,6 @@ if (checkSession()) { $main->setCentralPayload($oPatternCustom); $main->setFormAction("advancedSearchBL.php?fForSearch=1"); $main->render(); - } - - -} - -function getChosenMetaDataTags() { - $aKeys = array_keys($_POST); - $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)] = $_POST[$aKeys[$i]]; - $i++; - $sRowStart = $aKeys[$i]; - } - - } - } - if (count($aTagIDs) > 1) { - return implode(",",$aTagIDs); - } - return $aTagIDs[0]; -} - -/** -* Generate a string onsisting of all documents that match the search criteria -* and that the user is allowed to see -*/ -function getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString) { - global $default; - $aApprovedDocumentIDs = array(); - $sQuery = "SELECT DISTINCT D.id " . - "FROM documents AS D INNER JOIN document_fields_link AS DFL ON DFL.document_id = D.id " . - "INNER JOIN document_fields AS DF ON DF.id = DFL.document_field_id " . - "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.ID " . - "INNER JOIN status_lookup AS SL on D.status_id=SL.id " . - "WHERE DF.ID IN ($sMetaTagIDs) " . - "AND " . $sSQLSearchString . " " . - "AND SL.name='Live' " . - "AND SDUL.user_id = " . $_SESSION["userID"]; - $sql = $default->db; - $sql->query($sQuery); - while ($sql->next_record()) { - $aApprovedDocuments[count($aApprovedDocuments)] = $sql->f("id"); - } - if (count($aApprovedDocuments) > 1) { - return implode(",",$aApprovedDocuments); - } - return $aApprovedDocuments[0]; - -} - -/* -* 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; + } } ?> \ No newline at end of file diff --git a/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUI.inc b/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUI.inc index 97aec59..3404a48 100644 --- a/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/search/advancedSearchUI.inc @@ -37,14 +37,14 @@ function getMetaData($aMetaTagIDs) { return $sToRender; } - -function getSearchPage($sSearchString = "", $aMetaTagIDs = array()) { +function getSearchPage($sSearchString = "", $aMetaTagIDs = array(), $sHeading = "Advanced Search", $bSearchArchive = false) { global $default; - $sToRender = renderHeading("Advanced Search"); + $sToRender = renderHeading($sHeading); $sToRender .= "\n"; $sToRender .= "\n"; $sToRender .= "\n"; + $sToRender .= ($bSearchArchive ? " 1) { + return implode(",",$aTagIDs); + } + return $aTagIDs[0]; +} + +/** +* Generate a string consisting of all documents that match the search criteria +* and that the user is allowed to see +*/ +function getApprovedDocumentString($sMetaTagIDs, $sSQLSearchString, $sStatus = "Live") { + global $default; + $aApprovedDocumentIDs = array(); + $sQuery = "SELECT DISTINCT D.id " . + "FROM documents AS D INNER JOIN document_fields_link AS DFL ON DFL.document_id = D.id " . + "INNER JOIN document_fields AS DF ON DF.id = DFL.document_field_id " . + "INNER JOIN search_document_user_link AS SDUL ON SDUL.document_id = D.ID " . + "INNER JOIN status_lookup AS SL on D.status_id=SL.id " . + "WHERE DF.ID IN ($sMetaTagIDs) " . + "AND " . $sSQLSearchString . " " . + "AND SL.name='$sStatus' " . + "AND SDUL.user_id = " . $_SESSION["userID"]; + $sql = $default->db; + $sql->query($sQuery); + while ($sql->next_record()) { + $aApprovedDocuments[count($aApprovedDocuments)] = $sql->f("id"); + } + if (count($aApprovedDocuments) > 1) { + return implode(",",$aApprovedDocuments); + } + return $aApprovedDocuments[0]; + +} + +/* +* 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; +} +?> \ No newline at end of file
Search text: \n"; $sToRender .= "