예제 #1
0
 * 
 * Все права защищены. (c) 2005-2009 ООО "ТОП".
 * Данное программное обеспечение и все сопутствующие материалы
 * предоставляются на условиях лицензии, доступной по адресу
 * http://webim.ru/license.html
 * 
 */
require_once '../classes/functions.php';
require_once '../classes/class.thread.php';
require_once '../classes/class.operator.php';
require_once '../classes/class.visitsession.php';
require_once '../classes/class.visitedpage.php';
require_once '../classes/class.invitation.php';
$operator = Operator::getInstance()->GetLoggedOperator();
$pageId = verify_param('pageid', '/^([a-z0-9]{32})?$/', '');
if (empty($pageId)) {
    die('invalid or absent pageid');
}
$visitSession = VisitSession::GetInstance()->GetVisitSessionByPageId($pageId);
$remoteLevel = Browser::GetRemoteLevel($visitSession['useragent']);
$thread = VisitedPage::GetInstance()->GetInvitationThread($pageId);
if (empty($thread) || $thread['state'] == STATE_CLOSED) {
    $thread = Thread::getInstance()->CreateThread(WEBIM_CURRENT_LOCALE, STATE_INVITE, array('operatorfullname' => $operator['fullname'], 'operatorid' => $operator['operatorid'], 'visitsessionid' => $visitSession['visitsessionid']));
    VisitSession::GetInstance()->UpdateVisitSession($visitSession['visitsessionid'], array('hasthread' => 1));
    $introMessage = Resources::Get('invite.intro.message', array($visitSession['visitorname']), WEBIM_CURRENT_LOCALE);
    Thread::getInstance()->PostMessage($thread['threadid'], KIND_FOR_AGENT, $introMessage);
    $invitationId = Invitation::getInstance()->CreateInvitation($thread['threadid']);
    VisitedPage::GetInstance()->UpdateVisitedPage($pageId, array('invitationid' => $invitationId));
}
header('Location: ' . WEBIM_ROOT . '/operator/agent.php?thread=' . $thread['threadid'] . '&token=' . $thread['token'] . '&level=' . $remoteLevel . '&force=false');
exit;
예제 #2
0
function sendLocation($thread)
{
    $threadid = $thread['threadid'];
    $token = $thread['token'];
    $level = Browser::GetRemoteLevel($_SERVER['HTTP_USER_AGENT']);
    $departmentkey = verify_param('deparmentkey', "/^\\w+\$/");
    $departmentParam = !empty($departmentkey) ? '&deparmentkey=' . $departmentkey : '';
    $url = WEBIM_ROOT . "/client.php?thread={$threadid}&token={$token}&level={$level}" . $departmentParam . getParametersToPassThru();
    header('Location: ' . $url);
    exit;
}
예제 #3
0
function handleWithoutToken($threadid, $viewonly)
{
    $TML = new SmartyClass();
    $operator = Operator::getInstance()->GetLoggedOperator();
    $remote_level = Browser::GetRemoteLevel($_SERVER['HTTP_USER_AGENT']);
    if ($remote_level != "ajaxed") {
        die("old browser is used, please update it");
    }
    $thread = Thread::getInstance()->GetThreadById($threadid);
    if (!$thread || !isset($thread['token'])) {
        die("wrong thread");
    }
    if ($viewonly && $operator['operatorid'] != $thread['operatorid']) {
        redirectToPageWithToken($thread, $viewonly, $remote_level);
    }
    $forcetake = verify_param("force", "/^true\$/", false);
    if ($forcetake) {
        ThreadProcessor::getInstance()->ProcessThread($thread['threadid'], 'operator_force_join', array("operatorid" => $operator["operatorid"]));
        redirectToPageWithToken($thread, null, $remote_level);
    } else {
        // is taken by another
        $visitSession = VisitSession::GetInstance()->GetVisitSessionById($thread['visitsessionid']);
        if ($thread['state'] != STATE_CLOSED && !empty($thread['operatorid']) && $operator['operatorid'] != $thread['operatorid'] && $operator['operatorid'] != $thread['nextoperatorid']) {
            $page = array('visitor' => $visitSession['visitorname'], 'agent' => $thread['operatorfullname'], 'force' => true, 'takelink' => $_SERVER['PHP_SELF'] . "?thread={$threadid}&force=true", 'viewlink' => $_SERVER['PHP_SELF'] . "?thread={$threadid}&viewonly=true", 'priority' => $thread['state'] == STATE_QUEUE_EXACT_OPERATOR || $thread['state'] == STATE_CHATTING_OPERATOR_BROWSER_CLOSED_REFRESHED);
            // TODO get rid of STATE_WAIT_ANOTHER_OPERATOR
            $TML->assign('link_arguments', "&thread={$threadid}");
            $TML->assign('page', $page);
            $TML->display('confirm.tpl');
            exit;
        }
        // is closed
        if ($thread['state'] == STATE_CLOSED) {
            $page = array('viewlink' => $_SERVER['PHP_SELF'] . "?thread=" . $threadid . "&viewonly=true", 'force' => false, 'thread_id' => $threadid, 'closed' => true);
            $TML->assign('link_arguments', "&thread={$threadid}");
            $TML->assign('page', $page);
            $TML->display('confirm.tpl');
            exit;
        }
    }
    ThreadProcessor::getInstance()->ProcessThread($thread['threadid'], 'operator_join', array('operatorid' => $operator['operatorid']));
    redirectToPageWithToken($thread, $viewonly, $remote_level);
}