public function check(Request $request)
 {
     dd($_POST);
     $request->all();
     $form = new Form();
     $form->username = $request->username;
     $form->telephon = $request->telephone;
     $form->email = $request->email;
     $form->save();
     return redirect('/');
 }
Пример #2
0
 public function postForm(Request $request)
 {
     $validator = Validator::make($request->all(), ['name' => 'required|max:35|min:2', 'phone' => 'required|max:15', 'email' => 'required|email|max:100|unique:users', 'g-recaptcha-response' => 'required|recaptcha']);
     if ($validator->fails()) {
         return redirect('/')->withInput()->withErrors($validator);
     }
     $form = new Form();
     $form->name = $request->name;
     $form->telephone = $request->phone;
     $form->email = $request->email;
     $form->save();
     return redirect('/');
 }
Пример #3
0
 public function destroy($form_slug, $field_slug)
 {
     $form = Form::where('slug', $form_slug)->firstOrFail();
     $field = $form->fields()->where('slug', $field_slug)->firstOrFail();
     $field->delete();
     return redirect()->route('admin.forms.edit', $form->slug)->with('message', trans('field.message.delete_success'));
 }
Пример #4
0
 public static function getReport($form_id)
 {
     $report = new Report();
     $report->title = 'Standard Report';
     $report->form_id = $form_id;
     $form = Form::findOrFail($form_id);
     $reportFields = [];
     $reportFields['reportFields'] = [];
     $reportFields['form'] = $form_id;
     foreach ($form->fields as $field) {
         $reportFields['reportFields'][$field->id]['fieldId'] = $field->id;
         $reportFields['reportFields'][$field->id]['display'] = 'text';
         switch ($field->type) {
             case 'number':
                 $reportFields['reportFields'][$field->id]['reportType'] = 'numMean';
                 break;
             default:
                 $reportFields['reportFields'][$field->id]['reportType'] = 'frequency';
                 break;
         }
         $reportFields['reportFields'] = array_values($reportFields['reportFields']);
     }
     $report->rules = json_encode($reportFields);
     return $report;
 }
