diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index b1a3f0fe..e7051e7d 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -56,6 +56,7 @@ $dbtables = array( "dtmlastvisited" => "datetime DEFAULT 0", "vcavatar" => "varchar(255)", "vcjabbername" => "varchar(255)", + "iperm" => "int DEFAULT 65535", ), "chatrevision" => array( @@ -83,7 +84,7 @@ $memtables = array(); $dbtables_can_update = array( "chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent"), "chatmessage" => array("agentId"), - "chatoperator" => array("vcavatar", "vcjabbername"), + "chatoperator" => array("vcavatar", "vcjabbername", "iperm"), "chatban" => array(), ); diff --git a/src/messenger/webim/install/dbperform.php b/src/messenger/webim/install/dbperform.php index 1c4da2aa..5c4a4d3b 100644 --- a/src/messenger/webim/install/dbperform.php +++ b/src/messenger/webim/install/dbperform.php @@ -106,6 +106,10 @@ if ($act == "silentcreateall") { runsql("ALTER TABLE chatthread ADD userid varchar(255) DEFAULT \"\"", $link); } + if( in_array("chatoperator.iperm", $absent) ) { + runsql("ALTER TABLE chatoperator ADD iperm int DEFAULT 65535", $link); + } + if( in_array("chatoperator.vcavatar", $absent) ) { runsql("ALTER TABLE chatoperator ADD vcavatar varchar(255)", $link); } diff --git a/src/messenger/webim/libs/common.php b/src/messenger/webim/libs/common.php index d3c3303d..28ea1797 100644 --- a/src/messenger/webim/libs/common.php +++ b/src/messenger/webim/libs/common.php @@ -297,6 +297,14 @@ function form_value_cb($key) { return false; } +function form_value_mb($key,$id) { + global $page; + if( isset($page) && isset($page["form$key"]) && is_array($page["form$key"]) ) { + return in_array($id, $page["form$key"]); + } + return false; +} + function no_field($key) { return getlocal2("errors.required",array(getlocal($key))); } diff --git a/src/messenger/webim/libs/operator.php b/src/messenger/webim/libs/operator.php index 4ac3e32c..388db8f8 100644 --- a/src/messenger/webim/libs/operator.php +++ b/src/messenger/webim/libs/operator.php @@ -12,6 +12,18 @@ * Evgeny Gryaznov - initial API and implementation */ +$can_administrate = 0; +$can_takeover = 1; +$can_viewthreads = 2; + +$can_count = 3; + +$permission_ids = array( + $can_administrate => "admin", + $can_takeover => "takeover", + $can_viewthreads => "viewthreads" +); + function operator_by_login($login) { $link = connect(); $operator = select_one_row( @@ -176,4 +188,24 @@ function get_redirect_links($threadid,$token) { return $agent_list; } +$permission_list = array(); + +function get_permission_list() { + global $permission_list, $permission_ids; + if(count($permission_list) == 0) { + foreach($permission_ids as $permid) { + $permission_list[] = array( + 'id' => $permid, + 'descr' => getlocal("permission.$permid") + ); + } + } + return $permission_list; +} + +function is_capable($perm,$operator) { + $permissions = $operator && isset($operator['iperm']) ? $operator['iperm'] : 0; + return $perm >= 0 && $perm < 32 && ($permissions & (1 << $perm)) != 0; +} + ?> diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index 0f879c70..5f173082 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -258,12 +258,18 @@ page.translate.title=Translate Open WebIM page_agent.create_new=Here you can create new operator page_agent.tab.avatar=Photo page_agent.tab.main=General +page_agent.tab.permissions=Permissions page_agents.agent_commonname=International name page_analysis.full.text.search=User name or message text search: page_avatar.intro=You can upload your photo only in JPG, GIF, PNG or TIF image file. page_avatar.title=Upload photo page_search.intro=Search for chat history of a specified user or a specified phrase in a message. page_settings.intro=Specify options affecting chat window and common system behavior +permission.admin=System administration: settings, operators management +permission.takeover=Take over chat thread +permission.viewthreads=View another operator's chat thread +permissions.intro=Here you can control operator's permissions +permissions.title=Permissions settings.chat.title=Title in the chat window settings.chat.title.description=Department of your company for example. settings.chatstyle=Select style for your chat windows diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index 04878ab8..3867d66f 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -258,12 +258,18 @@ page.translate.title= page_agent.create_new=Создание нового оператора page_agent.tab.avatar=Фотография page_agent.tab.main=Общее +page_agent.tab.permissions=Возможности page_agents.agent_commonname=Интернациональное имя page_analysis.full.text.search=Поиск по имени посетителя или по тексту сообщения: page_avatar.intro=Вы можете загрузить фотографию расширения JPG, GIF, PNG или TIF. page_avatar.title=Загрузка фотографии page_search.intro=На данной странице можно осуществить поиск диалогов по имени пользователя или фразе, встречающейся в сообщении. page_settings.intro=Здесь вы можете задать опции влияющие на отображение чат окна и общее поведение системы +permission.admin=Администрирование системы: настройка, управление операторами +permission.takeover=Перехватывать диалоги у других операторов +permission.viewthreads=Просматривать диалоги других операторов в режиме реального времени +permissions.intro=Здесь вы можете ограничить возможности оператора +permissions.title=Возможности оператора settings.chat.title=Заголовок в чат окне settings.chat.title.description=Например, название отдела вашей компании settings.chatstyle=Выберите вид вашего чат окна diff --git a/src/messenger/webim/operator/avatar.php b/src/messenger/webim/operator/avatar.php index 3e296b5a..dd8bb8ae 100644 --- a/src/messenger/webim/operator/avatar.php +++ b/src/messenger/webim/operator/avatar.php @@ -82,7 +82,8 @@ if( !$op ) { $page['tabs'] = array( getlocal("page_agent.tab.main") => "$webimroot/operator/operator.php?op=$opId", - getlocal("page_agent.tab.avatar") => "" + getlocal("page_agent.tab.avatar") => "", + getlocal("page_agent.tab.permissions") => "$webimroot/operator/permissions.php?op=$opId" ); start_html_output(); diff --git a/src/messenger/webim/operator/operator.php b/src/messenger/webim/operator/operator.php index 2ac30372..41ea9fd8 100644 --- a/src/messenger/webim/operator/operator.php +++ b/src/messenger/webim/operator/operator.php @@ -86,7 +86,8 @@ $page['operator'] = topage(get_operator_name($operator)); $page['tabs'] = $opId ? array( getlocal("page_agent.tab.main") => "", - getlocal("page_agent.tab.avatar") => "$webimroot/operator/avatar.php?op=$opId" + getlocal("page_agent.tab.avatar") => "$webimroot/operator/avatar.php?op=$opId", + getlocal("page_agent.tab.permissions") => "$webimroot/operator/permissions.php?op=$opId" ) : array(); start_html_output(); diff --git a/src/messenger/webim/operator/permissions.php b/src/messenger/webim/operator/permissions.php new file mode 100644 index 00000000..b9b6992f --- /dev/null +++ b/src/messenger/webim/operator/permissions.php @@ -0,0 +1,76 @@ + $opId); +$page['operator'] = topage(get_operator_name($operator)); +$errors = array(); + +$op = operator_by_id($opId); + +if( !$op ) { + $errors[] = getlocal("no_such_operator"); + +} else if( isset($_POST['op']) ) { + + $new_permissions = isset($op['iperm']) ? $op['iperm'] : 0; + + foreach($permission_ids as $perm => $id) { + if( verifyparam("permissions$id","/^on$/", "") == "on") { + $new_permissions |= (1 << $perm); + } else { + $new_permissions &= ~ (1 << $perm); + } + } + + if(count($errors) == 0) { + update_operator_permissions($op['operatorid'],$new_permissions); + + header("Location: $webimroot/operator/operator.php?op=$opId"); + exit; + } + +} + +$page['tabs'] = array( + getlocal("page_agent.tab.main") => "$webimroot/operator/operator.php?op=$opId", + getlocal("page_agent.tab.avatar") => "$webimroot/operator/avatar.php?op=$opId", + getlocal("page_agent.tab.permissions") => "" +); + +$page['permissionsList'] = get_permission_list(); +$page['formpermissions'] = array(""); + +foreach($permission_ids as $perm => $id) { + if(is_capable($perm,$op)) { + $page['formpermissions'][] = $id; + } +} + +start_html_output(); +require('../view/permissions.php'); +?> \ No newline at end of file diff --git a/src/messenger/webim/view/permissions.php b/src/messenger/webim/view/permissions.php new file mode 100644 index 00000000..a59d09f7 --- /dev/null +++ b/src/messenger/webim/view/permissions.php @@ -0,0 +1,100 @@ + + + + + + + + + + + + <?php echo getlocal("app.title") ?> - <?php echo getlocal("permissions.title") ?> + + +"> +"> + + + + + + + + +
+ +
+

+
|">|">
+ + + +
+
+ + 0 ) { ?> + + + + + + +
+ 0 ) { + print getlocal("errors.header"); + foreach( $errors as $e ) { + print getlocal("errors.prefix"); + print $e; + print getlocal("errors.suffix"); + } + print getlocal("errors.footer"); + } ?> + +
+ + +
+ + + + +
$v) { if($v) { ?>
+ + + + + + + + + + + + +
+ +
+ + +
+
+ +
+ + + +