Exemplo n.º 1
0
 public static function updateDueDate($requests)
 {
     $fields = Field::all();
     foreach ($fields as $field) {
         if ($field->student_label == "payment_date1") {
             $info = new Information();
             $info->field_id = $field->id;
             $info->value = $requests->get('due_1');
             $info->save();
         }
         $info = new Information();
         $info->field_id = $field->id;
         $info->save();
         if ($field->student_label == "payment_date2") {
             $info = new Information();
             $info->field_id = $field->id;
             $info->value = $requests->get('due_2');
             $info->save();
         }
         $info = new Information();
         $info->field_id = $field->id;
         $info->save();
         if ($field->student_label == "payment_date3") {
             $info = new Information();
             $info->field_id = $field->id;
             $info->value = $requests->get('due_3');
             $info->save();
         }
         $info = new Information();
         $info->field_id = $field->id;
         $info->save();
         if ($field->student_label == "payment_date4") {
             $info = new Information();
             $info->field_id = $field->id;
             $info->value = $requests->get('due_4');
             $info->save();
         }
         $info = new Information();
         $info->field_id = $field->id;
         $info->save();
         if ($field->student_label == "payment_date5") {
             $info = new Information();
             $info->field_id = $field->id;
             $info->value = $requests->get('due_5');
             $info->save();
         }
         $info = new Information();
         $info->field_id = $field->id;
         $info->save();
     }
     return Redirect::back()->with('msg', 'Due date was successfuly updated');
 }
Exemplo n.º 2
0
 public function show($id)
 {
     $experiment = Experiment::findOrFail($id);
     $elements = array();
     $element = Element::find($experiment->element_id);
     $xor2 = array();
     $xorElement = null;
     $antworten = array();
     while ($element != null) {
         if ($element->type == 5) {
             $xorElement = $element;
             $xor = json_decode($element->ref, true);
             $xor2 = array();
             if (is_array($xor)) {
                 foreach ($xor as $pkey => $pfad) {
                     foreach ($pfad as $ekey => $el) {
                         $ele = Element::find($el);
                         if ($ele->type == 2 or $ele->type == 3 or $ele->type == 4) {
                             $xor2[$pkey][$ekey] = $ele;
                             $antwortenObjects = Answer::where("element", $ele->id)->where("experiment", $id)->get();
                             foreach ($antwortenObjects as $antwortObject) {
                                 $antworten[$antwortObject->student][$ele->id] = $antwortObject;
                             }
                         }
                     }
                 }
             }
         } elseif ($element->type == 2 or $element->type == 4 or $element->type == 3) {
             $elements[] = Element::findOrFail($element->id);
             $antwortenObjects = Answer::where("element", $element->id)->where("experiment", $id)->get();
             foreach ($antwortenObjects as $antwortObject) {
                 $antworten[$antwortObject->student][$element->id] = $antwortObject;
             }
         }
         $element = $element->next();
     }
     $elements = array_merge($elements, [$xor2]);
     $fields = array();
     $fields2 = Field::all();
     foreach ($fields2 as $field) {
         $fields[$field->id] = $field;
     }
     return view('auswertung.show', compact('experiment', 'elements', 'antworten', 'xorElement', 'fields'));
 }
Exemplo n.º 3
0
 public function get_seek_announcements(Request $request)
 {
     $field_search = input::get('field');
     $term_search = input::get('term');
     $region_search = input::get('region');
     $municipalities_search = input::get('municipalities');
     if ($field_search == '0' || empty($field_search)) {
         $fields_all = Field::all(['id']);
         foreach ($fields_all as $field) {
             $fields[] = $field->id;
         }
     } else {
         $fields[] = $field_search;
     }
     if ($term_search == '0' || empty($term_search)) {
         $terms_all = Term::all(['id']);
         foreach ($terms_all as $term) {
             $terms[] = $term->id;
         }
     } else {
         $terms[] = $term_search;
     }
     if ($municipalities_search[0] == '0' || empty($municipalities_search)) {
         if ($region_search != '0' && !empty($region_search)) {
             $any_municipality = Region::find($region_search)->get_municipalities()->get();
         } else {
             $any_municipality = Municipality::all(['id']);
         }
         foreach ($any_municipality as $instance) {
             $municipality_id[] = $instance->id;
         }
     } else {
         $municipality_id = $municipalities_search;
     }
     $select = DB::select(' SELECT seek_trainings.id, field_seek_training.field_id, municipality_seek_training.municipality_id
                             FROM seek_trainings
                             JOIN field_seek_training ON seek_trainings.id = field_seek_training.seek_training_id
                             JOIN municipality_seek_training ON seek_trainings.id = municipality_seek_training.seek_training_id
                             WHERE field_seek_training.field_id in(' . implode(',', $fields) . ')
                             AND municipality_seek_training.municipality_id in (' . implode(',', $municipality_id) . ')
                             group by seek_trainings.id
                         ');
     foreach ($select as $instance) {
         $seek_training_filtered = new \stdClass();
         $seek_training_instance = SeekTraining::find($instance->id);
         $seek_training_field = Field::find($instance->field_id);
         $seek_training_municipality = Municipality::find($instance->municipality_id);
         $training_terms = DB::select('SELECT terms.name FROM seek_training_term JOIN terms ON terms.id = seek_training_term.term_id WHERE seek_training_id = ' . $instance->id);
         $seek_training_terms_array = [];
         foreach ($training_terms as $term) {
             $seek_training_terms_array[] = $term->name;
         }
         $seek_training_filtered->id = $seek_training_instance->id;
         $seek_training_filtered->header = $seek_training_instance->name;
         $seek_training_filtered->description = $seek_training_instance->description;
         $seek_training_filtered->file = $seek_training_instance->file;
         $seek_training_filtered->link = $seek_training_instance->link;
         $seek_training_filtered->per = $seek_training_instance->per;
         $seek_training_filtered->terms = implode(',', $seek_training_terms_array);
         $seek_training_filtered->contact = $seek_training_instance->contact;
         $seek_training_filtered->quantity = $seek_training_instance->quantity;
         $seek_training_filtered->field = $seek_training_field->name;
         $seek_training_filtered->municipality = $seek_training_municipality->name;
         $seek_training_filtered->isAdmin = !(!Auth::user() || Auth::user()->role == 100);
         $seek_training_filtered_array[] = $seek_training_filtered;
         unset($seek_training_filtered);
         unset($seek_training_months_array);
         unset($seek_training_terms_array);
     }
     return response(json_encode($seek_training_filtered_array), 200)->header('Content-Type', 'application/json');
 }
Exemplo n.º 4
0
 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.");
     }
 }
Exemplo n.º 5
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $fields = Field::all();
     $ctr = 0;
     return view('information.index', compact('fields', 'ctr'));
 }