예제 #1
0
 public function save()
 {
     $flash = Flash::Instance();
     if (parent::save('CSFailureCode')) {
         sendTo($this->name, 'index', $this->_modules);
     } else {
         $this->refresh();
     }
 }
 public function save()
 {
     $flash = Flash::Instance();
     $errors = array();
     if (parent::save('ReportDefinition', '', $errors)) {
         sendBack();
     } else {
         $flash->addErrors($errors);
         sendBack();
     }
 }
예제 #3
0
 public function save()
 {
     $flash = Flash::Instance();
     $errors = array();
     $this->_data['ReportPart']['name'] = strtolower($this->_data['ReportPart']['name']);
     if (parent::save('ReportPart', '', $errors)) {
         sendBack();
     } else {
         $flash->addErrors($errors);
         sendBack();
     }
 }
예제 #4
0
 protected function save_model($modelName, $dataIn = array(), &$errors = array())
 {
     return parent::save($modelName, $dataIn, $errors);
 }
예제 #5
0
 public function save_response()
 {
     // sort the data out
     if (isset($this->_data['response'])) {
         $this->_data['TicketResponse']['body'] = $this->_data['response'];
         $this->_data['TicketResponse']['ticket_id'] = $this->_data['ticket_id'];
         $this->_data['TicketResponse']['type'] = 'site';
     }
     $save = parent::save('TicketResponse', $this->_data['TicketResponse']);
     $ticket = new Ticket();
     $ticket->load($this->_data['TicketResponse']['ticket_id']);
     $plateout = TicketingUtils::StatusPlate($ticket);
     $headers = array('From' => TicketingUtils::getReplyAddress($ticket));
     $hours_data =& $this->_data['Hour'];
     if (isset($hours_data['duration']) && $hours_data['duration'] != 0) {
         if ($hours_data['duration_unit'] == 'days') {
             $hours_data['duration'] = $hours_data['duration'] * SystemCompanySettings::DAY_LENGTH;
         }
         // Calculate start time by working backward NB: Needs changing with date_format?
         $hours_data['start_time'] = date("d/m/Y H:i", time() - $hours_data['duration'] * 60 * 60);
         $hours_data['duration'] .= ' hours';
         parent::save('Hour');
     }
     // FIXME: If someone forces a file upload... I guess that causes this code to randomly send the file?
     if ($_FILES['file']['size'] > 0) {
         // Send MIME mail
         $boundary = 'EGS-Ticketing-System-' . base_convert(rand(1000, 9000), 10, 2);
         $headers['Content-Type'] = 'multipart/mixed; boundary=' . $boundary;
         $base64 = base64_encode(file_get_contents($_FILES['file']['tmp_name']));
         // Yay, hand written MIME email!
         $body = "--{$boundary}\r\n" . "Content-Transfer-Encoding: 8bit\r\n" . "Content-Type: text/plain; charset=ISO-8859-1\r\n" . "\r\n" . $plateout . $this->_data['TicketResponse']['body'] . "\r\n" . "\r\n" . "--{$boundary}\r\n" . 'Content-Type: octet/stream; name="' . $_FILES['file']['name'] . '"' . "\r\n" . "Content-Transfer-Encoding: base64\r\n" . 'Content-Disposition: attachment; filename="' . $_FILES['file']['name'] . '"' . "\r\n" . "\r\n" . chunk_split($base64) . "\r\n" . "\r\n" . "--{$boundary}--\r\n" . ".";
         $errors = array();
         $file = File::Factory($_FILES['file'], $errors, new File());
         $file->save();
         $ticketAttachment = TicketAttachment::Factory(array('ticket_id' => $this->_data['TicketResponse']['ticket_id'], 'file_id' => $file->id), $errors, new TicketAttachment());
         $ticketAttachment->save();
     } else {
         // No attachment, send plain text mail
         $body = $plateout . $this->_data['TicketResponse']['body'];
     }
     $header_string = "";
     foreach ($headers as $header => $value) {
         $header_string .= $header . ': ' . $value . "\r\n";
     }
     // FIXME: Do this further up
     if (!isset($this->_data['TicketResponse']['internal']) || isset($this->_data['TicketResponse']['internal']) && $this->_data['TicketResponse']['internal'] != 'on') {
         $recipients = TicketingUtils::GetRecipients($ticket);
         foreach ($recipients as $recipient) {
             mail($recipient, 're: [' . $ticket->ticket_queue_id . '-' . $ticket->id . '] ' . $ticket->summary, $body, $header_string);
         }
     }
     if (is_ajax()) {
         echo json_encode(array('success' => $save));
         exit;
     } else {
         sendTo('Tickets', 'view', array('ticketing'), array('id' => $this->_data['TicketResponse']['ticket_id']));
     }
 }
