Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / web / public_php / ams / inc / show_ticket.php
blobb472686d2bc3d1414f690a34a1b06d9b5df46ced
1 <?php
2 /**
3 * This function is beign used to load info that's needed for the show_ticket page.
4 * check if the person browsing this page is a mod/admin or the ticket creator himself, if not he'll be redirected to an error page.
5 * if the $_GET['action'] var is set and the user executing is a mod/admin, it will try to execute the action. The actions here are: forwarding of a ticket,
6 * assigning a ticket and unassigning a ticket. This function returns a lot of information that will be used by the template to show the ticket. Mods/admins will be able to
7 * also see hidden replies to a ticket.
8 * @author Daan Janssens, mentored by Matthew Lagoe
9 */
10 function show_ticket(){
11 //if logged in
12 if(WebUsers::isLoggedIn() && isset($_GET['id'])){
14 $result['user_id'] = unserialize($_SESSION['ticket_user'])->getTUserId();
15 $result['ticket_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
16 $target_ticket = new Ticket();
17 $target_ticket->load_With_TId($result['ticket_id']);
19 if(Ticket_User::isMod(unserialize($_SESSION['ticket_user'] ))){
20 if(isset($_POST['action'])){
21 switch($_POST['action']){
22 case "forward":
23 $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT);
24 $group_id = filter_var($_POST['group'], FILTER_SANITIZE_NUMBER_INT);
25 $result['ACTION_RESULT'] = Ticket::forwardTicket($result['user_id'], $ticket_id, $group_id);
26 break;
27 case "assignTicket":
28 $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT);
29 $result['ACTION_RESULT'] = Ticket::assignTicket($result['user_id'] , $ticket_id);
30 break;
31 case "unAssignTicket":
32 $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT);
33 $result['ACTION_RESULT'] = Ticket::unAssignTicket($result['user_id'], $ticket_id);
34 break;
40 if(($target_ticket->getAuthor() == unserialize($_SESSION['ticket_user'])->getTUserId()) || Ticket_User::isMod(unserialize($_SESSION['ticket_user']) )){
42 $show_as_admin = false;
43 if(Ticket_User::isMod(unserialize($_SESSION['ticket_user']))){
44 $show_as_admin = true;
47 $entire_ticket = Ticket::getEntireTicket( $result['ticket_id'],$show_as_admin);
48 Ticket_Log::createLogEntry($result['ticket_id'],unserialize($_SESSION['ticket_user'])->getTUserId(), 3);
49 $result['ticket_tId'] = $entire_ticket['ticket_obj']->getTId();
50 $result['ticket_forwardedGroupName'] = $entire_ticket['ticket_obj']->getForwardedGroupName();
51 $result['ticket_forwardedGroupId'] = $entire_ticket['ticket_obj']->getForwardedGroupId();
52 $result['ticket_title'] = $entire_ticket['ticket_obj']->getTitle();
53 $result['ticket_timestamp'] = $entire_ticket['ticket_obj']->getTimestamp();
54 $result['ticket_status'] = $entire_ticket['ticket_obj']->getStatus();
55 $result['ticket_author'] = $entire_ticket['ticket_obj']->getAuthor();
56 $result['ticket_prioritytext'] = $entire_ticket['ticket_obj']->getPriorityText();
57 $result['ticket_priorities'] = Ticket::getPriorityArray();
58 $result['ticket_priority'] = $entire_ticket['ticket_obj']->getPriority();
59 $result['ticket_statustext'] = $entire_ticket['ticket_obj']->getStatusText();
60 $result['ticket_lastupdate'] = Gui_Elements::time_elapsed_string(Ticket::getLatestReply($result['ticket_id'])->getTimestamp());
61 $result['ticket_category'] = $entire_ticket['ticket_obj']->getCategoryName();
62 $webUser = new WebUsers(Assigned::getUserAssignedToTicket($result['ticket_tId']));
63 $result['ticket_assignedToText'] = $webUser->getUsername();
64 $result['ticket_assignedTo'] = Assigned::getUserAssignedToTicket($result['ticket_tId']);
65 $result['ticket_replies'] = Gui_Elements::make_table($entire_ticket['reply_array'], Array("getTReplyId","getContent()->getContent","getTimestamp","getAuthor()->getExternId","getAuthor()->getPermission","getHidden"), Array("tReplyId","replyContent","timestamp","authorExtern","permission","hidden"));
66 $i = 0;
67 global $FILE_WEB_PATH;
68 $result['FILE_WEB_PATH'] = $FILE_WEB_PATH;
69 global $BASE_WEBPATH;
70 $result['BASE_WEBPATH'] = $BASE_WEBPATH;
71 foreach( $result['ticket_replies'] as $reply){
72 $webReplyUser = new WebUsers($reply['authorExtern']);
73 $result['ticket_replies'][$i]['author'] = $webReplyUser->getUsername();
74 $i++;
76 if(Ticket_User::isMod(unserialize($_SESSION['ticket_user']))){
77 $result['isMod'] = "TRUE";
78 $result['statusList'] = Ticket::getStatusArray();
79 $result['sGroups'] = Gui_Elements::make_table_with_key_is_id(Support_Group::getAllSupportGroups(), Array("getName"), "getSGroupId" );
81 $result['hasInfo'] = $target_ticket->hasInfo();
82 global $INGAME_WEBPATH;
83 $result['ingame_webpath'] = $INGAME_WEBPATH;
84 //get attachments
85 $result['ticket_attachments'] = Ticket::getAttachments($result['ticket_id']);
86 return $result;
88 }else{
89 //ERROR: No access!
90 $_SESSION['error_code'] = "403";
91 header("Cache-Control: max-age=1");
92 header("Location: index.php?page=error");
93 throw new SystemExit();
95 }else{
96 //ERROR: not logged in!
97 header("Cache-Control: max-age=1");
98 header("Location: index.php");
99 throw new SystemExit();