From 31613b60dbc8cda2879a64108fb299ccf398575e Mon Sep 17 00:00:00 2001 From: Evgeny Gryaznov Date: Sun, 2 Dec 2007 21:32:47 +0000 Subject: [PATCH] leave message, check email, db encoding git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@38 c66351dc-e62f-0410-b875-e3a5c0b9693f --- src/webim/client.php | 9 +- src/webim/install/dbinfo.php | 4 +- src/webim/install/dbperform.php | 1 + src/webim/leavemessage.php | 58 +++++++++++ src/webim/libs/chat.php | 7 +- src/webim/libs/common.php | 10 +- src/webim/libs/config.php | 6 ++ src/webim/locales/en/properties | 15 ++- src/webim/locales/ru/properties | 15 ++- src/webim/mail.php | 19 +++- src/webim/operator/agent.php | 3 +- src/webim/operator/update.php | 2 + src/webim/thread.php | 5 +- src/webim/view/chat_ajaxed.php | 2 +- src/webim/view/chat_leavemsg.php | 146 +++++++++++++++++++++++++++ src/webim/view/chat_leavemsgsent.php | 102 +++++++++++++++++++ src/webim/view/chat_mailthread.php | 24 +++++ src/webim/view/chat_simple.php | 2 +- 18 files changed, 416 insertions(+), 14 deletions(-) create mode 100644 src/webim/leavemessage.php create mode 100644 src/webim/view/chat_leavemsg.php create mode 100644 src/webim/view/chat_leavemsgsent.php diff --git a/src/webim/client.php b/src/webim/client.php index 933b8542..4cc30e88 100644 --- a/src/webim/client.php +++ b/src/webim/client.php @@ -14,6 +14,7 @@ require('libs/common.php'); require('libs/chat.php'); +require('libs/operator.php'); if( !isset($_GET['token']) || !isset($_GET['thread']) ) { @@ -23,6 +24,12 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { } if( !$thread ) { + if(!has_online_operators()) { + start_html_output(); + require('view/chat_leavemsg.php'); + exit; + } + $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""; $remote = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $_SERVER['REMOTE_ADDR']; $visitor = $remote_visitor(); @@ -65,4 +72,4 @@ if( $pparam == "mailthread" ) { require('view/chat_oldbrowser.php'); } -?> \ No newline at end of file +?> diff --git a/src/webim/install/dbinfo.php b/src/webim/install/dbinfo.php index 122c132a..639cf4f4 100644 --- a/src/webim/install/dbinfo.php +++ b/src/webim/install/dbinfo.php @@ -27,7 +27,7 @@ $dbtables = array( "referer" => "text", "locale" => "varchar(8)", "lastpinguser" => "datetime DEFAULT 0", - "lastpingagent" => "datetime DEFAULT 0" + "lastpingagent" => "datetime DEFAULT 0", ), "chatmessage" => array( @@ -56,7 +56,7 @@ $dbtables = array( $dbtables_can_update = array( "chatthread" => array("agentId"), - "chatmessage" => array("agentId") + "chatmessage" => array("agentId"), ); function show_install_err($text) { diff --git a/src/webim/install/dbperform.php b/src/webim/install/dbperform.php index e48245d0..5cd1ee7f 100644 --- a/src/webim/install/dbperform.php +++ b/src/webim/install/dbperform.php @@ -71,6 +71,7 @@ if($act == "createdb") { runsql("ALTER TABLE chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName", $link); runsql("update chatthread,chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link); } + } } diff --git a/src/webim/leavemessage.php b/src/webim/leavemessage.php new file mode 100644 index 00000000..1048a25a --- /dev/null +++ b/src/webim/leavemessage.php @@ -0,0 +1,58 @@ + 0 ) { + $page['formname'] = $name; + $page['formemail'] = $mail; + $page['formmessage'] = $message; + start_html_output(); + require('view/chat_leavemsg.php'); + exit; +} + +$subject = getstring2_("leavemail.subject", array($name), $webim_messages_encoding); +$body = getstring2_("leavemail.body", array($name,$mail,$message), $webim_messages_encoding); + +$headers = 'From: '.$webim_from_email."\r\n" . + 'Reply-To: '.$mail."\r\n" . + 'X-Mailer: PHP/'.phpversion(); + +mail($webim_messages_mail,$subject,wordwrap($body,70),$headers); + + +start_html_output(); +require('view/chat_leavemsgsent.php'); +?> \ No newline at end of file diff --git a/src/webim/libs/chat.php b/src/webim/libs/chat.php index 666b8e4f..67a373d9 100644 --- a/src/webim/libs/chat.php +++ b/src/webim/libs/chat.php @@ -55,12 +55,14 @@ function post_message_($threadid,$kind,$message,$link,$from=null,$time=null,$opi $time ? "FROM_UNIXTIME($time)" : "CURRENT_TIMESTAMP" ); perform_query($query,$link); + return mysql_insert_id($link); } function post_message($threadid,$kind,$message,$from=null,$agentid=null) { $link = connect(); - post_message_($threadid,$kind,$message,$link,$from,null,$agentid); + $id = post_message_($threadid,$kind,$message,$link,$from,null,$agentid); mysql_close($link); + return $id; } function prepare_html_message($text) { @@ -110,8 +112,9 @@ function get_messages($threadid,$meth,$isuser,&$lastid) { while ($msg = mysql_fetch_array($result, MYSQL_ASSOC)) { $message = ($meth == 'text') ? message_to_text($msg) : message_to_html($msg); $messages[] = $message; - if( $msg['messageid'] > $lastid ) + if( $msg['messageid'] > $lastid ) { $lastid = $msg['messageid']; + } } mysql_free_result($result); diff --git a/src/webim/libs/common.php b/src/webim/libs/common.php index 86e3e6bd..c569a71b 100644 --- a/src/webim/libs/common.php +++ b/src/webim/libs/common.php @@ -185,7 +185,7 @@ function connect() { or die('Could not connect: ' . mysql_error()); mysql_select_db($mysqldb,$link) or die('Could not select database'); if( $force_charset_in_connection ) { - mysql_query("SET character set $dbencoding", $link); + mysql_query("SET NAMES '$dbencoding'", $link); } return $link; } @@ -249,6 +249,10 @@ function no_field($key) { return getstring2("errors.required",array(getstring($key))); } +function wrong_field($key) { + return getstring2("errors.wrong_field",array(getstring($key))); +} + function get_popup($href,$message,$title,$wndName,$options) { return "$message"; } @@ -302,6 +306,10 @@ function date_diff($seconds) { } } +function is_valid_email($mail) { + return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $mail); +} + function quote_smart($value,$link) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); diff --git a/src/webim/libs/config.php b/src/webim/libs/config.php index 8014feec..d4ee5b59 100644 --- a/src/webim/libs/config.php +++ b/src/webim/libs/config.php @@ -51,6 +51,12 @@ $force_charset_in_connection = true; */ $webim_from_email = "webim@yourdomain.com"; // email from field +/* + * Inbox for left messages + */ +$webim_messages_mail = "operators@yourdomain.com"; +$webim_messages_encoding = "en"; + /* * Company international name. */ diff --git a/src/webim/locales/en/properties b/src/webim/locales/en/properties index c506a442..7e0f354b 100644 --- a/src/webim/locales/en/properties +++ b/src/webim/locales/en/properties @@ -102,7 +102,7 @@ page.gen_button.code=HTML code page.gen_button.sample=Example page.gen_button.code.description=Caution! Please don't change
the code manually because
we don't guarantee that
it will work! mail.user.history.subject=Web Messenger: dialog history -mail.user.history.body=Hello, {0}!\n\nYour chat history: \n\n{1}\n--- \nKind Regards,\nThe I-Services Support Team +mail.user.history.body=Hello, {0}!\n\nYour chat history: \n\n{1}\n--- \nKind Regards,\nWeb Messenger errors.header=Correct the mistakes: