Exemple #1
0
 /**
  * Save newly added dynamic categories
  */
 function save_category()
 {
     $this->auto_render = FALSE;
     $this->template = "";
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory($_POST);
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('job_category_title', 'required', 'length[3,200]');
         $post->add_rules('job_category_description', 'required');
         $post->add_rules('job_category_color', 'required', 'length[6,6]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // SAVE Category
             $job_category = new Job_Category_Model();
             $job_category->job_category_title = $post->job_category_title;
             $job_category->job_category_description = $post->job_category_description;
             $job_category->job_category_color = $post->job_category_color;
             $job_category->save();
             $form_saved = TRUE;
             echo json_encode(array("status" => "saved", "id" => $job_category->id));
         } else {
             echo json_encode(array("status" => "error"));
         }
     } else {
         echo json_encode(array("status" => "error"));
     }
 }
Exemple #2
0
 /**
  * Submits a new report.
  */
 public function submit($id = false, $saved = false)
 {
     $this->template->header->this_page = 'jobs_submit';
     $this->template->content = new View('jobs_submit');
     // setup and initialize form field names
     $form = array('job_title' => '', 'job_description' => '', 'latitude' => '', 'longitude' => '', 'location_name' => '', 'country_id' => '', 'job_category' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '');
     //	copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     if ($saved == 'saved') {
         $form_saved = TRUE;
     } else {
         $form_saved = FALSE;
     }
     // Initialize Default Values
     /*$form['job_date'] = date("m/d/Y",time());
     		$form['job_hour'] = "12";
     		$form['job_minute'] = "00";
             $form['job_ampm'] = "pm";
             // initialize custom field array
     		$form['custom_field'] = $this->_get_custom_form_fields($id,'',true);
                     //GET custom forms
     		$forms = array();
     		foreach (ORM::factory('form')->find_all() as $custom_forms)
     		{
     			$forms[$custom_forms->id] = $custom_forms->form_title;
     		}
     		$this->template->content->forms = $forms;*/
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things
         $post = Validation::factory(array_merge($_POST, $_FILES));
         //  Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('job_title', 'required', 'length[3,200]');
         $post->add_rules('job_description', 'required');
         // Validate for maximum and minimum latitude values
         $post->add_rules('latitude', 'required', 'between[-90,90]');
         $post->add_rules('longitude', 'required', 'between[-180,180]');
         $post->add_rules('location_name', 'required', 'length[3,200]');
         $post->add_rules('person_first', 'required', 'length[3,100]');
         $post->add_rules('person_last', 'required', 'length[3,100]');
         $post->add_rules('person_email', 'required', 'email', 'length[3,100]');
         //XXX: Hack to validate for no checkboxes checked
         if (!isset($_POST['job_category'])) {
             $post->job_category = "";
             $post->add_error('job_category', 'required');
         } else {
             $post->add_rules('job_category.*', 'required', 'numeric');
         }
         // Validate Personal Information
         if (!empty($_POST['person_first'])) {
             $post->add_rules('person_first', 'length[3,100]');
         }
         if (!empty($_POST['person_last'])) {
             $post->add_rules('person_last', 'length[3,100]');
         }
         if (!empty($_POST['person_email'])) {
             $post->add_rules('person_email', 'email', 'length[3,100]');
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // STEP 1: SAVE LOCATION
             $location = new Location_Model();
             $location->location_name = $post->location_name;
             $location->latitude = $post->latitude;
             $location->longitude = $post->longitude;
             $location->location_date = date("Y-m-d H:i:s", time());
             $location->save();
             // STEP 2: SAVE job
             $job = new Job_Model();
             $job->location_id = $location->id;
             $job->user_id = 0;
             $job->job_title = $post->job_title;
             $job->job_description = $post->job_description;
             $job->job_dateadd = date("Y-m-d H:i:s", time());
             $job->save();
             // STEP 3: SAVE CATEGORIES
             foreach ($post->job_category as $item) {
                 $job_category = new Job_Category_Model();
                 $job_category->job_id = $job->id;
                 $job_category->j_category_id = $item;
                 $job_category->save();
             }
             // STEP 5: SAVE PERSONAL INFORMATION
             $person = new Job_Person_Model();
             $person->location_id = $location->id;
             $person->job_id = $job->id;
             $person->person_first = $post->person_first;
             $person->person_last = $post->person_last;
             $person->person_email = $post->person_email;
             $person->person_date = date("Y-m-d H:i:s", time());
             $person->save();
             url::redirect('jobs/thanks');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('report'));
             $form_error = TRUE;
         }
     }
     // Retrieve Country Cities
     $default_country = Kohana::config('settings.default_country');
     $this->template->content->cities = $this->_get_cities($default_country);
     $this->template->content->multi_country = Kohana::config('settings.multi_country');
     $this->template->content->id = $id;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->categories = $this->_get_categories($form['job_category']);
     // Javascript Header
     $this->template->header->map_enabled = TRUE;
     $this->template->header->datepicker_enabled = TRUE;
     $this->template->header->js = new View('reports_submit_js');
     $this->template->header->js->default_map = Kohana::config('settings.default_map');
     $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom');
     if (!$form['latitude'] || !$form['latitude']) {
         $this->template->header->js->latitude = Kohana::config('settings.default_lat');
         $this->template->header->js->longitude = Kohana::config('settings.default_lon');
     } else {
         $this->template->header->js->latitude = $form['latitude'];
         $this->template->header->js->longitude = $form['longitude'];
     }
     //include footer form js file
     $footerjs = new View('footer_form_js');
     // Pack the javascript using the javascriptpacker helper
     $myPacker = new javascriptpacker($footerjs, 'Normal', false, false);
     $footerjs = $myPacker->pack();
     $this->template->header->js .= $footerjs;
 }