From 857f5e549dbc38e305d33dbb00214795fdb871b9 Mon Sep 17 00:00:00 2001 From: SJ Date: Tue, 16 May 2017 21:47:24 +0200 Subject: [PATCH] gui: folder search improvements Change-Id: Ia098c7c2efcb9011e706012ee074e0c354bebded Signed-off-by: SJ --- webui/controller/search/folder.php | 5 +- webui/model/search/search.php | 104 ++++++------------ .../default/assets/css/metro-bootstrap.css | 2 +- .../theme/default/templates/search/folder.tpl | 42 +------ 4 files changed, 38 insertions(+), 115 deletions(-) diff --git a/webui/controller/search/folder.php b/webui/controller/search/folder.php index a19b36a2..b9483e40 100644 --- a/webui/controller/search/folder.php +++ b/webui/controller/search/folder.php @@ -14,10 +14,7 @@ class ControllerSearchFolder extends Controller { $this->load->model('folder/folder'); - $this->data['extra_folders'] = $this->model_folder_folder->get_folders_for_user(); - array_unshift($this->data['extra_folders'], array('id' => 0, 'name' => '---')); - - $this->data['folders_by_hier'] = $this->model_folder_folder->get_all_folder_ids_hier($session->get("uid")); + $this->data['folders'] = $session->get("folders"); $this->render(); } diff --git a/webui/model/search/search.php b/webui/model/search/search.php index a3513b5d..7eca2f31 100644 --- a/webui/model/search/search.php +++ b/webui/model/search/search.php @@ -81,8 +81,6 @@ class ModelSearchSearch extends Model { else { return ""; } } - if(ENABLE_FOLDER_RESTRICTIONS == 1) { return ""; } - $all_your_addresses = $this->get_all_your_address(); return " (@from $all_your_addresses | @to $all_your_addresses) "; } @@ -90,9 +88,9 @@ class ModelSearchSearch extends Model { private function get_results($data = array(), $sort = 'sent', $order = 'DESC', $sortorder = '', $page = 0) { $ids = array(); - $__folders = array(); + $folders = $search_folders = array(); $match = ''; - $direction = $attachment = $size = $folders = ''; + $direction = $attachment = $size = ''; $tag_id_list = ''; $a = ""; $id = ""; @@ -190,19 +188,14 @@ class ModelSearchSearch extends Model { if(ENABLE_FOLDER_RESTRICTIONS == 1) { + $folders = $session->get("folders"); + $s = explode(" ", $data['folders']); while(list($k,$v) = each($s)) { - if(in_array($v, $session->get("folders"))) { - array_push($__folders, $v); + if(in_array($v, $folders)) { + array_push($search_folders, $v); } } - - if(count($__folders) > 0) { - $folders = "folder IN (" . implode(",", $__folders) . ") AND "; - } - else { - $folders = "folder IN (" . implode(",", $session->get("folders")) . ") AND "; - } } @@ -216,16 +209,8 @@ class ModelSearchSearch extends Model { $total_found = $query->total_found; $num_rows = $query->num_rows; } - else if(isset($data['folder']) && $data['folder']) { - $folder_id = -1; - - $folders = $session->get("folders"); - - $data['folder'] = trim($data['folder']); - - if(isset($folders[$data['folder']])) { - $folder_id = $folders[$data['folder']]; - } + else if(ENABLE_FOLDER_RESTRICTIONS == 1 && count($search_folders) > 0) { + $q2 = "?" . str_repeat(",?", count($search_folders)-1); if($data['match']) { @@ -243,13 +228,15 @@ class ModelSearchSearch extends Model { } // run a final query to filter which messages are in this folder - $q = "?" . str_repeat(",?", count($f_bag)-1); - array_push($f_bag, $folder_id); - - $query = $this->db->query("SELECT id FROM " . TABLE_FOLDER_MESSAGE . " WHERE message_id in ($q) AND folder_id=?", $f_bag); + $q1 = "?" . str_repeat(",?", count($f_bag)-1); + $f_bag = array_merge($f_bag, $search_folders); + + $query = $this->db->query("SELECT id FROM " . TABLE_FOLDER_MESSAGE . " WHERE message_id IN ($q1) AND folder_id IN ($q2)", $f_bag); + + if(LOG_LEVEL >= NORMAL) { syslog(LOG_INFO, sprintf("sql query: '%s' in %.2f s, %d hits", $query->query, $query->exec_time, $query->num_rows)); } } else { - $query = $this->sphx->query("SELECT message_id FROM " . SPHINX_FOLDER_INDEX . " WHERE folder_id=$folder_id $sortorder LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS); + $query = $this->sphx->query("SELECT message_id FROM " . SPHINX_FOLDER_INDEX . " WHERE folder_id IN ($q2) $sortorder LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS, $search_folders); } $total_found = $query->total_found; @@ -262,13 +249,8 @@ class ModelSearchSearch extends Model { list ($total_found, $num_rows, $id_list) = $this->get_sphinx_id_list($data['note'], SPHINX_NOTE_INDEX, 'note', $page); $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $folders id IN ($id_list) $sortorder LIMIT 0,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS); } - else if(ENABLE_FOLDER_RESTRICTIONS == 1 && isset($data['extra_folders']) && strlen($data['extra_folders']) > 0) { - $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $a $id $date $attachment $direction $size folder IN (" . preg_replace("/ /", ",", $data['extra_folders']) . ") AND MATCH('$match') $sortorder LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS); - $total_found = $query->total_found; - $num_rows = $query->num_rows; - } else { - $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $a $id $date $attachment $direction $size $folders MATCH('$match') $sortorder LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS); + $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $a $id $date $attachment $direction $size MATCH('$match') $sortorder LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS); $total_found = $query->total_found; $num_rows = $query->num_rows; } @@ -333,14 +315,6 @@ class ModelSearchSearch extends Model { } } - if(ENABLE_FOLDER_RESTRICTIONS == 1) { - $query = $this->sphx->query("SELECT id, folder FROM " . SPHINX_MAIN_INDEX . " WHERE id IN (" . implode(",", $ids) . ")"); - $ids = array(); - foreach($query->rows as $q) { - if(isset($q['folder']) && in_array($q['folder'], $session->get("folders"))) { array_push($ids, $q['id']); } - } - } - $total_found = count($ids); if($total_found >= $pagelen) { @@ -761,19 +735,13 @@ class ModelSearchSearch extends Model { $arr = array_merge($arr, $a, $a); - if(ENABLE_FOLDER_RESTRICTIONS == 1) { - $query = $this->sphx->query("SELECT folder FROM " . SPHINX_MAIN_INDEX . " WHERE id=" . (int)$id); - if(isset($query->row['folder']) && in_array($query->row['folder'], $session->get("folders"))) { return 1; } + if(Registry::get('auditor_user') == 1 && RESTRICTED_AUDITOR == 1) { + $query = $this->db->query("SELECT id FROM " . VIEW_MESSAGES . " WHERE id=? AND ( `fromdomain` IN ($q) OR `todomain` IN ($q) )", $arr); + } else { + $query = $this->db->query("SELECT id FROM " . VIEW_MESSAGES . " WHERE id=? AND ( `from` IN ($q) OR `to` IN ($q) )", $arr); } - else { - if(Registry::get('auditor_user') == 1 && RESTRICTED_AUDITOR == 1) { - $query = $this->db->query("SELECT id FROM " . VIEW_MESSAGES . " WHERE id=? AND ( `fromdomain` IN ($q) OR `todomain` IN ($q) )", $arr); - } else { - $query = $this->db->query("SELECT id FROM " . VIEW_MESSAGES . " WHERE id=? AND ( `from` IN ($q) OR `to` IN ($q) )", $arr); - } - if(isset($query->row['id'])) { return 1; } - } + if(isset($query->row['id'])) { return 1; } return 0; } @@ -832,34 +800,26 @@ class ModelSearchSearch extends Model { } else { - if(ENABLE_FOLDER_RESTRICTIONS == 1) { - $query = $this->sphx->query("SELECT id, folder FROM " . SPHINX_MAIN_INDEX . " WHERE id IN (" . implode(",", $id) . ")"); - } - else { - $arr = array_merge($arr, $a, $a); - if(Registry::get('auditor_user') == 1 && RESTRICTED_AUDITOR == 1) { - $query = $this->db->query("SELECT id FROM `" . VIEW_MESSAGES . "` WHERE `id` IN ($q2) AND ( `fromdomain` IN ($q) OR `todomain` IN ($q) )", $arr); - } else { + $arr = array_merge($arr, $a, $a); + if(Registry::get('auditor_user') == 1 && RESTRICTED_AUDITOR == 1) { + $query = $this->db->query("SELECT id FROM `" . VIEW_MESSAGES . "` WHERE `id` IN ($q2) AND ( `fromdomain` IN ($q) OR `todomain` IN ($q) )", $arr); + } else { - $query = $this->db->query("SELECT id FROM " . TABLE_PRIVATE . " WHERE `id` IN ($q2)", $id); - if($query->num_rows > 0) { - foreach ($query->rows as $r) { - array_push($parr, $r['id']); - } + $query = $this->db->query("SELECT id FROM " . TABLE_PRIVATE . " WHERE `id` IN ($q2)", $id); + if($query->num_rows > 0) { + foreach ($query->rows as $r) { + array_push($parr, $r['id']); } - - $query = $this->db->query("SELECT id FROM `" . VIEW_MESSAGES . "` WHERE `id` IN ($q2) AND ( `from` IN ($q) OR `to` IN ($q) )", $arr); } + $query = $this->db->query("SELECT id FROM `" . VIEW_MESSAGES . "` WHERE `id` IN ($q2) AND ( `from` IN ($q) OR `to` IN ($q) )", $arr); } + } if($query->num_rows > 0) { foreach ($query->rows as $q) { - if(ENABLE_FOLDER_RESTRICTIONS == 1) { - if(in_array($q['folder'], $session->get("folders"))) { array_push($result, $q['id']); } - } - else if(!in_array($q['id'], $result) && !in_array($q['id'], $parr)) { + if(!in_array($q['id'], $result) && !in_array($q['id'], $parr)) { array_push($result, $q['id']); } } diff --git a/webui/view/theme/default/assets/css/metro-bootstrap.css b/webui/view/theme/default/assets/css/metro-bootstrap.css index 8e8be126..59372b00 100644 --- a/webui/view/theme/default/assets/css/metro-bootstrap.css +++ b/webui/view/theme/default/assets/css/metro-bootstrap.css @@ -1669,7 +1669,7 @@ html,body{height:auto !important;height:100%;min-height:100%;} #searchcontainer #button_audit{width:100%;} #searchcontainer #button_search,#searchcontainer #button_options{width:30%;} #mainscreen{position:absolute;top:120px;right:20px;bottom:20px;left:20px;min-width:320px;z-index:0;} -#mailleftcontainer{position:absolute;top:0;left:0;bottom:0;width:195px;} +#mailleftcontainer{position:absolute;top:0;left:0;bottom:0;width:195px;border:1px solid #999999;} #mailboxlist-container{position:absolute;top:0;left:0;width:100%;bottom:0;border:1px solid #999999;border-top:none;background-color:#f9f9f9;overflow:auto;} .boxlistcontent{position:absolute;top:0px;bottom:34px;left:0;right:0;width:100%;overflow-y:auto;overflow-x:hidden;height:auto;} .boxfooter{position:absolute;bottom:0px;left:0px;right:0px;overflow:hidden;height:33px;border-top:1px solid #ccc;background-color:#f6f6f6;min-width:320px;} diff --git a/webui/view/theme/default/templates/search/folder.tpl b/webui/view/theme/default/templates/search/folder.tpl index 6234722e..92ca51f6 100644 --- a/webui/view/theme/default/templates/search/folder.tpl +++ b/webui/view/theme/default/templates/search/folder.tpl @@ -2,44 +2,10 @@
- -
- -
+ +
+ +
- -
- - - 0) { ?> - - - -
- - - -
- - - - -