From ee910e773515f76d341eae323b57d40d63068dee Mon Sep 17 00:00:00 2001 From: SJ Date: Wed, 27 Jun 2012 11:17:23 +0200 Subject: [PATCH] improved group handling --- webui/config.php | 3 ++ webui/controller/common/layout-email.php | 16 ++++++ webui/controller/common/layout-minimal.php | 26 +++++++++ webui/controller/group/email.php | 54 +++++++++++++++---- webui/controller/login/logout.php | 2 +- webui/index.php | 1 + webui/model/group/group.php | 17 ++++-- webui/model/user/user.php | 6 ++- webui/view/javascript/piler.js | 10 ++++ .../default/templates/common/layout-email.tpl | 29 ++++++++++ .../templates/common/layout-minimal.tpl | 47 ++++++++++++++++ .../theme/default/templates/group/add.tpl | 5 ++ .../theme/default/templates/group/edit.tpl | 5 ++ .../theme/default/templates/group/email.tpl | 16 ++++++ 14 files changed, 221 insertions(+), 16 deletions(-) create mode 100644 webui/controller/common/layout-email.php create mode 100644 webui/controller/common/layout-minimal.php create mode 100644 webui/view/theme/default/templates/common/layout-email.tpl create mode 100644 webui/view/theme/default/templates/common/layout-minimal.tpl create mode 100644 webui/view/theme/default/templates/group/email.tpl diff --git a/webui/config.php b/webui/config.php index ae72a3a0..e9967a16 100644 --- a/webui/config.php +++ b/webui/config.php @@ -177,6 +177,9 @@ $themes = array( ); +$letters = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); + + define('ACTION_ALL', 0); define('ACTION_UNKNOWN', 1); define('ACTION_LOGIN', 2); diff --git a/webui/controller/common/layout-email.php b/webui/controller/common/layout-email.php new file mode 100644 index 00000000..6c59da87 --- /dev/null +++ b/webui/controller/common/layout-email.php @@ -0,0 +1,16 @@ +template = "common/layout-email.tpl"; + + $this->render(); + } + + +} + + +?> diff --git a/webui/controller/common/layout-minimal.php b/webui/controller/common/layout-minimal.php new file mode 100644 index 00000000..a0478f55 --- /dev/null +++ b/webui/controller/common/layout-minimal.php @@ -0,0 +1,26 @@ +data['title'] = $this->document->title; + + $this->template = "common/layout-minimal.tpl"; + + + $this->children = array( + "common/menu", + "common/footer" + ); + + $this->render(); + + } + + +} + + +?> diff --git a/webui/controller/group/email.php b/webui/controller/group/email.php index f19c3167..132c5485 100644 --- a/webui/controller/group/email.php +++ b/webui/controller/group/email.php @@ -7,8 +7,8 @@ class ControllerGroupEmail extends Controller { public function index(){ $this->id = "content"; - $this->template = "user/list.tpl"; - $this->layout = "common/layout-empty"; + $this->template = "group/email.tpl"; + $this->layout = "common/layout-email"; $request = Registry::get('request'); @@ -17,28 +17,60 @@ class ControllerGroupEmail extends Controller { $this->load->model('group/group'); + $this->data['page'] = 0; + $this->data['page_len'] = get_page_length(); + + $this->data['total'] = 0; + + $this->data['sort'] = 'email'; $this->data['term'] = ''; - if(!isset($this->request->get['term']) || strlen($this->request->get['term']) < 2) { die("no data"); } + if(!isset($this->request->get['term']) || strlen($this->request->get['term']) < 1) { die("no data"); } + if(isset($this->request->get['page']) && is_numeric($this->request->get['page']) && $this->request->get['page'] > 0) { + $this->data['page'] = $this->request->get['page']; + } + + $this->data['search'] = $this->request->get['term']; /* check if we are admin */ if(Registry::get('admin_user') == 1) { - $emails = $this->model_group_group->get_emails_by_string($this->request->get['term']); - $i = 0; - $s = '[ '; + // for autocomplete - foreach($emails as $email) { - $i++; - $s .= '{ "id": "' . $i . '", "value": "' . $email['email'] . '" },'; + if(strlen($this->request->get['term']) >= 2) { + $emails = $this->model_group_group->get_emails_by_string($this->request->get['term']); + + $i = 0; + $s = '[ '; + + foreach($emails as $email) { + $i++; + $s .= '{ "id": "' . $i . '", "value": "' . $email['email'] . '" },'; + } + + $s = preg_replace("/,$/", "", $s) . " ]"; + + print $s; } - $s = preg_replace("/,$/", "", $s) . " ]"; + // for email list + + if(strlen($this->request->get['term']) == 1) { + $this->data['emails'] = $this->model_group_group->get_emails_by_string($this->request->get['term'], $this->data['page'], $this->data['page_len']); + + $this->data['total'] = $this->model_group_group->count_emails($this->request->get['term']); + + $this->data['prev_page'] = $this->data['page'] - 1; + $this->data['next_page'] = $this->data['page'] + 1; + + $this->data['total_pages'] = floor($this->data['total'] / $this->data['page_len']); + + $this->render(); + } - print $s; } } diff --git a/webui/controller/login/logout.php b/webui/controller/login/logout.php index f23c117b..71e41a4c 100644 --- a/webui/controller/login/logout.php +++ b/webui/controller/login/logout.php @@ -8,7 +8,7 @@ class ControllerLoginLogout extends Controller { $this->id = "content"; $this->template = "login/logout.tpl"; - $this->layout = "common/layout"; + $this->layout = "common/layout-minimal"; $request = Registry::get('request'); diff --git a/webui/index.php b/webui/index.php index 129ffac2..a53411cb 100644 --- a/webui/index.php +++ b/webui/index.php @@ -63,6 +63,7 @@ if(MEMCACHED_ENABLED) { Registry::set('counters', $counters); Registry::set('langs', $langs); Registry::set('themes', $themes); +Registry::set('letters', $letters); Registry::set('health_smtp_servers', $health_smtp_servers); Registry::set('partitions_to_monitor', $partitions_to_monitor); diff --git a/webui/model/group/group.php b/webui/model/group/group.php index 45e4fbb9..f4e50a33 100644 --- a/webui/model/group/group.php +++ b/webui/model/group/group.php @@ -140,10 +140,12 @@ class ModelGroupGroup extends Model { } - public function get_emails_by_string($s = '') { - if(strlen($s) < 2) { return array(); } + public function get_emails_by_string($s = '', $page = 0, $page_len = PAGE_LEN) { + $from = (int)$page * (int)$page_len; - $query = $this->db->query("SELECT email FROM `" . TABLE_EMAIL . "` WHERE email LIKE ? ORDER BY email ASC", array($s . "%") ); + if(strlen($s) < 1) { return array(); } + + $query = $this->db->query("SELECT email FROM `" . TABLE_EMAIL . "` WHERE email LIKE ? ORDER BY email ASC LIMIT " . (int)$from . ", " . (int)$page_len, array($s . "%") ); if(isset($query->rows)) { return $query->rows; } @@ -151,6 +153,15 @@ class ModelGroupGroup extends Model { } + public function count_emails($s = '') { + if(strlen($s) < 1) { return 0; } + + $query = $this->db->query("SELECT COUNT(*) AS num FROM `" . TABLE_EMAIL . "` WHERE email LIKE ?", array($s . "%") ); + + return $query->row['num']; + } + + public function get_groups_by_string($s = '') { if(strlen($s) < 2) { return array(); } diff --git a/webui/model/user/user.php b/webui/model/user/user.php index 3f7a481f..d53fdef6 100644 --- a/webui/model/user/user.php +++ b/webui/model/user/user.php @@ -380,6 +380,7 @@ class ModelUserUser extends Model { private function update_group_settings($uid = -1, $group = '') { + $__g = array(); if($uid <= 0 || $group == '') { return 0; } @@ -398,7 +399,10 @@ class ModelUserUser extends Model { foreach($group as $g) { $g = rtrim($g); - $query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, uid) VALUES(?,?)", array($groups[$g], (int)$uid)); + if(!isset($__g[$groups[$g]])) { + $query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, uid) VALUES(?,?)", array($groups[$g], (int)$uid)); + $__g[$groups[$g]] = 1; + } } return 1; diff --git a/webui/view/javascript/piler.js b/webui/view/javascript/piler.js index 85d5951f..f89def00 100644 --- a/webui/view/javascript/piler.js +++ b/webui/view/javascript/piler.js @@ -511,6 +511,16 @@ function toggle_bulk_check() { } +function append_email_from_slider(id, value) { + var prefix = '\n'; + + a = opener.document.getElementById('email'); + if(a && a.value == '') prefix = ''; + + a.value += prefix + value; +} + + $(document).ready(function() { $.datepicker.setDefaults($.datepicker.regional[piler_ui_lang]); $("#date1").datepicker( { dateFormat: 'yy-mm-dd' } ); diff --git a/webui/view/theme/default/templates/common/layout-email.tpl b/webui/view/theme/default/templates/common/layout-email.tpl new file mode 100644 index 00000000..508a6b99 --- /dev/null +++ b/webui/view/theme/default/templates/common/layout-email.tpl @@ -0,0 +1,29 @@ + + + + + piler | <?php print $title; ?> + + + + + + + + + + + + + + +
+ +

+ + + +
+ + + diff --git a/webui/view/theme/default/templates/common/layout-minimal.tpl b/webui/view/theme/default/templates/common/layout-minimal.tpl new file mode 100644 index 00000000..be7c3e55 --- /dev/null +++ b/webui/view/theme/default/templates/common/layout-minimal.tpl @@ -0,0 +1,47 @@ + + + + + piler | <?php print $title; ?> + + + + + + + + + + + + + + + +
+ + + +
+ +

+ + +
+ + + + + +
+ + + diff --git a/webui/view/theme/default/templates/group/add.tpl b/webui/view/theme/default/templates/group/add.tpl index f449a096..ffa101dd 100644 --- a/webui/view/theme/default/templates/group/add.tpl +++ b/webui/view/theme/default/templates/group/add.tpl @@ -19,6 +19,11 @@
**:
+
+ + + +
diff --git a/webui/view/theme/default/templates/group/edit.tpl b/webui/view/theme/default/templates/group/edit.tpl index 2c618d45..857ff0c4 100644 --- a/webui/view/theme/default/templates/group/edit.tpl +++ b/webui/view/theme/default/templates/group/edit.tpl @@ -21,6 +21,11 @@
**:
+
+ + + +
diff --git a/webui/view/theme/default/templates/group/email.tpl b/webui/view/theme/default/templates/group/email.tpl new file mode 100644 index 00000000..a85ddcc6 --- /dev/null +++ b/webui/view/theme/default/templates/group/email.tpl @@ -0,0 +1,16 @@ + + +
+ + + + + +
close
+