From d02848cce6da0b137d31cb049e9b7daaef446a62 Mon Sep 17 00:00:00 2001 From: steinm Date: Fri, 5 Nov 2010 21:41:37 +0000 Subject: [PATCH] - moved code for searching into inc.ClassDocument.php --- op/op.Search.php | 509 ++++++++++++----------------------------------- 1 file changed, 124 insertions(+), 385 deletions(-) diff --git a/op/op.Search.php b/op/op.Search.php index 3143d86e0..30e3e352b 100644 --- a/op/op.Search.php +++ b/op/op.Search.php @@ -91,288 +91,146 @@ function getTime() { function markQuery($str, $tag = "b") { GLOBAL $query; - $querywords = split(" ", $query); + $querywords = preg_split("/ /", $query); foreach ($querywords as $queryword) - $str = eregi_replace("($queryword)", "<" . $tag . ">\\1", $str); + $str = str_ireplace("($queryword)", "<" . $tag . ">\\1", $str); return $str; } -// -// Parse all of the parameters for the search -// - -// Create the keyword search string. This search spans up to three columns -// in the database: keywords, name and comment. - -if (isset($_GET["query"]) && is_string($_GET["query"])) { - $query = sanitizeString($_GET["query"]); -} -else { - $query = ""; -} -// Split the search string into constituent keywords. -$tkeys=array(); -if (strlen($query)>0) { - $tkeys = split("[\t\r\n ,]+", $query); -} - -$mode = "AND"; -if (isset($_GET["mode"]) && is_numeric($_GET["mode"]) && $_GET["mode"]==0) { - $mode = "OR"; -} - -$searchin = array(); -if (is_array($_GET["searchin"])) { - foreach ($_GET["searchin"] as $si) { - if (isset($si) && is_numeric($si)) { - switch ($si) { - case 1: // keywords - case 2: // name - case 3: // comment - $searchin[$si] = $si; - break; - } - } - } +// +// Parse all of the parameters for the search +// + +// Create the keyword search string. This search spans up to three columns +// in the database: keywords, name and comment. + +if (isset($_GET["query"]) && is_string($_GET["query"])) { + $query = sanitizeString($_GET["query"]); +} +else { + $query = ""; +} + +$mode = "AND"; +if (isset($_GET["mode"]) && is_numeric($_GET["mode"]) && $_GET["mode"]==0) { + $mode = "OR"; +} + +$searchin = array(); +if (isset($_GET['searchin']) && is_array($_GET["searchin"])) { + foreach ($_GET["searchin"] as $si) { + if (isset($si) && is_numeric($si)) { + switch ($si) { + case 1: // keywords + case 2: // name + case 3: // comment + $searchin[$si] = $si; + break; + } + } + } } // if none is checkd search all if (count($searchin)==0) $searchin=array( 0, 1, 2, 3); -$searchKey = ""; -// Assemble the arguments for the concatenation function. This allows the -// search to be carried across all the relevant fields. -$concatFunction = ""; -if (in_array(1, $searchin)) { - $concatFunction = "`tblDocuments`.`keywords`"; -} -if (in_array(2, $searchin)) { - $concatFunction = (strlen($concatFunction) == 0 ? "" : $concatFunction.", ")."`tblDocuments`.`name`"; -} -if (in_array(3, $searchin)) { - $concatFunction = (strlen($concatFunction) == 0 ? "" : $concatFunction.", ")."`tblDocuments`.`comment`"; -} - -if (strlen($concatFunction)>0 && count($tkeys)>0) { - $concatFunction = "CONCAT_WS(' ', ".$concatFunction.")"; - foreach ($tkeys as $key) { - $key = trim($key); - if (strlen($key)>0) { - $searchKey = (strlen($searchKey)==0 ? "" : $searchKey." ".$mode." ").$concatFunction." LIKE '%".$key."%'"; - } - } -} - -// Check to see if the search has been restricted to a particular sub-tree in -// the folder hierarchy. -$searchFolder = ""; -if (isset($_GET["targetidform1"]) && is_numeric($_GET["targetidform1"]) && $_GET["targetidform1"]>0) { - $targetid = $_GET["targetidform1"]; - $startFolder = getFolder($targetid); -} -else { - $targetid = $settings->_rootFolderID; - $startFolder = getFolder($targetid); -} -if (!is_object($startFolder)) { - UI::exitError(getMLText("search_results"),getMLText("invalid_folder_id")); +// Check to see if the search has been restricted to a particular sub-tree in +// the folder hierarchy. +if (isset($_GET["targetidform1"]) && is_numeric($_GET["targetidform1"]) && $_GET["targetidform1"]>0) { + $targetid = $_GET["targetidform1"]; + $startFolder = getFolder($targetid); } - -if ($targetid != $settings->_rootFolderID) { - $searchFolder = "`tblDocuments`.`folderList` LIKE '%:".$targetid.":%'"; -} - -// Now that the target folder has been identified, it is possible to create -// the full navigation bar. -$folderPathHTML = getFolderPathHTML($startFolder, true); -UI::htmlStartPage(getMLText("search_results")); -UI::globalNavigation($startFolder); -UI::pageNavigation($folderPathHTML, "", $startFolder); -UI::contentHeading(getMLText("search_results")); - -// Check to see if the search has been restricted to a particular -// document owner. -$searchOwner = ""; -if (isset($_GET["ownerid"]) && is_numeric($_GET["ownerid"]) && $_GET["ownerid"]!=-1) { - if (!is_object(getUser($_GET["ownerid"]))) { - UI::contentContainer(getMLText("unknown_owner")); - UI::htmlEndPage(); - exit; - } - $ownerid = $_GET["ownerid"]; -} -else { - $ownerid = -1; -} -if ($ownerid != -1) { - $searchOwner = "`tblDocuments`.`owner` = '".$ownerid."'"; -} - -// Is the search restricted to documents created between two specific dates? -$searchCreateDate = ""; -if (isset($_GET["creationdate"]) && $_GET["creationdate"]!=null) { - $startdate = makeTimeStamp(0, 0, 0, $_GET["createstartyear"], $_GET["createstartmonth"], $_GET["createstartday"]); - if (is_bool($startdate)) { - UI::contentContainer(getMLText("invalid_create_date_start")); - UI::htmlEndPage(); - exit; - } - $stopdate = makeTimeStamp(23, 59, 59, $_GET["createendyear"], $_GET["createendmonth"], $_GET["createendday"]); - if (is_bool($stopdate)) { - UI::contentContainer(getMLText("invalid_create_date_end")); - UI::htmlEndPage(); - exit; - } - $searchCreateDate = "`tblDocuments`.`date` >= ".$startdate. " AND `tblDocuments`.`date` <= ".$stopdate; -} - -// Is the search restricted to documents last updated between two specific -// dates? Not currently used as a more sophisticated method for reporting -// updates is required. -/* -$searchLastUpdate = ""; -if (isset($_GET["lastupdate"]) && $_GET["lastupdate"]!=null) { - $lastupdate = true; - - $startdate = makeTimeStamp(0, 0, 0, $_GET["updatestartyear"], $_GET["updatestartmonth"], $_GET["updatestartday"]); - if (is_bool($startdate)) { - die ("invalid start date for last update date range"); - } - $stopdate = mktime(23,59,59, $updateendmonth, $updateendday, $updateendyear); - $stopdate = makeTimeStamp(23, 59, 59, $_GET["updateendyear"], $_GET["updateendmonth"], $_GET["updateendday"]); - if (is_bool($stopdate)) { - die ("invalid end date for last update date range"); - } - $searchLastUpdate = "`contentDate` >= ".$startdate. " AND `contentDate` <= ".$stopdate; -} -*/ - -// -// Get the page number to display. If the result set contains more than -// 25 entries, it is displayed across multiple pages. -// -// This requires that a page number variable be used to track which page the -// user is interested in, and an extra clause on the select statement. -// -// Default page to display is always one. -$pageNumber=1; -if (isset($_GET["pg"])) { - if (is_numeric($_GET["pg"]) && $_GET["pg"]>0) { - $pageNumber = (integer)$_GET["pg"]; - } - else if (!strcasecmp($_GET["pg"], "all")) { - $pageNumber = "all"; - } -} - - -// ------------------------------------- Suche starten -------------------------------------------- -$startTime = getTime(); - -// -// Construct the SQL query that will be used to search the database. -// - -if (!$db->createTemporaryTable("ttcontentid") || !$db->createTemporaryTable("ttstatid")) { - UI::contentContainer(getMLText("internal_error")); - UI::htmlEndPage(); - exit; -} - -//$searchQuery = "SELECT `tblDocuments`.*, ". -// "`tblDocumentContent`.`version`, ". -// "`tblDocumentStatusLog`.`status`, `tblDocumentLocks`.`userID` as `lockUser` ". - -$searchQuery = "FROM `tblDocumentContent` ". - "LEFT JOIN `tblDocuments` ON `tblDocuments`.`id` = `tblDocumentContent`.`document` ". - "LEFT JOIN `tblDocumentStatus` ON `tblDocumentStatus`.`documentID` = `tblDocumentContent`.`document` ". - "LEFT JOIN `tblDocumentStatusLog` ON `tblDocumentStatusLog`.`statusID` = `tblDocumentStatus`.`statusID` ". - "LEFT JOIN `ttstatid` ON `ttstatid`.`maxLogID` = `tblDocumentStatusLog`.`statusLogID` ". - "LEFT JOIN `ttcontentid` ON `ttcontentid`.`maxVersion` = `tblDocumentStatus`.`version` AND `ttcontentid`.`document` = `tblDocumentStatus`.`documentID` ". - "LEFT JOIN `tblDocumentLocks` ON `tblDocuments`.`id`=`tblDocumentLocks`.`document` ". - "WHERE `ttstatid`.`maxLogID`=`tblDocumentStatusLog`.`statusLogID` ". - "AND `ttcontentid`.`maxVersion` = `tblDocumentContent`.`version`"; - -if (strlen($searchKey)>0) { - $searchQuery .= " AND (".$searchKey.")"; -} -if (strlen($searchFolder)>0) { - $searchQuery .= " AND ".$searchFolder; -} -if (strlen($searchOwner)>0) { - $searchQuery .= " AND (".$searchOwner.")"; -} -if (strlen($searchCreateDate)>0) { - $searchQuery .= " AND (".$searchCreateDate.")"; +else { + $targetid = $settings->_rootFolderID; + $startFolder = getFolder($targetid); +} +if (!is_object($startFolder)) { + UI::exitError(getMLText("search_results"),getMLText("invalid_folder_id")); +} + +// Now that the target folder has been identified, it is possible to create +// the full navigation bar. +$folderPathHTML = getFolderPathHTML($startFolder, true); +UI::htmlStartPage(getMLText("search_results")); +UI::globalNavigation($startFolder); +UI::pageNavigation($folderPathHTML, "", $startFolder); +UI::contentHeading(getMLText("search_results")); + +// Check to see if the search has been restricted to a particular +// document owner. +$owner = null; +if (isset($_GET["ownerid"]) && is_numeric($_GET["ownerid"]) && $_GET["ownerid"]!=-1) { + $owner = LetoDMS_getUser($_GET["ownerid"]); + if (!is_object($owner)) { + UI::contentContainer(getMLText("unknown_owner")); + UI::htmlEndPage(); + exit; + } +} + +// Is the search restricted to documents created between two specific dates? +$startdate = array(); +$stopdate = array(); +if (isset($_GET["creationdate"]) && $_GET["creationdate"]!=null) { + $startdate = array('year'=>$_GET["createstartyear"], 'month'=>$_GET["createstartmonth"], 'day'=>$_GET["createstartday"]); + if (!checkdate($startdate['month'], $startdate['year'], $startdate['day'])) { + UI::contentContainer(getMLText("invalid_create_date_start")); + UI::htmlEndPage(); + exit; + } + $stopdate = array('year'=>$_GET["createendyear"], 'month'=>$_GET["createendmonth"], 'day'=>$_GET["createendday"]); + if (!checkdate($stopdate['month'], $stopdate['year'], $stopdate['day'])) { + UI::contentContainer(getMLText("invalid_create_date_end")); + UI::htmlEndPage(); + exit; + } } // status -$stlist = "("; +$status = array(); if (isset($_GET["pendingReview"])){ - if ($stlist != "(") $stlist .= ","; - $stlist .= S_DRAFT_REV; + $status[] = S_DRAFT_REV; } if (isset($_GET["pendingApproval"])){ - if ($stlist != "(") $stlist .= ","; - $stlist .= S_DRAFT_APP; + $status[] = S_DRAFT_APP; } if (isset($_GET["released"])){ - if ($stlist != "(") $stlist .= ","; - $stlist .= S_RELEASED; + $status[] = S_RELEASED; } if (isset($_GET["rejected"])){ - if ($stlist != "(") $stlist .= ","; - $stlist .= S_REJECTED; + $status[] = S_REJECTED; } if (isset($_GET["obsolete"])){ - if ($stlist != "(") $stlist .= ","; - $stlist .= S_OBSOLETE; + $status[] = S_OBSOLETE; } if (isset($_GET["expired"])){ - if ($stlist != "(") $stlist .= ","; - $stlist .= S_EXPIRED; + $status[] = S_EXPIRED; } -if ($stlist != "("){ - $stlist .= ")"; - $searchQuery .= " AND `tblDocumentStatusLog`.`status` IN ".$stlist; +// +// Get the page number to display. If the result set contains more than +// 25 entries, it is displayed across multiple pages. +// +// This requires that a page number variable be used to track which page the +// user is interested in, and an extra clause on the select statement. +// +// Default page to display is always one. +$pageNumber=1; +if (isset($_GET["pg"])) { + if (is_numeric($_GET["pg"]) && $_GET["pg"]>0) { + $pageNumber = (integer)$_GET["pg"]; + } + else if (!strcasecmp($_GET["pg"], "all")) { + $pageNumber = "all"; + } } -// Count the number of rows that the search will produce. -$resArr = $db->getResultArray("SELECT COUNT(*) AS num ".$searchQuery); -$totalDocs = 0; -if (is_numeric($resArr[0]["num"]) && $resArr[0]["num"]>0) { - $totalDocs = (integer)$resArr[0]["num"]; -} -$totalPages = (integer)($totalDocs/25); -if (($totalDocs%25) > 0) { - $totalPages++; -} -if (is_numeric($pageNumber) && $pageNumber>$totalPages) { - $pageNumber = $totalPages; -} - -// If there are no results from the count query, then there is no real need -// to run the full query. TODO: re-structure code to by-pass additional -// queries when no initial results are found. In the meantime, make sure that -// the page number is at least 1. -if (is_numeric($pageNumber) && $pageNumber==0) { - $pageNumber = 1; -} -// Prepare the complete search query, including the LIMIT clause. -$searchQuery = "SELECT `tblDocuments`.*, ". - "`tblDocumentContent`.`version`, ". - "`tblDocumentStatusLog`.`status`, `tblDocumentLocks`.`userID` as `lockUser` ".$searchQuery; - -if (is_numeric($pageNumber)) { - $searchQuery .= " LIMIT ".(($pageNumber-1)*25).", 25"; -} - -// Send the complete search query to the database. -$resArr = $db->getResultArray($searchQuery); - + +// ------------------------------------- Suche starten -------------------------------------------- +$startTime = getTime(); +$resArr = LetoDMS_Document::search($query, 25, ($pageNumber-1)*25, $mode, $searchin, $startFolder, $owner, $status, $startdate, $stopdate); $searchTime = getTime() - $startTime; $searchTime = round($searchTime, 2); // ---------------------------------- Ausgabe der Ergebnisse -------------------------------------- @@ -383,12 +241,12 @@ UI::contentContainerStart(); $totalDocs)); + printMLText("search_report", array("count" => $resArr['totalDocs'])); } ?> @@ -403,7 +261,7 @@ if ($numResults == 0) { exit; } -UI::pageList($pageNumber, $totalPages, "../op/op.Search.php", $_GET); +UI::pageList($pageNumber, $resArr['totalPages'], "../op/op.Search.php", $_GET); print ""; print "\n\n"; @@ -418,30 +276,22 @@ print "\n"; print "\n\n\n"; $resultsFilteredByAccess = false; -foreach ($resArr as $docArr) { - - $document = new LetoDMS_Document( - $docArr["id"], $docArr["name"], - $docArr["comment"], $docArr["date"], - $docArr["expires"], $docArr["owner"], - $docArr["folder"], $docArr["inheritAccess"], - $docArr["defaultAccess"], $docArr["lockUser"], - $docArr["keywords"], $docArr["sequence"]); - +foreach ($resArr['docs'] as $document) { if ($document->getAccessMode($user) < M_READ) { $resultsFilteredByAccess = true; } else { + $lc = $document->getLatestContent(); print ""; //print ""; if (in_array(2, $searchin)) { - $docName = markQuery($docArr["name"], "i"); + $docName = markQuery($document->getName(), "i"); } else { - $docName = $docArr["name"]; + $docName = $document->getName(); } - print ""; - print ""; + print ""; - print ""; + print ""; - if (in_array(3, $searchin)) $comment = markQuery($docArr["comment"]); - else $comment = $docArr["comment"]; + if (in_array(3, $searchin)) $comment = markQuery($document->getComment()); + else $comment = $document->getComment(); if (strlen($comment) > 50) $comment = substr($comment, 0, 47) . "..."; print ""; - - /*print "\n"; - */ print "\n"; } } @@ -578,7 +317,7 @@ if ($resultsFilteredByAccess) { } print "
".getMLText("comment")."
/"; - $folder = getFolder($docArr["folder"]); + print "getID()."\">/"; + $folder = $document->getFolder(); $path = $folder->getPath(); for ($i = 1; $i < count($path); $i++) { print $path[$i]->getName()."/"; @@ -451,125 +301,14 @@ foreach ($resArr as $docArr) { $owner = $document->getOwner(); print "".$owner->getFullName()."".getOverallStatusText($docArr["status"]). "".getOverallStatusText($lc->getStatus()). "".$docArr["version"]."".$lc->getVersion()."".$comment.""; - if (!$db->createTemporaryTable("ttreviewid")) { - print "-"; - } - else { - $queryStr="SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, ". - "`tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, ". - "`tblDocumentReviewLog`.`userID`, `tblUsers`.`fullName`, `tblGroups`.`name` AS `groupName` ". - "FROM `tblDocumentReviewers` ". - "LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) ". - "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ". - "LEFT JOIN `tblUsers` on `tblUsers`.`id` = `tblDocumentReviewers`.`required`". - "LEFT JOIN `tblGroups` on `tblGroups`.`id` = `tblDocumentReviewers`.`required`". - "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ". - "AND `tblDocumentReviewers`.`documentID` = '". $docArr["id"] ."' ". - "AND `tblDocumentReviewers`.`version` = '". $docArr["version"] ."' "; - $rstat = $db->getResultArray($queryStr); - if (!is_bool($rstat) && count($rstat)>0) { - print "
    "; - $liFlag=false; - foreach ($rstat as $r) { - if ($r["status"]!=-2) { - print ""; - $required = null; - switch ($r["type"]) { - case 0: // Reviewer is an individual. - if (strlen($r["fullName"])==0) { - $reqName = getMLText("unknown_user").$r["required"]; - } - else { - $reqName = $r["fullName"]; - } - break; - case 1: // Reviewer is a group. - if (strlen($r["groupName"])==0) { - $reqName = getMLText("unknown_group").$r["required"]; - } - else { - $reqName = "".$r["groupName"].""; - } - break; - } - print "".$reqName.": "; - printReviewStatusText($r["status"], $r["date"]); - print ""; - $liFlag=true; - } - } - print "
"; - } - else { - print "-"; - } - } - print "
"; - if (!$db->createTemporaryTable("ttapproveid", $forceTemporaryTable)) { - print "-"; - } - else { - $queryStr="SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ". - "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ". - "`tblDocumentApproveLog`.`userID`, `tblUsers`.`fullName`, `tblGroups`.`name` AS `groupName` ". - "FROM `tblDocumentApprovers` ". - "LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ". - "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ". - "LEFT JOIN `tblUsers` on `tblUsers`.`id` = `tblDocumentApprovers`.`required`". - "LEFT JOIN `tblGroups` on `tblGroups`.`id` = `tblDocumentApprovers`.`required`". - "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ". - "AND `tblDocumentApprovers`.`documentID` = '". $docArr["id"] ."' ". - "AND `tblDocumentApprovers`.`version` = '". $docArr["version"] ."'"; - $astat = $db->getResultArray($queryStr); - if (!is_bool($astat) && count($astat)>0) { - print "
    "; - $liFlag=false; - foreach ($astat as $a) { - if ($a["status"]!=-2) { - print ""; - $required = null; - switch ($a["type"]) { - case 0: // Approver is an individual. - if (strlen($a["fullName"])==0) { - $reqName = getMLText("unknown_user").$a["required"]; - } - else { - $reqName = $a["fullName"]; - } - break; - case 1: // Approver is a group. - if (strlen($a["groupName"])==0) { - $reqName = getMLText("unknown_group").$a["required"]; - } - else { - $reqName = "".$a["groupName"].""; - } - break; - } - print "".$reqName.": "; - printApprovalStatusText($a["status"], $a["date"]); - print ""; - $liFlag=true; - } - } - print "
"; - } - else { - print "-"; - } - } - print "
\n"; -UI::pageList($pageNumber, $totalPages, "../op/op.Search.php", $_GET); +UI::pageList($pageNumber, $resArr['totalPages'], "../op/op.Search.php", $_GET); UI::contentContainerEnd(); UI::htmlEndPage();