2007-10-10 19:15:47 +04:00
|
|
|
<?php
|
|
|
|
/*
|
2013-03-07 01:22:53 +04:00
|
|
|
* Copyright 2005-2013 the original author or authors.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2007-10-10 19:15:47 +04:00
|
|
|
*/
|
|
|
|
|
2011-04-07 12:34:04 +04:00
|
|
|
require_once(dirname(__FILE__).'/track.php');
|
2012-09-28 18:46:42 +04:00
|
|
|
require_once(dirname(__FILE__).'/classes/thread.php');
|
2007-10-10 19:15:47 +04:00
|
|
|
|
2009-03-08 23:53:16 +03:00
|
|
|
$namecookie = "WEBIM_Data";
|
2008-10-03 19:11:02 +04:00
|
|
|
$usercookie = "WEBIM_UserID";
|
2007-10-10 19:15:47 +04:00
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function get_user_id()
|
|
|
|
{
|
|
|
|
return (time() + microtime()) . rand(0, 99999999);
|
2008-10-03 19:11:02 +04:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function message_to_text($msg)
|
|
|
|
{
|
2012-10-10 17:33:25 +04:00
|
|
|
if ($msg['kind'] == Thread::KIND_AVATAR) {
|
2012-09-28 18:46:42 +04:00
|
|
|
return "";
|
|
|
|
}
|
2011-02-26 17:04:12 +03:00
|
|
|
$message_time = date("H:i:s ", $msg['created']);
|
2012-10-10 17:33:25 +04:00
|
|
|
if ($msg['kind'] == Thread::KIND_USER || $msg['kind'] == Thread::KIND_AGENT) {
|
|
|
|
if ($msg['name'])
|
|
|
|
return $message_time . $msg['name'] . ": " . $msg['message'] . "\n";
|
2007-10-10 19:15:47 +04:00
|
|
|
else
|
2012-10-10 17:33:25 +04:00
|
|
|
return $message_time . $msg['message'] . "\n";
|
|
|
|
} else if ($msg['kind'] == Thread::KIND_INFO) {
|
|
|
|
return $message_time . $msg['message'] . "\n";
|
2007-10-10 19:15:47 +04:00
|
|
|
} else {
|
2012-10-10 17:33:25 +04:00
|
|
|
return $message_time . "[" . $msg['message'] . "]\n";
|
2007-10-10 19:15:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function get_user_name($username, $addr, $id)
|
|
|
|
{
|
2012-07-16 18:26:53 +04:00
|
|
|
return str_replace(
|
|
|
|
"{addr}", $addr,
|
|
|
|
str_replace(
|
|
|
|
"{id}", $id,
|
|
|
|
str_replace("{name}", $username, Settings::get('usernamepattern'))
|
|
|
|
)
|
|
|
|
);
|
2007-10-10 19:15:47 +04:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function is_ajax_browser($browserid, $ver, $useragent)
|
|
|
|
{
|
|
|
|
if ($browserid == "opera")
|
2007-10-10 19:15:47 +04:00
|
|
|
return $ver >= 8.02;
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($browserid == "safari")
|
2007-10-10 19:15:47 +04:00
|
|
|
return $ver >= 125;
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($browserid == "msie")
|
2007-10-10 19:15:47 +04:00
|
|
|
return $ver >= 5.5 && !strstr($useragent, "powerpc");
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($browserid == "netscape")
|
2007-10-10 19:15:47 +04:00
|
|
|
return $ver >= 7.1;
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($browserid == "mozilla")
|
2007-10-10 19:15:47 +04:00
|
|
|
return $ver >= 1.4;
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($browserid == "firefox")
|
2007-10-10 19:15:47 +04:00
|
|
|
return $ver >= 1.0;
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($browserid == "chrome")
|
2008-12-18 18:09:44 +03:00
|
|
|
return true;
|
2007-10-10 19:15:47 +04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
$knownAgents = array("opera", "msie", "chrome", "safari", "firefox", "netscape", "mozilla");
|
2007-10-10 19:15:47 +04:00
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function get_remote_level($useragent)
|
|
|
|
{
|
2007-10-10 19:15:47 +04:00
|
|
|
global $knownAgents;
|
|
|
|
$useragent = strtolower($useragent);
|
2011-02-26 17:04:12 +03:00
|
|
|
foreach ($knownAgents as $agent) {
|
|
|
|
if (strstr($useragent, $agent)) {
|
|
|
|
if (preg_match("/" . $agent . "[\\s\/]?(\\d+(\\.\\d+)?)/", $useragent, $matches)) {
|
2007-10-10 19:15:47 +04:00
|
|
|
$ver = $matches[1];
|
|
|
|
|
2012-12-27 18:07:11 +04:00
|
|
|
if (is_ajax_browser($agent, $ver, $useragent)) {
|
2007-10-10 19:15:47 +04:00
|
|
|
return "ajaxed";
|
2012-12-27 18:07:11 +04:00
|
|
|
} else {
|
2007-10-10 19:15:47 +04:00
|
|
|
return "old";
|
2012-12-27 18:07:11 +04:00
|
|
|
}
|
2007-10-10 19:15:47 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "simple";
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function is_agent_opera95()
|
|
|
|
{
|
2008-09-30 02:35:08 +04:00
|
|
|
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
|
2011-02-26 17:04:12 +03:00
|
|
|
if (strstr($useragent, "opera")) {
|
|
|
|
if (preg_match("/opera[\\s\/]?(\\d+(\\.\\d+)?)/", $useragent, $matches)) {
|
2008-09-30 02:35:08 +04:00
|
|
|
$ver = $matches[1];
|
|
|
|
|
|
|
|
if ($ver >= "9.5")
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function is_mac_opera()
|
|
|
|
{
|
2009-04-24 19:52:17 +04:00
|
|
|
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
|
2011-02-26 17:04:12 +03:00
|
|
|
return strstr($useragent, "opera") && strstr($useragent, "mac");
|
2009-04-24 19:52:17 +04:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function needsFramesrc()
|
|
|
|
{
|
2008-09-30 02:35:08 +04:00
|
|
|
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
|
2011-02-26 17:04:12 +03:00
|
|
|
return strstr($useragent, "safari/");
|
2008-09-30 02:35:08 +04:00
|
|
|
}
|
|
|
|
|
2012-03-13 21:26:18 +04:00
|
|
|
function setup_logo($group = NULL)
|
2011-02-26 17:04:12 +03:00
|
|
|
{
|
2012-07-16 18:26:53 +04:00
|
|
|
global $page;
|
2012-03-13 21:26:18 +04:00
|
|
|
$toplevelgroup = (!$group)?array():get_top_level_group($group);
|
2012-07-16 18:26:53 +04:00
|
|
|
$page['ct.company.name'] = topage(empty($toplevelgroup['vctitle'])?Settings::get('title'):$toplevelgroup['vctitle']);
|
|
|
|
$page['ct.company.chatLogoURL'] = topage(empty($toplevelgroup['vclogo'])?Settings::get('logo'):$toplevelgroup['vclogo']);
|
|
|
|
$page['webimHost'] = topage(empty($toplevelgroup['vchosturl'])?Settings::get('hosturl'):$toplevelgroup['vchosturl']);
|
2008-11-08 02:24:45 +03:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info, $referrer, $canshowcaptcha)
|
|
|
|
{
|
2012-07-16 18:26:53 +04:00
|
|
|
global $page;
|
2009-08-11 19:06:46 +04:00
|
|
|
$page['formname'] = topage($name);
|
|
|
|
$page['formemail'] = topage($email);
|
|
|
|
$page['formmessage'] = $message ? topage($message) : "";
|
2012-07-16 18:26:53 +04:00
|
|
|
$page['showcaptcha'] = Settings::get("enablecaptcha") == "1" && $canshowcaptcha ? "1" : "";
|
2009-08-11 19:06:46 +04:00
|
|
|
$page['formgroupid'] = $groupid;
|
|
|
|
$page['formgroupname'] = $groupname;
|
2011-02-16 04:17:30 +03:00
|
|
|
$page['forminfo'] = topage($info);
|
2009-08-11 19:06:46 +04:00
|
|
|
$page['referrer'] = urlencode(topage($referrer));
|
2012-03-09 23:40:07 +04:00
|
|
|
|
2012-07-16 18:26:53 +04:00
|
|
|
if (Settings::get('enablegroups') == '1') {
|
2012-03-09 23:40:07 +04:00
|
|
|
$groups = setup_groups_select($groupid, false);
|
|
|
|
if ($groups) {
|
|
|
|
$page['groups'] = $groups['select'];
|
|
|
|
$page['group.descriptions'] = json_encode($groups['descriptions']);
|
|
|
|
$page['default.department.description'] = $groups['defaultdescription'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 19:06:46 +04:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function setup_survey($name, $email, $groupid, $info, $referrer)
|
|
|
|
{
|
2012-07-16 18:26:53 +04:00
|
|
|
global $page;
|
2011-02-26 17:04:12 +03:00
|
|
|
|
2009-04-05 03:51:16 +04:00
|
|
|
$page['formname'] = topage($name);
|
|
|
|
$page['formemail'] = topage($email);
|
|
|
|
$page['formgroupid'] = $groupid;
|
|
|
|
$page['forminfo'] = topage($info);
|
|
|
|
$page['referrer'] = urlencode(topage($referrer));
|
|
|
|
|
2012-07-16 18:26:53 +04:00
|
|
|
if (Settings::get('enablegroups') == '1' && Settings::get('surveyaskgroup') == '1') {
|
2012-03-09 23:40:07 +04:00
|
|
|
$groups = setup_groups_select($groupid, true);
|
|
|
|
if ($groups) {
|
|
|
|
$page['groups'] = $groups['select'];
|
|
|
|
$page['group.descriptions'] = json_encode($groups['descriptions']);
|
|
|
|
$page['default.department.description'] = $groups['defaultdescription'];
|
2009-04-05 03:51:16 +04:00
|
|
|
}
|
|
|
|
}
|
2011-02-26 17:04:12 +03:00
|
|
|
|
2012-07-16 18:26:53 +04:00
|
|
|
$page['showemail'] = Settings::get("surveyaskmail") == "1" ? "1" : "";
|
|
|
|
$page['showmessage'] = Settings::get("surveyaskmessage") == "1" ? "1" : "";
|
|
|
|
$page['showname'] = Settings::get('usercanchangename') == "1" ? "1" : "";
|
2009-04-05 03:51:16 +04:00
|
|
|
}
|
|
|
|
|
2012-03-09 23:40:07 +04:00
|
|
|
function setup_groups_select($groupid, $markoffline)
|
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
$showgroups = ($groupid == '')?true:group_has_children($groupid);
|
2012-03-09 23:40:07 +04:00
|
|
|
if (!$showgroups) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
$allgroups = get_groups(false);
|
2012-03-09 23:40:07 +04:00
|
|
|
|
|
|
|
if (empty($allgroups)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$val = "";
|
|
|
|
$selectedgroupid = $groupid;
|
|
|
|
$groupdescriptions = array();
|
|
|
|
foreach ($allgroups as $k) {
|
|
|
|
$groupname = $k['vclocalname'];
|
|
|
|
if ($k['inumofagents'] == 0 || ($groupid && $k['parent'] != $groupid && $k['groupid'] != $groupid )) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-16 18:26:53 +04:00
|
|
|
if ($k['ilastseen'] !== NULL && $k['ilastseen'] < Settings::get('online_timeout')) {
|
2012-03-09 23:40:07 +04:00
|
|
|
if (!$selectedgroupid) {
|
|
|
|
$selectedgroupid = $k['groupid']; // select first online group
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$groupname .= $markoffline?" (offline)":"";
|
|
|
|
}
|
|
|
|
$isselected = $k['groupid'] == $selectedgroupid;
|
|
|
|
if ($isselected) {
|
|
|
|
$defaultdescription = $k['vclocaldescription'];
|
|
|
|
}
|
|
|
|
$val .= "<option value=\"" . $k['groupid'] . "\"" . ($isselected ? " selected=\"selected\"" : "") . ">$groupname</option>";
|
|
|
|
$groupdescriptions[] = $k['vclocaldescription'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'select' => $val,
|
|
|
|
'descriptions' => $groupdescriptions,
|
|
|
|
'defaultdescription' => $defaultdescription
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function setup_chatview_for_user($thread, $level)
|
|
|
|
{
|
2012-07-16 18:26:53 +04:00
|
|
|
global $page, $webimroot;
|
2008-09-30 02:35:08 +04:00
|
|
|
$page = array();
|
2012-09-28 18:46:42 +04:00
|
|
|
if (! empty($thread->groupId)) {
|
|
|
|
$group = group_by_id($thread->groupId);
|
2012-03-13 21:26:18 +04:00
|
|
|
$group = get_top_level_group($group);
|
|
|
|
} else {
|
|
|
|
$group = array();
|
|
|
|
}
|
2008-09-30 02:35:08 +04:00
|
|
|
$page['agent'] = false;
|
|
|
|
$page['user'] = true;
|
|
|
|
$page['canpost'] = true;
|
2012-09-28 18:46:42 +04:00
|
|
|
$nameisset = getstring("chat.default.username") != $thread->userName;
|
2008-09-30 02:35:08 +04:00
|
|
|
$page['displ1'] = $nameisset ? "none" : "inline";
|
|
|
|
$page['displ2'] = $nameisset ? "inline" : "none";
|
|
|
|
$page['level'] = $level;
|
2012-09-28 18:46:42 +04:00
|
|
|
$page['ct.chatThreadId'] = $thread->id;
|
|
|
|
$page['ct.token'] = $thread->lastToken;
|
|
|
|
$page['ct.user.name'] = htmlspecialchars(topage($thread->userName));
|
2012-07-16 18:26:53 +04:00
|
|
|
$page['canChangeName'] = Settings::get('usercanchangename') == "1";
|
|
|
|
$page['chat.title'] = topage(empty($group['vcchattitle'])?Settings::get('chattitle'):$group['vcchattitle']);
|
2008-09-30 02:35:08 +04:00
|
|
|
|
2012-03-13 21:26:18 +04:00
|
|
|
setup_logo($group);
|
2012-07-16 18:26:53 +04:00
|
|
|
if (Settings::get('sendmessagekey') == 'enter') {
|
2009-04-24 19:09:46 +04:00
|
|
|
$page['send_shortcut'] = "Enter";
|
2011-02-26 17:04:12 +03:00
|
|
|
$page['ignorectrl'] = 1;
|
2009-04-24 19:09:46 +04:00
|
|
|
} else {
|
2009-04-24 19:52:17 +04:00
|
|
|
$page['send_shortcut'] = is_mac_opera() ? "⌘-Enter" : "Ctrl-Enter";
|
2011-02-26 17:04:12 +03:00
|
|
|
$page['ignorectrl'] = 0;
|
2009-04-24 19:09:46 +04:00
|
|
|
}
|
2008-09-30 02:35:08 +04:00
|
|
|
|
2012-09-28 18:46:42 +04:00
|
|
|
$params = "thread=" . $thread->id . "&token=" . $thread->lastToken;
|
2011-02-26 17:04:12 +03:00
|
|
|
$page['mailLink'] = "$webimroot/client.php?" . $params . "&level=$level&act=mailthread";
|
2009-03-08 23:53:16 +03:00
|
|
|
|
2012-07-16 18:26:53 +04:00
|
|
|
if (Settings::get('enablessl') == "1" && !is_secure_request()) {
|
2011-02-26 17:04:12 +03:00
|
|
|
$page['sslLink'] = get_app_location(true, true) . "/client.php?" . $params . "&level=$level";
|
2009-03-08 23:53:16 +03:00
|
|
|
}
|
|
|
|
|
2008-09-30 02:35:08 +04:00
|
|
|
$page['isOpera95'] = is_agent_opera95();
|
|
|
|
$page['neediframesrc'] = needsFramesrc();
|
|
|
|
|
2012-07-16 18:26:53 +04:00
|
|
|
$page['frequency'] = Settings::get('updatefrequency_chat');
|
2013-01-24 16:36:36 +04:00
|
|
|
|
|
|
|
// Load dialogs style options
|
|
|
|
$style_config = get_dialogs_style_config(getchatstyle());
|
|
|
|
$page['chatStyles.chatWindowParams'] = $style_config['chat']['window_params'];
|
|
|
|
$page['chatStyles.mailWindowParams'] = $style_config['mail']['window_params'];
|
|
|
|
|
|
|
|
// Load core style options
|
|
|
|
$style_config = get_core_style_config();
|
|
|
|
$page['coreStyles.historyWindowParams'] = $style_config['history']['window_params'];
|
2008-09-30 02:35:08 +04:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function setup_chatview_for_operator($thread, $operator)
|
|
|
|
{
|
2012-07-16 18:26:53 +04:00
|
|
|
global $page, $webimroot, $company_logo_link, $webim_encoding, $company_name;
|
2008-09-30 02:35:08 +04:00
|
|
|
$page = array();
|
2012-09-28 18:46:42 +04:00
|
|
|
if (! is_null($thread->groupId)) {
|
|
|
|
$group = group_by_id($thread->groupId);
|
2012-03-13 21:26:18 +04:00
|
|
|
$group = get_top_level_group($group);
|
|
|
|
} else {
|
|
|
|
$group = array();
|
|
|
|
}
|
2008-09-30 02:35:08 +04:00
|
|
|
$page['agent'] = true;
|
|
|
|
$page['user'] = false;
|
2012-09-28 18:46:42 +04:00
|
|
|
$page['canpost'] = $thread->agentId == $operator['operatorid'];
|
|
|
|
$page['ct.chatThreadId'] = $thread->id;
|
|
|
|
$page['ct.token'] = $thread->lastToken;
|
|
|
|
$page['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread->userName, $thread->remote, $thread->userId)));
|
2012-07-16 18:26:53 +04:00
|
|
|
$page['chat.title'] = topage(empty($group['vcchattitle'])?Settings::get('chattitle'):$group['vcchattitle']);
|
2008-09-30 02:35:08 +04:00
|
|
|
|
2012-03-13 21:26:18 +04:00
|
|
|
setup_logo($group);
|
2012-07-16 18:26:53 +04:00
|
|
|
if (Settings::get('sendmessagekey') == 'enter') {
|
2009-04-24 19:09:46 +04:00
|
|
|
$page['send_shortcut'] = "Enter";
|
2011-02-26 17:04:12 +03:00
|
|
|
$page['ignorectrl'] = 1;
|
2009-04-24 19:09:46 +04:00
|
|
|
} else {
|
2009-04-24 19:52:17 +04:00
|
|
|
$page['send_shortcut'] = is_mac_opera() ? "⌘-Enter" : "Ctrl-Enter";
|
2011-02-26 17:04:12 +03:00
|
|
|
$page['ignorectrl'] = 0;
|
2009-04-24 19:09:46 +04:00
|
|
|
}
|
|
|
|
|
2012-07-16 18:26:53 +04:00
|
|
|
if (Settings::get('enablessl') == "1" && !is_secure_request()) {
|
2012-09-28 18:46:42 +04:00
|
|
|
$page['sslLink'] = get_app_location(true, true) . "/operator/agent.php?thread=" . $thread->id . "&token=" . $thread->lastToken;
|
2009-03-08 23:53:16 +03:00
|
|
|
}
|
2008-09-30 02:35:08 +04:00
|
|
|
$page['isOpera95'] = is_agent_opera95();
|
|
|
|
$page['neediframesrc'] = needsFramesrc();
|
2012-09-28 18:46:42 +04:00
|
|
|
$page['historyParams'] = array("userid" => "" . $thread->userId);
|
2011-02-26 17:04:12 +03:00
|
|
|
$page['historyParamsLink'] = add_params($webimroot . "/operator/userhistory.php", $page['historyParams']);
|
2012-07-16 18:26:53 +04:00
|
|
|
if (Settings::get('enabletracking')) {
|
2012-09-28 18:46:42 +04:00
|
|
|
$visitor = track_get_visitor_by_threadid($thread->id);
|
2011-04-07 12:34:04 +04:00
|
|
|
$page['trackedParams'] = array("visitor" => "" . $visitor['visitorid']);
|
|
|
|
$page['trackedParamsLink'] = add_params($webimroot . "/operator/tracked.php", $page['trackedParams']);
|
|
|
|
}
|
2012-09-28 18:46:42 +04:00
|
|
|
$canned_messages = load_canned_messages($thread->locale, 0);
|
|
|
|
if ($thread->groupId) {
|
2012-01-26 20:00:30 +04:00
|
|
|
$canned_messages = array_merge(
|
2012-09-28 18:46:42 +04:00
|
|
|
load_canned_messages($thread->locale, $thread->groupId),
|
2012-01-26 20:00:30 +04:00
|
|
|
$canned_messages
|
|
|
|
);
|
|
|
|
};
|
2012-12-27 18:07:11 +04:00
|
|
|
|
|
|
|
// Get predefined answers
|
|
|
|
$predefined_answers = array();
|
2011-02-26 17:04:12 +03:00
|
|
|
foreach ($canned_messages as $answer) {
|
2012-12-27 18:07:11 +04:00
|
|
|
$predefined_answers[] = array(
|
|
|
|
'short' => htmlspecialchars(
|
|
|
|
topage($answer['vctitle']?$answer['vctitle']:cutstring($answer['vcvalue'], 97, '...'))
|
|
|
|
),
|
|
|
|
'full' => myiconv($webim_encoding, getoutputenc(), $answer['vcvalue'])
|
|
|
|
);
|
2008-10-11 04:06:15 +04:00
|
|
|
}
|
2012-12-27 18:07:11 +04:00
|
|
|
$page['predefinedAnswers'] = json_encode($predefined_answers);
|
|
|
|
|
2012-09-28 18:46:42 +04:00
|
|
|
$params = "thread=" . $thread->id . "&token=" . $thread->lastToken;
|
2011-02-26 17:04:12 +03:00
|
|
|
$page['redirectLink'] = "$webimroot/operator/agent.php?" . $params . "&act=redirect";
|
2008-10-02 13:43:58 +04:00
|
|
|
|
2008-09-30 02:35:08 +04:00
|
|
|
$page['namePostfix'] = "";
|
2012-07-16 18:26:53 +04:00
|
|
|
$page['frequency'] = Settings::get('updatefrequency_chat');
|
2013-01-24 16:36:36 +04:00
|
|
|
|
|
|
|
// Load dialogs style options
|
|
|
|
$style_config = get_dialogs_style_config(getchatstyle());
|
|
|
|
$page['chatStyles.chatWindowParams'] = $style_config['chat']['window_params'];
|
|
|
|
$page['chatStyles.mailWindowParams'] = $style_config['mail']['window_params'];
|
|
|
|
|
|
|
|
// Load core style options
|
|
|
|
$style_config = get_core_style_config();
|
|
|
|
$page['coreStyles.historyWindowParams'] = $style_config['history']['window_params'];
|
2008-09-30 02:35:08 +04:00
|
|
|
}
|
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
function ban_for_addr($addr)
|
2011-02-26 17:04:12 +03:00
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
$db = Database::getInstance();
|
|
|
|
return $db->query(
|
|
|
|
"select banid,comment from {chatban} " .
|
2012-09-05 16:46:15 +04:00
|
|
|
"where dtmtill > :now AND address = :addr",
|
|
|
|
array(
|
|
|
|
':addr' => $addr,
|
|
|
|
':now' => time()
|
|
|
|
),
|
2012-07-13 16:56:50 +04:00
|
|
|
array('return_rows' => Database::RETURN_ONE_ROW)
|
|
|
|
);
|
2008-05-11 02:35:16 +04:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function visitor_from_request()
|
|
|
|
{
|
2009-03-08 23:53:16 +03:00
|
|
|
global $namecookie, $webim_encoding, $usercookie;
|
|
|
|
$defaultName = getstring("chat.default.username");
|
|
|
|
$userName = $defaultName;
|
2011-02-26 17:04:12 +03:00
|
|
|
if (isset($_COOKIE[$namecookie])) {
|
|
|
|
$data = base64_decode(strtr($_COOKIE[$namecookie], '-_,', '+/='));
|
|
|
|
if (strlen($data) > 0) {
|
|
|
|
$userName = myiconv("utf-8", $webim_encoding, $data);
|
2008-05-12 13:23:16 +04:00
|
|
|
}
|
2009-03-08 23:53:16 +03:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
if ($userName == $defaultName) {
|
2009-03-08 23:53:16 +03:00
|
|
|
$userName = getgetparam('name', $userName);
|
2008-05-12 13:23:16 +04:00
|
|
|
}
|
2007-10-10 19:15:47 +04:00
|
|
|
|
2008-10-03 19:11:02 +04:00
|
|
|
if (isset($_COOKIE[$usercookie])) {
|
|
|
|
$userId = $_COOKIE[$usercookie];
|
|
|
|
} else {
|
|
|
|
$userId = get_user_id();
|
2011-02-26 17:04:12 +03:00
|
|
|
setcookie($usercookie, $userId, time() + 60 * 60 * 24 * 365);
|
2008-10-03 19:11:02 +04:00
|
|
|
}
|
2011-02-26 17:04:12 +03:00
|
|
|
return array('id' => $userId, 'name' => $userName);
|
2007-10-10 19:15:47 +04:00
|
|
|
}
|
|
|
|
|
2011-02-26 17:04:12 +03:00
|
|
|
function get_remote_host()
|
|
|
|
{
|
2009-08-08 02:49:11 +04:00
|
|
|
$extAddr = $_SERVER['REMOTE_ADDR'];
|
|
|
|
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
|
2011-02-26 17:04:12 +03:00
|
|
|
$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
|
|
|
|
$extAddr = $_SERVER['REMOTE_ADDR'] . ' (' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ')';
|
2009-08-08 02:49:11 +04:00
|
|
|
}
|
|
|
|
return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
|
|
|
|
}
|
|
|
|
|
2013-03-13 01:03:50 +04:00
|
|
|
?>
|