Example #1
0
 function save_grading_scale()
 {
     access_control($this);
     # Get the passed details into the url data array if any
     $urldata = $this->uri->uri_to_assoc(3, array('m', 'i', 'a', 't'));
     # Pick all assigned data
     $data = assign_to_data($urldata);
     if ($data['save'] || $data['saveandnew']) {
         $data['formdata'] = $data;
         $required_fields = array('gradingname', 'classes');
         foreach ($data as $key => $data_value) {
             $data[$key] = restore_bad_chars($data_value);
         }
         $_POST = clean_form_data($data);
         $validation_results = validate_form('', $_POST, $required_fields);
         $feename_error = '';
         #Only proceed if the validation for required fields passes
         if ($validation_results['bool']) {
             #Convert classes into strings
             if (is_array($_POST['classes'])) {
                 $_POST['classes'] = stringify_array($_POST['classes'], '|');
             } else {
                 $_POST['classes'] = '|' . $_POST['classes'] . '|';
             }
             if (!empty($data['editid'])) {
                 $result = $this->db->query($this->Query_reader->get_query_by_code('update_grading_scale', array_merge($_POST, array('id' => $data['editid']))));
             } else {
                 #Add the school id and author to the data array
                 $_POST = array_merge($_POST, array('school' => $this->myschool['id'], 'author' => $this->session->userdata('userid')));
                 $result = $this->db->query($this->Query_reader->get_query_by_code('add_grading_scale', $_POST));
                 #Check if grades have been added
                 if (!empty($_POST['gradingdetails'])) {
                     $grades = explode('|', trim($_POST['gradingdetails']));
                     #Format the data for the query
                     $query_data = '';
                     foreach ($grades as $grade) {
                         $grade_details = explode('^', $grade);
                         $query_data .= $query_data == '' ? '(' . $this->db->insert_id() . ', "' . $grade_details[0] . '", "' . $grade_details[1] . '"' . ', "' . $grade_details[2] . '", "' . $grade_details[3] . '")' : ',(' . $this->db->insert_id() . ', "' . $grade_details[0] . '", "' . $grade_details[1] . '"' . ', "' . $grade_details[2] . '", "' . $grade_details[3] . '")';
                     }
                     $papers_result = $this->db->query($this->Query_reader->get_query_by_code('add_grading_details', array('rows' => $query_data)));
                 }
             }
             #Format and send the errors
             if (!empty($result) && $result) {
                 $data['msg'] = empty($data['editid']) ? $data['gradingname'] . ' has been added.' : 'Details for ' . $data['gradename'] . ' have been updated.';
                 $data['formdata'] = array();
             } else {
                 if (empty($data['msg'])) {
                     $data['msg'] = "ERROR: The grading scale could not be saved or was not saved correctly.";
                 }
             }
         }
         $data['requiredfields'] = $validation_results['requiredfields'];
     }
     $data['classes'] = $this->classobj->get_classes();
     $data['terms'] = $this->terms->get_terms();
     $this->load->view('incl/grading_form', $data);
 }
Example #2
0
 function save_exam()
 {
     access_control($this);
     # Get the passed details into the url data array if any
     $urldata = $this->uri->uri_to_assoc(3, array('m', 'i', 'a', 't'));
     # Pick all assigned data
     $data = assign_to_data($urldata);
     if ($data['save'] || $data['saveandnew']) {
         $data['formdata'] = $data;
         $required_fields = array('exam', 'term', 'contribution', 'classes');
         foreach ($data as $key => $data_value) {
             $data[$key] = restore_bad_chars($data_value);
         }
         $_POST = clean_form_data($data);
         $validation_results = validate_form('', $_POST, $required_fields);
         $feename_error = '';
         #Only proceed if the validation for required fields passes
         if ($validation_results['bool']) {
             #Convert classes into strings
             if (is_array($_POST['classes'])) {
                 $_POST['classes'] = stringify_array($_POST['classes'], '|');
             } else {
                 $_POST['classes'] = '|' . $_POST['classes'] . '|';
             }
             if (!empty($data['editid'])) {
                 $result = $this->db->query($this->Query_reader->get_query_by_code('update_exam', array_merge($_POST, array('id' => $data['editid']))));
             } else {
                 #Add the school id and author to the data array
                 $_POST = array_merge($_POST, array('school' => $this->myschool['id'], 'author' => $this->session->userdata('userid')));
                 $result = $this->db->query($this->Query_reader->get_query_by_code('add_exam', $_POST));
             }
             #Format and send the errors
             if (!empty($result) && $result) {
                 $data['msg'] = empty($data['editid']) ? $data['exam'] . ' has been added.' : 'Details for ' . $data['exam'] . ' have been updated.';
                 $data['formdata'] = array();
             } else {
                 if (empty($data['msg'])) {
                     $data['msg'] = "ERROR: The exam could not be saved or was not saved correctly.";
                 }
             }
         }
         $data['requiredfields'] = $validation_results['requiredfields'];
     }
     $data['classes'] = $this->classobj->get_classes();
     $data['terms'] = $this->terms->get_terms();
     $this->load->view('incl/exam_form', $data);
 }
