avatar management

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@158 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2008-10-05 23:46:54 +00:00
parent 1dcddb9af8
commit cbce7c1561
10 changed files with 292 additions and 8 deletions

View File

@ -124,7 +124,7 @@ function create_table($id,$link) {
mysql_query($query,$link) or show_install_err(' Query failed: '.mysql_error());
if( $id == 'chatoperator' ) {
create_operator_("admin", "", "Administrator", "Administrator", $link);
create_operator_("admin", "", "Administrator", "Administrator", "", $link);
} else if( $id == 'chatrevision' ) {
perform_query("INSERT INTO chatrevision VALUES (1)",$link);
}

View File

@ -301,6 +301,11 @@ function no_field($key) {
return getlocal2("errors.required",array(getlocal($key)));
}
function failed_uploading_file($filename, $key) {
return getlocal2("errors.failed.uploading.file",
array($filename, getlocal($key)));
}
function wrong_field($key) {
return getlocal2("errors.wrong_field",array(getlocal($key)));
}

View File

@ -88,4 +88,9 @@ $online_timeout = 30;
*/
$user_link_pattern = "";
/*
* Maximum uploaded file size.
*/
$max_uploaded_file_size = 100000;
?>

View File

@ -45,24 +45,37 @@ function update_operator($operatorid,$login,$password,$localename,$commonname) {
$link = connect();
$query = sprintf(
"update chatoperator set vclogin = '%s',%s vclocalename = '%s', vccommonname = '%s'".
", vcjabbername= '%s'".
" where operatorid = %s",
mysql_real_escape_string($login),
($password ? " vcpassword='".md5($password)."'," : ""),
mysql_real_escape_string($localename),
mysql_real_escape_string($commonname),
'',
$operatorid );
perform_query($query,$link);
mysql_close($link);
}
function create_operator_($login,$password,$localename,$commonname,$link) {
function update_operator_avatar($operatorid,$avatar) {
$link = connect();
$query = sprintf(
"insert into chatoperator (vclogin,vcpassword,vclocalename,vccommonname) values ('%s','%s','%s','%s')",
"update chatoperator set vcavatar = '%s' where operatorid = %s",
mysql_real_escape_string($avatar), $operatorid );
perform_query($query,$link);
mysql_close($link);
}
function create_operator_($login,$password,$localename,$commonname,$avatar,$link) {
$query = sprintf(
"insert into chatoperator (vclogin,vcpassword,vclocalename,vccommonname,vcavatar,vcjabbername) values ('%s','%s','%s','%s','%s','%s')",
mysql_real_escape_string($login),
md5($password),
mysql_real_escape_string($localename),
mysql_real_escape_string($commonname));
mysql_real_escape_string($commonname),
mysql_real_escape_string($avatar), '');
perform_query($query,$link);
$id = mysql_insert_id($link);
@ -70,9 +83,9 @@ function create_operator_($login,$password,$localename,$commonname,$link) {
return select_one_row("select * from chatoperator where operatorid = $id", $link );
}
function create_operator($login,$password,$localename,$commonname) {
function create_operator($login,$password,$localename,$commonname,$avatar) {
$link = connect();
$newop = create_operator_($login,$password,$localename,$commonname,$link);
$newop = create_operator_($login,$password,$localename,$commonname,$avatar,$link);
mysql_close($link);
return $newop;
}

View File

@ -106,6 +106,7 @@ page_agent.title=Operator details
page_agent.intro=This page displays agent details, if you have access rights you can edit them.
page_agent.error.duplicate_login=Please choose another login, because agent with entered login is already registered in the system.
page_agent.error.wrong_login=Login should contain only latin characters, numbers and underscore symbol.
page_agent.clear_avatar=Remove avatar
my_settings.error.password_match=Entered passwords do not match
topMenu.admin=Administration
topMenu.users=Visitors
@ -135,6 +136,10 @@ form.field.password_confirm=Confirmation
form.field.password_confirm.description=Confirm new password.
form.field.password=Password
form.field.password.description=Enter new password or leave the <br/>field empty to keep previous one.
form.field.avatar.upload=Upload avatar
form.field.avatar.upload.description=Choose the avatar file to upload. <br/> The picture size should not exceed 100x100 px.
form.field.avatar.current=Current avatar image
form.field.avatar.current.description=Your avatar image.
form.field.address=Visitor's Address
form.field.address.description=Ex: 12.23.45.123 or todo.com
form.field.ban_days=Days
@ -173,6 +178,10 @@ confirm.take.yes=Yes, I'm sure
content.blocked=Here you can defend from malicious visitors.
content.history=Search the dialogs history
content.logoff=Log out of the system.
errors.failed.uploading.file=Error uploading file "{0}": "{1}".
errors.file.move.error=Error moving file
errors.file.size.exceeded=Uploaded file size exceeded
errors.invalid.file.type=Invalid file type
errors.wrong_field=Please fill "{0}" correctly.
form.field.agent_commonname=International name (Latin)
form.field.agent_commonname.description=This name will be seen by your visitors.
@ -221,8 +230,12 @@ page.gen_button.choose_locale=Target locale
page.gen_button.include_site_name=Include host name into code
page.gen_button.secure_links=Use secure links (https)
page_agent.create_new=Here you can create new operator
page_agent.tab.avatar=Photo
page_agent.tab.main=General
page_agents.agent_commonname=International name
page_analysis.full.text.search=User name or message text search:
page_avatar.intro=You can upload your photo only in JPG, GIF, PNG or TIF image file.
page_avatar.title=Upload photo
page_search.intro=Search for chat history of a specified user or a specified phrase in a message.
page_settings.intro=Specify options affecting chat window and common system behavior
settings.company.title=Company title

View File

@ -106,6 +106,7 @@ page_agent.title=
page_agent.intro=На этой странице Вы можете просмотреть детали и свойства агента и отредактировать их
page_agent.error.duplicate_login=Выберите другой логин, т.к. агент с введенным логином уже зарегистрирован в системе.
page_agent.error.wrong_login=Логин должен состоять из латинских символов, цифр и знака подчеркивания.
page_agent.clear_avatar=Удалить аватарку
my_settings.error.password_match=Введенные пароли должны совпадать
topMenu.admin=Операторское меню
topMenu.users=Посетители
@ -135,6 +136,10 @@ form.field.password_confirm=
form.field.password_confirm.description=Подтвердите введенный пароль.
form.field.password=Пароль
form.field.password.description=Введите новый пароль или оставьте поле <br/>пустым, чтобы сохранить старый.
form.field.avatar.upload=Загрузить аватарку
form.field.avatar.upload.description=Выберите файл на локальном диске. <br/> Для наилучшего отображения размер картинки <br/> не должен превосходить 100x100 px.
form.field.avatar.current=Изображение текущей аватарки
form.field.avatar.current.description=Данное изображение посетители будут видеть своем чат окне, <br/> когда будут общаться с Вами. Нажав на ссылку под изображением,<br/>Вы можете удалить аватарку.
form.field.address=Адрес посетителя
form.field.address.description=Например: 12.23.45.123 или relay.info.ru
form.field.ban_days=Дни
@ -173,6 +178,10 @@ confirm.take.yes=
content.blocked=Здесь можно защищаться от спама и вредных посетителей
content.history=Поиск по истории диалогов
content.logoff=Покинуть систему.
errors.failed.uploading.file=Ошибка выгрузки файла "{0}": "{1}".
errors.file.move.error=Ошибка копирования файла
errors.file.size.exceeded=Превышен допустимый размер файла
errors.invalid.file.type=Недопустимый формат файла
errors.wrong_field=Неправильно заполнено поле "{0}"
form.field.agent_commonname=Интернациональное имя (латиницей)
form.field.agent_commonname.description=Под этим именем Вас увидят ваши посетители из других стран.
@ -221,8 +230,12 @@ page.gen_button.choose_locale=
page.gen_button.include_site_name=Включать имя сайта в код
page.gen_button.secure_links=Использовать защищенное соединение (https)
page_agent.create_new=Создание нового оператора
page_agent.tab.avatar=Фотография
page_agent.tab.main=Общее
page_agents.agent_commonname=Интернациональное имя
page_analysis.full.text.search=Поиск по имени посетителя или по тексту сообщения:
page_avatar.intro=Вы можете загрузить фотографию расширения JPG, GIF, PNG или TIF.
page_avatar.title=Загрузка фотографии
page_search.intro=На данной странице можно осуществить поиск диалогов по имени пользователя или фразе, встречающейся в сообщении.
page_settings.intro=Здесь вы можете задать опции влияющие на отображение чат окна и общее поведение системы
settings.company.title=Название компании

View File

@ -0,0 +1,102 @@
<?php
/*
* This file is part of Web Instant Messenger project.
*
* Copyright (c) 2005-2008 Web Messenger Community
* 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_once('../libs/common.php');
require_once('../libs/operator.php');
$operator = check_login();
$page = array('agentId' => '', 'avatar' => '');
$page['operator'] = topage(get_operator_name($operator));
$errors = array();
if( isset($_POST['agentId']) ) {
$avatar = '';
$agentId = verifyparam( "agentId", "/^(\d{1,9})?$/", "");
$op = operator_by_id($agentId);
$login = $op ? $op['vclogin'] : '';
if( !$op ) {
$errors[] = getlocal("no_such_operator");
} else if( isset($_FILES['avatarFile']) && $_FILES['avatarFile']['name']) {
$valid_types = array("gif","jpg", "png", "tif");
$orig_filename = $_FILES['avatarFile']['name'];
$tmp_file_name = $_FILES['avatarFile']['tmp_name'];
$ext = substr($orig_filename, 1 + strrpos($orig_filename, "."));
$new_file_name = "$agentId.$ext";
if ($_FILES['avatarFile']['size'] > $max_uploaded_file_size) {
$errors[] = failed_uploading_file($orig_filename, "errors.file.size.exceeded");
} elseif(!in_array($ext, $valid_types)) {
$errors[] = failed_uploading_file($orig_filename, "errors.invalid.file.type");
} else {
$avatar_local_dir = "../images/avatar/";
$full_file_path = $avatar_local_dir.$new_file_name;
if (file_exists($full_file_path)) {
unlink($full_file_path);
}
if (!move_uploaded_file($_FILES['avatarFile']['tmp_name'], $full_file_path)) {
$errors[] = failed_uploading_file($orig_filename, "errors.file.move.error");
} else {
$avatar = "$webimroot/images/avatar/$new_file_name";
}
}
} else {
$errors[] = "No file selected";
}
if(count($errors) == 0) {
update_operator_avatar($op['operatorid'],$avatar);
if ($agentId && $avatar && $_SESSION['operator'] && $operator['operatorid'] == $agentId) {
$_SESSION['operator']['vcavatar'] = $avatar;
}
header("Location: $webimroot/operator/avatar.php?op=".topage($op['vclogin']));
exit;
} else {
$page['avatar'] = topage($op ? $op['vcavatar'] : '');
$page['agentId'] = $agentId;
$page['formlogin'] = topage($login);
}
} else {
$login = verifyparam( 'op', "/^[\w_]+$/");
$op = operator_by_login( $login );
if( !$op ) {
$errors[] = getlocal("no_such_operator");
$page['formlogin'] = topage($login);
} else {
if (isset($_GET['delete']) && $_GET['delete'] == "true") {
update_operator_avatar($op['operatorid'],'');
header("Location: $webimroot/operator/avatar.php?op=".topage($op['vclogin']));
exit;
}
$page['formlogin'] = topage($op['vclogin']);
$page['agentId'] = topage($op['operatorid']);
$page['avatar'] = topage($op['vcavatar']);
}
}
$page['tabs'] = isset($login) ? array(
getlocal("page_agent.tab.main") => "$webimroot/operator/operator.php?op=".topage($login),
getlocal("page_agent.tab.avatar") => ""
) : array();
start_html_output();
require('../view/avatar.php');
?>

View File

@ -53,7 +53,7 @@ if( isset($_POST['login']) && isset($_POST['password']) ) {
if( count($errors) == 0 ) {
if (!$agentId) {
create_operator($login,$password,$localname,$commonname);
create_operator($login,$password,$localname,$commonname,"");
} else {
update_operator($agentId,$login,$password,$localname,$commonname);
}
@ -83,6 +83,11 @@ if( isset($_POST['login']) && isset($_POST['password']) ) {
$page['operator'] = topage(get_operator_name($operator));
$page['tabs'] = isset($login) ? array(
getlocal("page_agent.tab.main") => "",
getlocal("page_agent.tab.avatar") => "$webimroot/operator/avatar.php?op=".topage($login)
) : array();
start_html_output();
require('../view/agent.php');
?>

View File

@ -70,7 +70,11 @@
<?php } ?>
<form name="agentForm" method="post" action="<?php echo $webimroot ?>/operator/operator.php">
<table cellspacing='0' cellpadding='0' border='0'><tr><td background='<?php echo $webimroot ?>/images/loginbg.gif'><table cellspacing='0' cellpadding='0' border='0'><tr><td><img src='<?php echo $webimroot ?>/images/logincrnlt.gif' width='16' height='16' border='0' alt=''></td><td></td><td><img src='<?php echo $webimroot ?>/images/logincrnrt.gif' width='16' height='16' border='0' alt=''></td></tr><tr><td></td><td align='center'><table border='0' cellspacing='0' cellpadding='0'>
<table cellspacing='0' cellpadding='0' border='0'>
<?php if($page['tabs']) { ?>
<tr><td align="right" style="padding-right:16px;"><table cellspacing="0" cellpadding="0" border="0"><tr><?php foreach($page['tabs'] as $k => $v) { if($v) { ?><td class="textform" style="padding: 2px 9px 3px 9px;"><a href="<?php echo $v ?>"><?php echo $k ?></a></td><?php } else { ?><td class="textform" background="<?php echo $webimroot ?>/images/loginbg.gif" style="border-left:1px solid #bbbbbb;border-top:1px solid #bbbbbb;border-right:1px solid #bbbbbb;padding: 2px 9px 3px 9px;"><?php echo $k ?></td><?php }} ?></tr></table></td></tr>
<?php } ?>
<tr><td background='<?php echo $webimroot ?>/images/loginbg.gif'><table cellspacing='0' cellpadding='0' border='0'><tr><td><img src='<?php echo $webimroot ?>/images/logincrnlt.gif' width='16' height='16' border='0' alt=''></td><td></td><td><img src='<?php echo $webimroot ?>/images/logincrnrt.gif' width='16' height='16' border='0' alt=''></td></tr><tr><td></td><td align='center'><table border='0' cellspacing='0' cellpadding='0'>
<tr><td class='formauth'><?php echo getlocal('form.field.login') ?><b><font class='red'>*</font></b></td><td width='10'><img width='10' height='1' border='0' alt='' src='<?php echo $webimroot ?>/images/free.gif'></td><td></td></tr><tr><td height='2' colspan='3'></td></tr><tr><td>
<input type="text" name="login" size="40" value="<?php echo form_value('login') ?>" class="formauth"/>
</td><td></td><td class='formauth'><span class='formdescr'> &mdash; <?php echo getlocal('form.field.login.description') ?></span></td></tr><tr><td colspan='3' height='10'></td></tr>
@ -91,6 +95,7 @@
<input type="text" name="commonname" size="40" value="<?php echo form_value('commonname') ?>" class="formauth"/>
</td><td></td><td class='formauth'><span class='formdescr'> &mdash; <?php echo getlocal('form.field.agent_commonname.description') ?></span></td></tr><tr><td colspan='3' height='10'></td></tr>
<tr><td colspan='3' height='20'></td></tr><tr><td colspan='3' background='<?php echo $webimroot ?>/images/formline.gif'><img src='<?php echo $webimroot ?>/images/formline.gif' width='1' height='2' border='0' alt=''></td></tr><tr><td colspan='3' height='10'></td></tr>
<tr>
<td class="formauth" colspan="3">

View File

@ -0,0 +1,123 @@
<?php
/*
* This file is part of Web Instant Messenger project.
*
* Copyright (c) 2005-2008 Web Messenger Community
* 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
*/
?>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo $webimroot ?>/styles.css" />
<link rel="shortcut icon" href="<?php echo $webimroot ?>/images/favicon.ico" type="image/x-icon"/>
<title>
<?php echo getlocal("app.title") ?> - <?php echo getlocal("page_avatar.title") ?>
</title>
<meta http-equiv="keywords" content="<?php echo getlocal("page.main_layout.meta_keyword") ?>">
<meta http-equiv="description" content="<?php echo getlocal("page.main_layout.meta_description") ?>">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#2971C1" vlink="#2971C1" alink="#2971C1">
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td valign="top" class="text">
<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="left" valign="top">
<h1><?php echo getlocal("page_avatar.title") ?></h1>
</td><td align="right" class="text" valign="top"><table cellspacing="0" cellpadding="0" border="0"><tr><td class="textform"><?php echo getlocal2("menu.operator",array($page['operator'])) ?></td><td class="textform"><img src='<?php echo $webimroot ?>/images/topdiv.gif' width="25" height="15" border="0" alt="|" /></td><td class="textform"><a href="<?php echo $webimroot ?>/operator/operators.php" title="<?php echo getlocal("menu.agents") ?>"><?php echo getlocal("menu.agents") ?></a></td><td class="textform"><img src='<?php echo $webimroot ?>/images/topdiv.gif' width="25" height="15" border="0" alt="|" /></td><td class="textform"><a href="<?php echo $webimroot ?>/operator/index.php" title="<?php echo getlocal("menu.main") ?>"><?php echo getlocal("menu.main") ?></a></td></tr></table></td></tr></table>
<?php echo getlocal("page_avatar.intro") ?>
<br />
<br />
<?php if( isset($errors) && count($errors) > 0 ) { ?>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td valign="top"><img src='<?php echo $webimroot ?>/images/icon_err.gif' width="40" height="40" border="0" alt="" /></td>
<td width="10"></td>
<td class="text">
<?php if( isset($errors) && count($errors) > 0 ) {
print getlocal("errors.header");
foreach( $errors as $e ) {
print getlocal("errors.prefix");
print $e;
print getlocal("errors.suffix");
}
print getlocal("errors.footer");
} ?>
</td>
</tr>
</table>
<?php } ?>
<form name="avatarForm" method="post" action="<?php echo $webimroot ?>/operator/avatar.php" enctype="multipart/form-data">
<table cellspacing='0' cellpadding='0' border='0'>
<?php if($page['tabs']) { ?>
<tr><td align="right" style="padding-right:16px;"><table cellspacing="0" cellpadding="0" border="0"><tr><?php foreach($page['tabs'] as $k => $v) { if($v) { ?><td class="textform" style="padding: 2px 9px 3px 9px;"><a href="<?php echo $v ?>"><?php echo $k ?></a></td><?php } else { ?><td class="textform" background="<?php echo $webimroot ?>/images/loginbg.gif" style="border-left:1px solid #bbbbbb;border-top:1px solid #bbbbbb;border-right:1px solid #bbbbbb;padding: 2px 9px 3px 9px;"><?php echo $k ?></td><?php }} ?></tr></table></td></tr>
<?php } ?>
<tr><td background='<?php echo $webimroot ?>/images/loginbg.gif'><table cellspacing='0' cellpadding='0' border='0'><tr><td><img src='<?php echo $webimroot ?>/images/logincrnlt.gif' width='16' height='16' border='0' alt=''></td><td></td><td><img src='<?php echo $webimroot ?>/images/logincrnrt.gif' width='16' height='16' border='0' alt=''></td></tr><tr><td></td><td align='center'><table border='0' cellspacing='0' cellpadding='0'>
<?php if( $page['avatar'] ) { ?>
<tr><td class='formauth'><?php echo getlocal('form.field.avatar.current') ?></td><td width='10'><img width='10' height='1' border='0' alt='' src='<?php echo $webimroot ?>/images/free.gif'></td><td></td></tr><tr><td height='2' colspan='3'></td></tr><tr><td>
<img src="<?php echo $page['avatar'] ?>"/>
<br/>
<a class="formauth" href='<?php echo $webimroot ?>/operator/avatar.php?op=<?php echo $page['formlogin'] ?>&delete=true'>
<?php echo getlocal("page_agent.clear_avatar") ?>
</a>
</td><td></td><td class='formauth'><span class='formdescr'> &mdash; <?php echo getlocal('form.field.avatar.current.description') ?></span></td></tr><tr><td colspan='3' height='10'></td></tr>
<?php } ?>
<tr><td class='formauth'><?php echo getlocal('form.field.avatar.upload') ?><b><font class='red'>*</font></b></td><td width='10'><img width='10' height='1' border='0' alt='' src='<?php echo $webimroot ?>/images/free.gif'></td><td></td></tr><tr><td height='2' colspan='3'></td></tr><tr><td>
<input type="file" name="avatarFile" size="40" value="<?php echo form_value('avatarFile') ?>" class="formauth"/>
</td><td></td><td class='formauth'><span class='formdescr'> &mdash; <?php echo getlocal('form.field.avatar.upload.description') ?></span></td></tr><tr><td colspan='3' height='10'></td></tr>
<tr><td colspan='3' height='20'></td></tr><tr><td colspan='3' background='<?php echo $webimroot ?>/images/formline.gif'><img src='<?php echo $webimroot ?>/images/formline.gif' width='1' height='2' border='0' alt=''></td></tr><tr><td colspan='3' height='10'></td></tr>
<tr>
<td class="formauth" colspan="3">
<input type="hidden" name="agentId" value="<?php echo $page['agentId'] ?>"/>
<input type="image" name="" src='<?php echo $webimroot.getlocal("image.button.save") ?>' border="0" alt='<?php echo getlocal("button.save") ?>'/>
</td>
</tr>
</table></td><td></td></tr><tr><td><img src='<?php echo $webimroot ?>/images/logincrnlb.gif' width='16' height='16' border='0' alt=''></td><td></td><td><img src='<?php echo $webimroot ?>/images/logincrnrb.gif' width='16' height='16' border='0' alt=''></td></tr></table></td></tr></table>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="2" height="10"></td>
</tr>
<tr>
<td width="30"></td>
<td class="formauth"><span class="formdescr"><?php echo getlocal("common.asterisk_explanation") ?></span></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>