Esempio n. 1
0
/**
 * Prepare some data for chat for operator
 *
 * @param UrlGeneratorInterface $url_generator A URL generator object.
 * @param Request $request The current request.
 * @param Thread $thread thread object.
 * @param array $operator Operator's data.
 * @return array Array of chat view data
 */
function setup_chatview_for_operator(UrlGeneratorInterface $url_generator, Request $request, Thread $thread, $operator)
{
    $data = setup_chatview($thread);
    // Set operator info
    $data['chat']['user'] = array('name' => htmlspecialchars(get_user_name($thread->userName, $thread->remote, $thread->userId)), 'canPost' => (bool) ($thread->agentId == $operator['operatorid']), 'isAgent' => true);
    // Set SSL link
    if (Settings::get('enablessl') == "1" && !$request->isSecure()) {
        $data['chat']['links']['ssl'] = $url_generator->generateSecure('chat_operator', array('thread_id' => $thread->id, 'token' => $thread->lastToken), UrlGeneratorInterface::ABSOLUTE_URL);
    }
    // Set chat link
    $data['chat']['links']['chat'] = $url_generator->generate('chat_operator', array('thread_id' => $thread->id, 'token' => $thread->lastToken), UrlGeneratorInterface::ABSOLUTE_URL);
    // Set history window params
    $data['chat']['links']['history'] = $url_generator->generate('history_user', array('user_id' => $thread->userId));
    // Set tracking params
    if (Settings::get('enabletracking')) {
        $visitor = track_get_visitor_by_thread_id($thread->id);
        $data['chat']['links']['tracked'] = $url_generator->generate('history_user_track', array('visitor' => $visitor['visitorid']));
    }
    // Check if agent can post messages
    if ($thread->agentId == $operator['operatorid']) {
        // Get predefined answers
        $canned_messages = load_canned_messages($thread->locale, 0);
        if ($thread->groupId) {
            $canned_messages = array_merge(load_canned_messages($thread->locale, $thread->groupId), $canned_messages);
        }
        $predefined_answers = array();
        foreach ($canned_messages as $answer) {
            $predefined_answers[] = array('short' => htmlspecialchars($answer['vctitle'] ? $answer['vctitle'] : cut_string($answer['vcvalue'], 97, '...')), 'full' => $answer['vcvalue']);
        }
        $data['chat']['messageForm']['predefinedAnswers'] = $predefined_answers;
    }
    // Set link to user redirection page
    $data['chat']['links']['redirect'] = $url_generator->generate('chat_operator_redirection_links', array('thread_id' => $thread->id, 'token' => $thread->lastToken));
    return $data;
}
 /**
  * Generates a page with user tracking information.
  *
  * @param Request $request
  * @return string Rendered page content
  */
 public function userTrackAction(Request $request)
 {
     if (Settings::get('enabletracking') == '0') {
         throw new BadRequestException('Tracking is disabled.');
     }
     if ($request->query->has('thread')) {
         $thread_id = $request->query->get('thread');
         if (!preg_match("/^\\d{1,8}\$/", $thread_id)) {
             throw new BadRequestException('Wrong thread ID.');
         }
         $visitor = track_get_visitor_by_thread_id($thread_id);
         if (!$visitor) {
             throw new BadRequestException('Wrong thread.');
         }
     } else {
         $visitor_id = $request->query->get('visitor');
         if (!preg_match("/^\\d{1,8}\$/", $visitor_id)) {
             throw new BadRequestException('Wrong visitor ID.');
         }
         $visitor = track_get_visitor_by_id($visitor_id);
         if (!$visitor) {
             throw new BadRequestException('Wrong visitor.');
         }
     }
     $path = track_get_path($visitor);
     $page['entry'] = htmlspecialchars($visitor['entry']);
     $page['history'] = array();
     ksort($path);
     foreach ($path as $k => $v) {
         $page['history'][] = array('date' => date_to_text($k), 'link' => htmlspecialchars($v));
     }
     $page['title'] = getlocal('Tracked path of visitor');
     $page['show_small_login'] = false;
     return $this->render('tracked', $page);
 }