Example #3
0
function stringify_array($array_obj, $value_separator)
{
    if (is_array($array_obj)) {
        foreach ($array_obj as $val) {
            if (is_array($val)) {
                $value_separator .= stringify_array($val, $value_separator);
            } else {
                $value_separator .= $val . "|";
            }
        }
        return $value_separator;
    } else {
        return $value_separator = "ERROR : {$array_obj} is not an array";
    }
}
Example #4
0
 function save_fee()
 {
     access_control($this);
     # Get the passed details into the url data array if any
     $urldata = $this->uri->uri_to_assoc(3, array('m', 'i', 'a', 't'));
     # Pick all assigned data
     $data = assign_to_data($urldata);
     if ($this->input->post('save')) {
         $data['feedetails'] = $_POST;
         $required_fields = array('fee', 'amount', 'classes*COMBOBOX', 'frequency', 'term');
         $_POST = clean_form_data($_POST);
         $validation_results = validate_form('', $_POST, $required_fields);
         $feename_error = '';
         #set status as editing on destination if updating
         if ($this->input->post('editid')) {
             $data['editid'] = $_POST['editid'];
         }
         #Only proceed if the validation for required fields passes
         if ($validation_results['bool'] && !(empty($data['editid']) && !empty($user_details))) {
             if ($this->input->post('editid')) {
                 #Check if another fee other than the current one exists with the same name for the same term
                 $fee_details = $this->Query_reader->get_row_as_array('search_fees_structure', array('limittext' => '', 'isactive' => 'Y', 'searchstring' => ' AND term = "' . $data['feedetails']['term'] . '" AND fee = "' . $data['feedetails']['fee'] . '" AND id != ' . $data['editid'] . ' AND school =' . $this->myschool['id']));
                 if (empty($fee_details)) {
                     #Add the school id and author to the data array
                     $_POST = array_merge($_POST, array('school' => $this->myschool['id'], 'author' => $this->session->userdata('userid')));
                     #Convert classes into strings
                     $_POST['classes'] = stringify_array($_POST['classes'], '|');
                     $result = $this->financeobj->update_fee(array_merge($_POST, array('id' => $data['editid'])));
                 } else {
                     if (!empty($class_details)) {
                         $feename_error = "<br />WARNING: A fee with the same name for the same term already exists.";
                     }
                 }
             } else {
                 #Check if fee name exists for the selected term
                 $fee_details = $this->Query_reader->get_row_as_array('search_fees_structure', array('limittext' => '', 'isactive' => 'Y', 'searchstring' => ' AND term = "' . $data['feedetails']['term'] . '" AND fee = "' . $data['feedetails']['fee'] . '"'));
                 if (empty($fee_details)) {
                     #Add the school id and author to the data array
                     $_POST = array_merge($_POST, array('school' => $this->myschool['id'], 'author' => $this->session->userdata('userid')));
                     #Convert classes into strings
                     $_POST['classes'] = stringify_array($_POST['classes'], '|');
                     $result = $this->financeobj->add_fee($_POST);
                 } else {
                     if (!empty($fee_details)) {
                         $feename_error = "<br />WARNING: A fee with the same name for the selected term already exists.";
                     }
                 }
             }
             #Format and send the errors
             if (!empty($result) && $result) {
                 $this->session->set_userdata('usave', "The fee data has been successfully saved.");
                 redirect("finances/manage_fee_structure/m/usave");
             } else {
                 if (empty($data['msg'])) {
                     $data['msg'] = "ERROR: The fee could not be saved or was not saved correctly." . $feename_error;
                 }
             }
         } else {
             if (empty($data['editid']) && !empty($fee_details)) {
                 $data['msg'] = "WARNING: A fee with the same name already exists.<br />";
             }
         }
         if ((empty($validation_results['bool']) || !empty($validation_results['bool']) && !$validation_results['bool']) && empty($data['msg'])) {
             $data['msg'] = "WARNING: The highlighted fields are required.";
         }
         $data['requiredfields'] = $validation_results['requiredfields'];
     }
     $data['classes'] = $this->classobj->get_classes();
     $data['terms'] = $this->terms->get_terms();
     $this->load->view('finances/fee_form_view', $data);
 }