/** * save new ticket * */ function __addTicket() { //profiling $this->data['controller_profiling'][] = __FUNCTION__; //PERMISSIONS CHECK - GENERAL //do this check after __commonAll_ProjectBasics() if ($this->data['permission']['add_item_tickets'] != 1) { redirect('/admin/error/permission-denied'); } //flow control $next = true; //check if any post data (avoid direct url access) if (!isset($_POST['submit'])) { redirect('/admin/tickets/new'); } //validate form if ($next) { if (!$this->__flmFormValidation('add_ticket')) { //show error $this->notices('error', $this->form_processor->error_message, 'html'); $next = false; } } //validate hidden fields if ($next) { if (!$this->__flmFormValidation('add_ticket_hidden')) { //log this error log_message('error', '[FILE: ' . __FILE__ . '] [FUNCTION: ' . __FUNCTION__ . '] [LINE: ' . __LINE__ . "] [MESSAGE: Add Ticket failed: Required hidden form fields are missing or invalid]"); //show error $this->notices('error', $this->data['lang']['lang_request_could_not_be_completed'], 'html'); $next = false; } } //add to database if ($next) { //add ticket $ticket_id = $this->tickets_model->addTicket(); $this->data['debug'][] = $this->tickets_model->debug_data; //check if there was an errro inserting record if (!$ticket_id) { //log this error log_message('error', '[FILE: ' . __FILE__ . '] [FUNCTION: ' . __FUNCTION__ . '] [LINE: ' . __LINE__ . "] [MESSAGE: Add new ticket failed - Database error"); //halt $next = false; } } //is there an attachment? - move the uploaded file into /files/tickets folder if ($next) { //do we have an attachemeny if ($this->input->post('tickets_file_folder')) { //move the attachments to final destination if (!tickets_move_attachment($this->input->post('tickets_file_folder'), $this->input->post('tickets_file_name'))) { //delete ticket $this->tickets_model->deleteTicket($ticket_id); $this->data['debug'][] = $this->tickets_model->debug_data; } } } //results if ($next) { //show success $this->notices('success', $this->data['lang']['lang_request_has_been_completed'], 'noty'); //send notifications $this->__emailer('mailqueue_new_ticket', array('ticket_id' => $ticket_id)); } else { //show error $this->notices('error', $this->data['lang']['lang_request_could_not_be_completed'], 'noty'); //noty or html } //show tickets list page $this->__listTickets(); }
/** * save new ticket * */ function __addReply() { //profiling $this->data['controller_profiling'][] = __FUNCTION__; //flow control $next = true; //check if any post data (avoid direct url access) if (!isset($_POST['submit'])) { redirect('/client/ticket/' . $this->uri->segment(3) . '/view'); } //validate form if ($next) { if (!$this->__flmFormValidation('add_reply')) { //show error $this->notices('error', $this->form_processor->error_message, 'html'); $next = false; } } //validate hidden fields if ($next) { if (!$this->__flmFormValidation('add_reply_hidden')) { //log this error log_message('error', '[FILE: ' . __FILE__ . '] [FUNCTION: ' . __FUNCTION__ . '] [LINE: ' . __LINE__ . "] [MESSAGE: Add ticket reply failed: Required hidden form fields are missing or invalid]"); //show error $this->notices('error', $this->data['lang']['lang_request_could_not_be_completed'], 'html'); $next = false; } } //SANITY: make sure client is replying to their own ticket //TODO //add to database if ($next) { //add ticket $ticket_id = $this->tickets_replies_model->addReply(); $this->data['debug'][] = $this->tickets_replies_model->debug_data; //check if there was an errro inserting record if (!$ticket_id) { //log this error log_message('error', '[FILE: ' . __FILE__ . '] [FUNCTION: ' . __FUNCTION__ . '] [LINE: ' . __LINE__ . "] [MESSAGE: Add ticket reply failed - Database error"); //halt $next = false; } } //attachments if ($next) { //is there an attachment? - move the uploaded file into /files/tickets folder if ($this->input->post('tickets_file_folder')) { //move the attachments to final destination if (!tickets_move_attachment($this->input->post('tickets_file_folder'), $this->input->post('tickets_file_name'))) { //delete ticket $this->tickets_replies_model->deleteReply($ticket_id); $this->data['debug'][] = $this->tickets_replies_model->debug_data; } } } //results if ($next) { //everything went ok, now update status of main ticket $this->tickets_model->updateStatus($this->input->post('tickets_replies_ticket_id'), 'client-replied'); $this->data['debug'][] = $this->tickets_model->debug_data; //show success $this->notices('success', $this->data['lang']['lang_request_has_been_completed'], 'noty'); //send email $this->__emailer('mailqueue_ticket_reply'); } else { //show error $this->notices('error', $this->data['lang']['lang_request_could_not_be_completed'], 'noty'); //noty or html } //show tickets list page $this->__viewTicket(); }