From edd60363f363abc45828632ab9dacee5a8275467 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 5 May 2021 13:43:40 +0200 Subject: [PATCH 1/4] return false if query fails --- SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php index 2eb15428b..cc5b39119 100644 --- a/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php +++ b/SeedDMS_SQLiteFTS/SQLiteFTS/Indexer.php @@ -175,6 +175,8 @@ class SeedDMS_SQLiteFTS_Indexer { if($query) $sql .= " WHERE docs MATCH ".$this->_conn->quote($query); $res = $this->_conn->query($sql); + if(!$res) + return false; $row = $res->fetch(); $sql = "SELECT ".$this->_rawid.", documentid FROM docs"; From 1e08ea06e9c0acf487ac31c4d451719ccb879e6e Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 5 May 2021 13:44:02 +0200 Subject: [PATCH 2/4] add missing ' AND ' in query string --- SeedDMS_SQLiteFTS/SQLiteFTS/Search.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/SeedDMS_SQLiteFTS/SQLiteFTS/Search.php b/SeedDMS_SQLiteFTS/SQLiteFTS/Search.php index 78b5ed86c..77b3993f6 100644 --- a/SeedDMS_SQLiteFTS/SQLiteFTS/Search.php +++ b/SeedDMS_SQLiteFTS/SQLiteFTS/Search.php @@ -79,11 +79,11 @@ class SeedDMS_SQliteFTS_Search { if(!empty($fields['owner'])) { if(is_string($fields['owner'])) { if($querystr) - $querystr .= ' '; + $querystr .= ' AND '; $querystr .= 'owner:'.$fields['owner']; } elseif(is_array($fields['owner'])) { if($querystr) - $querystr .= ' '; + $querystr .= ' AND '; $querystr .= '(owner:'; $querystr .= implode(' OR owner:', $fields['owner']); $querystr .= ')'; @@ -91,14 +91,14 @@ class SeedDMS_SQliteFTS_Search { } if(!empty($fields['category'])) { if($querystr) - $querystr .= ' '; + $querystr .= ' AND '; $querystr .= '(category:'; $querystr .= implode(' OR category:', $fields['category']); $querystr .= ')'; } if(!empty($fields['status'])) { if($querystr) - $querystr .= ' '; + $querystr .= ' AND '; $status = array_map(function($v){return $v+10;}, $fields['status']); $querystr .= '(status:'; $querystr .= implode(' OR status:', $status); @@ -106,21 +106,21 @@ class SeedDMS_SQliteFTS_Search { } if(!empty($fields['user'])) { if($querystr) - $querystr .= ' '; + $querystr .= ' AND '; $querystr .= '(users:'; $querystr .= implode(' OR users:', $fields['user']); $querystr .= ')'; } if(!empty($fields['rootFolder']) && $fields['rootFolder']->getFolderList()) { if($querystr) - $querystr .= ' '; + $querystr .= ' AND '; $querystr .= '(path:'; $querystr .= str_replace(':', 'x', $fields['rootFolder']->getFolderList().$fields['rootFolder']->getID().':'); $querystr .= ')'; } if(!empty($fields['startFolder']) && $fields['startFolder']->getFolderList()) { if($querystr) - $querystr .= ' '; + $querystr .= ' AND '; $querystr .= '(path:'; $querystr .= str_replace(':', 'x', $fields['startFolder']->getFolderList().$fields['startFolder']->getID().':'); $querystr .= ')'; From 805dbe212ade0440427676f37861837a86032fa7 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 5 May 2021 13:46:05 +0200 Subject: [PATCH 3/4] fix html for date picker and accordion --- views/bootstrap4/class.Bootstrap4.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/views/bootstrap4/class.Bootstrap4.php b/views/bootstrap4/class.Bootstrap4.php index d8209cf9a..1a181e7f3 100644 --- a/views/bootstrap4/class.Bootstrap4.php +++ b/views/bootstrap4/class.Bootstrap4.php @@ -1366,7 +1366,7 @@ $(document).ready(function() { $dateformat = getConvertDateFormat(); $content = '
- +
@@ -1743,7 +1743,7 @@ $(document).ready(function() { */ $content = '
- +
@@ -3527,13 +3527,13 @@ $("body").on("click", "span.openpopupbox", function(e) { ?>
-
- + -
-
+
+
From e870e2071b9131a32ab3c4d091a2ef4c0c3bb539 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 5 May 2021 13:47:38 +0200 Subject: [PATCH 4/4] redo the search form --- out/out.Search.php | 189 ++++------- views/bootstrap/class.Search.php | 559 ++++++++++++++----------------- 2 files changed, 313 insertions(+), 435 deletions(-) diff --git a/out/out.Search.php b/out/out.Search.php index d34d3b572..1b0b00e41 100644 --- a/out/out.Search.php +++ b/out/out.Search.php @@ -64,15 +64,7 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext $categories = array(); $categorynames = array(); if(isset($_GET['category']) && $_GET['category']) { - foreach($_GET['category'] as $catname) { - if($catname) { - $cat = $dms->getDocumentCategoryByName($catname); - $categories[] = $cat; - $categorynames[] = $cat->getName(); - } - } - } elseif(isset($_GET['categoryids']) && $_GET['categoryids']) { - foreach($_GET['categoryids'] as $catid) { + foreach($_GET['category'] as $catid) { if($catid) { $cat = $dms->getDocumentCategory($catid); $categories[] = $cat; @@ -104,16 +96,18 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext // Check to see if the search has been restricted to a particular // document owner. $owner = []; + $ownernames = []; if (isset($_GET["owner"])) { + $owner = $_GET['owner']; if (!is_array($_GET['owner'])) { - if(!empty($_GET['owner']) && $o = $dms->getUserByLogin($_GET['owner'])) - $owner[] = $o->getLogin(); + if(!empty($_GET['owner']) && $o = $dms->getUser($_GET['owner'])) + $ownernames[] = $o->getLogin(); else UI::exitError(getMLText("search"),getMLText("unknown_owner")); } else { foreach($_GET["owner"] as $l) { - if($l && $o = $dms->getUserByLogin($l)) - $owner[] = $o->getLogin(); + if($l && $o = $dms->getUser($l)) + $ownernames[] = $o->getLogin(); } } } @@ -134,34 +128,16 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext } // status - $status = array(); - if (isset($_GET["pendingReview"])){ - $status[] = S_DRAFT_REV; - } - if (isset($_GET["pendingApproval"])){ - $status[] = S_DRAFT_APP; - } - if (isset($_GET["inWorkflow"])){ - $status[] = S_IN_WORKFLOW; - } - if (isset($_GET["released"])){ - $status[] = S_RELEASED; - } - if (isset($_GET["rejected"])){ - $status[] = S_REJECTED; - } - if (isset($_GET["obsolete"])){ - $status[] = S_OBSOLETE; - } - if (isset($_GET["expired"])){ - $status[] = S_EXPIRED; - } + if(isset($_GET['status'])) + $status = $_GET['status']; + else + $status = array(); // Check to see if the search has been restricted to a particular sub-tree in // the folder hierarchy. $startFolder = null; - if (isset($_GET["targetid"]) && is_numeric($_GET["targetid"]) && $_GET["targetid"]>0) { - $targetid = $_GET["targetid"]; + if (isset($_GET["folderfullsearchid"]) && is_numeric($_GET["folderfullsearchid"]) && $_GET["folderfullsearchid"]>0) { + $targetid = $_GET["folderfullsearchid"]; $startFolder = $dms->getFolder($targetid); if (!is_object($startFolder)) { UI::exitError(getMLText("search"),getMLText("invalid_folder_id")); @@ -188,7 +164,7 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext $index = $fulltextservice->Indexer(); if($index) { $lucenesearch = $fulltextservice->Search(); - $searchresult = $lucenesearch->search($query, array('owner'=>$owner, 'status'=>$status, 'category'=>$categorynames, 'user'=>$user->isAdmin() ? [] : [$user->getLogin()], 'mimetype'=>$mimetype, 'startFolder'=>$startFolder, 'rootFolder'=>$rootFolder), ($pageNumber == 'all' ? array() : array('limit'=>$limit, 'offset'=>$limit * ($pageNumber-1)))); + $searchresult = $lucenesearch->search($query, array('owner'=>$ownernames, 'status'=>$status, 'category'=>$categorynames, 'user'=>$user->isAdmin() ? [] : [$user->getLogin()], 'mimetype'=>$mimetype, 'startFolder'=>$startFolder, 'rootFolder'=>$rootFolder), ($pageNumber == 'all' ? array() : array('limit'=>$limit, 'offset'=>$limit * ($pageNumber-1)))); if($searchresult === false) { $session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_invalid_searchterm'))); $dcount = 0; @@ -313,105 +289,81 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext $owner = array(); $ownerobjs = array(); if (isset($_GET["owner"])) { + $owner = $_GET['owner']; if (!is_array($_GET['owner'])) { - if(!empty($_GET['owner']) && $o = $dms->getUserByLogin($_GET['owner'])) { + if(!empty($_GET['owner']) && $o = $dms->getUser($_GET['owner'])) { $ownerobjs[] = $o; - $owner = $o->getLogin(); } else UI::exitError(getMLText("search"),getMLText("unknown_owner")); } else { foreach($_GET["owner"] as $l) { - if($o = $dms->getUserByLogin($l)) { + if($o = $dms->getUser($l)) { $ownerobjs[] = $o; - $owner[] = $o->getLogin(); } } } } - // Is the search restricted to documents created between two specific dates? - $startdate = array(); - $stopdate = array(); - if (isset($_GET["creationdate"]) && $_GET["creationdate"]!=null) { - $creationdate = true; - } else { - $creationdate = false; + /* Creation date {{{ */ + $createstartdate = array(); + $createenddate = array(); + if(!empty($_GET["createstart"])) { + $createstartts = makeTsFromDate($_GET["createstart"]); + $createstartdate = array('year'=>(int)date('Y', $createstartts), 'month'=>(int)date('m', $createstartts), 'day'=>(int)date('d', $createstartts), 'hour'=>0, 'minute'=>0, 'second'=>0); } - - if(isset($_GET["createstart"])) { - $tmp = explode("-", $_GET["createstart"]); - $startdate = array('year'=>(int)$tmp[0], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[2], 'hour'=>0, 'minute'=>0, 'second'=>0); - } else { - if(isset($_GET["createstartyear"])) - $startdate = array('year'=>$_GET["createstartyear"], 'month'=>$_GET["createstartmonth"], 'day'=>$_GET["createstartday"], 'hour'=>0, 'minute'=>0, 'second'=>0); - } - if ($startdate && !checkdate($startdate['month'], $startdate['day'], $startdate['year'])) { + if ($createstartdate && !checkdate($createstartdate['month'], $createstartdate['day'], $createstartdate['year'])) { UI::exitError(getMLText("search"),getMLText("invalid_create_date_end")); } - if(isset($_GET["createend"])) { - $tmp = explode("-", $_GET["createend"]); - $stopdate = array('year'=>(int)$tmp[0], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[2], 'hour'=>23, 'minute'=>59, 'second'=>59); - } else { - if(isset($_GET["createendyear"])) - $stopdate = array('year'=>$_GET["createendyear"], 'month'=>$_GET["createendmonth"], 'day'=>$_GET["createendday"], 'hour'=>23, 'minute'=>59, 'second'=>59); + if(!empty($_GET["createend"])) { + $createendts = makeTsFromDate($_GET["createend"]); + $createenddate = array('year'=>(int)date('Y', $createendts), 'month'=>(int)date('m', $createendts), 'day'=>(int)date('d', $createendts), 'hour'=>23, 'minute'=>59, 'second'=>59); } - if ($stopdate && !checkdate($stopdate['month'], $stopdate['day'], $stopdate['year'])) { + if ($createenddate && !checkdate($createenddate['month'], $createenddate['day'], $createenddate['year'])) { UI::exitError(getMLText("search"),getMLText("invalid_create_date_end")); } + /* }}} */ + /* Status date {{{ */ $statusstartdate = array(); - $statusstopdate = array(); - if (isset($_GET["statusdate"]) && $_GET["statusdate"]!=null) { - $statusdate = true; - } else { - $statusdate = false; + $statusenddate = array(); + if(!empty($_GET["statusdatestart"])) { + $statusstartts = makeTsFromDate($_GET["statusdatestart"]); + $statusstartdate = array('year'=>(int)date('Y', $statusstartts), 'month'=>(int)date('m', $statusstartts), 'day'=>(int)date('d', $statusstartts), 'hour'=>0, 'minute'=>0, 'second'=>0); } - - if(isset($_GET["statusstart"])) { - $tmp = explode("-", $_GET["statusstart"]); - $statusstartdate = array('year'=>(int)$tmp[0], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[2], 'hour'=>0, 'minute'=>0, 'second'=>0); + if ($statusstartdate && !checkdate($statusstartdate['month'], $statusstartdate['day'], $statusstartdate['year'])) { + UI::exitError(getMLText("search"),getMLText("invalid_status_date_start")); } - if ($statusstartdate && !checkdate($statusstartdate['month'], $startdate['day'], $startdate['year'])) { - UI::exitError(getMLText("search"),getMLText("invalid_status_date_end")); - } - if(isset($_GET["statusend"])) { - $tmp = explode("-", $_GET["statusend"]); - $statusstopdate = array('year'=>(int)$tmp[0], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[2], 'hour'=>23, 'minute'=>59, 'second'=>59); - } - if ($statusstopdate && !checkdate($statusstopdate['month'], $stopdate['day'], $stopdate['year'])) { + if(!empty($_GET["statusdateend"])) { + $statusendts = makeTsFromDate($_GET["statusdateend"]); + $statusenddate = array('year'=>(int)date('Y', $statusendts), 'month'=>(int)date('m', $statusendts), 'day'=>(int)date('d', $statusendts), 'hour'=>23, 'minute'=>59, 'second'=>59); + } + if ($statusenddate && !checkdate($statusenddate['month'], $statusenddate['day'], $statusenddate['year'])) { UI::exitError(getMLText("search"),getMLText("invalid_status_date_end")); } + /* }}} */ + /* Expiration date {{{ */ $expstartdate = array(); - $expstopdate = array(); - if (isset($_GET["expirationdate"]) && $_GET["expirationdate"]!=null) { - $expirationdate = true; - } else { - $expirationdate = false; - } - - if(isset($_GET["expirationstart"]) && $_GET["expirationstart"]) { - $tmp = explode("-", $_GET["expirationstart"]); - $expstartdate = array('year'=>(int)$tmp[0], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[2], 'hour'=>0, 'minute'=>0, 'second'=>0); + $expenddate = array(); + if(!empty($_GET["expirationstart"])) { + $expstartts = makeTsFromDate($_GET["expirationstart"]); + $expstartdate = array('year'=>(int)date('Y', $expstartts), 'month'=>(int)date('m', $expstartts), 'day'=>(int)date('d', $expstartts), '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[0], 'month'=>(int)$tmp[1], 'day'=>(int)$tmp[2], 'hour'=>0, 'minute'=>0, 'second'=>0); - if (!checkdate($expstopdate['month'], $expstopdate['day'], $expstopdate['year'])) { + if(!empty($_GET["expirationend"])) { + $expendts = makeTsFromDate($_GET["expirationend"]); + $expenddate = array('year'=>(int)date('Y', $expendts), 'month'=>(int)date('m', $expendts), 'day'=>(int)date('d', $expendts), 'hour'=>23, 'minute'=>59, 'second'=>59); + if (!checkdate($expenddate['month'], $expenddate['day'], $expenddate['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(); } + /* }}} */ // status + $status = isset($_GET['status']) ? $_GET['status'] : array(); + /* $status = array(); if (isset($_GET["pendingReview"])){ $status[] = S_DRAFT_REV; @@ -434,6 +386,7 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext if (isset($_GET["expired"])){ $status[] = S_EXPIRED; } + */ /* Do not search for folders if result shall be filtered by status. * If this is not done, unexplainable results will be delivered. @@ -446,13 +399,10 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext // category $categories = array(); - $categorynames = array(); if(isset($_GET['category']) && $_GET['category']) { - foreach($_GET['category'] as $catname) { - if($catname) { - $cat = $dms->getDocumentCategoryByName($catname); + foreach($_GET['category'] as $catid) { + if($cat = $dms->getDocumentCategory($catid)) { $categories[] = $cat; - $categorynames[] = $cat->getName(); } } } @@ -513,17 +463,17 @@ if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext 'startFolder'=>$startFolder, 'owner'=>$ownerobjs, 'status'=>$status, - 'creationstartdate'=>$creationdate ? $startdate : array(), - 'creationenddate'=>$creationdate ? $stopdate : array(), + 'creationstartdate'=>$createstartdate ? $createstartdate : array(), + 'creationenddate'=>$createenddate ? $createenddate : array(), 'modificationstartdate'=>array(), 'modificationenddate'=>array(), 'categories'=>$categories, 'attributes'=>$attributes, 'mode'=>$resultmode, - 'expirationstartdate'=>$expirationdate ? $expstartdate : array(), - 'expirationenddate'=>$expirationdate ? $expstopdate : array(), - 'statusstartdate'=>$statusdate ? $statusstartdate : array(), - 'statusenddate'=>$statusdate ? $statusstopdate : array(), + 'expirationstartdate'=>$expstartdate ? $expstartdate : array(), + 'expirationenddate'=>$expenddate ? $expenddate : array(), + 'statusstartdate'=>$statusstartdate ? $statusstartdate : array(), + 'statusenddate'=>$statusenddate ? $statusenddate : array(), 'orderby'=>$orderby )); $total = $resArr['totalDocs'] + $resArr['totalFolders']; @@ -593,18 +543,17 @@ if($settings->_showSingleSearchHit && count($entries) == 1) { $view->setParam('searchin', isset($searchin) ? $searchin : array()); $view->setParam('startfolder', isset($startFolder) ? $startFolder : null); $view->setParam('owner', $owner); - $view->setParam('startdate', isset($startdate) ? $startdate : array()); - $view->setParam('stopdate', isset($stopdate) ? $stopdate : array()); - $view->setParam('expstartdate', isset($expstartdate) ? $expstartdate : array()); - $view->setParam('expstopdate', isset($expstopdate) ? $expstopdate : array()); - $view->setParam('statusstartdate', isset($statusstartdate) ? $statusstartdate : array()); - $view->setParam('statusstopdate', isset($statusstopdate) ? $statusstopdate : array()); + $view->setParam('createstartdate', $createstartdate ? getReadableDate($createstartts) : ''); + $view->setParam('createenddate', $createenddate ? getReadableDate($createendts) : ''); + $view->setParam('expstartdate', $expstartdate ? getReadableDate($expstartts) : ''); + $view->setParam('expenddate', $expenddate ? getReadableDate($expendts) : ''); + $view->setParam('statusstartdate', $statusstartdate ? getReadableDate($statusstartts) : ''); + $view->setParam('statusenddate', $statusenddate ? getReadableDate($statusendts) : ''); $view->setParam('creationdate', isset($creationdate) ? $creationdate : ''); $view->setParam('expirationdate', isset($expirationdate) ? $expirationdate: ''); $view->setParam('statusdate', isset($statusdate) ? $statusdate: ''); $view->setParam('status', isset($status) ? $status : array()); $view->setParam('categories', isset($categories) ? $categories : ''); - $view->setParam('category', isset($categorynames) ? $categorynames : ''); $view->setParam('mimetype', isset($mimetype) ? $mimetype : ''); $view->setParam('attributes', isset($attributes) ? $attributes : ''); $attrdefs = $dms->getAllAttributeDefinitions(array(SeedDMS_Core_AttributeDefinition::objtype_document, SeedDMS_Core_AttributeDefinition::objtype_documentcontent, SeedDMS_Core_AttributeDefinition::objtype_folder, SeedDMS_Core_AttributeDefinition::objtype_all)); diff --git a/views/bootstrap/class.Search.php b/views/bootstrap/class.Search.php index f36c870ef..01ff9bcb0 100644 --- a/views/bootstrap/class.Search.php +++ b/views/bootstrap/class.Search.php @@ -132,17 +132,16 @@ function typeahead() { /* {{{ */ $enablefullsearch = $this->params['enablefullsearch']; $enableclipboard = $this->params['enableclipboard']; $attributes = $this->params['attributes']; - $category = $this->params['category']; $categories = $this->params['categories']; $mimetype = $this->params['mimetype']; $owner = $this->params['owner']; $startfolder = $this->params['startfolder']; - $startdate = $this->params['startdate']; - $stopdate = $this->params['stopdate']; + $createstartdate = $this->params['createstartdate']; + $createenddate = $this->params['createenddate']; $expstartdate = $this->params['expstartdate']; - $expstopdate = $this->params['expstopdate']; + $expenddate = $this->params['expenddate']; $statusstartdate = $this->params['statusstartdate']; - $statusstopdate = $this->params['statusstopdate']; + $statusenddate = $this->params['statusenddate']; $creationdate = $this->params['creationdate']; $expirationdate = $this->params['expirationdate']; $statusdate = $this->params['statusdate']; @@ -161,8 +160,6 @@ function typeahead() { /* {{{ */ $timeout = $this->params['timeout']; $xsendfile = $this->params['xsendfile']; - $this->htmlAddHeader(''."\n", 'js'); - $this->htmlStartPage(getMLText("search_results")); $this->globalNavigation(); $this->contentStart(); @@ -172,7 +169,7 @@ function typeahead() { /* {{{ */ $this->columnStart(4); //echo "
";print_r($_GET);echo "
"; ?> -