Added pergroups settings

This commit is contained in:
Dmitriy Simushev 2012-03-13 17:26:18 +00:00
parent f9d39a8257
commit 0fc5beb17a
12 changed files with 226 additions and 41 deletions

View File

@ -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);

View File

@ -307,6 +307,10 @@ div.errinfo {
margin-top: 5px;
}
.fheader {
margin: 8px auto 8px;
}
.flabel {
position: relative;
margin: 8px auto 2px;

View File

@ -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(),

View File

@ -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) {

View File

@ -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");
?>

View File

@ -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;

View File

@ -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']);
}
?>

View File

@ -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

View File

@ -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=Такой группы не существует

View File

@ -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;
?>

View File

@ -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']);
}
}

View File

@ -22,6 +22,29 @@
require_once("inc_menu.php");
require_once("inc_tabbar.php");
function tpl_header() { global $page, $webimroot;
?>
<script type="text/javascript" language="javascript" src="<?php echo $webimroot ?>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" language="javascript">
function updateParentGroup() {
if($("#parentgroup").val() == '') {
$("#extrafields").show();
}else{
$("#extrafields").hide();
}
}
$(function(){
$("#parentgroup").change(function() {
updateParentGroup();
});
updateParentGroup();
});
</script>
<?php
}
$page['title'] = getlocal("page.group.title");
$page['menuid'] = "groups";
@ -107,12 +130,52 @@ require_once('inc_errors.php');
<div class="field">
<div class="flabel"><?php echo getlocal('form.field.groupparent') ?></div>
<div class="fvalue">
<select name="parentgroup" ><?php foreach($page['availableParentGroups'] as $k) { echo "<option value=\"".$k['groupid']."\"".($k['groupid'] == form_value("parentgroup") ? " selected=\"selected\"" : "").">".str_repeat('&nbsp;', $k['level']*2).$k['vclocalname']."</option>"; } ?></select>
<select name="parentgroup" id="parentgroup"><?php foreach($page['availableParentGroups'] as $k) { echo "<option value=\"".$k['groupid']."\"".($k['groupid'] == form_value("parentgroup") ? " selected=\"selected\"" : "").">".str_repeat('&nbsp;', $k['level']*2).$k['vclocalname']."</option>"; } ?></select>
</div>
<div class="fdescr"> &mdash; <?php echo getlocal('form.field.groupparent.description') ?></div>
<br clear="all"/>
</div>
<div id="extrafields">
<div class="fheader"><?php echo getlocal('page.group.extrafields.title') ?></div>
<div class="field">
<div class="flabel"><?php echo getlocal('settings.company.title') ?></div>
<div class="fvalue">
<input type="text" name="title" size="40" value="<?php echo form_value('title') ?>" class="formauth"/>
</div>
<div class="fdescr"> &mdash; <?php echo getlocal('settings.company.title.description') ?></div>
<br clear="all"/>
</div>
<div class="field">
<div class="flabel"><?php echo getlocal('settings.chat.title') ?></div>
<div class="fvalue">
<input type="text" name="chattitle" size="40" value="<?php echo form_value('chattitle') ?>" class="formauth"/>
</div>
<div class="fdescr"> &mdash; <?php echo getlocal('settings.chat.title') ?></div>
<br clear="all"/>
</div>
<div class="field">
<div class="flabel"><?php echo getlocal('settings.logo') ?></div>
<div class="fvalue">
<input type="text" name="logo" size="40" value="<?php echo form_value('logo') ?>" class="formauth"/>
</div>
<div class="fdescr"> &mdash; <?php echo getlocal('settings.logo.description') ?></div>
<br clear="all"/>
</div>
<div class="field">
<div class="flabel"><?php echo getlocal('settings.host') ?></div>
<div class="fvalue">
<input type="text" name="hosturl" size="40" value="<?php echo form_value('hosturl') ?>" class="formauth"/>
</div>
<div class="fdescr"> &mdash; <?php echo getlocal('settings.host.description') ?></div>
<br clear="all"/>
</div>
</div>
<div class="fbutton">
<input type="image" name="save" value="" src='<?php echo $webimroot.getlocal("image.button.save") ?>' alt='<?php echo getlocal("button.save") ?>'/>
</div>