Пример #5
0
 /**
  * Show the form responses for a given slug.
  *
  * @param  string  $slug
  * @return Response
  */
 public function responses($slug)
 {
     die('@TODO: Not working yet.');
     $form = \App\Form::where('slug', '=', $slug)->firstOrFail();
     $responses = \App\Response::where('form_id', '=', $form->id)->get();
     return view('forms.responses', array('fields' => $form->fields, 'responses' => $responses));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['prompt' => 'required|max:100|unique_with:forms, formgroup = form_group_id, formtype = form_type_id', 'formgroup' => 'required|not_in:0', 'formtype' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $form = new Form();
         $form->form_group_id = $request->formgroup;
         $form->form_type_id = $request->formtype;
         $form->prompt = $request->prompt;
         $form->required = $request->required == '1' ? 1 : 0;
         $form->expected_answer = $request->expected_answer == '1' ? 1 : 0;
         $form->exempt = $request->exempt == '1' ? 1 : 0;
         $form->save();
         if ($request->formtype == 9) {
             $multiData = array();
             foreach ($request->multiselect as $option) {
                 $multiData[] = array('form_id' => $form->id, 'multi_select_id' => $option);
             }
             if (count($multiData) > 0) {
                 FormMultiSelect::insert($multiData);
             }
         }
         if ($request->formtype == 10) {
             $singleData = array();
             foreach ($request->singleselect as $option) {
                 $singleData[] = array('form_id' => $form->id, 'single_select_id' => $option);
             }
             if (count($singleData) > 0) {
                 FormSingleSelect::insert($singleData);
             }
         }
         if ($request->formtype == 11) {
             if ($request->has('formula')) {
                 $formformula = new FormFormula();
                 $formformula->form_id = $form->id;
                 $formformula->formula = $request->formula;
                 $formformula->save();
             }
         }
         \DB::commit();
         Session::flash('flash_message', 'Form successfully added!');
         return redirect()->route("form.index");
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
Пример #7
0
 public function store(Request $request, $id)
 {
     $user = \Auth::user();
     $form = Form::findorfail($id);
     $input = Request::all();
     Message::create(['user_id' => $user['id'], 'form_id' => $form['id'], 'content' => $input['content'], 'type' => $input['type']]);
     return redirect('/form');
 }
Пример #8
0
 public function update($id)
 {
     $lines = Line::all();
     $forms = Form::all();
     $product = Product::findOrFail($id);
     $dataView = ['product' => $product, 'lines' => $lines, 'forms' => $forms];
     return view('admin.product.edit', $dataView);
 }
Пример #9
0
 public function store(Request $request, $id)
 {
     $user = \Auth::user();
     $input = Request::all();
     $forms = Form::findorfail($id);
     Comment::create(['content' => $input['content'], 'user_id' => $user->id, 'form_id' => $forms->id]);
     return redirect(url('/form', $id));
 }
Пример #10
0
 public function getRecordArray(Request $request)
 {
     $id = $request->id;
     $rid = RecordPreset::where('id', '=', $id)->first()->rid;
     $record = Record::where('rid', '=', $rid)->first();
     $form = Form::where('fid', '=', $record->fid)->first();
     $field_collect = $form->fields()->get();
     $field_array = array();
     foreach ($field_collect as $field) {
         $data = array();
         $data['flid'] = $field->flid;
         $data['type'] = $field->type;
         if ($field->type == 'Text') {
             $textfield = TextField::where('rid', '=', $record->rid)->first();
             $data['text'] = $textfield->text;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Rich Text') {
             $rtfield = RichTextField::where('rid', '=', $record->rid)->first();
             $data['rawtext'] = $rtfield->rawtext;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Number') {
             $numberfield = NumberField::where('rid', '=', $record->rid)->first();
             $data['number'] = $numberfield->number;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'List') {
             $listfield = ListField::where('rid', '=', $record->rid)->first();
             $data['option'] = $listfield->option;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Multi-Select List') {
             $mslfield = MultiSelectListField::where('rid', '=', $record->rid)->first();
             $data['options'] = explode('[!]', $mslfield->options);
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Generated List') {
             $gnlfield = GeneratedListField::where('rid', '=', $record->rid)->first();
             $data['options'] = explode('[!]', $gnlfield->options);
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Date') {
             $datefield = DateField::where('rid', '=', $record->rid)->first();
             $date_array['circa'] = $datefield->circa;
             $date_array['era'] = $datefield->era;
             $date_array['day'] = $datefield->day;
             $date_array['month'] = $datefield->month;
             $date_array['year'] = $datefield->year;
             $data['data'] = $date_array;
             $flid_array[] = $field->flid;
         } elseif ($field->type == 'Schedule') {
             $schedfield = ScheduleField::where('rid', '=', $record->rid)->first();
             $data['events'] = explode('[!]', $schedfield->events);
             $flid_array[] = $field->flid;
         }
         $field_array[$field->flid] = $data;
     }
     $response['data'] = $field_array;
     $response['flids'] = $flid_array;
     return $response;
 }
Пример #11
0
 public function doDelete($id)
 {
     $form = Form::findOrFail($id);
     try {
         $form->delete();
         return redirect()->back()->with('message', 'Form has been deleted successfully !');
     } catch (ParseException $ex) {
         echo 'Failed to create new meal , with error message: ' . $ex->getMessage();
     }
 }
Пример #12
0
 /**
  * returns an array with each verb person label
  */
 public function getPersonArray()
 {
     //query forms table for all values
     $forms = \App\Form::all();
     //initialize array to store values from forms table
     $person_array = [];
     foreach ($forms as $form) {
         $person_array[$form->id] = $form->person;
     }
     return $person_array;
 }
Пример #13
0
 public function postSelected(Request $request, $form_code)
 {
     $randomCode = Auth::id() . mt_rand(0, 999) . time();
     $form = Form::where('form_code', $form_code)->where('form_type', 'template')->where('form_active', '1')->firstOrFail();
     $form->update(['form_copy' => $form->form_copy + 1]);
     $formCopy = Form::create(['form_cuid' => Auth::id(), 'form_type' => 'normal', 'form_code' => $randomCode, 'form_active' => 0, 'form_title' => $form->form_title, 'form_summary' => $form->form_summary, 'form_sort' => 0, 'form_url' => $randomCode, 'form_tips_email' => 0, 'form_limit_auz' => 'allow_all']);
     foreach ($form->Field()->get() as $field) {
         $fieldCopy = Field::create(['field_cuid' => Auth::id(), 'field_form_id' => $formCopy->form_id, 'field_sort' => $field->field_sort, 'field_type' => $field->field_type, 'field_title' => $field->field_title, 'field_tips' => $field->field_tips, 'field_attr_name' => Auth::id() . mt_rand(0, 999) . time() . mt_rand(0, 999), 'field_attr_value' => $field->field_attr_value, 'field_attr_width' => $field->field_attr_width, 'field_must' => $field->field_must]);
         foreach ($field->FieldChildren()->get() as $fieldchildren) {
             FieldChildren::create(['fieldchildren_field_id' => $fieldCopy->field_id, 'fieldchildren_key' => $fieldchildren->fieldchildren_key, 'fieldchildren_value' => $fieldchildren->fieldchildren_value, 'fieldchildren_value2' => $fieldchildren->fieldchildren_value2, 'fieldchildren_value3' => $fieldchildren->fieldchildren_value3, 'fieldchildren_img_id' => $fieldchildren->fieldchildren_img_id, 'fieldchildren_checked' => $fieldchildren->fieldchildren_checked, 'fieldchildren_disabled' => $fieldchildren->fieldchildren_disabled]);
         }
     }
     $res = redirect('/form/info/' . $formCopy->form_code)->with('msgSuccess', '此表单模板已经添加到您的表单中心当中');
     return $res;
 }
Пример #14
0
 public function getIndex(Request $request)
 {
     User::createTable();
     // User::createAdmin('*****@*****.**','admin');
     Img::createTable();
     Mylog::createTable();
     Email::createTable();
     Banner::createTable();
     Activity::createTable();
     Form::createTable();
     Field::createTable();
     FieldChildren::createTable();
     Result::createTable();
     ResultRow::createTable();
     Charge::createTable();
 }
Пример #15
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     // Delete all records
     Submission::whereNotNull('id')->delete();
     Form::whereNotNull('id')->delete();
     $form1 = Form::create(['slug' => 'the-test', 'title' => 'Nice test Form']);
     $form1->fields()->save(new Field(['slug' => 'name', 'title' => 'Name', 'rules' => 'required|string']));
     $form1->fields()->save(new Field(['slug' => 'rating', 'title' => 'Rating', 'rules' => 'required|integer|min:1|max:5']));
     $form2 = Form::create(['slug' => 'test-with-email-confirmation', 'title' => 'Test that sends email confirmation', 'confirmation_message' => 'Thanks for the message !', 'confirmation_email_field' => 'email', 'owner_email' => '*****@*****.**', 'owner_name' => 'That Company']);
     $form2->fields()->save(new Field(['slug' => 'email', 'title' => 'Email', 'rules' => 'required|email']));
     Form::create(['slug' => 'test-with-email-notification', 'title' => 'Test with email notification', 'send_email_to' => 'john@example.com,max@example.com', 'owner_email' => '*****@*****.**', 'owner_name' => 'That Company']);
     Form::create(['slug' => 'test-with-redirect', 'title' => 'Test with a redirect', 'redirect_to_url' => 'https://example.com/']);
     Form::create(['slug' => 'test-closed', 'title' => 'Closed form test', 'accept_submissions' => false]);
     Eloquent::reguard();
 }
Пример #16
0
 public function run()
 {
     $uploads = public_path('images/uploads');
     $filesObj = \Symfony\Component\Finder\Finder::create()->files()->in($uploads);
     $files = [];
     foreach ($filesObj as $file) {
         $files[] = $file->getFilename();
     }
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 5; $i++) {
         $image = $faker->optional()->randomElement($files);
         $images = [];
         $imagesCount = mt_rand(0, 3);
         for ($j = 0; $j < $imagesCount; $j++) {
             $img = $faker->randomElement($files);
             $images[] = 'images/uploads/' . $img;
         }
         \App\Form::create(['title' => $faker->sentence(4), 'textaddon' => $faker->sentence(2), 'checkbox' => $faker->boolean(), 'date' => $faker->date(), 'time' => $faker->time(), 'timestamp' => $faker->dateTime, 'image' => is_null($image) ? $image : 'images/uploads/' . $image, 'images' => $images, 'select' => $faker->optional()->randomElement([1, 2, 3]), 'textarea' => $faker->paragraph(5), 'ckeditor' => $faker->paragraph(5)]);
     }
 }
