tray/src/messenger/webim/libs/groups.php

98 lines
2.8 KiB
PHP
Raw Normal View History

<?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.
*/
2011-02-26 17:04:12 +03:00
function group_by_id($id)
{
global $mysqlprefix;
$link = connect();
$group = select_one_row(
2011-02-26 17:04:12 +03:00
"select * from ${mysqlprefix}chatgroup where groupid = $id", $link);
close_connection($link);
return $group;
}
2011-02-26 17:04:12 +03:00
function get_group_name($group)
{
global $home_locale, $current_locale;
2011-02-26 17:04:12 +03:00
if ($home_locale == $current_locale || !isset($group['vccommonname']) || !$group['vccommonname'])
return $group['vclocalname'];
else
return $group['vccommonname'];
}
2011-02-26 17:04:12 +03:00
function setup_group_settings_tabs($gid, $active)
{
global $page, $webimroot, $settings;
2011-02-26 17:04:12 +03:00
if ($gid) {
$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();
}
}
2011-02-26 17:04:12 +03:00
function get_operator_groupslist($operatorid, $link)
{
global $settings, $mysqlprefix;
if ($settings['enablegroups'] == '1') {
$groupids = array(0);
$allgroups = select_multi_assoc("select groupid from ${mysqlprefix}chatgroupoperator where operatorid = $operatorid order by groupid", $link);
foreach ($allgroups as $g) {
$groupids[] = $g['groupid'];
}
return implode(",", $groupids);
} else {
return "";
}
}
2012-02-24 17:52:39 +04:00
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);
}
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']);
}
?>