コード例 #1
0
ファイル: CommentController.php プロジェクト: syscover/forms
 public function storeCustomRecord($parameters)
 {
     $record = Record::find($this->request->input('ref'));
     $record->data_403 = json_decode($record->data_403);
     $form = $record->getForm;
     $state = $record->getState;
     $names = [];
     $usersEmails = [];
     $messages = [];
     $comment = Comment::create(['record_id_404' => $this->request->input('ref'), 'user_id_404' => auth('pulsar')->user()->id_010, 'date_404' => date('U'), 'subject_404' => $this->request->input('subject'), 'comment_404' => $this->request->input('comment')]);
     // check new recipients
     Miscellaneous::checkRecipients($record, $form);
     // get recipient emails to compare with new user email
     $recipients = Recipient::where('record_id_406', $this->request->input('ref'))->where('comments_406', true)->get();
     // set recipients
     foreach ($recipients as $recipient) {
         if ($recipient->email_406 != auth('pulsar')->user()->email_010) {
             $names[] = $recipient->name_406;
             $usersEmails[] = $recipient->email_406;
         }
     }
     // get users with the emails recipients
     $users = User::whereIn('email_010', $usersEmails)->get();
     $matchAuthor = false;
     foreach ($recipients as $recipient) {
         if ($recipient->email_406 == auth('pulsar')->user()->email_010) {
             $matchAuthor = true;
         } else {
             // send to all recipients less Author recipient
             // get user and permissions
             $matchUser = null;
             foreach ($users as $user) {
                 if ($user->email_010 == $recipient->email_406) {
                     $matchUser = $user;
                     break;
                 }
             }
             if ($matchUser != null) {
                 $userAcl = AclLibrary::getProfileAcl($matchUser->profile_id_010);
             }
             $messages[] = ['type_id_405' => 'comment', 'record_id_405' => $record->id_403, 'date_405' => date('U'), 'recipient_id_405' => $recipient->id_406, 'forward_405' => $recipient->forward_406, 'subject_405' => 'forms::pulsar.subject_comment', 'name_405' => $recipient->name_406, 'email_405' => $recipient->email_406, 'form_id_405' => $form->id_401, 'user_id_405' => $matchUser == null ? null : $matchUser->id_010, 'template_405' => 'forms::emails.comment', 'text_template_405' => 'forms::emails.text_comment', 'data_message_405' => json_encode(['name_form_405' => $form->name_401, 'author_comment_405' => auth('pulsar')->user()->name_010 . ' ' . auth('pulsar')->user()->surname_010, 'date_comment_405' => date(config('pulsar.datePattern')), 'subject_comment_405' => $comment->subject_404, 'comment_405' => $comment->comment_404, 'name_state_405' => $state->name_400, 'color_state_405' => $state->color_400, 'names_405' => implode(", ", $names), 'permission_state_405' => $matchUser == null ? false : $userAcl->allows('forms-record', 'edit', $matchUser->profile_id_010), 'permission_comment_405' => $matchUser == null ? false : $userAcl->allows('forms-comment', 'create', $matchUser->profile_id_010), 'permission_forward_405' => $matchUser == null ? false : $userAcl->allows('forms-form', 'edit', $matchUser->profile_id_010), 'permission_record_405' => $matchUser == null ? false : $userAcl->allows('forms-record', 'show', $matchUser->profile_id_010)]), 'data_405' => json_encode($record->toArray())];
         }
     }
     if (!$matchAuthor) {
         // Include Author to recipients but not forward
         Recipient::create(['record_id_406' => $record->id_403, 'forward_406' => false, 'name_406' => auth('pulsar')->user()->name_010 . ' ' . auth('pulsar')->user()->surname_010, 'email_406' => auth('pulsar')->user()->email_010, 'comments_406' => true, 'states_406' => true]);
     }
     if (count($messages) > 0) {
         Message::insert($messages);
     }
     $parameters['redirectParentJs'] = true;
     return $parameters;
 }
コード例 #2
0
ファイル: Record.php プロジェクト: syscover/forms
 public function customCount($request, $parameters)
 {
     return Record::where('form_id_403', $parameters['form']);
 }
コード例 #3
0
ファイル: RecordController.php プロジェクト: syscover/forms
 /**
  *  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'));
     }
 }