public function add() { $form = array('building_id' => '', 'name' => '', 'index' => '', 'img_uri' => '', 'active' => ''); $errors = $form; if ($_POST) { $post = new Validation($_POST); $post->pre_filter('trim', true); $post->add_rules('buildings_id', 'required', 'digit'); $post->add_rules('name', 'required'); $post->add_rules('index', 'required'); $post->add_rules('img_uri', 'required'); $post->add_rules('active', 'required'); if ($post->validate()) { // check for invilid $form = arr::overwrite($form, $post->as_array()); $people = new Person_Model(); $result = $people->save($this->input->get('person'), $person_id); } else { $form = arr::overwrite($form, $post->as_array()); client::validation_results(arr::overwrite($errors, $post->errors('hiring_employee_form_validations'))); client::messageSend("There were errors in some fields", E_USER_WARNING); } } $building = new Building_Model(); $buildings_list = $building->select_list(); $this->template->title = 'Seating::Spaces::Add'; $this->template->content = new View('pages/spaces_add'); $this->template->content->form = $form; $this->template->content->buildings_list = $buildings_list; }
public function action_edit($edit_id = null) { if (!$edit_id) { client::messageSend("Invalid Request", E_USER_WARNING); $this->request->redirect('markers'); } $this->template->title = 'Markers :: Edit'; $this->template->content = new View('admin/pages/markers_edit'); $marker = ORM::factory('marker', $edit_id); // echo Kohana::debug($marker->has('spaces',orm::factory('space',1)));die; $this->template->content->spaces_list = ORM::factory('space')->find_all()->as_array('id', 'name'); if ($_POST) { // var_dump($_POST);die; $marker->email = Arr::get($_POST, 'email'); if (Arr::get($_POST, 'space')) { $marker->remove_all('spaces'); foreach (Arr::get($_POST, 'space', array()) as $space_id) { $space = ORM::factory('space', $space_id); $marker->add('spaces', $space); } } if ($marker->validate()) { $marker->save(); client::messageSend("The Marker '{$marker->email}' Was Saved", E_USER_NOTICE); $this->request->redirect('admin/markers'); } else { client::validation_results($marker->errors()); client::messageSend("There were errors in some fields", E_USER_WARNING); } } $this->template->content->marker = $marker; }
public function action_edit($edit_id = null) { if (!$edit_id) { client::messageSend("Invalid Request", E_USER_WARNING); $this->request->redirect('buildings'); } $this->template->title = 'Buildings :: Edit'; $this->template->content = new View('admin/pages/buildings_edit'); $this->template->content->sites_list = ORM::factory('site')->find_all()->as_array('id', 'name'); $building = ORM::factory('building')->find($edit_id); if ($_POST) { $building->site_id = Arr::get($_POST, 'site_id'); $building->name = Arr::get($_POST, 'name'); $building->lat = Arr::get($_POST, 'lat'); $building->long = Arr::get($_POST, 'long'); if ($building->validate()) { $building->save(); client::messageSend("The Building '{$building->name}' Was Saved", E_USER_NOTICE); $this->request->redirect('admin/buildings'); } else { client::validation_results($building->errors()); client::messageSend("There were errors in some fields", E_USER_WARNING); } } $this->template->content->building = $building; }
public function action_edit($edit_id = null) { if (!$edit_id) { client::messageSend("Invalid Request", E_USER_WARNING); $this->request->redirect('spaces'); } $this->template->title = 'Spaces :: Edit'; $this->template->content = new View('admin/pages/spaces_edit'); $this->template->content->buildings_list = ORM::factory('building')->find_all()->as_array('id', 'name'); $space = ORM::factory('space')->find($edit_id); if ($_POST) { $space->name = Arr::get($_POST, 'name'); $space->index = Arr::get($_POST, 'index'); $space->img_url = Arr::get($_POST, 'img_url'); if ($space->validate()) { $space->save(); client::messageSend("The Space '{$space->name}' Was Saved", E_USER_NOTICE); $this->request->redirect('admin/spaces'); } else { client::validation_results($space->errors()); client::messageSend("There were errors in some fields", E_USER_WARNING); } } $this->template->content->space = $space; }
/** * note: Route set to /login */ public function login() { $username = $this->input->post('bz_username'); $password = $this->input->post('bz_password'); if ($_POST) { $validation = Validation::factory($this->input->post())->pre_filter('trim')->add_rules('bz_username', 'required')->add_rules('bz_password', 'required'); if ($validation->validate()) { if ($this->bugzilla->login($username, $password)) { url::redirect(); } else { client::messageSend($this->bugzilla->error_message(), E_USER_WARNING); } } else { client::validation_results($validation->errors()); client::messageSend("There were errors in some fields", E_USER_WARNING); } } $this->template->content = new View('pages/bz_login'); $this->template->content->bz_username = $username; $this->template->content->bz_password = $password; $this->template->title = 'Worker Managment :: Login'; }
public function action_edit($edit_id = null) { if (!$edit_id) { client::messageSend("Invalid Request", E_USER_WARNING); $this->request->redirect('sites'); } $this->template->title = 'Sites :: Edit'; $this->template->content = new View('admin/pages/sites_edit'); $site = ORM::factory('site')->find($edit_id); if ($_POST) { $site->name = Arr::get($_POST, 'name'); $site->lat = Arr::get($_POST, 'lat'); $site->long = Arr::get($_POST, 'long'); if ($site->validate()) { $site->save(); client::messageSend("The Site '{$site->name}' Was Saved", E_USER_NOTICE); $this->request->redirect('admin/sites'); } else { client::validation_results($site->errors()); client::messageSend("There were errors in some fields", E_USER_WARNING); } } $this->template->content->site = $site; }
/** * Set the results of the validation (from Validation_Core). * self::validation($input_key) then uses this to output those errors * at the specific form input element * * @param array $results */ public static function validation_results($results) { self::$validation_results = $results; }
/** * Form for submitting Contractor hirings */ public function contractor() { $hiring = new Hiring_Model($this->get_ldap()); $this->select_lists['manager'] = hiring_forms::format_manager_list($hiring->manager_list()); $this->select_lists['buddy'] = hiring_forms::format_manager_list($hiring->buddy_list()); // allow only hire_type = 'Contractor' $this->select_lists['hire_type'] = array('Contractor' => 'Contractor'); /** * track required fields with this array, Validator uses it and form helper * uses it to determine which fields to decorate as 'required' in the UI */ $required_fields = array('contract_type', 'contractor_category', 'first_name', 'last_name', 'address', 'phone_number', 'email_address', 'start_date', 'end_date', 'pay_rate', 'payment_limit', 'manager', 'location', 'statement_of_work'); $form = array('hire_type' => 'Contractor', 'contract_type' => '', 'contractor_category' => '', 'first_name' => '', 'last_name' => '', 'org_name' => '', 'address' => '', 'phone_number' => '', 'email_address' => '', 'start_date' => '', 'end_date' => '', 'pay_rate' => '', 'payment_limit' => '', 'manager' => '', 'buddy' => '', 'location' => '', 'location_other' => '', 'statement_of_work' => '', 'mail_needed' => '', 'default_username' => '', 'mail_alias' => '', 'mail_lists' => '', 'other_comments' => ''); $errors = $form; if ($_POST) { hiring_forms::filter_disallowed_values($this->select_lists); $post = new Validation($_POST); $post->pre_filter('trim', true); $post->add_rules('start_date', 'valid::date'); $post->add_rules('end_date', 'valid::date'); $post->add_rules('email_address', 'valid::email'); if ($this->input->post('mail_needed') == '1') { array_push($required_fields, 'location'); } if ($this->input->post('location') == 'other') { array_push($required_fields, 'location_other'); } // add all the required fields foreach ($required_fields as $required_field) { $post->add_rules($required_field, 'required'); } if ($post->validate()) { // check for invilid $form = arr::overwrite($form, $post->as_array()); $form = $this->build_supplemental_form_values($form, $hiring); $bugs_to_file = array(Bugzilla::BUG_NEWHIRE_SETUP, Bugzilla::BUG_HR_CONTRACTOR); if ($form['mail_needed']) { $bugs_to_file[] = Bugzilla::BUG_EMAIL_SETUP; } // File the appropriate Bugs $this->file_these($bugs_to_file, $form); // Send Buddy Email if (!empty($form['buddy'])) { $this->notify_buddy($form, $hiring); } if (!client::has_errors()) { url::redirect('hiring/contractor'); } } else { $form = arr::overwrite($form, $post->as_array()); client::validation_results(arr::overwrite($errors, $post->errors('hiring_contractor_form_validations'))); client::messageSend("There were errors in some fields", E_USER_WARNING); } } // the UI used client to determine which fields to decorate as 'required' form::required_fields($required_fields); $this->template->js_extra = html::script(array('media/js/jquery.autocomplete.min.js'), false); $this->template->css_extra = html::stylesheet(array('media/css/jquery.autocomplete.css'), array('screen')); $this->template->title = 'Hiring::Contractor'; $this->template->content = new View('pages/hiring_contractor'); $this->template->content->form = $form; $this->template->content->lists = $this->select_lists; }