/** * function that creates a ticket Attachment. */ public static function add_Attachment($TId, $filename, $author, $tempFile) { global $FILE_STORAGE_PATH; $length = mt_rand(20, 25); $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$-_.+!*\'(),'; $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } $targetFile = $FILE_STORAGE_PATH . $randomString . "/" . $filename; if (file_exists($targetFile)) { return self::add_Attachment($TId, $filename, $author, $tempFile); } $ticket = new Ticket(); $ticket->load_With_TId($TId); //create the attachment! try { $dbl = new DBLayer("lib"); $dbl->insert("`ticket_attachments`", array('ticket_TId' => $TId, 'Filename' => $filename, 'Filesize' => filesize($tempFile), 'Uploader' => $author, 'Path' => $randomString . "/" . $filename)); } catch (Exception $e) { return $false; } mkdir($FILE_STORAGE_PATH . $randomString); $return = move_uploaded_file($tempFile, $targetFile); if ($return == false) { $dbl->delete("`ticket_attachments`", array('Path' => $randomString . "/" . $filename), "`Path` = :Path"); } //write a log entry Ticket_Log::createLogEntry($TId, $author, 10); return $return; }
/** * This function is beign used to load info that's needed for the show_ticket page. * 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. * 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, * 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 * also see hidden replies to a ticket. * @author Daan Janssens, mentored by Matthew Lagoe */ function show_ticket() { //if logged in if (WebUsers::isLoggedIn() && isset($_GET['id'])) { $result['user_id'] = unserialize($_SESSION['ticket_user'])->getTUserId(); $result['ticket_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT); $target_ticket = new Ticket(); $target_ticket->load_With_TId($result['ticket_id']); if (Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { if (isset($_POST['action'])) { switch ($_POST['action']) { case "forward": $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); $group_id = filter_var($_POST['group'], FILTER_SANITIZE_NUMBER_INT); $result['ACTION_RESULT'] = Ticket::forwardTicket($result['user_id'], $ticket_id, $group_id); break; case "assignTicket": $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); $result['ACTION_RESULT'] = Ticket::assignTicket($result['user_id'], $ticket_id); break; case "unAssignTicket": $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); $result['ACTION_RESULT'] = Ticket::unAssignTicket($result['user_id'], $ticket_id); break; } } } if ($target_ticket->getAuthor() == unserialize($_SESSION['ticket_user'])->getTUserId() || Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { $show_as_admin = false; if (Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { $show_as_admin = true; } $entire_ticket = Ticket::getEntireTicket($result['ticket_id'], $show_as_admin); Ticket_Log::createLogEntry($result['ticket_id'], unserialize($_SESSION['ticket_user'])->getTUserId(), 3); $result['ticket_tId'] = $entire_ticket['ticket_obj']->getTId(); $result['ticket_forwardedGroupName'] = $entire_ticket['ticket_obj']->getForwardedGroupName(); $result['ticket_forwardedGroupId'] = $entire_ticket['ticket_obj']->getForwardedGroupId(); $result['ticket_title'] = $entire_ticket['ticket_obj']->getTitle(); $result['ticket_timestamp'] = $entire_ticket['ticket_obj']->getTimestamp(); $result['ticket_status'] = $entire_ticket['ticket_obj']->getStatus(); $result['ticket_author'] = $entire_ticket['ticket_obj']->getAuthor(); $result['ticket_prioritytext'] = $entire_ticket['ticket_obj']->getPriorityText(); $result['ticket_priorities'] = Ticket::getPriorityArray(); $result['ticket_priority'] = $entire_ticket['ticket_obj']->getPriority(); $result['ticket_statustext'] = $entire_ticket['ticket_obj']->getStatusText(); $result['ticket_lastupdate'] = Gui_Elements::time_elapsed_string(Ticket::getLatestReply($result['ticket_id'])->getTimestamp()); $result['ticket_category'] = $entire_ticket['ticket_obj']->getCategoryName(); $webUser = new WebUsers(Assigned::getUserAssignedToTicket($result['ticket_tId'])); $result['ticket_assignedToText'] = $webUser->getUsername(); $result['ticket_assignedTo'] = Assigned::getUserAssignedToTicket($result['ticket_tId']); $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")); $i = 0; global $FILE_WEB_PATH; $result['FILE_WEB_PATH'] = $FILE_WEB_PATH; global $BASE_WEBPATH; $result['BASE_WEBPATH'] = $BASE_WEBPATH; foreach ($result['ticket_replies'] as $reply) { $webReplyUser = new WebUsers($reply['authorExtern']); $result['ticket_replies'][$i]['author'] = $webReplyUser->getUsername(); $i++; } if (Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { $result['isMod'] = "TRUE"; $result['statusList'] = Ticket::getStatusArray(); $result['sGroups'] = Gui_Elements::make_table_with_key_is_id(Support_Group::getAllSupportGroups(), array("getName"), "getSGroupId"); } $result['hasInfo'] = $target_ticket->hasInfo(); global $INGAME_WEBPATH; $result['ingame_webpath'] = $INGAME_WEBPATH; //get attachments $result['ticket_attachments'] = Ticket::getAttachments($result['ticket_id']); return $result; } else { //ERROR: No access! $_SESSION['error_code'] = "403"; header("Cache-Control: max-age=1"); header("Location: index.php?page=error"); throw new SystemExit(); } } else { //ERROR: not logged in! header("Cache-Control: max-age=1"); header("Location: index.php"); throw new SystemExit(); } }
/** * This function is beign used to load info that's needed for the show_ticket_log page. * This page shows the logs related to a ticket: who created the ticket, who replied on it, who viewed it, assigned or forwarded it. * Only mods/admins are able to browse the log though. The found information is returned so it can be used by the template. * @author Daan Janssens, mentored by Matthew Lagoe */ function show_ticket_log() { global $INGAME_WEBPATH; global $WEBPATH; //if logged in if (WebUsers::isLoggedIn() && isset($_GET['id'])) { //only allow admins to browse the log! if (Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { $result['ticket_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT); $target_ticket = new Ticket(); $target_ticket->load_With_TId($result['ticket_id']); $result['ticket_title'] = $target_ticket->getTitle(); //return all logs related to a ticket. $ticket_logs = Ticket_Log::getLogsOfTicket($result['ticket_id']); $log_action_array = Ticket_Log::getActionTextArray(); //fetch information about each returned ticket in a format that is usable for the template $result['ticket_logs'] = Gui_Elements::make_table($ticket_logs, array("getTLogId", "getTimestamp", "getAuthor()->getExternId", "getAction", "getArgument()"), array("tLogId", "timestamp", "authorExtern", "action", "argument")); $i = 0; //for each ticket add action specific informaton to the to-be-shown text: uses the query_backpart foreach ($result['ticket_logs'] as $log) { $webUser = new WebUsers($log['authorExtern']); $author = $webUser->getUsername(); $result['ticket_logs'][$i]['author'] = $author; $query_backpart = ""; if ($log['action'] == 2) { $webUser2 = new WebUsers($log['argument']); $query_backpart = $webUser2->getUsername(); } else { if ($log['action'] == 4) { if (Helpers::check_if_game_client()) { $query_backpart = "<a href='" . $INGAME_WEBPATH . "?page=show_reply&id=" . $log['argument'] . "'>ID#" . $log['argument'] . "</a>"; } else { $query_backpart = "<a href='" . $WEBPATH . "?page=show_reply&id=" . $log['argument'] . "'>ID#" . $log['argument'] . "</a>"; } } else { if ($log['action'] == 5) { $statusArray = Ticket::getStatusArray(); $query_backpart = $statusArray[$log['argument']]; } else { if ($log['action'] == 6) { $priorityArray = Ticket::getPriorityArray(); $query_backpart = $priorityArray[$log['argument']]; } else { if ($log['action'] == 8) { if (Helpers::check_if_game_client()) { $query_backpart = "<a href='" . $INGAME_WEBPATH . "?page=show_sgroupy&id=" . $log['argument'] . "'>" . Support_Group::getGroup($log['argument'])->getName() . "</a>"; } else { $query_backpart = "<a href='" . $WEBPATH . "?page=show_sgroupy&id=" . $log['argument'] . "'>" . Support_Group::getGroup($log['argument'])->getName() . "</a>"; } } } } } } $result['ticket_logs'][$i]['query'] = $author . " " . $log_action_array[$log['action']] . " " . $query_backpart; $result['ticket_logs'][$i]['timestamp_elapsed'] = Gui_Elements::time_elapsed_string($log['timestamp']); $i++; } if (Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) { $result['isMod'] = "TRUE"; } global $INGAME_WEBPATH; $result['ingame_webpath'] = $INGAME_WEBPATH; return $result; } else { //ERROR: No access! $_SESSION['error_code'] = "403"; header("Cache-Control: max-age=1"); header("Location: index.php?page=error"); throw new SystemExit(); } } else { //ERROR: not logged in! header("Cache-Control: max-age=1"); header("Location: index.php"); throw new SystemExit(); } }
/** * creates a new reply on a ticket. * Creates a ticket_content entry and links it with a new created ticket_reply, a log entry will be written about this. * In case the ticket creator replies on a ticket, he will set the status by default to 'waiting on support'. * @param $content the content of the reply * @param $author the id of the reply creator. * @param $ticket_id the id of the ticket of which we want the replies. * @param $hidden should be 0 or 1 * @param $ticket_creator the ticket's starter his id. */ public static function createReply($content, $author, $ticket_id, $hidden, $ticket_creator) { $ticket_content = new Ticket_Content(); $ticket_content->setContent($content); $ticket_content->create(); $content_id = $ticket_content->getTContentId(); $ticket_reply = new Ticket_Reply(); $ticket_reply->set(array('Ticket' => $ticket_id, 'Content' => $content_id, 'Author' => $author, 'Hidden' => $hidden)); $ticket_reply->create(); $reply_id = $ticket_reply->getTReplyId(); if ($ticket_creator == $author) { Ticket::updateTicketStatus($ticket_id, 1, $author); } Ticket_Log::createLogEntry($ticket_id, $author, 4, $reply_id); }