/** * Processes submitting of the form which is generated in * {@link \Mibew\Controller\GroupController::showMembersFormAction()} method. * * @param Request $request Incoming request. * @return string Rendered page content. * @throws NotFoundException If the operator's group with specified ID is * not found in the system. */ public function submitFormAction(Request $request) { csrf_check_token($request); $operators = get_operators_list(); $group_id = $request->attributes->getInt('group_id'); $group = group_by_id($group_id); // Check if specified group exists if (!$group) { throw new NotFoundException('The group is not found.'); } // Update members list $new_members = array(); foreach ($operators as $op) { if ($request->request->get('op' . $op['operatorid']) == 'on') { $new_members[] = $op['operatorid']; } } update_group_members($group_id, $new_members); // Redirect opeartor to group members page. $parameters = array('group_id' => $group_id, 'stored' => true); return $this->redirect($this->generateUrl('group_members', $parameters)); }
/** * 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; }
$tmlPage['formendday'] = date('d', $currTime); $tmlPage['formendmonth'] = date('m.y', $currTime); } } // // This function should be defined before it's used otherwise on // some PHP verions it can fail with Fatal error: Call to undefined function // function get_operators_list() { $operators = Operator::getInstance()->GetAllAccessedOperators(); $result = array(); $result[''] = Resources::Get('search.any.operator'); if (!empty($operators)) { foreach ($operators as $op) { $result[$op['operatorid']] = $op['fullname']; } } return $result; } $tmlPage['availableDays'] = range(1, 31); $currTime = getCurrentTime(); $tmlPage['availableMonth'] = get_month_selection($currTime - 400 * 24 * 60 * 60, $currTime); $tmlPage['operatorList'] = get_operators_list(); $TML->assign('departments', Operator::getInstance()->enumAvailableDepartmentsForOperator($operator['operatorid'], Resources::getCurrentLocale())); $TML->assign('locales', getAvailableLocalesForChat()); $tmlPage['show_empty'] = $show_empty; $TML->assign('page_settings', $tmlPage); $TML->assign('advanced', true); $TML->display('thread_search.tpl'); require_once dirname(__FILE__) . '/inc/admin_epilog.php';
/** * 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()); }
function get_operators_from_adjacent_groups($operator) { return get_operators_list(array('isolated_operator_id' => $operator['operatorid'])); }
/** * 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); }