From b03ca2effbef7461c5e67ef1e8ad86694d3a2c1e Mon Sep 17 00:00:00 2001 From: SJ Date: Sat, 15 Sep 2012 15:30:35 +0200 Subject: [PATCH] added folder handling to webui --- src/config.h | 2 +- webui/.htaccess | 1 + webui/controller/folder/copy.php | 27 ++++++ webui/controller/folder/list.php | 82 +++++++++++++++++++ webui/controller/search/folder.php | 1 + webui/controller/search/helper.php | 2 + webui/language/en/messages.php | 3 + webui/language/hu/messages.iso-8859-2.php | 3 + webui/language/hu/messages.php | 3 + webui/model/folder/folder.php | 61 ++++++++++++++ webui/model/search/search.php | 31 +++++++ webui/model/user/auth.php | 1 + webui/view/javascript/piler.js | 69 ++++++++++++---- .../default/templates/common/layout-new.tpl | 5 +- .../theme/default/templates/common/menu.tpl | 3 + .../theme/default/templates/folder/list.tpl | 54 ++++++++++++ .../theme/default/templates/search/folder.tpl | 7 +- .../theme/default/templates/search/helper.tpl | 4 +- 18 files changed, 340 insertions(+), 19 deletions(-) create mode 100644 webui/controller/folder/copy.php create mode 100644 webui/controller/folder/list.php create mode 100644 webui/view/theme/default/templates/folder/list.tpl diff --git a/src/config.h b/src/config.h index 3625eaec..63dc2efc 100644 --- a/src/config.h +++ b/src/config.h @@ -13,7 +13,7 @@ #define VERSION "0.1.21" -#define BUILD 704 +#define BUILD 705 #define HOSTID "mailarchiver" diff --git a/webui/.htaccess b/webui/.htaccess index f8fad96f..99f7fba9 100644 --- a/webui/.htaccess +++ b/webui/.htaccess @@ -8,6 +8,7 @@ RewriteRule ^search-helper.php /index.php?route=search/helper [L] RewriteRule ^audit-helper.php /index.php?route=audit/helper [L] RewriteRule ^message.php /index.php?route=message/view [L] RewriteRule ^bulkrestore.php /index.php?route=message/bulkrestore [L] +RewriteRule ^folders.php /index.php?route=folder/list& [QSA,L] RewriteRule ^settings.php /index.php?route=user/settings [L] RewriteRule ^login.php /index.php?route=login/login [L] RewriteRule ^logout.php /index.php?route=login/logout [L] diff --git a/webui/controller/folder/copy.php b/webui/controller/folder/copy.php new file mode 100644 index 00000000..77263475 --- /dev/null +++ b/webui/controller/folder/copy.php @@ -0,0 +1,27 @@ +id = "content"; + $this->template = "search/save.tpl"; + $this->layout = "common/layout-empty"; + + + $request = Registry::get('request'); + $db = Registry::get('db'); + + $this->load->model('folder/folder'); + + $this->model_folder_folder->copy_message_to_folder_by_id($this->request->post['folder_id'], $this->request->post['id']); + + + //$this->render(); + } + +} + +?> diff --git a/webui/controller/folder/list.php b/webui/controller/folder/list.php new file mode 100644 index 00000000..480471d0 --- /dev/null +++ b/webui/controller/folder/list.php @@ -0,0 +1,82 @@ +id = "content"; + $this->template = "folder/list.tpl"; + $this->layout = "common/layout"; + + + $request = Registry::get('request'); + $db = Registry::get('db'); + + $this->load->model('folder/folder'); + + $this->document->title = $this->data['text_folders']; + + if(isset($this->request->post['name']) && $this->request->post['name']) { + $this->model_folder_folder->add_extra_folder($this->request->post['name']); + + Header("Location: folders.php"); + return; + } + + + if(isset($this->request->get['id']) && $this->request->get['id'] > 0) { + $this->model_folder_folder->remove_extra_folder($this->request->get['id']); + + Header("Location: folders.php"); + return; + } + + /*if($this->request->server['REQUEST_METHOD'] == 'POST' && PASSWORD_CHANGE_ENABLED == 1 && $this->validate() == true) { + + if($this->model_user_auth->change_password(Registry::get('username'), $this->request->post['password']) == 1) { + $this->data['x'] = $this->data['text_password_changed']; + } + else { + $this->data['x'] = $this->data['text_failed_to_change_password']; + } + }*/ + + + $this->data['page_len'] = get_page_length(); + + $this->data['extra_folders'] = $this->model_folder_folder->get_extra_folders_for_user(); + + $this->render(); + } + + + private function validate() { + + if(!isset($this->request->post['password']) || !isset($this->request->post['password2']) ) { + $this->error['password'] = $this->data['text_missing_password']; + } + + if(strlen(@$this->request->post['password']) < MIN_PASSWORD_LENGTH || strlen(@$this->request->post['password2']) < MIN_PASSWORD_LENGTH) { + $this->error['password'] = $this->data['text_invalid_password']; + } + + if($this->request->post['password'] != $this->request->post['password2']) { + $this->error['password'] = $this->data['text_password_mismatch']; + } + + + if (!$this->error) { + return true; + } else { + return false; + } + + } + + + +} + +?> diff --git a/webui/controller/search/folder.php b/webui/controller/search/folder.php index 82a282ab..3caef4ad 100644 --- a/webui/controller/search/folder.php +++ b/webui/controller/search/folder.php @@ -14,6 +14,7 @@ class ControllerSearchFolder extends Controller { $this->load->model('folder/folder'); $this->data['folders'] = $this->model_folder_folder->get_folders_for_user(); + $this->data['extra_folders'] = $this->model_folder_folder->get_extra_folders_for_user(); $this->render(); } diff --git a/webui/controller/search/helper.php b/webui/controller/search/helper.php index 688df486..a82dd0b8 100644 --- a/webui/controller/search/helper.php +++ b/webui/controller/search/helper.php @@ -17,6 +17,7 @@ class ControllerSearchHelper extends Controller { 'note' => '', 'ref' => '', 'folders' => '', + 'extra_folders' => '', 'any' => '' ); @@ -94,6 +95,7 @@ class ControllerSearchHelper extends Controller { private function fixup_post_request() { if(isset($this->request->post['ref'])) { $this->a['ref'] = $this->request->post['ref']; } if(isset($this->request->post['folders'])) { $this->a['folders'] = $this->request->post['folders']; } + if(isset($this->request->post['extra_folders'])) { $this->a['extra_folders'] = $this->request->post['extra_folders']; } $this->a['sort'] = $this->request->post['sort']; $this->a['order'] = $this->request->post['order']; diff --git a/webui/language/en/messages.php b/webui/language/en/messages.php index 104e5228..2afdbdc3 100644 --- a/webui/language/en/messages.php +++ b/webui/language/en/messages.php @@ -39,6 +39,7 @@ $_['text_compressed'] = "compressed"; $_['text_confirm_to_reset_counters'] = "Confirm to reset counters"; $_['text_content_filter'] = "Content filter"; $_['text_conversation_available'] = "Conversation available"; +$_['text_copied'] = "Copied"; $_['text_counters'] = "Counters"; $_['text_cpu_load'] = "CPU load"; $_['text_cpu_usage'] = "CPU usage"; @@ -94,6 +95,7 @@ $_['text_exact_domain_name_or_email_address'] = "exact domain name or email addr $_['text_exclude'] = "Exclude"; $_['text_existing_domains'] = "Existing domains"; $_['text_existing_email'] = "Existing email"; +$_['text_existing_folders'] = "Existing folders"; $_['text_existing_groups'] = "Existing groups"; $_['text_existing_policies'] = "Existing policies"; $_['text_existing_rules'] = "Existing rules"; @@ -112,6 +114,7 @@ $_['text_failed_to_remove'] = "Failed to remove"; $_['text_failed_to_restore'] = "Failed to restore"; $_['text_failed_to_update'] = "Failed to update"; $_['text_first'] = "First"; +$_['text_folder'] = "Folder"; $_['text_folders'] = "Folders"; $_['text_from'] = "From"; $_['text_from_domain'] = "From domain"; diff --git a/webui/language/hu/messages.iso-8859-2.php b/webui/language/hu/messages.iso-8859-2.php index 59b0fa08..86ef68f7 100644 --- a/webui/language/hu/messages.iso-8859-2.php +++ b/webui/language/hu/messages.iso-8859-2.php @@ -39,6 +39,7 @@ $_['text_compressed'] = "t $_['text_confirm_to_reset_counters'] = "Számlálók nullázásának megerõsítése"; $_['text_content_filter'] = "Tartalomszûrõ"; $_['text_conversation_available'] = "Levélváltás elérhetõ"; +$_['text_copied'] = "Átmásolva"; $_['text_counters'] = "Számlálók"; $_['text_cpu_load'] = "CPU terhelés"; $_['text_cpu_usage'] = "CPU használat"; @@ -94,6 +95,7 @@ $_['text_exact_domain_name_or_email_address'] = "pontos domainn $_['text_exclude'] = "Kihagy"; $_['text_existing_domains'] = "Létezõ domainek"; $_['text_existing_email'] = "Létezõ email"; +$_['text_existing_groups'] = "Létezõ mappák"; $_['text_existing_groups'] = "Létezõ csoportok"; $_['text_existing_policies'] = "Létezõ házirendek"; $_['text_existing_rules'] = "Létezõ szabályok"; @@ -112,6 +114,7 @@ $_['text_failed_to_remove'] = "Hiba az elt $_['text_failed_to_restore'] = "Hiba a visszaállítás során"; $_['text_failed_to_update'] = "Nem sikerült módosítani"; $_['text_first'] = "Elsõ"; +$_['text_folder'] = "Mappa"; $_['text_folders'] = "Mappák"; $_['text_from'] = "Feladó"; $_['text_from_domain'] = "Feladó domain"; diff --git a/webui/language/hu/messages.php b/webui/language/hu/messages.php index 459c8492..12643064 100644 --- a/webui/language/hu/messages.php +++ b/webui/language/hu/messages.php @@ -39,6 +39,7 @@ $_['text_compressed'] = "tömörített"; $_['text_confirm_to_reset_counters'] = "Számlálók nullázásának megerÅ‘sítése"; $_['text_content_filter'] = "TartalomszűrÅ‘"; $_['text_conversation_available'] = "Levélváltás elérhetÅ‘"; +$_['text_copied'] = "Ãtmásolva"; $_['text_counters'] = "Számlálók"; $_['text_cpu_load'] = "CPU terhelés"; $_['text_cpu_usage'] = "CPU használat"; @@ -94,6 +95,7 @@ $_['text_exact_domain_name_or_email_address'] = "pontos domainnév vagy email c $_['text_exclude'] = "Kihagy"; $_['text_existing_domains'] = "LétezÅ‘ domainek"; $_['text_existing_email'] = "LétezÅ‘ email"; +$_['text_existing_groups'] = "LétezÅ‘ mappák"; $_['text_existing_groups'] = "LétezÅ‘ csoportok"; $_['text_existing_policies'] = "LétezÅ‘ házirendek"; $_['text_existing_rules'] = "LétezÅ‘ szabályok"; @@ -112,6 +114,7 @@ $_['text_failed_to_remove'] = "Hiba az eltávolításkor"; $_['text_failed_to_restore'] = "Hiba a visszaállítás során"; $_['text_failed_to_update'] = "Nem sikerült módosítani"; $_['text_first'] = "ElsÅ‘"; +$_['text_folder'] = "Mappa"; $_['text_folders'] = "Mappák"; $_['text_from'] = "Feladó"; $_['text_from_domain'] = "Feladó domain"; diff --git a/webui/model/folder/folder.php b/webui/model/folder/folder.php index 1f7a17fe..c60ceb4a 100644 --- a/webui/model/folder/folder.php +++ b/webui/model/folder/folder.php @@ -54,6 +54,31 @@ class ModelFolderFolder extends Model { } + public function get_extra_folders_for_user() { + $query = $this->db->query("SELECT `id`, `name` FROM `" . TABLE_FOLDER_EXTRA . "` WHERE uid=? ORDER BY name", array($_SESSION['uid'])); + + if(isset($query->rows)) { return $query->rows; } + + return array(); + } + + + private function is_your_extra_folder($folder_id = 0) { + $query = $this->db->query("SELECT `id` FROM `" . TABLE_FOLDER_EXTRA . "` WHERE uid=? AND id=?", array($_SESSION['uid'], $folder_id)); + if(isset($query->row['id'])) { return 1; } + + return 0; + } + + + public function copy_message_to_folder_by_id($folder_id = 0, $meta_id = 0) { + if(!$this->is_your_extra_folder($folder_id)) { return -1; } + + $query = $this->db->query("INSERT INTO " . TABLE_FOLDER_MESSAGE . " (folder_id, id) VALUES(?,?)", array($folder_id, $meta_id)); + return $this->db->countAffected(); + } + + public function get_all_folder_ids($uid = 0) { $arr = array(); @@ -70,6 +95,21 @@ class ModelFolderFolder extends Model { } + public function get_all_extra_folder_ids($uid = 0) { + $arr = array(); + + $query = $this->db->query("SELECT id FROM `" . TABLE_FOLDER_EXTRA . "` WHERE uid=?", array($uid)); + + if(isset($query->rows)) { + foreach ($query->rows as $q) { + array_push($arr, $q['id']); + } + } + + return $arr; + } + + private function get_sub_folders($id = 0, &$arr = array()) { $query = $this->db->query("SELECT id FROM `" . TABLE_FOLDER . "` WHERE parent_id=?", array($id)); @@ -106,6 +146,27 @@ class ModelFolderFolder extends Model { } + public function add_extra_folder($name = '') { + if($name == '') { return -1; } + + $query = $this->db->query("INSERT INTO " . TABLE_FOLDER_EXTRA . " (uid, name) VALUES(?,?)", array($_SESSION['uid'], $name)); + return $this->db->countAffected(); + } + + + public function remove_extra_folder($id = 0) { + if($id == 0) { return -1; } + + $query = $this->db->query("DELETE FROM " . TABLE_FOLDER_EXTRA . " WHERE id=? AND uid=?", array($id, $_SESSION['uid'])); + if($this->db->countAffected() == 1) { + $query = $this->db->query("DELETE FROM " . TABLE_FOLDER_MESSAGE . " WHERE folder_id=?", array($id)); + return $this->db->countAffected(); + } + + return 0; + } + + } ?> diff --git a/webui/model/search/search.php b/webui/model/search/search.php index c0dbbb52..abb88973 100644 --- a/webui/model/search/search.php +++ b/webui/model/search/search.php @@ -292,6 +292,10 @@ class ModelSearchSearch extends Model { $id_list = $this->get_sphinx_id_list($data['note'], SPHINX_NOTE_INDEX, 'note'); $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $folders id IN ($id_list) $sortorder LIMIT 0," . MAX_SEARCH_HITS); } + else if(ENABLE_FOLDER_RESTRICTIONS == 1 && isset($data['extra_folders']) && $data['extra_folders']) { + $ids_in_extra_folders = $this->get_sphinx_id_list_by_extra_folders($data['extra_folders']); + $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $a $date $attachment $direction $size MATCH('$match') AND id IN ($ids_in_extra_folders) $sortorder LIMIT 0," . MAX_SEARCH_HITS); + } else { $query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $a $date $attachment $direction $size $folders MATCH('$match') $sortorder LIMIT 0," . MAX_SEARCH_HITS); } @@ -388,6 +392,33 @@ class ModelSearchSearch extends Model { } + private function get_sphinx_id_list_by_extra_folders($extra_folders = '') { + $id_list = ''; + $q = ''; + $__folders = array(); + + $s = explode(" ", $extra_folders); + while(list($k,$v) = each($s)) { + if(in_array($v, $_SESSION['extra_folders']) && is_numeric($v)) { + array_push($__folders, $v); + if($q) { $q .= ",?"; } + else { $q = "?"; } + } + } + + + $q = $this->db->query("SELECT id FROM " . TABLE_FOLDER_MESSAGE . " WHERE folder_id IN ($q)", $__folders); + + foreach($q->rows as $a) { + $id_list .= "," . $a['id']; + } + + if($id_list) { $id_list = substr($id_list, 1, strlen($id_list)); } + + return $id_list; + } + + private function get_meta_data($ids = array(), $q = '', $sortorder = '') { $messages = array(); $tag = array(); diff --git a/webui/model/user/auth.php b/webui/model/user/auth.php index 890c02b9..3e19bdad 100644 --- a/webui/model/user/auth.php +++ b/webui/model/user/auth.php @@ -21,6 +21,7 @@ class ModelUserAuth extends Model { $_SESSION['emails'] = $this->model_user_user->get_users_all_email_addresses($query->row['uid']); $_SESSION['folders'] = $this->model_folder_folder->get_all_folder_ids($query->row['uid']); + $_SESSION['extra_folders'] = $this->model_folder_folder->get_all_extra_folder_ids($query->row['uid']); AUDIT(ACTION_LOGIN, $username, '', '', 'successful auth against user table'); diff --git a/webui/view/javascript/piler.js b/webui/view/javascript/piler.js index eddff9a5..0c5639f1 100644 --- a/webui/view/javascript/piler.js +++ b/webui/view/javascript/piler.js @@ -197,6 +197,7 @@ function assemble_search_term(n, prefix) { var attachment_type = ''; var e; var folders = ''; + var extra_folders = ''; e = document.getElementById(prefix + 'searchtype'); if(e && e.value) { data = data + "searchtype=" + e.value; } @@ -274,6 +275,11 @@ function assemble_search_term(n, prefix) { if(b.name && b.name.substring(0, 7) == 'folder_' && b.checked) { folders = folders + "+" + b.name.substring(7); } + + if(b.name && b.name.substring(0, 13) == 'extra_folder_' && b.checked) { + extra_folders = extra_folders + "+" + b.name.substring(13); + } + } } @@ -282,6 +288,10 @@ function assemble_search_term(n, prefix) { data = data + "&folders=" + folders; } + if(extra_folders) { + extra_folders = extra_folders.substring(1); + data = data + "&extra_folders=" + extra_folders; + } //alert("data: " + data); @@ -709,13 +719,37 @@ function show_message(id, msg, timeout){ } -function move_message_list_scrollbar(direction) { - - var current_result_div = document.getElementById('e_' + current_messages[current_message_serial]); - if(current_result_div){ - if(current_message_serial % 2) current_result_div.className = 'resultrow odd'; - else current_result_div.className = 'resultrow'; +function set_scroll_position(current_message_serial) { + var objDiv = document.getElementById("messagelistcontainer"); + if(objDiv) { + objDiv.scrollTop = current_message_serial*17 - 30; } +} + + +function highlight_message_by_position(pos) { + var a; + + for(i=1; i<=current_messages.length; i++) { + a = document.getElementById('e_' + current_messages[i]); + if(a) { + if(i % 2) a.className = 'resultrow odd'; + else a.className = 'resultrow'; + } + } + + load_url_with_get(message_loader_url + current_messages[pos], 'mailpreviewframe'); + + a = document.getElementById('e_' + current_messages[pos]); + + if(a){ a.className = 'resultrow selected'; } + + set_scroll_position(pos); + +} + + +function move_message_list_scrollbar(direction) { if(direction == 'down') { if(current_message_serial < current_messages.length-1) current_message_serial++; @@ -724,14 +758,21 @@ function move_message_list_scrollbar(direction) { if(current_message_serial > 1) current_message_serial--; } - load_url_with_get(message_loader_url + current_messages[current_message_serial], 'mailpreviewframe'); - - current_result_div = document.getElementById('e_' + current_messages[current_message_serial]); - - if(current_result_div){ current_result_div.className = 'resultrow selected'; } - - var objDiv = document.getElementById("messagelistcontainer"); - if(objDiv) objDiv.scrollTop = current_message_serial*17 - 30; + highlight_message_by_position(current_message_serial); +} + + +function copy_message_to_folder(folder_id, id, copied) { + if(id <= 0) { return 0; } + + params = "folder_id=" + folder_id + "&id=" + id; + + send_ajax_post_request(folder_copy_url, params); + + show_message('messagebox1', '

