diff --git a/config.php.in b/config.php.in index b92a117c..f39a6f1c 100644 --- a/config.php.in +++ b/config.php.in @@ -375,6 +375,8 @@ include("system/helper/detectmobilebrowser.php"); // make sure auditors are restricted in a saas environment if($config['ENABLE_SAAS'] == 1) { $config['RESTRICTED_AUDITOR'] = 1; } if($session->get("username") == 'auditor@local' || isset($_SERVER['argv'][2]) ) { $config['RESTRICTED_AUDITOR'] = 0; } +// disable folders for normal users with no folder restrictions set +if($config['ENABLE_FOLDER_RESTRICTIONS'] == 1 && $session->get("admin_user") == 0 && (!$session->get("folders") || count($session->get("folders")) <= 1)) { $config['ENABLE_FOLDER_RESTRICTIONS'] = 0; } diff --git a/webui/controller/search/folder.php b/webui/controller/search/folder.php index a19b36a2..73ab17b7 100644 --- a/webui/controller/search/folder.php +++ b/webui/controller/search/folder.php @@ -15,7 +15,6 @@ 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")); diff --git a/webui/model/folder/folder.php b/webui/model/folder/folder.php index 4189124e..79524a81 100644 --- a/webui/model/folder/folder.php +++ b/webui/model/folder/folder.php @@ -57,17 +57,20 @@ class ModelFolderFolder extends Model { public function get_folders_for_user() { $session = Registry::get('session'); + $folders = $session->get("folders"); - $q = str_repeat("?,", count($session->get("folders"))); + $q = str_repeat("?,", count($folders)); $q = preg_replace("/\,$/", "", $q); - if(isAuditorUser() == 1) { - $query = $this->db->query("SELECT `id`, `name` FROM `" . TABLE_FOLDER); - } else { - $query = $this->db->query("SELECT `id`, `name` FROM `" . TABLE_FOLDER . "` WHERE id IN ($q)", $session->get("folders")); - } + $query = $this->db->query("SELECT `id`, `name` FROM `" . TABLE_FOLDER . "` WHERE id IN ($q)", $folders); - if(isset($query->rows)) { return $query->rows; } + if(isset($query->rows)) { + $arr = $query->rows; + if(in_array(0, $folders, TRUE)) { + array_unshift($arr, array('id' => 0, 'name' => '---')); + } + return $arr; + } return array(); } @@ -95,11 +98,12 @@ class ModelFolderFolder extends Model { public function get_folder_id_array_for_user($uid = 0, $is_admin = 0) { $arr = array(); + $add_folder0 = ($is_admin == 0); - if($is_admin == 2) { + $query = $this->db->query("SELECT id FROM `" . TABLE_FOLDER_USER . "` WHERE uid=?", array($uid)); + if($is_admin == 2 && (!isset($query->rows) || count($query->rows) == 0)) { $query = $this->db->query("SELECT id FROM `" . TABLE_FOLDER); - } else { - $query = $this->db->query("SELECT id FROM `" . TABLE_FOLDER_USER . "` WHERE uid=?", array($uid)); + $add_folder0 = 1; } if(isset($query->rows)) { @@ -109,6 +113,10 @@ class ModelFolderFolder extends Model { } } + if($add_folder0 == 1) { + array_unshift($arr, 0); + } + return $arr; } diff --git a/webui/model/search/search.php b/webui/model/search/search.php index cc6a5db9..40f2dcc9 100644 --- a/webui/model/search/search.php +++ b/webui/model/search/search.php @@ -79,8 +79,6 @@ class ModelSearchSearch extends Model { else { return ""; } } - if(ENABLE_FOLDER_RESTRICTIONS == 1) { return ""; } - $all_your_addresses = $this->get_all_your_address("emails"); $all_your_wildcard_domains = $this->get_all_your_address("wildcard_domains"); @@ -219,7 +217,7 @@ 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) { + else if(ENABLE_FOLDER_RESTRICTIONS == 1 && isset($data['extra_folders'])) { $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; diff --git a/webui/view/theme/default/templates/message/view.tpl b/webui/view/theme/default/templates/message/view.tpl index 84b8a6b2..47d2cc3d 100644 --- a/webui/view/theme/default/templates/message/view.tpl +++ b/webui/view/theme/default/templates/message/view.tpl @@ -55,7 +55,6 @@