mirror of
				https://github.com/Mibew/tray.git
				synced 2025-10-03 00:03:34 +03:00 
			
		
		
		
	Added sorting at operators page
This commit is contained in:
		
							parent
							
								
									a53ff04192
								
							
						
					
					
						commit
						00fd2b796c
					
				| @ -68,6 +68,64 @@ function operator_by_id($id) | ||||
| 	return $operator; | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Get list of operators taking into account $options | ||||
|  * @param array $options Associative array of options. It can contains following keys: | ||||
|  *  - 'sort': an associative array of sorting options. | ||||
|  *  - 'isolated_operator_id': id of current operators. If it set - function would return | ||||
|  *    only operators from adjacent groups. | ||||
|  * | ||||
|  * 'sort' array must contains two keys: 'by' and 'desc'. | ||||
|  * 'by' means the field by which operators would be sort and can take following | ||||
|  * values: 'commonname', 'localename', 'login', 'lastseen'. 'desc' means order in which operators would | ||||
|  * be sort. If it's 'true' operators would be sort in descending order and in | ||||
|  * ascending order overwise. | ||||
|  * | ||||
|  */ | ||||
| function get_operators_list($options) | ||||
| { | ||||
| 	global $mysqlprefix; | ||||
| 	$link = connect(); | ||||
| 
 | ||||
| 	if ( !empty($options['sort']) && isset($options['sort']['by']) && isset($options['sort']['desc'])) { | ||||
| 		switch ($options['sort']['by']) { | ||||
| 			case 'commonname': | ||||
| 				$orderby = 'vccommonname'; | ||||
| 				break; | ||||
| 			case 'localename': | ||||
| 				$orderby = 'vclocalename'; | ||||
| 				break; | ||||
| 			case 'lastseen': | ||||
| 				$orderby = 'time'; | ||||
| 				break; | ||||
| 			default: | ||||
| 				$orderby = 'vclogin'; | ||||
| 				break; | ||||
| 		} | ||||
| 		$orderby = $orderby . ' ' . ($options['sort']['desc']?'DESC':'ASC'); | ||||
| 	} else { | ||||
| 		$orderby = "vclogin"; | ||||
| 	} | ||||
| 
 | ||||
| 	$query = "select distinct ${mysqlprefix}chatoperator.operatorid, vclogin, vclocalename, vccommonname, istatus, idisabled, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " . | ||||
| 		 "from ${mysqlprefix}chatoperator" . | ||||
| 		 ( | ||||
| 		 empty($options['isolated_operator_id']) ? "" : | ||||
| 			sprintf(", ${mysqlprefix}chatgroupoperator " . | ||||
| 				" where ${mysqlprefix}chatoperator.operatorid = ${mysqlprefix}chatgroupoperator.operatorid and ${mysqlprefix}chatgroupoperator.groupid in " . | ||||
| 				"(select g.groupid from ${mysqlprefix}chatgroup g, " . | ||||
| 				"(select distinct parent from ${mysqlprefix}chatgroup, ${mysqlprefix}chatgroupoperator " . | ||||
| 				"where ${mysqlprefix}chatgroup.groupid = ${mysqlprefix}chatgroupoperator.groupid and ${mysqlprefix}chatgroupoperator.operatorid = %u) i " . | ||||
| 				"where g.groupid = i.parent or g.parent = i.parent " . | ||||
| 				")", $options['isolated_operator_id']) | ||||
| 		 ) . | ||||
| 		 " order by " . $orderby; | ||||
| 
 | ||||
| 	$operators = select_multi_assoc($query, $link); | ||||
| 	close_connection($link); | ||||
| 	return $operators; | ||||
| } | ||||
| 
 | ||||
