/**
  * returns the tickets that are related in someway defined by $input.
  * The $input parameter should be a string that defines what kind of queue should be loaded. A new pagination object will be instantiated and will load 10 entries,
  * related to the $_GET['pagenum'] variable.
  * @param $input identifier that defines what queue to load.
  * @param $user_id the id of the user that browses the queues, some queues can be depending on this.
  * @return an array consisting of ticket objects, beware, the author & category of a ticket, are objects on their own (no integers are used this time).
  */
 public function getTickets($input, $user_id)
 {
     switch ($input) {
         case "all":
             $this->queue->loadAllTickets();
             break;
         case "all_open":
             $this->queue->loadAllOpenTickets();
             break;
         case "archive":
             $this->queue->loadAllClosedTickets();
             break;
         case "not_assigned":
             $this->queue->loadAllNotAssignedTickets();
             break;
         case "todo":
             $this->queue->loadToDoTickets($user_id);
             break;
         case "create":
             //set these with the createQueue function proceding the getTickets function
             break;
         default:
             return "ERROR";
     }
     $this->pagination = new Pagination($this->queue->getQuery(), "lib", 10, "Ticket", $this->queue->getParams());
     $elemArray = $this->pagination->getElements();
     if (!empty($elemArray)) {
         foreach ($elemArray as $element) {
             $catInstance = new Ticket_Category();
             $catInstance->load_With_TCategoryId($element->getTicket_Category());
             $element->setTicket_Category($catInstance);
             $userInstance = new Ticket_User();
             $userInstance->load_With_TUserId($element->getAuthor());
             $element->setAuthor($userInstance);
         }
     }
     return $this->pagination->getElements();
 }
Example #2
0
/**
* This function is beign used to load info that's needed for the createticket page.
* the $_GET['user_id'] identifies for which user you try to create a ticket. A normal user can only create a ticket for himself, a mod/admin however can also create tickets for other users.
* It will also load all categories and return these, they will be used by the template.
* @author Daan Janssens, mentored by Matthew Lagoe
*/
function createticket()
{
    //if logged in
    if (WebUsers::isLoggedIn()) {
        //in case user_id-GET param set it's value as target_id, if no user_id-param is given, use the session id.
        if (isset($_GET['user_id'])) {
            //check if you are a mod/admin or you try to create a ticket for your own, if this is not the case redirect to error page
            if ($_GET['user_id'] != $_SESSION['id'] && !ticket_user::isMod(unserialize($_SESSION['ticket_user']))) {
                //ERROR: No access!
                $_SESSION['error_code'] = "403";
                header("Cache-Control: max-age=1");
                header("Location: index.php?page=error");
                throw new SystemExit();
            } else {
                //if user_id is given, then set it as the target_id
                $result['target_id'] = filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT);
            }
        } else {
            //set session_id as target_id
            $result['target_id'] = $_SESSION['id'];
        }
        if (Helpers::check_if_game_client()) {
            //get all additional info, which is needed for adding the extra info page
            $result[] = $_GET;
            $result['ingame'] = true;
        }
        //create array of category id & names
        $catArray = Ticket_Category::getAllCategories();
        $result['category'] = Gui_Elements::make_table_with_key_is_id($catArray, array("getName"), "getTCategoryId");
        global $INGAME_WEBPATH;
        $result['ingame_webpath'] = $INGAME_WEBPATH;
        $result['TITLE_ERROR'] = $INGAME_WEBPATH;
        return $result;
    } else {
        //ERROR: not logged in!
        header("Cache-Control: max-age=1");
        header("Location: index.php");
        throw new SystemExit();
    }
}
Example #3
0
 /**
  * get category attribute of the object in the form of text (string).
  */
 public function getCategoryName()
 {
     $category = Ticket_Category::constr_TCategoryId($this->getTicket_Category());
     return $category->getName();
 }
Example #4
0
/**
* 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
*/
function create_ticket()
{
    //if logged in
    global $INGAME_WEBPATH;
    global $WEBPATH;
    $return = array();
    $error = false;
    if (WebUsers::isLoggedIn() && isset($_SESSION['ticket_user'])) {
        if (strlen(preg_replace('/\\s\\s+/', ' ', $_POST['Title'])) < 2) {
            $return = array_merge($_POST, $return);
            $return['no_visible_elements'] = 'FALSE';
            $catArray = Ticket_Category::getAllCategories();
            $return['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
            $return['category'] = Gui_Elements::make_table_with_key_is_id($catArray, array("getName"), "getTCategoryId");
            $return['TITLE_ERROR_MESSAGE'] = "Title must not be blank!";
            $return['TITLE_ERROR'] = true;
            $error = true;
        }
        if (strlen(preg_replace('/\\s\\s+/', ' ', $_POST['Content'])) < 2) {
            $return = array_merge($_POST, $return);
            $return['no_visible_elements'] = 'FALSE';
            $catArray = Ticket_Category::getAllCategories();
            $return['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
            $return['category'] = Gui_Elements::make_table_with_key_is_id($catArray, array("getName"), "getTCategoryId");
            $return['CONTENT_ERROR_MESSAGE'] = "Content must not be blank!";
            $return['CONTENT_ERROR'] = true;
            $error = true;
        }
        if ($error) {
            helpers::loadTemplate('createticket', $return);
            throw new SystemExit();
        }
        if (isset($_POST['target_id'])) {
            //if target_id is the same as session id or is admin
            if ($_POST['target_id'] == $_SESSION['id'] || Ticket_User::isMod(unserialize($_SESSION['ticket_user']))) {
                $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 {
                    if ($_POST['target_id'] == $_SESSION['id']) {
                        //if the ticket is being made for the executing user himself
                        $author = unserialize($_SESSION['ticket_user'])->getTUserId();
                    } else {
                        //if a mod tries to make a ticket for someone else
                        $author = Ticket_User::constr_ExternId($_POST['target_id'])->getTUserId();
                    }
                    //create the ticket & return the id of the newly created ticket.
                    $ticket_id = Ticket::create_Ticket($title, $content, $category, $author, unserialize($_SESSION['ticket_user'])->getTUserId(), 0, $_POST);
                    //redirect to the new ticket.
                    if (Helpers::check_if_game_client()) {
                        header("Cache-Control: max-age=1");
                        header("Location: " . $INGAME_WEBPATH . "?page=show_ticket&id=" . $ticket_id);
                    } else {
                        header("Cache-Control: max-age=1");
                        header("Location: " . $WEBPATH . "?page=show_ticket&id=" . $ticket_id);
                        throw new SystemExit();
                    }
                } catch (PDOException $e) {
                    //ERROR: LIB DB is not online!
                    print_r($e);
                    throw new SystemExit();
                    header("Cache-Control: max-age=1");
                    header("Location: index.php");
                    throw new SystemExit();
                }
            } else {
                //ERROR: permission denied!
                $_SESSION['error_code'] = "403";
                header("Cache-Control: max-age=1");
                header("Location: index.php?page=error");
                throw new SystemExit();
            }
        } else {
            //ERROR: The form was not filled in correclty
            header("Cache-Control: max-age=1");
            header("Location: index.php?page=createticket");
            throw new SystemExit();
        }
    } else {
        //ERROR: user is not logged in
        header("Cache-Control: max-age=1");
        header("Location: index.php");
        throw new SystemExit();
    }
}