Пример #17
0
 /**
  *
  * Mass assign a value to many records at once, similar to update, but loops through all of them
  *
  * @param $pid
  * @param $fid
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function massAssignRecords($pid, $fid, Request $request)
 {
     if (!$this->checkPermissions($fid, 'modify')) {
         return redirect()->back();
     }
     $flid = $request->input("field_selection");
     if (!is_numeric($flid)) {
         flash()->overlay("That is not a valid field");
         return redirect()->back();
     }
     if ($request->has($flid)) {
         $form_field_value = $request->input($flid);
         //Note this only works when there is one form element being submitted, so if you have more, check Date
     } else {
         flash()->overlay("You didn't provide a value to assign to the records", "Whoops.");
         return redirect()->back();
     }
     if ($request->has("overwrite")) {
         $overwrite = $request->input("overwrite");
         //Overwrite field in all records, even if it has data
     } else {
         $overwrite = 0;
     }
     $field = Field::find($flid);
     foreach (Form::find($fid)->records()->get() as $record) {
         if ($field->type == "Text") {
             $matching_record_fields = $record->textfields()->where("flid", '=', $flid)->get();
             $record->updated_at = Carbon::now();
             $record->save();
             if ($matching_record_fields->count() > 0) {
                 $textfield = $matching_record_fields->first();
                 if ($overwrite == true || $textfield->text == "" || is_null($textfield->text)) {
                     $revision = RevisionController::storeRevision($record->rid, 'edit');
                     $textfield->text = $form_field_value;
                     $textfield->save();
                     $revision->oldData = RevisionController::buildDataArray($record);
                     $revision->save();
                 } else {
                     continue;
                 }
             } else {
                 $tf = new TextField();
                 $revision = RevisionController::storeRevision($record->rid, 'edit');
                 $tf->flid = $field->flid;
                 $tf->rid = $record->rid;
                 $tf->text = $form_field_value;
                 $tf->save();
                 $revision->oldData = RevisionController::buildDataArray($record);
                 $revision->save();
             }
         } elseif ($field->type == "Rich Text") {
             $matching_record_fields = $record->richtextfields()->where("flid", '=', $flid)->get();
             $record->updated_at = Carbon::now();
             $record->save();
             if ($matching_record_fields->count() > 0) {
                 $richtextfield = $matching_record_fields->first();
                 if ($overwrite == true || $richtextfield->rawtext == "" || is_null($richtextfield->rawtext)) {
                     $revision = RevisionController::storeRevision($record->rid, 'edit');
                     $richtextfield->rawtext = $form_field_value;
                     $richtextfield->save();
                     $revision->oldData = RevisionController::buildDataArray($record);
                     $revision->save();
                 } else {
                     continue;
                 }
             } else {
                 $rtf = new RichTextField();
                 $revision = RevisionController::storeRevision($record->rid, 'edit');
                 $rtf->flid = $field->flid;
                 $rtf->rid = $record->rid;
                 $rtf->rawtext = $form_field_value;
                 $rtf->save();
                 $revision->oldData = RevisionController::buildDataArray($record);
                 $revision->save();
             }
         } elseif ($field->type == "Number") {
             $matching_record_fields = $record->numberfields()->where("flid", '=', $flid)->get();
             $record->updated_at = Carbon::now();
             $record->save();
             if ($matching_record_fields->count() > 0) {
                 $numberfield = $matching_record_fields->first();
                 if ($overwrite == true || $numberfield->number == "" || is_null($numberfield->number)) {
                     $revision = RevisionController::storeRevision($record->rid, 'edit');
                     $numberfield->number = $form_field_value;
                     $numberfield->save();
                     $revision->oldData = RevisionController::buildDataArray($record);
                     $revision->save();
                 } else {
                     continue;
                 }
             } else {
                 $nf = new NumberField();
                 $revision = RevisionController::storeRevision($record->rid, 'edit');
                 $nf->flid = $field->flid;
                 $nf->rid = $record->rid;
                 $nf->number = $form_field_value;
                 $nf->save();
                 $revision->oldData = RevisionController::buildDataArray($record);
                 $revision->save();
             }
         } elseif ($field->type == "List") {
             $matching_record_fields = $record->listfields()->where("flid", '=', $flid)->get();
             $record->updated_at = Carbon::now();
             $record->save();
             if ($matching_record_fields->count() > 0) {
                 $listfield = $matching_record_fields->first();
                 if ($overwrite == true || $listfield->option == "" || is_null($listfield->option)) {
                     $revision = RevisionController::storeRevision($record->rid, 'edit');
                     $listfield->option = $form_field_value;
                     $listfield->save();
                     $revision->oldData = RevisionController::buildDataArray($record);
                     $revision->save();
                 } else {
                     continue;
                 }
             } else {
                 $lf = new ListField();
                 $revision = RevisionController::storeRevision($record->rid, 'edit');
                 $lf->flid = $field->flid;
                 $lf->rid = $record->rid;
                 $lf->option = $form_field_value;
                 $lf->save();
                 $revision->oldData = RevisionController::buildDataArray($record);
                 $revision->save();
             }
         } elseif ($field->type == "Multi-Select List") {
             $matching_record_fields = $record->multiselectlistfields()->where("flid", '=', $flid)->get();
             $record->updated_at = Carbon::now();
             $record->save();
             if ($matching_record_fields->count() > 0) {
                 $multiselectlistfield = $matching_record_fields->first();
                 if ($overwrite == true || $multiselectlistfield->options == "" || is_null($multiselectlistfield->options)) {
                     $revision = RevisionController::storeRevision($record->rid, 'edit');
                     $multiselectlistfield->options = implode("[!]", $form_field_value);
                     $multiselectlistfield->save();
                     $revision->oldData = RevisionController::buildDataArray($record);
                     $revision->save();
                 } else {
                     continue;
                 }
             } else {
                 $mslf = new MultiSelectListField();
                 $revision = RevisionController::storeRevision($record->rid, 'edit');
                 $mslf->flid = $field->flid;
                 $mslf->rid = $record->rid;
                 $mslf->options = implode("[!]", $form_field_value);
                 $mslf->save();
                 $revision->oldData = RevisionController::buildDataArray($record);
                 $revision->save();
             }
         } elseif ($field->type == "Generated List") {
             $matching_record_fields = $record->generatedlistfields()->where("flid", '=', $flid)->get();
             $record->updated_at = Carbon::now();
             $record->save();
             if ($matching_record_fields->count() > 0) {
                 $generatedlistfield = $matching_record_fields->first();
                 if ($overwrite == true || $generatedlistfield->options == "" || is_null($generatedlistfield->options)) {
                     $revision = RevisionController::storeRevision($record->rid, 'edit');
                     $generatedlistfield->options = implode("[!]", $form_field_value);
                     $generatedlistfield->save();
                     $revision->oldData = RevisionController::buildDataArray($record);
                     $revision->save();
                 } else {
                     continue;
                 }
             } else {
                 $glf = new GeneratedListField();
                 $revision = RevisionController::storeRevision($record->rid, 'edit');
                 $glf->flid = $field->flid;
                 $glf->rid = $record->rid;
                 $glf->options = implode("[!]", $form_field_value);
                 $glf->save();
                 $revision->oldData = RevisionController::buildDataArray($record);
                 $revision->save();
             }
         } elseif ($field->type == "Date") {
             $matching_record_fields = $record->datefields()->where("flid", '=', $flid)->get();
             $record->updated_at = Carbon::now();
             $record->save();
             if ($matching_record_fields->count() > 0) {
                 $datefield = $matching_record_fields->first();
                 if ($overwrite == true || $datefield->month == "" || is_null($datefield->month)) {
                     $revision = RevisionController::storeRevision($record->rid, 'edit');
                     $datefield->circa = $request->input('circa_' . $flid, '');
                     $datefield->month = $request->input('month_' . $flid);
                     $datefield->day = $request->input('day_' . $flid);
                     $datefield->year = $request->input('year_' . $flid);
                     $datefield->era = $request->input('era_' . $flid, 'CE');
                     $datefield->save();
                     $revision->oldData = RevisionController::buildDataArray($record);
                     $revision->save();
                 } else {
                     continue;
                 }
             } else {
                 $df = new DateField();
                 $revision = RevisionController::storeRevision($record->rid, 'edit');
                 $df->circa = $request->input('circa_' . $flid, '');
                 $df->month = $request->input('month_' . $flid);
                 $df->day = $request->input('day_' . $flid);
                 $df->year = $request->input('year_' . $flid);
                 $df->era = $request->input('era_' . $flid, 'CE');
                 $df->rid = $record->rid;
                 $df->flid = $flid;
                 $df->save();
                 $revision->oldData = RevisionController::buildDataArray($record);
                 $revision->save();
             }
         } elseif ($field->type == "Schedule") {
             $matching_record_fields = $record->schedulefields()->where("flid", '=', $flid)->get();
             $record->updated_at = Carbon::now();
             $record->save();
             if ($matching_record_fields->count() > 0) {
                 $schedulefield = $matching_record_fields->first();
                 if ($overwrite == true || $schedulefield->events == "" || is_null($schedulefield->events)) {
                     $revision = RevisionController::storeRevision($record->rid, 'edit');
                     $schedulefield->events = implode("[!]", $form_field_value);
                     $schedulefield->save();
                     $revision->oldData = RevisionController::buildDataArray($record);
                     $revision->save();
                 } else {
                     continue;
                 }
             } else {
                 $sf = new ScheduleField();
                 $revision = RevisionController::storeRevision($record->rid, 'edit');
                 $sf->flid = $field->flid;
                 $sf->rid = $record->rid;
                 $sf->events = implode("[!]", $form_field_value);
                 $sf->save();
                 $revision->oldData = RevisionController::buildDataArray($record);
                 $revision->save();
             }
         } elseif ($field->type == "Geolocator") {
             $matching_record_fields = $record->geolocatorfields()->where("flid", '=', $flid)->get();
             $record->updated_at = Carbon::now();
             $record->save();
             if ($matching_record_fields->count() > 0) {
                 $geolocatorfield = $matching_record_fields->first();
                 if ($overwrite == true || $geolocatorfield->locations == "" || is_null($geolocatorfield->locations)) {
                     $revision = RevisionController::storeRevision($record->rid, 'edit');
                     $geolocatorfield->locations = implode("[!]", $form_field_value);
                     $geolocatorfield->save();
                     $revision->oldData = RevisionController::buildDataArray($record);
                     $revision->save();
                 } else {
                     continue;
                 }
             } else {
                 $gf = new GeolocatorField();
                 $revision = RevisionController::storeRevision($record->rid, 'edit');
                 $gf->flid = $field->flid;
                 $gf->rid = $record->rid;
                 $gf->locations = implode("[!]", $form_field_value);
                 $gf->save();
                 $revision->oldData = RevisionController::buildDataArray($record);
                 $revision->save();
             }
         }
     }
     flash()->overlay("The records were updated", "Good Job!");
     return redirect()->action('RecordController@index', compact('pid', 'fid'));
 }
Пример #18
0
 /**
  * Update usernamde and password
  *
  * @param  Request  $request
  * @param  Response $response
  * @return Response
  */
 public function updateSettings(Request $request, Response $response)
 {
     $input = $request->getParsedBody();
     $form = new Form();
     if ($form->updateUsernameAndPassword($input) === true) {
         $this->flash->addMessage('message', $form->flash['message']);
         $this->flash->addMessage('alert_type', 'success');
         return $response->withRedirect('/admin/');
     } else {
         $form = $form->getForm();
         $form['alert_type'] = 'danger';
         return $this->view->render($response, 'admin/settings.twig', ['form' => $form, 'csrf_name' => $request->getAttribute('csrf_name'), 'csrf_value' => $request->getAttribute('csrf_value'), 'active_page' => 'settings']);
     }
 }
