public function updateStudyYears() {
if (!$this->input->post() OR !$this->input->is_ajax_request() ){
echo json_encode(array('status'=>'failed','errors'=>array('Access Mode'=>'Disallowed')));
exit();
}
else {
$postData = $this->input->post(NULL, true);
$yearArray = $postData['years'];
if(empty($yearArray)) {
echo json_encode(array('status'=>'failed', 'errors'=>'Years are empty'));
exit();
}
$this->form_validation->set_rules('years[intStartYr]', 'Start Year', 'required',
array('required' => 'Start year must have a valid year.'));
$this->form_validation->set_rules('years[intEndYr]', 'End Year', 'required',
array('required' => 'End year must have a valid year.'));
if ($this->form_validation->run() === FALSE) {
$validationErrs = $this->form_validation->error_array();
echo json_encode(array('status'=>'form-errors', 'valErrs'=>$validationErrs));
exit;
}
else {
$status = $this->climate_indicators_model->setStudyYears($yearArray);
if ($status) {
echo json_encode(array('status'=>'success', 'message'=>'Study year information successfully updated.'));
}
else echo json_encode(array('status'=>'failed', 'errors'=>'Db error on update'));
}
exit();
}
}