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

107 lines
2.9 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)
{
$db = Database::getInstance();
$group = $db->query(
"select * from {chatgroup} where groupid = ?",
array($id),
array('return_rows' => Database::RETURN_ONE_ROW)
);
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;
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();
}
}
function get_operator_groupslist($operatorid)
2011-02-26 17:04:12 +03:00
{
$db = Database::getInstance();
if (Settings::get('enablegroups') == '1') {
2011-02-26 17:04:12 +03:00
$groupids = array(0);
$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 "";
}
}
2012-02-24 17:52:39 +04:00
function get_available_parent_groups($skipgroup)
{
$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;
}
function group_has_children($groupid)
2012-02-24 17:52:39 +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
?>