| function operator_get_all() | ||||
| { | ||||
| 	global $mysqlprefix; | ||||
|  | ||||
| @ -347,6 +347,7 @@ page_agent.tab.permissions=Permissions | ||||
| page_agent.title=Operator details | ||||
| page_agents.agent_name=Name | ||||
| page_agents.agents=Full list of operators: | ||||
| page_agents.commonname=International name | ||||
| page_agents.confirm=Are you sure that you want to delete operator "{0}"? | ||||
| page_agents.cannot.disable.admin=Cannot disable "admin". | ||||
| page_agents.cannot.disable.self=Cannot disable self. | ||||
| @ -362,6 +363,10 @@ page_agents.isaway=Away | ||||
| page_agents.isonline=Online | ||||
| page_agents.login=Login | ||||
| page_agents.new_agent=Add operator... | ||||
| page_agents.sort=Sort by: | ||||
| page_agents.sortdirection=Sort direction: | ||||
| page_agents.sortdirection.desc=descending | ||||
| page_agents.sortdirection.asc=ascending | ||||
| page_agents.status=Last active | ||||
| page_agents.title=Operators | ||||
| page_analysis.full.text.search=User name, operator name or message text search: | ||||
|  | ||||
| @ -345,6 +345,7 @@ page_agent.tab.permissions= | ||||
| page_agent.title=Äåòàëè îïåðàòîðà | ||||
| page_agents.agent_name=Èìÿ | ||||
| page_agents.agents=Ïîëíûé ñïèñîê îïåðàòîðîâ: | ||||
| page_agents.commonname=Èíòåðíàöèîíàëüíîå èìÿ | ||||
| page_agents.confirm=Âû óâåðåíû ÷òî õîòèòå óäàëèòü îïåðàòîðà "{0}"? | ||||
| page_agents.cannot.disable.admin=Íåâîçìîæíî çàáëîêèðîâàòü îïåðàòîðà "admin". | ||||
| page_agents.cannot.disable.self=Íåâîçìîæíî çàáëîêèðîâàòü ñåáÿ. | ||||
| @ -360,6 +361,10 @@ page_agents.isaway= | ||||
| page_agents.isonline=Äîñòóïåí | ||||
| page_agents.login=Ëîãèí | ||||
| page_agents.new_agent=Äîáàâèòü îïåðàòîðà... | ||||
| page_agents.sort=Ñîðòèðîâàòü ïî: | ||||
| page_agents.sortdirection=Íàïðàâëåíèå ñîðòèðîâêè: | ||||
| page_agents.sortdirection.desc=ïî óáûâàíèþ | ||||
| page_agents.sortdirection.asc=ïî âîçðàñòàíèþ | ||||
| page_agents.status=Ïîñëåäíèé ðàç | ||||
| page_agents.title=Îïåðàòîðû | ||||
| page_analysis.full.text.search=Ïîèñê ïî èìåíè ïîñåòèòåëÿ, èìåíè îïåðàòîðà èëè ïî òåêñòó ñîîáùåíèÿ: | ||||
|  | ||||
| @ -92,8 +92,26 @@ if (isset($_GET['act'])) { | ||||
| } | ||||
| 
 | ||||
| $page = array(); | ||||
| $page['allowedAgents'] = in_isolation($operator)?get_operators_from_adjacent_groups($operator):operator_get_all(); | ||||
| $sort['by'] = verifyparam("sortby", "/^(login|commonname|localename|lastseen)$/", "login"); | ||||
| $sort['desc'] = (verifyparam("sortdirection", "/^(desc|asc)$/", "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']; | ||||
| } | ||||
| $page['allowedAgents'] = get_operators_list($list_options); | ||||
| $page['canmodify'] = is_capable($can_administrate, $operator); | ||||
| $page['availableOrders'] = array( | ||||
| 	array('id' => 'login', 'name' => getlocal('page_agents.login')), | ||||
| 	array('id' => 'localename', 'name' => getlocal('page_agents.agent_name')), | ||||
| 	array('id' => 'commonname', 'name' => getlocal('page_agents.commonname')), | ||||
| 	array('id' => 'lastseen', 'name' => getlocal('page_agents.status')) | ||||
| ); | ||||
| $page['availableDirections'] = array( | ||||
| 	array('id' => 'desc', 'name' => getlocal('page_agents.sortdirection.desc')), | ||||
| 	array('id' => 'asc', 'name' => getlocal('page_agents.sortdirection.asc')), | ||||
| ); | ||||
| 
 | ||||
| setlocale(LC_TIME, getstring("time.locale")); | ||||
| 
 | ||||
|  | ||||
| @ -39,6 +39,32 @@ function tpl_content() { global $page, $webimroot, $errors; | ||||
| require_once('inc_errors.php'); | ||||
| ?>
 | ||||
| 
 | ||||
| <form name="agentsForm" method="get" action="<?php echo $webimroot ?>/operator/operators.php"> | ||||
| 
 | ||||
| 	<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner"> | ||||
| 
 | ||||
| 	<div class="packedFormField"> | ||||
| 		<?php echo getlocal("page_agents.sort") ?><br/>
 | ||||
| 		<select name="sortby" onchange="this.form.submit();"><?php | ||||
| 			foreach($page['availableOrders'] as $k) { | ||||
| 				echo "<option value=\"".$k['id']."\"".($k['id'] == form_value("sortby") ? " selected=\"selected\"" : "").">".$k['name']."</option>"; | ||||
| 			} ?></select>
 | ||||
| 	</div> | ||||
| 
 | ||||
| 	<div class="packedFormField"> | ||||
| 		<?php echo getlocal("page_agents.sortdirection") ?><br/>
 | ||||
| 		<select name="sortdirection" onchange="this.form.submit();"><?php | ||||
| 			foreach($page['availableDirections'] as $k) { | ||||
| 				echo "<option value=\"".$k['id']."\"".($k['id'] == form_value("sortdirection") ? " selected=\"selected\"" : "").">".$k['name']."</option>"; | ||||
| 			} ?></select>
 | ||||
| 	</div> | ||||
| 
 | ||||
| 	<br clear="all"/> | ||||
| 
 | ||||
| 	</div><div class="formbottom"><div class="formbottomi"></div></div></div> | ||||
| </form> | ||||
| <br /> | ||||
| 
 | ||||
| <?php if($page['canmodify']) { ?>
 | ||||
| <div class="tabletool"> | ||||
| 	<img src='<?php echo $webimroot ?>/images/buttons/createagent.gif' border="0" alt="" /> | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user