public function store(Request $request) { $user = \Auth::user(); $input = Request::all(); $imageName = $input['content'] . '.' . $input['content']->getClientOriginalExtension(); $input['content']->move(base_path() . '/public/images/', $imageName); Form::create(['title' => $input['title'], 'content' => str_replace("/tmp/", "", $imageName), 'description' => $input['description'], 'tag' => $input['tag'], 'user_id' => $user->id]); return redirect('/form'); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(FormRequest $request) { $form = Form::create($request->all()); $form->layout = '<LAYOUT></LAYOUT>'; $form->save(); $adminGroup = FormController::makeAdminGroup($form, $request); $form->adminGID = $adminGroup->id; $form->save(); if (isset($request['preset'])) { FormController::addPresets($form, $request['preset']); } flash()->overlay('Your form has been successfully created!', 'Good Job'); return redirect('projects/' . $form->pid); }
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; }
/** * 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(); }
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)]); } }
public function postCreate(FormPRequest $request) { $inputs = $request->only('form_title', 'form_summary', 'form_desc', 'form_sort', 'form_active'); $inputs['form_cuid'] = $request->user()->user_id; $inputs['form_type'] = 'template'; $inputs['form_code'] = Auth::id() . mt_rand(0, 999) . time(); if ($inputs['form_active'] == '') { $inputs['form_active'] = 0; } $inputs['form_img_thumbnail'] = $request->input('form_img_thumbnail', 0); $form = Form::create($inputs); if ($inputs['form_img_thumbnail']) { Img::find($inputs['form_img_thumbnail'])->relation(); } if ($form) { $res = redirect('/manage/template/field-new/' . $form->form_code)->with('msgSuccess', MSG_SU); } else { $res = redirect()->back()->with('msgError', MSG_FA); } return $res; }
public function postCreate(FormCreatePRequest $request) { if (Gate::denies('create-form')) { abort(403); } $inputs = $request->only('form_title', 'form_summary', 'form_sort', 'form_active', 'form_url', 'form_tips_email', 'form_limit_write', 'form_limit_auz'); $inputs['form_cuid'] = $request->user()->user_id; $inputs['form_type'] = 'normal'; $inputs['form_code'] = Auth::id() . mt_rand(0, 999) . time(); if ($inputs['form_active'] == '') { $inputs['form_active'] = 0; } if ($inputs['form_tips_email'] == '') { $inputs['form_tips_email'] = 0; } $form = Form::create($inputs); if ($form) { $res = redirect('/form/field-new/' . $form->form_code)->with('msgSuccess', MSG_SU); } else { $res = redirect()->back()->with('msgError', MSG_FA); } return $res; }
/** * Store a newly created resource in storage. * * @return Response */ public function store(CreateFormRequest $request) { $form = Form::create($request->all()); return redirect()->route('forms.index'); }
public function storeform(Request $request, $id) { // dd($request->all()); $this->validate($request, ['category' => 'required', 'group' => 'required', 'prompt' => 'required', 'formtype' => 'required']); \DB::beginTransaction(); try { $template = AuditTemplate::find($id); $form_type = FormType::find($request->formtype); $prompt = $request->prompt; foreach ($request->category as $cat_id) { $category = FormCategory::find($cat_id); $cat_order = 1; $a_cat_id = 0; $clast_cnt = AuditTemplateCategory::getLastOrder($template->id); if (empty($clast_cnt)) { $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]); $a_cat_id = $a_cat->id; } else { $cat = AuditTemplateCategory::categoryExist($template->id, $category->id); if (empty($cat)) { $cat_order = $clast_cnt->category_order + 1; $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]); $a_cat_id = $a_cat->id; } else { $a_cat_id = $cat->id; } } foreach ($request->group as $grp_id) { $group = FormGroup::find($grp_id); $grp_order = 1; $a_grp_id = 0; $glast_cnt = AuditTemplateGroup::getLastOrder($a_cat_id); if (empty($glast_cnt)) { $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]); $a_grp_id = $a_grp->id; } else { $grp = AuditTemplateGroup::categoryExist($a_cat_id, $group->id); if (empty($grp)) { $grp_order = $glast_cnt->group_order + 1; $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]); $a_grp_id = $a_grp->id; } else { $a_grp_id = $grp->id; } } $form = Form::create(array('audit_template_id' => $template->id, 'form_type_id' => $form_type->id, 'prompt' => strtoupper($prompt), 'required' => $request->required == '1' ? 1 : 0, 'expected_answer' => $request->expected_answer == '1' ? 1 : 0, 'exempt' => $request->exempt == '1' ? 1 : 0)); 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')) { $text = $request->formula; preg_match_all('/:(.*?):/', $text, $matches); $index = array(); foreach ($matches[1] as $value) { $split_up = explode('_', $value); $last_item = $split_up[count($split_up) - 1]; $index[] = $last_item; } $formula1 = $text; foreach ($matches[1] as $key => $a) { $formula1 = str_replace(':' . $a . ':', $index[$key], $formula1); } $formformula = new FormFormula(); $formformula->form_id = $form->id; $formformula->formula = $formula1; $formformula->formula_desc = $request->formula; $formformula->save(); } } if ($request->formtype == 12) { if ($request->has('condition')) { } } $order = 1; $a_frm_id = 0; $last_cnt = AuditTemplateForm::getLastOrder($a_grp_id); if (!empty($last_cnt)) { $order = $last_cnt->order + 1; } AuditTemplateForm::insert(array('audit_template_group_id' => $a_grp_id, 'order' => $order, 'audit_template_id' => $template->id, 'form_id' => $form->id)); } } \DB::commit(); Session::flash('flash_message', 'Template successfully added!'); return redirect()->route("audittemplate.form", $id); } catch (Exception $e) { DB::rollBack(); Session::flash('flash_message', 'An error occured in adding form!'); return redirect()->back(); } }
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; }
public function restoreData(Request $request) { $this->json_file = null; $this->decoded_json = null; $users_exempt_from_lockout = new Collection(); $users_exempt_from_lockout->put(1, 1); //Add another one of these with (userid,userid) to exempt extra users $this->lockUsers($users_exempt_from_lockout); if ($request->session()->has("restore_file_path")) { $filepath = $request->session()->get("restore_file_path"); $request->session()->forget("restore_file_path"); } else { return $this->ajaxResponse(false, "You did not select a valid restore point or upload a valid backup file"); } try { $this->json_file = Storage::get($filepath); } catch (\Exception $e) { $this->ajaxResponse(false, "The backup file couldn't be opened. Make sure it still exists and the permissions are correct."); } try { $this->decoded_json = json_decode($this->json_file); $this->decoded_json->kora3; } catch (\Exception $e) { $this->ajaxResponse(false, "The backup file contains invalid JSON data, it may be corrupt or damaged. Check the file or try another one.\n The restore did not start, so data already in the database was not deleted."); } $backup_data = $this->decoded_json; //Delete all existing data try { foreach (User::all() as $User) { if ($User->id == 1) { //Do not delete the default admin user continue; } else { $User->delete(); } } foreach (Project::all() as $Project) { $Project->delete(); } foreach (Form::all() as $Form) { $Form->delete(); } foreach (Field::all() as $Field) { $Field->delete(); } foreach (Record::all() as $Record) { $Record->delete(); } foreach (Metadata::all() as $Metadata) { $Metadata->delete(); } foreach (Token::all() as $Token) { $Token->delete(); } foreach (Revision::all() as $Revision) { $Revision->delete(); } foreach (DateField::all() as $DateField) { $DateField->delete(); } foreach (FormGroup::all() as $FormGroup) { $FormGroup->delete(); } foreach (GeneratedListField::all() as $GeneratedListField) { $GeneratedListField->delete(); } foreach (ListField::all() as $ListField) { $ListField->delete(); } foreach (MultiSelectListField::all() as $MultiSelectListField) { $MultiSelectListField->delete(); } foreach (NumberField::all() as $NumberField) { $NumberField->delete(); } foreach (ProjectGroup::all() as $ProjectGroup) { $ProjectGroup->delete(); } foreach (RichTextField::all() as $RichTextField) { $RichTextField->delete(); } foreach (ScheduleField::all() as $ScheduleField) { $ScheduleField->delete(); } foreach (TextField::all() as $TextField) { $TextField->delete(); } } catch (\Exception $e) { $this->ajaxResponse(false, "There was a problem when attempting to remove existing information from the\n database, the database user may not have permission to do this or the database may be in use."); } try { //This try-catch is for non-QueryExceptions, like if a table is missing entirely from the JSON data // User foreach ($backup_data->users as $user) { try { $new_user = User::create(array("username" => $user->username, "name" => $user->name, "email" => $user->email, "password" => $user->password, "organization" => $user->organization, "language" => $user->language, "regtoken" => $user->regtoken)); $new_user->id = $user->id; $new_user->admin = $user->admin; $new_user->active = $user->active; $new_user->remember_token = $user->remember_token; $new_user->created_at = $user->created_at; $new_user->updated_at = $user->updated_at; $new_user->locked_out = true; $new_user->save(); } catch (\Exception $e) { $this->ajax_error_list->push($e->getMessage()); } } // Project foreach ($backup_data->projects as $project) { //$new_project = Project::create(array("name" => $project->name, "slug" => $project->slug, "description" => $project->description, "adminGID" => $project->adminGID, "active" => $project->active)); try { $new_project = Project::create(array()); $new_project->name = $project->name; $new_project->slug = $project->slug; $new_project->description = $project->description; $new_project->adminGID = $project->adminGID; $new_project->active = $project->active; $new_project->pid = $project->pid; $new_project->created_at = $project->created_at; $new_project->updated_at = $project->updated_at; $new_project->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Form foreach ($backup_data->forms as $form) { try { $new_form = Form::create(array("pid" => $form->pid)); $new_form->fid = $form->fid; $new_form->name = $form->name; $new_form->slug = $form->slug; $new_form->description = $form->description; $new_form->adminGID = $form->adminGID; $new_form->layout = $form->layout; $new_form->public_metadata = $form->public_metadata; $new_form->layout = $form->layout; $new_form->adminGID = $form->adminGID; $new_form->created_at = $form->created_at; $new_form->updated_at = $form->updated_at; $new_form->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Field foreach ($backup_data->fields as $field) { try { $new_field = Field::create(array("pid" => $field->pid, "fid" => $field->fid, "order" => $field->order, "type" => $field->type, "name" => $field->name, "slug" => $field->slug, "desc" => $field->desc, "required" => $field->required, "default" => $field->default, "options" => $field->options)); $new_field->flid = $field->flid; $new_field->default = $field->default; $new_field->options = $field->options; $new_field->created_at = $field->created_at; $new_field->updated_at = $field->updated_at; $new_field->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // FormGroup foreach ($backup_data->formgroups as $formgroup) { try { $new_formgroup = new FormGroup(); $new_formgroup->name = $formgroup->group_data->name; $new_formgroup->fid = $formgroup->group_data->fid; $new_formgroup->create = $formgroup->group_data->create; $new_formgroup->edit = $formgroup->group_data->edit; $new_formgroup->ingest = $formgroup->group_data->ingest; $new_formgroup->delete = $formgroup->group_data->delete; $new_formgroup->modify = $formgroup->group_data->modify; $new_formgroup->destroy = $formgroup->group_data->destroy; $new_formgroup->id = $formgroup->group_data->id; $new_formgroup->created_at = $formgroup->group_data->created_at; $new_formgroup->updated_at = $formgroup->group_data->updated_at; $new_formgroup->save(); foreach ($formgroup->user_data as $user_id) { $new_formgroup->users()->attach($user_id); } } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // ProjectGroup foreach ($backup_data->projectgroups as $projectgroup) { try { $new_projectgroup = new ProjectGroup(); $new_projectgroup->id = $projectgroup->group_data->id; $new_projectgroup->name = $projectgroup->group_data->name; $new_projectgroup->pid = $projectgroup->group_data->pid; $new_projectgroup->create = $projectgroup->group_data->create; $new_projectgroup->edit = $projectgroup->group_data->edit; $new_projectgroup->delete = $projectgroup->group_data->delete; $new_projectgroup->created_at = $projectgroup->group_data->created_at; $new_projectgroup->updated_at = $projectgroup->group_data->updated_at; $new_projectgroup->save(); foreach ($projectgroup->user_data as $user_id) { $new_projectgroup->users()->attach($user_id); } } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Record foreach ($backup_data->records as $record) { try { $new_record = new Record(array("pid" => $record->pid, "fid" => $record->fid, "owner" => $record->owner, "kid" => $record->kid)); $new_record->rid = $record->rid; $new_record->created_at = $record->created_at; $new_record->updated_at = $record->updated_at; $new_record->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // TextField foreach ($backup_data->textfields as $textfield) { try { $new_textfield = new TextField(array("rid" => $textfield->rid, "flid" => $textfield->flid, "text" => $textfield->text)); $new_textfield->id = $textfield->id; $new_textfield->created_at = $textfield->created_at; $new_textfield->updated_at = $textfield->updated_at; $new_textfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // RichTextField foreach ($backup_data->richtextfields as $richtextfield) { try { $new_richtextfield = new RichTextField(array("rid" => $richtextfield->rid, "flid" => $richtextfield->flid, "rawtext" => $richtextfield->rawtext)); $new_richtextfield->id = $richtextfield->id; $new_richtextfield->created_at = $richtextfield->created_at; $new_richtextfield->updated_at = $richtextfield->updated_at; $new_richtextfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // NumberField foreach ($backup_data->numberfields as $numberfield) { try { $new_numberfield = new NumberField(array("rid" => $numberfield->rid, "flid" => $numberfield->flid, "number" => $numberfield->number)); $new_numberfield->id = $numberfield->id; $new_numberfield->created_at = $numberfield->created_at; $new_numberfield->updated_at = $numberfield->updated_at; $new_numberfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // ListField foreach ($backup_data->listfields as $listfield) { try { $new_listfield = new ListField(array("rid" => $listfield->rid, "flid" => $listfield->flid, "option" => $listfield->option)); $new_listfield->id = $listfield->id; $new_listfield->created_at = $listfield->created_at; $new_listfield->updated_at = $listfield->updated_at; $new_listfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // GeneratedListField foreach ($backup_data->generatedlistfields as $generatedlistfield) { try { $new_generatedlistfield = new GeneratedListField(array("rid" => $generatedlistfield->rid, "flid" => $generatedlistfield->flid, "options" => $generatedlistfield->options)); $new_generatedlistfield->id = $generatedlistfield->id; $new_generatedlistfield->created_at = $generatedlistfield->created_at; $new_generatedlistfield->updated_at = $generatedlistfield->updated_at; $new_generatedlistfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // MultiSelectListField foreach ($backup_data->multiselectlistfields as $multiselectlistfield) { try { $new_multiselectlistfield = new MultiSelectListField(array("rid" => $multiselectlistfield->rid, "flid" => $multiselectlistfield->flid, "options" => $multiselectlistfield->options)); $new_multiselectlistfield->id = $multiselectlistfield->id; $new_multiselectlistfield->created_at = $multiselectlistfield->created_at; $new_multiselectlistfield->updated_at = $multiselectlistfield->updated_at; $new_multiselectlistfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // DateField foreach ($backup_data->datefields as $datefield) { try { $new_datefield = new DateField(); $new_datefield->id = $datefield->id; $new_datefield->rid = $datefield->rid; $new_datefield->flid = $datefield->flid; $new_datefield->circa = $datefield->circa; $new_datefield->month = $datefield->month; $new_datefield->day = $datefield->day; $new_datefield->year = $datefield->year; $new_datefield->era = $datefield->era; $new_datefield->created_at = $datefield->created_at; $new_datefield->updated_at = $datefield->updated_at; $new_datefield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // ScheduleField foreach ($backup_data->schedulefields as $schedulefield) { try { $new_schedulefield = new ScheduleField(array("rid" => $schedulefield->rid, "flid" => $schedulefield->flid, "events" => $schedulefield->events)); $new_schedulefield->id = $schedulefield->id; $new_schedulefield->created_at = $schedulefield->created_at; $new_schedulefield->updated_at = $schedulefield->updated_at; $new_schedulefield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // GeolocatorField foreach ($backup_data->geolocatorfields as $geolocatorfield) { try { $new_geolocatorfield = new GeolocatorField(array("rid" => $geolocatorfield->rid, "flid" => $geolocatorfield->flid, "locations" => $geolocatorfield->locations)); $new_geolocatorfield->id = $geolocatorfield->id; $new_geolocatorfield->created_at = $geolocatorfield->created_at; $new_geolocatorfield->updated_at = $new_geolocatorfield->updated_at; $new_geolocatorfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Token foreach ($backup_data->tokens as $token) { try { $new_token = new Token(array('token' => $token->token, 'type' => $token->type)); $new_token->id = $token->id; $new_token->created_at = $token->created_at; $new_token->updated_at = $token->updated_at; $new_token->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Metadata foreach ($backup_data->metadatas as $metadata) { try { $new_metadata = new Metadata(array()); $new_metadata->flid = $metadata->flid; $new_metadata->pid = $metadata->pid; $new_metadata->fid = $metadata->fid; $new_metadata->name = $metadata->name; $new_metadata->created_at = $metadata->created_at; $new_metadata->updated_at = $metadata->updated_at; $new_metadata->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Revision foreach ($backup_data->revisions as $revision) { try { $new_revision = new Revision(array('id' => $revision->id, 'fid' => $revision->fid, 'rid' => $revision->rid, 'userId' => $revision->userId, 'type' => $revision->type, 'data' => $revision->data, 'oldData' => $revision->oldData, 'rollback' => $revision->rollback)); $new_revision->created_at = $revision->created_at; $new_revision->updated_at = $revision->updated_at; $new_revision->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } } catch (\Exception $e) { $this->ajax_error_list->push($e->getMessage()); $this->ajaxResponse(false, "An unknown error prevented the restore from completing.\n You can try restoring from a different backup file or restore point.\n Users will stay locked out until you run a successful restore or manually unlock them above.\n For this error, it's not recommended that you unlock users unless you have resolved the problem"); } if (count($this->ajax_error_list) != 0) { $this->ajaxResponse(false, "Not all of your data was restored, check the errors below for details.\n The errors are in order that they occurred, if you can resolve the first error, it will often correct\n one or more of the errors below it.\n Users will stay locked out until you run a successful restore or manually unlock them above."); } else { $this->unlockUsers(); $this->ajaxResponse(true, "The restore completed successfully."); } }
/** * Run the database seeds. * * @return void */ public function run() { Form::create(['slug' => 'form-a', 'template_form' => null, 'template_success' => null, 'fields' => '[{"label":"First Name","placeholder":false,"name":"first_name","type":"text","attributes":{"maxlength":60},"validators":"required|between:1,60"},{"label":"Last Name","name":"last_name","type":"text","attributes":{"maxlength":60},"validators":"required|between:2,60"},{"label":"Email","placeholder":"*****@*****.**","name":"email","helper":"Type a valid email, please.","type":"email","attributes":{"maxlength":90},"validators":"required|email|between:5,90"},{"label":"Street","name":"street","type":"text","attributes":{"maxlength":60},"validators":"required|between:3,60"},{"label":"City","name":"city","type":"text","attributes":{"maxlength":60},"validators":"required|between:2,60"},{"label":"State","name":"state","placeholder":"Select one","type":"select","attributes":{"style":"max-width: 110px"},"validators":"required","options":{"AA":"AA","AE":"AE","AK":"AK","AL":"AL","AP":"AP","AR":"AR","AS":"AS","AZ":"AZ","CA":"CA","CO":"CO","CT":"CT","DC":"DC","DE":"DE","FL":"FL","FM":"FM","GA":"GA","GU":"GU","HI":"HI","IA":"IA","ID":"ID","IL":"IL","IN":"IN","KS":"KS","KY":"KY","LA":"LA","MA":"MA","MD":"MD","ME":"ME","MH":"MH","MI":"MI","MN":"MN","MO":"MO","MP":"MP","MS":"MS","MT":"MT","NC":"NC","ND":"ND","NE":"NE","NH":"NH","NJ":"NJ","NM":"NM","NV":"NV","NY":"NY","OH":"OH","OK":"OK","OR":"OR","PA":"PA","PR":"PR","PW":"PW","RI":"RI","SC":"SC","SD":"SD","TN":"TN","TX":"TX","UT":"UT","VA":"VA","VI":"VI","VT":"VT","WA":"WA","WI":"WI","WV":"WV","WY":"WY"}},{"label":"Zipcode","name":"zipcode","type":"text","attributes":{"maxlength":5},"validators":"required|max:5|digits_between:3,5"},{"label":"Phone","name":"phone","helper":"Numbers only.","type":"text","attributes":{"maxlength":13},"validators":"required|numeric|digits_between:6,13"},{"label":"Fax","name":"fax","helper":"Numbers only.","type":"text","attributes":{"maxlength":13},"validators":"numeric|digits_between:6,13"},{"label":"Best time to contact","placeholder":"Select a time","name":"best_time","type":"select","options":{"morning":"Morning","afternoon":"Afternoon","evening":"Evening"},"validators":"required"},{"label":"Terms of Services","name":"tos","type":"checkbox","options":{"1":"I accept the Terms of Services"},"validators":"required"}]', 'show_responses' => true]); Form::create(['slug' => 'form-b', 'template_form' => 'form-custom', 'template_success' => 'success-custom', 'fields' => '[{"label":"Your Name","placeholder":false,"name":"first_name","type":"text","attributes":{"maxlength":60},"validators":"required|between:1,60"},{"label":"Email","placeholder":"*****@*****.**","name":"email","helper":"Type a valid email, please.","type":"email","attributes":{"maxlength":90},"validators":"required|email|between:5,90"},{"label":"City","name":"city","type":"text","attributes":{"maxlength":60},"validators":"required|between:2,60"},{"label":"State","name":"state","placeholder":"Select one","type":"select","attributes":{"style":"max-width: 110px"},"validators":"required","options":{"AA":"AA","AE":"AE","AK":"AK","AL":"AL","AP":"AP","AR":"AR","AS":"AS","AZ":"AZ","CA":"CA","CO":"CO","CT":"CT","DC":"DC","DE":"DE","FL":"FL","FM":"FM","GA":"GA","GU":"GU","HI":"HI","IA":"IA","ID":"ID","IL":"IL","IN":"IN","KS":"KS","KY":"KY","LA":"LA","MA":"MA","MD":"MD","ME":"ME","MH":"MH","MI":"MI","MN":"MN","MO":"MO","MP":"MP","MS":"MS","MT":"MT","NC":"NC","ND":"ND","NE":"NE","NH":"NH","NJ":"NJ","NM":"NM","NV":"NV","NY":"NY","OH":"OH","OK":"OK","OR":"OR","PA":"PA","PR":"PR","PW":"PW","RI":"RI","SC":"SC","SD":"SD","TN":"TN","TX":"TX","UT":"UT","VA":"VA","VI":"VI","VT":"VT","WA":"WA","WI":"WI","WV":"WV","WY":"WY"}},{"label":"Zipcode","name":"zipcode","type":"text","attributes":{"maxlength":5},"validators":"required|max:5|digits_between:3,5"},{"label":"Terms of Services","name":"tos","type":"checkbox","options":{"1":"I accept the Terms of Services"},"validators":"required"}]', 'show_responses' => false]); }