diff --git a/src/messenger/webim/libs/common.php b/src/messenger/webim/libs/common.php
index de636c4e..0cbc6498 100644
--- a/src/messenger/webim/libs/common.php
+++ b/src/messenger/webim/libs/common.php
@@ -267,6 +267,14 @@ function perform_query($query,$link) {
or die(' Query failed: '.mysql_error()/*.": ".$query*/);
}
+function rows_count($link,$table,$whereclause="") {
+ $result = mysql_query("SELECT count(*) FROM $table $whereclause",$link)
+ or die(' Count query failed: '.mysql_error());
+ $line = mysql_fetch_array($result, MYSQL_NUM);
+ mysql_free_result($result);
+ return $line[0];
+}
+
function select_one_row($query,$link) {
$result = mysql_query($query,$link) or die(' Query failed: ' .
mysql_error().": ".$query);
diff --git a/src/messenger/webim/libs/groups.php b/src/messenger/webim/libs/groups.php
index 2e4b790c..46dd5cc0 100644
--- a/src/messenger/webim/libs/groups.php
+++ b/src/messenger/webim/libs/groups.php
@@ -20,6 +20,14 @@ function group_by_id($id) {
return $group;
}
+function get_group_name($group) {
+ global $home_locale, $current_locale;
+ if( $home_locale == $current_locale || !$group['vccommonname'] )
+ return $group['vclocalname'];
+ else
+ return $group['vccommonname'];
+}
+
function setup_group_settings_tabs($gid, $active) {
global $page, $webimroot, $settings;
if($gid) {
diff --git a/src/messenger/webim/libs/operator.php b/src/messenger/webim/libs/operator.php
index 70dfb6f9..ca18637e 100644
--- a/src/messenger/webim/libs/operator.php
+++ b/src/messenger/webim/libs/operator.php
@@ -194,19 +194,52 @@ function logout_operator() {
}
}
-function get_redirect_links($threadid,$token) {
- global $page, $webimroot;
- $found = get_operators();
- setup_pagination($found);
+function setup_redirect_links($threadid,$token) {
+ global $page, $webimroot, $settings;
+ loadsettings();
+ $link = connect();
+
+ $operatorscount = rows_count($link, "chatoperator");
+ $groupscount = $settings['enablegroups'] == "1" ? rows_count($link, "chatgroup") : 0;
+
+ prepare_pagination(max($operatorscount,$groupscount),8);
+ $limit = $page['pagination']['limit'];
+
+ $query = "select operatorid, vclogin, vclocalename, vccommonname, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time ".
+ "from chatoperator order by vclogin $limit";
+ $operators = select_multi_assoc($query, $link);
+
+ if($settings['enablegroups'] == "1") {
+ $query = "select groupid, vclocalname, vccommonname from chatgroup order by vclocalname $limit";
+ $groups = select_multi_assoc($query, $link);
+ }
+
+ mysql_close($link);
$agent_list = "";
$params = array('thread' => $threadid, 'token' => $token);
- for( $indagent = 0; $indagent < count($page['pagination.items']); $indagent += 1 ) {
- $agent = $page['pagination.items'][$indagent];
+ foreach($operators as $agent) {
$params['nextAgent'] = $agent['operatorid'];
- $agent_list .= "
".topage($agent['vclocalename'])."";
+ $online = $agent['time'] < $settings['online_timeout'] ? getlocal("char.redirect.operator.online_suff") : "";
+ $agent_list .= "".
+ topage(get_operator_name($agent)).
+ " $online";
}
- return $agent_list;
+ $page['redirectToAgent'] = $agent_list;
+
+ $group_list = "";
+ if($settings['enablegroups'] == "1") {
+ $params = array('thread' => $threadid, 'token' => $token);
+ foreach($groups as $group) {
+ $params['nextGroup'] = $group['groupid'];
+ $group_list .= "".
+ topage(get_group_name($group)).
+ "";
+ }
+ }
+ $page['redirectToGroup'] = $group_list;
}
$permission_list = array();
diff --git a/src/messenger/webim/libs/pagination.php b/src/messenger/webim/libs/pagination.php
index 01353140..29e28900 100644
--- a/src/messenger/webim/libs/pagination.php
+++ b/src/messenger/webim/libs/pagination.php
@@ -27,15 +27,15 @@ function generate_pagination_image($id,$alt) {
return "";
}
-function setup_pagination($items,$default_items_per_page=15) {
+function prepare_pagination($items_count,$default_items_per_page=15) {
global $page;
- if( $items ) {
+ if( $items_count ) {
$items_per_page = verifyparam("items", "/^\d{1,3}$/", $default_items_per_page);
if( $items_per_page < 2 )
$items_per_page = 2;
- $total_pages = div(count($items) + $items_per_page - 1, $items_per_page);
+ $total_pages = div($items_count + $items_per_page - 1, $items_per_page);
$curr_page = verifyparam("page", "/^\d{1,6}$/", 1);
if( $curr_page < 1 )
@@ -44,14 +44,24 @@ function setup_pagination($items,$default_items_per_page=15) {
$curr_page = $total_pages;
$start_index = ($curr_page-1)*$items_per_page;
- $end_index = min($start_index+$items_per_page, count($items));
- $page['pagination.items'] = array_slice($items, $start_index, $end_index-$start_index);
+ $end_index = min($start_index+$items_per_page, $items_count);
$page['pagination'] =
array( "page" => $curr_page, "items" => $items_per_page, "total" => $total_pages,
- "count" => count($items), "start" => $start_index, "end" => $end_index );
+ "count" => $items_count, "start" => $start_index, "end" => $end_index,
+ "limit" => "LIMIT $start_index,".($end_index - $start_index) );
+ } else {
+ $page['pagination'] = true;
+ }
+}
+
+function setup_pagination($items,$default_items_per_page=15) {
+ global $page;
+ prepare_pagination($items ? count($items) : 0, $default_items_per_page);
+ if($items && count($items) > 0) {
+ $p = $page['pagination'];
+ $page['pagination.items'] = array_slice($items, $p['start'], $p['end']-$p['start']);
} else {
$page['pagination.items'] = false;
- $page['pagination'] = true;
}
}
diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties
index b316c015..a258de7f 100644
--- a/src/messenger/webim/locales/en/properties
+++ b/src/messenger/webim/locales/en/properties
@@ -27,11 +27,16 @@ chat.mailthread.sent.content=History of your chat was sent on address {0}
chat.mailthread.sent.title=Sent
chat.predefined_answers=Hello, how may I help you?\nHello! Welcome to our support. How may I help you?
chat.redirect.back=Back...
-chat.redirect.choose_operator=Choose an operator:
+chat.redirect.operator=Operator:
+char.redirect.operator.online_suff=(online)
+chat.redirect.group=Group:
+chat.redirect.cannot=You are not chatting with visitor.
+chat.redirect.choose=Choose:
chat.redirect.title=Redirect to
another operator
chat.redirected.close=Close...
chat.redirected.closewindow=Click to close the window
chat.redirected.content=The visitor placed in priorty queue of the operator {0}.
+chat.redirected.group.content=The visitor placed in priorty queue of the group {0}.
chat.redirected.title=The visitor redirected to another operator
chat.status.operator.changed=Operator {0} changed operator {1}
chat.status.operator.dead=Operator has connection issues, we temporarily moved you to foreground queue. Sorry for keeping you waiting.
diff --git a/src/messenger/webim/operator/agent.php b/src/messenger/webim/operator/agent.php
index fd8dae90..0d4e1336 100644
--- a/src/messenger/webim/operator/agent.php
+++ b/src/messenger/webim/operator/agent.php
@@ -14,6 +14,7 @@
require_once('../libs/common.php');
require_once('../libs/chat.php');
+require_once('../libs/groups.php');
require_once('../libs/operator.php');
require_once('../libs/pagination.php');
require_once('../libs/expand.php');
@@ -90,7 +91,7 @@ start_html_output();
$pparam = verifyparam( "act", "/^(redirect)$/", "default");
if( $pparam == "redirect" ) {
- $page['pagination_list'] = get_redirect_links($threadid,$token);
+ setup_redirect_links($threadid,$token);
expand("../styles", getchatstyle(), "redirect.tpl");
} else {
expand("../styles", getchatstyle(), "chat.tpl");
diff --git a/src/messenger/webim/operator/preview.php b/src/messenger/webim/operator/preview.php
index cb6f9dc4..1c76d559 100644
--- a/src/messenger/webim/operator/preview.php
+++ b/src/messenger/webim/operator/preview.php
@@ -16,6 +16,7 @@ require_once('../libs/common.php');
require_once('../libs/chat.php');
require_once('../libs/pagination.php');
require_once('../libs/operator.php');
+require_once('../libs/groups.php');
require_once('../libs/expand.php');
require_once('../libs/settings.php');
@@ -71,9 +72,9 @@ if($show == 'redirect' || $show == 'redirected' || $show == 'agentchat' || $show
'operatorid' => ($show=='agentrochat' ? 2 : 1),
));
if($show=='redirect') {
- $page['pagination_list'] = get_redirect_links( 0,$show=='agentrochat' ? 124 : 123);
+ setup_redirect_links( 0,$show=='agentrochat' ? 124 : 123);
} elseif($show=='redirected') {
- $page['nextAgent'] = "Administrator";
+ $page['message'] = getlocal2("chat.redirected.content",array("Administrator"));
}
$page['redirectLink'] = "$webimroot/operator/preview.php?preview=$preview&show=redirect";
expand("../styles", "$preview", "$show.tpl");
diff --git a/src/messenger/webim/operator/redirect.php b/src/messenger/webim/operator/redirect.php
index cd1841e9..3836a61f 100644
--- a/src/messenger/webim/operator/redirect.php
+++ b/src/messenger/webim/operator/redirect.php
@@ -16,6 +16,7 @@ require_once('../libs/common.php');
require_once('../libs/operator.php');
require_once('../libs/chat.php');
require_once('../libs/expand.php');
+require_once('../libs/groups.php');
$operator = check_login();
@@ -27,27 +28,50 @@ if( !$thread || !isset($thread['ltoken']) || $token != $thread['ltoken'] ) {
die("wrong thread");
}
-$nextid = verifyparam( "nextAgent", "/^\d{1,8}$/");
-$nextOperator = operator_by_id($nextid);
-
$page = array();
$errors = array();
-if( $nextOperator ) {
- $page['nextAgent'] = topage(get_operator_name($nextOperator));
- if( $thread['istate'] == $state_chatting ) {
- $link = connect();
- commit_thread( $threadid,
- array("istate" => $state_waiting, "nextagent" => $nextid, "agentId" => 0), $link);
- post_message_($thread['threadid'], $kind_events,
- getstring2_("chat.status.operator.redirect",
- array(get_operator_name($operator)),$thread['locale']), $link);
- mysql_close($link);
+if(isset($_GET['nextGroup'])) {
+ $nextid = verifyparam( "nextGroup", "/^\d{1,8}$/");
+ $nextGroup = group_by_id($nextid);
+
+ if( $nextGroup ) {
+ $page['message'] = getlocal2("chat.redirected.group.content",array(topage(get_group_name($nextGroup))));
+ if( $thread['istate'] == $state_chatting ) {
+ $link = connect();
+ commit_thread( $threadid,
+ array("istate" => $state_waiting, "nextagent" => 0, "groupid" => $nextid, "agentId" => 0, "agentName" => "''"), $link);
+ post_message_($thread['threadid'], $kind_events,
+ getstring2_("chat.status.operator.redirect",
+ array(get_operator_name($operator)),$thread['locale']), $link);
+ mysql_close($link);
+ } else {
+ $errors[] = getlocal("chat.redirect.cannot");
+ }
} else {
- $errors[] = "You are not chatting with visitor"; // FIXME
+ $errors[] = "Unknown group";
}
+
} else {
- $errors[] = "Unknown operator"; // FIXME
+ $nextid = verifyparam( "nextAgent", "/^\d{1,8}$/");
+ $nextOperator = operator_by_id($nextid);
+
+ if( $nextOperator ) {
+ $page['message'] = getlocal2("chat.redirected.content",array(topage(get_operator_name($nextOperator))));
+ if( $thread['istate'] == $state_chatting ) {
+ $link = connect();
+ commit_thread( $threadid,
+ array("istate" => $state_waiting, "nextagent" => $nextid, "agentId" => 0), $link);
+ post_message_($thread['threadid'], $kind_events,
+ getstring2_("chat.status.operator.redirect",
+ array(get_operator_name($operator)),$thread['locale']), $link);
+ mysql_close($link);
+ } else {
+ $errors[] = getlocal("chat.redirect.cannot");
+ }
+ } else {
+ $errors[] = "Unknown operator";
+ }
}
setup_logo();
diff --git a/src/messenger/webim/styles/default/templates/redirect.tpl b/src/messenger/webim/styles/default/templates/redirect.tpl
index b6efa055..d9c5ce63 100644
--- a/src/messenger/webim/styles/default/templates/redirect.tpl
+++ b/src/messenger/webim/styles/default/templates/redirect.tpl
@@ -72,7 +72,7 @@
- ${msg:chat.redirect.choose_operator}
+ ${msg:chat.redirect.choose}
|
@@ -89,13 +89,32 @@
-
- ${page:pagination_list}
-
+
+
+
+
+${if:redirectToAgent}
+ ${msg:chat.redirect.operator}
+
+ ${page:redirectToAgent}
+
+${endif:redirectToAgent}
+ |
+
+${if:redirectToGroup}
+ ${msg:chat.redirect.group}
+
+ ${page:redirectToGroup}
+
+${endif:redirectToGroup}
+ |
+
+
|
+ ${pagination}
|
diff --git a/src/messenger/webim/styles/default/templates/redirected.tpl b/src/messenger/webim/styles/default/templates/redirected.tpl
index a9c7e949..18d5a275 100644
--- a/src/messenger/webim/styles/default/templates/redirected.tpl
+++ b/src/messenger/webim/styles/default/templates/redirected.tpl
@@ -48,7 +48,7 @@
- ${msg:chat.redirected.content,nextAgent}
+ ${page:message}
|
diff --git a/src/messenger/webim/styles/original/templates/redirect.tpl b/src/messenger/webim/styles/original/templates/redirect.tpl
index 7a4f25ee..0a5a8328 100644
--- a/src/messenger/webim/styles/original/templates/redirect.tpl
+++ b/src/messenger/webim/styles/original/templates/redirect.tpl
@@ -32,7 +32,7 @@
${msg:chat.redirect.title} |
- ${msg:chat.redirect.choose_operator}
+ ${msg:chat.redirect.choose}
|
@@ -60,9 +60,25 @@
+
+
+
+${if:redirectToAgent}
+ ${msg:chat.redirect.operator}
- ${page:pagination_list}
+ ${page:redirectToAgent}
+${endif:redirectToAgent}
+ |
+
+${if:redirectToGroup}
+ ${msg:chat.redirect.group}
+
+ ${page:redirectToGroup}
+
+${endif:redirectToGroup}
+ |
+
|
diff --git a/src/messenger/webim/styles/original/templates/redirected.tpl b/src/messenger/webim/styles/original/templates/redirected.tpl
index 62ef7d35..90b3f277 100644
--- a/src/messenger/webim/styles/original/templates/redirected.tpl
+++ b/src/messenger/webim/styles/original/templates/redirected.tpl
@@ -47,7 +47,7 @@
|
- ${msg:chat.redirected.content,nextAgent}
+ ${page:message}
${msg:chat.redirected.closewindow}
|
| |