function updateCurrentOrCreateSession() { $session = $this->getCurrentSession(); $visitorInfo = GetVisitorFromRequestAndSetCookie(); $fl_login = isset($_SESSION['login']) ? $_SESSION['login'] : ''; if (empty($session)) { $ip = Browser::GetExtAddr(); $remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : null; $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; $userid = null; $sessionId = $this->createVisitSession($ip, $remoteHost, $useragent, $userid, $visitorInfo['id'], $visitorInfo['name'], $fl_login, $visitorInfo['partnerref']); } else { $sessionId = is_array($session) ? $session['visitsessionid'] : $session; $this->UpdateVisitSession($sessionId, array('fl_login' => $fl_login, 'visitorname' => $visitorInfo['name'])); } VisitedPage::GetInstance()->addOrUpdateFromSession($sessionId); $_SESSION['WEBIM_VISIT_SESSION_ID'] = $sessionId; return $sessionId; }
function tryToGetExistingThread() { $threadid = verify_param('thread', "/^\\d{1,8}\$/", ''); $thread = null; if (empty($threadid)) { $visitor = GetVisitorFromRequestAndSetCookie(); $thread = MapperFactory::getMapper('Thread')->getActiveThreadForVisitor($visitor['id']); } else { $thread = Thread::getInstance()->GetThreadById($threadid); $token = verify_param('token', "/^\\d{1,8}\$/"); if ($token != $thread['token'] || $thread['state'] == STATE_CLOSED) { $thread = null; } } if (!empty($thread) && (visitorHasAccess($thread) || empty($threadid))) { ThreadProcessor::getInstance()->ProcessThread($thread['threadid'], 'ping_visitor'); $thread = Thread::getInstance()->GetThreadById($thread['threadid']); if (empty($thread) || $thread['state'] == STATE_CLOSED) { $thread = null; } } else { $thread = null; } return $thread; }
function visitorHasAccess($thread) { if ($thread == null) { return false; } $visitor = GetVisitorFromRequestAndSetCookie(); $visitSession = VisitSession::GetInstance()->GetVisitSessionById($thread['visitsessionid']); $token = isset($_REQUEST['token']) ? $_REQUEST['token'] : null; $res = $thread['token'] == $token && $visitSession['visitorid'] == $visitor['id']; return $res; }
function PrintThreadMessages($thread, $token, $lastid, $isvisitor, $format, $viewonly = false) { $threadid = $thread['threadid']; $istyping = abs($thread['current'] - $thread[$isvisitor ? "lpoperator" : "lpvisitor"]) < WEBIM_CONNECTION_TIMEOUT && $thread[$isvisitor ? "agenttyping" : "visitortyping"] == "1" ? "1" : "0"; $israted = empty($thread['ratedoperatorid']) ? 'false' : 'true'; $visitSession = $isvisitor ? GetVisitorFromRequestAndSetCookie() : MapperFactory::getMapper("VisitSession")->getById($thread['visitsessionid']); $visitorname = $isvisitor ? removeSpecialSymbols($visitSession['name']) : removeSpecialSymbols(htmlspecialchars($visitSession['visitorname'])); $rate = $thread['rate']; if ($format == "xml") { $visitorname = "visitorname=\"{$visitorname}\""; $operatorfullname = "operatorfullname=\"" . $thread['operatorfullname'] . "\""; $fl_login = "******"" . ($isvisitor || empty($visitSession['fl_login']) ? '' : $visitSession['fl_login']) . "\""; $threadstate = "state=\"" . $thread['state'] . "\""; $isHasMessages = true; if ($lastid != 0 && !$viewonly) { $isHasMessages = $isvisitor ? $this->isHasMessagesForVisitor($thread['threadid']) : $this->isHasMessagesForOperator($thread['threadid']); } $haveMessegesToAlert = "needtoalert=\"" . ($isHasMessages ? "true" : "false") . "\""; $output = array(); if ($isHasMessages) { $output = $this->GetMessages($threadid, "xml", $isvisitor, $lastid); if ($thread['state'] !== STATE_CLOSED) { if ($isvisitor) { $this->unsetThreadHasMessagesForVisitor($thread['threadid']); } else { if (!$viewonly) { $this->unsetThreadHasMessagesForOperator($thread['threadid']); } } } } Browser::SendXmlHeaders(); print "<thread lastid=\"{$lastid}\" typing=\"" . $istyping . "\" viewonly=\"" . $viewonly . "\" {$visitorname} {$operatorfullname} {$fl_login} {$haveMessegesToAlert} {$threadstate} israted=\"{$israted}\" rate=\"{$rate}\">"; foreach ($output as $msg) { if (!$isvisitor && strpos($msg, "webimFeedbackBtn") !== false) { continue; } print $msg; } print "</thread>"; } elseif ($format == "html") { $output = $this->GetMessages($threadid, "html", $isvisitor, $lastid); Browser::SendHtmlHeaders(); $url = WEBIM_ROOT . "/thread.php?act=refresh&thread=" . $threadid . "&token=" . $token . "&html=on&visitor=" . ($isvisitor ? "true" : "false"); print "<html><head>\n" . "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"" . WEBIM_ROOT . "/css/admin_chat.css?" . WEBIM_VERSION . "\" />\n" . "<meta http-equiv=\"Refresh\" content=\"7; URL={$url}&sn=11\">\n" . "<meta http-equiv=\"Pragma\" content=\"no-cache\">\n" . "</head>" . "<body bgcolor='#FFFFFF' text='#000000' link='#C28400' vlink='#C28400' alink='#C28400' marginwidth='0' marginheight='0' leftmargin='0' rightmargin='0' topmargin='0' bottommargin='0' onload=\"if (location.hash != '#aend') {location.hash='#aend';}\">" . "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td valign='top' class='message'>"; foreach ($output as $msg) { if (!$isvisitor && strpos($msg, "webimFeedbackBtn") !== false) { continue; } print $msg; } print "</td></tr></table><a name='aend'>" . "</body></html>"; } }
require_once 'classes/functions.php'; require_once 'classes/class.thread.php'; require_once 'classes/class.smartyclass.php'; require_once 'classes/class.settings.php'; require_once 'classes/class.visitor.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stdf.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/captcha.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/feedback.php'; $captcha = new captcha(); $TML = new SmartyClass(); $TML->assignCompanyInfoAndTheme(); $errors = array(); $page = array(); $department = (int) $_REQUEST["department_db_id"]; $canChangeName = Visitor::getInstance()->canVisitorChangeName(); $v = GetVisitorFromRequestAndSetCookie(); $visitorid = $v['id']; $captcha_num = $v['captcha']; $message = get_mandatory_param('message'); $has_errors = false; if (count($_POST) == 0 && count($_FILES) == 0) { //костыль. при отправке на сервер большого файла приходит пустой request и files, как по длругому определить, пока не придумал $has_errors = true; $errors[0] = 6; $errors[1] = iconv("UTF-8", "WINDOWS-1251//IGNORE", "Файл очень велик"); } elseif (!$captcha->checkNumber($captcha_num)) { $has_errors = true; $errors[0] = 5; $errors[1] = iconv("UTF-8", "WINDOWS-1251//IGNORE", "Неверно введен текст"); } elseif (empty($message) || $message == '') { $has_errors = true;