Added aggregating groups

This commit is contained in:
Dmitriy Simushev 2012-02-24 13:52:39 +00:00
parent 4f16162665
commit 0802ce8993
16 changed files with 158 additions and 55 deletions

View File

@ -329,6 +329,13 @@ div.errinfo {
background: url(images/subitem.gif) no-repeat 10px 2px;
}
.forminner .level0{
}
.forminner .level1{
padding-left: 20px;
}
.fieldinrow {
min-width: 300px;
display: inline;
@ -502,6 +509,13 @@ table.list tbody tr:hover td, table.list tbody tr:hover td a, table.statistics t
color: #1D485E;
}
table.list td.level0{
}
table.list td.level1{
padding-left: 20px;
}
/* awaiting */
table.awaiting {

View File

@ -28,6 +28,7 @@ $dbtables = array(
"vclocaldescription" => "varchar(1024) NOT NULL",
"vccommondescription" => "varchar(1024) NOT NULL",
"iweight" => "int NOT NULL DEFAULT 0",
"parent" => "int DEFAULT NULL",
),
"${mysqlprefix}chatthread" => array(
@ -146,6 +147,9 @@ $dbtables = array(
);
$dbtables_indexes = array(
"${mysqlprefix}chatgroup" => array(
"parent" => "parent"
),
"${mysqlprefix}chatmessage" => array(
"idx_agentid" => "agentid"
),
@ -164,7 +168,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"),
"${mysqlprefix}chatgroup" => array("vcemail", "iweight", "parent"),
"${mysqlprefix}chatgroupoperator" => array(),
"${mysqlprefix}chatresponses" => array("vctitle"),
"${mysqlprefix}chatsitevisitor" => array(),

View File

@ -171,6 +171,15 @@ if ($act == "silentcreateall") {
runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD iweight int DEFAULT 0", $link);
}
if (in_array("${mysqlprefix}chatgroup.parent", $absent)) {
runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD parent int DEFAULT NULL AFTER groupid", $link);
}
$res = mysql_query("select null from information_schema.statistics where table_schema = '$mysqldb' and table_name = '${mysqlprefix}chatgroup' and index_name = 'parent'", $link);
if ($res && mysql_num_rows($res) == 0) {
runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD INDEX (parent)", $link);
}
$res = mysql_query("select null from information_schema.statistics where table_schema = '$mysqldb' and table_name = '${mysqlprefix}chatmessage' and index_name = 'idx_agentid'", $link);
if ($res && mysql_num_rows($res) == 0) {
runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD INDEX idx_agentid (agentid)", $link);

View File

@ -331,25 +331,29 @@ function setup_survey($name, $email, $groupid, $info, $referrer)
$page['forminfo'] = topage($info);
$page['referrer'] = urlencode(topage($referrer));
$selectedgroupid = $groupid;
if ($settings['enablegroups'] == '1' && $settings["surveyaskgroup"] == "1") {
$link = connect();
$showgroups = ($groupid == '')?true:group_has_children($groupid, $link);
if ($showgroups) {
$allgroups = get_groups($link, false);
close_connection($link);
$val = "";
$groupdescriptions = array();
foreach ($allgroups as $k) {
$groupname = $k['vclocalname'];
if ($k['inumofagents'] == 0) {
if ($k['inumofagents'] == 0 || ($groupid && $k['parent'] != $groupid && $k['groupid'] != $groupid )) {
continue;
}
if ($k['ilastseen'] !== NULL && $k['ilastseen'] < $settings['online_timeout']) {
if (!$groupid) {
$groupid = $k['groupid']; // select first online group
if (!$selectedgroupid) {
$selectedgroupid = $k['groupid']; // select first online group
}
} else {
$groupname .= " (offline)";
}
$isselected = $k['groupid'] == $groupid;
$isselected = $k['groupid'] == $selectedgroupid;
if ($isselected) {
$defaultdescription = $k['vclocaldescription'];
}
@ -360,6 +364,8 @@ function setup_survey($name, $email, $groupid, $info, $referrer)
$page['group.descriptions'] = json_encode($groupdescriptions);
$page['default.department.description'] = empty($defaultdescription)?' ':$defaultdescription;
}
close_connection($link);
}
$page['showemail'] = $settings["surveyaskmail"] == "1" ? "1" : "";
$page['showmessage'] = $settings["surveyaskmessage"] == "1" ? "1" : "";

View File

@ -72,7 +72,7 @@ function get_groups_list()
$link = connect();
$allgroups = get_all_groups($link);
close_connection($link);
$result[] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"));
$result[] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"), 'level' => 0);
foreach ($allgroups as $g) {
$result[] = $g;
}

View File

@ -66,4 +66,31 @@ function get_operator_groupslist($operatorid, $link)
}
}
function get_available_parent_groups($skipgroup)
{
global $mysqlprefix;
$link = connect();
$query = "select ${mysqlprefix}chatgroup.groupid as groupid, parent, vclocalname from ${mysqlprefix}chatgroup order by vclocalname";
$groupslist = select_multi_assoc($query, $link);
$result = array(array('groupid' => '', 'level' => '', 'vclocalname' => getlocal("form.field.groupparent.root")));
if ($skipgroup) {
$skipgroup = (array)$skipgroup;
} else {
$skipgroup = array();
}
$result = array_merge($result, get_sorted_child_groups_($groupslist, $skipgroup, 0) );
close_connection($link);
return $result;
}
function group_has_children($groupid, $link)
{
global $mysqlprefix;
$children = select_one_row(sprintf("select COUNT(*) as count from ${mysqlprefix}chatgroup where parent = %u", $groupid),
$link);
return ($children['count'] > 0);
}
?>

View File

@ -176,7 +176,8 @@ function has_online_operators($groupid = "")
$link = connect();
$query = "select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time from ${mysqlprefix}chatoperator";
if ($groupid) {
$query .= ", ${mysqlprefix}chatgroupoperator where groupid = $groupid and ${mysqlprefix}chatoperator.operatorid = " .
$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 = " .
"${mysqlprefix}chatgroupoperator.operatorid and istatus = 0";
} else {
if ($settings['enablegroups'] == 1) {
@ -390,14 +391,29 @@ function prepare_menu($operator, $hasright = true)
function get_all_groups($link)
{
global $mysqlprefix;
$query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription from ${mysqlprefix}chatgroup order by vclocalname";
return select_multi_assoc($query, $link);
$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));
}
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;
}
function get_groups($link, $checkaway)
{
global $mysqlprefix;
$query = "select ${mysqlprefix}chatgroup.groupid as groupid, vclocalname, vclocaldescription, iweight" .
$query = "select ${mysqlprefix}chatgroup.groupid as groupid, parent, vclocalname, vclocaldescription, iweight" .
", (SELECT count(*) from ${mysqlprefix}chatgroupoperator where ${mysqlprefix}chatgroup.groupid = " .
"${mysqlprefix}chatgroupoperator.groupid) as inumofagents" .
", (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
@ -412,7 +428,7 @@ function get_groups($link, $checkaway)
: ""
) .
" from ${mysqlprefix}chatgroup order by iweight, vclocalname";
return select_multi_assoc($query, $link);
return get_sorted_child_groups_(select_multi_assoc($query, $link));
}
function get_operator_groupids($operatorid)

View File

@ -154,6 +154,9 @@ form.field.groupdesc=Description
form.field.groupemail.description=Group email for notifications. Leave empty to use the default address.
form.field.groupname.description=Name to identify the group.
form.field.groupname=Name
form.field.groupparent=Parent group
form.field.groupparent.description=Groups can be organized in a hierarchical structure
form.field.groupparent.root=&lt;none&gt;
form.field.groupweight=Weight
form.field.groupweight.description=Groups with lower weight display higher in groups list. Group weight is a positive integer value.
form.field.login.description=Login can consist of small Latin letters and underscore.

View File

@ -152,6 +152,9 @@ form.field.groupdesc=
form.field.groupemail.description=Адрес для извещений. Оставьте пустым, чтобы использовать глобальный адрес.
form.field.groupname.description=Может быть названием отдела в вашей компании.
form.field.groupname=Название группы
form.field.groupparent=Ðîäèòåëüñêàÿ ãðóïïà
form.field.groupparent.description=Ãðóïïû ìîãóò áûòü îðãàíèçîâàíû â èåðàðõè÷åñêóþ ñòðóêòóðó
form.field.groupparent.root=&lt;íåò&gt;
form.field.groupweight=Вес группы
form.field.groupweight.description=Группы с меньшим весом отображаются выше в списке групп. Вес - это целое положительное число.
form.field.login.description=Логин может состоять из маленьких латинских букв и знака подчеркивания.

View File

@ -39,18 +39,19 @@ function group_by_name($name)
return $group;
}
function create_group($name, $descr, $commonname, $commondescr, $weight ,$email)
function create_group($name, $descr, $commonname, $commondescr, $email, $weight, $parentgroup)
{
global $mysqlprefix;
$link = connect();
$query = sprintf(
"insert into ${mysqlprefix}chatgroup (vclocalname,vclocaldescription,vccommonname,vccommondescription,iweight,vcemail) values ('%s','%s','%s','%s',%u,'%s')",
"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),
$weight,
db_escape_string($email));
db_escape_string($email),
$weight);
perform_query($query, $link);
$id = db_insert_id($link);
@ -60,42 +61,50 @@ function create_group($name, $descr, $commonname, $commondescr, $weight ,$email)
return $newdep;
}
function update_group($groupid, $name, $descr, $commonname, $commondescr, $weight, $email)
function update_group($groupid, $name, $descr, $commonname, $commondescr, $email, $weight, $parentgroup)
{
global $mysqlprefix;
$link = connect();
$query = sprintf(
"update ${mysqlprefix}chatgroup set vclocalname = '%s', vclocaldescription = '%s', vccommonname = '%s', vccommondescription = '%s', iweight = %u, vcemail = '%s' where groupid = %s",
"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),
$weight,
db_escape_string($email),
$weight,
$groupid);
perform_query($query, $link);
if ($parentgroup) {
$query = sprintf("update ${mysqlprefix}chatgroup set parent = NULL where parent = %u", $groupid);
perform_query($query, $link);
}
close_connection($link);
}
if (isset($_POST['name'])) {
$groupid = verifyparam("gid", "/^(\d{1,9})?$/", "");
$name = getparam('name');
$description = getparam('description');
$commonname = getparam('commonname');
$commondescription = getparam('commondescription');
$weight = getparam('weight');
$email = getparam('email');
$weight = getparam('weight');
$parentgroup = verifyparam("parentgroup", "/^(\d{1,9})?$/", "");
if (!$name)
$errors[] = no_field("form.field.groupname");
if ($email != '' && !is_valid_email($email))
$errors[] = wrong_field("form.field.mail");
if (! preg_match("/^\d{1,9}$/", $weight))
$errors[] = wrong_field("form.field.groupweight");
if ($email != '' && !is_valid_email($email))
$errors[] = wrong_field("form.field.mail");
if (! $parentgroup)
$parentgroup = NULL;
$existing_group = group_by_name($name);
if ((!$groupid && $existing_group) ||
@ -104,11 +113,11 @@ if (isset($_POST['name'])) {
if (count($errors) == 0) {
if (!$groupid) {
$newdep = create_group($name, $description, $commonname, $commondescription, $weight, $email);
$newdep = create_group($name, $description, $commonname, $commondescription, $email, $weight, $parentgroup);
header("Location: $webimroot/operator/groupmembers.php?gid=" . $newdep['groupid']);
exit;
} else {
update_group($groupid, $name, $description, $commonname, $commondescription, $weight, $email);
update_group($groupid, $name, $description, $commonname, $commondescription, $email, $weight, $parentgroup);
header("Location: $webimroot/operator/group.php?gid=$groupid&stored");
exit;
}
@ -117,8 +126,9 @@ if (isset($_POST['name'])) {
$page['formdescription'] = topage($description);
$page['formcommonname'] = topage($commonname);
$page['formcommondescription'] = topage($commondescription);
$page['formweight'] = topage($weight);
$page['formemail'] = topage($email);
$page['formweight'] = topage($weight);
$page['formparentgroup'] = topage($parentgroup);
$page['grid'] = topage($groupid);
}
@ -134,13 +144,15 @@ if (isset($_POST['name'])) {
$page['formdescription'] = topage($group['vclocaldescription']);
$page['formcommonname'] = topage($group['vccommonname']);
$page['formcommondescription'] = topage($group['vccommondescription']);
$page['formweight'] = topage($group['iweight']);
$page['formemail'] = topage($group['vcemail']);
$page['formweight'] = topage($group['iweight']);
$page['formparentgroup'] = topage($group['parent']);
$page['grid'] = topage($group['groupid']);
}
}
$page['stored'] = isset($_GET['stored']);
$page['availableParentGroups'] = get_available_parent_groups($groupid);
prepare_menu($operator);
setup_group_settings_tabs($groupid, 0);
start_html_output();

View File

@ -129,7 +129,7 @@ function print_pending_threads($groupids, $since)
: "") .
($settings['enablegroups'] == '1'
? "AND (groupid is NULL" . ($groupids
? " OR groupid IN ($groupids)"
? " OR groupid IN ($groupids) OR groupid IN (SELECT parent FROM ${mysqlprefix}chatgroup WHERE groupid IN ($groupids)) "
: "") .
") "
: "") .

View File

@ -49,7 +49,7 @@ require_once('inc_errors.php');
<?php echo getlocal("canned.group") ?><br/>
<select name="group" onchange="this.form.submit();"><?php
foreach($page['groups'] as $k) {
echo "<option value=\"".$k["groupid"]."\"".($k["groupid"] == form_value("group") ? " selected=\"selected\"" : "").">".$k["vclocalname"]."</option>";
echo "<option value=\"".$k["groupid"]."\"".($k["groupid"] == form_value("group") ? " selected=\"selected\"" : "").">".str_repeat('&nbsp', $k['level']*2).$k["vclocalname"]."</option>";
} ?></select>
</div>

View File

@ -74,7 +74,7 @@ require_once('inc_errors.php');
<div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.choose_group") ?></div>
<div class="fvaluenodesc">
<select name="group" onchange="this.form.submit();"><?php foreach($page['groups'] as $k) { echo "<option value=\"".$k['groupid']."\"".($k['groupid'] == form_value("group") ? " selected=\"selected\"" : "").">".$k['vclocalname']."</option>"; } ?></select>
<select name="group" onchange="this.form.submit();"><?php foreach($page['groups'] as $k) { echo "<option value=\"".$k['groupid']."\"".($k['groupid'] == form_value("group") ? " selected=\"selected\"" : "").">".str_repeat('&nbsp;', $k['level']*2).$k['vclocalname']."</option>"; } ?></select>
</div>
</div>
<br clear="all"/>

View File

@ -86,6 +86,15 @@ require_once('inc_errors.php');
<br clear="all"/>
</div>
<div class="field">
<div class="flabel"><?php echo getlocal('form.field.mail') ?></div>
<div class="fvalue">
<input type="text" name="email" size="40" value="<?php echo form_value('email') ?>" class="formauth"/>
</div>
<div class="fdescr"> &mdash; <?php echo getlocal('form.field.groupemail.description') ?></div>
<br clear="all"/>
</div>
<div class="field">
<div class="flabel"><?php echo getlocal('form.field.groupweight') ?></div>
<div class="fvalue">
@ -96,11 +105,11 @@ require_once('inc_errors.php');
</div>
<div class="field">
<div class="flabel"><?php echo getlocal('form.field.mail') ?></div>
<div class="flabel"><?php echo getlocal('form.field.groupparent') ?></div>
<div class="fvalue">
<input type="text" name="email" size="40" value="<?php echo form_value('email') ?>" class="formauth"/>
<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>
</div>
<div class="fdescr"> &mdash; <?php echo getlocal('form.field.groupemail.description') ?></div>
<div class="fdescr"> &mdash; <?php echo getlocal('form.field.groupparent.description') ?></div>
<br clear="all"/>
</div>

View File

@ -73,7 +73,7 @@ require_once('inc_errors.php');
if(count($page['groups']) > 0) {
foreach( $page['groups'] as $grp ) { ?>
<tr>
<td class="notlast">
<td class="notlast level<?php echo $grp['level'] ?>">
<a href="<?php echo $webimroot ?>/operator/group.php?gid=<?php echo $grp['groupid'] ?>" id="ti<?php echo $grp['groupid'] ?>" class="man">
<?php echo htmlspecialchars(topage($grp['vclocalname'])) ?>
</a>

View File

@ -48,7 +48,7 @@ require_once('inc_errors.php');
<b><?php echo $page['currentop'] ?>&lrm;</b>
</p>
<?php foreach( $page['groups'] as $pm ) { ?>
<div class="field">
<div class="field level<?php echo $pm['level'] ?>">
<div class="flabel"><?php echo htmlspecialchars(topage($pm['vclocalname'])) ?></div>
<div class="fvalue">
<input type="checkbox" name="group<?php echo $pm['groupid'] ?>" value="on"<?php echo form_value_mb('group',$pm['groupid']) ? " checked=\"checked\"" : "" ?><?php echo $page['canmodify'] ? "" : " disabled=\"disabled\"" ?>/>