예제 #6
0
 public function save()
 {
     $flash = Flash::Instance();
     // this is going to be a prodomintely (sp?) ajax save... effectively we're
     // not moving away from the page if we have an error... this is the best way
     // to preserve such a delicate form like this
     // set a few vars
     $normal_field_exists = FALSE;
     // ensure we have some fields
     if (!isset($this->_data['Report']['options']) or empty($this->_data['Report']['options'])) {
         echo $this->returnResponse(FALSE, array('message' => '<li>No fields specified</li>'));
         exit;
     }
     // loop through fields, check if any are of NORMAL type
     foreach ($this->_data['Report']['options'] as $field => $options) {
         // remember, if the field type doesn't exist it's default is 'normal'
         if (!isset($options['field_type']) or $options['field_type']) {
             $normal_field_exists = TRUE;
             break;
             // no point in continuing
         }
     }
     // if the normal fields exists status hasn't changed, throw the error
     if ($normal_field_exists === FALSE) {
         echo $this->returnResponse(FALSE, array('message' => '<li>No normal fields specified</li>'));
         exit;
     }
     // serialise the report options back to itself
     $this->_data['Report']['options'] = serialize($this->_data['Report']['options']);
     // remove the id if we want to save as a copy, a new id (and thus the record) will be generated
     if (strtolower($this->_data['save']) == 'save copy') {
         unset($this->_data['Report']['id']);
     }
     // Set the rpeort definition id, unless Default was selected
     if ($this->_data['report_def'] != 'Default') {
         $def = new ReportDefinition();
         $rdef = $def->getDefinition($this->_data['report_def']);
         $this->_data['Report']['report_definition'] = $rdef->_data['id'];
     }
     // fire up the db
     $db = DB::Instance();
     $db->StartTrans();
     // post data, output status
     if (parent::save($this->modeltype)) {
         $db->CompleteTrans();
         $link = sprintf('/?module=%s&controller=%s&action=%s&id=%s', $this->module, $this->name, 'view', $this->saved_model->id);
         echo $this->returnResponse(TRUE, array('redirect' => $link));
         exit;
     } else {
         $db->FailTrans();
         $db->CompleteTrans();
         // get the errors
         $flash->save();
         $errors = $flash->__get('errors');
         $flash->clear();
         $message = '<li>Failed to save Report</li>';
         if (!empty($errors)) {
             foreach ($errors as $error) {
                 $message .= "<li>" . $error . "</li>";
             }
         }
         echo $this->returnResponse(FALSE, array('message' => $message));
         exit;
     }
 }
예제 #7
0
 public function save()
 {
     $flash = Flash::Instance();
     $errors = array();
     // delete any existing uzlet / module relationships
     if (isset($this->_data['Uzlet']['id']) && !empty($this->_data['Uzlet']['id'])) {
         $uzlet_modules = new UzletModuleCollection(DataObjectFactory::Factory('UzletModule'));
         $sh = new SearchHandler($uzlet_modules, false);
         $sh->addConstraint(new Constraint('uzlet_id', '=', $this->_data['Uzlet']['id']));
         $uzlet_modules->delete($sh);
     }
     // apply uzlet_id to UzletModulesCollection
     if (isset($this->_data['UzletModuleCollection']) && !empty($this->_data['UzletModuleCollection']['module_id'])) {
         foreach ($this->_data['UzletModuleCollection']['module_id'] as $key => $value) {
             $this->_data['UzletModuleCollection']['uzlet_id'][$key] = '';
         }
     }
     // delete any existing calls
     if (isset($this->_data['Uzlet']['id']) && !empty($this->_data['Uzlet']['id'])) {
         $uzlet_calls = new UzletCallCollection(DataObjectFactory::Factory('UzletCall'));
         $sh = new SearchHandler($uzlet_calls, false);
         $sh->addConstraint(new Constraint('uzlet_id', '=', $this->_data['Uzlet']['id']));
         $uzlet_calls->delete($sh);
     }
     // prepare the call field
     if (isset($this->_data['UzletCallCollection']['Call']) && $this->_data['UzletCallCollection']['Call'] != '') {
         // split up the call field by line
         $arr = explode("\n", $this->_data['UzletCallCollection']['Call']);
         foreach ($arr as $key => $value) {
             // we're not interested in empty lines
             $empty_test = trim($value);
             if (!empty($empty_test)) {
                 $pieces = explode(":", $value);
                 // we're also only interested if we have two pieces to work with
                 // actually we're interested if we have MORE THAN 2 parts, the arguement might be json for example
                 if (count($pieces) >= 2) {
                     $this->_data['UzletCallCollection']['uzlet_id'][$key] = '';
                     $this->_data['UzletCallCollection']['func'][$key] = $pieces[0];
                     // remove the function from the array, bind all the remaining part back together
                     // this will preserve any parameter that contains JSON etc (well, anything with a ":")
                     unset($pieces[0]);
                     $this->_data['UzletCallCollection']['arg'][$key] = implode(':', $pieces);
                 }
             }
         }
         unset($this->_data['UzletCallCollection']['Call']);
     } else {
         unset($this->_data['UzletCallCollection']);
     }
     if (parent::save('Uzlet', '', $errors)) {
         sendBack();
     } else {
         $flash->addErrors($errors);
         sendBack();
     }
 }