Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / web / public_php / ams / inc / show_queue.php
blob6132719fa3e47d18b9dec9e9b6ddd3b00607239c
1 <?php
2 /**
3 * This function is beign used to load info that's needed for the show_queue page.
4 * check if the person who wants to view this page is a mod/admin, if this is not the case, he will be redirected to an error page.
5 * if an action is set (this is done by $_GET['action']) it will try to execute it first, actions are: assign a ticket, unassign a ticket an create a queue.
6 * There are a few predefined queues which is the 'all tickets' queue, 'archive' queue, 'todo' queue, .. these are passed by $_GET['get'].
7 * if $_GET['get'] = create; then it's a custom made queue, this will call the createQueue function which builds the query that we will later use to get the tickets.
8 * The tickets fetched will be returned and used in the template. Now why use POST and GET params here and have a createQueue function twice? Well the first time someone creates
9 * a queue the POST variables will be used, however after going to the next page it will use the GET params.
10 * @author Daan Janssens, mentored by Matthew Lagoe
12 function show_queue(){
13 global $INGAME_WEBPATH;
14 global $WEBPATH;
15 //if logged in & queue id is given
16 if(WebUsers::isLoggedIn() && isset($_GET['get'])){
18 if( Ticket_User::isMod(unserialize($_SESSION['ticket_user']))){
20 //the queue you want to see.
21 $result['queue_view'] = filter_var($_GET['get'], FILTER_SANITIZE_STRING);
22 $user_id = unserialize($_SESSION['ticket_user'])->getTUserId();
23 $queueArray = array();
24 $queue_handler = new Ticket_Queue_handler();
26 //Pagination Base Links
27 if (Helpers::check_if_game_client()) {
28 $result['pagination_base_link'] = $INGAME_WEBPATH."?page=show_queue&get=".$result['queue_view'] ;
29 }else{
30 $result['pagination_base_link'] = $WEBPATH."?page=show_queue&get=".$result['queue_view'] ;
33 //form url to keep the getters constant
34 if (Helpers::check_if_game_client()) {
35 $result['getURL'] = $INGAME_WEBPATH."?page=show_queue&get=" . $result['queue_view'];
36 }else{
37 $result['getURL'] = $WEBPATH."?page=show_queue&get=" . $result['queue_view'];
40 if(isset($_GET['pagenum'])){
41 $result['getURL'] = $result['getURL'] . "&pagenum=".$_GET['pagenum'];
44 if(isset($_GET['get']) && ($_GET['get'] == "create") && isset($_GET['userid']) && isset($_GET['groupid']) && isset($_GET['what']) && isset($_GET['how']) && isset($_GET['who'])){
45 $userid = filter_var($_GET['userid'], FILTER_SANITIZE_NUMBER_INT);
46 $groupid = filter_var($_GET['groupid'], FILTER_SANITIZE_NUMBER_INT);
47 $what = filter_var($_GET['what'], FILTER_SANITIZE_STRING);
48 $how = filter_var($_GET['how'], FILTER_SANITIZE_STRING);
49 $who = filter_var($_GET['who'], FILTER_SANITIZE_STRING);
50 //create the custom queue
51 $queue_handler->CreateQueue($userid, $groupid, $what, $how, $who);
53 if (Helpers::check_if_game_client()) {
54 $result['pagination_base_link'] = $INGAME_WEBPATH."?page=show_queue&get=create&userid=".$userid."&groupid=".$groupid."&what=".$what."&how=".$how."&who=".$who;
55 }else{
56 $result['pagination_base_link'] = $WEBPATH."?page=show_queue&get=create&userid=".$userid."&groupid=".$groupid."&what=".$what."&how=".$how."&who=".$who;
60 $result['prev_created_userid'] = $userid;
61 $result['prev_created_groupid'] = $groupid;
62 $result['prev_created_what'] = $what;
63 $result['prev_created_how'] = $how;
64 $result['prev_created_who'] = $who;
66 $result['getURL'] = $result['getURL'] . "&userid=".$userid."&groupid=".$groupid."&what=".$what."&how=".$how."&who=".$who;
70 //if an action is set
71 if(isset($_POST['action'])){
72 switch($_POST['action']){
73 case "assignTicket":
74 $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT);
75 $result['ACTION_RESULT'] = Ticket::assignTicket($user_id, $ticket_id);
76 break;
78 case "unAssignTicket":
79 $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT);
80 $result['ACTION_RESULT'] = Ticket::unAssignTicket($user_id, $ticket_id);
81 break;
83 case "create_queue":
84 $userid = filter_var($_POST['userid'], FILTER_SANITIZE_NUMBER_INT);
85 if (isset($_POST['groupid'])) {
86 $groupid = filter_var($_POST['groupid'], FILTER_SANITIZE_NUMBER_INT);
87 } else {
88 $groupid = 0;
90 $what = filter_var($_POST['what'], FILTER_SANITIZE_STRING);
91 $how = filter_var($_POST['how'], FILTER_SANITIZE_STRING);
92 $who = filter_var($_POST['who'], FILTER_SANITIZE_STRING);
93 //create the custom queue
94 $queue_handler->CreateQueue($userid, $groupid, $what, $how, $who);
95 if (Helpers::check_if_game_client()) {
96 $result['pagination_base_link'] = $INGAME_WEBPATH."?page=show_queue&get=create&userid=".$userid."&groupid=".$groupid."&what=".$what."&how=".$how."&who=".$who;
97 }else{
98 $result['pagination_base_link'] = $WEBPATH."?page=show_queue&get=create&userid=".$userid."&groupid=".$groupid."&what=".$what."&how=".$how."&who=".$who;
100 $result['prev_created_userid'] = $userid;
101 $result['prev_created_groupid'] = $groupid;
102 $result['prev_created_what'] = $what;
103 $result['prev_created_how'] = $how;
104 $result['prev_created_who'] = $who;
105 $result['getURL'] = $result['getURL'] . "&userid=".$userid."&groupid=".$groupid."&what=".$what."&how=".$how."&who=".$who;
107 break;
112 $queueArray = $queue_handler->getTickets($result['queue_view'], $user_id);
114 //pagination
115 $result['links'] = $queue_handler->getPagination()->getLinks(5);
116 $result['lastPage'] = $queue_handler->getPagination()->getLast();
117 $result['currentPage'] = $queue_handler->getPagination()->getCurrent();
120 //if queue_view is a valid parameter value
121 if ($queueArray != "ERROR"){
122 $result['tickets'] = Gui_Elements::make_table($queueArray, Array("getTId","getTitle","getTimestamp","getAuthor()->getExternId","getTicket_Category()->getName","getStatus","getStatusText","getAssigned","getForwardedGroupName","getForwardedGroupId"), Array("tId","title","timestamp","authorExtern","category","status","statusText","assigned","forwardedGroupName","forwardedGroupId"));
123 $i = 0;
124 foreach( $result['tickets'] as $ticket){
125 $web_author = new WebUsers($ticket['authorExtern']);
126 $result['tickets'][$i]['author'] = $web_author->getUsername();
127 $web_assigned = new WebUsers($ticket['assigned']);
128 $result['tickets'][$i]['assignedText'] = $web_assigned->getUsername();
129 $result['tickets'][$i]['timestamp_elapsed'] = Gui_Elements::time_elapsed_string($ticket['timestamp']);
130 $i++;
132 $result['user_id'] = unserialize($_SESSION['ticket_user'])->getTUserId();
134 //Queue creator field info
135 $result['grouplist'] = Gui_Elements::make_table(Support_Group::getGroups(), Array("getSGroupId","getName"), Array("sGroupId","name"));
136 $result['teamlist'] = Gui_Elements::make_table(Ticket_User::getModsAndAdmins(), Array("getTUserId","getExternId"), Array("tUserId","externId"));
137 $i = 0;
138 foreach( $result['teamlist'] as $member){
139 $web_teammember = new Webusers($member['externId']);
140 $result['teamlist'][$i]['name'] = $web_teammember->getUsername();
141 $i++;
143 global $INGAME_WEBPATH;
144 $result['ingame_webpath'] = $INGAME_WEBPATH;
145 return $result;
147 }else{
149 //ERROR: Doesn't exist!
150 $_SESSION['error_code'] = "404";
151 header("Cache-Control: max-age=1");
152 header("Location: ams?page=error");
153 throw new SystemExit();
156 }else{
157 //ERROR: No access!
158 $_SESSION['error_code'] = "403";
159 header("Cache-Control: max-age=1");
160 header("Location: index.php?page=error");
161 throw new SystemExit();
163 }else{
164 //ERROR: not logged in!
165 header("Cache-Control: max-age=1");
166 header("Location: index.php");
167 throw new SystemExit();