diff --git a/src/messenger/webim/libs/operator.php b/src/messenger/webim/libs/operator.php index 74f255d3..0589ede7 100755 --- a/src/messenger/webim/libs/operator.php +++ b/src/messenger/webim/libs/operator.php @@ -68,6 +68,64 @@ function operator_by_id($id) return $operator; } +/** + * Get list of operators taking into account $options + * @param array $options Associative array of options. It can contains following keys: + * - 'sort': an associative array of sorting options. + * - 'isolated_operator_id': id of current operators. If it set - function would return + * only operators from adjacent groups. + * + * 'sort' array must contains two keys: 'by' and 'desc'. + * 'by' means the field by which operators would be sort and can take following + * values: 'commonname', 'localename', 'login', 'lastseen'. 'desc' means order in which operators would + * be sort. If it's 'true' operators would be sort in descending order and in + * ascending order overwise. + * + */ +function get_operators_list($options) +{ + global $mysqlprefix; + $link = connect(); + + if ( !empty($options['sort']) && isset($options['sort']['by']) && isset($options['sort']['desc'])) { + switch ($options['sort']['by']) { + case 'commonname': + $orderby = 'vccommonname'; + break; + case 'localename': + $orderby = 'vclocalename'; + break; + case 'lastseen': + $orderby = 'time'; + break; + default: + $orderby = 'vclogin'; + break; + } + $orderby = $orderby . ' ' . ($options['sort']['desc']?'DESC':'ASC'); + } else { + $orderby = "vclogin"; + } + + $query = "select distinct ${mysqlprefix}chatoperator.operatorid, vclogin, vclocalename, vccommonname, istatus, idisabled, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " . + "from ${mysqlprefix}chatoperator" . + ( + empty($options['isolated_operator_id']) ? "" : + sprintf(", ${mysqlprefix}chatgroupoperator " . + " where ${mysqlprefix}chatoperator.operatorid = ${mysqlprefix}chatgroupoperator.operatorid and ${mysqlprefix}chatgroupoperator.groupid in " . + "(select g.groupid from ${mysqlprefix}chatgroup g, " . + "(select distinct parent from ${mysqlprefix}chatgroup, ${mysqlprefix}chatgroupoperator " . + "where ${mysqlprefix}chatgroup.groupid = ${mysqlprefix}chatgroupoperator.groupid and ${mysqlprefix}chatgroupoperator.operatorid = %u) i " . + "where g.groupid = i.parent or g.parent = i.parent " . + ")", $options['isolated_operator_id']) + ) . + " order by " . $orderby; + + $operators = select_multi_assoc($query, $link); + close_connection($link); + return $operators; +} + function operator_get_all() { global $mysqlprefix; diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index 9d7c524d..776a7dc3 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -347,6 +347,7 @@ page_agent.tab.permissions=Permissions page_agent.title=Operator details page_agents.agent_name=Name page_agents.agents=Full list of operators: +page_agents.commonname=International name page_agents.confirm=Are you sure that you want to delete operator "{0}"? page_agents.cannot.disable.admin=Cannot disable "admin". page_agents.cannot.disable.self=Cannot disable self. @@ -362,6 +363,10 @@ page_agents.isaway=Away page_agents.isonline=Online page_agents.login=Login page_agents.new_agent=Add operator... +page_agents.sort=Sort by: +page_agents.sortdirection=Sort direction: +page_agents.sortdirection.desc=descending +page_agents.sortdirection.asc=ascending page_agents.status=Last active page_agents.title=Operators page_analysis.full.text.search=User name, operator name or message text search: diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index 72f7990b..d6c63334 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -345,6 +345,7 @@ page_agent.tab.permissions= page_agent.title=Детали оператора page_agents.agent_name=Имя page_agents.agents=Полный список операторов: +page_agents.commonname=Интернациональное имя page_agents.confirm=Вы уверены что хотите удалить оператора "{0}"? page_agents.cannot.disable.admin=Невозможно заблокировать оператора "admin". page_agents.cannot.disable.self=Невозможно заблокировать себя. @@ -360,6 +361,10 @@ page_agents.isaway= page_agents.isonline=Доступен page_agents.login=Логин page_agents.new_agent=Добавить оператора... +page_agents.sort=Сортировать по: +page_agents.sortdirection=Направление сортировки: +page_agents.sortdirection.desc=по убыванию +page_agents.sortdirection.asc=по возрастанию page_agents.status=Последний раз page_agents.title=Операторы page_analysis.full.text.search=Поиск по имени посетителя, имени оператора или по тексту сообщения: diff --git a/src/messenger/webim/operator/operators.php b/src/messenger/webim/operator/operators.php index f6c2de41..729fc2c9 100644 --- a/src/messenger/webim/operator/operators.php +++ b/src/messenger/webim/operator/operators.php @@ -92,8 +92,26 @@ if (isset($_GET['act'])) { } $page = array(); -$page['allowedAgents'] = in_isolation($operator)?get_operators_from_adjacent_groups($operator):operator_get_all(); +$sort['by'] = verifyparam("sortby", "/^(login|commonname|localename|lastseen)$/", "login"); +$sort['desc'] = (verifyparam("sortdirection", "/^(desc|asc)$/", "desc") == "desc"); +$page['formsortby'] = $sort['by']; +$page['formsortdirection'] = $sort['desc']?'desc':'asc'; +$list_options['sort'] = $sort; +if (in_isolation($operator)) { + $list_options['isolated_operator_id'] = $operator['operatorid']; +} +$page['allowedAgents'] = get_operators_list($list_options); $page['canmodify'] = is_capable($can_administrate, $operator); +$page['availableOrders'] = array( + array('id' => 'login', 'name' => getlocal('page_agents.login')), + array('id' => 'localename', 'name' => getlocal('page_agents.agent_name')), + array('id' => 'commonname', 'name' => getlocal('page_agents.commonname')), + array('id' => 'lastseen', 'name' => getlocal('page_agents.status')) +); +$page['availableDirections'] = array( + array('id' => 'desc', 'name' => getlocal('page_agents.sortdirection.desc')), + array('id' => 'asc', 'name' => getlocal('page_agents.sortdirection.asc')), +); setlocale(LC_TIME, getstring("time.locale")); diff --git a/src/messenger/webim/view/agents.php b/src/messenger/webim/view/agents.php index 539f7d15..25ba3577 100644 --- a/src/messenger/webim/view/agents.php +++ b/src/messenger/webim/view/agents.php @@ -39,6 +39,32 @@ function tpl_content() { global $page, $webimroot, $errors; require_once('inc_errors.php'); ?> +
+