2013-07-06 20:38:57 +00:00
|
|
|
<?php
|
2013-09-13 22:39:03 +00:00
|
|
|
/**
|
|
|
|
* This function is beign used to create a new ticket.
|
|
|
|
* It will first check if the user who executed this function is the person of whom the setting is or if it's a mod/admin. If this is not the case the page will be redirected to an error page.
|
|
|
|
* next it will filter the POST data and it will try to create the new ticket. Afterwards a redirecion to the ticket will occur.
|
|
|
|
* @author Daan Janssens, mentored by Matthew Lagoe
|
|
|
|
*/
|
2013-07-06 20:38:57 +00:00
|
|
|
function create_ticket(){
|
2013-07-08 12:49:03 +00:00
|
|
|
//if logged in
|
2013-09-09 01:47:32 +00:00
|
|
|
global $INGAME_WEBPATH;
|
|
|
|
global $WEBPATH;
|
2013-07-08 12:49:03 +00:00
|
|
|
if(WebUsers::isLoggedIn() && isset($_SESSION['ticket_user'])){
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-08 12:49:03 +00:00
|
|
|
if(isset($_POST['target_id'])){
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-08 12:49:03 +00:00
|
|
|
//if target_id is the same as session id or is admin
|
2013-09-09 01:47:32 +00:00
|
|
|
if( ($_POST['target_id'] == $_SESSION['id']) || Ticket_User::isMod(unserialize($_SESSION['ticket_user'])) ){
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-08 12:49:03 +00:00
|
|
|
$category = filter_var($_POST['Category'], FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
$title = filter_var($_POST['Title'], FILTER_SANITIZE_STRING);
|
|
|
|
$content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING);
|
|
|
|
try{
|
2013-07-06 20:38:57 +00:00
|
|
|
if($_POST['target_id'] == $_SESSION['id']){
|
2013-09-13 22:39:03 +00:00
|
|
|
//if the ticket is being made for the executing user himself
|
2013-09-09 01:47:32 +00:00
|
|
|
$author = unserialize($_SESSION['ticket_user'])->getTUserId();
|
2013-07-06 20:38:57 +00:00
|
|
|
}else{
|
2013-09-13 22:39:03 +00:00
|
|
|
//if a mod tries to make a ticket for someone else
|
2013-07-10 10:36:14 +00:00
|
|
|
$author= Ticket_User::constr_ExternId($_POST['target_id'])->getTUserId();
|
2013-07-06 20:38:57 +00:00
|
|
|
}
|
2013-09-13 22:39:03 +00:00
|
|
|
//create the ticket & return the id of the newly created ticket.
|
2013-09-09 01:47:32 +00:00
|
|
|
$ticket_id = Ticket::create_Ticket($title, $content, $category, $author, unserialize($_SESSION['ticket_user'])->getTUserId(),0, $_POST);
|
2013-09-13 22:39:03 +00:00
|
|
|
//redirect to the new ticket.
|
2013-09-09 01:47:32 +00:00
|
|
|
if (Helpers::check_if_game_client()) {
|
|
|
|
header("Location: ".$INGAME_WEBPATH."?page=show_ticket&id=".$ticket_id);
|
|
|
|
}else{
|
|
|
|
header("Location: ".$WEBPATH."?page=show_ticket&id=".$ticket_id);
|
|
|
|
}
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-08 12:49:03 +00:00
|
|
|
}catch (PDOException $e) {
|
|
|
|
//ERROR: LIB DB is not online!
|
2013-08-05 23:00:17 +00:00
|
|
|
print_r($e);
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-07-08 12:49:03 +00:00
|
|
|
header("Location: index.php");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-07-06 20:38:57 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-06 20:38:57 +00:00
|
|
|
}else{
|
2013-07-08 12:49:03 +00:00
|
|
|
//ERROR: permission denied!
|
|
|
|
$_SESSION['error_code'] = "403";
|
|
|
|
header("Location: index.php?page=error");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-07-08 12:49:03 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-06 20:38:57 +00:00
|
|
|
}else{
|
2013-07-08 12:49:03 +00:00
|
|
|
//ERROR: The form was not filled in correclty
|
2013-08-05 23:00:17 +00:00
|
|
|
header("Location: index.php?page=create_ticket");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2014-09-03 05:06:43 +00:00
|
|
|
}
|
2013-07-08 12:49:03 +00:00
|
|
|
}else{
|
|
|
|
//ERROR: user is not logged in
|
|
|
|
header("Location: index.php");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2014-09-03 05:06:43 +00:00
|
|
|
}
|
|
|
|
|
2013-07-06 20:38:57 +00:00
|
|
|
}
|
|
|
|
|