' + copied + '

', 0.85); + + current_message_id = 0; + } diff --git a/webui/view/theme/default/templates/common/layout-new.tpl b/webui/view/theme/default/templates/common/layout-new.tpl index 8aaf2aad..6de37a6f 100644 --- a/webui/view/theme/default/templates/common/layout-new.tpl +++ b/webui/view/theme/default/templates/common/layout-new.tpl @@ -21,10 +21,12 @@ @@ -116,6 +118,7 @@ + -
+
diff --git a/webui/view/theme/default/templates/common/menu.tpl b/webui/view/theme/default/templates/common/menu.tpl index 6e84c93f..9870b735 100644 --- a/webui/view/theme/default/templates/common/menu.tpl +++ b/webui/view/theme/default/templates/common/menu.tpl @@ -2,6 +2,9 @@
id="active"> | + + id="active"> | + id="active"> | : | id="active"> diff --git a/webui/view/theme/default/templates/folder/list.tpl b/webui/view/theme/default/templates/folder/list.tpl new file mode 100644 index 00000000..cad4da87 --- /dev/null +++ b/webui/view/theme/default/templates/folder/list.tpl @@ -0,0 +1,54 @@ + + + + + +
+ + + +
+ + + + + + + + +. + + + diff --git a/webui/view/theme/default/templates/search/folder.tpl b/webui/view/theme/default/templates/search/folder.tpl index cd65190b..f83ba82c 100644 --- a/webui/view/theme/default/templates/search/folder.tpl +++ b/webui/view/theme/default/templates/search/folder.tpl @@ -4,9 +4,14 @@
- + + +
+ + +
diff --git a/webui/view/theme/default/templates/search/helper.tpl b/webui/view/theme/default/templates/search/helper.tpl index 6d1c4924..4b72ce3f 100644 --- a/webui/view/theme/default/templates/search/helper.tpl +++ b/webui/view/theme/default/templates/search/helper.tpl @@ -44,10 +44,10 @@