From a570ed75d02e00e7985407e97fc1bcd3e7a8b978 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 26 Feb 2013 10:19:26 +0000 Subject: [PATCH] Update Chat JavaScript Application Make prechat survey and leave message parts of the Chat JavaScript Application --- src/messenger/webim/client.php | 125 +++------ src/messenger/webim/js/compiled/chat/app.js | 3 +- .../webim/js/compiled/chat/layouts/chat.js | 2 +- .../js/compiled/chat/layouts/leave_message.js | 8 + .../webim/js/compiled/chat/layouts/survey.js | 8 + .../leave_message_description.js | 8 + .../leave_message/leave_message_form.js | 9 + .../leave_message_sent_description.js | 8 + .../model_views/survey/base_survey_form.js | 9 + .../chat/model_views/survey/survey_form.js | 9 + .../leave_message/leave_message_form.js | 10 + .../models/survey/base_survey_form.js} | 2 +- .../chat/models/survey/survey_form.js | 10 + .../webim/js/compiled/chat/modules/chat.js | 14 +- .../js/compiled/chat/modules/leave_message.js | 9 + .../webim/js/compiled/chat/modules/survey.js | 8 + src/messenger/webim/js/compiled/chat_app.js | 111 +++++++- src/messenger/webim/js/compiled/survey.js | 8 - src/messenger/webim/js/source/chat/app.js | 25 +- .../webim/js/source/chat/layouts/chat.js | 5 +- .../js/source/chat/layouts/leave_message.js | 49 ++++ .../webim/js/source/chat/layouts/survey.js | 48 ++++ .../leave_message_description.js | 40 +++ .../leave_message/leave_message_form.js | 108 ++++++++ .../leave_message_sent_description.js | 40 +++ .../model_views/survey/base_survey_form.js | 81 ++++++ .../chat/model_views/survey/survey_form.js | 76 ++++++ .../leave_message/leave_message_form.js | 143 ++++++++++ .../chat/models/survey/base_survey_form.js | 76 ++++++ .../source/chat/models/survey/survey_form.js | 137 ++++++++++ .../webim/js/source/chat/modules/chat.js | 31 ++- .../js/source/chat/modules/leave_message.js | 70 +++++ .../webim/js/source/chat/modules/survey.js | 49 ++++ src/messenger/webim/js/source/leavemessage.js | 11 - src/messenger/webim/js/source/survey.js | 25 -- src/messenger/webim/leavemessage.php | 145 ---------- src/messenger/webim/libs/chat.php | 227 ++++++++++++---- .../webim/libs/classes/thread_processor.php | 256 ++++++++++++++++++ src/messenger/webim/libs/groups.php | 24 ++ src/messenger/webim/operator/agent.php | 6 +- .../webim/styles/dialogs/default/chat.css | 8 + .../chat_layout.handlebars | 27 ++ .../leave_message_description.handlebars | 6 + .../leave_message_form.handlebars | 43 +++ .../leave_message_layout.handlebars | 35 +++ .../leave_message_sent_description.handlebars | 6 + .../survey_form.handlebars | 42 +++ .../survey_layout.handlebars | 39 +++ .../dialogs/default/js/compiled/templates.js | 74 +++-- .../styles/dialogs/default/templates/chat.tpl | 70 +++-- .../default/templates/leavemessage.tpl | 98 ------- .../default/templates/leavemessagesent.tpl | 45 --- .../dialogs/default/templates/survey.tpl | 96 ------- src/messenger/webim/thread.php | 4 + 54 files changed, 1967 insertions(+), 659 deletions(-) create mode 100644 src/messenger/webim/js/compiled/chat/layouts/leave_message.js create mode 100644 src/messenger/webim/js/compiled/chat/layouts/survey.js create mode 100644 src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_description.js create mode 100644 src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_form.js create mode 100644 src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_sent_description.js create mode 100644 src/messenger/webim/js/compiled/chat/model_views/survey/base_survey_form.js create mode 100644 src/messenger/webim/js/compiled/chat/model_views/survey/survey_form.js create mode 100644 src/messenger/webim/js/compiled/chat/models/leave_message/leave_message_form.js rename src/messenger/webim/js/compiled/{leavemessage.js => chat/models/survey/base_survey_form.js} (51%) create mode 100644 src/messenger/webim/js/compiled/chat/models/survey/survey_form.js create mode 100644 src/messenger/webim/js/compiled/chat/modules/leave_message.js create mode 100644 src/messenger/webim/js/compiled/chat/modules/survey.js delete mode 100644 src/messenger/webim/js/compiled/survey.js create mode 100644 src/messenger/webim/js/source/chat/layouts/leave_message.js create mode 100644 src/messenger/webim/js/source/chat/layouts/survey.js create mode 100644 src/messenger/webim/js/source/chat/model_views/leave_message/leave_message_description.js create mode 100644 src/messenger/webim/js/source/chat/model_views/leave_message/leave_message_form.js create mode 100644 src/messenger/webim/js/source/chat/model_views/leave_message/leave_message_sent_description.js create mode 100644 src/messenger/webim/js/source/chat/model_views/survey/base_survey_form.js create mode 100644 src/messenger/webim/js/source/chat/model_views/survey/survey_form.js create mode 100644 src/messenger/webim/js/source/chat/models/leave_message/leave_message_form.js create mode 100644 src/messenger/webim/js/source/chat/models/survey/base_survey_form.js create mode 100644 src/messenger/webim/js/source/chat/models/survey/survey_form.js create mode 100644 src/messenger/webim/js/source/chat/modules/leave_message.js create mode 100644 src/messenger/webim/js/source/chat/modules/survey.js delete mode 100644 src/messenger/webim/js/source/leavemessage.js delete mode 100644 src/messenger/webim/js/source/survey.js delete mode 100644 src/messenger/webim/leavemessage.php create mode 100644 src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_description.handlebars create mode 100644 src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_form.handlebars create mode 100644 src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_layout.handlebars create mode 100644 src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_sent_description.handlebars create mode 100644 src/messenger/webim/styles/dialogs/default/handlebars_templates/survey_form.handlebars create mode 100644 src/messenger/webim/styles/dialogs/default/handlebars_templates/survey_layout.handlebars delete mode 100644 src/messenger/webim/styles/dialogs/default/templates/leavemessage.tpl delete mode 100644 src/messenger/webim/styles/dialogs/default/templates/leavemessagesent.tpl delete mode 100644 src/messenger/webim/styles/dialogs/default/templates/survey.tpl diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index eede8ff2..1f24a69d 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -47,8 +47,6 @@ if (get_remote_level($_SERVER['HTTP_USER_AGENT']) == 'old') { exit; } -$page = array(); - if( !isset($_GET['token']) || !isset($_GET['thread']) ) { $thread = NULL; @@ -57,6 +55,8 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { } if( !$thread ) { + + // Load group info $groupid = ""; $groupname = ""; $group = NULL; @@ -72,102 +72,58 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { } } + // Get visitor info $visitor = visitor_from_request(); - - if(isset($_POST['survey']) && $_POST['survey'] == 'on') { - $firstmessage = getparam("message"); - $info = getparam("info"); - $email = getparam("email"); - $referrer = urldecode(getparam("referrer")); + $info = getgetparam('info'); + $email = getgetparam('email'); - if(Settings::get('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']; - } + // Get referrer + $referrer = isset($_GET['url']) + ? $_GET['url'] + : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""); + + if(isset($_GET['referrer']) && $_GET['referrer']) { + $referrer .= "\n".$_GET['referrer']; } + // Check if there are online operators if(!has_online_operators($groupid)) { - // Create page array + // Display leave message page $page = array_merge_recursive( setup_logo($group), - setup_leavemessage($visitor['name'],$email,$firstmessage,$groupid,$groupname,$info,$referrer) + setup_leavemessage( + $visitor['name'], + $email, + $groupid, + $info, + $referrer + ) ); - expand("styles/dialogs", getchatstyle(), "leavemessage.tpl"); + $page['leaveMessageOptions'] = json_encode($page['leaveMessage']); + expand("styles/dialogs", getchatstyle(), "chat.tpl"); exit; } + // Get invitation info $invitation_state = invitation_state($_SESSION['visitorid']); - $visitor_is_invited = Settings::get('enabletracking') && $invitation_state['invited'] && !$invitation_state['threadid']; - if(Settings::get('enablepresurvey') == '1' && !(isset($_POST['survey']) && $_POST['survey'] == 'on') && !$visitor_is_invited) { - // Create page array + $visitor_is_invited = Settings::get('enabletracking') + && $invitation_state['invited'] + && !$invitation_state['threadid']; + + // Check if survey should be displayed + if(Settings::get('enablepresurvey') == '1' && !$visitor_is_invited) { + // Display prechat survey $page = array_merge_recursive( setup_logo($group), setup_survey($visitor['name'], $email, $groupid, $info, $referrer) ); - expand("styles/dialogs", getchatstyle(), "survey.tpl"); + $page['surveyOptions'] = json_encode($page['survey']); + expand("styles/dialogs", getchatstyle(), "chat.tpl"); exit; } - $remoteHost = get_remote_host(); - $userbrowser = $_SERVER['HTTP_USER_AGENT']; - - if(Thread::connectionLimitReached($remoteHost)) { - die("number of connections from your IP is exceeded, try again later"); - } - $thread = Thread::create(); - $thread->groupId = $groupid; - $thread->userName = $visitor['name']; - $thread->remote = $remoteHost; - $thread->referer = $referrer; - $thread->locale = $current_locale; - $thread->userId = $visitor['id']; - $thread->userAgent = $userbrowser; - $thread->state = Thread::STATE_LOADING; - $thread->save(); - - $_SESSION['threadid'] = $thread->id; - - $operator = invitation_accept($_SESSION['visitorid'], $thread->id); - if ($operator) { - $operator = operator_by_id($operator); - $operatorName = ($current_locale == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname']; - $thread->postMessage( - Thread::KIND_FOR_AGENT, - getstring2('chat.visitor.invitation.accepted', array($operatorName)) - ); - } - - if( $referrer ) { - $thread->postMessage( - Thread::KIND_FOR_AGENT, - getstring2('chat.came.from',array($referrer)) - ); - } - $thread->postMessage(Thread::KIND_INFO, getstring('chat.wait')); - if($email) { - $thread->postMessage(Thread::KIND_FOR_AGENT, getstring2('chat.visitor.email',array($email))); - } - if($info) { - $thread->postMessage(Thread::KIND_FOR_AGENT, getstring2('chat.visitor.info',array($info))); - } - if($firstmessage) { - $postedid = $thread->postMessage(Thread::KIND_USER, $firstmessage, $visitor['name']); - $thread->shownMessageId = $postedid; - $thread->save(); - } + // Start chat thread + $thread = chat_start_for_user($groupid, $visitor['id'], $visitor['name'], $referrer, $info); } $threadid = $thread->id; $token = $thread->lastToken; @@ -184,21 +140,14 @@ if (! $thread) { die("wrong thread"); } -$page = array_merge_recursive( - $page, - setup_chatview_for_user($thread) -); +$page = setup_chatview_for_user($thread); $pparam = verifyparam( "act", "/^(mailthread)$/", "default"); if( $pparam == "mailthread" ) { expand("styles/dialogs", getchatstyle(), "mail.tpl"); } else { - // Load JavaScript plugins and JavaScripts, CSS files required by them - $page['additional_css'] = get_additional_css('client_chat_window'); - $page['additional_js'] = get_additional_js('client_chat_window'); - $page['js_plugin_options'] = get_js_plugin_options('client_chat_window'); // Build js application options - $page['chatModule'] = json_encode($page['chat']); + $page['chatOptions'] = json_encode($page['chat']); // Expand page expand("styles/dialogs", getchatstyle(), "chat.tpl"); } diff --git a/src/messenger/webim/js/compiled/chat/app.js b/src/messenger/webim/js/compiled/chat/app.js index 74e93fa6..6b902ca4 100644 --- a/src/messenger/webim/js/compiled/chat/app.js +++ b/src/messenger/webim/js/compiled/chat/app.js @@ -5,4 +5,5 @@ Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ -(function(a,d){var b=a.Application;b.addRegions({mainRegion:"#main-region"});b.addInitializer(function(c){a.Objects.server=new a.Server(d.extend({interactionType:MibewAPIChatInteraction},c.server));b.Chat.start(c)});b.on("start",function(){a.Objects.server.runUpdater()})})(Mibew,_); +(function(a,d){var b=a.Application;b.addRegions({mainRegion:"#main-region"});b.addInitializer(function(c){a.Objects.server=new a.Server(d.extend({interactionType:MibewAPIChatInteraction},c.server));a.Objects.Models.page=new a.Models.Page(c.page);switch(c.startFrom){case "chat":b.Chat.start(c.chatOptions);break;case "survey":b.Survey.start(c.surveyOptions);break;case "leaveMessage":b.LeaveMessage.start(c.leaveMessageOptions);break;default:throw Error("Dont know how to start!");}});b.on("start",function(){a.Objects.server.runUpdater()})})(Mibew, +_); diff --git a/src/messenger/webim/js/compiled/chat/layouts/chat.js b/src/messenger/webim/js/compiled/chat/layouts/chat.js index 7d5dfe48..4800a61a 100644 --- a/src/messenger/webim/js/compiled/chat/layouts/chat.js +++ b/src/messenger/webim/js/compiled/chat/layouts/chat.js @@ -5,4 +5,4 @@ Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ -(function(a,b){a.Layouts.Chat=b.Marionette.Layout.extend({template:Handlebars.templates.chat_layout,regions:{controlsRegion:"#controls-region",avatarRegion:"#avatar-region",messagesRegion:{selector:"#messages-region",regionType:a.Regions.Messages},statusRegion:"#status-region",messageFormRegion:"#message-form-region",soundRegion:"#sound-region"},serializeData:function(){return{user:a.Objects.Models.user.toJSON()}}})})(Mibew,Backbone); +(function(a,c){a.Layouts.Chat=c.Marionette.Layout.extend({template:Handlebars.templates.chat_layout,regions:{controlsRegion:"#controls-region",avatarRegion:"#avatar-region",messagesRegion:{selector:"#messages-region",regionType:a.Regions.Messages},statusRegion:"#status-region",messageFormRegion:"#message-form-region",soundRegion:"#sound-region"},serializeData:function(){var b=a.Objects.Models;return{page:b.page.toJSON(),user:b.user.toJSON()}}})})(Mibew,Backbone); diff --git a/src/messenger/webim/js/compiled/chat/layouts/leave_message.js b/src/messenger/webim/js/compiled/chat/layouts/leave_message.js new file mode 100644 index 00000000..61511ef2 --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/layouts/leave_message.js @@ -0,0 +1,8 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +(function(a,b){a.Layouts.LeaveMessage=b.Marionette.Layout.extend({template:Handlebars.templates.leave_message_layout,regions:{leaveMessageFormRegion:"#content-wrapper",descriptionRegion:"#description-region"},serializeData:function(){return{page:a.Objects.Models.page.toJSON()}}})})(Mibew,Backbone); diff --git a/src/messenger/webim/js/compiled/chat/layouts/survey.js b/src/messenger/webim/js/compiled/chat/layouts/survey.js new file mode 100644 index 00000000..b2aefec9 --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/layouts/survey.js @@ -0,0 +1,8 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +(function(a,b){a.Layouts.Survey=b.Marionette.Layout.extend({template:Handlebars.templates.survey_layout,regions:{surveyFormRegion:"#content-wrapper"},serializeData:function(){return{page:a.Objects.Models.page.toJSON()}}})})(Mibew,Backbone); diff --git a/src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_description.js b/src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_description.js new file mode 100644 index 00000000..ff4b3292 --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_description.js @@ -0,0 +1,8 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +(function(a,b,c){a.Views.LeaveMessageDescription=b.Marionette.ItemView.extend({template:c.templates.leave_message_description,serializeData:function(){return{page:a.Objects.Models.page.toJSON()}}})})(Mibew,Backbone,Handlebars); diff --git a/src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_form.js b/src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_form.js new file mode 100644 index 00000000..e8e5551d --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_form.js @@ -0,0 +1,9 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +(function(d,e,b){var c=d.Views.BaseSurveyForm;d.Views.LeaveMessageForm=c.extend({template:e.templates.leave_message_form,events:b.extend({},c.prototype.events,{"click #send-message":"submitForm"}),ui:b.extend({},c.prototype.ui,{captcha:'input[name="captcha"]',captchaImg:"#captcha-img"}),modelEvents:b.extend({},c.prototype.modelEvents,{"submit:error":"showError submitError"}),submitForm:function(){var a={};this.model.get("groups")&&(a.groupId=this.ui.groupSelect.val());a.name=this.ui.name.val()||""; +a.email=this.ui.email.val()||"";a.message=this.ui.message.val()||"";this.model.get("showCaptcha")&&(a.captcha=this.ui.captcha.val()||"");this.model.set(a,{validate:!0});this.model.submit()},submitError:function(a,c){if(c.code==a.ERROR_WRONG_CAPTCHA&&a.get("showCaptcha")){var b=this.ui.captchaImg.attr("src"),b=b.replace(/\?d\=[0-9]+/,"");this.ui.captchaImg.attr("src",b+"?d="+(new Date).getTime())}}})})(Mibew,Handlebars,_); diff --git a/src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_sent_description.js b/src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_sent_description.js new file mode 100644 index 00000000..ccd290f4 --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/model_views/leave_message/leave_message_sent_description.js @@ -0,0 +1,8 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +(function(a,b,c){a.Views.LeaveMessageSentDescription=b.Marionette.ItemView.extend({template:c.templates.leave_message_sent_description,serializeData:function(){return{page:a.Objects.Models.page.toJSON()}}})})(Mibew,Backbone,Handlebars); diff --git a/src/messenger/webim/js/compiled/chat/model_views/survey/base_survey_form.js b/src/messenger/webim/js/compiled/chat/model_views/survey/base_survey_form.js new file mode 100644 index 00000000..c599866d --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/model_views/survey/base_survey_form.js @@ -0,0 +1,9 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +(function(c,d){c.Views.BaseSurveyForm=d.Marionette.ItemView.extend({events:{'change select[name="group"]':"changeGroupDescription","submit form":"preventSubmit"},ui:{groupSelect:'select[name="group"]',groupDescription:"#groupDescription",name:'input[name="name"]',email:'input[name="email"]',message:'textarea[name="message"]',errors:".errors"},modelEvents:{invalid:"showError","submit:error":"showError"},preventSubmit:function(b){b.preventDefault()},changeGroupDescription:function(){var b=this.ui.groupSelect.prop("selectedIndex"), +a=this.model.get("groups").descriptions||[];this.ui.groupDescription.text(a[b]||"")},showError:function(b,a){this.ui.errors.html("string"==typeof a?a:a.message)}})})(Mibew,Backbone); diff --git a/src/messenger/webim/js/compiled/chat/model_views/survey/survey_form.js b/src/messenger/webim/js/compiled/chat/model_views/survey/survey_form.js new file mode 100644 index 00000000..149c93ef --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/model_views/survey/survey_form.js @@ -0,0 +1,9 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +(function(b,d,e){var c=b.Views.BaseSurveyForm;b.Views.SurveyForm=c.extend({template:d.templates.survey_form,events:e.extend({},c.prototype.events,{"click #submit-survey":"submitForm"}),submitForm:function(){var a={};this.model.get("groups")&&(a.groupId=this.ui.groupSelect.val());this.model.get("canChangeName")&&(a.name=this.ui.name.val()||"");this.model.get("showEmail")&&(a.email=this.ui.email.val()||"");this.model.get("showMessage")&&(a.message=this.ui.message.val()||"");this.model.set(a,{validate:!0}); +this.model.submit()}})})(Mibew,Handlebars,_); diff --git a/src/messenger/webim/js/compiled/chat/models/leave_message/leave_message_form.js b/src/messenger/webim/js/compiled/chat/models/leave_message/leave_message_form.js new file mode 100644 index 00000000..b680c5f4 --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/models/leave_message/leave_message_form.js @@ -0,0 +1,10 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +(function(c,e){var d=c.Models.BaseSurveyForm;c.Models.LeaveMessageForm=d.extend({defaults:e.extend({},d.prototype.defaults,{showCaptcha:!1,captcha:""}),validate:function(a){var b=c.Localization;if("undefined"!=typeof a.email){if(!a.email)return b.get("leavemessage.error.email.required");if(!c.Utils.checkEmail(a.email))return b.get("leavemessage.error.wrong.email")}if("undefined"!=typeof a.name&&!a.name)return b.get("leavemessage.error.name.required");if("undefined"!=typeof a.message&&!a.message)return b.get("leavemessage.error.message.required"); +if(this.get("showCaptcha")&&"undefined"!=typeof a.captcha&&!a.captcha)return b.get("errors.captcha")},submit:function(){if(!this.validate(this.attributes)){var a=this;c.Objects.server.callFunctions([{"function":"processLeaveMessage",arguments:{references:{},"return":{},groupId:a.get("groupId"),name:a.get("name"),info:a.get("info"),email:a.get("email"),message:a.get("message"),referrer:a.get("referrer"),captcha:a.get("captcha"),threadId:null,token:null}}],function(b){0==b.errorCode?a.trigger("submit:complete", +a):a.trigger("submit:error",a,{code:b.errorCode,message:b.errorMessage||""})},!0)}},ERROR_WRONG_CAPTCHA:10})})(Mibew,_); diff --git a/src/messenger/webim/js/compiled/leavemessage.js b/src/messenger/webim/js/compiled/chat/models/survey/base_survey_form.js similarity index 51% rename from src/messenger/webim/js/compiled/leavemessage.js rename to src/messenger/webim/js/compiled/chat/models/survey/base_survey_form.js index 17d21f05..abedb816 100644 --- a/src/messenger/webim/js/compiled/leavemessage.js +++ b/src/messenger/webim/js/compiled/chat/models/survey/base_survey_form.js @@ -5,4 +5,4 @@ Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ -EventHelper.register(window,"onload",function(){MessageForm=new ClientForm(document.leaveMessageForm)}); \ No newline at end of file +(function(a){a.Models.BaseSurveyForm=a.Models.Base.extend({defaults:{name:"",email:"",message:"",info:"",referrer:"",groupId:null,groups:null}})})(Mibew); diff --git a/src/messenger/webim/js/compiled/chat/models/survey/survey_form.js b/src/messenger/webim/js/compiled/chat/models/survey/survey_form.js new file mode 100644 index 00000000..f6582268 --- /dev/null +++ b/src/messenger/webim/js/compiled/chat/models/survey/survey_form.js @@ -0,0 +1,10 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +(function(b,e){var d=b.Models.BaseSurveyForm;b.Models.SurveyForm=d.extend({defaults:e.extend({},d.prototype.defaults,{showEmail:!1,showMessage:!1,canChangeName:!1}),validate:function(a){if(this.get("showEmail")&&"undefined"!=typeof a.email&&!b.Utils.checkEmail(a.email))return b.Localization.get("presurvey.error.wrong_email")},submit:function(){if(!this.validate(this.attributes)){var a=this;b.Objects.server.callFunctions([{"function":"processSurvey",arguments:{references:{},"return":{next:"next",options:"options"}, +groupId:a.get("groupId"),name:a.get("name"),info:a.get("info"),email:a.get("email"),message:a.get("message"),referrer:a.get("referrer"),threadId:null,token:null}}],function(c){if(0==c.errorCode)switch(a.trigger("submit:complete",a),b.Application.Survey.stop(),c.next){case "chat":b.Application.Chat.start(c.options);break;case "leaveMessage":b.Application.LeaveMessage.start(c.options);break;default:throw Error("Do not know how to continue!");}else a.trigger("submit:error",a,{code:c.errorCode,message:c.errorMessage|| +""})},!0)}}})})(Mibew,_); diff --git a/src/messenger/webim/js/compiled/chat/modules/chat.js b/src/messenger/webim/js/compiled/chat/modules/chat.js index 44077be7..d7f4c389 100644 --- a/src/messenger/webim/js/compiled/chat/modules/chat.js +++ b/src/messenger/webim/js/compiled/chat/modules/chat.js @@ -5,10 +5,10 @@ Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ -(function(a){a.Objects.Models.Controls={};a.Objects.Models.Status={};var j=[],k=a.Application,l=k.module("Chat",{startWithParent:!1});l.addInitializer(function(c){var e=c.chatModule,g=a.Objects,d=a.Objects.Models,b=a.Objects.Models.Controls,h=a.Objects.Models.Status;d.thread=new a.Models.Thread(e.thread);d.user=new a.Models.ChatUser(e.user);d.page=new a.Models.Page(c.page);c=new a.Layouts.Chat;a.Objects.chatLayout=c;k.mainRegion.show(c);var f=new a.Collections.Controls;d.user.get("isAgent")||(b.userName= -new a.Models.UserNameControl({weight:220}),f.add(b.userName),b.sendMail=new a.Models.SendMailControl({weight:200,link:e.links.mail,windowParams:e.windowsParams.mail}),f.add(b.sendMail));d.user.get("isAgent")&&(b.redirect=new a.Models.RedirectControl({weight:200,link:e.links.redirect}),f.add(b.redirect),b.history=new a.Models.HistoryControl({weight:180,link:e.links.history,windowParams:e.windowsParams.history}),f.add(b.history));b.sound=new a.Models.SoundControl({weight:160});f.add(b.sound);b.refresh= -new a.Models.RefreshControl({weight:140});f.add(b.refresh);e.links.ssl&&(b.secureMode=new a.Models.SecureModeControl({weight:120,link:e.links.ssl}),f.add(b.secureMode));b.close=new a.Models.CloseControl({weight:100});f.add(b.close);g.Collections.controls=f;c.controlsRegion.show(new a.Views.ControlsCollection({collection:f}));h.message=new a.Models.StatusMessage({hideTimeout:5E3});h.typing=new a.Models.StatusTyping({hideTimeout:5E3});g.Collections.status=new a.Collections.Status([h.message,h.typing]); -c.statusRegion.show(new a.Views.StatusCollection({collection:g.Collections.status}));d.user.get("isAgent")||(d.avatar=new a.Models.Avatar,c.avatarRegion.show(new a.Views.Avatar({model:d.avatar})));g.Collections.messages=new a.Collections.Messages;d.messageForm=new a.Models.MessageForm(e.messageForm);c.messageFormRegion.show(new a.Views.MessageForm({model:d.messageForm}));c.messagesRegion.show(new a.Views.MessagesCollection({collection:g.Collections.messages}));d.sound=new a.Models.Sound;c.soundRegion.show(new a.Views.Sound({model:d.sound})); -j.push(g.server.callFunctionsPeriodically(function(){var b=a.Objects.Models.thread,c=a.Objects.Models.user;return[{"function":"update",arguments:{"return":{typing:"typing",canPost:"canPost"},references:{},threadId:b.get("id"),token:b.get("token"),lastId:b.get("lastId"),typed:c.get("typing"),user:!c.get("isAgent")}}]},function(b){b.errorCode?a.Objects.Models.Status.message.setMessage(b.errorMessage||"refresh failed"):(b.typing&&a.Objects.Models.Status.typing.show(),a.Objects.Models.user.set({canPost:b.canPost|| -!1}))}))});l.addFinalizer(function(){a.Objects.chatLayout.close();for(var c=0;cgroupId = $groupid; - $thread->userName = $name; - $thread->remote = $remoteHost; - $thread->referer = $referrer; - $thread->locale = $current_locale; - $thread->userId = $visitor['id']; - $thread->userAgent = $userbrowser; - $thread->state = Thread::STATE_LEFT; - $thread->save(); - - if( $referrer ) { - $thread->postMessage(Thread::KIND_FOR_AGENT,getstring2('chat.came.from',array($referrer))); - } - if($email) { - $thread->postMessage(Thread::KIND_FOR_AGENT, getstring2('chat.visitor.email',array($email))); - } - if($info) { - $thread->postMessage(Thread::KIND_FOR_AGENT, getstring2('chat.visitor.info',array($info))); - } - $thread->postMessage(Thread::KIND_USER, $message, $name); -} - -$groupid = ""; -$groupname = ""; -$group = NULL; -if(Settings::get('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"); -} else if( !$visitor_name ) { - $errors[] = no_field("form.field.name"); -} else if( !$message ) { - $errors[] = no_field("form.field.message"); -} else { - if( !is_valid_email($email)) { - $errors[] = wrong_field("form.field.email"); - } -} - -if(Settings::get("enablecaptcha") == "1" && can_show_captcha()) { - $captcha = getparam('captcha'); - $original = isset($_SESSION["mibew_captcha"]) ? $_SESSION["mibew_captcha"] : ""; - if(empty($original) || empty($captcha) || $captcha != $original) { - $errors[] = getlocal('errors.captcha'); - } - unset($_SESSION['mibew_captcha']); -} - -if( count($errors) > 0 ) { - $page = array_merge_recursive( - $page, - setup_logo($group), - setup_leavemessage($visitor_name,$email,$message,$groupid,$groupname,$info,$referrer) - ); - expand("styles/dialogs", getchatstyle(), "leavemessage.tpl"); - exit; -} - -$message_locale = Settings::get('left_messages_locale'); -if(!locale_exists($message_locale)) { - $message_locale = $home_locale; -} - -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); - -if (isset($group) && !empty($group['vcemail'])) { - $inbox_mail = $group['vcemail']; -} else { - if (! is_null($group['parent'])) { - $parentgroup = group_by_id($group['parent']); - if ($parentgroup && !empty($parentgroup['vcemail'])) { - $inbox_mail = $parentgroup['vcemail']; - } - } -} - -if (empty($inbox_mail)) { - $inbox_mail = Settings::get('email'); -} - -if($inbox_mail) { - webim_mail($inbox_mail, $email, $subject, $body); -} - -$page = array_merge_recursive( - $page, - setup_logo($group) -); -expand("styles/dialogs", getchatstyle(), "leavemessagesent.tpl"); -?> \ No newline at end of file diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index d3ed177b..7228ab7b 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -156,42 +156,93 @@ function setup_logo($group = NULL) { return $data; } +/** + * Prepare values common for chat, prechat survey form and leave message form. + * @return array + */ +function prepare_chat_app_data() { + $data = array(); + + // Set enter key shortcut + if (Settings::get('sendmessagekey') == 'enter') { + $data['send_shortcut'] = "Enter"; + } else { + $data['send_shortcut'] = is_mac_opera() + ? "⌘-Enter" + : "Ctrl-Enter"; + } + + // Set refresh frequency + $data['frequency'] = Settings::get('updatefrequency_chat'); + + // Load JavaScript plugins and JavaScripts, CSS files required by them + $data['additional_css'] = get_additional_css('client_chat_window'); + $data['additional_js'] = get_additional_js('client_chat_window'); + $data['js_plugin_options'] = get_js_plugin_options('client_chat_window'); + + // Set some localized strings + $data['localized'] = array( + 'email.required' => no_field("form.field.email"), + 'name.required' => no_field("form.field.name"), + 'message.required' => no_field("form.field.message"), + 'wrong.email' => wrong_field("form.field.email") + ); + + return $data; +} + /** * Prepare data to display leave message form * * @param string $name User name * @param string $email User email - * @param string $message First message text - * @param int $groupid Id of selected group - * @param string $groupname Name of selected group + * @param int $group_id Id of selected group * @param string $info User info * @param string $referrer URL of referrer page * @return array Array of leave message form data - * - * @todo Think about $info param. It seems to this param is meaningless. */ -function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info, $referrer) { - $data = array(); +function setup_leavemessage($name, $email, $group_id, $info, $referrer) { + $data = prepare_chat_app_data(); - $canshowcaptcha = can_show_captcha(); - $data['formname'] = topage($name); - $data['formemail'] = topage($email); - $data['formmessage'] = $message ? topage($message) : ""; - $data['showcaptcha'] = Settings::get("enablecaptcha") == "1" && $canshowcaptcha ? "1" : ""; - $data['formgroupid'] = $groupid; - $data['formgroupname'] = $groupname; - $data['forminfo'] = topage($info); - $data['referrer'] = urlencode(topage($referrer)); + // Create some empty arrays + $data['leaveMessage'] = array(); + + $group = group_by_id($group_id); + $group_name = ''; + if ($group) { + $group_name = get_group_name($group); + } + + $data['leaveMessage']['leaveMessageForm'] = array( + 'name' => topage($name), + 'email' => topage($email), + 'groupId' => $group_id, + 'groupName' => $group_name, + 'info' => topage($info), + 'referrer' => topage($referrer), + 'showCaptcha' => (bool)(Settings::get("enablecaptcha") == "1" + && can_show_captcha()) + ); + + $data['page.title'] = (empty($group_name)?'':$group_name.': ') + . getlocal('leavemessage.title'); + $data['leaveMessage']['page'] = array( + 'title' => $data['page.title'] + ); if (Settings::get('enablegroups') == '1') { - $groups = setup_groups_select($groupid, false); + $groups = setup_groups_select($group_id, false); if ($groups) { - $data['groups'] = $groups['select']; - $data['group.descriptions'] = json_encode($groups['descriptions']); - $data['default.department.description'] = $groups['defaultdescription']; + $data['leaveMessage']['leaveMessageForm']['groups'] = array( + 'select' => $groups['select'], + 'descriptions' => $groups['descriptions'], + 'defaultDescription' => $groups['defaultdescription'] + ); } } + $data['startFrom'] = 'leaveMessage'; + return $data; } @@ -200,34 +251,47 @@ function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info * * @param string $name User name * @param string $email User email - * @param int $groupid Id of selected group + * @param int $group_id Id of selected group * @param string $info User info * @param string $referrer URL of referrer page * @return array Array of survey data - * - * @todo Think about $info param. It seems to this param is meaningless. */ -function setup_survey($name, $email, $groupid, $info, $referrer) { - $data = array(); +function setup_survey($name, $email, $group_id, $info, $referrer) { + $data = prepare_chat_app_data(); - $data['formname'] = topage($name); - $data['formemail'] = topage($email); - $data['formgroupid'] = $groupid; - $data['forminfo'] = topage($info); - $data['referrer'] = urlencode(topage($referrer)); + // Create some empty arrays + $data['survey'] = array(); - if (Settings::get('enablegroups') == '1' && Settings::get('surveyaskgroup') == '1') { - $groups = setup_groups_select($groupid, true); + $data['survey']['surveyForm'] = array( + 'name' => topage($name), + 'groupId' => $group_id, + 'email' => topage($email), + 'info' => topage($info), + 'referrer' => topage($referrer), + 'showEmail' => (bool)(Settings::get("surveyaskmail") == "1"), + 'showMessage' => (bool)(Settings::get("surveyaskmessage") == "1"), + 'canChangeName' => (bool)(Settings::get('usercanchangename') == "1") + ); + + $data['page.title'] = getlocal('presurvey.title'); + $data['survey']['page'] = array( + 'title' => $data['page.title'] + ); + + if (Settings::get('enablegroups') == '1' + && Settings::get('surveyaskgroup') == '1') { + + $groups = setup_groups_select($group_id, true); if ($groups) { - $data['groups'] = $groups['select']; - $data['group.descriptions'] = json_encode($groups['descriptions']); - $data['default.department.description'] = $groups['defaultdescription']; + $data['survey']['surveyForm']['groups'] = array( + 'select' => $groups['select'], + 'descriptions' => $groups['descriptions'], + 'defaultDescription' => $groups['defaultdescription'], + ); } } - $data['showemail'] = Settings::get("surveyaskmail") == "1" ? "1" : ""; - $data['showmessage'] = Settings::get("surveyaskmessage") == "1" ? "1" : ""; - $data['showname'] = Settings::get('usercanchangename') == "1" ? "1" : ""; + $data['startFrom'] = 'survey'; return $data; } @@ -283,7 +347,7 @@ function setup_groups_select($groupid, $markoffline) * @return array Array of chat view data */ function setup_chatview(Thread $thread) { - $data = array(); + $data = prepare_chat_app_data(); // Get group info if (! empty($thread->groupId)) { @@ -306,11 +370,14 @@ function setup_chatview(Thread $thread) { 'token' => $thread->lastToken ); - $data['chat.title'] = topage( + $data['page.title'] = topage( empty($group['vcchattitle']) ? Settings::get('chattitle') : $group['vcchattitle'] ); + $data['chat']['page'] = array( + 'title' => $data['page.title'] + ); // Setup logo $data = array_merge_recursive( @@ -320,12 +387,8 @@ function setup_chatview(Thread $thread) { // Set enter key shortcut if (Settings::get('sendmessagekey') == 'enter') { - $data['send_shortcut'] = "Enter"; $data['chat']['messageForm']['ignoreCtrl'] = true; } else { - $data['send_shortcut'] = is_mac_opera() - ? "⌘-Enter" - : "Ctrl-Enter"; $data['chat']['messageForm']['ignoreCtrl'] = false; } @@ -333,9 +396,6 @@ function setup_chatview(Thread $thread) { $data['isOpera95'] = is_agent_opera95(); $data['neediframesrc'] = needsFramesrc(); - // Set refresh frequency - $data['frequency'] = Settings::get('updatefrequency_chat'); - // Load dialogs style options $style_config = get_dialogs_style_config(getchatstyle()); $data['chat']['windowsParams']['mail'] @@ -346,6 +406,8 @@ function setup_chatview(Thread $thread) { $data['chat']['windowsParams']['history'] = $style_config['history']['window_params']; + $data['startFrom'] = 'chat'; + return $data; } @@ -531,4 +593,75 @@ function get_remote_host() return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr; } +/** + * Start chat thread for user + * + * @global string $current_locale Current locale code + * @param int $group_id Id of group related to thread + * @param string $visitor_id Id of the visitor + * @param string $visitor_name Name of the visitor + * @param string $referrer Page user came from + * @param string $info User info + */ +function chat_start_for_user($group_id, $visitor_id, $visitor_name, $referrer, $info) { + global $current_locale; + + // Get user info + $remote_host = get_remote_host(); + $user_browser = $_SERVER['HTTP_USER_AGENT']; + + // Check connection limit + if(Thread::connectionLimitReached($remote_host)) { + die("number of connections from your IP is exceeded, try again later"); + } + + // Create thread + $thread = Thread::create(); + $thread->groupId = $group_id; + $thread->userName = $visitor_name; + $thread->remote = $remote_host; + $thread->referer = $referrer; + $thread->locale = $current_locale; + $thread->userId = $visitor_id; + $thread->userAgent = $user_browser; + $thread->state = Thread::STATE_LOADING; + $thread->save(); + + $_SESSION['threadid'] = $thread->id; + + // Check if invitation accept + $operator = invitation_accept($_SESSION['visitorid'], $thread->id); + if ($operator) { + $operator = operator_by_id($operator); + $operator_name = get_operator_name($operator); + $thread->postMessage( + Thread::KIND_FOR_AGENT, + getstring2( + 'chat.visitor.invitation.accepted', + array($operator_name) + ) + ); + } + + // Send some messages + if ($referrer) { + $thread->postMessage( + Thread::KIND_FOR_AGENT, + getstring2('chat.came.from',array($referrer)) + ); + } + + $thread->postMessage(Thread::KIND_INFO, getstring('chat.wait')); + + // TODO: May be move sending this message somewhere else? + if ($info) { + $thread->postMessage( + Thread::KIND_FOR_AGENT, + getstring2('chat.visitor.info',array($info)) + ); + } + + return $thread; +} + ?> \ No newline at end of file diff --git a/src/messenger/webim/libs/classes/thread_processor.php b/src/messenger/webim/libs/classes/thread_processor.php index 72211c36..a97d85ff 100644 --- a/src/messenger/webim/libs/classes/thread_processor.php +++ b/src/messenger/webim/libs/classes/thread_processor.php @@ -403,6 +403,254 @@ class ThreadProcessor extends ClientSideProcessor { 'closed' => true ); } + + /** + * Process submitted prechat survey. + * + * @global string $namecookie Name of cookie that store visitor name + * @param array $args Associative array of arguments. It must contains + * following keys: + * - 'threadId': for this function this param equals to null; + * - 'token': for this function this param equals to null; + * - 'name': string, user name; + * - 'email': string, user email; + * - 'message': string, first user message; + * - 'info': string, some info about user; + * - 'referrer': page user came from; + * - 'groupId': selected group id. + * @return array Array of results. It contains following keys: + * - 'next': string, indicates what module run next; + * - 'options': options array for next module. + */ + protected function apiProcessSurvey($args) { + global $namecookie; + + $visitor = visitor_from_request(); + + // Get form values + $first_message = $args['message']; + $info = $args['info']; + $email = $args['email']; + $referrer = $args['referrer']; + + // Verify group id + $group_id = ''; + $group = NULL; + if(Settings::get('enablegroups') == '1') { + if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) { + $group = group_by_id($args['groupId']); + if ($group) { + $group_id = $args['groupId']; + } + } + } + + if(Settings::get('usercanchangename') == "1" && !empty($args['name'])) { + $newname = $args['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; + } + } + + // Check if there are online operators + if(!has_online_operators($group_id)) { + // Display leave message page + $client_data = setup_leavemessage( + $visitor['name'], + $email, + $group_id, + $info, + $referrer + ); + $options = $client_data['leaveMessage']; + $options['page'] += setup_logo($group); + return array( + 'next' => 'leaveMessage', + 'options' => $options + ); + } + + // Initialize dialog + $thread = chat_start_for_user( + $group_id, + $visitor['id'], + $visitor['name'], + $referrer, + $info + ); + + // Send some messages + if($email) { + $thread->postMessage( + Thread::KIND_FOR_AGENT, + getstring2('chat.visitor.email',array($email)) + ); + } + + if($first_message) { + $posted_id = $thread->postMessage( + Thread::KIND_USER, + $first_message, + $visitor['name'] + ); + $thread->shownMessageId = $posted_id; + $thread->save(); + } + + // Prepare chat options + $client_data = setup_chatview_for_user($thread); + $options = $client_data['chat']; + $options['page'] += setup_logo($group); + + return array( + 'next' => 'chat', + 'options' => $options + ); + } + + /** + * Process submitted leave message form. + * + * Send message to operator email and create special meil thread. + * @global string $home_locale Code of the home locale + * @global string $current_locale Code of the current locale + * @param array $args Associative array of arguments. It must contains + * following keys: + * - 'threadId': for this function this param equals to null; + * - 'token': for this function this param equals to null; + * - 'name': string, user name; + * - 'email': string, user email; + * - 'message': string, user message; + * - 'info': string, some info about user; + * - 'referrer': string, page user came from; + * - 'captcha': string, captcha value; + * - 'groupId': selected group id. + * + * @throws ThreadProcessorException Can throw an exception if captcha or + * email is wrong. + */ + protected function apiProcessLeaveMessage($args) { + global $home_locale, $current_locale; + + // Check captcha + if(Settings::get('enablecaptcha') == '1' && can_show_captcha()) { + $captcha = $args['captcha']; + $original = isset($_SESSION["mibew_captcha"]) + ? $_SESSION["mibew_captcha"] + : ''; + unset($_SESSION['mibew_captcha']); + if(empty($original) || empty($captcha) || $captcha != $original) { + throw new ThreadProcessorException( + getlocal('errors.captcha'), + ThreadProcessorException::ERROR_WRONG_CAPTCHA + ); + } + } + + // Get form fields + $email = $args['email']; + $name = $args['name']; + $message = $args['message']; + $info = $args['info']; + $referrer = $args['referrer']; + + if( !is_valid_email($email)) { + throw new ThreadProcessorException( + wrong_field("form.field.email"), + ThreadProcessorException::ERROR_WRONG_EMAIL + ); + } + + // Verify group id + $group_id = ''; + if(Settings::get('enablegroups') == '1') { + if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) { + $group = group_by_id($args['groupId']); + if ($group) { + $group_id = $args['groupId']; + } + } + } + + // Create thread for left message + $remote_host = get_remote_host(); + $user_browser = $_SERVER['HTTP_USER_AGENT']; + $visitor = visitor_from_request(); + + // Get message locale + $message_locale = Settings::get('left_messages_locale'); + if(!locale_exists($message_locale)) { + $message_locale = $home_locale; + } + + // Create thread + $thread = Thread::create(); + $thread->groupId = $groupid; + $thread->userName = $name; + $thread->remote = $remote_host; + $thread->referer = $referrer; + $thread->locale = $current_locale; + $thread->userId = $visitor['id']; + $thread->userAgent = $user_browser; + $thread->state = Thread::STATE_LEFT; + $thread->save(); + + // Send some messages + if ($referrer) { + $thread->postMessage( + Thread::KIND_FOR_AGENT, + getstring2('chat.came.from', array($referrer)) + ); + } + if($email) { + $thread->postMessage( + Thread::KIND_FOR_AGENT, + getstring2('chat.visitor.email', array($email)) + ); + } + if($info) { + $thread->postMessage( + Thread::KIND_FOR_AGENT, + getstring2('chat.visitor.info', array($info)) + ); + } + $thread->postMessage(Thread::KIND_USER, $message, $name); + + // Get email for message + $inbox_mail = get_group_email($group_id); + + if (empty($inbox_mail)) { + $inbox_mail = Settings::get('email'); + } + + // Send email + if($inbox_mail) { + // Prepare message to send by email + $subject = getstring2_("leavemail.subject", + array($args['name']), + $message_locale + ); + $body = getstring2_( + "leavemail.body", + array( + $args['name'], + $email, + $message, + $info ? $info."\n" : "" + ), + $message_locale + ); + + // Send + webim_mail($inbox_mail, $email, $subject, $body); + } + } } class ThreadProcessorException extends RequestProcessorException { @@ -442,6 +690,14 @@ class ThreadProcessorException extends RequestProcessorException { * Wrong recipient value */ const WRONG_RECIPIENT_VALUE = 9; + /** + * Wrong captcha value + */ + const ERROR_WRONG_CAPTCHA = 10; + /** + * Wrong email address + */ + const ERROR_WRONG_EMAIL = 11; } ?> \ No newline at end of file diff --git a/src/messenger/webim/libs/groups.php b/src/messenger/webim/libs/groups.php index 223928ec..4e5d47fc 100644 --- a/src/messenger/webim/libs/groups.php +++ b/src/messenger/webim/libs/groups.php @@ -104,4 +104,28 @@ function get_top_level_group($group) return is_null($group['parent'])?$group:group_by_id($group['parent']); } +/** + * Try to load email for specified group or for its parent. + * @param int $group_id Group id + * @return string|boolean Email address or false if there is no email + */ +function get_group_email($group_id) { + // Try to get group email + $group = group_by_id($group_id); + if ($group && !empty($group['vcemail'])) { + return $group['vcemail']; + } + + // Try to get parent group email + if (! is_null($group['parent'])) { + $group = group_by_id($group['parent']); + if ($group && !empty($group['vcemail'])) { + return $group['vcemail']; + } + } + + // There is no email + return false; +} + ?> \ No newline at end of file diff --git a/src/messenger/webim/operator/agent.php b/src/messenger/webim/operator/agent.php index 7a14ba06..20cabe6d 100644 --- a/src/messenger/webim/operator/agent.php +++ b/src/messenger/webim/operator/agent.php @@ -128,12 +128,8 @@ if ($pparam == "redirect") { setup_redirect_links($threadid, $operator, $token); expand("../styles/dialogs", getchatstyle(), "redirect.tpl"); } else { - // Load JavaScript plugins and JavaScripts, CSS files required by them - $page['additional_css'] = get_additional_css('agent_chat_window'); - $page['additional_js'] = get_additional_js('agent_chat_window'); - $page['js_plugin_options'] = get_js_plugin_options('agent_chat_window'); // Build js application options - $page['chatModule'] = json_encode($page['chat']); + $page['chatOptions'] = json_encode($page['chat']); // Expand page expand("../styles/dialogs", getchatstyle(), "chat.tpl"); } diff --git a/src/messenger/webim/styles/dialogs/default/chat.css b/src/messenger/webim/styles/dialogs/default/chat.css index fbbf0118..124e403a 100644 --- a/src/messenger/webim/styles/dialogs/default/chat.css +++ b/src/messenger/webim/styles/dialogs/default/chat.css @@ -110,6 +110,12 @@ img { height: 16px; background: transparent url("images/buttons.gif") scroll no-repeat 0 0; } +.iclosewin { + background-position: -128px -16px; +} +a:hover .iclosewin { + background-position: -128px 0; +} .close-control .tpl-image { background-position: -128px -16px; } @@ -377,6 +383,8 @@ img { } .wndbr .buttons { top: 14px; + position: absolute; + right: 25px; } #headers { padding: 0 10px; diff --git a/src/messenger/webim/styles/dialogs/default/handlebars_templates/chat_layout.handlebars b/src/messenger/webim/styles/dialogs/default/handlebars_templates/chat_layout.handlebars index 5d61509c..afd26b36 100644 --- a/src/messenger/webim/styles/dialogs/default/handlebars_templates/chat_layout.handlebars +++ b/src/messenger/webim/styles/dialogs/default/handlebars_templates/chat_layout.handlebars @@ -1,3 +1,30 @@ +{{! Chat window top. Includes logo and some info about company}} +
+ +
+ {{! Chat header}}
diff --git a/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_description.handlebars b/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_description.handlebars new file mode 100644 index 00000000..6df3781c --- /dev/null +++ b/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_description.handlebars @@ -0,0 +1,6 @@ + +
{{L10n "leavemessage.descr"}}
\ No newline at end of file diff --git a/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_form.handlebars b/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_form.handlebars new file mode 100644 index 00000000..cb12a115 --- /dev/null +++ b/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_form.handlebars @@ -0,0 +1,43 @@ +
+ + + + {{#unless groups}}{{#if groupId}}{{/if}}{{/unless}} + +
+ + + + + + + + + + + {{#if groups}} + + + + + + + + + {{/if}} + + + + + {{#if showCaptcha}} + + + + + {{/if}} +
{{L10n "form.field.email"}}:
{{L10n "form.field.name"}}:
{{L10n "form.field.department"}}
{{L10n "form.field.department.description"}}{{groups.defaultDescription}}
{{L10n "form.field.message"}}: + +
+ {{L10n "mailthread.perform"}} +
 
+
\ No newline at end of file diff --git a/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_layout.handlebars b/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_layout.handlebars new file mode 100644 index 00000000..29eed8d9 --- /dev/null +++ b/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_layout.handlebars @@ -0,0 +1,35 @@ +{{! Logo block}} +
+ +
+ +{{! Header block. Contains description}} +
+
+
+
+ +{{! Empty container for main content}} +
\ No newline at end of file diff --git a/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_sent_description.handlebars b/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_sent_description.handlebars new file mode 100644 index 00000000..84a7d66d --- /dev/null +++ b/src/messenger/webim/styles/dialogs/default/handlebars_templates/leave_message_sent_description.handlebars @@ -0,0 +1,6 @@ + +
{{L10n "leavemessage.sent.message"}}
\ No newline at end of file diff --git a/src/messenger/webim/styles/dialogs/default/handlebars_templates/survey_form.handlebars b/src/messenger/webim/styles/dialogs/default/handlebars_templates/survey_form.handlebars new file mode 100644 index 00000000..47b43a5a --- /dev/null +++ b/src/messenger/webim/styles/dialogs/default/handlebars_templates/survey_form.handlebars @@ -0,0 +1,42 @@ +
+ + + + + {{#unless showEmail}}{{/unless}} + {{#unless groups}}{{#if groupId}}{{/if}}{{/unless}} + {{#unless showMessage}}{{/unless}} + +
+ + + {{#if groups}} + + + + + + + + + {{/if}} + + + + + {{#if showEmail}} + + + + + {{/if}} + {{#if showMessage}} + + + + + {{/if}} +
{{L10n "form.field.department"}}
{{L10n "form.field.department.description"}}{{groups.defaultDescription}}
{{L10n "presurvey.name"}}
{{L10n "presurvey.mail"}}
{{L10n "presurvey.question"}}
+ {{L10n "presurvey.submit"}} +
 
+
\ No newline at end of file diff --git a/src/messenger/webim/styles/dialogs/default/handlebars_templates/survey_layout.handlebars b/src/messenger/webim/styles/dialogs/default/handlebars_templates/survey_layout.handlebars new file mode 100644 index 00000000..1d9aff5e --- /dev/null +++ b/src/messenger/webim/styles/dialogs/default/handlebars_templates/survey_layout.handlebars @@ -0,0 +1,39 @@ +{{! Logo block}} +
+ +
+ +{{! Header block. Contains description and close link}} +
+
+
+ {{L10n +
+
{{L10n "presurvey.intro"}}
+
+
+ +{{! Empty container for main content}} +
\ No newline at end of file diff --git a/src/messenger/webim/styles/dialogs/default/js/compiled/templates.js b/src/messenger/webim/styles/dialogs/default/js/compiled/templates.js index 42ce4dae..ae7da469 100644 --- a/src/messenger/webim/styles/dialogs/default/js/compiled/templates.js +++ b/src/messenger/webim/styles/dialogs/default/js/compiled/templates.js @@ -4,23 +4,57 @@ Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ -(function(){var l=Handlebars.template,n=Handlebars.templates=Handlebars.templates||{};n.user_name_control=l(function(d,b,e,g,a){function c(a,d){var c,f,b;c=""+('\n
\n \n '}function k(a,d){var c,f,b;b={hash:{},data:d};c='\n '+j((f=(f=a.user,null==f||!1===f?f:f.name),typeof f===q?f.apply(a):f))+'\n \n '}this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var h,q="function",j=this.escapeExpression,m=e.helperMissing,p=this;return(d=e["if"].call(b,(h=b.user,null==h||!1===h?h:h.canChangeName),{hash:{},inverse:p.program(6,function(a,d){var b,c;b={hash:{},data:d};return b="\n"+(j((c=e.L10n,c?c.call(a,"chat.client.name",b):m.call(a,"L10n","chat.client.name",b)))+" "+j((c=(c=a.user,null==c||!1===c?c:c.name),typeof c===q?c.apply(a): -c))+"\n")},a),fn:p.program(1,function(a,d){var b,f;b={hash:{},data:d};b='\n '+(j((f=e.L10n,f?f.call(a,"chat.client.name",b):m.call(a,"L10n","chat.client.name",b)))+"\n ");if((f=e["if"].call(a,a.nameInput,{hash:{},inverse:p.program(4,k,d),fn:p.program(2,c,d),data:d}))||0===f)b+=f;return b+="\n"},a),data:a}))||0===d?d:""});n.status_typing=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var c;d=e.helperMissing;g=this.escapeExpression; -a={hash:{},data:a};return g((c=e.L10n,c?c.call(b,"typing.remote",a):d.call(b,"L10n","typing.remote",a)))});n.chat_layout=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var c,k;g=e.helperMissing;var h=this.escapeExpression;d='\n
\n
\n \n
\n
\n
\n\n\n
\n
\n '; -if((k=e.unless.call(b,(c=b.user,null==c||!1===c?c:c.isAgent),{hash:{},inverse:this.noop,fn:this.program(1,function(){return'\n
\n '},a),data:a}))||0===k)d+=k;a={hash:{},data:a};return d=d+'\n \n
\n \n
\n
\n
\n\n\n
\n\n\n\n\n\n
')});n.avatar=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var c=this.escapeExpression;return(d=e["if"].call(b,b.imageLink,{hash:{},inverse:this.program(3,function(){return'
'},a),fn:this.program(1,function(a,d){var b,j;b=''},a),data:a}))||0===d?d:""});n.close_control=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var c;d=e.helperMissing;g=this.escapeExpression;a={hash:{},data:a};return b='
')});n.history_control=l(function(d, -b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var c;d=e.helperMissing;g=this.escapeExpression;a={hash:{},data:a};return b='
')});n.status_message=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};d=this.escapeExpression;(e=e.message)?e=e.call(b,{hash:{},data:a}):(e=b.message,e="function"=== -typeof e?e.apply(b):e);return d(e)});n.secure_mode_control=l(function(){this.compilerInfo=[2,">= 1.0.0-rc.3"];return'
'});n.sound_control=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var c=e.helperMissing,k=this.escapeExpression;return(d=e["if"].call(b,b.enabled,{hash:{},inverse:this.program(3,function(a,d){var b,m;b={hash:{},data:d};return b='\n
\n')},a),fn:this.program(1,function(a,d){var b,m;b={hash:{},data:d};return b='\n
\n')},a),data:a}))||0===d?d:""});n.message=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var c, -k=this.escapeExpression,h=e.helperMissing;d={hash:{},data:a};d=""+(k((c=e.formatTime,c?c.call(b,b.created,d):h.call(b,"formatTime",b.created,d)))+" \n");if((c=e["if"].call(b,b.name,{hash:{},inverse:this.noop,fn:this.program(1,function(a,b){var d,c;d="";(c=e.name)?c=c.call(a,{hash:{},data:b}):(c=a.name,c="function"===typeof c?c.apply(a):c);return d+=k(c)+": "}, -a),data:a}))||0===c)d+=c;d+="\n";if((c=e["if"].call(b,b.allowFormatting,{hash:{},inverse:this.program(5,function(a,d){var b,c;c={hash:{},data:d};return k((b=e.apply,b?b.call(a,a.message,"urlReplace, nl2br",c):h.call(a,"apply",a.message,"urlReplace, nl2br",c)))},a),fn:this.program(3,function(a,d){var b,c;c={hash:{},data:d};return k((b=e.apply,b?b.call(a,a.message,"urlReplace, nl2br, allowTags", -c):h.call(a,"apply",a.message,"urlReplace, nl2br, allowTags",c)))},a),data:a}))||0===c)d+=c;return d+="
"});n.message_form=l(function(d,b,e,g,a){function c(a,b){var c,d;c={hash:{},data:b};c='\n \n "}function k(a){var c;return a=""+("\n \n ")}this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var h,l="function",j=this.escapeExpression,m=e.helperMissing,p=this;d='
\n';if((g=e["if"].call(b,(h=b.user,null==h||!1===h?h:h.canPost),{hash:{},inverse:p.noop,fn:p.program(1, -function(){return'\n
\n \n
\n'},a),data:a}))||0===g)d+=g;d+='\n
\n\n
\n';if((g=e["if"].call(b,(h=b.user,null==h||!1===h?h:h.canPost),{hash:{},inverse:p.noop,fn:p.program(3,function(a,d){var b,f,g;b='\n
\n
\n ';if((g=e["if"].call(a,(f=a.user, -null==f||!1===f?f:f.isAgent),{hash:{},inverse:p.noop,fn:p.program(4,c,d),data:d}))||0===g)b+=g;g={hash:{},data:d};b=b+'\n
\n ');g={hash:{},data:d};return b+=j((f=e.L10n,f?f.call(a,"chat.window.send_message_short_and_shortcut",g):m.call(a,"L10n","chat.window.send_message_short_and_shortcut",g)))+"\n
\n"},a), -data:a}))||0===g)d+=g;return d+'\n
\n
'});n.send_mail_control=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var c;d=e.helperMissing;g=this.escapeExpression;a={hash:{},data:a};return b='
')});n.refresh_control=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers; -a=a||{};var c;d=e.helperMissing;g=this.escapeExpression;a={hash:{},data:a};return b='
')});n.redirect_control=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};var c,k=e.helperMissing,h=this.escapeExpression;return(d=e["if"].call(b,(c=b.user,null==c||!1===c?c:c.canPost),{hash:{},inverse:this.noop,fn:this.program(1,function(a, -c){var b,d;b={hash:{},data:c};return b='\n
\n')},a),data:a}))||0===d?d:""});n.status=l(function(d,b,e,g,a){this.compilerInfo=[2,">= 1.0.0-rc.3"];e=e||d.helpers;a=a||{};d=this.escapeExpression;(e=e.title)?e=e.call(b,{hash:{},data:a}):(e=b.title,e="function"===typeof e?e.apply(b):e);return d(e)})})(); +(function(){var r=Handlebars.template,s=Handlebars.templates=Handlebars.templates||{};s.user_name_control=r(function(a,e,f,b,c){function j(a,b){var d,g,c;d=""+('\n
\n \n '}function k(a,b){var d,g,c;c={hash:{},data:b};d='\n '+h((g=(g=a.user,null==g||!1===g?g:g.name),typeof g===p?g.apply(a):g))+'\n \n '}this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var l,p="function",h=this.escapeExpression,m=f.helperMissing,n=this;return(a=f["if"].call(e,(l=e.user,null==l||!1===l?l:l.canChangeName),{hash:{},inverse:n.program(6,function(a,b){var d,g;d={hash:{},data:b};return d="\n"+(h((g=f.L10n,g?g.call(a,"chat.client.name",d):m.call(a,"L10n","chat.client.name",d)))+" "+h((g=(g=a.user,null==g||!1===g?g:g.name),typeof g===p?g.apply(a): +g))+"\n")},c),fn:n.program(1,function(a,b){var d,g;d={hash:{},data:b};d='\n '+(h((g=f.L10n,g?g.call(a,"chat.client.name",d):m.call(a,"L10n","chat.client.name",d)))+"\n ");if((g=f["if"].call(a,a.nameInput,{hash:{},inverse:n.program(4,k,b),fn:n.program(2,j,b),data:b}))||0===g)d+=g;return d+="\n"},c),data:c}))||0===a?a:""});s.status_typing=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j;a=f.helperMissing;b=this.escapeExpression; +c={hash:{},data:c};return b((j=f.L10n,j?j.call(e,"typing.remote",c):a.call(e,"L10n","typing.remote",c)))});s.leave_message_form=r(function(a,e,f,b,c){function j(a,b){var c,d;c=''}this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var k,l="function",p=this.escapeExpression,h=this,m=f.helperMissing;a=""+('
\n \n \n \n ';if((b=f.unless.call(e,e.groups,{hash:{},inverse:h.noop,fn:h.program(1,function(a,b){var c;return(c=f["if"].call(a,a.groupId,{hash:{}, +inverse:h.noop,fn:h.program(2,j,b),data:b}))||0===c?c:""},c),data:c}))||0===b)a+=b;b={hash:{},data:c};a=a+'\n\n
\n\n \n \n \n \n \n \n \n \n \n ';if((b=f["if"].call(e,e.groups,{hash:{},inverse:h.noop,fn:h.program(4,function(a,b){var c, +d,g;g={hash:{},data:b};c='\n \n \n \n \n \n \n \n \n "},c),data:c}))||0===b)a+=b;a+="\n \n \n \n \n ";if((b=f["if"].call(e,e.showCaptcha,{hash:{},inverse:h.noop,fn:h.program(6,function(){return'\n \n \n \n \n '},c),data:c}))||0===b)a+=b;a+='\n
'+(p((k=f.L10n,k?k.call(e,"form.field.email",b):m.call(e,"L10n","form.field.email",b)))+':
';b={hash:{},data:c};a+=p((k=f.L10n,k?k.call(e,"form.field.name",b):m.call(e,"L10n","form.field.name",b)))+':
'+(p((d=f.L10n,d?d.call(a,"form.field.department",g):m.call(a,"L10n","form.field.department",g)))+'
';g={hash:{},data:b};return c+=p((d=f.L10n,d?d.call(a,"form.field.department.description", +g):m.call(a,"L10n","form.field.department.description",g)))+''+p((d=(d=a.groups,null==d||!1===d?d:d.defaultDescription),typeof d===l?d.apply(a):d))+"
";b={hash:{},data:c};a+=p((k=f.L10n,k?k.call(e,"form.field.message",b):m.call(e,"L10n","form.field.message",b)))+':\n \n
\n '; +b={hash:{},data:c};return a+=p((k=f.L10n,k?k.call(e,"mailthread.perform",b):m.call(e,"L10n","mailthread.perform",b)))+'\n
 
\n
'});s.leave_message_layout=r(function(a,e,f,b,c){function j(a){var d;return a=""+('\n \n ')}function k(a){var d;return a=""+("\n \n \n \n ')}function l(a){var d;return a=""+("\n \n \n \n ')}function p(a){var d;return a=""+('\n \n ')}this.compilerInfo= +[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var h,m="function",n=this.escapeExpression,q=this;a='\n
\n \n
\n\n\n
\n
\n
\n
\n\n\n
'}); +s.avatar=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j=this.escapeExpression;return(a=f["if"].call(e,e.imageLink,{hash:{},inverse:this.program(3,function(){return'
'},c),fn:this.program(1,function(a,b){var c,e;c=''},c),data:c}))||0===a?a:""});s.close_control=r(function(a,e,f,b, +c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j;a=f.helperMissing;b=this.escapeExpression;c={hash:{},data:c};return e='
')});s.history_control=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j;a=f.helperMissing;b=this.escapeExpression;c={hash:{},data:c};return e='
')});s.status_message=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};a=this.escapeExpression;(f=f.message)?f=f.call(e,{hash:{},data:c}):(f=e.message,f="function"===typeof f?f.apply(e):f);return a(f)});s.survey_form=r(function(a,e,f,b,c){function j(a,b){var c,d;c=''}this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var k,l="function",p=this.escapeExpression,h=this,m=f.helperMissing;a=""+('
\n \n \n \n \n ';if((b=f.unless.call(e,e.showEmail,{hash:{},inverse:h.noop,fn:h.program(1,function(a,b){var c,d;c=''},c),data:c}))||0===b)a+=b;a+="\n "; +if((b=f.unless.call(e,e.groups,{hash:{},inverse:h.noop,fn:h.program(3,function(a,b){var c;return(c=f["if"].call(a,a.groupId,{hash:{},inverse:h.noop,fn:h.program(4,j,b),data:b}))||0===c?c:""},c),data:c}))||0===b)a+=b;a+="\n ";if((b=f.unless.call(e,e.showMessage,{hash:{},inverse:h.noop,fn:h.program(6,function(a,b){var c,d;c=''},c),data:c}))||0===b)a+= +b;a+='\n\n
\n\n \n ';if((b=f["if"].call(e,e.groups,{hash:{},inverse:h.noop,fn:h.program(8,function(a,b){var c,d,g;g={hash:{},data:b};c="\n \n \n \n \n \n \n \n \n "},c),data:c}))||0===b)a+=b;b={hash:{},data:c};a=a+"\n \n \n \n \n ";if((b=f["if"].call(e,e.showEmail,{hash:{},inverse:h.noop,fn:h.program(12,function(a,c){var b,d;b={hash:{},data:c};b="\n \n \n \n \n '},c),data:c}))||0===b)a+=b;a+="\n ";if((b=f["if"].call(e,e.showMessage,{hash:{},inverse:h.noop,fn:h.program(14,function(a,b){var c,d;c={hash:{},data:b};c="\n \n \n \n \n "},c),data:c}))||0===b)a+=b;a+='\n
"+(p((d=f.L10n,d?d.call(a,"form.field.department",g):m.call(a,"L10n","form.field.department",g)))+'
"; +g={hash:{},data:b};return c+=p((d=f.L10n,d?d.call(a,"form.field.department.description",g):m.call(a,"L10n","form.field.department.description",g)))+''+p((d=(d=a.groups,null==d||!1===d?d:d.defaultDescription),typeof d===l?d.apply(a):d))+"
"+(p((k=f.L10n,k?k.call(e,"presurvey.name",b):m.call(e,"L10n","presurvey.name",b)))+'
"+(p((d=f.L10n,d?d.call(a,"presurvey.mail",b):m.call(a,"L10n", +"presurvey.mail",b)))+'
"+(p((d=f.L10n,d?d.call(a,"presurvey.question",c):m.call(a, +"L10n","presurvey.question",c)))+'
\n ';b={hash:{},data:c};return a+=p((k=f.L10n,k?k.call(e,"presurvey.submit",b):m.call(e,"L10n","presurvey.submit", +b)))+'\n
 
\n
'});s.chat_layout=r(function(a,e,f,b,c){function j(d){var a;return d=""+('\n \n ')}function k(a){var g;return a=""+("\n \n \n \n ')}function l(a){var g;return a=""+("\n \n \n \n ')}function p(a){var g;return a=""+('\n \n ')}this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var h,m,n="function",q=this.escapeExpression,t=this;b=f.helperMissing; +a='\n
\n \n
\n\n\n
\n
\n \n
\n
\n
\n\n\n
\n
\n '; +if((m=f.unless.call(e,(h=e.user,null==h||!1===h?h:h.isAgent),{hash:{},inverse:t.noop,fn:t.program(11,function(){return'\n
\n '},c),data:c}))||0===m)a+=m;c={hash:{},data:c};return a=a+'\n \n
\n \n
\n
\n
\n\n\n
\n\n\n\n\n\n
')});s.secure_mode_control=r(function(){this.compilerInfo=[2,">= 1.0.0-rc.3"];return'
'});s.sound_control=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j=f.helperMissing,k=this.escapeExpression;return(a=f["if"].call(e,e.enabled,{hash:{},inverse:this.program(3, +function(a,b){var c,e;c={hash:{},data:b};return c='\n
\n')},c),fn:this.program(1,function(a,c){var b,e;b={hash:{},data:c};return b='\n
\n')}, +c),data:c}))||0===a?a:""});s.message=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j,k=this.escapeExpression,l=f.helperMissing;a={hash:{},data:c};a=""+(k((j=f.formatTime,j?j.call(e,e.created,a):l.call(e,"formatTime",e.created,a)))+" \n");if((j=f["if"].call(e,e.name,{hash:{},inverse:this.noop,fn:this.program(1,function(a,b){var c,e;c="";(e=f.name)?e=e.call(a,{hash:{},data:b}):(e=a.name,e="function"===typeof e?e.apply(a):e);return c+=k(e)+": "},c),data:c}))||0===j)a+=j;a+="\n";if((j=f["if"].call(e,e.allowFormatting,{hash:{},inverse:this.program(5,function(a,c){var b,e;e={hash:{},data:c};return k((b=f.apply,b?b.call(a,a.message,"urlReplace, nl2br",e):l.call(a,"apply",a.message,"urlReplace, nl2br", +e)))},c),fn:this.program(3,function(a,c){var b,e;e={hash:{},data:c};return k((b=f.apply,b?b.call(a,a.message,"urlReplace, nl2br, allowTags",e):l.call(a,"apply",a.message,"urlReplace, nl2br, allowTags",e)))},c),data:c}))||0===j)a+=j;return a+="
"});s.message_form=r(function(a,e,f,b,c){function j(a,b){var d,g;d={hash:{},data:b};d='\n \n "}function k(a){var b;return a=""+("\n \n ")}this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var l,p="function",h=this.escapeExpression,m= +f.helperMissing,n=this;a='
\n';if((b=f["if"].call(e,(l=e.user,null==l||!1===l?l:l.canPost),{hash:{},inverse:n.noop,fn:n.program(1,function(){return'\n
\n \n
\n'},c),data:c}))||0===b)a+=b;a+='\n
\n\n
\n';if((b=f["if"].call(e,(l=e.user,null==l||!1===l?l:l.canPost),{hash:{},inverse:n.noop,fn:n.program(3, +function(a,b){var d,g,c;d='\n
\n
\n ';if((c=f["if"].call(a,(g=a.user,null==g||!1===g?g:g.isAgent),{hash:{},inverse:n.noop,fn:n.program(4,j,b),data:b}))||0===c)d+=c;c={hash:{},data:b};d=d+'\n
\n ');c={hash:{},data:b};return d+=h((g=f.L10n,g?g.call(a, +"chat.window.send_message_short_and_shortcut",c):m.call(a,"L10n","chat.window.send_message_short_and_shortcut",c)))+"\n
\n"},c),data:c}))||0===b)a+=b;return a+'\n
\n
'});s.send_mail_control=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j;a=f.helperMissing;b=this.escapeExpression;c={hash:{},data:c};return e='
')});s.survey_layout=r(function(a,e,f,b,c){function j(a){var b;return a=""+('\n \n ')}function k(a){var b;return a=""+("\n \n \n \n ')}function l(a){var b;return a=""+("\n \n \n \n ')}function p(a){var b;return a=""+('\n \n ')}this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var h,m,n="function",q=this.escapeExpression,r=this;b=f.helperMissing;a='\n
\n \n
\n\n\n
\n
\n
\n ';m={hash:{},data:c};a+=q((h=f.L10n,h?h.call(e,\n
\n
';m={hash:{},data:c};return a+=q((h=f.L10n,h?h.call(e,"presurvey.intro",m):b.call(e, +"L10n","presurvey.intro",m)))+'
\n
\n
\n\n\n
'});s.leave_message_description=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j,k=f.helperMissing,l=this.escapeExpression;b={hash:{},data:c};a='
\n \n ');b={hash:{},data:c};a+=l((j=f.L10n,j?j.call(e,\n \n
\n
';b={hash:{},data:c};return a+=l((j=f.L10n,j?j.call(e,"leavemessage.descr",b):k.call(e,"L10n","leavemessage.descr",b)))+"
"});s.refresh_control=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{}; +var j;a=f.helperMissing;b=this.escapeExpression;c={hash:{},data:c};return e='
')});s.redirect_control=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j,k=f.helperMissing,l=this.escapeExpression;return(a=f["if"].call(e,(j=e.user,null==j||!1===j?j:j.canPost),{hash:{},inverse:this.noop,fn:this.program(1,function(a,b){var c, +e;c={hash:{},data:b};return c='\n
\n')},c),data:c}))||0===a?a:""});s.status=r(function(a,e,f,b,c){this.compilerInfo=[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};a=this.escapeExpression;(f=f.title)?f=f.call(e,{hash:{},data:c}):(f=e.title,f="function"===typeof f?f.apply(e):f);return a(f)});s.leave_message_sent_description=r(function(a,e,f,b,c){this.compilerInfo= +[2,">= 1.0.0-rc.3"];f=f||a.helpers;c=c||{};var j,k=f.helperMissing,l=this.escapeExpression;b={hash:{},data:c};a='
\n \n ');b={hash:{},data:c};a+=l((j=f.L10n,j?j.call(e,
+\n \n
\n
';b={hash:{},data:c};return a+=l((j=f.L10n,j?j.call(e,"leavemessage.sent.message",b):k.call(e,"L10n","leavemessage.sent.message",b)))+"
"})})(); diff --git a/src/messenger/webim/styles/dialogs/default/templates/chat.tpl b/src/messenger/webim/styles/dialogs/default/templates/chat.tpl index a84a81c7..ca3fe308 100644 --- a/src/messenger/webim/styles/dialogs/default/templates/chat.tpl +++ b/src/messenger/webim/styles/dialogs/default/templates/chat.tpl @@ -46,7 +46,29 @@ 'chat.client.changename': "${msg:chat.client.changename}", 'chat.window.toolbar.turn_off_sound': "${msg:chat.window.toolbar.turn_off_sound}", 'chat.window.toolbar.turn_on_sound': "${msg:chat.window.toolbar.turn_on_sound}", - 'chat.window.poweredby': "${msg:chat.window.poweredby}" + 'chat.window.poweredby': "${msg:chat.window.poweredby}", + 'chat.mailthread.sent.close': "${msg:chat.mailthread.sent.close}", + 'form.field.department': "${msg:form.field.department}", + 'form.field.department.description': "${msg:form.field.department.description}", + 'form.field.email': "${msg:form.field.email}", + 'form.field.name': "${msg:form.field.name}", + 'form.field.message': "${msg:form.field.message}", + 'leavemessage.close': "${msg:leavemessage.close}", + 'leavemessage.descr': "${msg:leavemessage.descr}", + 'leavemessage.sent.message': "${msg:leavemessage.sent.message}", + 'leavemessage.error.email.required': '${page:localized.email.required}', + 'leavemessage.error.name.required': '${page:localized.name.required}', + 'leavemessage.error.message.required': '${page:localized.message.required}', + 'leavemessage.error.wrong.email': '${page:localized.wrong.email}', + 'errors.captcha': '${msg:errors.captcha}', + 'mailthread.perform': "${msg:mailthread.perform}", + 'presurvey.name': "${msg:presurvey.name}", + 'presurvey.mail': "${msg:presurvey.mail}", + 'presurvey.question': "${msg:presurvey.question}", + 'presurvey.submit': "${msg:presurvey.submit}", + 'presurvey.error.wrong_email': "${msg:presurvey.error.wrong_email}", + 'presurvey.title': "${msg:presurvey.title}", + 'presurvey.intro': '${msg:presurvey.intro}' }); //--> @@ -61,9 +83,24 @@ page: { style: '${styleid}', webimRoot: '${webimroot}', - tplRoot: '${tplroot}' + tplRoot: '${tplroot}', + company: { + name: '${page:company.name}', + chatLogoURL: '${page:company.chatLogoURL}' + }, + webimHost: '${page:webimHost}', + title: '${page:page.title}' }, - chatModule: ${page:chatModule}, + ${if:chatOptions} + chatOptions: ${page:chatOptions}, + ${endif:chatOptions} + ${if:surveyOptions} + surveyOptions: ${page:surveyOptions}, + ${endif:surveyOptions} + ${if:leaveMessageOptions} + leaveMessageOptions: ${page:leaveMessageOptions}, + ${endif:leaveMessageOptions} + startFrom: "${page:startFrom}", plugins: ${page:js_plugin_options} }); }); @@ -71,33 +108,6 @@ - - -
- -
-
\ No newline at end of file diff --git a/src/messenger/webim/styles/dialogs/default/templates/leavemessage.tpl b/src/messenger/webim/styles/dialogs/default/templates/leavemessage.tpl deleted file mode 100644 index 52de124c..00000000 --- a/src/messenger/webim/styles/dialogs/default/templates/leavemessage.tpl +++ /dev/null @@ -1,98 +0,0 @@ - - - - ${msg:leavemessage.title} - - - - - - - - -
- - - - ${ifnot:groups}${if:formgroupid}${endif:formgroupid}${endif:groups} - -
- -
-
-
-
- ${msg:leavemessage.close} -
-
${msg:leavemessage.descr}
-
-
-
- ${if:errors} - ${errors} - ${endif:errors} - - - - - - - - - - ${if:groups} - - - - - - - - - ${endif:groups} - - - - - ${if:showcaptcha} - - - - - ${endif:showcaptcha} -
${msg:form.field.email}:
${msg:form.field.name}:
${msg:form.field.department} - -
${msg:form.field.department.description}${page:default.department.description}
${msg:form.field.message}: - -
- ${msg:mailthread.perform} -
 
-
-
- - diff --git a/src/messenger/webim/styles/dialogs/default/templates/leavemessagesent.tpl b/src/messenger/webim/styles/dialogs/default/templates/leavemessagesent.tpl deleted file mode 100644 index 90f2e3ef..00000000 --- a/src/messenger/webim/styles/dialogs/default/templates/leavemessagesent.tpl +++ /dev/null @@ -1,45 +0,0 @@ - - - - ${msg:leavemessage.sent.title} - - - - -
- -
-
-
-
- ${msg:chat.mailthread.sent.close} -
-
${msg:leavemessage.sent.message}
-
-
-
-   -
- - \ No newline at end of file diff --git a/src/messenger/webim/styles/dialogs/default/templates/survey.tpl b/src/messenger/webim/styles/dialogs/default/templates/survey.tpl deleted file mode 100644 index 5e56eddc..00000000 --- a/src/messenger/webim/styles/dialogs/default/templates/survey.tpl +++ /dev/null @@ -1,96 +0,0 @@ - - - - ${msg:presurvey.title} - - - - - - - -
- -
-
-
-
- ${msg:leavemessage.close} -
-
${msg:presurvey.intro}
-
-
-
- -
- - - - - ${ifnot:showemail}${endif:showemail} - ${ifnot:groups}${if:formgroupid}${endif:formgroupid}${endif:groups} - ${ifnot:showmessage}${endif:showmessage} - - - ${if:groups} - - - - - - - - - ${endif:groups} - - - - - ${if:showemail} - - - - - ${endif:showemail} - ${if:showmessage} - - - - - ${endif:showmessage} -
${msg:form.field.department}
${msg:form.field.department.description}${page:default.department.description}
${msg:presurvey.name}
${msg:presurvey.mail}
${msg:presurvey.question}:
- ${msg:presurvey.submit} -
 
-
- - \ No newline at end of file diff --git a/src/messenger/webim/thread.php b/src/messenger/webim/thread.php index ad818796..f5b204f4 100644 --- a/src/messenger/webim/thread.php +++ b/src/messenger/webim/thread.php @@ -18,6 +18,10 @@ require_once('libs/init.php'); require_once('libs/chat.php'); require_once('libs/operator.php'); +require_once('libs/invitation.php'); +require_once('libs/groups.php'); +require_once('libs/captcha.php'); +require_once('libs/notify.php'); require_once('libs/classes/thread.php'); require_once('libs/classes/mibew_api.php'); require_once('libs/classes/mibew_api_interaction.php');