/** * Processes submitting of the form which is generated in * {@link \Mibew\Controller\Operator\GroupsController::showFormAction()} * method. * * @param Request $request Incoming request. * @return string Rendered page content. * @throws NotFoundException If the operator with specified ID is not found * in the system. */ public function submitFormAction(Request $request) { csrf_check_token($request); $operator = $this->getOperator(); $operator_in_isolation = in_isolation($operator); $op_id = $request->attributes->getInt('operator_id'); // Check if the target operator exists $op = operator_by_id($op_id); if (!$op) { throw new NotFoundException('The operator is not found.'); } // Get all groups that are available for the target operator. $groups = $operator_in_isolation ? get_groups_for_operator($operator) : get_all_groups(); // Build list of operator's new groups. $new_groups = array(); foreach ($groups as $group) { if ($request->request->get('group' . $group['groupid']) == 'on') { $new_groups[] = $group['groupid']; } } // Update operator's group and redirect the current operator to the same // page using GET method. update_operator_groups($op['operatorid'], $new_groups); $redirect_to = $this->generateUrl('operator_groups', array('operator_id' => $op_id, 'stored' => true)); return $this->redirect($redirect_to); }
/** * 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); }
/** * Generates list of all operators in the system. * * @param Request $request Incoming request. * @return string Rendered page content. */ public function indexAction(Request $request) { $operator = $this->getOperator(); $page = array('errors' => $request->attributes->get('errors', array())); $sort['by'] = $request->query->get('sortby'); if (!in_array($sort['by'], array('login', 'commonname', 'localename', 'lastseen'))) { $sort['by'] = 'login'; } $sort['desc'] = $request->query->get('sortdirection', 'desc') == 'desc'; $page['formsortby'] = $sort['by']; $page['formsortdirection'] = $sort['desc'] ? 'desc' : 'asc'; $list_options['sort'] = $sort; if (in_isolation($operator)) { $list_options['isolated_operator_id'] = $operator['operatorid']; } $operators_list = get_operators_list($list_options); // Prepare operator to render in template foreach ($operators_list as &$item) { $item['vclogin'] = $item['vclogin']; $item['vclocalename'] = $item['vclocalename']; $item['vccommonname'] = $item['vccommonname']; $item['isAvailable'] = operator_is_available($item); $item['isAway'] = operator_is_away($item); $item['lastTimeOnline'] = time() - $item['time']; $item['isDisabled'] = operator_is_disabled($item); } unset($item); $page['allowedAgents'] = $operators_list; $page['canmodify'] = is_capable(CAN_ADMINISTRATE, $operator); $page['availableOrders'] = array(array('id' => 'login', 'name' => getlocal('Login')), array('id' => 'localename', 'name' => getlocal('Name')), array('id' => 'commonname', 'name' => getlocal('International name')), array('id' => 'lastseen', 'name' => getlocal('Last active'))); $page['availableDirections'] = array(array('id' => 'desc', 'name' => getlocal('descending')), array('id' => 'asc', 'name' => getlocal('ascending'))); $page['title'] = getlocal('Operators'); $page['menuid'] = 'operators'; $page = array_merge($page, prepare_menu($operator)); $this->getAssetManager()->attachJs('js/compiled/operators.js'); return $this->render('operators', $page); }
function setup_redirect_links(UrlGeneratorInterface $url_generator, $threadid, $operator, $token) { $result = array(); $operator_in_isolation = in_isolation($operator); $list_options = $operator_in_isolation ? array('isolated_operator_id' => $operator['operatorid']) : array(); $operators = get_operators_list($list_options); $operators_count = count($operators); $groups_count = 0; $groups = array(); if (Settings::get('enablegroups') == "1") { $groupslist = $operator_in_isolation ? get_groups_for_operator($operator, true) : get_groups(true); foreach ($groupslist as $group) { if ($group['inumofagents'] == 0) { continue; } $groups[] = $group; } $groups_count = count($groups); } $p = pagination_info(max($operators_count, $groups_count), 8); $result['pagination'] = $p; $operators = array_slice($operators, $p['start'], $p['end'] - $p['start']); $groups = array_slice($groups, $p['start'], $p['end'] - $p['start']); $agent_list = ""; $params = array('thread_id' => $threadid, 'token' => $token); foreach ($operators as $agent) { $params['nextAgent'] = $agent['operatorid']; $status = $agent['time'] < Settings::get('online_timeout') ? ($agent['istatus'] == 0 ? getlocal("(online)") : getlocal("(away)")) : ""; $agent_list .= "<li><a href=\"" . $url_generator->generate('chat_operator_redirect', $params) . "\" title=\"" . get_operator_name($agent) . "\">" . get_operator_name($agent) . "</a> $status</li>"; } $result['redirectToAgent'] = $agent_list; $group_list = ""; if (Settings::get('enablegroups') == "1") { $params = array('thread_id' => $threadid, 'token' => $token); foreach ($groups as $group) { $params['nextGroup'] = $group['groupid']; $status = group_is_online($group) ? getlocal("(online)") : (group_is_away($group) ? getlocal("(away)") : ""); $group_list .= "<li><a href=\"" . $url_generator->generate('chat_operator_redirect', $params) . "\" title=\"" . get_group_name($group) . "\">" . get_group_name($group) . "</a> $status</li>"; } } $result['redirectToGroup'] = $group_list; return $result; }
/** * Builds access condition for history select query. * * @param array $operator List of operator's fields. * @return array Associative array with the following keys: * - "condition": string, additional condition that should be used in SQL * query's where clause. * - "values": array, list of additional values for placeholders. */ protected function buildAccessCondition($operator) { // Administrators can view anything if (is_capable(CAN_ADMINISTRATE, $operator)) { return array('condition' => '', 'values' => array()); } // Operators without "view threads" permission can view only their // own history. if (!is_capable(CAN_VIEWTHREADS, $operator)) { return array('condition' => ' AND {thread}.agentid = :operator_id ', 'values' => array(':operator_id' => $operator['operatorid'])); } // Operators who have "view threads" permission can be in isolation. if (in_isolation($operator)) { // This is not the best way of getting operators from adjacent // groups, but it's the only way that does not break encapsulation // of operators storage. $operators = get_operators_list(array('isolated_operator_id' => $operator['operatorid'])); $operators_placeholders = array(); $counter = 0; foreach ($operators as $op) { $operators_placeholders[':_access_op_' . $counter] = $op['operatorid']; $counter++; } $operators_in_statement = implode(', ', array_keys($operators_placeholders)); // Also the operator can view threads for the groups he belongs too. // These threads include ones that had no related operator but were // started for a specified group. $groups = get_all_groups_for_operator($operator); $groups_placeholders = array(); $counter = 0; foreach ($groups as $group) { $groups_placeholders[':_access_grp_' . $counter] = $group['groupid']; $counter++; } $groups_in_statement = implode(', ', array_keys($groups_placeholders)); return array('condition' => ' AND (' . '{thread}.agentid IN (' . $operators_in_statement . ') ' . 'OR {thread}.groupid IN (' . $groups_in_statement . ')' . ') ', 'values' => $operators_placeholders + $groups_placeholders); } // It seems that the operator can view anything. return array('condition' => '', 'values' => array()); }
/** * Return updated operators list. API function * * @param array $args Associative array of arguments. It must contains the * following keys: * - 'agentId': Id of the agent related to users window * * @return array Array of results. It contains the following keys: * - 'operators': array of online operators */ protected function apiUpdateOperators($args) { // Check access and get operators info $operator = $this->checkOperator($args['agentId']); // Return empty array if show operators option disabled if (Settings::get('showonlineoperators') != '1') { return array('operators' => array()); } // Check if curent operator is in isolation $list_options = in_isolation($operator) ? array('isolated_operator_id' => $operator['operatorid']) : array(); // Get operators list $operators = get_operators_list($list_options); // Create resulting list of operators $result_list = array(); foreach ($operators as $item) { if (!operator_is_online($item)) { continue; } $result_list[] = array('id' => (int) $item['operatorid'], 'name' => htmlspecialchars($item['vclocalename']), 'away' => (bool) operator_is_away($item)); } // Send operators list to the client side return array('operators' => $result_list); }