2009-03-23 00:22:51 +03:00
|
|
|
<?php
|
|
|
|
/*
|
2009-06-04 02:44:32 +04:00
|
|
|
* This file is part of Mibew Messenger project.
|
2009-08-04 20:30:39 +04:00
|
|
|
*
|
2011-02-16 03:22:22 +03:00
|
|
|
* Copyright (c) 2005-2011 Mibew Messenger Community
|
2009-08-04 19:03:27 +04:00
|
|
|
* All rights reserved. The contents of this file are subject to the terms of
|
|
|
|
* the Eclipse Public License v1.0 which accompanies this distribution, and
|
|
|
|
* is available at http://www.eclipse.org/legal/epl-v10.html
|
2009-08-04 20:30:39 +04:00
|
|
|
*
|
2009-08-04 17:38:37 +04:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* the GNU General Public License Version 2 or later (the "GPL"), in which case
|
|
|
|
* the provisions of the GPL are applicable instead of those above. If you wish
|
|
|
|
* to allow use of your version of this file only under the terms of the GPL, and
|
|
|
|
* not to allow others to use your version of this file under the terms of the
|
|
|
|
* EPL, indicate your decision by deleting the provisions above and replace them
|
|
|
|
* with the notice and other provisions required by the GPL.
|
2009-08-04 20:30:39 +04:00
|
|
|
*
|
2009-03-23 00:22:51 +03:00
|
|
|
* Contributors:
|
|
|
|
* Evgeny Gryaznov - initial API and implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once('../libs/common.php');
|
|
|
|
require_once('../libs/operator.php');
|
2009-03-25 02:34:57 +03:00
|
|
|
require_once('../libs/groups.php');
|
2009-03-23 00:22:51 +03:00
|
|
|
|
|
|
|
$operator = check_login();
|
|
|
|
|
2009-03-23 00:34:08 +03:00
|
|
|
$page = array('grid' => '');
|
2009-03-23 00:22:51 +03:00
|
|
|
$errors = array();
|
|
|
|
$groupid = '';
|
|
|
|
|
2011-02-26 17:06:19 +03:00
|
|
|
function group_by_name($name)
|
|
|
|
{
|
|
|
|
global $mysqlprefix;
|
2009-03-23 00:22:51 +03:00
|
|
|
$link = connect();
|
|
|
|
$group = select_one_row(
|
2011-11-09 22:59:07 +04:00
|
|
|
"select * from ${mysqlprefix}chatgroup where vclocalname = '" . db_escape_string($name) . "'", $link);
|
2011-11-09 18:16:37 +04:00
|
|
|
close_connection($link);
|
2009-03-23 00:22:51 +03:00
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
2012-03-13 21:26:18 +04:00
|
|
|
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)
|
2011-02-26 17:06:19 +03:00
|
|
|
{
|
|
|
|
global $mysqlprefix;
|
2012-03-13 21:26:18 +04:00
|
|
|
check_group_params($group);
|
2009-03-23 00:22:51 +03:00
|
|
|
$link = connect();
|
|
|
|
$query = sprintf(
|
2012-03-13 21:26:18 +04:00
|
|
|
"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']);
|
2011-02-26 17:06:19 +03:00
|
|
|
|
|
|
|
perform_query($query, $link);
|
2011-11-10 00:57:48 +04:00
|
|
|
$id = db_insert_id($link);
|
2009-03-23 00:22:51 +03:00
|
|
|
|
2011-02-26 17:06:19 +03:00
|
|
|
$newdep = select_one_row("select * from ${mysqlprefix}chatgroup where groupid = $id", $link);
|
2011-11-09 18:16:37 +04:00
|
|
|
close_connection($link);
|
2009-03-23 00:22:51 +03:00
|
|
|
return $newdep;
|
|
|
|
}
|
|
|
|
|
2012-03-13 21:26:18 +04:00
|
|
|
/**
|
|
|
|
* @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)
|
2011-02-26 17:06:19 +03:00
|
|
|
{
|
|
|
|
global $mysqlprefix;
|
2012-03-13 21:26:18 +04:00
|
|
|
check_group_params($group, array('id'));
|
2009-03-23 00:22:51 +03:00
|
|
|
$link = connect();
|
|
|
|
$query = sprintf(
|
2012-03-13 21:26:18 +04:00
|
|
|
"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']);
|
2011-02-26 17:06:19 +03:00
|
|
|
perform_query($query, $link);
|
2012-02-24 17:52:39 +04:00
|
|
|
|
2012-03-13 21:26:18 +04:00
|
|
|
if ($group['parent']) {
|
|
|
|
$query = sprintf("update ${mysqlprefix}chatgroup set parent = NULL where parent = %u", $group['id']);
|
2012-02-24 17:52:39 +04:00
|
|
|
perform_query($query, $link);
|
|
|
|
}
|
2011-11-09 18:16:37 +04:00
|
|
|
close_connection($link);
|
2009-03-23 00:22:51 +03:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:06:19 +03:00
|
|
|
if (isset($_POST['name'])) {
|
|
|
|
$groupid = verifyparam("gid", "/^(\d{1,9})?$/", "");
|
2009-03-23 00:22:51 +03:00
|
|
|
$name = getparam('name');
|
|
|
|
$description = getparam('description');
|
|
|
|
$commonname = getparam('commonname');
|
|
|
|
$commondescription = getparam('commondescription');
|
2011-03-02 01:56:27 +03:00
|
|
|
$email = getparam('email');
|
2012-02-24 17:52:39 +04:00
|
|
|
$weight = getparam('weight');
|
|
|
|
$parentgroup = verifyparam("parentgroup", "/^(\d{1,9})?$/", "");
|
2012-03-13 21:26:18 +04:00
|
|
|
$title = getparam('title');
|
|
|
|
$chattitle = getparam('chattitle');
|
|
|
|
$hosturl = getparam('hosturl');
|
|
|
|
$logo = getparam('logo');
|
2011-02-26 17:06:19 +03:00
|
|
|
|
|
|
|
if (!$name)
|
2009-03-23 00:22:51 +03:00
|
|
|
$errors[] = no_field("form.field.groupname");
|
|
|
|
|
2012-02-24 17:52:39 +04:00
|
|
|
if ($email != '' && !is_valid_email($email))
|
|
|
|
$errors[] = wrong_field("form.field.mail");
|
|
|
|
|
2012-02-24 18:50:52 +04:00
|
|
|
if (! preg_match("/^(\d{1,9})?$/", $weight))
|
2012-02-15 17:56:55 +04:00
|
|
|
$errors[] = wrong_field("form.field.groupweight");
|
|
|
|
|
2012-02-24 18:50:52 +04:00
|
|
|
if ($weight == '')
|
|
|
|
$weight = 0;
|
|
|
|
|
2012-02-24 17:52:39 +04:00
|
|
|
if (! $parentgroup)
|
|
|
|
$parentgroup = NULL;
|
2011-03-02 01:56:27 +03:00
|
|
|
|
2009-03-23 00:22:51 +03:00
|
|
|
$existing_group = group_by_name($name);
|
2011-02-26 17:06:19 +03:00
|
|
|
if ((!$groupid && $existing_group) ||
|
|
|
|
($groupid && $existing_group && $groupid != $existing_group['groupid']))
|
2009-03-23 00:22:51 +03:00
|
|
|
$errors[] = getlocal("page.group.duplicate_name");
|
|
|
|
|
2011-02-26 17:06:19 +03:00
|
|
|
if (count($errors) == 0) {
|
2009-03-23 00:22:51 +03:00
|
|
|
if (!$groupid) {
|
2012-03-13 21:26:18 +04:00
|
|
|
$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));
|
2011-02-26 17:06:19 +03:00
|
|
|
header("Location: $webimroot/operator/groupmembers.php?gid=" . $newdep['groupid']);
|
2009-03-23 00:22:51 +03:00
|
|
|
exit;
|
|
|
|
} else {
|
2012-03-13 21:26:18 +04:00
|
|
|
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));
|
2009-03-25 02:34:57 +03:00
|
|
|
header("Location: $webimroot/operator/group.php?gid=$groupid&stored");
|
2009-03-23 00:22:51 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$page['formname'] = topage($name);
|
|
|
|
$page['formdescription'] = topage($description);
|
|
|
|
$page['formcommonname'] = topage($commonname);
|
|
|
|
$page['formcommondescription'] = topage($commondescription);
|
2011-03-02 01:56:27 +03:00
|
|
|
$page['formemail'] = topage($email);
|
2012-02-24 17:52:39 +04:00
|
|
|
$page['formweight'] = topage($weight);
|
|
|
|
$page['formparentgroup'] = topage($parentgroup);
|
2009-03-23 00:34:08 +03:00
|
|
|
$page['grid'] = topage($groupid);
|
2012-03-13 21:26:18 +04:00
|
|
|
$page['formtitle'] = topage($title);
|
|
|
|
$page['formchattitle'] = topage($chattitle);
|
|
|
|
$page['formhosturl'] = topage($hosturl);
|
|
|
|
$page['formlogo'] = topage($logo);
|
2009-03-23 00:22:51 +03:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:06:19 +03:00
|
|
|
} else if (isset($_GET['gid'])) {
|
|
|
|
$groupid = verifyparam('gid', "/^\d{1,9}$/");
|
2009-03-23 00:22:51 +03:00
|
|
|
$group = group_by_id($groupid);
|
|
|
|
|
2011-02-26 17:06:19 +03:00
|
|
|
if (!$group) {
|
2009-03-23 00:22:51 +03:00
|
|
|
$errors[] = getlocal("page.group.no_such");
|
2009-03-23 00:34:08 +03:00
|
|
|
$page['grid'] = topage($groupid);
|
2009-03-23 00:22:51 +03:00
|
|
|
} else {
|
|
|
|
$page['formname'] = topage($group['vclocalname']);
|
|
|
|
$page['formdescription'] = topage($group['vclocaldescription']);
|
|
|
|
$page['formcommonname'] = topage($group['vccommonname']);
|
|
|
|
$page['formcommondescription'] = topage($group['vccommondescription']);
|
2011-03-02 01:56:27 +03:00
|
|
|
$page['formemail'] = topage($group['vcemail']);
|
2012-02-24 17:52:39 +04:00
|
|
|
$page['formweight'] = topage($group['iweight']);
|
|
|
|
$page['formparentgroup'] = topage($group['parent']);
|
2009-03-23 00:34:08 +03:00
|
|
|
$page['grid'] = topage($group['groupid']);
|
2012-03-13 21:26:18 +04:00
|
|
|
$page['formtitle'] = topage($group['vctitle']);
|
|
|
|
$page['formchattitle'] = topage($group['vcchattitle']);
|
|
|
|
$page['formhosturl'] = topage($group['vchosturl']);
|
|
|
|
$page['formlogo'] = topage($group['vclogo']);
|
2009-03-23 00:22:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-25 02:34:57 +03:00
|
|
|
$page['stored'] = isset($_GET['stored']);
|
2012-02-24 17:52:39 +04:00
|
|
|
$page['availableParentGroups'] = get_available_parent_groups($groupid);
|
2009-03-23 00:22:51 +03:00
|
|
|
prepare_menu($operator);
|
2009-03-25 02:34:57 +03:00
|
|
|
setup_group_settings_tabs($groupid, 0);
|
2009-03-23 00:22:51 +03:00
|
|
|
start_html_output();
|
|
|
|
require('../view/group.php');
|
2011-03-02 01:56:27 +03:00
|
|
|
?>
|