undef HALF_FREQUENCY_SENDING_TO_CLIENT
[ryzomcore.git] / web / public_php / ams / func / create_ticket.php
blob713d4f19f80108d0e8216d082da76b360d6343bd
1 <?php
2 /**
3 * This function is beign used to create a new ticket.
4 * 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.
5 * next it will filter the POST data and it will try to create the new ticket. Afterwards a redirecion to the ticket will occur.
6 * @author Daan Janssens, mentored by Matthew Lagoe
7 */
8 function create_ticket(){
9 //if logged in
10 global $INGAME_WEBPATH;
11 global $WEBPATH;
12 $return = array();
13 $error = false;
14 if(WebUsers::isLoggedIn() && isset($_SESSION['ticket_user'])){
16 if(strlen (preg_replace('/\s\s+/', ' ', $_POST['Title']) )<2){
17 $return = array_merge ( $_POST, $return);
18 $return['no_visible_elements'] = 'FALSE';
19 $catArray = Ticket_Category::getAllCategories();
20 $return['permission'] = unserialize( $_SESSION['ticket_user'] ) -> getPermission();
21 $return['category'] = Gui_Elements::make_table_with_key_is_id($catArray, Array("getName"), "getTCategoryId" );
22 $return['TITLE_ERROR_MESSAGE'] = "Title must not be blank!";
23 $return['TITLE_ERROR'] = true;
24 $error = true;
26 if(strlen (preg_replace('/\s\s+/', ' ', $_POST['Content']) )<2){
27 $return = array_merge ( $_POST, $return);
28 $return['no_visible_elements'] = 'FALSE';
29 $catArray = Ticket_Category::getAllCategories();
30 $return['permission'] = unserialize( $_SESSION['ticket_user'] ) -> getPermission();
31 $return['category'] = Gui_Elements::make_table_with_key_is_id($catArray, Array("getName"), "getTCategoryId" );
32 $return['CONTENT_ERROR_MESSAGE'] = "Content must not be blank!";
33 $return['CONTENT_ERROR'] = true;
34 $error = true;
38 if ($error) {
39 helpers :: loadTemplate( 'createticket' , $return );
40 throw new SystemExit();
42 if(isset($_POST['target_id'])){
44 //if target_id is the same as session id or is admin
45 if( ($_POST['target_id'] == $_SESSION['id']) || Ticket_User::isMod(unserialize($_SESSION['ticket_user'])) ){
47 $category = filter_var($_POST['Category'], FILTER_SANITIZE_NUMBER_INT);
48 $title = filter_var($_POST['Title'], FILTER_SANITIZE_STRING);
49 $content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING);
50 try{
51 if($_POST['target_id'] == $_SESSION['id']){
52 //if the ticket is being made for the executing user himself
53 $author = unserialize($_SESSION['ticket_user'])->getTUserId();
54 }else{
55 //if a mod tries to make a ticket for someone else
56 $author= Ticket_User::constr_ExternId($_POST['target_id'])->getTUserId();
58 //create the ticket & return the id of the newly created ticket.
59 $ticket_id = Ticket::create_Ticket($title, $content, $category, $author, unserialize($_SESSION['ticket_user'])->getTUserId(),0, $_POST);
60 //redirect to the new ticket.
61 if (Helpers::check_if_game_client()) {
62 header("Cache-Control: max-age=1");
63 header("Location: ".$INGAME_WEBPATH."?page=show_ticket&id=".$ticket_id);
64 }else{
65 header("Cache-Control: max-age=1");
66 header("Location: ".$WEBPATH."?page=show_ticket&id=".$ticket_id);
67 throw new SystemExit();
70 }catch (PDOException $e) {
71 //ERROR: LIB DB is not online!
72 print_r($e);
73 throw new SystemExit();
74 header("Cache-Control: max-age=1");
75 header("Location: index.php");
76 throw new SystemExit();
79 }else{
80 //ERROR: permission denied!
81 $_SESSION['error_code'] = "403";
82 header("Cache-Control: max-age=1");
83 header("Location: index.php?page=error");
84 throw new SystemExit();
87 }else{
88 //ERROR: The form was not filled in correclty
89 header("Cache-Control: max-age=1");
90 header("Location: index.php?page=createticket");
91 throw new SystemExit();
93 }else{
94 //ERROR: user is not logged in
95 header("Cache-Control: max-age=1");
96 header("Location: index.php");
97 throw new SystemExit();