/**
  * @param REQUEST service_code
  */
 public function services()
 {
     // If a service_id is provided, they want the service info
     if (isset($_REQUEST['service_code'])) {
         try {
             $category = new Category($_REQUEST['service_code']);
             if ($category->allowsPosting($this->person)) {
                 $this->template->blocks[] = new Block('open311/serviceInfo.inc', array('category' => $category));
             } else {
                 // Not allowed to post to this category
                 header('HTTP/1.0 403 Forbidden', true, 403);
                 $_SESSION['errorMessages'][] = new \Exception('noAccessAllowed');
             }
         } catch (\Exception $e) {
             // Unknown service
             header('HTTP/1.0 404 Not Found', true, 404);
             $_SESSION['errorMessages'][] = new \Exception('open311/unknownService');
         }
     } else {
         $table = new CategoryTable();
         $categoryList = $table->find();
         $this->template->blocks[] = new Block('open311/serviceList.inc', array('categoryList' => $categoryList));
     }
 }
 /**
  *
  */
 public function add()
 {
     $ticket = new Ticket();
     $issue = new Issue();
     // Categories are required before starting the process
     // Handle any Category choice passed in
     if (!empty($_REQUEST['category_id'])) {
         $category = new Category($_REQUEST['category_id']);
         if ($category->allowsPosting($_SESSION['USER'])) {
             $ticket->setCategory($category);
         } else {
             $_SESSION['errorMessages'][] = new \Exception('noAccessAllowed');
             header('Location: ' . BASE_URL);
             exit;
         }
     }
     // Handle any Location choice passed in
     if (!empty($_GET['location'])) {
         $ticket->setLocation($_GET['location']);
         $ticket->setAddressServiceData(AddressService::getLocationData($ticket->getLocation()));
     }
     // Handle any Person choice passed in
     if (!empty($_REQUEST['reportedByPerson_id'])) {
         $issue->setReportedByPerson_id($_REQUEST['reportedByPerson_id']);
     }
     // Handle any Department choice passed in
     // Choosing a department here will cause the assignment form
     // to pre-select that department's defaultPerson
     $currentDepartment = null;
     if (isset($_GET['department_id'])) {
         try {
             $currentDepartment = new Department($_GET['department_id']);
         } catch (\Exception $e) {
             // Ignore any bad departments passed in
         }
     }
     // If they haven't chosen a department, start by assigning
     // the ticket to the current User, and use the current user's department
     if (!isset($currentDepartment)) {
         $ticket->setAssignedPerson($_SESSION['USER']);
         if ($_SESSION['USER']->getDepartment()) {
             $currentDepartment = $_SESSION['USER']->getDepartment();
         }
     }
     // Process the ticket form when it's posted
     if (isset($_POST['category_id'])) {
         try {
             $ticket->handleAdd($_POST);
             // Calls save as needed - no need to save() again
             $this->redirectToTicketView($ticket);
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     // Display all the forms
     $this->template->setFilename('ticketCreation');
     $this->template->blocks['right-top'][] = new Block('tickets/chooseLocation.inc', array('ticket' => $ticket));
     $this->template->blocks['right-bottom'][] = new Block('tickets/chooseReportedByPerson.inc', array('issue' => $issue));
     $this->template->blocks['left'][] = new Block('tickets/addTicketForm.inc', array('ticket' => $ticket, 'issue' => $issue, 'currentDepartment' => $currentDepartment));
 }