From 609e039950fc5a5a8ac8227fe01ddababaf7a3f7 Mon Sep 17 00:00:00 2001 From: Evgeny Gryaznov Date: Wed, 4 Jun 2008 22:51:46 +0000 Subject: [PATCH] mail fixes, visitors message count in history, loading state, pre 1.0.10 git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@95 c66351dc-e62f-0410-b875-e3a5c0b9693f --- src/webim/INSTALL.txt | 2 +- src/webim/INSTALL_RUS.txt | 2 +- src/webim/button.php | 3 ++- src/webim/client.php | 3 ++- src/webim/install/dbinfo.php | 5 ++-- src/webim/install/dbperform.php | 7 ++++++ src/webim/install/whatsnew.txt | 11 ++++++++ src/webim/leavemessage.php | 12 +++------ src/webim/libs/chat.php | 43 +++++++++++++++++++++----------- src/webim/libs/common.php | 42 +++++++++++++++++++++++-------- src/webim/libs/config.php | 14 +++++++++-- src/webim/locales/en/properties | 2 ++ src/webim/locales/ru/properties | 20 ++++++++------- src/webim/mail.php | 8 +----- src/webim/operator/history.php | 3 ++- src/webim/operator/update.php | 8 +++--- src/webim/view/chat_ajaxed.php | 13 +++++++++- src/webim/view/thread_search.php | 8 ++++-- 18 files changed, 140 insertions(+), 66 deletions(-) diff --git a/src/webim/INSTALL.txt b/src/webim/INSTALL.txt index 6b2c7d15..e36e4414 100644 --- a/src/webim/INSTALL.txt +++ b/src/webim/INSTALL.txt @@ -1,5 +1,5 @@ -Web Instant Messenger 1.0.9 +Web Instant Messenger 1.0.10 Copyright (c) 2005-2008 Web Messenger Creators Community. This program and the accompanying materials are made available under diff --git a/src/webim/INSTALL_RUS.txt b/src/webim/INSTALL_RUS.txt index b4927893..69e393f1 100644 --- a/src/webim/INSTALL_RUS.txt +++ b/src/webim/INSTALL_RUS.txt @@ -1,5 +1,5 @@ -Web Instant Messenger 1.0.9 +Web Instant Messenger 1.0.10 Copyright (c) 2005-2008 сообщество разработчиков Web Messenger. Данное программное обеспечение и сопутствующие материалы подпадают под diff --git a/src/webim/button.php b/src/webim/button.php index 46e7a071..2736f76a 100644 --- a/src/webim/button.php +++ b/src/webim/button.php @@ -17,8 +17,9 @@ require_once('libs/operator.php'); $image = verifyparam("image","/^\w+$/", "webim"); $lang = verifyparam("lang", "/^[\w-]{2,5}$/", ""); -if( !$lang || !in_array($lang,$available_locales) ) +if(!$lang || !in_array($lang,$available_locales)) { $lang = $current_locale; +} $image_postfix = has_online_operators() ? "on" : "off"; $filename = "locales/${lang}/button/${image}_${image_postfix}.gif"; diff --git a/src/webim/client.php b/src/webim/client.php index 26f8b141..8e801f6d 100644 --- a/src/webim/client.php +++ b/src/webim/client.php @@ -31,7 +31,8 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { } $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""; - $remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $_SERVER['REMOTE_ADDR']; + $extAddr = $_SERVER['REMOTE_ADDR']; + $remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr; $visitor = $remote_visitor(); $thread = create_thread($visitor['name'], $remoteHost, $referer,$current_locale); $_SESSION['threadid'] = $thread['threadid']; diff --git a/src/webim/install/dbinfo.php b/src/webim/install/dbinfo.php index e89a3eaf..3ec2e9ff 100644 --- a/src/webim/install/dbinfo.php +++ b/src/webim/install/dbinfo.php @@ -30,6 +30,7 @@ $dbtables = array( "lastpingagent" => "datetime DEFAULT 0", "userTyping" => "int DEFAULT 0", "agentTyping" => "int DEFAULT 0", + "messageCount" => "varchar(16)" ), "chatmessage" => array( @@ -59,7 +60,7 @@ $dbtables = array( $memtables = array(); $dbtables_can_update = array( - "chatthread" => array("agentId", "userTyping", "agentTyping"), + "chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount"), "chatmessage" => array("agentId"), ); @@ -108,7 +109,7 @@ function create_table($id,$link) { function get_tables($link) { global $mysqldb, $errors; - $result = mysql_query("SHOW TABLES FROM $mysqldb"); + $result = mysql_query("SHOW TABLES FROM `$mysqldb`"); if( $result ) { $arr = array(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { diff --git a/src/webim/install/dbperform.php b/src/webim/install/dbperform.php index 5e4eff6b..94236e46 100644 --- a/src/webim/install/dbperform.php +++ b/src/webim/install/dbperform.php @@ -80,6 +80,13 @@ if($act == "createdb") { runsql("ALTER TABLE chatthread ADD userTyping int DEFAULT 0", $link); } + if( in_array("chatthread.messageCount", $absent) ) { + runsql("ALTER TABLE chatthread ADD messageCount varchar(16)", $link); + runsql("ALTER TABLE chatmessage ADD index idx_threadid_ikind (threadid, ikind)", $link); + runsql("UPDATE chatthread t SET t.messageCount = (SELECT COUNT(*) FROM chatmessage WHERE chatmessage.threadid = t.threadid AND ikind = 1)", $link); + runsql("ALTER TABLE chatmessage DROP INDEX idx_threadid_ikind", $link); + } + } } diff --git a/src/webim/install/whatsnew.txt b/src/webim/install/whatsnew.txt index fe123115..2ce54509 100644 --- a/src/webim/install/whatsnew.txt +++ b/src/webim/install/whatsnew.txt @@ -1,4 +1,15 @@ + 1.0.10 + ------ + + [+] Number of messages from visitor in history + [+] State "loading" (means user is still loading his window) + [!] Company logo link target is now an option in config + [!] Mail encoding fixed (separate option) + [!] Operator/user locale is stored in cookie + [!] localized dates + [!] fixed installing on DB with numeric name + 1.0.9 ----- diff --git a/src/webim/leavemessage.php b/src/webim/leavemessage.php index bcff0d24..34f0d8b3 100644 --- a/src/webim/leavemessage.php +++ b/src/webim/leavemessage.php @@ -43,16 +43,10 @@ if( count($errors) > 0 ) { exit; } -// FIXME mail encoding +$subject = getstring2_("leavemail.subject", array($visitor_name), $webim_messages_locale); +$body = getstring2_("leavemail.body", array($visitor_name,$email,$message), $webim_messages_locale); -$subject = getstring2_("leavemail.subject", array($visitor_name), $webim_messages_encoding); -$body = getstring2_("leavemail.body", array($visitor_name,$email,$message), $webim_messages_encoding); - -$headers = 'From: '.$webim_from_email."\r\n" . - 'Reply-To: '.$email."\r\n" . - 'X-Mailer: PHP/'.phpversion(); - -mail($webim_messages_mail,$subject,wordwrap($body,70),$headers); +webim_mail($webim_messages_mail, $email, $subject, $body); start_html_output(); diff --git a/src/webim/libs/chat.php b/src/webim/libs/chat.php index 797a2354..519b8310 100644 --- a/src/webim/libs/chat.php +++ b/src/webim/libs/chat.php @@ -22,6 +22,7 @@ $state_queue = 0; $state_waiting = 1; $state_chatting = 2; $state_closed = 3; +$state_loading = 4; $kind_user = 1; $kind_agent = 2; @@ -166,13 +167,14 @@ function print_thread_messages($thread, $token, $lastid, $isuser,$format) { } } -function get_user_name($username, $id="") { +function get_user_name($username, $addr) { global $presentable_name_pattern; - return str_replace("{id}", $id, str_replace("{name}", $username, $presentable_name_pattern)); + return str_replace("{addr}", $addr, + str_replace("{name}", $username, $presentable_name_pattern)); } function setup_chatview_for_user($thread,$level) { - global $page, $webimroot, $user_can_change_name, $company_logo_link, $company_name; + global $page, $webimroot, $user_can_change_name, $company_logo_link, $company_name, $webim_host; $page = array(); $page['agent'] = false; $page['user'] = true; @@ -192,22 +194,24 @@ function setup_chatview_for_user($thread,$level) { $params = "thread=".$thread['threadid']."&token=".$thread['ltoken']; $page['selfLink'] = "$webimroot/client.php?".$params."&level=".$level; + $page['webimHost'] = $webim_host; } function setup_chatview_for_operator($thread,$operator) { - global $page, $webimroot, $company_logo_link, $company_name; + global $page, $webimroot, $company_logo_link, $company_name, $webim_host; $page = array(); $page['agent'] = true; $page['user'] = false; $page['canpost'] = true; $page['ct.chatThreadId'] = $thread['threadid']; $page['ct.token'] = $thread['ltoken']; - $page['ct.user.name'] = topage(get_user_name($thread['userName'])); + $page['ct.user.name'] = topage(get_user_name($thread['userName'],$thread['remote'])); $page['ct.company.name'] = topage($company_name); $page['ct.company.chatLogoURL'] = topage($company_logo_link); $page['send_shortcut'] = "Ctrl-Enter"; + $page['webimHost'] = $webim_host; // TODO $page['namePostfix'] = ""; @@ -273,14 +277,21 @@ function update_thread_access($threadid, $params, $link) { } function ping_thread($thread, $isuser,$istyping) { - global $kind_for_agent, $state_chatting, $state_waiting, $kind_conn, $connection_timeout; + global $kind_for_agent, $state_queue, $state_loading, $state_chatting, $state_waiting, $kind_conn, $connection_timeout; $link = connect(); $params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP", ($isuser ? "userTyping" : "agentTyping") => ($istyping? "1" : "0") ); $lastping = $thread[$isuser ? "lpagent" : "lpuser"]; $current = $thread['current']; - + + if( $thread['istate'] == $state_loading && $isuser) { + $params['istate'] = $state_queue; + commit_thread($thread['threadid'], $params, $link); + mysql_close($link); + return; + } + if( $lastping > 0 && abs($current-$lastping) > $connection_timeout ) { $params[$isuser ? "lastpingagent" : "lastpinguser"] = "0"; if( !$isuser ) { @@ -302,7 +313,7 @@ function ping_thread($thread, $isuser,$istyping) { } function commit_thread($threadid,$params,$link) { - $query = "update chatthread set lrevision = ".next_revision($link).", dtmmodified = CURRENT_TIMESTAMP"; + $query = "update chatthread t set lrevision = ".next_revision($link).", dtmmodified = CURRENT_TIMESTAMP"; foreach( $params as $k => $v ) { $query .= ", ".$k."=".$v; } @@ -330,7 +341,8 @@ function close_thread($thread,$isuser) { if( $thread['istate'] != $state_closed ) { $link = connect(); - commit_thread( $thread['threadid'], array('istate' => $state_closed), $link); + commit_thread( $thread['threadid'], array('istate' => $state_closed, + 'messageCount' => '(SELECT COUNT(*) FROM chatmessage WHERE chatmessage.threadid = t.threadid AND ikind = 1)'), $link); mysql_close($link); } @@ -353,11 +365,12 @@ function thread_by_id($id) { } function create_thread($username,$remoteHost,$referer,$lang) { + global $state_loading; $link = connect(); $query = sprintf( - "insert into chatthread (userName,"."ltoken,remote,referer,lrevision,locale,dtmcreated,dtmmodified) values ". - "('%s',"."%s,'%s','%s',%s,'%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)", + "insert into chatthread (userName,"."ltoken,remote,referer,lrevision,locale,dtmcreated,dtmmodified,istate) values ". + "('%s',"."%s,'%s','%s',%s,'%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$state_loading)", mysql_real_escape_string($username), next_token(), mysql_real_escape_string($remoteHost), @@ -384,7 +397,7 @@ function do_take_thread($threadid,$operatorId,$operatorName) { } function reopen_thread($threadid) { - global $state_queue,$state_waiting,$state_chatting,$state_closed,$kind_events; + global $state_queue,$state_loading,$state_waiting,$state_chatting,$state_closed,$kind_events; $thread = thread_by_id($threadid); if( !$thread ) @@ -393,7 +406,7 @@ function reopen_thread($threadid) { if( $thread['istate'] == $state_closed ) return FALSE; - if( $thread['istate'] != $state_chatting && $thread['istate'] != $state_queue ) { + if( $thread['istate'] != $state_chatting && $thread['istate'] != $state_queue && $thread['istate'] != $state_loading ) { $link = connect(); commit_thread( $threadid, array("istate" => $state_waiting ), $link); @@ -405,7 +418,7 @@ function reopen_thread($threadid) { } function take_thread($thread,$operator) { - global $state_queue, $state_waiting, $state_chatting, $kind_events, $home_locale; + global $state_queue, $state_loading, $state_waiting, $state_chatting, $kind_events, $home_locale; $state = $thread['istate']; $threadid = $thread['threadid']; @@ -413,7 +426,7 @@ function take_thread($thread,$operator) { $operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname']; - if( $state == $state_queue || $state == $state_waiting) { + if( $state == $state_queue || $state == $state_waiting || $state == $state_loading) { do_take_thread($threadid, $operator['operatorid'], $operatorName); if( $state == $state_waiting ) { diff --git a/src/webim/libs/common.php b/src/webim/libs/common.php index 9e782f40..f9afb65d 100644 --- a/src/webim/libs/common.php +++ b/src/webim/libs/common.php @@ -17,7 +17,7 @@ session_start(); require_once(dirname(__FILE__).'/converter.php'); require_once(dirname(__FILE__).'/config.php'); -$version = 'v1.0.9'; +$version = 'v1.0.10/pre1'; function myiconv($in_enc, $out_enc, $string) { global $_utf8win1251, $_win1251utf8; @@ -69,6 +69,12 @@ function debugexit_print( $var ) { function get_user_locale() { global $available_locales, $default_locale; + if( isset($_COOKIE['webim_locale']) ) { + $requested_lang = $_COOKIE['webim_locale']; + if( in_array($requested_lang,$available_locales) ) + return $requested_lang; + } + if( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ) { $requested_langs = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach( $requested_langs as $requested_lang) { @@ -87,12 +93,13 @@ function get_user_locale() { } function get_locale() { - global $available_locales; + global $available_locales, $webimroot; $locale = verifyparam("locale", "/^[\w-]{2,5}$/", ""); if( $locale && in_array($locale,$available_locales) ) { $_SESSION['locale'] = $locale; + setcookie('webim_locale', $locale, time()+60*60*24*1000, "$webimroot/"); } else if( isset($_SESSION['locale']) ){ $locale = $_SESSION['locale']; } @@ -102,13 +109,8 @@ function get_locale() { return $locale; } -function set_locale($locale) { - global $current_locale, $available_locales; - if( in_array($locale,$available_locales) ) - $current_locale = $locale; -} - $current_locale = get_locale(); +setlocale(LC_TIME, $current_locale); $messages = array(); $output_encoding = array(); @@ -179,6 +181,11 @@ function getlocal($text) { return myiconv($webim_encoding,getoutputenc(), getstring_($text,$current_locale)); } +function getlocal_($text,$locale) { + global $webim_encoding; + return myiconv($webim_encoding,getoutputenc(), getstring_($text,$locale)); +} + function topage($text) { global $webim_encoding; return myiconv($webim_encoding,getoutputenc(), $text); @@ -350,8 +357,8 @@ function date_diff($seconds) { } } -function is_valid_email($mail) { - return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $mail); +function is_valid_email($email) { + return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email); } function quote_smart($value,$link) { @@ -377,7 +384,7 @@ function get_month_selection($fromtime,$totime) { $result = array(); do { $current = mktime(0,0,0,$month,1,$year); - $result[date("m.y",$current)] = date("M, Y",$current); + $result[date("m.y",$current)] = strftime("%B, %Y",$current); $month++; if( $month > 12 ) { $month = 1; @@ -400,4 +407,17 @@ function set_form_date($utime,$prefix) { $page["form${prefix}month"] = date("m.y", $utime); } +function webim_mail($toaddr, $reply_to, $subject, $body) { + global $webim_encoding, $webim_from_email, $mail_encoding; + + $headers = "From: $webim_from_email\r\n" + ."Reply-To: ".myiconv($webim_encoding, $mail_encoding, $reply_to)."\r\n" + ."Content-Type: text/plain; charset=$mail_encoding\r\n" + .'X-Mailer: PHP/'.phpversion(); + + $real_subject = "=?".$mail_encoding."?B?".base64_encode(myiconv($webim_encoding,$mail_encoding,$subject))."?="; + + mail($toaddr, $real_subject, wordwrap(myiconv($webim_encoding, $mail_encoding, $body),70), $headers); +} + ?> \ No newline at end of file diff --git a/src/webim/libs/config.php b/src/webim/libs/config.php index 05cc69a4..29a6e767 100644 --- a/src/webim/libs/config.php +++ b/src/webim/libs/config.php @@ -40,6 +40,11 @@ $force_charset_in_connection = true; */ $compatibility_encoding = "cp1251"; +/* + * This encoding will be used for emails + */ +$mail_encoding = $webim_encoding; + /* * From field in outgoing mail. */ @@ -49,7 +54,7 @@ $webim_from_email = "webim@yourdomain.com"; /* email from field */ * Inbox for left messages */ $webim_messages_mail = "operators@yourdomain.com"; -$webim_messages_encoding = "en"; +$webim_messages_locale = "en"; /* * Company international name. @@ -61,6 +66,11 @@ $company_name = "My Company Ltd."; */ $company_logo_link = ""; +/* + * Web Messenger host + */ +$webim_host = ""; + /* * Locales */ @@ -74,7 +84,7 @@ $default_locale = "en"; /* if user does not provide known la $user_can_change_name = true; /* - * How to build presentable visitor name from {name}. Default: {name} + * How to build presentable visitor name from {name} or {addr}. Default: {name} */ $presentable_name_pattern = "{name}"; diff --git a/src/webim/locales/en/properties b/src/webim/locales/en/properties index 98a777df..f7857cc5 100644 --- a/src/webim/locales/en/properties +++ b/src/webim/locales/en/properties @@ -55,6 +55,7 @@ chat.thread.state_wait=In queue chat.thread.state_wait_for_another_agent=Waiting for operator chat.thread.state_chatting_with_agent=In chat chat.thread.state_closed=Closed +chat.thread.state_loading=Loading clients.title=List of awaiting visitors clients.no_clients=The list of awaiting visitors is empty clients.intro=The page displays list of awaiting visitors. @@ -79,6 +80,7 @@ page_analysis.search.title=Chats history page.analysis.search.head_name=Name page.analysis.search.head_host=Visitor's address page.analysis.search.head_operator=Operator +page.analysis.search.head_messages=Visitor's messages page.analysis.search.head_time=Time in chat common.asterisk_explanation=* - mandatory fields page_agents.title=Agents diff --git a/src/webim/locales/ru/properties b/src/webim/locales/ru/properties index 8e0b12f3..acad71eb 100644 --- a/src/webim/locales/ru/properties +++ b/src/webim/locales/ru/properties @@ -13,9 +13,9 @@ page_login.remember= page_login.error=Введен неправильный логин или пароль agent.not_logged_in=Ваша сессия устарела, войдите, пожалуйста, снова page_client.pending_users=На этой странице можно просмотреть список ожидающих ответа посетителей. -chat.window.title.agent=Вэб Мессенджер -chat.window.title.user=Вэб Мессенджер -chat.window.product_name=Вэб Мессенджер +chat.window.title.agent=Веб Мессенджер +chat.window.title.user=Веб Мессенджер +chat.window.product_name=Веб Мессенджер chat.window.close_title=Закрыть диалог chat.window.chatting_with=Вы общаетесь с: chat.window.poweredby=Предоставлено: @@ -55,6 +55,7 @@ chat.thread.state_wait= chat.thread.state_wait_for_another_agent=Ожидание оператора chat.thread.state_chatting_with_agent=В диалоге chat.thread.state_closed=Закрыто +chat.thread.state_loading=Загружается clients.title=Список ожидающих посетителей clients.no_clients=В этой очереди ожидающих посетителей нет clients.intro=На этой странице можно просмотреть список ожидающих ответа посетителей. @@ -79,6 +80,7 @@ page_analysis.search.title= page.analysis.search.head_name=Имя page.analysis.search.head_host=Адрес посетителя page.analysis.search.head_operator=Оператор +page.analysis.search.head_messages=Сообщений посетителя page.analysis.search.head_time=Время в диалоге common.asterisk_explanation=* - поля, обязательные для заполнения page_agents.title=Агенты @@ -99,14 +101,14 @@ leftMenu.client_agents= leftMenu.client_gen_button=Код кнопки admin.content.description=Набор функций, доступный только зарегистрированным операторам admin.content.client_agents=Создание, удаление агентов компании. Управление их правами и возможностями. -admin.content.client_gen_button=Получение HTML-кода для кнопки "Вэб Мессенджера". +admin.content.client_gen_button=Получение HTML-кода для кнопки "Веб Мессенджера". page.gen_button.title=Получение HTML-кода кнопки -page.gen_button.intro=На этой странице Вы можете получить HTML-код кнопки "Вэб Мессенджера" для размещения на своем сайте. +page.gen_button.intro=На этой странице Вы можете получить HTML-код кнопки "Веб Мессенджера" для размещения на своем сайте. page.gen_button.code=HTML-код page.gen_button.sample=Пример page.gen_button.code.description=Внимание! При внесении
каких-либо изменений
в этот код работоспособность
кнопки не гарантируется! -mail.user.history.subject=Вэб Мессенджер: история диалога -mail.user.history.body=Здраствуйте, {0}!\n\nПо Вашему запросу, высылаем историю: \n\n{1}\n--- \nС уважением,\nВэб Мессенджер +mail.user.history.subject=Веб Мессенджер: история диалога +mail.user.history.body=Здраствуйте, {0}!\n\nПо Вашему запросу, высылаем историю: \n\n{1}\n--- \nС уважением,\nВеб Мессенджер errors.header=Исправьте ошибки: