2007-10-10 19:15:47 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of Web Instant Messenger project.
|
|
|
|
*
|
2008-05-06 01:08:57 +04:00
|
|
|
* Copyright (c) 2005-2008 Internet Services Ltd.
|
2007-10-10 19:15:47 +04:00
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under 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
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* Evgeny Gryaznov - initial API and implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
require('../libs/common.php');
|
|
|
|
require('../libs/operator.php');
|
|
|
|
|
|
|
|
$operator = check_login();
|
|
|
|
|
|
|
|
$page = array('agentId' => '');
|
|
|
|
$errors = array();
|
|
|
|
|
2008-05-06 01:08:57 +04:00
|
|
|
|
2007-10-10 19:15:47 +04:00
|
|
|
if( isset($_POST['login']) && isset($_POST['password']) ) {
|
|
|
|
$agentId = verifyparam( "agentId", "/^(\d{1,9})?$/", "");
|
|
|
|
$login = getparam('login');
|
|
|
|
$password = getparam('password');
|
|
|
|
$passwordConfirm = getparam('passwordConfirm');
|
2008-05-06 01:08:57 +04:00
|
|
|
$localname = getparam('name');
|
2007-10-10 19:15:47 +04:00
|
|
|
$commonname = getparam('commonname');
|
|
|
|
|
2008-05-06 01:08:57 +04:00
|
|
|
|
|
|
|
if( !$localname )
|
2007-10-10 19:15:47 +04:00
|
|
|
$errors[] = no_field("form.field.agent_name");
|
|
|
|
|
|
|
|
if( !$commonname )
|
|
|
|
$errors[] = no_field("form.field.agent_commonname");
|
|
|
|
|
|
|
|
if( !$login )
|
|
|
|
$errors[] = no_field("form.field.login");
|
|
|
|
|
|
|
|
if( !$agentId && !$password )
|
|
|
|
$errors[] = no_field("form.field.password");
|
|
|
|
|
|
|
|
if( $password != $passwordConfirm )
|
|
|
|
$errors[] = getstring("my_settings.error.password_match");
|
|
|
|
|
2008-05-06 01:08:57 +04:00
|
|
|
$existing_operator = operator_by_login($login);
|
|
|
|
if( (!$agentId && $existing_operator) ||
|
|
|
|
( $agentId && $existing_operator && $agentId != $existing_operator['operatorid']) )
|
2007-10-10 19:15:47 +04:00
|
|
|
$errors[] = getstring("page_agent.error.duplicate_login");
|
|
|
|
|
|
|
|
if( count($errors) == 0 ) {
|
2008-05-06 01:08:57 +04:00
|
|
|
if (!$agentId) {
|
|
|
|
create_operator($login,$password,$localname,$commonname);
|
2007-10-10 19:15:47 +04:00
|
|
|
} else {
|
2008-05-06 01:08:57 +04:00
|
|
|
update_operator($agentId,$login,$password,$localname,$commonname);
|
2007-10-10 19:15:47 +04:00
|
|
|
}
|
|
|
|
header("Location: ".dirname($_SERVER['PHP_SELF'])."/operators.php");
|
|
|
|
exit;
|
|
|
|
} else {
|
|
|
|
$page['formlogin'] = $login;
|
2008-05-06 01:08:57 +04:00
|
|
|
$page['formname'] = $localname;
|
2007-10-10 19:15:47 +04:00
|
|
|
$page['formcommonname'] = $commonname;
|
|
|
|
$page['agentId'] = $agentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if( isset($_GET['op']) ) {
|
|
|
|
$login = verifyparam( 'op', "/^[\w_]+$/");
|
|
|
|
$op = operator_by_login( $login );
|
|
|
|
|
|
|
|
if( !$op ) {
|
|
|
|
$errors[] = getstring("no_such_operator");
|
|
|
|
$page['formlogin'] = $login;
|
|
|
|
} else {
|
|
|
|
$page['formlogin'] = $op['vclogin'];
|
|
|
|
$page['formname'] = $op['vclocalename'];
|
|
|
|
$page['formcommonname'] = $op['vccommonname'];
|
|
|
|
$page['agentId'] = $op['operatorid'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$page['operator'] = get_operator_name($operator);
|
|
|
|
|
|
|
|
start_html_output();
|
|
|
|
require('../view/agent.php');
|
2007-05-10 21:31:10 +04:00
|
|
|
?>
|