Пример #19
0
 public function search(Request $request)
 {
     $input = Request::all();
     $users = User::all();
     $sort = 'new';
     $forms = Form::where('tag', $input['tag'])->get();
     return view('welcome', compact('forms', 'users', 'sort'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $form = Form::findOrFail($id);
     $form->delete();
     return redirect()->route('forms.index');
 }
 public function forms()
 {
     $forms = Form::select('forms.id', 'form_groups.group_desc as group', 'form_types.form_type as type', 'forms.prompt')->join('form_groups', 'forms.form_group_id', '=', 'form_groups.id')->join('form_types', 'forms.form_type_id', '=', 'form_types.id')->get();
     return Datatables::of($forms)->make(true);
     // return Datatables::of(Form::all())->make(true);
 }
Пример #22
0
 public function destroy($slug)
 {
     $form = Form::where('slug', $slug)->firstOrFail();
     $form->delete();
     return redirect()->route('admin.forms.index')->with('message', trans('form.message.delete_success'));
 }
 /**
  * Get all Submissions for a Specific Form
  * @param  int $form_id
  * @return \Illuminate\Http\Response
  */
 public function getFormSubmissions($form_id)
 {
     $form = Form::findOrFail($form_id);
     $submissions = $form->submissions->all();
     $submissions_array = [];
     foreach ($submissions as $submission) {
         $data = $submission->getSubmissionData();
         $submissions_array[] = $data;
     }
     return view('submissions.single-form', ['submissions' => $submissions_array]);
 }
 public function index($form_slug)
 {
     $form = Form::where('slug', $form_slug)->firstOrFail();
     $submissions = $form->submissions()->orderBy('created_at', 'desc')->paginate(20);
     return view('admin.submissions.index', ['form' => $form, 'submissions' => $submissions]);
 }
Пример #25
0
 public static function insertForm($template, $code, $type, $required, $prompt, $choices, $expected_answer, $image, $choices2 = null, $con_datas = null, $default_answer = null)
 {
     if (strtoupper($type) == 'DOUBLE') {
         $form_type = FormType::where('form_type', "NUMERIC")->first();
     } else {
         $form_type = FormType::where('form_type', strtoupper($type))->first();
     }
     switch ($required) {
         case 't':
             $required = 1;
             break;
         case 'yes':
             $required = 1;
             break;
         case 'f':
             $required = 0;
             break;
         case 'no':
             $required = 0;
             break;
         default:
             # code...
             break;
     }
     $form = Form::create(array('audit_template_id' => $template->id, 'form_type_id' => $form_type->id, 'prompt' => strtoupper($prompt), 'required' => $required, 'exempt' => 0, 'default_answer' => $default_answer, 'image' => $image, 'code' => $code));
     if ($form_type->id == 9) {
         $choices = explode("~", $choices);
         foreach ($choices as $choice) {
             $sel = MultiSelect::where('option', $choice)->first();
             if (empty($sel)) {
                 $sel = MultiSelect::create(array('option' => strtoupper($choice)));
             }
             FormMultiSelect::create(array('form_id' => $form->id, 'multi_select_id' => $sel->id));
         }
         if (!empty($default_answer)) {
             $_form = Form::find($form->id);
             $ans = MultiSelect::where('option', strtoupper($default_answer))->first();
             $_form->default_answer = $ans->id;
             $_form->update();
         }
     }
     if ($form_type->id == 10) {
         $choices = explode("~", $choices);
         foreach ($choices as $choice) {
             if ($choice == "1") {
                 $opt = "YES";
             } elseif ($choice == "0") {
                 $opt = "NO";
             } else {
                 $opt = $choice;
             }
             $sel = SingleSelect::firstOrCreate(array('option' => strtoupper($opt)));
             FormSingleSelect::create(array('form_id' => $form->id, 'single_select_id' => $sel->id));
         }
         if (!empty($expected_answer)) {
             $_form = Form::find($form->id);
             // $ans = SingleSelect::where('option',strtoupper($expected_answer))->first();
             // $_form->expected_answer = $ans->id;
             // $_form->update();
             $ans = explode("^", $expected_answer);
             $pos_ans = [];
             foreach ($ans as $value) {
                 $_ans = SingleSelect::where('option', strtoupper($value))->first();
                 $pos_ans[] = $_ans->id;
             }
             if (!empty($pos_ans)) {
                 $_form->expected_answer = implode("^", $pos_ans);
                 $_form->update();
             }
         }
         if (!empty($default_answer)) {
             $_form = Form::find($form->id);
             // $ans = SingleSelect::where('option',strtoupper($default_answer))->first();
             // $_form->default_answer = $ans->id;
             // $_form->update();
             $ans = explode("^", $default_answer);
             $pos_ans = [];
             foreach ($ans as $value) {
                 $_ans = SingleSelect::where('option', strtoupper($value))->first();
                 $pos_ans[] = $_ans->id;
             }
             if (!empty($pos_ans)) {
                 $_form->default_answer = implode("^", $pos_ans);
                 $_form->update();
             }
         }
     }
     if ($form_type->id == 11) {
         // dd($choices2);
         FormFormula::create(['form_id' => $form->id, 'formula' => $choices, 'formula_desc' => $choices2]);
     }
     if ($form_type->id == 12) {
         foreach ($con_datas as $con_data) {
             $con = FormCondition::create(['form_id' => $form->id, 'option' => $con_data['option'], 'condition' => $con_data['condition'], 'condition_desc' => $con_data['condition_desc']]);
         }
         if (!empty($expected_answer)) {
             $_form = Form::find($form->id);
             $ans = explode("^", $expected_answer);
             $pos_ans = [];
             foreach ($ans as $value) {
                 $_ans = FormCondition::where('option', strtoupper($value))->where('form_id', $form->id)->first();
                 $pos_ans[] = $_ans->id;
             }
             if (!empty($pos_ans)) {
                 $_form->expected_answer = implode("^", $pos_ans);
                 $_form->update();
             }
         }
         if (!empty($default_answer)) {
             if (!empty($default_answer)) {
                 $_form = Form::find($form->id);
                 $ans = FormCondition::where('option', strtoupper($default_answer))->where('form_id', $form->id)->first();
                 if (!empty($ans)) {
                     $_form->default_answer = $ans->id;
                     $_form->update();
                 }
             }
         }
     }
     return $form;
 }
Пример #26
0
 public function postDel(Request $request, $form_code)
 {
     $form = Form::where('form_code', '=', $form_code)->where('form_type', 'template')->firstOrFail();
     //删除 fields 和 fieldchildrens
     $fields = $form->Field();
     foreach ($fields->get() as $field) {
         $field->FieldChildren()->forceDelete();
     }
     $fields->forceDelete();
     //删除 results 和 ResultRow
     $results = $form->Result();
     foreach ($results->get() as $result) {
         $result->ResultRow()->forceDelete();
     }
     $results->forceDelete();
     //删除form 关联的 img
     $img = $form->Img_thumbnail()->first();
     if ($img) {
         $img->decouple();
     }
     //删除form
     $form->forceDelete();
     $res = ['response' => 'YES', 'status' => 1];
     return response()->json($res);
 }
Пример #27
0
 /**
  * Returns true if a user is in a form's admin group, false if not.
  *
  * @param Form $form
  * @return bool
  */
 public function isFormAdmin(Form $form)
 {
     if ($this->admin) {
         return true;
     }
     if ($this->isProjectAdmin(ProjectController::getProject($form->pid))) {
         return true;
     }
     $adminGroup = $form->adminGroup()->first();
     if ($adminGroup->hasUser($this)) {
         return true;
     }
     return false;
 }
 public function destroyform($id)
 {
     $audit_form = AuditTemplateForm::findOrFail($id);
     FormFormula::where('form_id', $audit_form->form_id)->delete();
     FormCondition::where('form_id', $audit_form->form_id)->delete();
     FormMultiSelect::where('form_id', $audit_form->form_id)->delete();
     FormSingleSelect::where('form_id', $audit_form->form_id)->delete();
     $audit_form->delete();
     Form::where('id', $audit_form->form_id)->delete();
     Session::flash('flash_message', 'Template form succesfully deleted!');
     return redirect()->route("audittemplate.form", $audit_form->audit_template_id);
 }
Пример #29
0
 private function addPresets(Form $form, $fid)
 {
     $preset = Form::where('fid', '=', $fid)->first();
     $field_assoc = array();
     $form->layout = $preset->layout;
     foreach ($preset->fields()->get() as $field) {
         $new = new Field();
         $new->pid = $form->pid;
         $new->fid = $form->fid;
         $new->order = $field->order;
         $new->type = $field->type;
         $new->name = $field->name;
         $new->slug = $field->slug . '_' . $form->slug;
         $new->desc = $field->desc;
         $new->required = $field->required;
         $new->default = $field->default;
         $new->options = $field->options;
         $new->save();
         $field_assoc[$field->flid] = $new->flid;
     }
     $xmlArray = FormController::xmlToArray($form->layout);
     for ($i = 0; $i < sizeof($xmlArray); $i++) {
         if ($xmlArray[$i]['tag'] == 'ID') {
             $temp = $field_assoc[$xmlArray[$i]['value']];
             $xmlArray[$i]['value'] = $temp;
         }
     }
     $x = new FieldNavController();
     $xmlString = $x->valsToXML($xmlArray);
     $form->layout = $xmlString;
     $form->save();
 }
Пример #30
0
 public function testRedirectAfterSubmission()
 {
     $form = Form::where('slug', 'test-with-redirect')->firstOrFail();
     $this->call('POST', '/forms/' . $form->slug);
     $this->assertRedirectedTo($form->redirect_to_url);
 }