From 0802ce899388b11f93416da0837a6b8ac862c5e3 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 24 Feb 2012 13:52:39 +0000 Subject: [PATCH] Added aggregating groups --- src/messenger/webim/default.css | 14 ++++++ src/messenger/webim/install/dbinfo.php | 6 ++- src/messenger/webim/install/dbperform.php | 9 ++++ src/messenger/webim/libs/chat.php | 52 +++++++++++--------- src/messenger/webim/libs/getcode.php | 2 +- src/messenger/webim/libs/groups.php | 27 ++++++++++ src/messenger/webim/libs/operator.php | 26 ++++++++-- src/messenger/webim/locales/en/properties | 3 ++ src/messenger/webim/locales/ru/properties | 3 ++ src/messenger/webim/operator/group.php | 44 +++++++++++------ src/messenger/webim/operator/update.php | 2 +- src/messenger/webim/view/canned.php | 2 +- src/messenger/webim/view/gen_button.php | 2 +- src/messenger/webim/view/group.php | 17 +++++-- src/messenger/webim/view/groups.php | 2 +- src/messenger/webim/view/operator_groups.php | 2 +- 16 files changed, 158 insertions(+), 55 deletions(-) diff --git a/src/messenger/webim/default.css b/src/messenger/webim/default.css index 6ad63ce4..5da5b8e3 100644 --- a/src/messenger/webim/default.css +++ b/src/messenger/webim/default.css @@ -329,6 +329,13 @@ div.errinfo { background: url(images/subitem.gif) no-repeat 10px 2px; } +.forminner .level0{ +} + +.forminner .level1{ + padding-left: 20px; +} + .fieldinrow { min-width: 300px; display: inline; @@ -502,6 +509,13 @@ table.list tbody tr:hover td, table.list tbody tr:hover td a, table.statistics t color: #1D485E; } +table.list td.level0{ +} + +table.list td.level1{ + padding-left: 20px; +} + /* awaiting */ table.awaiting { diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index 95d57ef8..7edbb2bd 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -28,6 +28,7 @@ $dbtables = array( "vclocaldescription" => "varchar(1024) NOT NULL", "vccommondescription" => "varchar(1024) NOT NULL", "iweight" => "int NOT NULL DEFAULT 0", + "parent" => "int DEFAULT NULL", ), "${mysqlprefix}chatthread" => array( @@ -146,6 +147,9 @@ $dbtables = array( ); $dbtables_indexes = array( + "${mysqlprefix}chatgroup" => array( + "parent" => "parent" + ), "${mysqlprefix}chatmessage" => array( "idx_agentid" => "agentid" ), @@ -164,7 +168,7 @@ $dbtables_can_update = array( "${mysqlprefix}chatmessage" => array("agentId"), "${mysqlprefix}chatoperator" => array("vcavatar", "vcjabbername", "iperm", "istatus", "idisabled", "vcemail", "dtmrestore", "vcrestoretoken"), "${mysqlprefix}chatban" => array(), - "${mysqlprefix}chatgroup" => array("vcemail", "iweight"), + "${mysqlprefix}chatgroup" => array("vcemail", "iweight", "parent"), "${mysqlprefix}chatgroupoperator" => array(), "${mysqlprefix}chatresponses" => array("vctitle"), "${mysqlprefix}chatsitevisitor" => array(), diff --git a/src/messenger/webim/install/dbperform.php b/src/messenger/webim/install/dbperform.php index b84222e1..a3e6f058 100644 --- a/src/messenger/webim/install/dbperform.php +++ b/src/messenger/webim/install/dbperform.php @@ -171,6 +171,15 @@ if ($act == "silentcreateall") { runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD iweight int DEFAULT 0", $link); } + if (in_array("${mysqlprefix}chatgroup.parent", $absent)) { + runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD parent int DEFAULT NULL AFTER groupid", $link); + } + + $res = mysql_query("select null from information_schema.statistics where table_schema = '$mysqldb' and table_name = '${mysqlprefix}chatgroup' and index_name = 'parent'", $link); + if ($res && mysql_num_rows($res) == 0) { + runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD INDEX (parent)", $link); + } + $res = mysql_query("select null from information_schema.statistics where table_schema = '$mysqldb' and table_name = '${mysqlprefix}chatmessage' and index_name = 'idx_agentid'", $link); if ($res && mysql_num_rows($res) == 0) { runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD INDEX idx_agentid (agentid)", $link); diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index bf92fbea..4bf8c9c3 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -331,34 +331,40 @@ function setup_survey($name, $email, $groupid, $info, $referrer) $page['forminfo'] = topage($info); $page['referrer'] = urlencode(topage($referrer)); + $selectedgroupid = $groupid; + if ($settings['enablegroups'] == '1' && $settings["surveyaskgroup"] == "1") { $link = connect(); - $allgroups = get_groups($link, false); - close_connection($link); - $val = ""; - $groupdescriptions = array(); - foreach ($allgroups as $k) { - $groupname = $k['vclocalname']; - if ($k['inumofagents'] == 0) { - continue; - } - if ($k['ilastseen'] !== NULL && $k['ilastseen'] < $settings['online_timeout']) { - if (!$groupid) { - $groupid = $k['groupid']; // select first online group + $showgroups = ($groupid == '')?true:group_has_children($groupid, $link); + if ($showgroups) { + $allgroups = get_groups($link, false); + close_connection($link); + $val = ""; + $groupdescriptions = array(); + foreach ($allgroups as $k) { + $groupname = $k['vclocalname']; + if ($k['inumofagents'] == 0 || ($groupid && $k['parent'] != $groupid && $k['groupid'] != $groupid )) { + continue; } - } else { - $groupname .= " (offline)"; + if ($k['ilastseen'] !== NULL && $k['ilastseen'] < $settings['online_timeout']) { + if (!$selectedgroupid) { + $selectedgroupid = $k['groupid']; // select first online group + } + } else { + $groupname .= " (offline)"; + } + $isselected = $k['groupid'] == $selectedgroupid; + if ($isselected) { + $defaultdescription = $k['vclocaldescription']; + } + $val .= ""; + $groupdescriptions[] = $k['vclocaldescription']; } - $isselected = $k['groupid'] == $groupid; - if ($isselected) { - $defaultdescription = $k['vclocaldescription']; - } - $val .= ""; - $groupdescriptions[] = $k['vclocaldescription']; + $page['groups'] = $val; + $page['group.descriptions'] = json_encode($groupdescriptions); + $page['default.department.description'] = empty($defaultdescription)?' ':$defaultdescription; } - $page['groups'] = $val; - $page['group.descriptions'] = json_encode($groupdescriptions); - $page['default.department.description'] = empty($defaultdescription)?' ':$defaultdescription; + close_connection($link); } $page['showemail'] = $settings["surveyaskmail"] == "1" ? "1" : ""; diff --git a/src/messenger/webim/libs/getcode.php b/src/messenger/webim/libs/getcode.php index 747dabbb..99bca9f1 100644 --- a/src/messenger/webim/libs/getcode.php +++ b/src/messenger/webim/libs/getcode.php @@ -72,7 +72,7 @@ function get_groups_list() $link = connect(); $allgroups = get_all_groups($link); close_connection($link); - $result[] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group")); + $result[] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"), 'level' => 0); foreach ($allgroups as $g) { $result[] = $g; } diff --git a/src/messenger/webim/libs/groups.php b/src/messenger/webim/libs/groups.php index 1a02c3f8..1abfe89b 100644 --- a/src/messenger/webim/libs/groups.php +++ b/src/messenger/webim/libs/groups.php @@ -66,4 +66,31 @@ function get_operator_groupslist($operatorid, $link) } } +function get_available_parent_groups($skipgroup) +{ + global $mysqlprefix; + $link = connect(); + $query = "select ${mysqlprefix}chatgroup.groupid as groupid, parent, vclocalname from ${mysqlprefix}chatgroup order by vclocalname"; + $groupslist = select_multi_assoc($query, $link); + $result = array(array('groupid' => '', 'level' => '', 'vclocalname' => getlocal("form.field.groupparent.root"))); + + if ($skipgroup) { + $skipgroup = (array)$skipgroup; + } else { + $skipgroup = array(); + } + + $result = array_merge($result, get_sorted_child_groups_($groupslist, $skipgroup, 0) ); + close_connection($link); + return $result; +} + +function group_has_children($groupid, $link) +{ + global $mysqlprefix; + $children = select_one_row(sprintf("select COUNT(*) as count from ${mysqlprefix}chatgroup where parent = %u", $groupid), + $link); + return ($children['count'] > 0); +} + ?> diff --git a/src/messenger/webim/libs/operator.php b/src/messenger/webim/libs/operator.php index 470ba9ab..f5fc9826 100755 --- a/src/messenger/webim/libs/operator.php +++ b/src/messenger/webim/libs/operator.php @@ -176,7 +176,8 @@ function has_online_operators($groupid = "") $link = connect(); $query = "select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time from ${mysqlprefix}chatoperator"; if ($groupid) { - $query .= ", ${mysqlprefix}chatgroupoperator where groupid = $groupid and ${mysqlprefix}chatoperator.operatorid = " . + $query .= ", ${mysqlprefix}chatgroupoperator, ${mysqlprefix}chatgroup where ${mysqlprefix}chatgroup.groupid = ${mysqlprefix}chatgroupoperator.groupid and " . + "(${mysqlprefix}chatgroup.groupid = $groupid or ${mysqlprefix}chatgroup.parent = $groupid) and ${mysqlprefix}chatoperator.operatorid = " . "${mysqlprefix}chatgroupoperator.operatorid and istatus = 0"; } else { if ($settings['enablegroups'] == 1) { @@ -390,14 +391,29 @@ function prepare_menu($operator, $hasright = true) function get_all_groups($link) { global $mysqlprefix; - $query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription from ${mysqlprefix}chatgroup order by vclocalname"; - return select_multi_assoc($query, $link); + $query = "select ${mysqlprefix}chatgroup.groupid as groupid, parent, vclocalname, vclocaldescription from ${mysqlprefix}chatgroup order by vclocalname"; + return get_sorted_child_groups_(select_multi_assoc($query, $link)); +} + +function get_sorted_child_groups_($groupslist, $skipgroups = array(), $maxlevel = -1, $groupid = NULL, $level = 0) +{ + $child_groups = array(); + foreach ($groupslist as $index => $group) { + if ($group['parent'] == $groupid && !in_array($group['groupid'], $skipgroups)) { + $group['level'] = $level; + $child_groups[] = $group; + if ($maxlevel == -1 || $level < $maxlevel) { + $child_groups = array_merge($child_groups, get_sorted_child_groups_($groupslist, $skipgroups, $maxlevel, $group['groupid'], $level+1)); + } + } + } + return $child_groups; } function get_groups($link, $checkaway) { global $mysqlprefix; - $query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription, iweight" . + $query = "select ${mysqlprefix}chatgroup.groupid as groupid, parent, vclocalname, vclocaldescription, iweight" . ", (SELECT count(*) from ${mysqlprefix}chatgroupoperator where ${mysqlprefix}chatgroup.groupid = " . "${mysqlprefix}chatgroupoperator.groupid) as inumofagents" . ", (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " . @@ -412,7 +428,7 @@ function get_groups($link, $checkaway) : "" ) . " from ${mysqlprefix}chatgroup order by iweight, vclocalname"; - return select_multi_assoc($query, $link); + return get_sorted_child_groups_(select_multi_assoc($query, $link)); } function get_operator_groupids($operatorid) diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index fad50795..a1f81e22 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -154,6 +154,9 @@ form.field.groupdesc=Description form.field.groupemail.description=Group email for notifications. Leave empty to use the default address. form.field.groupname.description=Name to identify the group. form.field.groupname=Name +form.field.groupparent=Parent group +form.field.groupparent.description=Groups can be organized in a hierarchical structure +form.field.groupparent.root=<none> form.field.groupweight=Weight form.field.groupweight.description=Groups with lower weight display higher in groups list. Group weight is a positive integer value. form.field.login.description=Login can consist of small Latin letters and underscore. diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index 184029e5..b79d8738 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -152,6 +152,9 @@ form.field.groupdesc= form.field.groupemail.description=Адрес для извещений. Оставьте пустым, чтобы использовать глобальный адрес. form.field.groupname.description=Может быть названием отдела в вашей компании. form.field.groupname=Название группы +form.field.groupparent=Родительская группа +form.field.groupparent.description=Группы могут быть организованы в иерархическую структуру +form.field.groupparent.root=<нет> form.field.groupweight=Вес группы form.field.groupweight.description=Группы с меньшим весом отображаются выше в списке групп. Вес - это целое положительное число. form.field.login.description=Логин может состоять из маленьких латинских букв и знака подчеркивания. diff --git a/src/messenger/webim/operator/group.php b/src/messenger/webim/operator/group.php index fd90ade9..b4a5af1d 100644 --- a/src/messenger/webim/operator/group.php +++ b/src/messenger/webim/operator/group.php @@ -39,18 +39,19 @@ function group_by_name($name) return $group; } -function create_group($name, $descr, $commonname, $commondescr, $weight ,$email) +function create_group($name, $descr, $commonname, $commondescr, $email, $weight, $parentgroup) { global $mysqlprefix; $link = connect(); $query = sprintf( - "insert into ${mysqlprefix}chatgroup (vclocalname,vclocaldescription,vccommonname,vccommondescription,iweight,vcemail) values ('%s','%s','%s','%s',%u,'%s')", + "insert into ${mysqlprefix}chatgroup (parent, vclocalname,vclocaldescription,vccommonname,vccommondescription,vcemail,iweight) values (%s, '%s','%s','%s','%s','%s',%u)", + ($parentgroup?(int)$parentgroup:'NULL'), db_escape_string($name), db_escape_string($descr), db_escape_string($commonname), db_escape_string($commondescr), - $weight, - db_escape_string($email)); + db_escape_string($email), + $weight); perform_query($query, $link); $id = db_insert_id($link); @@ -60,42 +61,50 @@ function create_group($name, $descr, $commonname, $commondescr, $weight ,$email) return $newdep; } -function update_group($groupid, $name, $descr, $commonname, $commondescr, $weight, $email) +function update_group($groupid, $name, $descr, $commonname, $commondescr, $email, $weight, $parentgroup) { global $mysqlprefix; $link = connect(); $query = sprintf( - "update ${mysqlprefix}chatgroup set vclocalname = '%s', vclocaldescription = '%s', vccommonname = '%s', vccommondescription = '%s', iweight = %u, vcemail = '%s' where groupid = %s", + "update ${mysqlprefix}chatgroup set parent = %s, vclocalname = '%s', vclocaldescription = '%s', vccommonname = '%s', vccommondescription = '%s', vcemail = '%s', iweight = %u where groupid = %s", + ($parentgroup?(int)$parentgroup:'NULL'), db_escape_string($name), db_escape_string($descr), db_escape_string($commonname), db_escape_string($commondescr), - $weight, db_escape_string($email), + $weight, $groupid); - perform_query($query, $link); + + if ($parentgroup) { + $query = sprintf("update ${mysqlprefix}chatgroup set parent = NULL where parent = %u", $groupid); + perform_query($query, $link); + } close_connection($link); } - if (isset($_POST['name'])) { $groupid = verifyparam("gid", "/^(\d{1,9})?$/", ""); $name = getparam('name'); $description = getparam('description'); $commonname = getparam('commonname'); $commondescription = getparam('commondescription'); - $weight = getparam('weight'); $email = getparam('email'); + $weight = getparam('weight'); + $parentgroup = verifyparam("parentgroup", "/^(\d{1,9})?$/", ""); if (!$name) $errors[] = no_field("form.field.groupname"); + if ($email != '' && !is_valid_email($email)) + $errors[] = wrong_field("form.field.mail"); + if (! preg_match("/^\d{1,9}$/", $weight)) $errors[] = wrong_field("form.field.groupweight"); - if ($email != '' && !is_valid_email($email)) - $errors[] = wrong_field("form.field.mail"); + if (! $parentgroup) + $parentgroup = NULL; $existing_group = group_by_name($name); if ((!$groupid && $existing_group) || @@ -104,11 +113,11 @@ if (isset($_POST['name'])) { if (count($errors) == 0) { if (!$groupid) { - $newdep = create_group($name, $description, $commonname, $commondescription, $weight, $email); + $newdep = create_group($name, $description, $commonname, $commondescription, $email, $weight, $parentgroup); header("Location: $webimroot/operator/groupmembers.php?gid=" . $newdep['groupid']); exit; } else { - update_group($groupid, $name, $description, $commonname, $commondescription, $weight, $email); + update_group($groupid, $name, $description, $commonname, $commondescription, $email, $weight, $parentgroup); header("Location: $webimroot/operator/group.php?gid=$groupid&stored"); exit; } @@ -117,8 +126,9 @@ if (isset($_POST['name'])) { $page['formdescription'] = topage($description); $page['formcommonname'] = topage($commonname); $page['formcommondescription'] = topage($commondescription); - $page['formweight'] = topage($weight); $page['formemail'] = topage($email); + $page['formweight'] = topage($weight); + $page['formparentgroup'] = topage($parentgroup); $page['grid'] = topage($groupid); } @@ -134,13 +144,15 @@ if (isset($_POST['name'])) { $page['formdescription'] = topage($group['vclocaldescription']); $page['formcommonname'] = topage($group['vccommonname']); $page['formcommondescription'] = topage($group['vccommondescription']); - $page['formweight'] = topage($group['iweight']); $page['formemail'] = topage($group['vcemail']); + $page['formweight'] = topage($group['iweight']); + $page['formparentgroup'] = topage($group['parent']); $page['grid'] = topage($group['groupid']); } } $page['stored'] = isset($_GET['stored']); +$page['availableParentGroups'] = get_available_parent_groups($groupid); prepare_menu($operator); setup_group_settings_tabs($groupid, 0); start_html_output(); diff --git a/src/messenger/webim/operator/update.php b/src/messenger/webim/operator/update.php index ac36d9bd..ec4ea5f9 100644 --- a/src/messenger/webim/operator/update.php +++ b/src/messenger/webim/operator/update.php @@ -129,7 +129,7 @@ function print_pending_threads($groupids, $since) : "") . ($settings['enablegroups'] == '1' ? "AND (groupid is NULL" . ($groupids - ? " OR groupid IN ($groupids)" + ? " OR groupid IN ($groupids) OR groupid IN (SELECT parent FROM ${mysqlprefix}chatgroup WHERE groupid IN ($groupids)) " : "") . ") " : "") . diff --git a/src/messenger/webim/view/canned.php b/src/messenger/webim/view/canned.php index 0c913a11..9a7eddea 100644 --- a/src/messenger/webim/view/canned.php +++ b/src/messenger/webim/view/canned.php @@ -49,7 +49,7 @@ require_once('inc_errors.php');
diff --git a/src/messenger/webim/view/gen_button.php b/src/messenger/webim/view/gen_button.php index 26bd1853..fbdb87dd 100644 --- a/src/messenger/webim/view/gen_button.php +++ b/src/messenger/webim/view/gen_button.php @@ -74,7 +74,7 @@ require_once('inc_errors.php');
- +

diff --git a/src/messenger/webim/view/group.php b/src/messenger/webim/view/group.php index 7831c2b4..9315428e 100644 --- a/src/messenger/webim/view/group.php +++ b/src/messenger/webim/view/group.php @@ -86,6 +86,15 @@ require_once('inc_errors.php');
+
+
+
+ +
+
+
+
+
@@ -96,14 +105,14 @@ require_once('inc_errors.php');
-
+
- +
-
+

- +
diff --git a/src/messenger/webim/view/groups.php b/src/messenger/webim/view/groups.php index e62159f1..43a87248 100644 --- a/src/messenger/webim/view/groups.php +++ b/src/messenger/webim/view/groups.php @@ -73,7 +73,7 @@ require_once('inc_errors.php'); if(count($page['groups']) > 0) { foreach( $page['groups'] as $grp ) { ?> - + diff --git a/src/messenger/webim/view/operator_groups.php b/src/messenger/webim/view/operator_groups.php index 736398ad..67532f50 100644 --- a/src/messenger/webim/view/operator_groups.php +++ b/src/messenger/webim/view/operator_groups.php @@ -48,7 +48,7 @@ require_once('inc_errors.php');

-
+
/>