diff --git a/src/messenger/webim/libs/operator.php b/src/messenger/webim/libs/operator.php
index ad4d33f2..74f255d3 100755
--- a/src/messenger/webim/libs/operator.php
+++ b/src/messenger/webim/libs/operator.php
@@ -450,9 +450,28 @@ function get_sorted_child_groups_($groupslist, $skipgroups = array(), $maxlevel
return $child_groups;
}
-function get_groups_($link, $operator, $checkaway)
+function get_groups_($link, $checkaway, $operator, $order = NULL)
{
global $mysqlprefix;
+
+ if($order){
+ switch($order['by']){
+ case 'weight':
+ $orderby = "iweight";
+ break;
+ case 'lastseen':
+ $orderby = "ilastseen";
+ break;
+ default:
+ $orderby = "${mysqlprefix}chatgroup.vclocalname";
+ }
+ $orderby = sprintf(" IF(ISNULL(${mysqlprefix}chatgroup.parent),CONCAT('_',%s),'') %s, ${mysqlprefix}chatgroup.iweight ",
+ $orderby,
+ ($order['desc']?'DESC':'ASC'));
+ }else{
+ $orderby = "iweight, vclocalname";
+ }
+
$query = "select ${mysqlprefix}chatgroup.groupid as groupid, ${mysqlprefix}chatgroup.parent as parent, vclocalname, vclocaldescription, iweight" .
", (SELECT count(*) from ${mysqlprefix}chatgroupoperator where ${mysqlprefix}chatgroup.groupid = " .
"${mysqlprefix}chatgroupoperator.groupid) as inumofagents" .
@@ -474,18 +493,23 @@ function get_groups_($link, $operator, $checkaway)
"where ${mysqlprefix}chatgroup.groupid = i.parent or ${mysqlprefix}chatgroup.parent = i.parent "
: ""
) .
- " order by iweight, vclocalname";
+ " order by " . $orderby;
return get_sorted_child_groups_(select_multi_assoc($query, $link));
}
function get_groups($link, $checkaway)
{
- return get_groups_($link, NULL, $checkaway);
+ return get_groups_($link, $checkaway, NULL);
}
function get_groups_for_operator($link, $operator, $checkaway)
{
- return get_groups_($link, $operator, $checkaway);
+ return get_groups_($link, $checkaway, $operator);
+}
+
+function get_sorted_groups($link, $order)
+{
+ return get_groups_($link, true, NULL, $order);
}
function get_operator_groupids($operatorid)
diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties
index 499cb548..c5cb376b 100644
--- a/src/messenger/webim/locales/en/properties
+++ b/src/messenger/webim/locales/en/properties
@@ -301,6 +301,10 @@ page.groups.intro=This page displays a list of groups. Each group can have separ
page.groups.isaway=Away
page.groups.isonline=Online
page.groups.new=Create new group
+page.groups.sort=Sort by:
+page.groups.sortdirection=Sort direction:
+page.groups.sortdirection.desc=descending
+page.groups.sortdirection.asc=ascending
page.groups.title=Groups
page.groups.weight=Weight
page.preview.agentchat=Chat window (operator-mode)
diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties
index 4b7f7585..4c8d6edd 100644
--- a/src/messenger/webim/locales/ru/properties
+++ b/src/messenger/webim/locales/ru/properties
@@ -299,6 +299,10 @@ page.groups.intro=
page.groups.isaway=Away
page.groups.isonline=Доступна
page.groups.new=Добавить группу...
+page.groups.sort=Сортировать по:
+page.groups.sortdirection=Направление сортировки:
+page.groups.sortdirection.desc=по убыванию
+page.groups.sortdirection.asc=по возрастанию
page.groups.title=Группы
page.groups.weight=Вес
page.preview.agentchat=Окно чата (со стороны оператора)
diff --git a/src/messenger/webim/operator/groups.php b/src/messenger/webim/operator/groups.php
index 6d053aa5..3c336b79 100644
--- a/src/messenger/webim/operator/groups.php
+++ b/src/messenger/webim/operator/groups.php
@@ -61,10 +61,23 @@ function is_away($group)
$page = array();
+$sort['by'] = verifyparam("sortby", "/^(name|lastseen|weight)$/", "name");
+$sort['desc'] = (verifyparam("sortdirection", "/^(desc|asc)$/", "desc") == "desc");
$link = connect();
-$page['groups'] = get_groups($link, true);
+$page['groups'] = get_sorted_groups($link, $sort);
close_connection($link);
+$page['formsortby'] = $sort['by'];
+$page['formsortdirection'] = $sort['desc']?'desc':'asc';
$page['canmodify'] = is_capable($can_administrate, $operator);
+$page['availableOrders'] = array(
+ array('id' => 'name', 'name' => getlocal('form.field.groupname')),
+ array('id' => 'lastseen', 'name' => getlocal('page_agents.status')),
+ array('id' => 'weight', 'name' => getlocal('page.groups.weight'))
+);
+$page['availableDirections'] = array(
+ array('id' => 'desc', 'name' => getlocal('page.groups.sortdirection.desc')),
+ array('id' => 'asc', 'name' => getlocal('page.groups.sortdirection.asc')),
+);
prepare_menu($operator);
start_html_output();
diff --git a/src/messenger/webim/view/groups.php b/src/messenger/webim/view/groups.php
index 43a87248..209ee5e9 100644
--- a/src/messenger/webim/view/groups.php
+++ b/src/messenger/webim/view/groups.php
@@ -49,6 +49,33 @@ require_once('inc_errors.php');
+