/** * 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; }