2007-10-10 19:15:47 +04:00
< ? php
/*
2009-06-04 02:44:32 +04:00
* This file is part of Mibew Messenger project .
2009-08-04 20:30:39 +04:00
*
2011-02-16 03:22:22 +03:00
* Copyright ( c ) 2005 - 2011 Mibew Messenger Community
2009-08-04 19:03:27 +04:00
* All rights reserved . The contents of this file are subject to the terms of
* the Eclipse Public License v1 . 0 which accompanies this distribution , and
* is available at http :// www . eclipse . org / legal / epl - v10 . html
2009-08-04 20:30:39 +04:00
*
2009-08-04 17:38:37 +04:00
* Alternatively , the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later ( the " GPL " ), in which case
* the provisions of the GPL are applicable instead of those above . If you wish
* to allow use of your version of this file only under the terms of the GPL , and
* not to allow others to use your version of this file under the terms of the
* EPL , indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by the GPL .
2009-08-04 20:30:39 +04:00
*
2007-10-10 19:15:47 +04:00
* Contributors :
* Evgeny Gryaznov - initial API and implementation
*/
2008-12-08 03:34:28 +03:00
$can_administrate = 0 ;
$can_takeover = 1 ;
$can_viewthreads = 2 ;
2009-05-31 20:13:22 +04:00
$can_modifyprofile = 3 ;
2008-12-08 03:34:28 +03:00
2009-05-31 20:13:22 +04:00
$can_count = 4 ;
2008-12-08 03:34:28 +03:00
$permission_ids = array (
$can_administrate => " admin " ,
$can_takeover => " takeover " ,
2009-05-31 20:13:22 +04:00
$can_viewthreads => " viewthreads " ,
$can_modifyprofile => " modifyprofile "
2008-12-08 03:34:28 +03:00
);
2011-02-26 16:43:30 +03:00
function operator_by_login ( $login )
{
global $mysqlprefix ;
2007-10-10 19:15:47 +04:00
$link = connect ();
$operator = select_one_row (
2011-11-09 22:59:07 +04:00
" select * from ${ mysqlprefix } chatoperator where vclogin = ' " . db_escape_string ( $login ) . " ' " , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2007-10-10 19:15:47 +04:00
return $operator ;
}
2011-02-26 16:43:30 +03:00
function operator_by_email ( $mail )
{
global $mysqlprefix ;
2009-09-01 02:43:30 +04:00
$link = connect ();
$operator = select_one_row (
2011-11-09 22:59:07 +04:00
" select * from ${ mysqlprefix } chatoperator where vcemail = ' " . db_escape_string ( $mail ) . " ' " , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2009-09-01 02:43:30 +04:00
return $operator ;
}
2011-02-26 16:43:30 +03:00
function operator_by_id_ ( $id , $link )
{
global $mysqlprefix ;
2007-10-10 19:15:47 +04:00
return select_one_row (
2011-02-26 16:43:30 +03:00
" select * from ${ mysqlprefix } chatoperator where operatorid = $id " , $link );
2007-10-10 19:15:47 +04:00
}
2011-02-26 16:43:30 +03:00
function operator_by_id ( $id )
{
2007-10-10 19:15:47 +04:00
$link = connect ();
2011-02-26 16:43:30 +03:00
$operator = operator_by_id_ ( $id , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2007-10-10 19:15:47 +04:00
return $operator ;
}
2012-03-16 01:26:47 +04:00
/**
* 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 ;
}
2011-02-26 16:43:30 +03:00
function operator_get_all ()
{
global $mysqlprefix ;
2011-02-21 03:02:39 +03:00
$link = connect ();
2011-12-19 21:55:22 +04:00
$query = " select operatorid, vclogin, vclocalename, vccommonname, istatus, idisabled, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
2011-02-26 16:13:16 +03:00
" from ${ mysqlprefix } chatoperator order by vclogin " ;
2011-02-21 03:02:39 +03:00
$operators = select_multi_assoc ( $query , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2011-02-21 03:02:39 +03:00
return $operators ;
}
2012-02-25 23:40:05 +04:00
function get_operators_from_adjacent_groups ( $operator )
{
global $mysqlprefix ;
$link = connect ();
$query = " select distinct ${ mysqlprefix } chatoperator.operatorid, vclogin, vclocalename, vccommonname, istatus, idisabled, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
" from ${ mysqlprefix } chatoperator, ${ 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 = " . $operator [ 'operatorid' ] . " ) i " .
" where g.groupid = i.parent or g.parent = i.parent " .
" ) order by vclogin " ;
$operators = select_multi_assoc ( $query , $link );
close_connection ( $link );
return $operators ;
}
2011-02-26 16:43:30 +03:00
function operator_is_online ( $operator )
{
2011-02-21 03:02:39 +03:00
global $settings ;
return $operator [ 'time' ] < $settings [ 'online_timeout' ];
}
2011-02-26 16:43:30 +03:00
function operator_is_available ( $operator )
{
2011-02-21 03:02:39 +03:00
global $settings ;
2011-02-26 16:43:30 +03:00
return $operator [ 'istatus' ] == 0 && $operator [ 'time' ] < $settings [ 'online_timeout' ] ? " 1 " : " " ;
2011-02-21 03:02:39 +03:00
}
2011-02-26 16:43:30 +03:00
function operator_is_away ( $operator )
{
2011-02-21 03:02:39 +03:00
global $settings ;
2011-02-26 16:43:30 +03:00
return $operator [ 'istatus' ] != 0 && $operator [ 'time' ] < $settings [ 'online_timeout' ] ? " 1 " : " " ;
2011-02-21 03:02:39 +03:00
}
2011-12-19 21:55:22 +04:00
function operator_is_disabled ( $operator )
{
return $operator [ 'idisabled' ] == '1' ;
}
2011-02-26 16:43:30 +03:00
function update_operator ( $operatorid , $login , $email , $password , $localename , $commonname )
{
global $mysqlprefix ;
2007-10-10 19:15:47 +04:00
$link = connect ();
$query = sprintf (
2011-02-26 16:43:30 +03:00
" update ${ mysqlprefix } chatoperator set vclogin = '%s',%s vclocalename = '%s', vccommonname = '%s' " .
" , vcemail = '%s', vcjabbername= '%s' " .
2008-03-05 01:22:48 +03:00
" where operatorid = %s " ,
2011-11-09 22:59:07 +04:00
db_escape_string ( $login ),
2011-02-26 16:43:30 +03:00
( $password ? " vcpassword=' " . md5 ( $password ) . " ', " : " " ),
2011-11-09 22:59:07 +04:00
db_escape_string ( $localename ),
db_escape_string ( $commonname ),
db_escape_string ( $email ),
2008-10-06 03:46:54 +04:00
'' ,
2011-02-26 16:43:30 +03:00
$operatorid );
2007-10-10 19:15:47 +04:00
2011-02-26 16:43:30 +03:00
perform_query ( $query , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2007-10-10 19:15:47 +04:00
}
2011-02-26 16:43:30 +03:00
function update_operator_avatar ( $operatorid , $avatar )
{
global $mysqlprefix ;
2008-10-06 03:46:54 +04:00
$link = connect ();
$query = sprintf (
2011-02-26 16:13:16 +03:00
" update ${ mysqlprefix } chatoperator set vcavatar = '%s' where operatorid = %s " ,
2011-11-09 22:59:07 +04:00
db_escape_string ( $avatar ), $operatorid );
2008-10-06 03:46:54 +04:00
2011-02-26 16:43:30 +03:00
perform_query ( $query , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2008-10-06 03:46:54 +04:00
}
2011-02-26 16:43:30 +03:00
function create_operator_ ( $login , $email , $password , $localename , $commonname , $avatar , $link )
{
global $mysqlprefix ;
2007-10-10 19:15:47 +04:00
$query = sprintf (
2011-02-26 16:13:16 +03:00
" insert into ${ mysqlprefix } chatoperator (vclogin,vcpassword,vclocalename,vccommonname,vcavatar,vcemail,vcjabbername) values ('%s','%s','%s','%s','%s','%s','%s') " ,
2011-11-09 22:59:07 +04:00
db_escape_string ( $login ),
2011-02-26 16:43:30 +03:00
md5 ( $password ),
2011-11-09 22:59:07 +04:00
db_escape_string ( $localename ),
db_escape_string ( $commonname ),
db_escape_string ( $avatar ),
db_escape_string ( $email ), '' );
2011-02-26 16:43:30 +03:00
perform_query ( $query , $link );
2011-11-10 00:57:48 +04:00
$id = db_insert_id ( $link );
2007-10-10 19:15:47 +04:00
2011-02-26 16:43:30 +03:00
return select_one_row ( " select * from ${ mysqlprefix } chatoperator where operatorid = $id " , $link );
2007-10-17 14:43:34 +04:00
}
2011-02-26 16:43:30 +03:00
function create_operator ( $login , $email , $password , $localename , $commonname , $avatar )
{
2007-10-17 14:43:34 +04:00
$link = connect ();
2011-02-26 16:43:30 +03:00
$newop = create_operator_ ( $login , $email , $password , $localename , $commonname , $avatar , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2007-10-10 19:15:47 +04:00
return $newop ;
}
2011-02-26 16:43:30 +03:00
function notify_operator_alive ( $operatorid , $istatus )
{
global $mysqlprefix ;
2007-10-10 19:15:47 +04:00
$link = connect ();
2011-02-26 16:43:30 +03:00
perform_query ( " update ${ mysqlprefix } chatoperator set istatus = $istatus , dtmlastvisited = CURRENT_TIMESTAMP where operatorid = $operatorid " , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2007-10-10 19:15:47 +04:00
}
2011-02-26 16:43:30 +03:00
function has_online_operators ( $groupid = " " )
{
2011-02-26 16:13:16 +03:00
global $settings , $mysqlprefix ;
2009-01-14 01:19:12 +03:00
loadsettings ();
2007-10-10 19:15:47 +04:00
$link = connect ();
2011-02-26 16:13:16 +03:00
$query = " select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time from ${ mysqlprefix } chatoperator " ;
2011-02-26 16:43:30 +03:00
if ( $groupid ) {
2012-02-24 17:52:39 +04:00
$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 = " .
2011-04-07 02:31:22 +04:00
" ${ mysqlprefix } chatgroupoperator.operatorid and istatus = 0 " ;
2009-07-24 11:37:58 +04:00
} else {
2012-01-16 00:51:12 +04:00
if ( $settings [ 'enablegroups' ] == 1 ) {
$query .= " , ${ mysqlprefix } chatgroupoperator where ${ mysqlprefix } chatoperator.operatorid = " .
" ${ mysqlprefix } chatgroupoperator.operatorid and istatus = 0 " ;
} else {
$query .= " where istatus = 0 " ;
}
2009-06-05 03:01:17 +04:00
}
2011-02-26 16:43:30 +03:00
$row = select_one_row ( $query , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2009-06-05 21:33:14 +04:00
return $row [ 'time' ] < $settings [ 'online_timeout' ] && $row [ 'total' ] > 0 ;
2007-10-10 19:15:47 +04:00
}
2011-02-26 16:43:30 +03:00
function is_operator_online ( $operatorid , $link )
{
2011-02-26 16:13:16 +03:00
global $settings , $mysqlprefix ;
2011-02-26 15:24:29 +03:00
loadsettings_ ( $link );
2011-02-26 16:43:30 +03:00
$query = " select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
2011-02-26 16:13:16 +03:00
" from ${ mysqlprefix } chatoperator where operatorid = $operatorid " ;
2011-02-26 16:43:30 +03:00
$row = select_one_row ( $query , $link );
2011-02-26 15:24:29 +03:00
return $row [ 'time' ] < $settings [ 'online_timeout' ] && $row [ 'total' ] == 1 ;
}
2011-02-26 16:43:30 +03:00
function get_operator_name ( $operator )
{
2007-10-10 19:15:47 +04:00
global $home_locale , $current_locale ;
2011-02-26 16:43:30 +03:00
if ( $home_locale == $current_locale )
2007-10-10 19:15:47 +04:00
return $operator [ 'vclocalename' ];
else
return $operator [ 'vccommonname' ];
}
2011-02-26 16:43:30 +03:00
function append_query ( $link , $pv )
{
2009-03-25 02:34:57 +03:00
$infix = '?' ;
2011-02-26 16:43:30 +03:00
if ( strstr ( $link , $infix ) !== FALSE )
2009-03-25 02:34:57 +03:00
$infix = '&' ;
return " $link $infix $pv " ;
}
2011-02-26 16:43:30 +03:00
function check_login ( $redirect = true )
{
global $webimroot , $mysqlprefix ;
if ( ! isset ( $_SESSION [ " ${ mysqlprefix } operator " ])) {
if ( isset ( $_COOKIE [ 'webim_lite' ])) {
list ( $login , $pwd ) = preg_split ( " /,/ " , $_COOKIE [ 'webim_lite' ], 2 );
2007-10-10 19:15:47 +04:00
$op = operator_by_login ( $login );
2011-12-19 21:55:22 +04:00
if ( $op && isset ( $pwd ) && isset ( $op [ 'vcpassword' ]) && md5 ( $op [ 'vcpassword' ]) == $pwd && ! operator_is_disabled ( $op )) {
2011-02-26 16:43:30 +03:00
$_SESSION [ " ${ mysqlprefix } operator " ] = $op ;
2007-10-10 19:15:47 +04:00
return $op ;
}
}
2009-02-04 02:33:30 +03:00
$requested = $_SERVER [ 'PHP_SELF' ];
2011-02-26 16:43:30 +03:00
if ( $_SERVER [ 'REQUEST_METHOD' ] == 'GET' && $_SERVER [ 'QUERY_STRING' ]) {
$requested .= " ? " . $_SERVER [ 'QUERY_STRING' ];
2009-02-04 02:33:30 +03:00
}
2011-02-26 16:43:30 +03:00
if ( $redirect ) {
2009-05-31 18:36:11 +04:00
$_SESSION [ 'backpath' ] = $requested ;
header ( " Location: $webimroot /operator/login.php " );
exit ;
} else {
return null ;
}
2007-10-10 19:15:47 +04:00
}
2011-02-26 16:43:30 +03:00
return $_SESSION [ " ${ mysqlprefix } operator " ];
2007-10-10 19:15:47 +04:00
}
2011-04-13 18:44:09 +04:00
// Force the admin to set a password after the installation
function force_password ( $operator )
{
global $webimroot ;
if ( $operator [ 'vcpassword' ] == md5 ( '' ))
{
header ( " Location: $webimroot /operator/operator.php?op=1 " );
exit ;
}
}
2011-02-26 16:43:30 +03:00
function get_logged_in ()
{
global $mysqlprefix ;
return isset ( $_SESSION [ " ${ mysqlprefix } operator " ]) ? $_SESSION [ " ${ mysqlprefix } operator " ] : FALSE ;
2007-10-10 19:15:47 +04:00
}
2011-02-26 16:43:30 +03:00
function login_operator ( $operator , $remember )
{
global $webimroot , $mysqlprefix ;
$_SESSION [ " ${ mysqlprefix } operator " ] = $operator ;
if ( $remember ) {
$value = $operator [ 'vclogin' ] . " , " . md5 ( $operator [ 'vcpassword' ]);
setcookie ( 'webim_lite' , $value , time () + 60 * 60 * 24 * 1000 , " $webimroot / " );
2007-10-10 19:15:47 +04:00
2011-02-26 16:43:30 +03:00
} else if ( isset ( $_COOKIE [ 'webim_lite' ])) {
2007-10-30 15:13:04 +03:00
setcookie ( 'webim_lite' , '' , time () - 3600 , " $webimroot / " );
2007-10-10 19:15:47 +04:00
}
}
2011-02-26 16:43:30 +03:00
function logout_operator ()
{
global $webimroot , $mysqlprefix ;
unset ( $_SESSION [ " ${ mysqlprefix } operator " ]);
2009-04-05 01:14:35 +04:00
unset ( $_SESSION [ 'backpath' ]);
2011-02-26 16:43:30 +03:00
if ( isset ( $_COOKIE [ 'webim_lite' ])) {
2007-10-30 15:13:04 +03:00
setcookie ( 'webim_lite' , '' , time () - 3600 , " $webimroot / " );
2007-10-10 19:15:47 +04:00
}
}
2012-02-25 23:40:05 +04:00
function setup_redirect_links ( $threadid , $operator , $token )
2011-02-26 16:43:30 +03:00
{
2011-02-26 16:13:16 +03:00
global $page , $webimroot , $settings , $mysqlprefix ;
2009-03-29 03:51:33 +04:00
loadsettings ();
2012-02-25 23:40:05 +04:00
$operator_in_isolation = in_isolation ( $operator );
$operators = $operator_in_isolation ? get_operators_from_adjacent_groups ( $operator ) : operator_get_all ();
$operatorscount = count ( $operators );
$link = connect ();
2009-03-29 03:51:33 +04:00
2011-02-16 03:43:19 +03:00
$groupscount = 0 ;
2011-02-26 16:43:30 +03:00
$groups = array ();
if ( $settings [ 'enablegroups' ] == " 1 " ) {
2012-02-25 23:40:05 +04:00
$groupslist = $operator_in_isolation ? get_groups_for_operator ( $link , $operator , true ) : get_groups ( $link , true );
foreach ( $groupslist as $group ) {
2011-02-26 16:43:30 +03:00
if ( $group [ 'inumofagents' ] == 0 ) {
2011-02-16 03:43:19 +03:00
continue ;
}
$groups [] = $group ;
}
$groupscount = count ( $groups );
2009-03-29 03:51:33 +04:00
}
2012-02-25 23:40:05 +04:00
close_connection ( $link );
2011-02-26 16:43:30 +03:00
prepare_pagination ( max ( $operatorscount , $groupscount ), 8 );
2011-02-16 03:43:19 +03:00
$p = $page [ 'pagination' ];
$limit = $p [ 'limit' ];
2012-02-25 23:40:05 +04:00
$operators = array_slice ( $operators , $p [ 'start' ], $p [ 'end' ] - $p [ 'start' ]);
2011-02-26 16:43:30 +03:00
$groups = array_slice ( $groups , $p [ 'start' ], $p [ 'end' ] - $p [ 'start' ]);
2008-10-15 01:14:49 +04:00
$agent_list = " " ;
$params = array ( 'thread' => $threadid , 'token' => $token );
2011-02-26 16:43:30 +03:00
foreach ( $operators as $agent ) {
2008-10-15 01:14:49 +04:00
$params [ 'nextAgent' ] = $agent [ 'operatorid' ];
2009-07-24 11:37:58 +04:00
$status = $agent [ 'time' ] < $settings [ 'online_timeout' ]
2011-02-26 16:43:30 +03:00
? ( $agent [ 'istatus' ] == 0
? getlocal ( " char.redirect.operator.online_suff " )
: getlocal ( " char.redirect.operator.away_suff " )
)
: " " ;
$agent_list .= " <li><a href= \" " . add_params ( $webimroot . " /operator/redirect.php " , $params ) .
" \" title= \" " . topage ( get_operator_name ( $agent )) . " \" > " .
topage ( get_operator_name ( $agent )) .
" </a> $status </li> " ;
2009-03-29 03:51:33 +04:00
}
$page [ 'redirectToAgent' ] = $agent_list ;
$group_list = " " ;
2011-02-26 16:43:30 +03:00
if ( $settings [ 'enablegroups' ] == " 1 " ) {
2009-03-29 03:51:33 +04:00
$params = array ( 'thread' => $threadid , 'token' => $token );
2011-02-26 16:43:30 +03:00
foreach ( $groups as $group ) {
2009-03-29 03:51:33 +04:00
$params [ 'nextGroup' ] = $group [ 'groupid' ];
2011-02-26 16:43:30 +03:00
$status = $group [ 'ilastseen' ] !== NULL && $group [ 'ilastseen' ] < $settings [ 'online_timeout' ]
? getlocal ( " char.redirect.operator.online_suff " )
2009-07-24 11:37:58 +04:00
: ( $group [ 'ilastseenaway' ] !== NULL && $group [ 'ilastseenaway' ] < $settings [ 'online_timeout' ]
2011-02-26 16:43:30 +03:00
? getlocal ( " char.redirect.operator.away_suff " )
: " " );
$group_list .= " <li><a href= \" " . add_params ( $webimroot . " /operator/redirect.php " , $params ) .
" \" title= \" " . topage ( get_group_name ( $group )) . " \" > " .
topage ( get_group_name ( $group )) .
" </a> $status </li> " ;
2009-03-29 03:51:33 +04:00
}
2008-10-15 01:14:49 +04:00
}
2009-03-29 03:51:33 +04:00
$page [ 'redirectToGroup' ] = $group_list ;
2008-10-15 01:14:49 +04:00
}
2008-12-08 03:34:28 +03:00
$permission_list = array ();
2011-02-26 16:43:30 +03:00
function get_permission_list ()
{
2008-12-08 03:34:28 +03:00
global $permission_list , $permission_ids ;
2011-02-26 16:43:30 +03:00
if ( count ( $permission_list ) == 0 ) {
foreach ( $permission_ids as $permid ) {
2008-12-08 03:34:28 +03:00
$permission_list [] = array (
'id' => $permid ,
'descr' => getlocal ( " permission. $permid " )
);
}
}
return $permission_list ;
}
2011-02-26 16:43:30 +03:00
function is_capable ( $perm , $operator )
{
2008-12-08 03:34:28 +03:00
$permissions = $operator && isset ( $operator [ 'iperm' ]) ? $operator [ 'iperm' ] : 0 ;
return $perm >= 0 && $perm < 32 && ( $permissions & ( 1 << $perm )) != 0 ;
}
2012-02-25 23:40:05 +04:00
function in_isolation ( $operator )
{
global $settings , $can_administrate ;
loadsettings ();
return ( ! is_capable ( $can_administrate , $operator ) && $settings [ 'enablegroups' ] && $settings [ 'enablegroupsisolation' ]);
}
2011-02-26 16:43:30 +03:00
function prepare_menu ( $operator , $hasright = true )
{
2009-03-16 04:20:04 +03:00
global $page , $settings , $can_administrate ;
$page [ 'operator' ] = topage ( get_operator_name ( $operator ));
2011-02-26 16:43:30 +03:00
if ( $hasright ) {
2009-03-16 04:20:04 +03:00
loadsettings ();
$page [ 'showban' ] = $settings [ 'enableban' ] == " 1 " ;
2009-03-22 14:54:59 +03:00
$page [ 'showstat' ] = $settings [ 'enablestatistics' ] == " 1 " ;
2009-03-16 04:20:04 +03:00
$page [ 'showadmin' ] = is_capable ( $can_administrate , $operator );
2009-04-10 18:12:57 +04:00
$page [ 'currentopid' ] = $operator [ 'operatorid' ];
2009-03-16 04:20:04 +03:00
}
}
2011-02-26 16:43:30 +03:00
function get_all_groups ( $link )
{
global $mysqlprefix ;
2012-02-24 17:52:39 +04:00
$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 ));
}
2012-02-25 23:40:05 +04:00
function get_all_groups_for_operator ( $operator , $link )
{
global $mysqlprefix ;
$query = " select g.groupid as groupid, g.parent, g.vclocalname, g.vclocaldescription " .
" from ${ mysqlprefix } chatgroup g, " .
" (select distinct parent from ${ mysqlprefix } chatgroup, ${ mysqlprefix } chatgroupoperator " .
" where ${ mysqlprefix } chatgroup.groupid = ${ mysqlprefix } chatgroupoperator.groupid and ${ mysqlprefix } chatgroupoperator.operatorid = " . $operator [ 'operatorid' ] . " ) i " .
" where g.groupid = i.parent or g.parent = i.parent " .
" order by vclocalname " ;
return get_sorted_child_groups_ ( select_multi_assoc ( $query , $link ));
}
2012-02-24 17:52:39 +04:00
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 ;
2009-07-24 11:37:58 +04:00
}
2012-03-02 01:39:19 +04:00
function get_groups_ ( $link , $checkaway , $operator , $order = NULL )
2011-02-26 16:43:30 +03:00
{
global $mysqlprefix ;
2012-03-02 01:39:19 +04:00
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 " ;
}
2012-02-25 23:40:05 +04:00
$query = " select ${ mysqlprefix } chatgroup.groupid as groupid, ${ mysqlprefix } chatgroup.parent as parent, vclocalname, vclocaldescription, iweight " .
2011-04-07 02:31:22 +04:00
" , (SELECT count(*) from ${ mysqlprefix } chatgroupoperator where ${ mysqlprefix } chatgroup.groupid = " .
" ${ mysqlprefix } chatgroupoperator.groupid) as inumofagents " .
2011-02-26 16:43:30 +03:00
" , (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
2011-04-07 02:31:22 +04:00
" from ${ mysqlprefix } chatgroupoperator, ${ mysqlprefix } chatoperator where istatus = 0 and " .
" ${ mysqlprefix } chatgroup.groupid = ${ mysqlprefix } chatgroupoperator.groupid " .
2011-02-26 16:43:30 +03:00
" and ${ mysqlprefix } chatgroupoperator.operatorid = ${ mysqlprefix } chatoperator.operatorid) as ilastseen " .
( $checkaway
? " , (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
2011-04-07 02:31:22 +04:00
" from ${ mysqlprefix } chatgroupoperator, ${ mysqlprefix } chatoperator where istatus <> 0 and " .
" ${ mysqlprefix } chatgroup.groupid = ${ mysqlprefix } chatgroupoperator.groupid " .
2011-02-26 16:43:30 +03:00
" and ${ mysqlprefix } chatgroupoperator.operatorid = ${ mysqlprefix } chatoperator.operatorid) as ilastseenaway "
: " "
) .
2012-02-25 23:40:05 +04:00
" from ${ mysqlprefix } chatgroup " .
( $operator
? " , (select distinct parent from ${ mysqlprefix } chatgroup, ${ mysqlprefix } chatgroupoperator " .
" where ${ mysqlprefix } chatgroup.groupid = ${ mysqlprefix } chatgroupoperator.groupid and ${ mysqlprefix } chatgroupoperator.operatorid = " . $operator [ 'operatorid' ] . " ) i " .
" where ${ mysqlprefix } chatgroup.groupid = i.parent or ${ mysqlprefix } chatgroup.parent = i.parent "
: " "
) .
2012-03-02 01:39:19 +04:00
" order by " . $orderby ;
2012-02-24 17:52:39 +04:00
return get_sorted_child_groups_ ( select_multi_assoc ( $query , $link ));
2009-03-23 00:22:51 +03:00
}
2012-02-25 23:40:05 +04:00
function get_groups ( $link , $checkaway )
{
2012-03-02 01:39:19 +04:00
return get_groups_ ( $link , $checkaway , NULL );
2012-02-25 23:40:05 +04:00
}
function get_groups_for_operator ( $link , $operator , $checkaway )
{
2012-03-02 01:39:19 +04:00
return get_groups_ ( $link , $checkaway , $operator );
}
function get_sorted_groups ( $link , $order )
{
return get_groups_ ( $link , true , NULL , $order );
2012-02-25 23:40:05 +04:00
}
2011-02-26 16:43:30 +03:00
function get_operator_groupids ( $operatorid )
{
global $mysqlprefix ;
2009-03-23 00:22:51 +03:00
$link = connect ();
2011-02-26 16:13:16 +03:00
$query = " select groupid from ${ mysqlprefix } chatgroupoperator where operatorid = $operatorid " ;
2009-03-23 00:22:51 +03:00
$result = select_multi_assoc ( $query , $link );
2011-11-09 18:16:37 +04:00
close_connection ( $link );
2009-03-23 00:22:51 +03:00
return $result ;
}
2011-04-07 02:31:22 +04:00
?>