diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index 84d1aff0..661959ba 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -41,66 +41,67 @@ if($settings['enablessl'] == "1" && $settings['forcessl'] == "1") { if( !isset($_GET['token']) || !isset($_GET['thread']) ) { - $chatstyle = verifyparam( "style", "/^\w+$/", ""); - $info = getgetparam('info'); - $email = getgetparam('email'); $thread = NULL; - $firstmessage = NULL; if( isset($_SESSION['threadid']) ) { $thread = reopen_thread($_SESSION['threadid']); } if( !$thread ) { $groupid = ""; + $groupname = ""; if($settings['enablegroups'] == '1') { $groupid = verifyparam( "group", "/^\d{1,8}$/", ""); if($groupid) { $group = group_by_id($groupid); if(!$group) { $groupid = ""; + } else { + $groupname = get_group_name($group); } } } + + $visitor = visitor_from_request(); + if(isset($_POST['survey']) && $_POST['survey'] == 'on') { + $firstmessage = getparam("message"); + $info = getparam("info"); + $email = getparam("email"); + $referrer = urldecode(getparam("referrer")); + + if($settings['usercanchangename'] == "1" && isset($_POST['name'])) { + $newname = getparam("name"); + if($newname != $visitor['name']) { + $data = strtr(base64_encode(myiconv($webim_encoding,"utf-8",$newname)), '+/=', '-_,'); + setcookie($namecookie, $data, time()+60*60*24*365); + $visitor['name'] = $newname; + } + } + } else { + $firstmessage = NULL; + $info = getgetparam('info'); + $email = getgetparam('email'); + $referrer = isset($_GET['url']) ? $_GET['url'] : + (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""); + if(isset($_GET['referrer']) && $_GET['referrer']) { + $referrer .= "\n".$_GET['referrer']; + } + } + if(!has_online_operators($groupid)) { $page = array(); setup_logo(); - $page['formname'] = topage(getgetparam('name')); - $page['formemail'] = topage($email); - $page['showcaptcha'] = $settings["enablecaptcha"] == "1" && can_show_captcha() ? "1" : ""; - $page['info'] = topage($info); + setup_leavemessage($visitor['name'],$email,$firstmessage,$groupid,$groupname,$info,$referrer,can_show_captcha()); expand("styles", getchatstyle(), "leavemessage.tpl"); exit; } - $visitor = visitor_from_request(); - $referer = isset($_GET['url']) ? $_GET['url'] : - (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""); - if(isset($_GET['referrer']) && $_GET['referrer']) { - $referer .= "\n".$_GET['referrer']; - } - - if($settings['enablepresurvey'] == '1') { - if(isset($_POST['survey']) && $_POST['survey'] == 'on') { - $firstmessage = getparam("message"); - $info = getparam("info"); - $email = getparam("email"); - if($settings['usercanchangename'] == "1" && isset($_POST['name'])) { - $newname = getparam("name"); - if($newname != $visitor['name']) { - $data = strtr(base64_encode(myiconv($webim_encoding,"utf-8",$newname)), '+/=', '-_,'); - setcookie($namecookie, $data, time()+60*60*24*365); - $visitor['name'] = $newname; - } - } - $referer = urldecode(getparam("referrer")); - } else { - $page = array(); - setup_logo(); - setup_survey($visitor['name'], $email, $groupid, $info, $referer); - expand("styles", getchatstyle(), "survey.tpl"); - exit; - } + if($settings['enablepresurvey'] == '1' && !(isset($_POST['survey']) && $_POST['survey'] == 'on')) { + $page = array(); + setup_logo(); + setup_survey($visitor['name'], $email, $groupid, $info, $referrer); + expand("styles", getchatstyle(), "survey.tpl"); + exit; } $remoteHost = get_remote_host(); @@ -111,11 +112,11 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { 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,$state_loading,$link); + $thread = create_thread($groupid,$visitor['name'], $remoteHost, $referrer,$current_locale,$visitor['id'], $userbrowser,$state_loading,$link); $_SESSION['threadid'] = $thread['threadid']; - if( $referer ) { - post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.came.from',array($referer)),$link); + if( $referrer ) { + post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.came.from',array($referrer)),$link); } post_message_($thread['threadid'],$kind_info,getstring('chat.wait'),$link); if($email) { @@ -133,6 +134,7 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { $threadid = $thread['threadid']; $token = $thread['ltoken']; $level = get_remote_level($_SERVER['HTTP_USER_AGENT']); + $chatstyle = verifyparam( "style", "/^\w+$/", ""); header("Location: $webimroot/client.php?thread=$threadid&token=$token&level=$level".($chatstyle ? "&style=$chatstyle" : "")); exit; } diff --git a/src/messenger/webim/leavemessage.php b/src/messenger/webim/leavemessage.php index a2c70df1..6d8043c7 100644 --- a/src/messenger/webim/leavemessage.php +++ b/src/messenger/webim/leavemessage.php @@ -22,19 +22,22 @@ require_once('libs/common.php'); require_once('libs/chat.php'); require_once('libs/expand.php'); +require_once('libs/groups.php'); require_once('libs/captcha.php'); $errors = array(); $page = array(); -function store_message($name, $email, $info, $message) { +function store_message($name, $email, $info, $message,$groupid,$referrer) { 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); + $thread = create_thread($groupid,$name,$remoteHost,$referrer,$current_locale,$visitor['id'], $userbrowser,$state_left,$link); + if( $referrer ) { + post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.came.from',array($referrer)),$link); + } if($email) { post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.visitor.email',array($email)),$link); } @@ -45,10 +48,26 @@ function store_message($name, $email, $info, $message) { mysql_close($link); } +$groupid = ""; +$groupname = ""; +loadsettings(); +if($settings['enablegroups'] == '1') { + $groupid = verifyparam( "group", "/^\d{1,8}$/", ""); + if($groupid) { + $group = group_by_id($groupid); + if(!$group) { + $groupid = ""; + } else { + $groupname = get_group_name($group); + } + } +} + $email = getparam('email'); $visitor_name = getparam('name'); $message = getparam('message'); $info = getparam('info'); +$referrer = urldecode(getparam("referrer")); if( !$email ) { $errors[] = no_field("form.field.email"); @@ -62,7 +81,6 @@ if( !$email ) { } } -loadsettings(); if($settings["enablecaptcha"] == "1" && can_show_captcha()) { $captcha = getparam('captcha'); $original = $_SESSION['captcha']; @@ -73,11 +91,7 @@ if($settings["enablecaptcha"] == "1" && can_show_captcha()) { } if( count($errors) > 0 ) { - $page['formname'] = topage($visitor_name); - $page['formemail'] = $email; - $page['formmessage'] = topage($message); - $page['showcaptcha'] = $settings["enablecaptcha"] == "1" && can_show_captcha() ? "1" : ""; - $page['info'] = topage($info); + setup_leavemessage($visitor_name,$email,$message,$groupid,$groupname,$info,$referrer,can_show_captcha()); setup_logo(); expand("styles", getchatstyle(), "leavemessage.tpl"); exit; @@ -88,7 +102,7 @@ if(!locale_exists($message_locale)) { $message_locale = $home_locale; } -store_message($visitor_name, $email, $info, $message); +store_message($visitor_name, $email, $info, $message, $groupid, $referrer); $subject = getstring2_("leavemail.subject", array($visitor_name), $message_locale); $body = getstring2_("leavemail.body", array($visitor_name,$email,$message,$info ? "$info\n" : ""), $message_locale); diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index b6df4c9e..717ae8b9 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -280,6 +280,18 @@ function setup_logo() { $page['webimHost'] = topage($settings['hosturl']); } +function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info, $referrer,$canshowcaptcha) { + global $settings, $page; + $page['formname'] = topage($name); + $page['formemail'] = topage($email); + $page['formmessage'] = $message ? topage($message) : ""; + $page['showcaptcha'] = $settings["enablecaptcha"] == "1" && $canshowcaptcha ? "1" : ""; + $page['formgroupid'] = $groupid; + $page['formgroupname'] = $groupname; + $page['forminfo'] = topage($info); + $page['referrer'] = urlencode(topage($referrer)); +} + function setup_survey($name, $email, $groupid, $info, $referrer) { global $settings, $page; @@ -300,10 +312,11 @@ function setup_survey($name, $email, $groupid, $info, $referrer) { continue; } if($k['ilastseen'] !== NULL && $k['ilastseen'] < $settings['online_timeout']) { - $groupname .= " (online)"; if(!$groupid) { $groupid = $k['groupid']; // select first online group } + } else { + $groupname .= " (offline)"; } $isselected = $k['groupid'] == $groupid; $val .= ""; diff --git a/src/messenger/webim/operator/redirect.php b/src/messenger/webim/operator/redirect.php index c29de53b..7bdb5743 100644 --- a/src/messenger/webim/operator/redirect.php +++ b/src/messenger/webim/operator/redirect.php @@ -67,8 +67,13 @@ if(isset($_GET['nextGroup'])) { $page['message'] = getlocal2("chat.redirected.content",array(topage(get_operator_name($nextOperator)))); if( $thread['istate'] == $state_chatting ) { $link = connect(); - commit_thread( $threadid, - array("istate" => $state_waiting, "nextagent" => $nextid, "agentId" => 0), $link); + $threadupdate = array("istate" => $state_waiting, "nextagent" => $nextid, "agentId" => 0); + if($thread['groupid'] != 0) { + if(FALSE === select_one_row("select groupid from chatgroupoperator where operatorid = $nextid and groupid = ".$thread['groupid'], $link)) { + $threadupdate['groupid'] = 0; + } + } + commit_thread( $threadid, $threadupdate, $link); post_message_($thread['threadid'], $kind_events, getstring2_("chat.status.operator.redirect", array(get_operator_name($operator)),$thread['locale']), $link); diff --git a/src/messenger/webim/styles/default/templates/leavemessage.tpl b/src/messenger/webim/styles/default/templates/leavemessage.tpl index 870e840c..faa33a2e 100644 --- a/src/messenger/webim/styles/default/templates/leavemessage.tpl +++ b/src/messenger/webim/styles/default/templates/leavemessage.tpl @@ -44,6 +44,8 @@
+ +${if:formgroupid}${endif:formgroupid} - +
@@ -68,7 +70,7 @@ ${endif:webimHost} ${endif:ct.company.chatLogoURL} ${msg:leavemessage.title}${if:formgroupname}${form:groupname}: ${endif:formgroupname}${msg:leavemessage.title}
diff --git a/src/messenger/webim/styles/original/templates/leavemessage.tpl b/src/messenger/webim/styles/original/templates/leavemessage.tpl index e6cd559d..e82fbf06 100644 --- a/src/messenger/webim/styles/original/templates/leavemessage.tpl +++ b/src/messenger/webim/styles/original/templates/leavemessage.tpl @@ -29,12 +29,14 @@ + +${if:formgroupid}${endif:formgroupid} diff --git a/src/messenger/webim/styles/simplicity/templates/leavemessage.tpl b/src/messenger/webim/styles/simplicity/templates/leavemessage.tpl index ad7f941f..df92c731 100644 --- a/src/messenger/webim/styles/simplicity/templates/leavemessage.tpl +++ b/src/messenger/webim/styles/simplicity/templates/leavemessage.tpl @@ -10,10 +10,12 @@ + + ${if:formgroupid}${endif:formgroupid}
-

${msg:leavemessage.title}

+

${if:formgroupname}${form:groupname}: ${endif:formgroupname}${msg:leavemessage.title}

-

${msg:leavemessage.title}

+

${if:formgroupname}${form:groupname}: ${endif:formgroupname}${msg:leavemessage.title}