Ejemplo n.º 1
0
 /**
  * Generates list of available canned messages.
  *
  * @param Request $request
  * @return string Rendered page content
  */
 public function indexAction(Request $request)
 {
     $operator = $this->getOperator();
     $page = array('errors' => array());
     // Build list of available locales
     $all_locales = get_available_locales();
     $locales_with_label = array();
     foreach ($all_locales as $id) {
         $locale_info = get_locale_info($id);
         $locales_with_label[] = array('id' => $id, 'name' => $locale_info ? $locale_info['name'] : $id);
     }
     $page['locales'] = $locales_with_label;
     // Get selected locale, if any.
     $lang = $this->extractLocale($request);
     if (!$lang) {
         $lang = in_array(get_current_locale(), $all_locales) ? get_current_locale() : $all_locales[0];
     }
     // Get selected group ID, if any.
     $group_id = $this->extractGroupId($request);
     if ($group_id) {
         $group = group_by_id($group_id);
         if (!$group) {
             $page['errors'][] = getlocal('No such group');
             $group_id = false;
         }
     }
     // Build list of available groups
     $all_groups = in_isolation($operator) ? get_groups_for_operator($operator) : get_all_groups();
     $page['groups'] = array();
     $page['groups'][] = array('groupid' => '', 'vclocalname' => getlocal('-all operators-'), 'level' => 0);
     foreach ($all_groups as $g) {
         $page['groups'][] = $g;
     }
     // Get messages and setup pagination
     $canned_messages = load_canned_messages($lang, $group_id);
     foreach ($canned_messages as &$message) {
         $message['vctitle'] = $message['vctitle'];
         $message['vcvalue'] = $message['vcvalue'];
     }
     unset($message);
     $pagination = setup_pagination($canned_messages);
     $page['pagination'] = $pagination['info'];
     $page['pagination.items'] = $pagination['items'];
     // Buil form values
     $page['formlang'] = $lang;
     $page['formgroup'] = $group_id;
     // Set other needed page values and render the response
     $page['title'] = getlocal('Canned Messages');
     $page['menuid'] = 'canned';
     $page = array_merge($page, prepare_menu($operator));
     return $this->render('canned_messages', $page);
 }
Ejemplo n.º 2
0
/**
 * Import canned messages from a YAML file.
 *
 * @param string $locale Locale code.
 * @param string $file Full path to the file that should be imported.
 */
function import_canned_messages($locale, $file)
{
    // Get new canned messages that should be imported.
    $parser = new YamlParser();
    $new_messages = $parser->parse(file_get_contents($file));
    if (empty($new_messages)) {
        // Nothing to import.
        return;
    }
    // Get list of existing canned messages for specified locale an key it by
    // message value.
    $loaded_messages = load_canned_messages($locale, false);
    $existing_messages = array();
    if (!empty($loaded_messages)) {
        foreach ($loaded_messages as $message) {
            $existing_messages[$message['vcvalue']] = $message;
        }
    }
    // Save only new messages to avoid duplication
    foreach ($new_messages as $message) {
        if (array_key_exists($message, $existing_messages)) {
            continue;
        }
        add_canned_message($locale, null, cut_string($message, 97, '...'), $message);
    }
}
Ejemplo n.º 3
0
function setup_chatview_for_operator($thread, $operator)
{
    global $page, $webimroot, $company_logo_link, $company_name, $settings;
    loadsettings();
    $page = array();
    $page['agent'] = true;
    $page['user'] = false;
    $page['canpost'] = $thread['agentId'] == $operator['operatorid'];
    $page['ct.chatThreadId'] = $thread['threadid'];
    $page['ct.token'] = $thread['ltoken'];
    $page['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread['userName'], $thread['remote'], $thread['userid'])));
    $page['chat.title'] = topage($settings['chattitle']);
    setup_logo();
    if ($settings['sendmessagekey'] == 'enter') {
        $page['send_shortcut'] = "Enter";
        $page['ignorectrl'] = 1;
    } else {
        $page['send_shortcut'] = is_mac_opera() ? "⌘-Enter" : "Ctrl-Enter";
        $page['ignorectrl'] = 0;
    }
    if ($settings['enablessl'] == "1" && !is_secure_request()) {
        $page['sslLink'] = get_app_location(true, true) . "/operator/agent.php?thread=" . $thread['threadid'] . "&token=" . $thread['ltoken'];
    }
    $page['isOpera95'] = is_agent_opera95();
    $page['neediframesrc'] = needsFramesrc();
    $page['historyParams'] = array("userid" => "" . $thread['userid']);
    $page['historyParamsLink'] = add_params($webimroot . "/operator/userhistory.php", $page['historyParams']);
    $predefinedres = "";
    $canned_messages = load_canned_messages($thread['locale'], $thread['groupid']);
    foreach ($canned_messages as $answer) {
        $predefinedres .= "<option>" . htmlspecialchars(topage($answer['vcvalue'])) . "</option>";
    }
    $page['predefinedAnswers'] = $predefinedres;
    $params = "thread=" . $thread['threadid'] . "&amp;token=" . $thread['ltoken'];
    $page['redirectLink'] = "{$webimroot}/operator/agent.php?" . $params . "&amp;act=redirect";
    $page['namePostfix'] = "";
    $page['frequency'] = $settings['updatefrequency_chat'];
}
Ejemplo n.º 4
0
    $allgroups = get_all_groups($link);
    mysql_close($link);
    $page['groups'] = array();
    $page['groups'][] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"));
    foreach ($allgroups as $g) {
        $page['groups'][] = $g;
    }
}
# delete
if (isset($_GET['act']) && $_GET['act'] == 'delete') {
    $key = isset($_GET['key']) ? $_GET['key'] : "";
    if (!preg_match("/^\\d+\$/", $key)) {
        $errors[] = "Wrong key";
    }
    if (count($errors) == 0) {
        $link = connect();
        perform_query("delete from {$mysqlprefix}chatresponses where id = {$key}", $link);
        mysql_close($link);
        header("Location: {$webimroot}/operator/canned.php?lang={$lang}&group={$groupid}");
        exit;
    }
}
# get messages
$messages = load_canned_messages($lang, $groupid);
setup_pagination($messages);
# form values
$page['formlang'] = $lang;
$page['formgroup'] = $groupid;
prepare_menu($operator);
start_html_output();
require '../view/canned.php';
Ejemplo n.º 5
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;
}