create special thread for left message

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@607 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2009-08-07 22:49:11 +00:00
parent f03fa806ab
commit 672fc56b46
4 changed files with 42 additions and 17 deletions

View File

@ -102,20 +102,15 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
}
}
$extAddr = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
$extAddr = $_SERVER['REMOTE_ADDR'].' ('.$_SERVER['HTTP_X_FORWARDED_FOR'].')';
}
$remoteHost = get_remote_host();
$userbrowser = $_SERVER['HTTP_USER_AGENT'];
$remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
$link = connect();
if(!check_connections_from_remote($remoteHost, $link)) {
mysql_close($link);
die("number of connections from your IP is exceeded, try again later");
}
$thread = create_thread($groupid,$visitor['name'], $remoteHost, $referer,$current_locale,$visitor['id'], $userbrowser,$link);
$thread = create_thread($groupid,$visitor['name'], $remoteHost, $referer,$current_locale,$visitor['id'], $userbrowser,$state_loading,$link);
$_SESSION['threadid'] = $thread['threadid'];
if( $referer ) {

View File

@ -26,6 +26,24 @@ require_once('libs/expand.php');
$errors = array();
$page = array();
function store_message($name, $email, $info, $message) {
global $state_left, $current_locale, $kind_for_agent, $kind_user;
$groupid = 0;
$remoteHost = get_remote_host();
$userbrowser = $_SERVER['HTTP_USER_AGENT'];
$visitor = visitor_from_request();
$link = connect();
$thread = create_thread($groupid,$name,$remoteHost,"",$current_locale,$visitor['id'], $userbrowser,$state_left,$link);
if($email) {
post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.visitor.email',array($email)),$link);
}
if($info) {
post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.visitor.info',array($info)),$link);
}
post_message_($thread['threadid'],$kind_user,$message,$link,$name);
mysql_close($link);
}
$email = getparam('email');
$visitor_name = getparam('name');
$message = getparam('message');
@ -69,6 +87,8 @@ if(!locale_exists($message_locale)) {
$message_locale = $home_locale;
}
store_message($visitor_name, $email, $info, $message);
$subject = getstring2_("leavemail.subject", array($visitor_name), $message_locale);
$body = getstring2_("leavemail.body", array($visitor_name,$email,$message,$info ? "$info\n" : ""), $message_locale);

View File

@ -30,6 +30,7 @@ $state_waiting = 1;
$state_chatting = 2;
$state_closed = 3;
$state_loading = 4;
$state_left = 5;
$kind_user = 1;
$kind_agent = 2;
@ -523,11 +524,10 @@ function thread_by_id($id) {
return $thread;
}
function create_thread($groupid,$username,$remoteHost,$referer,$lang,$userid,$userbrowser,$link) {
global $state_loading;
function create_thread($groupid,$username,$remoteHost,$referer,$lang,$userid,$userbrowser,$initialState,$link) {
$query = sprintf(
"insert into chatthread (userName,userid,ltoken,remote,referer,lrevision,locale,userAgent,dtmcreated,dtmmodified,istate".($groupid?",groupid":"").") values ".
"('%s','%s',%s,'%s','%s',%s,'%s','%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$state_loading".($groupid?",$groupid":"").")",
"('%s','%s',%s,'%s','%s',%s,'%s','%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$initialState".($groupid?",$groupid":"").")",
mysql_real_escape_string($username, $link),
mysql_real_escape_string($userid, $link),
next_token(),
@ -556,14 +556,14 @@ function do_take_thread($threadid,$operatorId,$operatorName) {
}
function reopen_thread($threadid) {
global $state_queue,$state_loading,$state_waiting,$state_chatting,$state_closed,$kind_events;
global $state_queue,$state_loading,$state_waiting,$state_chatting,$state_closed,$state_left,$kind_events;
$link = connect();
$thread = thread_by_id_($threadid, $link);
if( !$thread )
return FALSE;
if( $thread['istate'] == $state_closed )
if( $thread['istate'] == $state_closed || $thread['istate'] == $state_left )
return FALSE;
if( $thread['istate'] != $state_chatting && $thread['istate'] != $state_queue && $thread['istate'] != $state_loading ) {
@ -631,13 +631,13 @@ function check_for_reassign($thread,$operator) {
}
function check_connections_from_remote($remote,$link) {
global $settings, $state_closed;
global $settings, $state_closed, $state_left;
if($settings['max_connections_from_one_host'] == 0) {
return true;
}
$result = select_one_row(
"select count(*) as opened from chatthread ".
"where remote = '". mysql_real_escape_string($remote, $link)."' AND istate <> $state_closed", $link );
"where remote = '". mysql_real_escape_string($remote, $link)."' AND istate <> $state_closed AND istate <> $state_left", $link );
if($result && isset($result['opened'])) {
return $result['opened'] < $settings['max_connections_from_one_host'];
}
@ -669,4 +669,13 @@ function visitor_from_request() {
return array( 'id' => $userId, 'name' => $userName );
}
function get_remote_host() {
$extAddr = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
$extAddr = $_SERVER['REMOTE_ADDR'].' ('.$_SERVER['HTTP_X_FORWARDED_FOR'].')';
}
return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
}
?>

View File

@ -36,7 +36,8 @@ $threadstate_to_string = array(
$state_waiting => "prio",
$state_chatting => "chat",
$state_closed => "closed",
$state_loading => "wait"
$state_loading => "wait",
$state_left => "closed"
);
$threadstate_key = array(
@ -111,7 +112,7 @@ function thread_to_xml($thread,$link) {
}
function print_pending_threads($groupids,$since) {
global $webim_encoding, $settings, $state_closed;
global $webim_encoding, $settings, $state_closed, $state_left;
$link = connect();
$revision = $since;
@ -120,7 +121,7 @@ function print_pending_threads($groupids,$since) {
"unix_timestamp(dtmmodified), lrevision, istate, remote, nextagent, agentId, userid, shownmessageid, userAgent, (select vclocalname from chatgroup where chatgroup.groupid = chatthread.groupid) as groupname ".
"from chatthread where lrevision > $since ".
($since <= 0
? "AND istate <> $state_closed "
? "AND istate <> $state_closed AND istate <> $state_left "
: "").
($settings['enablegroups'] == '1'
? "AND (groupid is NULL".($groupids