From 095f22c7b21bc8c0bea175f5e0f55e348e344e27 Mon Sep 17 00:00:00 2001 From: SJ Date: Mon, 25 Jun 2012 22:14:30 +0200 Subject: [PATCH] updated the group handling + revised admin permissions --- util/db-mysql.sql | 11 +++- util/db-upgrade-0.18-vs-0.19.sql | 8 ++- webui/config.php | 1 + webui/controller/group/add.php | 2 + webui/controller/group/edit.php | 3 +- webui/controller/group/email.php | 48 +++++++++++++++++ webui/controller/group/group.php | 48 +++++++++++++++++ webui/controller/health/health.php | 2 +- webui/controller/user/edit.php | 2 +- webui/language/en/messages.php | 6 +++ webui/language/hu/messages.iso-8859-2.php | 6 +++ webui/language/hu/messages.php | 6 +++ webui/model/group/group.php | 35 +++++++++++++ webui/model/search/message.php | 7 +-- webui/model/search/search.php | 10 ++-- webui/model/user/auth.php | 3 +- webui/model/user/user.php | 39 ++++++++++++-- webui/system/misc.php | 35 ++++++------- webui/view/javascript/piler.js | 52 +++++++++++++++++++ .../default/stylesheet/style-default.css | 1 + .../theme/default/templates/common/layout.tpl | 3 ++ .../theme/default/templates/group/add.tpl | 9 +++- .../theme/default/templates/group/edit.tpl | 14 +++-- .../view/theme/default/templates/user/add.tpl | 20 +++---- .../theme/default/templates/user/edit.tpl | 20 +++---- 25 files changed, 323 insertions(+), 68 deletions(-) create mode 100644 webui/controller/group/email.php create mode 100644 webui/controller/group/group.php diff --git a/util/db-mysql.sql b/util/db-mysql.sql index a6618d26..94f4c241 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -189,7 +189,6 @@ create index `user_settings_idx` on `user_settings`(`username`); drop table if exists `user`; create table if not exists `user` ( `uid` int unsigned not null primary key, - `gid` int default 0, `username` char(64) not null unique, `realname` char(64) default null, `password` char(48) default null, @@ -198,7 +197,7 @@ create table if not exists `user` ( `isadmin` tinyint default 0 ) Engine=InnoDB; -insert into `user` (`uid`, `gid`, `username`, `realname`, `password`, `isadmin`, `domain`) values (0, 0, 'admin', 'built-in piler admin', '$1$PItc7d$zsUgON3JRrbdGS11t9JQW1', 1, 'local'); +insert into `user` (`uid`, `username`, `realname`, `password`, `isadmin`, `domain`) values (0, 'admin', 'built-in piler admin', '$1$PItc7d$zsUgON3JRrbdGS11t9JQW1', 1, 'local'); drop table if exists `email`; create table if not exists `email` ( @@ -223,6 +222,14 @@ create table if not exists `group` ( ) ENGINE=InnoDB; +create table if not exists `group_user` ( + `id` bigint unsigned not null, + `uid` int unsigned not null, + key `group_user_idx` (`id`), + key `group_user_idx2` (`uid`) +) ENGINE=InnoDB; + + create table if not exists `group_email` ( `id` bigint unsigned not null, `email` char(128) not null, diff --git a/util/db-upgrade-0.18-vs-0.19.sql b/util/db-upgrade-0.18-vs-0.19.sql index b2c7372c..429c3939 100644 --- a/util/db-upgrade-0.18-vs-0.19.sql +++ b/util/db-upgrade-0.18-vs-0.19.sql @@ -10,6 +10,12 @@ create table if not exists `group_email` ( key `group_email_idx` (`id`) ) ENGINE=InnoDB; -alter table `user` add column `gid` int default 0; +create table if not exists `group_user` ( + `id` bigint unsigned not null, + `uid` int unsigned not null, + key `group_user_idx` (`id`), + key `group_user_idx2` (`uid`) +) ENGINE=InnoDB; + diff --git a/webui/config.php b/webui/config.php index 5834b62d..ae72a3a0 100644 --- a/webui/config.php +++ b/webui/config.php @@ -81,6 +81,7 @@ define('DB_DATABASE', 'piler'); define('TABLE_USER', 'user'); define('TABLE_GROUP', 'group'); +define('TABLE_GROUP_USER', 'group_user'); define('TABLE_GROUP_EMAIL', 'group_email'); define('TABLE_EMAIL', 'email'); define('TABLE_META', 'metadata'); diff --git a/webui/controller/group/add.php b/webui/controller/group/add.php index 837d0d5c..ab61d7eb 100644 --- a/webui/controller/group/add.php +++ b/webui/controller/group/add.php @@ -26,6 +26,8 @@ class ControllerGroupAdd extends Controller { if($this->request->server['REQUEST_METHOD'] == 'POST') { $ret = 0; + $this->data['post'] = $this->request->post; + if($this->validate() == true){ $ret = $this->model_group_group->add_group($this->request->post); diff --git a/webui/controller/group/edit.php b/webui/controller/group/edit.php index f69f6a39..dbcbb4f8 100644 --- a/webui/controller/group/edit.php +++ b/webui/controller/group/edit.php @@ -38,8 +38,6 @@ class ControllerGroupEdit extends Controller { if(Registry::get('admin_user') == 1) { - $this->data['group'] = $this->model_group_group->get_domain_by_id($this->data['id']); - if($this->request->server['REQUEST_METHOD'] == 'POST') { if($this->validate() == true){ @@ -59,6 +57,7 @@ class ControllerGroupEdit extends Controller { } } else { + $this->data['group'] = $this->model_group_group->get_domain_by_id($this->data['id']); $this->data['email'] = $this->model_group_group->get_emails_by_group_id($this->data['id']); } } diff --git a/webui/controller/group/email.php b/webui/controller/group/email.php new file mode 100644 index 00000000..f19c3167 --- /dev/null +++ b/webui/controller/group/email.php @@ -0,0 +1,48 @@ +id = "content"; + $this->template = "user/list.tpl"; + $this->layout = "common/layout-empty"; + + + $request = Registry::get('request'); + $db = Registry::get('db'); + $language = Registry::get('language'); + + $this->load->model('group/group'); + + + $this->data['term'] = ''; + + if(!isset($this->request->get['term']) || strlen($this->request->get['term']) < 2) { die("no data"); } + + + /* 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 = '[ '; + + foreach($emails as $email) { + $i++; + $s .= '{ "id": "' . $i . '", "value": "' . $email['email'] . '" },'; + } + + $s = preg_replace("/,$/", "", $s) . " ]"; + + print $s; + } + } + + +} + +?> diff --git a/webui/controller/group/group.php b/webui/controller/group/group.php new file mode 100644 index 00000000..013c3782 --- /dev/null +++ b/webui/controller/group/group.php @@ -0,0 +1,48 @@ +id = "content"; + $this->template = "user/list.tpl"; + $this->layout = "common/layout-empty"; + + + $request = Registry::get('request'); + $db = Registry::get('db'); + $language = Registry::get('language'); + + $this->load->model('group/group'); + + + $this->data['term'] = ''; + + if(!isset($this->request->get['term']) || strlen($this->request->get['term']) < 2) { die("no data"); } + + + /* check if we are admin */ + + if(Registry::get('admin_user') == 1) { + $results = $this->model_group_group->get_groups_by_string($this->request->get['term']); + + $i = 0; + $s = '[ '; + + foreach($results as $result) { + $i++; + $s .= '{ "id": "' . $i . '", "value": "' . $result['groupname'] . '" },'; + } + + $s = preg_replace("/,$/", "", $s) . " ]"; + + print $s; + } + } + + +} + +?> diff --git a/webui/controller/health/health.php b/webui/controller/health/health.php index b25782f1..41063c9f 100644 --- a/webui/controller/health/health.php +++ b/webui/controller/health/health.php @@ -19,7 +19,7 @@ class ControllerHealthHealth extends Controller { /* check if we are admin */ - if(Registry::get('admin_user') != 1 && Registry::get('readonly_admin') != 1 && Registry::get('auditor_admin') != 1) { + if(Registry::get('admin_user') != 1 && Registry::get('readonly_admin') != 1) { $this->template = "common/error.tpl"; $this->data['errorstring'] = $this->data['text_you_are_not_admin']; } diff --git a/webui/controller/user/edit.php b/webui/controller/user/edit.php index 6d569285..633a82e7 100644 --- a/webui/controller/user/edit.php +++ b/webui/controller/user/edit.php @@ -71,9 +71,9 @@ class ControllerUserEdit extends Controller { } else { $this->data['user'] = $this->model_user_user->get_user_by_uid($this->data['uid']); - $this->data['groups'] = $this->model_group_group->get_groups(); $this->data['user']['group_membership'] = $this->model_user_user->get_additional_uids($this->data['uid']); + $this->data['user']['group'] = $this->model_group_group->get_groups_by_uid($this->data['uid']); $this->data['emails'] = $this->model_user_user->get_emails($this->data['user']['username']); diff --git a/webui/language/en/messages.php b/webui/language/en/messages.php index 763ff04e..2081d50e 100644 --- a/webui/language/en/messages.php +++ b/webui/language/en/messages.php @@ -86,6 +86,7 @@ $_['text_empty_search_result'] = "Empty search result"; $_['text_enable'] = "Enable"; $_['text_enabled'] = "enabled"; $_['text_enter_one_email_address_per_line'] = "Enter one email address per line"; +$_['text_enter_one_group_per_line'] = "Enter one group per line"; $_['text_enter_search_terms'] = "Enter your search terms"; $_['text_error'] = "Error"; $_['text_exact_domain_name_or_email_address'] = "exact domain name or email address"; @@ -168,6 +169,7 @@ $_['text_memory_usage'] = "Memory usage"; $_['text_message'] = "message"; $_['text_messages'] = "messages"; $_['text_message_text'] = "Message text"; +$_['text_min_2_chars'] = "Min. 2 characters"; $_['text_missing_data'] = "Missing data"; $_['text_missing_password'] = "Missing password"; $_['text_modify'] = "Modify"; @@ -245,6 +247,10 @@ $_['text_save_search_terms'] = "Save search terms"; $_['text_saved_search_terms'] = "Saved search terms"; $_['text_search'] = "Search"; $_['text_search2'] = "search"; +$_['text_search_emails'] = "Search email addresses"; +$_['text_search_email_to_add'] = "Search email to add"; +$_['text_search_groups'] = "Search groups"; +$_['text_search_group_to_add'] = "Search group to add"; $_['text_search_terms'] = "Search terms"; $_['text_select_action'] = "Select action"; $_['text_select_all'] = "Select all"; diff --git a/webui/language/hu/messages.iso-8859-2.php b/webui/language/hu/messages.iso-8859-2.php index 02fb33ea..3ec3e621 100644 --- a/webui/language/hu/messages.iso-8859-2.php +++ b/webui/language/hu/messages.iso-8859-2.php @@ -86,6 +86,7 @@ $_['text_empty_search_result'] = "Nincs tal $_['text_enable'] = "Engedélyez"; $_['text_enabled'] = "engedélyezve"; $_['text_enter_one_email_address_per_line'] = "Egy sorba egy email címet írjon"; +$_['text_enter_one_group_per_line'] = "Egy sorba egy csoportnevet írjon"; $_['text_enter_search_terms'] = "Írja be a keresési feltételeket"; $_['text_error'] = "Hiba"; $_['text_exact_domain_name_or_email_address'] = "pontos domainnév vagy email cím"; @@ -169,6 +170,7 @@ $_['text_memory_usage'] = "Mem $_['text_message'] = "üzenet"; $_['text_messages'] = "üzenet"; $_['text_message_text'] = "Levél szöveg"; +$_['text_min_2_chars'] = "Min. 2 karakter"; $_['text_missing_data'] = "Hiányzó adat"; $_['text_missing_password'] = "Hiányzó jelszó"; $_['text_modify'] = "Módosítás"; @@ -246,6 +248,10 @@ $_['text_save_search_terms'] = "Keres $_['text_saved_search_terms'] = "Elmentett keresések"; $_['text_search'] = "Keresés"; $_['text_search2'] = "keresés"; +$_['text_search_emails'] = "Email címek keresése"; +$_['text_search_email_to_add'] = "írja be az email cím elejét"; +$_['text_search_groups'] = "Csoportok keresése"; +$_['text_search_group_to_add'] = "írja be a csoport nevének elejét"; $_['text_search_terms'] = "Keresési feltételek"; $_['text_select_action'] = "Művelet választás"; $_['text_select_all'] = "Mindegyik kijelölése"; diff --git a/webui/language/hu/messages.php b/webui/language/hu/messages.php index d20798ac..dba388b0 100644 --- a/webui/language/hu/messages.php +++ b/webui/language/hu/messages.php @@ -86,6 +86,7 @@ $_['text_empty_search_result'] = "Nincs találat a keresĂ©sre"; $_['text_enable'] = "EngedĂ©lyez"; $_['text_enabled'] = "engedĂ©lyezve"; $_['text_enter_one_email_address_per_line'] = "Egy sorba egy email cĂ­met Ă­rjon"; +$_['text_enter_one_group_per_line'] = "Egy sorba egy csoportnevet Ă­rjon"; $_['text_enter_search_terms'] = "ĂŤrja be a keresĂ©si feltĂ©teleket"; $_['text_error'] = "Hiba"; $_['text_exact_domain_name_or_email_address'] = "pontos domainnĂ©v vagy email cĂ­m"; @@ -169,6 +170,7 @@ $_['text_memory_usage'] = "MemĂłria használat"; $_['text_message'] = "ĂĽzenet"; $_['text_messages'] = "ĂĽzenet"; $_['text_message_text'] = "LevĂ©l szöveg"; +$_['text_min_2_chars'] = "Min. 2 karakter"; $_['text_missing_data'] = "HiányzĂł adat"; $_['text_missing_password'] = "HiányzĂł jelszĂł"; $_['text_modify'] = "MĂłdosĂ­tás"; @@ -246,6 +248,10 @@ $_['text_save_search_terms'] = "KeresĂ©si feltĂ©tel mentĂ©se"; $_['text_saved_search_terms'] = "Elmentett keresĂ©sek"; $_['text_search'] = "KeresĂ©s"; $_['text_search2'] = "keresĂ©s"; +$_['text_search_emails'] = "Email cĂ­mek keresĂ©se"; +$_['text_search_email_to_add'] = "Ă­rja be az email cĂ­m elejĂ©t"; +$_['text_search_groups'] = "Csoportok keresĂ©se"; +$_['text_search_group_to_add'] = "Ă­rja be a csoport nevĂ©nek elejĂ©t"; $_['text_search_terms'] = "KeresĂ©si feltĂ©telek"; $_['text_select_action'] = "Művelet választás"; $_['text_select_all'] = "Mindegyik kijelölĂ©se"; diff --git a/webui/model/group/group.php b/webui/model/group/group.php index 5f1ee153..45e4fbb9 100644 --- a/webui/model/group/group.php +++ b/webui/model/group/group.php @@ -140,6 +140,41 @@ class ModelGroupGroup extends Model { } + public function get_emails_by_string($s = '') { + if(strlen($s) < 2) { return array(); } + + $query = $this->db->query("SELECT email FROM `" . TABLE_EMAIL . "` WHERE email LIKE ? ORDER BY email ASC", array($s . "%") ); + + if(isset($query->rows)) { return $query->rows; } + + return array(); + } + + + public function get_groups_by_string($s = '') { + if(strlen($s) < 2) { return array(); } + + $query = $this->db->query("SELECT groupname FROM `" . TABLE_GROUP . "` WHERE groupname LIKE ? ORDER BY groupname ASC", array($s . "%") ); + + if(isset($query->rows)) { return $query->rows; } + + return array(); + } + + + public function get_groups_by_uid($uid = 0) { + $groups = ''; + + $query = $this->db->query("SELECT `" . TABLE_GROUP_USER . "`.id, groupname FROM `" . TABLE_GROUP_USER . "`, `" . TABLE_GROUP . "` WHERE `" . TABLE_GROUP_USER . "`.id=`" . TABLE_GROUP . "`.id AND uid=?", array($uid) ); + + if(isset($query->rows)) { + foreach ($query->rows as $q) { $groups .= "\n" . $q['groupname']; } + } + + return preg_replace("/^\n/", "", $groups); + } + + } ?> diff --git a/webui/model/search/message.php b/webui/model/search/message.php index fc3dc390..d515d6e1 100644 --- a/webui/model/search/message.php +++ b/webui/model/search/message.php @@ -57,8 +57,6 @@ class ModelSearchMessage extends Model { public function get_message_headers($id = '') { $data = ''; - //$f = $this->get_store_path($id); - //$msg = $this->decrypt_and_uncompress_file($f.".m"); $msg = $this->get_raw_message($id); $pos = strpos($msg, "\n\r\n"); @@ -95,8 +93,6 @@ class ModelSearchMessage extends Model { $msg = $this->get_raw_message($id); -//print "a: $msg\n"; - $a = explode("\n", $msg); $msg = ""; while(list($k, $l) = each($a)){ @@ -166,7 +162,7 @@ class ModelSearchMessage extends Model { if($this->check_boundary($boundary, $l) == 1){ if($text_plain == 1 || $has_text_plain == 0) { - $message .= $this->flush_body_chunk($body_chunk, $charset, $qp, $base64, $text_plain, $text_html); + $message .= $this->flush_body_chunk($body_chunk, $charset, $qp, $base64, $text_plain, $text_html); } $text_plain = $text_html = $qp = $base64 = 0; @@ -235,7 +231,6 @@ class ModelSearchMessage extends Model { $chunk = preg_replace("//", ">", $chunk); - //$chunk = "
\n" . $this->print_nicely($chunk) . "
\n"; $chunk = preg_replace("/\n/", "
\n", $chunk); $chunk = "\n" . $this->print_nicely($chunk); } diff --git a/webui/model/search/search.php b/webui/model/search/search.php index 161c4478..0620aef9 100644 --- a/webui/model/search/search.php +++ b/webui/model/search/search.php @@ -104,7 +104,7 @@ class ModelSearchSearch extends Model { $data['subject'] = $this->fixup_sphinx_operators($data['subject']); - if(Registry::get('admin_user') == 1 || Registry::get('auditor_user') == 1) { + if(Registry::get('auditor_user') == 1) { if($data['f_from']) { $f1 .= "|" . $data['f_from']; $n_fc++; } if($data['o_from']) { $f1 .= "|" . $data['o_from']; $n_fc++; } if($data['from_domain']) { $fd .= "(@fromdomain " . substr($data['from_domain'], 1, strlen($data['from_domain'])) . ")"; $n_fc++; } @@ -174,7 +174,7 @@ class ModelSearchSearch extends Model { private function assemble_simple_query_conditions($data = array(), $sort = 'sent', $order = 'DESC', $sortorder = '', $cache_key = '') { $email = $match = ""; - if(Registry::get('admin_user') == 0 && Registry::get('auditor_user') == 0) { + if(Registry::get('auditor_user') == 0) { $all_your_addresses = $this->get_all_your_address(); @@ -404,7 +404,7 @@ class ModelSearchSearch extends Model { public function get_message_recipients($id = '') { $rcpt = array(); - if(Registry::get('admin_user') == 0 && Registry::get('auditor_user') == 0) { return $rcpt; } + if(Registry::get('auditor_user') == 0) { return $rcpt; } $query = $this->db->query("SELECT `to` FROM " . VIEW_MESSAGES . " WHERE piler_id=?", array($id)); @@ -434,7 +434,7 @@ class ModelSearchSearch extends Model { if($id == '') { return 0; } - if(Registry::get('admin_user') == 1 || Registry::get('auditor_user') == 1) { return 1; } + if(Registry::get('auditor_user') == 1) { return 1; } array_push($arr, $id); @@ -463,7 +463,7 @@ class ModelSearchSearch extends Model { if(count($id) < 1) { return array(); } - if(Registry::get('admin_user') == 1 || Registry::get('auditor_user') == 1) { return $id; } + if(Registry::get('auditor_user') == 1) { return $id; } $arr = $id; diff --git a/webui/model/user/auth.php b/webui/model/user/auth.php index a9a58afa..b344d16e 100644 --- a/webui/model/user/auth.php +++ b/webui/model/user/auth.php @@ -4,7 +4,7 @@ class ModelUserAuth extends Model { public function checkLogin($username = '', $password = '') { - $query = $this->db->query("SELECT " . TABLE_USER . ".username, " . TABLE_USER . ".uid, " . TABLE_USER . ".gid, " . TABLE_USER . ".realname, " . TABLE_USER . ".dn, " . TABLE_USER . ".password, " . TABLE_USER . ".isadmin, " . TABLE_USER . ".domain FROM " . TABLE_USER . ", " . TABLE_EMAIL . " WHERE " . TABLE_EMAIL . ".email=? AND " . TABLE_EMAIL . ".uid=" . TABLE_USER . ".uid", array($username)); + $query = $this->db->query("SELECT " . TABLE_USER . ".username, " . TABLE_USER . ".uid, " . TABLE_USER . ".realname, " . TABLE_USER . ".dn, " . TABLE_USER . ".password, " . TABLE_USER . ".isadmin, " . TABLE_USER . ".domain FROM " . TABLE_USER . ", " . TABLE_EMAIL . " WHERE " . TABLE_EMAIL . ".email=? AND " . TABLE_EMAIL . ".uid=" . TABLE_USER . ".uid", array($username)); if(!isset($query->row['password'])) { return 0; } @@ -14,7 +14,6 @@ class ModelUserAuth extends Model { $_SESSION['username'] = $query->row['username']; $_SESSION['uid'] = $query->row['uid']; - $_SESSION['gid'] = $query->row['gid']; $_SESSION['admin_user'] = $query->row['isadmin']; $_SESSION['email'] = $username; $_SESSION['domain'] = $query->row['domain']; diff --git a/webui/model/user/user.php b/webui/model/user/user.php index 1465b005..3f7a481f 100644 --- a/webui/model/user/user.php +++ b/webui/model/user/user.php @@ -68,7 +68,8 @@ class ModelUserUser extends Model { } - $query = $this->db->query("SELECT email FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($gid)); + $query = $this->db->query("SELECT `" . TABLE_GROUP_EMAIL . "`.email FROM `" . TABLE_GROUP_EMAIL . "`, `" . TABLE_GROUP_USER . "` WHERE `" . TABLE_GROUP_EMAIL . "`.id=`" . TABLE_GROUP_USER . "`.id and `" . TABLE_GROUP_USER . "`.uid=?", array($uid) ); + if(isset($query->rows)) { foreach ($query->rows as $q) { @@ -181,14 +182,13 @@ class ModelUserUser extends Model { if($page_len > 0) { $limit = " LIMIT " . (int)$from . ", " . (int)$page_len; } - $query = $this->db->query("SELECT " . TABLE_USER . ".uid, gid, isadmin, username, realname, domain, email FROM " . TABLE_USER . "," . TABLE_EMAIL . " $where_cond group by " . TABLE_USER . ".uid $_order $limit"); + $query = $this->db->query("SELECT " . TABLE_USER . ".uid, isadmin, username, realname, domain, email FROM " . TABLE_USER . "," . TABLE_EMAIL . " $where_cond group by " . TABLE_USER . ".uid $_order $limit"); foreach ($query->rows as $q) { if(Registry::get('admin_user') == 1 || (isset($q['domain']) && $q['domain'] == $my_domain[0]) ) { $users[] = array( 'uid' => $q['uid'], - 'gid' => $q['gid'], 'username' => $q['username'], 'realname' => $q['realname'], 'domain' => isset($q['domain']) ? $q['domain'] : "", @@ -286,7 +286,7 @@ class ModelUserUser extends Model { $encrypted_password = crypt($user['password']); - $query = $this->db->query("INSERT INTO " . TABLE_USER . " (uid, gid, username, realname, password, domain, dn, isadmin) VALUES(?,?,?,?,?,?,?,?)", array((int)$user['uid'], (int)$user['gid'], $user['username'], $user['realname'], $encrypted_password, $user['domain'], @$user['dn'], (int)$user['isadmin'])); + $query = $this->db->query("INSERT INTO " . TABLE_USER . " (uid, username, realname, password, domain, dn, isadmin) VALUES(?,?,?,?,?,?,?)", array((int)$user['uid'], $user['username'], $user['realname'], $encrypted_password, $user['domain'], @$user['dn'], (int)$user['isadmin'])); if($query->error == 1 || $this->db->countAffected() == 0){ return $user['username']; } @@ -297,6 +297,7 @@ class ModelUserUser extends Model { if($ret == 0) { return -2; } } + $this->update_group_settings((int)$user['uid'], $user['group']); return 1; } @@ -350,7 +351,7 @@ class ModelUserUser extends Model { if($this->db->countAffected() != 1) { return 0; } } - $query = $this->db->query("UPDATE " . TABLE_USER . " SET username=?, realname=?, domain=?, gid=?, dn=?, isadmin=? WHERE uid=?", array($user['username'], $user['realname'], $user['domain'], $user['gid'], @$user['dn'], $user['isadmin'], (int)$user['uid'])); + $query = $this->db->query("UPDATE " . TABLE_USER . " SET username=?, realname=?, domain=?, dn=?, isadmin=? WHERE uid=?", array($user['username'], $user['realname'], $user['domain'], @$user['dn'], $user['isadmin'], (int)$user['uid'])); /* first, remove all his email addresses */ @@ -372,6 +373,34 @@ class ModelUserUser extends Model { } + $this->update_group_settings((int)$user['uid'], $user['group']); + + return 1; + } + + + private function update_group_settings($uid = -1, $group = '') { + + if($uid <= 0 || $group == '') { return 0; } + + $query = $this->db->query("DELETE FROM `" . TABLE_GROUP_USER . "` WHERE uid=?", array($uid)); + + $query = $this->db->query("SELECT id, groupname FROM `" . TABLE_GROUP . "`"); + + $groups = array(); + + foreach ($query->rows as $q) { + $groups[$q['groupname']] = $q['id']; + } + + $group = explode("\n", $group); + + foreach($group as $g) { + $g = rtrim($g); + + $query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, uid) VALUES(?,?)", array($groups[$g], (int)$uid)); + } + return 1; } diff --git a/webui/system/misc.php b/webui/system/misc.php index 36d13cb9..b23abed7 100644 --- a/webui/system/misc.php +++ b/webui/system/misc.php @@ -284,8 +284,6 @@ function assemble_search_url($term = '') { parse_str($term, $a); -//print_r($a); - if(isset($a['search'])) { $term_value = $a['search']; } if(isset($a['f'])) { @@ -410,28 +408,27 @@ function fetch_url($url = '') { function fixup_date_condition($field = '', $date1 = 0, $date2 = 0) { - $date = ""; + $date = ""; - if($date1) { - list($y,$m,$d) = explode("-", $date1); - $date1 = mktime(0, 0, 0, $m, $d, $y); + if($date1) { + list($y,$m,$d) = explode("-", $date1); + $date1 = mktime(0, 0, 0, $m, $d, $y); - if($date1 > 0) { $date .= "$field >= $date1 "; } + if($date1 > 0) { $date .= "$field >= $date1 "; } + } + + if($date2) { + list($y,$m,$d) = explode("-", $date2); + $date2 = mktime(23, 59, 59, $m, $d, $y); + + if($date2 > 0) { + if($date) { $date .= " AND "; } + $date .= "$field <= $date2 "; } + } - if($date2) { - list($y,$m,$d) = explode("-", $date2); - $date2 = mktime(23, 59, 59, $m, $d, $y); - if($date2 > 0) { - if($date) { $date .= " AND "; } - $date .= "$field <= $date2 "; - } - } - - //if($date) { $date .= " AND "; } - - return $date; + return $date; } diff --git a/webui/view/javascript/piler.js b/webui/view/javascript/piler.js index 52e05d0b..85d5951f 100644 --- a/webui/view/javascript/piler.js +++ b/webui/view/javascript/piler.js @@ -523,3 +523,55 @@ $(document).ready(function() { }); + + $(function() { + + $("#s_piler_email").autocomplete({ + source: email_search_url, + minLength: 2, + select: function( event, ui ) { + if(ui.item){ + var prefix = '\n'; + var a = document.getElementById("email"); + + if(a && a.value == '') prefix = ''; + + $('#email').val($('#email').val() + prefix + ui.item.value); + } + + ui.item.value = ''; + } + }); + + $("#s_piler_group").autocomplete({ + source: group_search_url, + minLength: 2, + select: function( event, ui ) { + if(ui.item){ + var prefix = '\n'; + var a = document.getElementById("group"); + + if(a && a.value == '') prefix = ''; + + $('#group').val($('#group').val() + prefix + ui.item.value); + } + + ui.item.value = ''; + } + }); + + + }); + + +function toggle_hint(id, s, focus) { + + if(focus == 1){ + if(document.getElementById(id).value == s) document.getElementById(id).value = ''; + } + else { + if(document.getElementById(id).value == '') document.getElementById(id).value = s; + } +} + + diff --git a/webui/view/theme/default/stylesheet/style-default.css b/webui/view/theme/default/stylesheet/style-default.css index 7285111c..46bd656a 100644 --- a/webui/view/theme/default/stylesheet/style-default.css +++ b/webui/view/theme/default/stylesheet/style-default.css @@ -65,6 +65,7 @@ .restore_spinner { text-align: center; border: 0px solid black; } .text { font: normal 12px Arial, sans-serif; font-weight: bold; text-align:left; width: 408px; } + .autocompletetext { font: normal 12px Arial, sans-serif; font-style: italic; color: gray; font-weight: bold; text-align:left; width: 408px; } .ruletext { font: normal 12px Arial, sans-serif; font-weight: bold; text-align:left; width: 365px; } .advtext { font: bold 12px Arial, sans-serif; font-weight: bold; text-align:left; width: 280px; } .tagtext { font: normal 10px Arial, sans-serif; font-weight: bold; text-align:left; width: 265px; } diff --git a/webui/view/theme/default/templates/common/layout.tpl b/webui/view/theme/default/templates/common/layout.tpl index 8f00ec6c..7a7861cb 100644 --- a/webui/view/theme/default/templates/common/layout.tpl +++ b/webui/view/theme/default/templates/common/layout.tpl @@ -16,9 +16,12 @@ + diff --git a/webui/view/theme/default/templates/group/add.tpl b/webui/view/theme/default/templates/group/add.tpl index 9a3d7df2..f449a096 100644 --- a/webui/view/theme/default/templates/group/add.tpl +++ b/webui/view/theme/default/templates/group/add.tpl @@ -12,13 +12,18 @@
-
*:
+
*:
+
+
+ +
+
**:
 
-
*:
+
*:
**:
diff --git a/webui/view/theme/default/templates/group/edit.tpl b/webui/view/theme/default/templates/group/edit.tpl index 289738a5..2c618d45 100644 --- a/webui/view/theme/default/templates/group/edit.tpl +++ b/webui/view/theme/default/templates/group/edit.tpl @@ -10,17 +10,22 @@
:
-
+
-
*:
-
+
*:
+
+
+ +
+
**:
+
 
-
*:
+
*:
**:
@@ -33,6 +38,7 @@ +

 

:

 

diff --git a/webui/view/theme/default/templates/user/add.tpl b/webui/view/theme/default/templates/user/add.tpl index fa2bfa1d..70541bd5 100644 --- a/webui/view/theme/default/templates/user/add.tpl +++ b/webui/view/theme/default/templates/user/add.tpl @@ -32,17 +32,14 @@
+
+
*:
+
+
-
:
-
- -
+
**:
+
@@ -76,6 +73,11 @@ +
+
 
+
*:
**:
+
+
 
diff --git a/webui/view/theme/default/templates/user/edit.tpl b/webui/view/theme/default/templates/user/edit.tpl index 174a3d92..7dbfdde1 100644 --- a/webui/view/theme/default/templates/user/edit.tpl +++ b/webui/view/theme/default/templates/user/edit.tpl @@ -35,17 +35,14 @@
-
:
-
- -
+
*:
+
+
+
**:
+
+
@@ -90,6 +87,11 @@
+
+
 
+
*:
**:
+
+