seeddms-code/op/op.Search.php

395 lines
14 KiB
PHP
Raw Normal View History

2011-03-10 14:13:39 +00:00
<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2011 Uwe Steinmann
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include("../inc/inc.Settings.php");
include("../inc/inc.Utils.php");
2010-10-29 13:19:51 +00:00
include("../inc/inc.DBInit.php");
2011-03-10 14:13:39 +00:00
include("../inc/inc.Language.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.Authentication.php");
// Redirect to the search page if the navigation search button has been
// selected without supplying any search terms.
if (isset($_GET["navBar"])) {
if (!isset($_GET["folderid"]) || !is_numeric($_GET["folderid"]) || intval($_GET["folderid"])<1) {
$folderid=$settings->_rootFolderID;
}
else {
$folderid = $_GET["folderid"];
}
if(strlen($_GET["query"])==0) {
header("Location: ../out/out.SearchForm.php?folderid=".$folderid);
} else {
if(isset($_GET["fullsearch"]) && $_GET["fullsearch"]) {
2011-03-10 14:13:39 +00:00
header("Location: ../op/op.SearchFulltext.php?folderid=".$folderid."&query=".$_GET["query"]);
}
}
}
function getTime() {
if (function_exists('microtime')) {
$tm = microtime();
$tm = explode(' ', $tm);
return (float) sprintf('%f', $tm[1] + $tm[0]);
}
return time();
}
2010-10-29 13:19:51 +00:00
function markQuery($str, $tag = "b") {
2011-03-10 14:13:39 +00:00
GLOBAL $query;
$querywords = preg_split("/ /", $query);
foreach ($querywords as $queryword)
$str = str_ireplace("($queryword)", "<" . $tag . ">\\1</" . $tag . ">", $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 = $_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
2012-10-09 09:59:25 +00:00
case 4: // attributes
$searchin[$si] = $si;
break;
}
}
}
2010-10-29 13:19:51 +00:00
}
// if none is checkd search all
2012-10-09 09:59:25 +00:00
if (count($searchin)==0) $searchin=array( 0, 1, 2, 3, 4);
2010-10-29 13:19:51 +00:00
// 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 = $dms->getFolder($targetid);
}
else {
$targetid = $settings->_rootFolderID;
$startFolder = $dms->getFolder($targetid);
}
2010-10-29 13:19:51 +00:00
if (!is_object($startFolder)) {
UI::exitError(getMLText("search_results"),getMLText("invalid_folder_id"));
2010-10-29 13:19:51 +00:00
}
// 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 = $dms->getUser($_GET["ownerid"]);
if (!is_object($owner)) {
UI::htmlStartPage(getMLText("search_results"));
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) {
2013-01-24 10:13:08 +00:00
if(isset($_GET["createstart"])) {
$tmp = explode("-", $_GET["createstart"]);
$startdate = array('year'=>(int)$tmp[2], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[0], 'hour'=>0, 'minute'=>0, 'second'=>0);
} else {
$startdate = array('year'=>$_GET["createstartyear"], 'month'=>$_GET["createstartmonth"], 'day'=>$_GET["createstartday"], 'hour'=>0, 'minute'=>0, 'second'=>0);
}
if (!checkdate($startdate['month'], $startdate['day'], $startdate['year'])) {
UI::htmlStartPage(getMLText("search_results"));
UI::contentContainer(getMLText("invalid_create_date_start"));
UI::htmlEndPage();
exit;
}
2013-01-24 10:13:08 +00:00
if(isset($_GET["createend"])) {
$tmp = explode("-", $_GET["createend"]);
$stopdate = array('year'=>(int)$tmp[2], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[0], 'hour'=>0, 'minute'=>0, 'second'=>0);
} else {
$stopdate = array('year'=>$_GET["createendyear"], 'month'=>$_GET["createendmonth"], 'day'=>$_GET["createendday"], 'hour'=>23, 'minute'=>59, 'second'=>59);
}
if (!checkdate($stopdate['month'], $stopdate['day'], $stopdate['year'])) {
UI::htmlStartPage(getMLText("search_results"));
UI::contentContainer(getMLText("invalid_create_date_end"));
UI::htmlEndPage();
exit;
}
2010-10-29 13:19:51 +00:00
}
2013-01-24 10:13:08 +00:00
$expstartdate = array();
$expstopdate = array();
if (isset($_GET["expirationdate"]) && $_GET["expirationdate"]!=null) {
if(isset($_GET["expirationstart"]) && $_GET["expirationstart"]) {
$tmp = explode("-", $_GET["expirationstart"]);
$expstartdate = array('year'=>(int)$tmp[2], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[0], 'hour'=>0, 'minute'=>0, 'second'=>0);
if (!checkdate($expstartdate['month'], $expstartdate['day'], $expstartdate['year'])) {
UI::exitError(getMLText("search"),getMLText("invalid_expiration_date_start"));
}
} else {
$expstartdate = array('year'=>$_GET["expirationstartyear"], 'month'=>$_GET["expirationstartmonth"], 'day'=>$_GET["expirationstartday"], 'hour'=>0, 'minute'=>0, 'second'=>0);
$expstartdate = array();
}
if(isset($_GET["expirationend"]) && $_GET["expirationend"]) {
$tmp = explode("-", $_GET["expirationend"]);
$expstopdate = array('year'=>(int)$tmp[2], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[0], 'hour'=>0, 'minute'=>0, 'second'=>0);
if (!checkdate($expstopdate['month'], $expstopdate['day'], $expstopdate['year'])) {
UI::exitError(getMLText("search"),getMLText("invalid_expiration_date_end"));
}
} else {
$expstopdate = array('year'=>$_GET["expirationendyear"], 'month'=>$_GET["expirationendmonth"], 'day'=>$_GET["expirationendday"], 'hour'=>23, 'minute'=>59, 'second'=>59);
$expstopdate = array();
}
}
2010-10-29 13:19:51 +00:00
// status
$status = array();
2010-10-29 13:19:51 +00:00
if (isset($_GET["pendingReview"])){
$status[] = S_DRAFT_REV;
2010-10-29 13:19:51 +00:00
}
if (isset($_GET["pendingApproval"])){
$status[] = S_DRAFT_APP;
2010-10-29 13:19:51 +00:00
}
2013-01-24 10:13:08 +00:00
if (isset($_GET["inWorkflow"])){
$status[] = S_IN_WORKFLOW;
}
2010-10-29 13:19:51 +00:00
if (isset($_GET["released"])){
$status[] = S_RELEASED;
2010-10-29 13:19:51 +00:00
}
if (isset($_GET["rejected"])){
$status[] = S_REJECTED;
2010-10-29 13:19:51 +00:00
}
if (isset($_GET["obsolete"])){
$status[] = S_OBSOLETE;
2010-10-29 13:19:51 +00:00
}
if (isset($_GET["expired"])){
$status[] = S_EXPIRED;
2010-10-29 13:19:51 +00:00
}
2011-03-10 14:13:39 +00:00
// category
$categories = array();
if(isset($_GET['categoryids']) && $_GET['categoryids']) {
foreach($_GET['categoryids'] as $catid) {
if($catid > 0)
$categories[] = $dms->getDocumentCategory($catid);
2011-03-10 14:13:39 +00:00
}
}
2012-10-09 09:59:25 +00:00
if (isset($_GET["attributes"]))
$attributes = $_GET["attributes"];
else
$attributes = array();
//
// 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;
2013-01-24 10:13:08 +00:00
$limit = 15;
if (isset($_GET["pg"])) {
if (is_numeric($_GET["pg"]) && $_GET["pg"]>0) {
$pageNumber = (int) $_GET["pg"];
}
elseif (!strcasecmp($_GET["pg"], "all")) {
$limit = 0;
}
2010-10-29 13:19:51 +00:00
}
// ---------------- Start searching -----------------------------------------
$startTime = getTime();
2013-01-24 10:13:08 +00:00
$resArr = $dms->search($query, $limit, ($pageNumber-1)*$limit, $mode, $searchin, $startFolder, $owner, $status, $startdate, $stopdate, array(), array(), $categories, $attributes, 0x03, $expstartdate, $expstopdate);
2011-03-10 14:13:39 +00:00
$searchTime = getTime() - $startTime;
$searchTime = round($searchTime, 2);
$entries = array();
if($resArr['folders']) {
foreach ($resArr['folders'] as $entry) {
if ($entry->getAccessMode($user) >= M_READ) {
$entries[] = $entry;
}
}
2011-03-10 14:13:39 +00:00
}
if($resArr['docs']) {
foreach ($resArr['docs'] as $entry) {
if ($entry->getAccessMode($user) >= M_READ) {
$entries[] = $entry;
}
}
2011-03-10 14:13:39 +00:00
}
// -------------- Output results --------------------------------------------
2011-03-10 14:13:39 +00:00
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
$view = UI::factory($theme, $tmp[1], array('dms'=>$dms, 'user'=>$user, 'folder'=>$startFolder, 'searchhits'=>$entries, 'totalpages'=>$resArr['totalPages'], 'pagenumber'=>$pageNumber, 'searchtime'=>$searchTime, 'urlparams'=>$_GET, 'searchin'=>$searchin));
if($view) {
$view->show();
exit;
}
// Now that the target folder has been identified, it is possible to create
// the full navigation bar.
UI::htmlStartPage(getMLText("search_results"));
UI::globalNavigation($startFolder);
UI::pageNavigation(getFolderPathHTML($startFolder, true), "", $startFolder);
UI::contentHeading(getMLText("search_results"));
UI::contentContainerStart();
UI::pageList($pageNumber, $resArr['totalPages'], "../op/op.Search.php", $_GET);
2011-03-10 14:13:39 +00:00
print "<table class=\"folderView\">";
print "<thead>\n<tr>\n";
2011-11-29 07:19:25 +00:00
print "<th></th>\n";
2011-03-10 14:13:39 +00:00
print "<th>".getMLText("name")."</th>\n";
2012-10-09 09:59:25 +00:00
print "<th>".getMLText("attributes")."</th>\n";
2011-03-10 14:13:39 +00:00
print "<th>".getMLText("owner")."</th>\n";
print "<th>".getMLText("status")."</th>\n";
print "<th>".getMLText("version")."</th>\n";
print "<th>".getMLText("comment")."</th>\n";
//print "<th>".getMLText("reviewers")."</th>\n";
//print "<th>".getMLText("approvers")."</th>\n";
2010-10-29 13:19:51 +00:00
print "</tr>\n</thead>\n<tbody>\n";
2011-03-10 14:13:39 +00:00
$resultsFilteredByAccess = false;
$foldercount = $doccount = 0;
2011-11-29 07:19:25 +00:00
foreach ($entries as $entry) {
if(get_class($entry) == 'LetoDMS_Core_Document') {
$document = $entry;
$doccount++;
2011-11-29 07:19:25 +00:00
$lc = $document->getLatestContent();
print "<tr>";
//print "<td><img src=\"../out/images/file.gif\" class=\"mimeicon\"></td>";
if (in_array(2, $searchin)) {
2012-09-05 20:59:12 +00:00
$docName = markQuery(htmlspecialchars($document->getName()), "i");
2011-11-29 07:19:25 +00:00
} else {
2012-09-05 20:59:12 +00:00
$docName = htmlspecialchars($document->getName());
2011-11-29 07:19:25 +00:00
}
print "<td><a class=\"standardText\" href=\"../out/out.ViewDocument.php?documentid=".$document->getID()."\"><img class=\"mimeicon\" src=\"../out/images/icons/".UI::getMimeIcon($lc->getFileType())."\" title=\"".$lc->getMimeType()."\"></a></td>";
print "<td><a class=\"standardText\" href=\"../out/out.ViewDocument.php?documentid=".$document->getID()."\">/";
$folder = $document->getFolder();
$path = $folder->getPath();
for ($i = 1; $i < count($path); $i++) {
2012-09-05 20:59:12 +00:00
print htmlspecialchars($path[$i]->getName())."/";
2011-11-29 07:19:25 +00:00
}
print $docName;
print "</a></td>";
2012-10-09 09:59:25 +00:00
$attributes = $lc->getAttributes();
print "<td>";
print "<ul class=\"documentDetail\">\n";
$attributes = $lc->getAttributes();
if($attributes) {
foreach($attributes as $attribute) {
$attrdef = $attribute->getAttributeDefinition();
print "<li>".htmlspecialchars($attrdef->getName()).": ".htmlspecialchars($attribute->getValue())."</li>\n";
}
}
print "</ul>\n";
print "</td>";
2011-11-29 07:19:25 +00:00
$owner = $document->getOwner();
2012-09-05 20:59:12 +00:00
print "<td>".htmlspecialchars($owner->getFullName())."</td>";
2011-11-29 07:19:25 +00:00
$display_status=$lc->getStatus();
print "<td>".getOverallStatusText($display_status["status"]). "</td>";
print "<td class=\"center\">".$lc->getVersion()."</td>";
2012-09-05 20:59:12 +00:00
if (in_array(3, $searchin)) $comment = markQuery(htmlspecialchars($document->getComment()));
else $comment = htmlspecialchars($document->getComment());
2011-11-29 07:19:25 +00:00
if (strlen($comment) > 50) $comment = substr($comment, 0, 47) . "...";
print "<td>".$comment."</td>";
print "</tr>\n";
} elseif(get_class($entry) == 'LetoDMS_Core_Folder') {
$folder = $entry;
$foldercount++;
2011-11-29 07:19:25 +00:00
if (in_array(2, $searchin)) {
2012-09-05 20:59:12 +00:00
$folderName = markQuery(htmlspecialchars($folder->getName()), "i");
2011-11-29 07:19:25 +00:00
} else {
2012-09-05 20:59:12 +00:00
$folderName = htmlspecialchars($folder->getName());
2011-11-29 07:19:25 +00:00
}
print "<td><a class=\"standardText\" href=\"../out/out.ViewFolder.php?folderid=".$folder->getID()."\"><img src=\"../out/images/folder_closed.gif\" width=18 height=18 border=0></a></td>";
print "<td><a class=\"standardText\" href=\"../out/out.ViewFolder.php?folderid=".$folder->getID()."\">";
$path = $folder->getPath();
2012-10-09 09:59:25 +00:00
print "/";
for ($i = 1; $i < count($path)-1; $i++) {
print htmlspecialchars($path[$i]->getName())."/";
2011-11-29 07:19:25 +00:00
}
2012-09-13 13:56:59 +00:00
print $folderName;
2011-11-29 07:19:25 +00:00
print "</a></td>";
2012-10-09 09:59:25 +00:00
print "<td></td>";
2011-11-29 07:19:25 +00:00
$owner = $folder->getOwner();
2012-09-05 20:59:12 +00:00
print "<td>".htmlspecialchars($owner->getFullName())."</td>";
2011-11-29 07:19:25 +00:00
print "<td></td>";
print "<td></td>";
2012-09-05 20:59:12 +00:00
if (in_array(3, $searchin)) $comment = markQuery(htmlspecialchars($folder->getComment()));
else $comment = htmlspecialchars($folder->getComment());
2011-11-29 07:19:25 +00:00
if (strlen($comment) > 50) $comment = substr($comment, 0, 47) . "...";
print "<td>".$comment."</td>";
print "</tr>\n";
2011-03-10 14:13:39 +00:00
}
}
if (0 && $resultsFilteredByAccess) {
2011-03-10 14:13:39 +00:00
print "<tr><td colspan=\"7\">". getMLText("search_results_access_filtered") . "</td></tr>";
}
2011-03-10 14:13:39 +00:00
print "</tbody></table>\n";
$numResults = $doccount + $foldercount;
if ($numResults == 0) {
print "<p>".getMLText("search_no_results")."</p>";
} else {
// print "<p>".getMLText("search_report", array("doccount" => $doccount, "foldercount" => $foldercount, 'searchtime'=>$searchTime))."</p>";
}
2011-03-10 14:13:39 +00:00
UI::pageList($pageNumber, $resArr['totalPages'], "../op/op.Search.php", $_GET);
UI::contentContainerEnd();
UI::htmlEndPage();
?>