2009-03-25 02:34:57 +03:00
|
|
|
<?php
|
|
|
|
/*
|
2013-03-07 01:22:53 +04:00
|
|
|
* Copyright 2005-2013 the original author or authors.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-03-25 02:34:57 +03:00
|
|
|
*/
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function group_by_id($id)
|
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
$db = Database::getInstance();
|
|
|
|
$group = $db->query(
|
|
|
|
"select * from {chatgroup} where groupid = ?",
|
|
|
|
array($id),
|
|
|
|
array('return_rows' => Database::RETURN_ONE_ROW)
|
|
|
|
);
|
2009-03-25 02:34:57 +03:00
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function get_group_name($group)
|
|
|
|
{
|
2009-03-29 03:51:33 +04:00
|
|
|
global $home_locale, $current_locale;
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($home_locale == $current_locale || !isset($group['vccommonname']) || !$group['vccommonname'])
|
2009-03-29 03:51:33 +04:00
|
|
|
return $group['vclocalname'];
|
|
|
|
else
|
|
|
|
return $group['vccommonname'];
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function setup_group_settings_tabs($gid, $active)
|
|
|
|
{
|
2009-03-25 02:34:57 +03:00
|
|
|
global $page, $webimroot, $settings;
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($gid) {
|
2009-03-25 02:34:57 +03:00
|
|
|
$page['tabs'] = array(
|
|
|
|
getlocal("page_group.tab.main") => $active != 0 ? "$webimroot/operator/group.php?gid=$gid" : "",
|
|
|
|
getlocal("page_group.tab.members") => $active != 1 ? "$webimroot/operator/groupmembers.php?gid=$gid" : "",
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$page['tabs'] = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
function get_operator_groupslist($operatorid)
|
2011-02-26 17:04:12 +03:00
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
global $settings;
|
|
|
|
$db = Database::getInstance();
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($settings['enablegroups'] == '1') {
|
|
|
|
$groupids = array(0);
|
2012-07-13 16:56:50 +04:00
|
|
|
$allgroups = $db->query(
|
|
|
|
"select groupid from {chatgroupoperator} where operatorid = ? order by groupid",
|
|
|
|
array($operatorid),
|
|
|
|
array('return_rows' => Database::RETURN_ALL_ROWS)
|
|
|
|
);
|
2011-02-26 17:04:12 +03:00
|
|
|
foreach ($allgroups as $g) {
|
|
|
|
$groupids[] = $g['groupid'];
|
|
|
|
}
|
|
|
|
return implode(",", $groupids);
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2011-02-26 14:57:56 +03:00
|
|
|
}
|
|
|
|
|
2012-02-24 17:52:39 +04:00
|
|
|
function get_available_parent_groups($skipgroup)
|
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
$db = Database::getInstance();
|
|
|
|
$groupslist = $db->query(
|
|
|
|
"select {chatgroup}.groupid as groupid, parent, vclocalname " .
|
|
|
|
"from {chatgroup} order by vclocalname",
|
|
|
|
NULL,
|
|
|
|
array('return_rows' => Database::RETURN_ALL_ROWS)
|
|
|
|
);
|
2012-02-24 17:52:39 +04:00
|
|
|
$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) );
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
function group_has_children($groupid)
|
2012-02-24 17:52:39 +04:00
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
$db = Database::getInstance();
|
|
|
|
$children = $db->query(
|
|
|
|
"select COUNT(*) as count from {chatgroup} where parent = ?",
|
|
|
|
array($groupid),
|
|
|
|
array('return_rows' => Database::RETURN_ONE_ROW)
|
|
|
|
);
|
2012-02-24 17:52:39 +04:00
|
|
|
return ($children['count'] > 0);
|
|
|
|
}
|
|
|
|
|
2012-03-13 21:26:18 +04:00
|
|
|
function get_top_level_group($group)
|
|
|
|
{
|
|
|
|
return is_null($group['parent'])?$group:group_by_id($group['parent']);
|
|
|
|
}
|
|
|
|
|
2013-03-13 01:03:50 +04:00
|
|
|
?>
|