Example #1
0
 public function updateCustomRecord($parameters)
 {
     Form::where('id_401', $parameters['id'])->update(['name_401' => $this->request->input('name'), 'email_account_id_401' => $this->request->input('emailAccount'), 'push_notification_401' => $this->request->has('pushNotification')]);
     $forwardsData = json_decode($this->request->input('forwardsData'));
     $ids = [];
     foreach ($forwardsData as $forwardData) {
         if (isset($forwardData->id_402)) {
             $ids[] = $forwardData->id_402;
             Forward::where('id_402', $forwardData->id_402)->update(["name_402" => $forwardData->name_402, "email_402" => trim(strtolower($forwardData->email_402)), "comments_402" => $forwardData->comments_402, "states_402" => $forwardData->states_402]);
         } else {
             $forwards[] = ["form_id_402" => $parameters['id'], "name_402" => $forwardData->name_402, "email_402" => trim(strtolower($forwardData->email_402)), "comments_402" => $forwardData->comments_402, "states_402" => $forwardData->states_402];
         }
     }
     if (count($ids) > 0) {
         // to delete forwards the we have delete
         Forward::whereNotIn('id_402', $ids)->delete();
     }
     if (isset($forwards) && count($forwards) > 0) {
         Forward::insert($forwards);
     }
 }
Example #2
0
 public function getForwards()
 {
     return Form::hasMany('Syscover\\Forms\\Models\\Forward', 'form_id_402');
 }
Example #3
0
 /**
  *  Function to record a data form
  *
  * @access	public
  * @return  json | \Illuminate\Http\RedirectResponse
  */
 public function recordForm()
 {
     $fields = json_decode($this->request->input('_fields'));
     $form = Form::find(Crypt::decrypt($this->request->input('_tokenForm')));
     $forwards = $form->getForwards;
     $recipients = [];
     $names = [];
     $messages = [];
     $recordDate = date('U');
     // test that, there are any form
     if ($form == null) {
         $response = ['success' => false, 'message' => "Form don't exist"];
         return response()->json($response);
     }
     $data = [];
     foreach ($fields->data as $field) {
         $obj = ['type' => $field->type, 'name' => $field->name, 'value' => $this->request->input($field->name)];
         if (isset($field->length)) {
             $obj['length'] = $field->length;
         }
         if (isset($field->label)) {
             $obj['label'] = $field->label;
         }
         $data[] = $obj;
     }
     $defaultState = Preference::getValue('formsDefaultState', 4);
     $dataRecord = ['form_id_403' => $form->id_401, 'date_403' => $recordDate, 'date_text_403' => date(config('pulsar.datePattern'), $recordDate), 'state_id_403' => $defaultState->value_018, 'subject_403' => $this->request->input($fields->subject, null), 'name_403' => $this->request->input($fields->name, null), 'surname_403' => $this->request->input($fields->surname, null), 'company_403' => $this->request->input($fields->company, null), 'email_403' => $this->request->input($fields->email, null), 'data_403' => json_encode($data)];
     $record = Record::create($dataRecord);
     $state = $record->getState;
     // set data with array with decode information to make $dataRecord for message
     $dataRecord['data_403'] = $data;
     // set ID record
     $dataRecord['id_403'] = $record->id_403;
     // set records unopened
     $form->n_unopened_401 = Record::where('form_id_403', $form->id_401)->where('opened_403', false)->count();
     $form->save();
     foreach ($forwards as $forward) {
         // set recipients from forwards to sow in the email message
         $names[] = $forward->name_402;
         $recipients[] = ['record_id_406' => $record->id_403, 'forward_406' => true, 'name_406' => $forward->name_402, 'email_406' => $forward->email_402, 'comments_406' => $forward->comments_402, 'states_406' => $forward->states_402];
     }
     if (count($recipients) > 0) {
         Recipient::insert($recipients);
     }
     // get recipient emails to compare with new user email
     $recipients = $record->getRecipients;
     foreach ($recipients as $recipient) {
         // get user and permissions
         $user = User::where('email_010', $recipient->email_406)->first();
         if ($user != null) {
             $userAcl = AclLibrary::getProfileAcl($user->profile_id_010);
         }
         $messages[] = ['type_id_405' => 'record', 'record_id_405' => $record->id_403, 'date_405' => date('U'), 'recipient_id_405' => $recipient->id_406, 'forward_405' => true, 'subject_405' => 'forms::pulsar.subject_email_record', 'name_405' => $recipient->name_406, 'email_405' => $recipient->email_406, 'form_id_405' => $form->id_401, 'user_id_405' => $user == null ? null : $user->id_010, 'template_405' => 'forms::emails.record', 'text_template_405' => 'forms::emails.text_record', 'data_message_405' => json_encode(['name_form_405' => $form->name_401, 'name_state_405' => $state->name_400, 'color_state_405' => $state->color_400, 'names_405' => implode(", ", $names), 'permission_state_405' => $user == null ? false : $userAcl->allows('forms-record', 'edit', $user->profile_id_010), 'permission_comment_405' => $user == null ? false : $userAcl->allows('forms-comment', 'create', $user->profile_id_010), 'permission_forward_405' => $user == null ? false : $userAcl->allows('forms-form', 'edit', $user->profile_id_010), 'permission_record_405' => $user == null ? false : $userAcl->allows('forms-record', 'show', $user->profile_id_010)]), 'data_405' => json_encode($dataRecord)];
     }
     if (count($messages) > 0) {
         Message::insert($messages);
     }
     if ($this->request->input('_redirectOk') == '') {
         $response = ['success' => true, 'form' => ['date_403' => $recordDate, 'date_text_403' => date(config('pulsar.datePattern'), $recordDate), 'subject_403' => $this->request->input($fields->subject, null), 'state_id_403' => $defaultState->value_018, 'name_403' => $this->request->input($fields->name, null), 'surname_403' => $this->request->input($fields->surname, null), 'company_403' => $this->request->input($fields->company, null), 'email_403' => $this->request->input($fields->email, null), 'data_403' => json_encode($data)]];
         return response()->json($response);
     } else {
         return redirect($this->request->input('_redirectOk'));
     }
 }