From cbce7c156168515270ce500376d624a4126684b4 Mon Sep 17 00:00:00 2001 From: Evgeny Gryaznov Date: Sun, 5 Oct 2008 23:46:54 +0000 Subject: [PATCH] avatar management git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@158 c66351dc-e62f-0410-b875-e3a5c0b9693f --- src/messenger/webim/install/dbinfo.php | 2 +- src/messenger/webim/libs/common.php | 5 + src/messenger/webim/libs/config.php | 5 + src/messenger/webim/libs/operator.php | 23 +++- src/messenger/webim/locales/en/properties | 13 +++ src/messenger/webim/locales/ru/properties | 13 +++ src/messenger/webim/operator/avatar.php | 102 ++++++++++++++++++ src/messenger/webim/operator/operator.php | 7 +- src/messenger/webim/view/agent.php | 7 +- src/messenger/webim/view/avatar.php | 123 ++++++++++++++++++++++ 10 files changed, 292 insertions(+), 8 deletions(-) create mode 100644 src/messenger/webim/operator/avatar.php create mode 100644 src/messenger/webim/view/avatar.php diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index 65806048..b1a3f0fe 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -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); } diff --git a/src/messenger/webim/libs/common.php b/src/messenger/webim/libs/common.php index 8a86c873..527651f9 100644 --- a/src/messenger/webim/libs/common.php +++ b/src/messenger/webim/libs/common.php @@ -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))); } diff --git a/src/messenger/webim/libs/config.php b/src/messenger/webim/libs/config.php index 520c5776..8e9c6cfb 100644 --- a/src/messenger/webim/libs/config.php +++ b/src/messenger/webim/libs/config.php @@ -88,4 +88,9 @@ $online_timeout = 30; */ $user_link_pattern = ""; +/* + * Maximum uploaded file size. + */ +$max_uploaded_file_size = 100000; + ?> diff --git a/src/messenger/webim/libs/operator.php b/src/messenger/webim/libs/operator.php index 4485a56c..babf1bd6 100644 --- a/src/messenger/webim/libs/operator.php +++ b/src/messenger/webim/libs/operator.php @@ -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; } diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index 6e0617bd..db2ae062 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -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
field empty to keep previous one. +form.field.avatar.upload=Upload avatar +form.field.avatar.upload.description=Choose the avatar file to upload.
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 diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index 20db362f..5980055e 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -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=Введите новый пароль или оставьте поле
пустым, чтобы сохранить старый. +form.field.avatar.upload=Загрузить аватарку +form.field.avatar.upload.description=Выберите файл на локальном диске.
Для наилучшего отображения размер картинки
не должен превосходить 100x100 px. +form.field.avatar.current=Изображение текущей аватарки +form.field.avatar.current.description=Данное изображение посетители будут видеть своем чат окне,
когда будут общаться с Вами. Нажав на ссылку под изображением,
Вы можете удалить аватарку. 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=Название компании diff --git a/src/messenger/webim/operator/avatar.php b/src/messenger/webim/operator/avatar.php new file mode 100644 index 00000000..0cc7d047 --- /dev/null +++ b/src/messenger/webim/operator/avatar.php @@ -0,0 +1,102 @@ + '', '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'); +?> \ No newline at end of file diff --git a/src/messenger/webim/operator/operator.php b/src/messenger/webim/operator/operator.php index 72a0c411..4b70a19f 100644 --- a/src/messenger/webim/operator/operator.php +++ b/src/messenger/webim/operator/operator.php @@ -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'); ?> \ No newline at end of file diff --git a/src/messenger/webim/view/agent.php b/src/messenger/webim/view/agent.php index 9d0fcba5..4edcfe0a 100644 --- a/src/messenger/webim/view/agent.php +++ b/src/messenger/webim/view/agent.php @@ -70,7 +70,11 @@
-
+
+ + + +
$v) { if($v) { ?>
@@ -91,6 +95,7 @@ +
*
diff --git a/src/messenger/webim/view/avatar.php b/src/messenger/webim/view/avatar.php new file mode 100644 index 00000000..14abba01 --- /dev/null +++ b/src/messenger/webim/view/avatar.php @@ -0,0 +1,123 @@ + + + + + + + + + + + + <?php echo getlocal("app.title") ?> - <?php echo getlocal("page_avatar.title") ?> + + +"> +"> + + + + + + + + +
+ +
+

+
|">|">
+ + + +
+
+ + 0 ) { ?> + + + + + + +
+ 0 ) { + print getlocal("errors.header"); + foreach( $errors as $e ) { + print getlocal("errors.prefix"); + print $e; + print getlocal("errors.suffix"); + } + print getlocal("errors.footer"); + } ?> + +
+ + + + + + + +
$v) { if($v) { ?>
+ + + + + + + + + + + + +
+ +
+ &delete=true'> + + +
*
+ +
+ + +
+ + + + + + + + + + + + + + +
+ + + + +
+ + + +