From 0fc5beb17a1abfda8eda3a844e619a71e670fd13 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 13 Mar 2012 17:26:18 +0000 Subject: [PATCH] Added pergroups settings --- src/messenger/webim/client.php | 5 +- src/messenger/webim/default.css | 4 + src/messenger/webim/install/dbinfo.php | 8 +- src/messenger/webim/install/dbperform.php | 16 +++ src/messenger/webim/leavemessage.php | 4 +- src/messenger/webim/libs/chat.php | 29 +++-- src/messenger/webim/libs/groups.php | 5 + src/messenger/webim/locales/en/properties | 1 + src/messenger/webim/locales/ru/properties | 1 + src/messenger/webim/mail.php | 7 +- src/messenger/webim/operator/group.php | 122 ++++++++++++++++++---- src/messenger/webim/view/group.php | 65 +++++++++++- 12 files changed, 226 insertions(+), 41 deletions(-) diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index 373ebaed..33a7c7bb 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -50,6 +50,7 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { if( !$thread ) { $groupid = ""; $groupname = ""; + $group = NULL; if($settings['enablegroups'] == '1') { $groupid = verifyparam( "group", "/^\d{1,8}$/", ""); if($groupid) { @@ -91,7 +92,7 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { if(!has_online_operators($groupid)) { $page = array(); - setup_logo(); + setup_logo($group); setup_leavemessage($visitor['name'],$email,$firstmessage,$groupid,$groupname,$info,$referrer,can_show_captcha()); expand("styles/dialogs", getchatstyle(), "leavemessage.tpl"); exit; @@ -102,7 +103,7 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { $visitor_is_invited = $settings['enabletracking'] && $invitation_state['invited'] && !$invitation_state['threadid']; if($settings['enablepresurvey'] == '1' && !(isset($_POST['survey']) && $_POST['survey'] == 'on') && !$visitor_is_invited) { $page = array(); - setup_logo(); + setup_logo($group); setup_survey($visitor['name'], $email, $groupid, $info, $referrer); expand("styles/dialogs", getchatstyle(), "survey.tpl"); close_connection($link); diff --git a/src/messenger/webim/default.css b/src/messenger/webim/default.css index 5da5b8e3..904139a1 100644 --- a/src/messenger/webim/default.css +++ b/src/messenger/webim/default.css @@ -307,6 +307,10 @@ div.errinfo { margin-top: 5px; } +.fheader { + margin: 8px auto 8px; +} + .flabel { position: relative; margin: 8px auto 2px; diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index 39e53dce..a40fd53e 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -22,13 +22,17 @@ $dbtables = array( "${mysqlprefix}chatgroup" => array( "groupid" => "int NOT NULL auto_increment PRIMARY KEY", + "parent" => "int DEFAULT NULL", "vcemail" => "varchar(64)", "vclocalname" => "varchar(64) NOT NULL", "vccommonname" => "varchar(64) NOT NULL", "vclocaldescription" => "varchar(1024) NOT NULL", "vccommondescription" => "varchar(1024) NOT NULL", "iweight" => "int NOT NULL DEFAULT 0", - "parent" => "int DEFAULT NULL", + "vctitle" => "varchar(255) DEFAULT ''", + "vcchattitle" => "varchar(255) DEFAULT ''", + "vclogo" => "varchar(255) DEFAULT ''", + "vchosturl" => "varchar(255) DEFAULT ''", ), "${mysqlprefix}chatthread" => array( @@ -172,7 +176,7 @@ $dbtables_can_update = array( "${mysqlprefix}chatmessage" => array("agentId"), "${mysqlprefix}chatoperator" => array("vcavatar", "vcjabbername", "iperm", "istatus", "idisabled", "vcemail", "dtmrestore", "vcrestoretoken"), "${mysqlprefix}chatban" => array(), - "${mysqlprefix}chatgroup" => array("vcemail", "iweight", "parent"), + "${mysqlprefix}chatgroup" => array("vcemail", "iweight", "parent", "vctitle", "vcchattitle", "vclogo", "vchosturl"), "${mysqlprefix}chatgroupoperator" => array(), "${mysqlprefix}chatresponses" => array("vctitle"), "${mysqlprefix}chatsitevisitor" => array(), diff --git a/src/messenger/webim/install/dbperform.php b/src/messenger/webim/install/dbperform.php index d306a932..24f3a69b 100644 --- a/src/messenger/webim/install/dbperform.php +++ b/src/messenger/webim/install/dbperform.php @@ -177,6 +177,22 @@ if ($act == "silentcreateall") { runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD parent int DEFAULT NULL AFTER groupid", $link); } + if (in_array("${mysqlprefix}chatgroup.vctitle", $absent_columns)) { + runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD vctitle varchar(255) DEFAULT ''", $link); + } + + if (in_array("${mysqlprefix}chatgroup.vcchattitle", $absent_columns)) { + runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD vcchattitle varchar(255) DEFAULT ''", $link); + } + + if (in_array("${mysqlprefix}chatgroup.vclogo", $absent_columns)) { + runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD vclogo varchar(255) DEFAULT ''", $link); + } + + if (in_array("${mysqlprefix}chatgroup.vchosturl", $absent_columns)) { + runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD vchosturl varchar(255) DEFAULT ''", $link); + } + // Add absent indexes $absent_indexes = array(); foreach ($dbtables_indexes as $id => $indexes) { diff --git a/src/messenger/webim/leavemessage.php b/src/messenger/webim/leavemessage.php index 3fa42510..b256d53b 100644 --- a/src/messenger/webim/leavemessage.php +++ b/src/messenger/webim/leavemessage.php @@ -94,7 +94,7 @@ if($settings["enablecaptcha"] == "1" && can_show_captcha()) { if( count($errors) > 0 ) { setup_leavemessage($visitor_name,$email,$message,$groupid,$groupname,$info,$referrer,can_show_captcha()); - setup_logo(); + setup_logo($group); expand("styles/dialogs", getchatstyle(), "leavemessage.tpl"); exit; } @@ -130,6 +130,6 @@ if($inbox_mail) { close_connection($link); } -setup_logo(); +setup_logo($group); expand("styles/dialogs", getchatstyle(), "leavemessagesent.tpl"); ?> \ No newline at end of file diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 6961d907..bfba2ce3 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -299,13 +299,14 @@ function needsFramesrc() return strstr($useragent, "safari/"); } -function setup_logo() +function setup_logo($group = NULL) { global $page, $settings; loadsettings(); - $page['ct.company.name'] = topage($settings['title']); - $page['ct.company.chatLogoURL'] = topage($settings['logo']); - $page['webimHost'] = topage($settings['hosturl']); + $toplevelgroup = (!$group)?array():get_top_level_group($group); + $page['ct.company.name'] = topage(empty($toplevelgroup['vctitle'])?$settings['title']:$toplevelgroup['vctitle']); + $page['ct.company.chatLogoURL'] = topage(empty($toplevelgroup['vclogo'])?$settings['logo']:$toplevelgroup['vclogo']); + $page['webimHost'] = topage(empty($toplevelgroup['vchosturl'])?$settings['hosturl']:$toplevelgroup['vchosturl']); } function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info, $referrer, $canshowcaptcha) @@ -408,6 +409,12 @@ function setup_chatview_for_user($thread, $level) global $page, $webimroot, $settings; loadsettings(); $page = array(); + if (! is_null($thread['groupid'])) { + $group = group_by_id($thread['groupid']); + $group = get_top_level_group($group); + } else { + $group = array(); + } $page['agent'] = false; $page['user'] = true; $page['canpost'] = true; @@ -419,10 +426,10 @@ function setup_chatview_for_user($thread, $level) $page['ct.token'] = $thread['ltoken']; $page['ct.user.name'] = htmlspecialchars(topage($thread['userName'])); $page['canChangeName'] = $settings['usercanchangename'] == "1"; - $page['chat.title'] = topage($settings['chattitle']); + $page['chat.title'] = topage(empty($group['vcchattitle'])?$settings['chattitle']:$group['vcchattitle']); $page['chat.close.confirmation'] = getlocal('chat.close.confirmation'); - setup_logo(); + setup_logo($group); if ($settings['sendmessagekey'] == 'enter') { $page['send_shortcut'] = "Enter"; $page['ignorectrl'] = 1; @@ -449,16 +456,22 @@ function setup_chatview_for_operator($thread, $operator) global $page, $webimroot, $company_logo_link, $webim_encoding, $company_name, $settings; loadsettings(); $page = array(); + if (! is_null($thread['groupid'])) { + $group = group_by_id($thread['groupid']); + $group = get_top_level_group($group); + } else { + $group = array(); + } $page['agent'] = true; $page['user'] = false; $page['canpost'] = $thread['agentId'] == $operator['operatorid']; $page['ct.chatThreadId'] = $thread['threadid']; $page['ct.token'] = $thread['ltoken']; $page['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread['userName'], $thread['remote'], $thread['userid']))); - $page['chat.title'] = topage($settings['chattitle']); + $page['chat.title'] = topage(empty($group['vcchattitle'])?$settings['chattitle']:$group['vcchattitle']); $page['chat.close.confirmation'] = getlocal('chat.close.confirmation'); - setup_logo(); + setup_logo($group); if ($settings['sendmessagekey'] == 'enter') { $page['send_shortcut'] = "Enter"; $page['ignorectrl'] = 1; diff --git a/src/messenger/webim/libs/groups.php b/src/messenger/webim/libs/groups.php index 1abfe89b..106882b8 100644 --- a/src/messenger/webim/libs/groups.php +++ b/src/messenger/webim/libs/groups.php @@ -93,4 +93,9 @@ function group_has_children($groupid, $link) return ($children['count'] > 0); } +function get_top_level_group($group) +{ + return is_null($group['parent'])?$group:group_by_id($group['parent']); +} + ?> diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index 38845101..9d7c524d 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -290,6 +290,7 @@ page.gen_button.secure_links=Use secure links (https) page.gen_button.title=Button HTML code generation page.group.create_new=Create new group here. page.group.duplicate_name=Please choose another name because a group with that name already exists. +page.group.extrafields.title=The fields that located below are extra fields. These fields are only available for the top level groups and override corresponding system settings if specified. page.group.intro=On this page you can edit group details. page.group.membersnum=Operators page.group.no_such=No such group diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index e7e07f07..72f7990b 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -288,6 +288,7 @@ page.gen_button.secure_links= page.gen_button.title=Получение HTML-кода кнопки page.group.create_new=Здесь вы можете создать новую группу. page.group.duplicate_name=Пожалуйста, выберите другое имя. Группа с таким именем уже существует. +page.group.extrafields.title=Поля, расположенные ниже - дополнительные. Эти поля доступны только для групп верхнего уровня и, если заданы, переопределяют соответствующие настройки системы. page.group.intro=Здесь вы можете отредактировать детали группы. page.group.membersnum=Операторы page.group.no_such=Такой группы не существует diff --git a/src/messenger/webim/mail.php b/src/messenger/webim/mail.php index 2a5aba4b..552bb136 100644 --- a/src/messenger/webim/mail.php +++ b/src/messenger/webim/mail.php @@ -22,6 +22,7 @@ require_once('libs/common.php'); require_once('libs/chat.php'); require_once('libs/expand.php'); +require_once('libs/groups.php'); require_once('libs/notify.php'); $errors = array(); @@ -37,7 +38,7 @@ if( !$thread || !isset($thread['ltoken']) || $token != $thread['ltoken'] ) { $email = getparam('email'); $page['email'] = $email; - +$group = is_null($thread['groupid'])?NULL:group_by_id($thread['groupid']); if( !$email ) { $errors[] = no_field("form.field.email"); } else if( !is_valid_email($email)) { @@ -49,7 +50,7 @@ if( count($errors) > 0 ) { $page['ct.chatThreadId'] = $thread['threadid']; $page['ct.token'] = $thread['ltoken']; $page['level'] = ""; - setup_logo(); + setup_logo($group); expand("styles/dialogs", getchatstyle(), "mail.tpl"); exit; } @@ -70,7 +71,7 @@ $link = connect(); webim_mail($email, $webim_mailbox, $subject, $body, $link); close_connection($link); -setup_logo(); +setup_logo($group); expand("styles/dialogs", getchatstyle(), "mailsent.tpl"); exit; ?> \ No newline at end of file diff --git a/src/messenger/webim/operator/group.php b/src/messenger/webim/operator/group.php index ff8e9ab5..e729694d 100644 --- a/src/messenger/webim/operator/group.php +++ b/src/messenger/webim/operator/group.php @@ -39,19 +39,49 @@ function group_by_name($name) return $group; } -function create_group($name, $descr, $commonname, $commondescr, $email, $weight, $parentgroup) +function check_group_params($group, $extra_params = NULL) +{ + $obligatory_params = array( + 'name', + 'description', + 'commonname', + 'commondescription', + 'email', + 'weight', + 'parent', + 'chattitle', + 'hosturl', + 'logo'); + $params = is_null($extra_params)?$obligatory_params:array_merge($obligatory_params,$extra_params); + if(count(array_diff($params, array_keys($group))) != 0){ + die('Wrong parameters set!'); + } +} + +/** + * @param array $group Operators' group. + * The $group array must contains following keys: + * name, description, commonname, commondescription, + * email, weight, parent, title, chattitle, hosturl, logo + */ +function create_group($group) { global $mysqlprefix; + check_group_params($group); $link = connect(); $query = sprintf( - "insert into ${mysqlprefix}chatgroup (parent, vclocalname,vclocaldescription,vccommonname,vccommondescription,vcemail,iweight) values (%s, '%s','%s','%s','%s','%s',%u)", - ($parentgroup?(int)$parentgroup:'NULL'), - db_escape_string($name), - db_escape_string($descr), - db_escape_string($commonname), - db_escape_string($commondescr), - db_escape_string($email), - $weight); + "insert into ${mysqlprefix}chatgroup (parent, vclocalname,vclocaldescription,vccommonname,vccommondescription,vcemail,vctitle,vcchattitle,vchosturl,vclogo,iweight) values (%s, '%s','%s','%s','%s','%s','%s','%s','%s','%s',%u)", + ($group['parent']?(int)$group['parent']:'NULL'), + db_escape_string($group['name']), + db_escape_string($group['description']), + db_escape_string($group['commonname']), + db_escape_string($group['commondescription']), + db_escape_string($group['email']), + db_escape_string($group['title']), + db_escape_string($group['chattitle']), + db_escape_string($group['hosturl']), + db_escape_string($group['logo']), + $group['weight']); perform_query($query, $link); $id = db_insert_id($link); @@ -61,24 +91,35 @@ function create_group($name, $descr, $commonname, $commondescr, $email, $weight, return $newdep; } -function update_group($groupid, $name, $descr, $commonname, $commondescr, $email, $weight, $parentgroup) +/** + * @param array $group Operators' group. + * The $group array must contains following keys: + * id, name, description, commonname, commondescription, + * email, weight, parent, title, chattitle, hosturl, logo + */ +function update_group($group) { global $mysqlprefix; + check_group_params($group, array('id')); $link = connect(); $query = sprintf( - "update ${mysqlprefix}chatgroup set parent = %s, vclocalname = '%s', vclocaldescription = '%s', vccommonname = '%s', vccommondescription = '%s', vcemail = '%s', iweight = %u where groupid = %s", - ($parentgroup?(int)$parentgroup:'NULL'), - db_escape_string($name), - db_escape_string($descr), - db_escape_string($commonname), - db_escape_string($commondescr), - db_escape_string($email), - $weight, - $groupid); + "update ${mysqlprefix}chatgroup set parent = %s, vclocalname = '%s', vclocaldescription = '%s', vccommonname = '%s', vccommondescription = '%s', vcemail = '%s', vctitle = '%s', vcchattitle = '%s', vchosturl = '%s', vclogo = '%s', iweight = %u where groupid = %s", + ($group['parent']?(int)$group['parent']:'NULL'), + db_escape_string($group['name']), + db_escape_string($group['description']), + db_escape_string($group['commonname']), + db_escape_string($group['commondescription']), + db_escape_string($group['email']), + db_escape_string($group['title']), + db_escape_string($group['chattitle']), + db_escape_string($group['hosturl']), + db_escape_string($group['logo']), + $group['weight'], + $group['id']); perform_query($query, $link); - if ($parentgroup) { - $query = sprintf("update ${mysqlprefix}chatgroup set parent = NULL where parent = %u", $groupid); + if ($group['parent']) { + $query = sprintf("update ${mysqlprefix}chatgroup set parent = NULL where parent = %u", $group['id']); perform_query($query, $link); } close_connection($link); @@ -93,6 +134,10 @@ if (isset($_POST['name'])) { $email = getparam('email'); $weight = getparam('weight'); $parentgroup = verifyparam("parentgroup", "/^(\d{1,9})?$/", ""); + $title = getparam('title'); + $chattitle = getparam('chattitle'); + $hosturl = getparam('hosturl'); + $logo = getparam('logo'); if (!$name) $errors[] = no_field("form.field.groupname"); @@ -116,11 +161,34 @@ if (isset($_POST['name'])) { if (count($errors) == 0) { if (!$groupid) { - $newdep = create_group($name, $description, $commonname, $commondescription, $email, $weight, $parentgroup); + $newdep = create_group(array( + 'name' => $name, + 'description' => $description, + 'commonname' => $commonname, + 'commondescription' => $commondescription, + 'email' => $email, + 'weight' => $weight, + 'parent' => $parentgroup, + 'title' => $title, + 'chattitle' => $chattitle, + 'hosturl' => $hosturl, + 'logo' => $logo)); header("Location: $webimroot/operator/groupmembers.php?gid=" . $newdep['groupid']); exit; } else { - update_group($groupid, $name, $description, $commonname, $commondescription, $email, $weight, $parentgroup); + update_group(array( + 'id' => $groupid, + 'name' => $name, + 'description' => $description, + 'commonname' => $commonname, + 'commondescription' => $commondescription, + 'email' => $email, + 'weight' => $weight, + 'parent' => $parentgroup, + 'title' => $title, + 'chattitle' => $chattitle, + 'hosturl' => $hosturl, + 'logo' => $logo)); header("Location: $webimroot/operator/group.php?gid=$groupid&stored"); exit; } @@ -133,6 +201,10 @@ if (isset($_POST['name'])) { $page['formweight'] = topage($weight); $page['formparentgroup'] = topage($parentgroup); $page['grid'] = topage($groupid); + $page['formtitle'] = topage($title); + $page['formchattitle'] = topage($chattitle); + $page['formhosturl'] = topage($hosturl); + $page['formlogo'] = topage($logo); } } else if (isset($_GET['gid'])) { @@ -151,6 +223,10 @@ if (isset($_POST['name'])) { $page['formweight'] = topage($group['iweight']); $page['formparentgroup'] = topage($group['parent']); $page['grid'] = topage($group['groupid']); + $page['formtitle'] = topage($group['vctitle']); + $page['formchattitle'] = topage($group['vcchattitle']); + $page['formhosturl'] = topage($group['vchosturl']); + $page['formlogo'] = topage($group['vclogo']); } } diff --git a/src/messenger/webim/view/group.php b/src/messenger/webim/view/group.php index 9315428e..3de4c874 100644 --- a/src/messenger/webim/view/group.php +++ b/src/messenger/webim/view/group.php @@ -22,6 +22,29 @@ require_once("inc_menu.php"); require_once("inc_tabbar.php"); +function tpl_header() { global $page, $webimroot; +?> + + +
- +

+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+
+