private function addEditHandler($p_sMode = 'create')
 {
     $this->loginCheck();
     $bEdit = $p_sMode === 'edit';
     $oTicket = new APP_Model_Ticket();
     $oForm = new PPI_Model_Form();
     $oForm->init('ticket_create');
     $oForm->disableSubmit();
     $oForm->setFormStructure($oTicket->getAddEditFormStructure($p_sMode, array('isAdmin' => $this->getAuthData(false)->role_name !== 'member')));
     // Get the ticket ID
     $iTicketID = $this->get($p_sMode, 0);
     if ($oForm->isSubmitted() && $oForm->isValidated()) {
         $aSubmitValues = $oForm->getSubmitValues();
         $aSubmitValues += array('status' => 'open', 'severity' => 'minor', 'assigned_user_id' => 0, 'user_id' => $this->getAuthData(false)->id, 'created' => time());
         if ($bEdit && $iTicketID > 0) {
             $oTicket->update($aSubmitValues, $oTicket->getPrimaryKey() . " = " . $oTicket->quote($iTicketID));
         } else {
             $iTicketID = $oTicket->insert($aSubmitValues);
         }
         $this->setFlashMessage('Ticket successfully ' . ($bEdit ? 'updated.' : 'created'));
         $this->redirect('ticket/view/' . $iTicketID . '/' . str_replace(' ', '-', $aSubmitValues['title']));
     }
     if ($p_sMode === 'edit' && $iTicketID > 0) {
         $oForm->setDefaults($oTicket->find($iTicketID));
     }
     $formBuilder = $oForm->getRenderInformation();
     $aTicket = $oTicket->find($iTicketID);
     $this->load('ticket/create', compact('aTicket', 'formBuilder'));
 }
Beispiel #2
0
 /**
  *
  * @param string $p_sMode The Mode (Create or Edit)
  * @return void
  */
 protected function ticketAddEdit($p_sMode = 'create')
 {
     $bEdit = $p_sMode == 'edit';
     $oTicket = new APP_Model_Ticket();
     $oForm = new PPI_Model_Form();
     $oForm->init('admin_ticket_addedit');
     $oForm->setFormStructure($oTicket->getAdminAddEditFormStructure($p_sMode));
     if ($oForm->isSubmitted() && $oForm->isValidated()) {
         $aSubmitValues = $oForm->getSubmitValues();
         if (!$bEdit) {
             $aSubmitValues['user_id'] = $this->getAuthData(false)->id;
             $aSubmitValues['created'] = time();
         }
         // Edit mode to set the primary key so that it performs an update
         if ($bEdit && ($iTicketID = $this->oInput->get($p_sMode)) > 0) {
             $aSubmitValues[$oTicket->getPrimaryKey()] = $iTicketID;
         }
         // Put the record (insert/update)
         $oTicket->putRecord($aSubmitValues);
         $this->setFlashMessage('Ticket successfully ' . ($bEdit ? 'updated' : 'created') . '.');
         $this->redirect('admin/ticket');
     }
     if ($bEdit === true) {
         if (($iTicketID = $this->oInput->get('edit', 0)) < 1) {
             throw new PPI_Exception('Invalid User ID: ' . $iTicketID);
         }
         // Set the defaults here
         $oForm->setDefaults($oTicket->find($iTicketID));
     }
     $aViewVars = array('bEdit' => $bEdit, 'formBuilder' => $oForm->getRenderInformation(), 'leftMenu' => true);
     $this->adminLoad('admin/ticket_addedit', $aViewVars);
 }