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-02-26 17:06:19 +03:00
|
|
|
"select * from ${mysqlprefix}chatgroup where vclocalname = '" . mysql_real_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;
|
|
|
|
}
|
|
|
|
|
2011-03-02 01:56:27 +03:00
|
|
|
function create_group($name, $descr, $commonname, $commondescr, $email)
|
2011-02-26 17:06:19 +03:00
|
|
|
{
|
|
|
|
global $mysqlprefix;
|
2009-03-23 00:22:51 +03:00
|
|
|
$link = connect();
|
|
|
|
$query = sprintf(
|
2011-03-02 01:56:27 +03:00
|
|
|
"insert into ${mysqlprefix}chatgroup (vclocalname,vclocaldescription,vccommonname,vccommondescription,vcemail) values ('%s','%s','%s','%s','%s')",
|
2011-02-26 17:06:19 +03:00
|
|
|
mysql_real_escape_string($name),
|
|
|
|
mysql_real_escape_string($descr),
|
|
|
|
mysql_real_escape_string($commonname),
|
2011-03-02 01:56:27 +03:00
|
|
|
mysql_real_escape_string($commondescr),
|
|
|
|
mysql_real_escape_string($email));
|
2011-02-26 17:06:19 +03:00
|
|
|
|
|
|
|
perform_query($query, $link);
|
2009-03-23 00:22:51 +03:00
|
|
|
$id = mysql_insert_id($link);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-02 01:56:27 +03:00
|
|
|
function update_group($groupid, $name, $descr, $commonname, $commondescr, $email)
|
2011-02-26 17:06:19 +03:00
|
|
|
{
|
|
|
|
global $mysqlprefix;
|
2009-03-23 00:22:51 +03:00
|
|
|
$link = connect();
|
|
|
|
$query = sprintf(
|
2011-03-02 01:56:27 +03:00
|
|
|
"update ${mysqlprefix}chatgroup set vclocalname = '%s', vclocaldescription = '%s', vccommonname = '%s', vccommondescription = '%s', vcemail = '%s' where groupid = %s",
|
2009-03-23 00:22:51 +03:00
|
|
|
mysql_real_escape_string($name),
|
|
|
|
mysql_real_escape_string($descr),
|
|
|
|
mysql_real_escape_string($commonname),
|
|
|
|
mysql_real_escape_string($commondescr),
|
2011-03-02 01:56:27 +03:00
|
|
|
mysql_real_escape_string($email),
|
2011-02-26 17:06:19 +03:00
|
|
|
$groupid);
|
2009-03-23 00:22:51 +03:00
|
|
|
|
2011-02-26 17:06:19 +03: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');
|
2011-02-26 17:06:19 +03:00
|
|
|
|
|
|
|
if (!$name)
|
2009-03-23 00:22:51 +03:00
|
|
|
$errors[] = no_field("form.field.groupname");
|
|
|
|
|
2011-03-02 01:56:27 +03:00
|
|
|
if ($email != '' && !is_valid_email($email))
|
|
|
|
$errors[] = wrong_field("form.field.mail");
|
|
|
|
|
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) {
|
2011-03-02 01:56:27 +03:00
|
|
|
$newdep = create_group($name, $description, $commonname, $commondescription, $email);
|
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 {
|
2011-03-02 01:56:27 +03:00
|
|
|
update_group($groupid, $name, $description, $commonname, $commondescription, $email);
|
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);
|
2009-03-23 00:34:08 +03:00
|
|
|
$page['grid'] = topage($groupid);
|
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']);
|
2009-03-23 00:34:08 +03:00
|
|
|
$page['grid'] = topage($group['groupid']);
|
2009-03-23 00:22:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-25 02:34:57 +03:00
|
|
|
$page['stored'] = isset($_GET['stored']);
|
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
|
|
|
?>
|