Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 88

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 215

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 216

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 217

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 218

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 219

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 220
load->model('User_model'); $this->load->helper("url"); $this->load->library("pagination"); require_once APPPATH."/third_party/PHPExcel.php"; if (!$this->session->userdata('reg_number')) { $this->session->set_flashdata('flash_data', 'You don\'t have access!'); redirect('Welcome'); }else{ if($this->session->userdata('type')!='super_user'){ $this->session->set_flashdata('flash_data', 'You don\'t have access!'); redirect('Welcome'); } } } function index(){ $this->load->view('includes/super_header'); echo 'super user'; $this->load->view('includes/super_footer'); } public function clean_sub_subjects(){ $exam = $_REQUEST['exam_id']; $sql = "DELETE FROM ca WHERE exam_id = $exam AND subject_id IN ( SELECT subject_id FROM all_subjects WHERE is_sub = 1 )"; $this->db->query($sql); redirect($_SERVER['HTTP_REFERER']); } public function angalia_ca_sub(){ $exam_id = 79; foreach($this->db->distinct()->select('subject_id')->where('exam_id',$exam_id)->get('ca')->result() as $sub){ foreach($this->db->where('subject_id',$sub->subject_id)->where('is_sub',1)->get('all_subjects')->result() as $name){ if($name->is_sub == 1){ $count = $this->db->where('exam_id',$exam_id)->where('subject_id',$sub->subject_id)->count_all_results('ca'); if($count > 0){ echo $name->name." - ".$count."
"; //$this->db->where('subject_id',$name->subject_id)->where('exam_id',$exam_id)->delete('ca'); } } } echo "
"; } echo "
SCHOOL GPA ++++++++++++++"; foreach($this->db->where('exam_id',$exam_id)->get('subjects_school_gpa')->result() as $sub){ foreach($this->db->where('subject_id',$sub->subject_id)->get('all_subjects')->result() as $name){ if($name->is_sub == 1){ // tunadelete hapa echo $name->name."
"; //$this->db->where('subject_id',$name->subject_id)->where('school_id',$sub->school_id)->where('exam_id',$exam_id)->delete('subjects_school_gpa'); } } echo "
"; } } public function futa_ca_sub1(){ $exam_id = 79; foreach($this->db->distinct()->select('reg_number')->where('exam_id',$exam_id)->get('ca')->result() as $reg){ $comb = ''; foreach($this->db->where('reg_number',$reg->reg_number)->get('classes')->result() as $class){ $comb = $class->stream; } $getcasub = $this->db->distinct()->select('main_subject_id')->where('reg_number',$reg->reg_number)->where('exam_id',$exam_id)->get('ca_sub'); echo $reg->reg_number.' - '.$comb.'
'; foreach($getcasub->result() as $main_subject){ $countca = $this->db->where('subject_id',$main_subject->main_subject_id)->where('exam_id',$exam_id)->where('reg_number',$reg->reg_number)->count_all_results('ca'); if($countca == 0){ //d nothing foreach($this->db->where('subject_id',$main_subject->main_subject_id)->get('all_subjects')->result() as $rowname){ $subject_name = $rowname->name; } echo 'Futa hili = '.$main_subject->main_subject_id.' '.$subject_name.'
'; }else{ //la kufuta hili //tafuta jina la somo } } echo '
'; } } public function futa_ca_sub(){ $exam_id = 79; foreach($this->db->distinct()->select('reg_number')->where('exam_id',$exam_id)->get('ca')->result() as $reg){ foreach($this->db->where('reg_number',$reg->reg_number)->get('classes')->result() as $comb){ foreach($this->db->where('combination',$comb->stream)->get('combinations')->result() as $valid){ // find valid subjects; $subids = explode(',',$valid->ids); echo $comb->stream." "; $sub = $this->db->distinct()->select('main_subject_id')->where('reg_number',$reg->reg_number)->where_not_in('main_subject_id',$subids)->get('ca_sub'); if($sub->num_rows() > 0){ echo "Invalid ca sub
"; foreach($sub->result() as $ss){ foreach($this->db->where('subject_id',$ss->main_subject_id)->get('all_subjects')->result() as $name){ echo $name->name.", "; } } } echo "
"; $this->db->not_like('subject_id',26); ## GS $this->db->not_like('subject_id',60); ## AC $this->db->not_like('subject_id',28); ## BAM $this->db->not_like('subject_id',54); ## DIVINITY $this->db->not_like('subject_id',55); ## MUSIC $ca = $this->db->distinct()->select('subject_id')->where('reg_number',$reg->reg_number)->where_not_in('subject_id',$subids)->where('exam_id',$exam_id)->get('ca'); if($ca->num_rows() > 0){ echo "Invalid ca
"; foreach($ca->result() as $ss){ foreach($this->db->where('subject_id',$ss->subject_id)->get('all_subjects')->result() as $name){ echo $name->name.", "; } } } } } // $count_sub = $this->db->distinct()->select('main_subject_id')->where('reg_number',$sub->reg_number)->where('exam_id',$exam_id)->count_all_results('ca_sub'); // $this->db->not_like('subject_id',26); ## GS // $this->db->not_like('subject_id',28); ## BAM // $this->db->not_like('subject_id',54); ## DIVINITY // $this->db->not_like('subject_id',55); ## MUSIC // $count_ca = $this->db->distinct()->select('subject_id')->where('reg_number',$sub->reg_number)->where('exam_id',$exam_id)->count_all_results('ca'); // $st = $count_ca > $count_sub ? 'style="color:red"':'style="color:green"'; // if($count_ca > $count_sub){ // echo ''; // echo " count sub ".$count_sub." ". " count ca ".$count_ca." "; // foreach($this->db->where('reg_number',$sub->reg_number)->get('classes')->result() as $comb){ // echo $sub->reg_number.' '.$comb->stream." - "; // foreach($this->db->where('school_id',$comb->school_id)->get('schools')->result() as $sch){ // echo $sch->school_name." - "; // } // } // echo "SUBJECTS
"; // $this->db->not_like('subject_id',26); ## GS // $this->db->not_like('subject_id',28); ## BAM // $this->db->not_like('subject_id',54); ## DIVINITY // $this->db->not_like('subject_id',55); ## MUSIC // $this->db->distinct()->select('subject_id')->where('reg_number',$sub->reg_number)->where('exam_id',$exam_id); // foreach($this->db->get('ca')->result() as $main){ // foreach($this->db->where('subject_id',$main->subject_id)->get('all_subjects')->result() as $name){ // echo $name->name.", "; // } // } // echo '
'; // echo "
"; // echo "
"; // } } } public function testing_endtime(){ $now = time(); $endtime = ''; foreach($this->db->limit(5)->where('examination_id',52)->get('examination')->result() as $exam){ echo "Exam ".$exam->end_time." ".$exam->upload_deadline."
"; $endtime = $exam->upload_deadline." ".$exam->end_time; $endtime = strtotime($endtime); echo "Now: ".$now." End: ".$endtime; if($now > $endtime){ echo "Terminate"; }else{ echo "Allowed"; } } } public function school_upload(){ $exam = $_REQUEST['exam_id']; $status=0; foreach($this->db->select('school_upload')->where('examination_id',$exam)->get('examination')->result() as $ex){ $status = $ex->school_upload; } if($status == 0){ $status = 1; }else{ $status = 0; } $this->db->where('examination_id',$exam)->update('examination',array('school_upload'=>$status)); redirect($_SERVER['HTTP_REFERER']); } public function upload_questions(){ $exam = $_REQUEST['exam_id']; $status=0; foreach($this->db->select('upload_questions')->where('examination_id',$exam)->get('examination')->result() as $ex){ $status = $ex->upload_questions; } if($status == 0){ $status = 1; }else{ $status = 0; } $this->db->where('examination_id',$exam)->update('examination',array('upload_questions'=>$status)); redirect($_SERVER['HTTP_REFERER']); } public function upload_deadline(){ $time12 = $this->input->post('time'); $time24 = date("H:i", strtotime($time12)); $this->db->where('examination_id',$this->input->post('exam_id')); $this->db->update('examination',array('upload_deadline'=>$this->input->post('date'),'end_time'=>$time24)); redirect($_SERVER['HTTP_REFERER']); } public function school_report(){ $exam = $_REQUEST['exam_id']; $status=0; foreach($this->db->select('school_report')->where('examination_id',$exam)->get('examination')->result() as $ex){ $status = $ex->school_report; } if($status == 0){ $status = 1; }else{ $status = 0; } $this->db->where('examination_id',$exam)->update('examination',array('school_report'=>$status)); redirect($_SERVER['HTTP_REFERER']); } public function create_combination(){ exit; $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; // echo $exam_id.' - '.$candidate;exit; $students_updated=0; $this->db->where('examination_id',$exam_id); $gett=$this->db->get('examination'); $count=$gett->num_rows(); foreach($gett->result() as $rows){ $month=$rows->month; $class=$rows->class_level; $year=$rows->academic_year; $academic_year=$rows->academic_year; $region=$rows->region; $district_exam=$rows->district; $district=$rows->district; $exam_header=$rows->heading; $exam_name=$rows->exam_name; $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); $status = $rows->status; $category = $rows->category; $group_id = $rows->group_id; } /* $this->db->where('academic_year', $academic_year); $this->db->where('stream', 'UNK'); $this->db->where('candidate',$candidate); foreach($this->db->get('classes')->result() as $rt){; echo $rt->reg_number.'
'; $this->db->select('s.full_name,c.school_name,s.id_number'); $this->db->where('s.reg_number',$rt->reg_number); $this->db->from('students as s'); $this->db->join('schools as c','c.school_id=s.school_id'); $g = $this->db->get(); foreach($g->result() as $sc){ echo $sc->school_name." ".$sc->id_number."
"; } } exit; */ $this->db->distinct(); $this->db->select('reg_number'); $this->db->where('exam_id',$exam_id); foreach($this->db->get('ca')->result() as $students){ $this->db->distinct(); $this->db->select('subject_id'); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$students->reg_number); $this->db->not_like('subject_id',26); ## GS $this->db->not_like('subject_id',60); ## AC $this->db->not_like('subject_id',28); ## BAM $this->db->not_like('subject_id',54); ## DIVINITY $this->db->not_like('subject_id',55); ## MUSIC $this->db->order_by('subject_id','asc'); $this->db->limit(3); $subjects = $this->db->get('ca'); $sum = ''; foreach($subjects->result() as $subs){ $sum.= $subs->subject_id; // Concatinate the ID's //echo $subs->subject_id; } //echo " "; /* $this->db->select('s.full_name,c.school_name,s.id_number'); $this->db->where('s.reg_number',$students->reg_number); $this->db->from('students as s'); $this->db->join('schools as c','c.school_id=s.school_id'); $g = $this->db->get(); foreach($g->result() as $sc){ echo $sc->school_name." ".$sc->id_number." "; } echo $students->reg_number; */ $this->db->where('id_sum',$sum); $c = $this->db->get('combinations'); foreach($c->result() as $comb){ $data_stream = array('stream'=>$comb->combination); } if($c->num_rows() == 0){ ## UNK Combination $data_stream = array('stream'=>'UNK'); if($subjects->num_rows() == 3 ){ //echo " UNK - ".$subjects->num_rows(); $data_stream = array('stream'=>'UNK'); }else{ // echo " Incomplete ".$subjects->num_rows(); $this->db->where('reg_number',$students->reg_number); $this->db->where('academic_year', $academic_year); $this->db->where('candidate',$candidate); foreach($this->db->get('classes')->result() as $rt){; $data_stream = array('stream'=>$rt->stream); } } $this->db->where('reg_number',$students->reg_number); $this->db->where('academic_year', $academic_year); $this->db->where('candidate',$candidate); $this->db->update('classes',$data_stream); $this->db->where('reg_number',$students->reg_number); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->update('ca',$data_stream); $this->db->where('reg_number',$students->reg_number); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->update('monthly_results',$data_stream); }else{ $students_updated++; //echo " ".$data['stream']." Complete"; $this->db->where('reg_number',$students->reg_number); $this->db->where('academic_year', $academic_year); $this->db->where('candidate',$candidate); $this->db->update('classes',$data_stream); $this->db->where('reg_number',$students->reg_number); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->update('ca',$data_stream); $this->db->where('reg_number',$students->reg_number); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->update('monthly_results',$data_stream); } //echo "
"; } ?>
Info!

db->where('examination_id',$exam_id); $gett=$this->db->get('examination'); $count=$gett->num_rows(); foreach($gett->result() as $rows){ $month=$rows->month; $class=$rows->class_level; $year=$rows->academic_year; $academic_year=$rows->academic_year; $region=$rows->region; $district_exam=$rows->district; $district=$rows->district; $exam_header=$rows->heading; $exam_name=$rows->exam_name; $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); $status = $rows->status; $category = $rows->category; $group_id = $rows->group_id; } ## Monthly results for each school if($category == 'P'){ ####################################### $this->db->distinct(); $this->db->select('school_id'); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->order_by('id',"asc"); $this->db->limit($limit,$start); $g = $this->db->get('ca'); foreach($g->result() as $schools){ $school = $schools->school_id; foreach($this->db->where('school_id',$school)->get('schools')->result() as $ddd){ $district = $ddd->district; $region = $ddd->region; $stream = 'A'; } $sum_of_marks=0; $required_subjects_for_calcultion=0; $required_subjects_for_calcultion_average=0; $average_of_marks=0; $grade=''; $remark=''; $grade1=''; $sum_of_marks2=0; $mark_grade=''; $avg_cal=''; $div_cal=''; $complete=''; ## select sum of marks for this monly and this student for reqiured only $this->db->select('SUM(mark) as mark, AVG(mark) as avg, reg_number'); $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('status', 0); $this->db->group_by('reg_number'); $get_ca=$this->db->get('ca'); foreach($get_ca->result() as $row_ca){ $sum_of_marks = round($row_ca->mark); $average_of_marks = round($row_ca->avg); $reg_number = $row_ca->reg_number; ## Select all entered and included to the calculations $this->db->where('school_id',$school); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->not_like('subject_id',26); ## GS $this->db->not_like('subject_id',60); ## AC $this->db->not_like('subject_id',28); ## BAM $this->db->not_like('subject_id',54); ## DIVINITY $this->db->not_like('subject_id',55); ## MUSIC $this->db->where('status', 0); $required_subjects_for_calcultion=$this->db->count_all_results('ca'); //this for average take all subjects $this->db->where('school_id',$school); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('status', 0); $required_subjects_for_calcultion_average=$this->db->count_all_results('ca'); $subjects = 4; if($category =='A'){ $subjects = 2; } if($required_subjects_for_calcultion>$subjects){ //complete results $complete=1; }else{ //incoplete results $complete=0; } if($required_subjects_for_calcultion==0){ // No results calculations, because subjects for results calcultions not set'; }else{ //finding the grades from the score $this->db->where('students_type',$category); $get_grades=$this->db->get('grade_settings'); foreach($get_grades->result() as $row_grade){ if($row_grade->start_mark<=round($average_of_marks) && round($average_of_marks)<=$row_grade->end_mark){ $grade=$row_grade->grade; $remark=$row_grade->remark; //inserting values to the databse without positions $data3=array( 'school_id'=>$school, 'reg_number'=>$reg_number, 'class_level'=>$class, 'district_id'=>$district, 'region_id'=>$region, 'exam_id'=>$exam_id, 'stream'=>$stream, 'candidate'=>$candidate, 'academic_year'=>$academic_year, 'month'=>$month, 'total_marks'=>$sum_of_marks, 'average'=>$average_of_marks, 'grade'=>$grade, 'remark'=>$remark, 'category'=>$category, 'division'=>'---', 'complete'=>$complete, ); $this->db->where('school_id',$school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('month',$month); $this->db->where('academic_year',$academic_year); $this->db->where('class_level',$class); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('category', $category); $count_entered= $this->db->count_all_results('monthly_results'); if($count_entered>0){ $this->db->where('school_id',$school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('month',$month); $this->db->where('academic_year',$academic_year); $this->db->where('class_level',$class); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('category', $category); $this->db->update('monthly_results',$data3); //there should be updating on mid term results }else{ $this->db->insert('monthly_results',$data3); //there should be inserting into mid term results } } } $subjects = 5; $this->db->where('school_id',$school); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->not_like('subject_id',26); ## GS $this->db->not_like('subject_id',60); ## AC $this->db->not_like('subject_id',28); ## BAM $this->db->not_like('subject_id',54); ## DIVINITY $this->db->not_like('subject_id',55); ## MUSIC $this->db->where('status', 0); $this->db->order_by('mark', 'desc'); $this->db->limit($subjects); $ca = $this->db->get('ca'); $point = 42; $gpa=8;$division = "---"; $division_remark="Pass"; if($ca->num_rows() == $subjects){ $point = 0; foreach($ca->result() as $mark){ $this->db->where('students_type',$category); $this->db->where('grade',$mark->grade); $get_points=$this->db->get('point_settings'); foreach($get_points->result() as $row_point){ $point= $point+$row_point->point; } } //finding division if($grade=='E'){ $division_remark="Fail"; } $gpa = round($point/5,4); $data = array( //'division'=>$division, //'point'=>$point, 'gpa'=>$gpa, 'remark'=>$division_remark, ); //print_r($data); //echo "

"; $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $this->db->where('academic_year',$academic_year); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->update('monthly_results',$data); }else{ $data = array( // 'division'=>$division, // 'point'=>$point, 'gpa'=>$gpa, 'remark'=>$division_remark, ); $this->db->where('school_id',$school); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('category', $category); $this->db->update('monthly_results',$data); } } } ####################################### } }else{ //echo $exam_name;exit; $this->db->distinct(); //$this->db->where('school_id','SS5c3c69535aa4b'); $this->db->select('school_id'); if($group_id==0){ $this->db->where('region_id',$region); }else{ //$this->db->where('group_id',$group_id); } $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->order_by('id',"asc"); $this->db->limit($limit,$start); $g = $this->db->get('ca'); foreach($g->result() as $schools){ $school = $schools->school_id; foreach($this->db->where('school_id',$school)->get('schools')->result() as $ddd){ $district = $district_exam = $ddd->district; $region = $ddd->region; } //echo $group_id.' '. $region.' '.$district_exam.' - '.$district;exit; $sum_of_marks=0; $required_subjects_for_calcultion=0; $required_subjects_for_calcultion_average=0; $average_of_marks=0; $grade=''; $remark=''; $grade1=''; $sum_of_marks2=0; $mark_grade=''; $avg_cal=''; $div_cal=''; $complete=''; $subjects = 7; if($category =='A'){ $subjects = 3; } ## select sum of marks for this monly and this student for reqiured only $this->db->select('SUM(mark) as mark, AVG(mark) as avg, reg_number'); $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('status', 0); $this->db->group_by('reg_number'); $get_ca=$this->db->get('ca'); foreach($get_ca->result() as $row_ca){ $sum_of_marks=0; $reg_number = $row_ca->reg_number; //print_r($row_ca); echo "

"; $sum_of_marks = $row_ca->mark; $average_of_marks = $row_ca->avg; $this->db->where('reg_number',$reg_number); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->where('academic_year',$academic_year); foreach($this->db->get('classes')->result() as $classes){ $class = $classes->class_level; $district = $classes->district; $region = $classes->region; $stream = $classes->stream; } //this for average take all subjects $this->db->where('school_id',$school); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('status', 0); $count_subjects=$this->db->count_all_results('ca'); $subjects = 6; if($category =='A'){ $subjects = 2; } if($count_subjects > $subjects){ $complete=1; }else{ $complete=0; } $this->db->where('school_id',$school); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->not_like('subject_id',26); ## GS $this->db->not_like('subject_id',60); ## AC $this->db->not_like('subject_id',28); ## BAM $this->db->not_like('subject_id',54); ## DIVINITY $this->db->not_like('subject_id',55); ## MUSIC $this->db->where('status', 0); $this->db->order_by('mark', 'desc'); //$this->db->limit($subjects); $required_subjects_for_calcultion = $this->db->count_all_results('ca'); if($required_subjects_for_calcultion==0){ // No results calculations, because subjects for results calcultions not set'; }else{ //finding the grades from the score $this->db->where('students_type',$category); $get_grades=$this->db->get('grade_settings'); foreach($get_grades->result() as $row_grade){ if($row_grade->start_mark<=round($average_of_marks) && round($average_of_marks)<=$row_grade->end_mark){ $grade=$row_grade->grade; $remark=$row_grade->remark; //inserting values to the databse without positions $this->db->where('reg_number',$reg_number); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->where('academic_year',$academic_year); foreach($this->db->get('classes')->result() as $classes){ $class = $classes->class_level; $district = $classes->district; $region = $classes->region; $stream = $classes->stream; } if($category == 'P'){ $stream = 'A'; } $data3=array( 'school_id'=>$school, 'reg_number'=>$reg_number, 'class_level'=>$class, 'district_id'=>$district, 'region_id'=>$region, 'exam_id'=>$exam_id, 'stream'=>$stream, 'candidate'=>$candidate, 'academic_year'=>$academic_year, 'month'=>$month, 'total_marks'=>round($sum_of_marks), 'average'=>round($average_of_marks), 'grade'=>$grade, 'remark'=>$remark, 'category'=>$category, 'division'=>'---', 'complete'=>$complete, ); $this->db->where('school_id',$school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $count_entered= $this->db->count_all_results('monthly_results'); if($count_entered>0){ $this->db->where('school_id',$school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->update('monthly_results',$data3); }else{ $this->db->insert('monthly_results',$data3); } } } ## Division calculation here //echo "Division calculation here"; ## Finding best seven subejcts which are included in div cal $subjects = 7; if($category =='A'){ $subjects = 3; } $this->db->where('school_id',$school); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->not_like('subject_id',26); ## GS $this->db->not_like('subject_id',60); ## AC $this->db->not_like('subject_id',28); ## BAM $this->db->not_like('subject_id',54); ## DIVINITY $this->db->not_like('subject_id',55); ## MUSIC $this->db->where('status', 0); $this->db->order_by('mark', 'desc'); $this->db->limit($subjects); $ca = $this->db->get('ca'); $point = 42; $gpa=8;$division = "---"; $division_remark="Fail"; if($ca->num_rows() == $subjects){ $point = 0; foreach($ca->result() as $mark){ $this->db->where('students_type',$category); $this->db->where('grade',$mark->grade); $get_points=$this->db->get('point_settings'); foreach($get_points->result() as $row_point){ $point= $point+$row_point->point; } } //finding division $this->db->where('students_type',$category); $get_div=$this->db->get('division_settings'); foreach($get_div->result() as $row_div){ if($row_div->start_point<=round($point) && round($point)<=$row_div->end_point){ $division=$row_div->division; $division_remark=$row_div->remark; } } $gpa = round($point/7,4); if($category =='A'){ $gpa = round($point/3,4); } $data = array( 'division'=>$division, 'point'=>$point, 'complete_sort'=>1, 'complete'=>$point==42 ? 0:1, 'gpa'=>$gpa, 'remark'=>$division_remark, ); //print_r($data); //echo "

"; $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $this->db->where('academic_year',$academic_year); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->update('monthly_results',$data); }else{ if($region == 3){ $complete = 1; $pointNew = 0; // finding subject done and their grades foreach($ca->result() as $mark){ $this->db->where('students_type',$category); $this->db->where('grade',$mark->grade); $get_points=$this->db->get('point_settings'); foreach($get_points->result() as $row_point){ $pointNew= $pointNew+$row_point->point; } } // special case for dodoma division calculation for incomplete if($subjects == 3){ $pointNew = $pointNew + 7*($subjects - $ca->num_rows()); }else{ $pointNew = $pointNew + 5*($subjects - $ca->num_rows()); } $this->db->where('students_type',$category); $get_div=$this->db->get('division_settings'); foreach($get_div->result() as $row_div){ if($row_div->start_point<=round($pointNew) && round($pointNew)<=$row_div->end_point){ if($row_div->division != 0){ $division='IV'; }else{ $division = 0; } $division_remark=$row_div->remark; } } if($point > 2){ $division = 'IV'; }else{ $division = 0; } }else{ $complete = $point==42 ? 0:1; // other regions } $data = array( 'division'=>$division, 'point'=>$point, // 'complete'=>$point==42 ? 0:1, 'complete_sort'=>0, 'complete'=>$complete, 'gpa'=>$gpa, 'remark'=>$division_remark, ); $this->db->where('school_id',$school); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('category', $category); $this->db->update('monthly_results',$data); } /* //deleting monthly results if all ca for the specific month have been deleted $this->db->where('school_id',$school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $check_from_ca= $this->db->count_all_results('ca'); if($check_from_ca<1){ $this->db->where('school_id', $school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('month', $month); $this->db->where('academic_year',$academic_year); $this->db->where('class_level', $class); $this->db->where('category', $category); $this->db->delete('monthly_results'); } */ } } } } ## End monthly results redirect($_SERVER['HTTP_REFERER']); } /* public function calculate_results(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $limit = $_REQUEST['limit']; $order = $_REQUEST['order']; $this->db->where('examination_id',$exam_id); $gett=$this->db->get('examination'); $count=$gett->num_rows(); foreach($gett->result() as $rows){ $month=$rows->month; $year=$rows->academic_year; $academic_year=$rows->academic_year; $region=$rows->region; $district_exam=$rows->district; $exam_header=$rows->heading; $exam_name=$rows->exam_name; $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); $status = $rows->status; $category = $rows->category; } ## Monthly results for each school $this->db->distinct(); $this->db->select('school_id'); $this->db->where('exam_id',$exam_id); $this->db->order_by('id',$order); $this->db->limit($limit); $g = $this->db->get('ca'); foreach($g->result() as $schools){ $school = $schools->school_id; $sum_of_marks=0; $required_subjects_for_calcultion=0; $required_subjects_for_calcultion_average=0; $average_of_marks=0; $grade=''; $remark=''; $grade1=''; $sum_of_marks2=0; $mark_grade=''; $avg_cal=''; $div_cal=''; $complete=''; $subjects = 7; if($category =='A'){ $subjects = 3; } ## select sum of marks for this monly and this student for reqiured only $this->db->distinct(); $this->db->select('reg_number'); $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('status', 0); $get_ca=$this->db->get('ca'); foreach($get_ca->result() as $row_ca){ $sum_of_marks=0; $reg_number = $row_ca->reg_number; $this->db->where('school_id',$school); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->not_like('subject_id',26); ## GS $this->db->not_like('subject_id',60); ## AC $this->db->not_like('subject_id',28); ## BAM $this->db->not_like('subject_id',54); ## DIVINITY $this->db->not_like('subject_id',55); ## MUSIC $this->db->where('status', 0); $this->db->order_by('mark', 'desc'); $this->db->limit($subjects); $ca = $this->db->get('ca'); foreach($ca->result() as $cass){ $sum_of_marks = $sum_of_marks + $cass->mark; } $this->db->where('reg_number',$reg_number); $this->db->where('school_id',$school); $this->db->where('academic_year',$academic_year); foreach($this->db->get('classes')->result() as $classes){ $class = $classes->class_level; $district = $classes->district; $region = $classes->region; $stream = $classes->stream; } ## Select all entered and included to the calculations $this->db->where('school_id',$school); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->not_like('subject_id',26); ## GS $this->db->not_like('subject_id',28); ## BAM $this->db->not_like('subject_id',54); ## DIVINITY $this->db->not_like('subject_id',55); ## MUSIC $this->db->where('status', 0); $required_subjects_for_calcultion=$this->db->count_all_results('ca'); //this for average take all subjects $this->db->where('school_id',$school); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('status', 0); $required_subjects_for_calcultion_average=$this->db->count_all_results('ca'); $subjects = 6; if($category =='A'){ $subjects = 2; } if($required_subjects_for_calcultion>$subjects){ //complete results $complete=1; }else{ //incoplete results $complete=0; } if($required_subjects_for_calcultion==0){ // No results calculations, because subjects for results calcultions not set'; }else{ $average_of_marks=($sum_of_marks/$required_subjects_for_calcultion_average); //for considering total marks over total subjects required $average_of_marks=round($average_of_marks); //finding the grades from the score $this->db->where('students_type',$category); $get_grades=$this->db->get('grade_settings'); foreach($get_grades->result() as $row_grade){ if($row_grade->start_mark<=round($average_of_marks) && round($average_of_marks)<=$row_grade->end_mark){ $grade=$row_grade->grade; $remark=$row_grade->remark; //inserting values to the databse without positions $this->db->where('reg_number',$reg_number); $this->db->where('school_id',$school); $this->db->where('academic_year',$academic_year); foreach($this->db->get('classes')->result() as $classes){ $class = $classes->class_level; $district = $classes->district; $region = $classes->region; $stream = $classes->stream; } $data3=array( 'school_id'=>$school, 'reg_number'=>$reg_number, 'class_level'=>$class, 'district_id'=>$district, 'region_id'=>$region, 'exam_id'=>$exam_id, 'stream'=>$stream, 'candidate'=>$candidate, 'academic_year'=>$academic_year, 'month'=>$month, 'total_marks'=>$sum_of_marks, 'average'=>$average_of_marks, 'grade'=>$grade, 'remark'=>$remark, 'category'=>$category, 'division'=>'---', 'complete'=>$complete, ); //print_r($data3); echo "

"; $this->db->where('school_id',$school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $count_entered= $this->db->count_all_results('monthly_results'); if($count_entered>0){ $this->db->where('school_id',$school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->update('monthly_results',$data3); }else{ $this->db->insert('monthly_results',$data3); } } } ## Division calculation here //echo "Division calculation here"; ## Finding best seven subejcts which are included in div cal $subjects = 7; if($category =='A'){ $subjects = 3; } $this->db->where('school_id',$school); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->not_like('subject_id',26); ## GS $this->db->not_like('subject_id',28); ## BAM $this->db->not_like('subject_id',54); ## DIVINITY $this->db->not_like('subject_id',55); ## MUSIC $this->db->where('status', 0); $this->db->order_by('mark', 'desc'); $this->db->limit($subjects); $ca = $this->db->get('ca'); $point = 42; $gpa=8;$division = "---"; $division_remark="Fail"; if($ca->num_rows() == $subjects){ $point = 0; foreach($ca->result() as $mark){ $this->db->where('students_type',$category); $this->db->where('grade',$mark->grade); $get_points=$this->db->get('point_settings'); foreach($get_points->result() as $row_point){ $point= $point+$row_point->point; } } //finding division $this->db->where('students_type',$category); $get_div=$this->db->get('division_settings'); foreach($get_div->result() as $row_div){ if($row_div->start_point<=round($point) && round($point)<=$row_div->end_point){ $division=$row_div->division; $division_remark=$row_div->remark; } } $gpa = round($point/7,4); if($category =='A'){ $gpa = round($point/3,4); } $data = array( 'division'=>$division, 'point'=>$point, 'gpa'=>$gpa, 'remark'=>$division_remark, ); //print_r($data); //echo "

"; $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $this->db->where('academic_year',$academic_year); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->update('monthly_results',$data); }else{ $data = array( 'division'=>$division, 'point'=>$point, 'gpa'=>$gpa, 'remark'=>$division_remark, ); $this->db->where('school_id',$school); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('category', $category); $this->db->update('monthly_results',$data); } //deleting monthly results if all ca for the specific month have been deleted $this->db->where('school_id',$school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $check_from_ca= $this->db->count_all_results('ca'); if($check_from_ca<1 || $sum_of_marks==0){ $this->db->where('school_id', $school); $this->db->where('district_id', $district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$reg_number); $this->db->where('candidate',$candidate); $this->db->where('month', $month); $this->db->where('academic_year',$academic_year); $this->db->where('class_level', $class); $this->db->where('category', $category); $this->db->delete('monthly_results'); } } } } ## End monthly results redirect($_SERVER['HTTP_REFERER']); } */ public function calculate_sort_students_subjects(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $limit = $_REQUEST['limit']; $order = $_REQUEST['order']; $start = $_REQUEST['start']; $this->db->where('examination_id',$exam_id); $gett=$this->db->get('examination'); $count=$gett->num_rows(); foreach($gett->result() as $rows){ $month=$rows->month; $year=$rows->academic_year; $class=$rows->class_level; $academic_year=$rows->academic_year; $region=$rows->region; $district_exam=$rows->district; $exam_header=$rows->heading; $exam_name=$rows->exam_name; $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); $status = $rows->status; $category = $rows->category; } ## Monthly results for each school $this->db->distinct(); $this->db->select('school_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->order_by('id','asc'); $this->db->limit($limit,$start); $g = $this->db->get('ca'); foreach($g->result() as $schools){ $school = $schools->school_id; ## Getting district id for REO foreach($this->db->where('school_id',$school)->get('schools')->result() as $dist){ $district = $dist->district; } //....................Upadting subjects positions in ca table-----------------------------------------> $pos = $s = $new = $position=1; ## Sorting subjects $this->db->distinct(); $this->db->select('subject_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('school_id',$school); $this->db->where('class_level',$class); $this->db->where('month',$month); $this->db->where('category',$category); $this->db->where('academic_year',$year); $this->db->order_by('mark', 'desc'); $sub = $this->db->get('ca'); foreach($sub->result() as $marks){ $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$marks->subject_id); $this->db->where('school_id',$school); $this->db->where('class_level',$class); $this->db->where('month',$month); $this->db->where('category',$category); $this->db->where('academic_year',$year); $this->db->order_by('mark', 'desc'); $suba = $this->db->get('ca'); $i=0; $tempo = 0; $pos = $s = $new = $position=1; foreach($suba->result() as $marksa){ $i++; $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('mark',$marksa->mark); $this->db->where('subject_id',$marks->subject_id); $this->db->where('school_id',$school); $this->db->where('class_level',$class); $this->db->where('month',$month); $this->db->where('category',$category); $this->db->where('academic_year',$year); $s = $this->db->count_all_results('ca'); if($i > 1){ if($new != $marksa->mark){ $pos = $pos + $tempo; if($s>1){ $position = $pos+0.5; }else{ $position = $pos; } } }else{ if($s>1){ $position = $pos+0.5; }else{ $position = $pos; } } $datad=array( 'position'=>$position ); $tempo = $s; $new = $marksa->mark; $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('school_id',$school); $this->db->where('month',$month); $this->db->where('academic_year',$year); $this->db->where('class_level',$class); $this->db->where('category',$category); $this->db->where('reg_number',$marksa->reg_number); $this->db->where('subject_id',$marks->subject_id); $this->db->update('ca',$datad); } } // echo "
"; } ## End sorting redirect($_SERVER['HTTP_REFERER']); } public function calculate_sort_students(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $limit = $_REQUEST['limit']; $order = $_REQUEST['order']; $start = $_REQUEST['start']; $this->db->where('examination_id',$exam_id); $gett=$this->db->get('examination'); $count=$gett->num_rows(); foreach($gett->result() as $rows){ $month=$rows->month; $year=$rows->academic_year; $class=$rows->class_level; $academic_year=$rows->academic_year; $region=$rows->region; $district_exam=$rows->district; $exam_header=$rows->heading; $exam_name=$rows->exam_name; $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); $status = $rows->status; $category = $rows->category; } ## Monthly results for each school $this->db->distinct(); $this->db->select('school_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->order_by('id','asc'); $this->db->limit($limit,$start); $g = $this->db->get('monthly_results'); foreach($g->result() as $schools){ $school = $schools->school_id; ## Students sorting in class $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('school_id',$school); //$this->db->where('status',0); $this->db->where('class_level',$class); $this->db->where('month',$month); $this->db->where('category',$category); $this->db->where('academic_year',$year); // $this->db->order_by('average',"DESC"); $this->db->order_by('complete_sort',"DESC"); // $this->db->order_by('gpa',"ASC"); $this->db->order_by('average',"DESC"); $get_sub=$this->db->get('monthly_results'); $pos = $s = $new = $position = 1; $i=$tempo=0; foreach($get_sub->result() as $row_sub){ $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('average',$row_sub->average); // $this->db->where('total_marks',$row_sub->total_marks); $this->db->where('school_id',$school); $this->db->where('class_level',$class); $this->db->where('month',$month); $this->db->where('category',$category); $this->db->where('academic_year',$year); $s = $this->db->count_all_results('monthly_results'); $i++; if($i > 1){ if($new != $row_sub->average){ $pos = $pos + $tempo; if($s>1){ $position = $pos+0.5; }else{ $position = $pos; } } }else{ if($s>1){ $position = $pos+0.5; }else{ $position = $pos; } } // echo $row_sub->reg_number." ".$row_sub->total_marks." ".$pos." Status:".$row_sub->complete."
"; $tempo = $s; $new = $row_sub->average; $data = array('all_position'=>$position); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('school_id',$school); $this->db->where('category',$category); $this->db->where('month',$month); $this->db->where('academic_year',$year); $this->db->where('class_level',$class); $this->db->where('reg_number',$row_sub->reg_number); $this->db->update('monthly_results',$data); } ## stream sorting $this->db->distinct(); $this->db->select('stream'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('school_id',$school); //$this->db->where('status',0); $this->db->where('class_level',$class); $this->db->where('month',$month); $this->db->where('category',$category); $this->db->where('academic_year',$year); $get = $this->db->get('monthly_results'); foreach($get->result() as $str){ $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('class_level',$class); $this->db->where('stream',$str->stream); $this->db->where('month',$month); $this->db->where('category',$category); $this->db->where('academic_year',$year); $this->db->order_by('complete_sort',"DESC"); $this->db->order_by('average',"DESC"); //$this->db->order_by('gpa',"ASC"); $this->db->order_by('total_marks',"DESC"); $get_sub=$this->db->get('monthly_results'); $pos = $s = $new = $position = 1; $i=$tempo=0; foreach($get_sub->result() as $row_sub){ $this->db->where('average',$row_sub->average); $this->db->where('total_marks',$row_sub->total_marks); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('stream',$str->stream); $this->db->where('class_level',$class); $this->db->where('month',$month); $this->db->where('category',$category); $this->db->where('academic_year',$year); $s = $this->db->count_all_results('monthly_results'); $i++; if($i > 1){ if($new != $row_sub->total_marks){ $pos = $pos + $tempo; if($s>1){ $position = $pos+0.5; }else{ $position = $pos; } } }else{ if($s>1){ $position = $pos+0.5; }else{ $position = $pos; } } // echo $row_sub->reg_number." ".$row_sub->total_marks." ".$pos." Status:".$row_sub->complete."
"; $tempo = $s; $new = $row_sub->total_marks; $data = array('position'=>$position); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('category',$category); $this->db->where('month',$month); $this->db->where('academic_year',$year); $this->db->where('class_level',$class); $this->db->where('reg_number',$row_sub->reg_number); $this->db->update('monthly_results',$data); } } } ## End sorting redirect($_SERVER['HTTP_REFERER']); } public function calculate_gpa(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $limit = $_REQUEST['limit']; $start = $_REQUEST['start']; $order = $_REQUEST['order']; $this->db->where('examination_id',$exam_id); $gett=$this->db->get('examination'); $count=$gett->num_rows(); foreach($gett->result() as $rows){ $month=$rows->month; $class=$rows->class_level; $category=$rows->category; $year=$rows->academic_year; $region=$rows->region; $district_exam=$rows->district; $exam_header=$rows->heading; $exam_name=$rows->exam_name; $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); $status = $rows->status; $group_id = $rows->group_id; } $this->db->distinct(); $this->db->select('school_id'); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->order_by('id',"asc"); $this->db->limit($limit,$start); $get_school=$this->db->get('ca'); foreach($get_school->result() as $row_school){ $school=$row_school->school_id; ## Finding the distrit Id foreach($this->db->where('school_id',$school)->get('schools')->result() as $row_s){ $district = $row_s->district; } $average_gpa=8; $avg=0; $this->db->select('AVG(gpa) as gpa, AVG(average) as avg'); $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); if($category == 'A'){ $this->db->where('gpa <', '8'); }else{ $this->db->where('gpa <', '6'); } $sum_gpa=$this->db->get('monthly_results'); foreach($sum_gpa->result() as $row_sum_gpa){ $average_gpa= $row_sum_gpa->gpa; $avg= $row_sum_gpa->avg; } $this->db->distinct(); $this->db->select('reg_number'); $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $students = $this->db->count_all_results('ca'); ///inserting school average in database $data_gpa=array( 'school_id'=>$school, 'class_level'=>$class, 'academic_year'=>$year, 'month'=>$month, 'category'=>$category, 'gpa'=>$average_gpa, 'average'=>$avg, 'exam_id'=>$exam_id, 'candidate'=>$candidate, 'district_id'=>$district, 'region_id'=>$region, 'students'=>$students, ); $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $count_entered_gpa= $this->db->count_all_results('schools_position'); if($average_gpa > 0){ if($count_entered_gpa>0){ $this->db->where('school_id',$school); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->update('schools_position',$data_gpa); }else{ $this->db->insert('schools_position',$data_gpa); } } } ## End sorting redirect($_SERVER['HTTP_REFERER']); } public function calculate_sort_schools(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $this->db->where('examination_id',$exam_id); $gett=$this->db->get('examination'); $count=$gett->num_rows(); foreach($gett->result() as $rows){ $month=$rows->month; $year=$rows->academic_year; $region=$rows->region; $district_exam=$rows->district; $exam_header=$rows->heading; $exam_name=$rows->exam_name; $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); $status = $rows->status; $group_id = $rows->group_id; } //arranging school positions for region $sub_position=0; if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->order_by('gpa','asc'); $get_schools=$this->db->get('schools_position'); foreach($get_schools->result() as $row_school){ //....................Upadting schools positions in ca table-----------------------------------------> $school=$row_school->school_id; $sub_position++; $datad=array( 'position'=>$sub_position ); $this->db->where('school_id',$school); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->update('schools_position',$datad); } //arranging school positions fore region group wise > 40 $sub_position=0; if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('students >=',40); $this->db->order_by('gpa','asc'); $get_schools=$this->db->get('schools_position'); foreach($get_schools->result() as $row_school){ //....................Upadting schools positions in ca table-----------------------------------------> $school=$row_school->school_id; $sub_position++; $datad=array( 'rp_by_category'=>$sub_position ); $this->db->where('school_id',$school); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->update('schools_position',$datad); } //arranging school positions fore region group wise < 40 $sub_position=0; if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('students <',40); $this->db->order_by('gpa','asc'); $get_schools=$this->db->get('schools_position'); foreach($get_schools->result() as $row_school){ //....................Upadting schools positions in ca table-----------------------------------------> $school=$row_school->school_id; $sub_position++; $datad=array( 'rp_by_category'=>$sub_position ); $this->db->where('school_id',$school); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->update('schools_position',$datad); } //arranging school positions for district $this->db->distinct(); $this->db->select('district_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $get_d=$this->db->get('schools_position'); foreach($get_d->result() as $dist){ $sub_position=0; $this->db->where('district_id',$dist->district_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->order_by('gpa','asc'); $get_schools=$this->db->get('schools_position'); foreach($get_schools->result() as $row_school){ //....................Upadting schools positions in ca table-----------------------------------------> $school=$row_school->school_id; $sub_position++; $datad=array( 'district_position'=>$sub_position ); $this->db->where('school_id',$school); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->update('schools_position',$datad); } } //arranging school positions for district group wise $this->db->distinct(); $this->db->select('district_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $get_d=$this->db->get('schools_position'); foreach($get_d->result() as $dist){ $sub_position=0; $this->db->where('district_id',$dist->district_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('students >= ',40); $this->db->order_by('gpa','asc'); $get_schools=$this->db->get('schools_position'); foreach($get_schools->result() as $row_school){ //....................Upadting schools positions in ca table-----------------------------------------> $school=$row_school->school_id; $sub_position++; $datad=array( 'dp_by_category'=>$sub_position ); $this->db->where('school_id',$school); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->update('schools_position',$datad); } $sub_position=0; $this->db->where('district_id',$dist->district_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('students < ',40); $this->db->order_by('gpa','asc'); $get_schools=$this->db->get('schools_position'); foreach($get_schools->result() as $row_school){ //....................Upadting schools positions in ca table-----------------------------------------> $school=$row_school->school_id; $sub_position++; $datad=array( 'dp_by_category'=>$sub_position ); $this->db->where('school_id',$school); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->update('schools_position',$datad); } } ## End sorting redirect($_SERVER['HTTP_REFERER']); } public function calculate_sort_all_subjects(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $this->db->where('examination_id',$exam_id); $gett=$this->db->get('examination'); $count=$gett->num_rows(); foreach($gett->result() as $rows){ $month=$rows->month; $year=$rows->academic_year; $region=$rows->region; $district_exam=$rows->district; $exam_header=$rows->heading; $exam_name=$rows->exam_name; $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); $status = $rows->status; $class = $rows->class_level; $category = $rows->category; $group_id=$rows->group_id; } $this->db->distinct(); $this->db->select('school_id'); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $get_school=$this->db->get('ca'); foreach($get_school->result() as $row_school){ $school=$row_school->school_id; ## Finding the distrit Id foreach($this->db->where('school_id',$school)->get('schools')->result() as $row_s){ $district = $row_s->district; } //finding subjects gpa for each school and sort and insert into the database------------------------------- $this->db->select('AVG(gpa) as gpa, AVG(mark) as avg, subject_id'); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('school_id',$school); $this->db->where('month',$month); $this->db->where('candidate',$candidate); $this->db->group_by('subject_id'); $this->db->order_by('gpa','asc'); $gg = $this->db->get('ca'); foreach($gg->result() as $ress){ $data_subject_gpa=array( 'school_id'=>$school, 'subject_id'=>$ress->subject_id, 'class_level'=>$class, 'academic_year'=>$year, 'month'=>$month, 'category'=>$category, 'average'=>$ress->avg, 'gpa'=>$ress->gpa, 'exam_id'=>$exam_id, 'candidate'=>$candidate, 'district_id'=>$district, 'region_id'=>$region ); $this->db->where('school_id',$school); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$ress->subject_id); $count_entered_gpa= $this->db->count_all_results('subjects_school_gpa'); if($count_entered_gpa>0){ $this->db->where('school_id',$school); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('subject_id',$ress->subject_id); $this->db->update('subjects_school_gpa',$data_subject_gpa); }else{ $this->db->insert('subjects_school_gpa',$data_subject_gpa); } } } ## Sorting subjects by district $this->db->distinct(); $this->db->select('subject_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); foreach($this->db->get('subjects_school_gpa')->result() as $subject){ $sub_position=0; $this->db->distinct(); $this->db->select('district_id'); $this->db->where('exam_id',$exam_id); $this->db->where('subject_id',$subject->subject_id); $this->db->where('candidate',$candidate); foreach($this->db->get('subjects_school_gpa')->result() as $row_school){ $pos=0; $this->db->where('subject_id',$subject->subject_id); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('district_id',$row_school->district_id); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('month',$month); //$this->db->order_by('average','desc'); $this->db->order_by('gpa','asc'); $get_school=$this->db->get('subjects_school_gpa'); foreach($get_school->result() as $gg){ $pos++; $this->db->where('id',$gg->id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('month',$month); $this->db->where('subject_id',$subject->subject_id); $this->db->where('district_id',$row_school->district_id); $this->db->update('subjects_school_gpa',array('district_position'=>$pos)); } } $pos=0; $this->db->where('subject_id',$subject->subject_id); $this->db->where('region_id',$region); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); //$this->db->order_by('average','desc'); $this->db->order_by('gpa','asc'); $get_school=$this->db->get('subjects_school_gpa'); foreach($get_school->result() as $gg){ $pos++; $this->db->where('id',$gg->id); if($group_id==0){ $this->db->where('region_id',$region); }else{ //this fro group id } $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$subject->subject_id); $this->db->update('subjects_school_gpa',array('position'=>$pos)); } } ## End sorting redirect($_SERVER['HTTP_REFERER']); } public function update_gender(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $this->db->distinct(); $this->db->select('reg_number'); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('gender',''); foreach($this->db->get('monthly_results')->result() as $ss){ $this->db->select('gender,reg_number'); $this->db->where('reg_number',$ss->reg_number); foreach($this->db->get('students')->result() as $students){ $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$students->reg_number); $this->db->update('ca',array('gender'=>$students->gender)); $this->db->where('exam_id',$exam_id); $this->db->where('reg_number',$students->reg_number); $this->db->update('monthly_results',array('gender'=>$students->gender)); } } ## End gender redirect($_SERVER['HTTP_REFERER']); } public function calculate_full_sheet(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $order = $_REQUEST['order']; $limit = $_REQUEST['limit']; foreach($this->db->where('examination_id',$exam_id)->get('examination')->result() as $ex){ $category = $ex->category; $class_admitted = $ex->class_level; if($category=='A'){ // $admission_year = substr($ex->academic_year,-4); //echo $admission_year;exit; $admission_year=$year = date('Y');; }else{ $admission_year = $ex->academic_year; } } //echo $admission_year;exit; //$admission_year=2024; $f_boys = $f_girls = $f_total = $s_boys = $s_girls = $s_total = 0; $school_id = '';$o_iv_total = ''; $reg_boys = '';$reg_girls = '';$reg_total = '';$do_boys = '';$do_girls = '';$do_total = '';$a_boys = '';$a_girls = '';$a_total = '';$b_boys = '';$b_girls = '';$b_total = '';$c_boys = '';$c_girls = '';$c_total = '';$ac_boys = '';$ac_girls = '';$ac_total = '';$ac_percent = '';$d_boys = '';$d_girls = '';$d_total = '';$e_boys = '';$e_girls = '';$e_total = '';$de_percent = '';$fail_percent = '';$absent = '';$incomplete = '';$gpa = '';$dp = '';$rp = '';$dp_by_category = '';$rp_by_category = '';$district_id = '';$region_id = '';$i_boys = '';$i_girls = '';$i_total = '';$ii_boys = '';$ii_girls = '';$ii_total = '';$iii_boys = '';$iii_girls = '';$iii_total = '';$iv_boys = '';$iv_girls = '';$iv_total = '';$o_boys = '';$o_girls = '';$o_total = '';$i_iii_boys = '';$i_iii_girls = '';$i_iii_total = '';$o_iv_boys = '';$o_iv_girls = '';$o_iv_total; #reg boys and girls $this->db->distinct(); $this->db->select('school_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->order_by('school_id',$order); // $this->db->not_like('school_id',"SS5badbac5cda81"); $this->db->limit($limit); $g = $this->db->get('schools_position'); foreach($g->result() as $schools){ $school_id = $schools->school_id; #reg boys $this->db->where('school_id',$school_id); $this->db->where('gender','M'); $this->db->where('category',$category); $this->db->where('admission_year',$admission_year); $this->db->where('class_admitted',$class_admitted); $this->db->where('candidate',$candidate); $reg_boys = $this->db->count_all_results('students'); #reg girls $this->db->where('school_id',$school_id); $this->db->where('gender','F'); $this->db->where('category',$category); $this->db->where('admission_year',$admission_year); $this->db->where('class_admitted',$class_admitted); $this->db->where('candidate',$candidate); $reg_girls = $this->db->count_all_results('students'); $reg_total = $reg_boys+$reg_girls; # do boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('candidate',$candidate); $do_boys = $this->db->count_all_results('monthly_results'); # do girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('candidate',$candidate); $do_girls = $this->db->count_all_results('monthly_results'); $do_total = $do_boys+$do_girls; if($do_total <1){ $do_total = 1; } # a boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('grade','A'); $this->db->where('candidate',$candidate); $a_boys = $this->db->count_all_results('monthly_results'); # a girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('grade','A'); $this->db->where('candidate',$candidate); $a_girls = $this->db->count_all_results('monthly_results'); $a_total = $a_boys + $a_girls; # b boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('grade','B'); $this->db->where('candidate',$candidate); $b_boys = $this->db->count_all_results('monthly_results'); # b girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('grade','B'); $this->db->where('candidate',$candidate); $b_girls = $this->db->count_all_results('monthly_results'); $b_total = $b_boys + $b_girls; # c boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('grade','C'); $this->db->where('candidate',$candidate); $c_boys = $this->db->count_all_results('monthly_results'); # c girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('grade','C'); $this->db->where('candidate',$candidate); $c_girls = $this->db->count_all_results('monthly_results'); $c_total = $c_boys + $c_girls; # d boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('grade','D'); $this->db->where('candidate',$candidate); $d_boys = $this->db->count_all_results('monthly_results'); # d girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('grade','D'); $this->db->where('candidate',$candidate); $d_girls = $this->db->count_all_results('monthly_results'); $d_total = $d_boys + $d_girls; # e boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('grade','E'); $this->db->where('candidate',$candidate); $e_boys = $this->db->count_all_results('monthly_results'); # e girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('grade','E'); $this->db->where('candidate',$candidate); $e_girls = $this->db->count_all_results('monthly_results'); $e_total = $e_boys + $e_girls; # f boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('grade','F'); $this->db->where('candidate',$candidate); $f_boys = $this->db->count_all_results('monthly_results'); # f girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('grade','F'); $this->db->where('candidate',$candidate); $f_girls = $this->db->count_all_results('monthly_results'); $f_total = $f_boys + $f_girls; # S boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('grade','S'); $this->db->where('candidate',$candidate); $s_boys = $this->db->count_all_results('monthly_results'); # S girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('grade','S'); $this->db->where('candidate',$candidate); $s_girls = $this->db->count_all_results('monthly_results'); $s_total = $s_boys + $s_girls; # i boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('division','I'); $this->db->where('candidate',$candidate); $i_boys = $this->db->count_all_results('monthly_results'); # i girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('division','I'); $this->db->where('candidate',$candidate); $i_girls = $this->db->count_all_results('monthly_results'); $i_total = $i_boys + $i_girls; # ii boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('division','II'); $this->db->where('candidate',$candidate); $ii_boys = $this->db->count_all_results('monthly_results'); # ii girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('division','II'); $this->db->where('candidate',$candidate); $ii_girls = $this->db->count_all_results('monthly_results'); $ii_total = $ii_boys + $ii_girls; # iii boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('division','III'); $this->db->where('candidate',$candidate); $iii_boys = $this->db->count_all_results('monthly_results'); # iii girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('division','III'); $this->db->where('candidate',$candidate); $iii_girls = $this->db->count_all_results('monthly_results'); $iii_total = $iii_boys + $iii_girls; # iv boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('division','IV'); $this->db->where('candidate',$candidate); $iv_boys = $this->db->count_all_results('monthly_results'); # iv girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('division','IV'); $this->db->where('candidate',$candidate); $iv_girls = $this->db->count_all_results('monthly_results'); $iv_total = $iv_boys + $iv_girls; # o boys $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','M'); $this->db->where('division','0'); $this->db->where('candidate',$candidate); $o_boys = $this->db->count_all_results('monthly_results'); # o girls $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('gender','F'); $this->db->where('division','0'); $this->db->where('candidate',$candidate); $o_girls = $this->db->count_all_results('monthly_results'); $o_total = $o_boys + $o_girls; $ac_girls = $a_girls +$b_girls + $c_girls; $ac_boys = $a_boys +$b_boys + $c_boys; $ac_total = $ac_boys + $ac_girls; $de_girls = $d_girls +$e_girls; $de_boys = $d_boys +$e_boys; $de_total = $de_boys + $de_girls; $de_total = $de_boys + $de_girls; $i_iii_girls = $i_girls +$ii_girls + $iii_girls; $i_iii_boys = $i_boys +$ii_boys + $iii_boys; $i_iii_total = $i_iii_boys + $i_iii_girls; $o_iv_girls = $o_girls + $iv_girls; $o_iv_boys = $o_boys + $iv_boys; $o_iv_total = $o_total + $iv_total; $ac_percent = round(($ac_total/$do_total),2)*100; $de_percent = round(($de_total/$do_total),2)*100; $fail_percent = round(($o_total/$do_total),2)*100; $absent = $reg_total - $do_total; // echo 'Total '.$reg_total.' Do '.$do_total.' = '.$absent;exit; $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('complete',0); $inc = $this->db->count_all_results('monthly_results'); $incomplete = $inc; $this->db->where('school_id',$school_id); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); foreach($this->db->get('schools_position')->result() as $sc){ $gpa = $sc->gpa; $rp = $sc->position; $dp= $sc->district_position; $dp_by_category=$sc->dp_by_category; $rp_by_category=$sc->rp_by_category; $district_id=$sc->district_id; $region_id=$sc->region_id; $dp_by_ownership = $sc->dp_by_owner; $rp_by_ownership = $sc->rp_by_owner; $ownership = $sc->ownership; } $full_sheet_data = array( 'school_id'=>$school_id, 'reg_boys'=>$reg_boys, 'reg_girls'=>$reg_girls, 'reg_total'=>$reg_total, 'do_boys'=>$do_boys, 'do_girls'=>$do_girls, 'do_total'=>$do_total, 'a_boys'=>$a_boys, 'a_girls'=>$a_girls, 'a_total'=>$a_total, 'b_boys'=>$b_boys, 'b_girls'=>$b_girls, 'b_total'=>$b_total, 'c_boys'=>$c_boys, 'c_girls'=>$c_girls, 'c_total'=>$c_total, 'ac_boys'=>$ac_boys, 'ac_girls'=>$ac_girls, 'ac_total'=>$ac_total, 'ac_percent'=>$ac_percent, 'd_boys'=>$d_boys, 'd_girls'=>$d_girls, 'd_total'=>$d_total, 'e_boys'=>$e_boys, 'e_girls'=>$e_girls, 'e_total'=>$e_total, 'f_boys'=>$f_boys, 'f_girls'=>$f_girls, 'f_total'=>$f_total, 's_boys'=>$s_boys, 's_girls'=>$s_girls, 's_total'=>$s_total, 'de_percent'=>$de_percent, 'fail_percent'=>$fail_percent, 'absent'=>$absent, 'incomplete'=>$incomplete, 'gpa'=>$gpa, 'dp'=>$dp, 'rp'=>$rp, 'exam_id'=>$exam_id, 'candidate'=>$candidate, 'dp_by_category'=>$dp_by_category, 'rp_by_category'=>$rp_by_category, 'district_id'=>$district_id, 'region_id'=>$region_id, 'i_boys'=>$i_boys, 'i_girls'=>$i_girls, 'i_total'=>$i_total, 'ii_boys'=>$ii_boys, 'ii_girls'=>$ii_girls, 'ii_total'=>$ii_total, 'iii_boys'=>$iii_boys, 'iii_girls'=>$iii_girls, 'iii_total'=>$iii_total, 'iv_boys'=>$iv_boys, 'iv_girls'=>$iv_girls, 'iv_total'=>$iv_total, 'o_boys'=>$o_boys, 'o_girls'=>$o_girls, 'o_total'=>$o_total, 'i_iii_boys'=>$i_iii_boys, 'i_iii_girls'=>$i_iii_girls, 'i_iii_total'=>$i_iii_total, 'i_iv_total'=>($i_iii_total+$iv_total), 'i_iv_percent'=>(($i_iii_total+$iv_total)/$do_total)*100, 'o_iv_boys'=>$o_iv_boys, 'o_iv_girls '=>$o_iv_girls, 'o_iv_total'=>$o_iv_total, 'ownership'=>$ownership, 'dp_by_ownership'=>$dp_by_ownership, 'rp_by_ownership'=>$rp_by_ownership, ); $this->db->where('exam_id',$exam_id); $this->db->where('school_id',$school_id); $this->db->where('candidate',$candidate); $exam = $this->db->count_all_results('result_full_sheet'); if($exam > 0){ $this->db->where('candidate',$candidate); $this->db->where('school_id',$school_id); $this->db->where('exam_id',$exam_id); $this->db->update('result_full_sheet',$full_sheet_data); }else{ $this->db->insert('result_full_sheet',$full_sheet_data); } } ## End sorting redirect($_SERVER['HTTP_REFERER']); } public function set_sorting(){ $exam_id = $_REQUEST['exam_id']; $sort = $_REQUEST['sort']; if($sort == 'normal'){ $sort = "percent"; }else{ $sort = "normal"; } $this->db->where('examination_id',$exam_id)->update('examination',array('sorting'=>$sort)); redirect($_SERVER['HTTP_REFERER']); } public function mkeka_clear(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->delete('mkeka'); redirect($_SERVER['HTTP_REFERER']); } public function sort_by_percent(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $i=0; $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->order_by('i_iv_percent','desc')->order_by('gpa','asc'); foreach($this->db->get('result_full_sheet')->result() as $data){ $i++; $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('school_id',$data->school_id); $this->db->update('schools_position',array('position_bypercent'=>$i)); echo "I-IV: ".$data->i_iv_percent." GPA: ".$data->gpa."
"; } } public function mkeka(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $order = $_REQUEST['order']; $limit = $_REQUEST['limit']; $start = $_REQUEST['start']; $this->db->where('examination_id',$exam_id); foreach($this->db->get('examination')->result() as $ex){ $class = $ex->class_level; $category = $ex->category; $month = $ex->month; $year = $ex->academic_year; } $this->db->distinct(); $this->db->select('school_id'); // $this->db->where('school_id','SS5c3c6c316de83'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->order_by('id','asc'); $this->db->limit($limit,$start); foreach($this->db->get('monthly_results')->result() as $sch){ $school = $sch->school_id; $arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), ); if($category=='P'){ $data = file_get_contents(base_url('Calculate_results_primary_officers/print_full_sheet_officers_number?class=').base64_encode($class).'&candidate='.base64_encode($candidate).'&&exam_id='.base64_encode($exam_id).'&&school_id='.base64_encode($school).'&&stream='.base64_encode($category).'&&month='.base64_encode($month).'&&year='.base64_encode($year).'&&category='.base64_encode($category).'&&language='.base64_encode('english'), false, stream_context_create($arrContextOptions)); }else{ $data = file_get_contents(base_url('Calculate_results_secondary_officers/print_full_sheet_officers_number?class=').base64_encode($class).'&candidate='.base64_encode($candidate).'&&exam_id='.base64_encode($exam_id).'&&school_id='.base64_encode($school).'&&stream='.base64_encode($category).'&&month='.base64_encode($month).'&&year='.base64_encode($year).'&&category='.base64_encode($category).'&&language='.base64_encode('english'), false, stream_context_create($arrContextOptions)); } $array = array( 'school_id'=>$school, 'mkeka'=>$data, 'candidate'=>$candidate, 'exam_id'=>$exam_id, ); $this->db->where('exam_id',$exam_id); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $count = $this->db->count_all_results('mkeka'); if($count == 0){ $this->db->insert('mkeka',$array); }else{ $this->db->where('exam_id',$exam_id); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->update('mkeka',$array); } } ## End redirect($_SERVER['HTTP_REFERER']); } public function mkeka_verifiy(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $order = $_REQUEST['order']; $limit = $_REQUEST['limit']; $start = $_REQUEST['start']; $this->db->where('examination_id',$exam_id); foreach($this->db->get('examination')->result() as $ex){ $class = $ex->class_level; $category = $ex->category; $month = $ex->month; $year = $ex->academic_year; } $this->db->distinct(); $this->db->select('school_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); foreach($this->db->get('monthly_results')->result() as $sch){ $school = $sch->school_id; $this->db->where('exam_id',$exam_id); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $count = $this->db->count_all_results('mkeka'); if($count == 0){ if($category=='P'){ $data = file_get_contents(base_url('Calculate_results_primary_officers/print_full_sheet_officers_number?class=').base64_encode($class).'&candidate='.base64_encode($candidate).'&&exam_id='.base64_encode($exam_id).'&&school_id='.base64_encode($school).'&&stream='.base64_encode($category).'&&month='.base64_encode($month).'&&year='.base64_encode($year).'&&category='.base64_encode($category).'&&language='.base64_encode('english')); }else{ $data = file_get_contents(base_url('Calculate_results_secondary_officers/print_full_sheet_officers_number?class=').base64_encode($class).'&candidate='.base64_encode($candidate).'&&exam_id='.base64_encode($exam_id).'&&school_id='.base64_encode($school).'&&stream='.base64_encode($category).'&&month='.base64_encode($month).'&&year='.base64_encode($year).'&&category='.base64_encode($category).'&&language='.base64_encode('english')); } $array = array( 'school_id'=>$school, 'mkeka'=>$data, 'candidate'=>$candidate, 'exam_id'=>$exam_id, ); $this->db->insert('mkeka',$array); } } ## End redirect($_SERVER['HTTP_REFERER']); } public function calculate_insert_sort_district_positions(){ $exam_id = $_REQUEST['id']; $candidate = $_REQUEST['cand']; $position=0; $region=0; $district = $district_id = 0; $this->db->select("region_id, district_id, SUM(do_total) as do_exam, SUM(a_total) as a, SUM(b_total) as b, SUM(c_total) as c, SUM(d_total) as d, SUM(e_total) as e, SUM(ac_total) as ac_total, AVG(ac_percent) as ac_percent, SUM(i_total) as i, SUM(ii_total) as ii, SUM(iii_total) as iii, SUM(iv_total) as iv, SUM(o_total) as o, SUM(i_iii_total) as i_iii_total, AVG(gpa) as gpa"); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->group_by('district_id'); foreach($this->db->get('result_full_sheet')->result() as $data){ $region=$data->region_id; $district=$data->district_id; $save_data = array( 'exam_id'=>$exam_id, 'candidate'=>$candidate, 'district'=>$data->district_id, 'region'=>$data->region_id, 'a'=>$data->a, 'b'=>$data->b, 'c'=>$data->c, 'd'=>$data->d, 'e'=>$data->e, 'ac_total'=>$data->ac_total, 'ac_percent'=>$data->ac_percent, 'i'=>$data->i, 'ii'=>$data->ii, 'iii'=>$data->iii, 'iv'=>$data->iv, 'o'=>$data->o, 'i_iii'=>$data->i+$data->ii+$data->iii+$data->iv, 'i_iii_total'=>$data->i+$data->ii+$data->iii+$data->iv, 'i_iii_percent'=>round((($data->i+$data->ii+$data->iii+$data->iv)/$data->do_exam)*100), 'gpa'=>$data->gpa, ); $this->db->where('region',$data->region_id); $this->db->where('district',$data->district_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $exist = $this->db->count_all_results('district_position'); if($exist == 0){ $this->db->insert('district_position',$save_data); }else{ $this->db->where('region',$data->region_id); $this->db->where('district',$data->district_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->update('district_position',$save_data); } } $position=0; $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); //$this->db->order_by('i_iii_percent','desc'); $this->db->order_by('gpa','asc'); foreach($this->db->get('district_position')->result() as $dd){ $position++; $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('id',$dd->id); $this->db->update('district_position',array('position'=>$position)); } ## Update ownership $this->db->distinct(); $this->db->select('school_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $get = $this->db->get('schools_position'); foreach($get->result() as $results){ foreach($this->db->where('school_id',$results->school_id)->get('schools')->result() as $sch){ $own = strtoupper(substr(str_replace(' ','',$sch->school_ownership),0,1)); $data = array('ownership'=>$own); $this->db->where('exam_id',$exam_id); $this->db->where('school_id',$results->school_id); $this->db->update('schools_position',$data); } } ## Sort ownership by region $this->db->distinct(); $this->db->select('ownership'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $get2 = $this->db->get('schools_position'); foreach($get2->result() as $res){ $position=0; $this->db->where('ownership',$res->ownership); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->order_by('gpa','asc'); foreach($this->db->get('schools_position')->result() as $dpos){ $position++; $this->db->where('ownership',$res->ownership); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('school_id',$dpos->school_id); $this->db->update('schools_position',array('rp_by_owner'=>$position)); } } ## Sort ownership positions by district $this->db->distinct(); $this->db->select('district_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $get = $this->db->get('monthly_results'); foreach($get->result() as $results){ $this->db->distinct(); $this->db->select('ownership'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $get2 = $this->db->get('schools_position'); foreach($get2->result() as $res){ $position=0; $this->db->where('ownership',$res->ownership); $this->db->where('district_id',$results->district_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->order_by('gpa','asc'); foreach($this->db->get('schools_position')->result() as $dpos){ $position++; $this->db->where('ownership',$res->ownership); $this->db->where('district_id',$results->district_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('school_id',$dpos->school_id); $this->db->update('schools_position',array('dp_by_owner'=>$position)); } } $this->db->distinct(); $this->db->select('subject_id'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('district_id',$results->district_id); $get=$this->db->get('ca'); foreach($get->result() as $subjects){ $this->db->select('AVG(mark) as mark, AVG(gpa) as gpa'); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$subjects->subject_id); $this->db->where('district_id',$results->district_id); $get2=$this->db->get('ca'); foreach($get2->result() as $avg){ $this->db->where('district_id',$results->district_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$subjects->subject_id); $this->db->where('grade !=','F'); $pass = $this->db->count_all_results('ca'); $this->db->where('district_id',$results->district_id); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$subjects->subject_id); $total = $this->db->count_all_results('ca'); $percent = round(($pass/$total)*100,2); $data = array( 'average'=>$avg->mark, 'gpa'=>$avg->gpa, 'district_id'=>$results->district_id, 'subject_id'=>$subjects->subject_id, 'candidate'=>$candidate, 'region_id'=>$region, 'exam_id'=>$exam_id, 'pass_a_d'=>$percent ); $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$subjects->subject_id); $this->db->where('district_id',$results->district_id); $c = $this->db->count_all_results('subject_average_mark_districts'); if($c == 0){ $this->db->insert('subject_average_mark_districts',$data); }else{ $this->db->where('exam_id',$exam_id); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$subjects->subject_id); $this->db->where('district_id',$results->district_id); $this->db->update('subject_average_mark_districts',$data); } } } } ## End sorting redirect($_SERVER['HTTP_REFERER']); } public function check_ca(){ $this->db->distinct(); $this->db->select('school_id'); $this->db->where('exam_id',36); $this->db->order_by('school_id','desc'); $this->db->limit(150); $tt = $this->db->get('ca'); foreach($tt->result() as $school){ $this->db->where('school_id',$school->school_id); $this->db->where('exam_id',36); foreach($this->db->get('ca')->result() as $ca){ $mark_grade=""; $this->db->where('students_type','O'); $get_grades=$this->db->get('grade_settings'); foreach($get_grades->result() as $row_grade){ if($row_grade->start_mark<=round($ca->mark) && round($ca->mark)<=$row_grade->end_mark){ $mark_grade = $row_grade->grade; } } $this->db->where('id',$ca->id); $this->db->where('school_id',$school->school_id); $this->db->update('ca',array('mark'=>round($ca->mark),'grade'=>$mark_grade)); } } } public function insert_schools(){ $inputFileName = $_FILES["file"]["tmp_name"]; try { /// it will be your file name that you are posting with a form or can pass static name $_FILES["file"]["name"]; $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); } catch(Exception $e) { die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); } $data = array(); $data2 = array(); $valid_student = 0; $totalrows=$objPHPExcel->setActiveSheetIndex(0)->getHighestRow(); $objWorksheet=$objPHPExcel->setActiveSheetIndex(0); $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); $i = 0;$title=""; $title = $allDataInSheet[1]['A'].$allDataInSheet[1]['B'].$allDataInSheet[1]['C'].$allDataInSheet[1]['D'].$allDataInSheet[1]['E'].$allDataInSheet[1]['F'].$allDataInSheet[1]['G']; $title = str_replace(' ','',$title); if($title == 'SCHOOLNAMESCHOOLTYPEOWNERSHIPSCHOOLREGNUMBEREMAILMOBILEADDRESS(BOX)'){ $i=0; $region_name = ""; $rejected=0; $registered=0; $name_rejected=""; foreach($allDataInSheet as $schools){ if($i < 1){ $i++; }else{ if(strlen(str_replace(' ','', $schools['A']))>1){ ## Processing REGISTERING SCHOOLS $r = explode('/',$this->input->post('region')); $district = $r[0]; $region = $r[1]; foreach($this->db->where('id',$region)->get('regions')->result() as $re){ $region_name = $re->name; } $chool_type = $schools['B']; $istrue = true; while($istrue){ $school_id= $chool_type.uniqid(); $this->db->where('school_id',$school_id); $count= $this->db->count_all_results('schools'); if($count == 0){ $istrue = false; } } $this->db->where('school_reg_number',$schools['D']); $countt = $this->db->count_all_results('schools'); if($countt>0){ $rejected++; $name_rejected.=$rejected." ".$schools['A'].',
'; }else{ $data = array( 'school_id' => $school_id, 'school_name' =>$schools['A'], 'school_type' =>$schools['B'], 'school_email' => $schools['E'], 'school_mobile' => $schools['F'], 'school_address' => $schools['G'], 'school_location' => $region_name, 'country' => 'Tanzania', 'school_reg_number'=>$schools['D'], 'full_name'=>$schools['A'], 'school_ownership'=>$schools['C'], 'login_header'=>'JOINT EXAMINATION RESULTS '.$schools['A'], 'region'=>$region, 'district'=>$district, 'school_logo'=>'Not set', 'school_moto'=>'Not set', 'school_header'=>'Not set', 'password'=>MD5('default'), 'password_recover'=>'default', 'type'=>'Admin', 'year_registered'=>date('Y') ); /// echo $this->security->xss_clean($this->input->post('group_id'));exit; $ff = $this->db->insert('schools', $data); //inserting schools to group if is set if($this->security->xss_clean($this->input->post('group_id'))>0){ $data3 = array( 'group_id'=>$this->security->xss_clean($this->input->post('group_id')), 'school_id'=>$school_id, 'date_registered'=>date('M d Y'), ); $this->db->insert('group_schools',$data3); } if($ff){ $registered++; } } ####################################### } } } redirect('Super_user/register_schools?registered='.$registered.'&rejected='.$rejected.'&name='.urlencode($name_rejected)); }else{ redirect('Super_user/register_schools?error_format'); } } public function remove_subject(){ $district_id = $this->uri->segment(3); $subject_id = $this->uri->segment(4); $group_id = $this->uri->segment(5); if($group_id == 'G'){ $this->db->where('group_id',$district_id); }else{ $this->db->where('district_id',$district_id); } $this->db->where('subject_id',$subject_id); $delete = $this->db->delete('all_subjects_region'); redirect($_SERVER['HTTP_REFERER']); } public function register_region(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/register_region'); $this->load->view('includes/super_footer'); } public function set_questions(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/set_questions'); $this->load->view('includes/super_footer'); } public function set_questions_post(){ $ids = explode('.',$this->input->post('params')); $exam_id = $this->input->post('exam_id'); $subject_id = $ids[1]; $type = $ids[2]; $qns = $this->input->post('qns'); $data = array( 'exam_id'=>$exam_id, 'subject_id'=>$subject_id, 'questions'=>$qns, 'type'=>$type, ); $this->db->where('exam_id',$exam_id); $this->db->where('subject_id',$subject_id); $this->db->where('type',$type); $count = $this->db->count_all_results('examination_questions'); if($count > 0) { ## Do update $this->db->where('exam_id',$exam_id); $this->db->where('subject_id',$subject_id); $this->db->where('type',$type); $this->db->update('examination_questions',$data); }else{ $this->db->insert('examination_questions',$data); } } public function register_schools(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/register_schools'); $this->load->view('includes/super_footer'); } public function subject_subjects(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/subject_subjects'); $this->load->view('includes/super_footer'); } public function register_sub_region(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/register_sub_region'); $this->load->view('includes/super_footer'); } public function viewed_results_login(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/viewed_results_login'); $this->load->view('includes/super_footer'); } public function viewed_results_public(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/viewed_results_public'); $this->load->view('includes/super_footer'); } public function insert_regions(){ $data = array( 'name'=>$this->input->post('region'), // 'heading' =>$this->input->post('heading') ); $data= $this->security->xss_clean($data); $this->db->insert('regions',$data); redirect('Super_user/register_region'); } public function insert_sub_regions(){ $data = array( 'regions_id'=>$this->input->post('region'), 'district_name' =>$this->input->post('sub_region'), 'heading' =>$this->input->post('heading') ); $data= $this->security->xss_clean($data); $this->db->insert('regions_distrincts',$data); redirect('Super_user/register_sub_region'); } public function insert_subjects(){ $data = array( 'name'=>$this->input->post('name'), 'short_name'=>$this->input->post('short_name'), 'is_sub'=>$this->input->post('type') ); $this->db->like('name',$this->input->post('name'),'BOTH'); $count = $this->db->count_all_results('all_subjects'); if($count == 0){ $this->db->insert('all_subjects',$data); } redirect('Super_user/register_subjects?suc'); } public function assign_subjects_olevel(){ $i=0; if($_POST){ $sub = $this->input->post('subjects'); $r = explode(',',$this->input->post('region')); $region = $r[0]; $district = $r[1]; //echo $region.' = '.$district;exit; //kill district abd region but group id becomes region if($district=='G'){ foreach($sub as $subject){ $this->db->where('region_id',0); $this->db->where('district_id',0); $this->db->where('subject_id',$subject); $this->db->where('group_id',$region); $this->db->where('category','O'); $count = $this->db->count_all_results('all_subjects_region'); if($count == 0){ $data = array( 'subject_id'=>$subject, 'region_id'=>0, 'group_id'=> $region, 'district_id'=>0, 'category'=>'O' ); $this->db->insert('all_subjects_region',$data); $i++; } } }else{ $this->db->where('regions_id',$region); $get = $this->db->get('regions_distrincts'); foreach($get->result() as $opt){ foreach($sub as $subject){ $this->db->where('region_id',$region); $this->db->where('district_id',$opt->id); $this->db->where('subject_id',$subject); $this->db->where('category','O'); $count = $this->db->count_all_results('all_subjects_region'); if($count == 0){ $data = array( 'subject_id'=>$subject, 'region_id'=>$region, 'district_id'=>$opt->id, 'category'=>'O' ); $this->db->insert('all_subjects_region',$data); $i++; } } } } } redirect('Super_user/assign_subjects_o/'.$i); } public function assign_subjects_plevel(){ $i=0; if($_POST){ $sub = $this->input->post('subjects'); $r = explode(',',$this->input->post('region')); $region = $r[0]; $district = $r[1]; //echo $region.' = '.$district;exit; //kill district abd region but group id becomes region if($district=='G'){ foreach($sub as $subject){ $this->db->where('region_id',0); $this->db->where('district_id',0); $this->db->where('subject_id',$subject); $this->db->where('group_id',$region); $this->db->where('category','P'); $count = $this->db->count_all_results('all_subjects_region'); if($count == 0){ $data = array( 'subject_id'=>$subject, 'region_id'=>0, 'group_id'=> $region, 'district_id'=>0, 'category'=>'P' ); $this->db->insert('all_subjects_region',$data); $i++; } } }else{ $this->db->where('regions_id',$region); $get = $this->db->get('regions_distrincts'); foreach($get->result() as $opt){ foreach($sub as $subject){ $this->db->where('region_id',$region); $this->db->where('district_id',$opt->id); $this->db->where('subject_id',$subject); $this->db->where('category','P'); $count = $this->db->count_all_results('all_subjects_region'); if($count == 0){ $data = array( 'subject_id'=>$subject, 'region_id'=>$region, 'district_id'=>$opt->id, 'category'=>'P' ); $this->db->insert('all_subjects_region',$data); $i++; } } } } } redirect('Super_user/assign_subjects_p/'.$i); } public function view_subjects(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/view_subjects'); $this->load->view('includes/super_footer'); } public function assign_subjects_alevel(){ $i=0; if($_POST){ $sub = $this->input->post('subjects'); $r = explode(',',$this->input->post('region')); $region = $r[0]; $district = $r[1]; //echo $region.' = '.$district;exit; //kill district abd region but group id becomes region if($district=='G'){ foreach($sub as $subject){ $this->db->where('region_id',0); $this->db->where('district_id',0); $this->db->where('subject_id',$subject); $this->db->where('group_id',$region); $this->db->where('category','A'); $count = $this->db->count_all_results('all_subjects_region'); if($count == 0){ $data = array( 'subject_id'=>$subject, 'region_id'=>0, 'group_id'=> $region, 'district_id'=>0, 'category'=>'A' ); $this->db->insert('all_subjects_region',$data); $i++; } } }else{ $this->db->where('regions_id',$region); $get = $this->db->get('regions_distrincts'); foreach($get->result() as $opt){ foreach($sub as $subject){ $this->db->where('region_id',$region); $this->db->where('district_id',$opt->id); $this->db->where('subject_id',$subject); $this->db->where('category','A'); $count = $this->db->count_all_results('all_subjects_region'); if($count == 0){ $data = array( 'subject_id'=>$subject, 'region_id'=>$region, 'district_id'=>$opt->id, 'category'=>'A' ); $this->db->insert('all_subjects_region',$data); $i++; } } } } } redirect('Super_user/assign_subjects_a/'.$i); } public function load_subjects(){ $category = $this->input->post('category'); $sub = $this->input->post('subject_id'); $name = $this->input->post('name'); $contibution = $this->input->post('costibution'); $data = explode('/',$this->input->post('class_level')); $exam_id = $data[0]; $class = $data[1]; $region = $data[2]; $district = $data[3]; $this->db->where('is_sub',1); $gett=$this->db->get('all_subjects'); ?>

Main subject:

result() as $ros){ if($sub != $ros->subject_id){ ?>
Check the subject and enter the maximum mark of the subject.
Sub-subjects Maximum mark Percent(Apply only for custom selection)
input->post('category'); $contr = $this->input->post('contribution'); $sub = $this->input->post('sub'); $main = $this->input->post('main'); $data = explode('/',$this->input->post('data')); $exam_id = $data[0]; $class = $data[1]; $region = $data[2]; $district = $data[3]; $percent_sum=0; $count = 0; if($contr == 'Custom'){ foreach($sub as $subject){ $count++; $percent_sum = $percent_sum + $subject['percent']; } }else{ $percent_sum = 100; $count = count($sub); } if($count < 2){ ?>
Sub-subjects count must be greater than one!

Sum of Contribution percent must be exaclty 100%!
0){ $data = array( 'examination_id'=>$exam_id, 'main_subject_id'=>$main, 'sub_subject_id'=>$subject_id, 'max_mark'=>$max, 'contribution'=>$contribution, 'percent'=>$percent, 'class_level'=>$class, 'region_id'=>$region, 'district_id'=>$district, 'category'=>$category, ); ## validating duplications. $this->db->where('main_subject_id',$main); $this->db->where('sub_subject_id',$subject_id); $this->db->where('category',$category); $this->db->where('examination_id',$exam_id); $count_sub = $this->db->count_all_results('sub_subjects'); if($count_sub == 0){ $insert = $this->db->insert('sub_subjects',$data); }else{ $this->db->where('main_subject_id',$main); $this->db->where('sub_subject_id',$subject_id); $this->db->where('category',$category); $this->db->where('examination_id',$exam_id); $this->db->update('sub_subjects',$data); } } } ?>
Data saved successfully!
load->view('includes/super_header'); $this->load->view('users/superuser/assign_subjects_o'); $this->load->view('includes/super_footer'); } public function assign_subjects_p(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/assign_subjects_p'); $this->load->view('includes/super_footer'); } public function assign_subjects_a(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/assign_subjects_a'); $this->load->view('includes/super_footer'); } public function assign_sub_subjects_o(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/assign_sub_subjects_o'); $this->load->view('includes/super_footer'); } public function assign_sub_subjects_a(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/assign_sub_subjects_a'); $this->load->view('includes/super_footer'); } public function register_user(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/register_user'); $this->load->view('includes/super_footer'); } public function primary_register_user(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/primary_register_user'); $this->load->view('includes/super_footer'); } public function view_results_primary(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/view_results_primary'); $this->load->view('includes/super_footer'); } public function view_results_O_level(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/view_results_O_level'); $this->load->view('includes/super_footer'); } public function view_results_O_level_calculate(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/view_results_O_level_calculate'); $this->load->view('includes/super_footer'); } public function set_exam_public(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/set_exam_public'); $this->load->view('includes/super_footer'); } public function upload_results_o_level_officer(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/upload_results_o_level_officer'); $this->load->view('includes/super_footer'); } public function upload_results_officers_o_level(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/upload_results_officers_o_level'); $this->load->view('includes/super_footer'); } public function insert_results_O_level(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/insert_results_O_level'); $this->load->view('includes/super_footer'); } public function view_results_a_level(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/view_results_a_level'); $this->load->view('includes/super_footer'); } public function register_groups(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/register_groups'); $this->load->view('includes/super_footer'); } public function primary_register_groups(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/primary_register_groups'); $this->load->view('includes/super_footer'); } public function register_subjects(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/register_subjects'); $this->load->view('includes/super_footer'); } public function view_users(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/view_users'); $this->load->view('includes/super_footer'); } public function view_group_schools(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/view_group_schools'); $this->load->view('includes/super_footer'); } public function load_category(){ $cat = $this->input->post('category'); if($cat == 1){ // region ?>
input->post('category'); $this->db->where('reg_number',$this->input->post('email')); $count=$this->db->count_all_results('education_officers'); if($count>0){ redirect('Super_user/register_user?Exist'); }else{ if($cat == 1){ $category = "main"; $data = array( 'full_name'=>$this->input->post('name'), 'reg_number'=>$this->input->post('email'), 'district'=>0, 'region'=>$this->input->post('region'), 'title'=>$this->input->post('title'), 'category'=>$category, 'type'=>'Officer', 'school_type'=>'SS', 'password'=>md5('default'), 'password_recover'=>'default', 'group_id'=>0 ); $data = $this->security->xss_clean($data); $this->db->insert('education_officers',$data); echo 1; }elseif($cat == 2){ $category = "sub"; $d = explode(',',$this->input->post('region')); $sub_region = $d[0]; $region = $d[1]; $data = array( 'full_name'=>$this->input->post('name'), 'reg_number'=>$this->input->post('email'), 'district'=>$sub_region, 'region'=>$region, 'title'=>$this->input->post('title'), 'category'=>$category, 'type'=>'Officer', 'school_type'=>'SS', 'password'=>md5('default'), 'password_recover'=>'default', 'group_id'=>0 ); $data = $this->security->xss_clean($data); $this->db->insert('education_officers',$data); echo 1; }else{ $category = "Group_admin"; $data = array( 'full_name'=>$this->input->post('name'), 'reg_number'=>$this->input->post('email'), 'district'=>0, 'region'=>0, 'title'=>$this->input->post('title'), 'category'=>$category, 'type'=>'Officer', 'school_type'=>'SS', 'password'=>md5('default'), 'password_recover'=>'default', 'group_id'=>$this->input->post('group_id'), ); $data = $this->security->xss_clean($data); $this->db->insert('education_officers',$data); echo 1; } } redirect('Super_user/register_user?Sent'); } } public function insert_user_primary(){ if($_POST){ $cat = $this->input->post('category'); $this->db->where('reg_number',$this->input->post('email')); $count=$this->db->count_all_results('education_officers'); if($count>0){ redirect('Super_user/primary_register_user?Exist'); }else{ if($cat == 1){ $category = "main"; $data = array( 'full_name'=>$this->input->post('name'), 'reg_number'=>$this->input->post('email'), 'district'=>0, 'region'=>$this->input->post('region'), 'title'=>$this->input->post('title'), 'category'=>$category, 'type'=>'Officer', 'school_type'=>'PS', 'password'=>md5('default'), 'password_recover'=>'default', 'group_id'=>0 ); $data = $this->security->xss_clean($data); $this->db->insert('education_officers',$data); echo 1; }elseif($cat == 2){ $category = "sub"; $d = explode(',',$this->input->post('region')); $sub_region = $d[0]; $region = $d[1]; $data = array( 'full_name'=>$this->input->post('name'), 'reg_number'=>$this->input->post('email'), 'district'=>$sub_region, 'region'=>$region, 'title'=>$this->input->post('title'), 'category'=>$category, 'type'=>'Officer', 'school_type'=>'PS', 'password'=>md5('default'), 'password_recover'=>'default', 'group_id'=>0 ); $data = $this->security->xss_clean($data); $this->db->insert('education_officers',$data); echo 1; }else{ $category = "Group_admin"; $data = array( 'full_name'=>$this->input->post('name'), 'reg_number'=>$this->input->post('email'), 'district'=>0, 'region'=>0, 'title'=>$this->input->post('title'), 'category'=>$category, 'type'=>'Officer', 'school_type'=>'PS', 'password'=>md5('default'), 'password_recover'=>'default', 'group_id'=>$this->input->post('group_id'), ); $data = $this->security->xss_clean($data); $this->db->insert('education_officers',$data); echo 1; } } redirect('Super_user/primary_register_user?Sent'); } } public function insert_group(){ $name = $this->security->xss_clean($this->input->post('name')); $this->db->where('name',$name); $count=$this->db->count_all_results('exam_groups'); if($count>0){ redirect('Super_user/register_groups?Exist'); }else{ $data=array( 'name'=>$this->security->xss_clean($this->input->post('name')), 'url'=>$this->security->xss_clean($this->input->post('url')), 'email'=>$this->security->xss_clean($this->input->post('email')), 'heading'=>$this->security->xss_clean($this->input->post('heading')), 'mobile'=>$this->security->xss_clean($this->input->post('mobile')), 'full_name'=>$this->security->xss_clean($this->input->post('full_name')), 'date_registered'=>date('M d Y'), 'group_type'=>'SS', ); $this->db->insert('exam_groups',$data); redirect('Super_user/register_groups?Sent'); } } public function insert_group_primary(){ $name = $this->security->xss_clean($this->input->post('name')); $this->db->where('name',$name); $count=$this->db->count_all_results('exam_groups'); if($count>0){ redirect('Super_user/register_groups?Exist'); }else{ $data=array( 'name'=>$this->security->xss_clean($this->input->post('name')), 'email'=>$this->security->xss_clean($this->input->post('email')), 'heading'=>$this->security->xss_clean($this->input->post('heading')), 'mobile'=>$this->security->xss_clean($this->input->post('mobile')), 'full_name'=>$this->security->xss_clean($this->input->post('full_name')), 'date_registered'=>date('M d Y'), 'group_type'=>'PS', ); $this->db->insert('exam_groups',$data); redirect('Super_user/primary_register_groups?Sent'); } } public function edit_group(){ $data=array( 'name'=>$this->security->xss_clean($this->input->post('name')), 'url'=>$this->security->xss_clean($this->input->post('url')), 'email'=>$this->security->xss_clean($this->input->post('email')), // 'heading'=>$this->security->xss_clean($this->input->post('heading')), 'mobile'=>$this->security->xss_clean($this->input->post('mobile')), 'full_name'=>$this->security->xss_clean($this->input->post('full_name')), // 'date_registered'=>date('M d Y'), ); $this->db->where('group_id',$this->security->xss_clean($this->input->post('group_id'))); $this->db->update('exam_groups',$data); redirect('Super_user/register_groups?Sent'); } public function edit_group_primary(){ $data=array( 'name'=>$this->security->xss_clean($this->input->post('name')), 'email'=>$this->security->xss_clean($this->input->post('email')), // 'heading'=>$this->security->xss_clean($this->input->post('heading')), 'mobile'=>$this->security->xss_clean($this->input->post('mobile')), 'full_name'=>$this->security->xss_clean($this->input->post('full_name')), // 'date_registered'=>date('M d Y'), ); $this->db->where('group_id',$this->security->xss_clean($this->input->post('group_id'))); $this->db->update('exam_groups',$data); redirect('Super_user/primary_register_groups?Sent'); } public function edit_heading(){ $data=array( 'heading'=>$this->security->xss_clean($this->input->post('heading')), ); $this->db->where('group_id',$this->security->xss_clean($this->input->post('id'))); $this->db->update('exam_groups',$data); redirect('Super_user/register_groups?Sent'); } public function edit_heading_primary(){ $data=array( 'heading'=>$this->security->xss_clean($this->input->post('heading')), ); $this->db->where('group_id',$this->security->xss_clean($this->input->post('id'))); $this->db->update('exam_groups',$data); redirect('Super_user/primary_register_groups?Sent'); } public function change_status(){ $no=base64_decode($_GET['id']); $this->db->where('group_id', $no); $get=$this->db->get('exam_groups'); foreach($get->result() as $row){ $status=$row->status; if($status==0){ $data=array( 'status'=>1 ); }else{ $data=array( 'status'=>0 ); } } $this->db->where('group_id', $no); $this->db->update('exam_groups',$data); redirect('Super_user/register_groups?Changed'); } public function change_publish(){ $no=$_GET['exam_id']; $this->db->where('examination_id', $no); $get=$this->db->get('examination'); foreach($get->result() as $row){ $status=$row->status; if($status==0){ $data=array( 'status'=>1 ); }else{ $data=array( 'status'=>0 ); } } $this->db->where('examination_id', $no); $this->db->update('examination',$data); redirect('Super_user/set_exam_public?Changed'); } public function change_public(){ $no=$_GET['exam_id']; $this->db->where('examination_id', $no); $get=$this->db->get('examination'); foreach($get->result() as $row){ $status=$row->public; if($status==0){ $data=array( 'public'=>1 ); }else{ $data=array( 'public'=>0 ); } } $this->db->where('examination_id', $no); $this->db->update('examination',$data); redirect('Super_user/set_exam_public?Changed'); } public function change_status_primary(){ $no=base64_decode($_GET['id']); $this->db->where('group_id', $no); $get=$this->db->get('exam_groups'); foreach($get->result() as $row){ $status=$row->status; if($status==0){ $data=array( 'status'=>1 ); }else{ $data=array( 'status'=>0 ); } } $this->db->where('group_id', $no); $this->db->update('exam_groups',$data); redirect('Super_user/primary_register_groups?Changed'); } public function delete_group(){ $no=base64_decode($_GET['id']); $this->db->where('group_id', $no); $this->db->delete('exam_groups'); redirect('Super_user/register_groups?Deleted'); } public function delete_group_primary(){ $no=base64_decode($_GET['id']); $this->db->where('group_id', $no); $this->db->delete('exam_groups'); redirect('Super_user/primary_register_groups?Deleted'); } public function delete_user(){ $no=base64_decode($_GET['id']); $this->db->where('id', $no); $this->db->delete('education_officers'); redirect('Super_user/register_user?Deleted'); } public function delete_user_primary(){ $no=base64_decode($_GET['id']); $this->db->where('id', $no); $this->db->delete('education_officers'); redirect('Super_user/primary_register_user?Deleted'); } public function load_members(){ $group_id = $this->input->post('id'); ?> db->where('group_id',$group_id); $gtr=$this->db->get('group_schools'); foreach($gtr->result() as $rows){ $this->db->where('school_id',$rows->school_id); $gtzz=$this->db->get('schools'); foreach($gtzz->result() as $row){ $i++; ?>
S/NO School Name Center Number Remove
school_name)); ?> school_reg_number; ?>

school_id; ?>

input->post('school_id'); $id = $this->input->post('id'); $this->db->where('group_id',$id); $this->db->where('school_id',$school_id); $count = $this->db->count_all_results('group_schools'); if($count == 0){ $data = array( 'group_id'=>$id, 'school_id'=>$school_id, 'date_registered'=>date('M d Y'), ); $this->db->insert('group_schools',$data); } } } public function remove_members(){ if($_POST){ $school_id = $this->input->post('school_id'); $id = $this->input->post('id'); $this->db->where('group_id',$id); $this->db->where('school_id',$school_id); $this->db->delete('group_schools'); echo "One member removed"; } } public function assignments(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/assignments'); $this->load->view('includes/super_footer'); } public function error_report_excel(){ $this->load->view('includes/super_header'); $this->load->view('users/superuser/error_report_excel'); $this->load->view('includes/super_footer'); } public function send_ca_excel(){ $inputFileName = $_FILES["file"]["tmp_name"]; $filename = $_FILES["file"]["name"]; $filetype = $_FILES["file"]["type"]; $ext = pathinfo($filename, PATHINFO_EXTENSION); $allowed = array( "xls" => array( "application/vnd.ms-excel" ), "xlsx" => array( "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) ); $file_allowed = false; // this checks also if mimetype of xlsx is just a mimetype of xlsx and nothing else if ( isset( $allowed[$ext] ) && in_array( $filetype, $allowed[$ext] ) ) { $file_allowed = true; } if(!$file_allowed){ redirect($_SERVER['HTTP_REFERER']."&error=".json_encode('The submited file is invalid')); exit(); } try { /// it will be your file name that you are posting with a form or can pass static name $_FILES["file"]["name"]; $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $data = array(); $data2 = array(); $valid_student = 0; $totalrows=$objPHPExcel->setActiveSheetIndex(0)->getHighestRow(); $objWorksheet=$objPHPExcel->setActiveSheetIndex(0); $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); $template = $allDataInSheet[1]['A'].$allDataInSheet[1]['B'].$allDataInSheet[1]['C']; if($template != 'S/NCA/NOSCORE'){ redirect($_SERVER['HTTP_REFERER']."&error=".json_encode('The submited file format is invalid')); exit(); } $region = $this->input->post('region'); $subject_id = $this->input->post('subject_id'); $main_subject_id = $this->input->post('main_subject_id'); $school =$this->input->post('school_id'); $candidate = $this->input->post('candidate'); $exam_id = $this->input->post('exam_id'); $district = $this->input->post('district'); $table=""; $marks_entered=0; $empty_fields = 0; $data = array(); $this->db->where('examination_id', $exam_id); $get=$this->db->get('examination'); foreach($get->result() as $row){ $month = $row->month; $category = $row->category; $academic_year = $row->academic_year; $class = $row->class_level; } //S/N CA/NO SCORE foreach($allDataInSheet as $result){ $reg_number=$stream=""; $this->db->where('school_id',$school); $this->db->where('id_number',$result['B']); $this->db->where('admission_year',$academic_year); // $this->db->where('region',$region); foreach($this->db->get('students')->result() as $student){ $reg_number = $student->reg_number; foreach($this->db->where('reg_number',$reg_number)->where('school_id',$school)->where('academic_year',$academic_year)->get('classes')->result() as $cla){ $stream = $cla->stream; } } $mark = $result['C']; $this->db->where('students_type',$category); $get_grades=$this->db->get('grade_settings'); foreach($get_grades->result() as $row_grade){ if($row_grade->start_mark<=round($mark) && round($mark)<=$row_grade->end_mark){ $mark_grade = $row_grade->grade; } } $point=10; $this->db->where('students_type',$category); $this->db->where('grade',$mark_grade); $ff = $this->db->get('point_settings'); foreach($ff->result() as $p){ $point = $p->point; } if($mark !== NULL){ $mark = round($mark); } if($subject_id == $main_subject_id){ $table = 'ca'; ## This subject has NO sub subject $data = array( 'school_id' => $school, 'district_id' => $district, 'region_id' => $region, 'exam_id' => $exam_id, 'reg_number' =>$reg_number, 'mark' =>round($mark), 'month' => $month, 'academic_year' => $academic_year, 'subject_id' => $subject_id, 'class_level' => $class, 'category' => $category, 'grade' => $mark_grade, 'gpa' => $point, 'stream' => $stream, 'candidate' => $candidate, 'entered_by' => $this->session->userdata('reg_number'), 'date_entered' => date('d-m-Y H:i:s'), ); }else{ $new_mark=0; $this->db->where('region_id',$region); $this->db->where('category',$category); $this->db->where('examination_id',$exam_id); $this->db->where('main_subject_id',$main_subject_id); $this->db->where('sub_subject_id',$subject_id); $gg = $this->db->get('sub_subjects'); foreach($gg->result() as $new){ ## select calculation criteria if($new->contribution == 'Custom'){ $new_mark = round(($mark*$new->percent)/$new->max_mark); }else{ $this->db->where('region_id',$region); $this->db->where('category',$category); $this->db->where('examination_id',$exam_id); $this->db->where('main_subject_id',$main_subject_id); $n = $this->db->count_all_results('sub_subjects'); if($n == 0){ $n = 1; } $new_mark = round(($mark*100)/($new->max_mark)); } } $table = 'ca_sub'; ## This is sub subjects $data = array( 'school_id' => $school, 'district_id' => $district, 'region_id' => $region, 'reg_number' =>$reg_number, 'mark' =>$mark, 'new_mark' =>$new_mark, 'month' => $month, 'academic_year' => $academic_year, 'main_subject_id' => $main_subject_id, 'subject_id' => $subject_id, 'class_level' => $class, 'category' => $category, 'exam_id' => $exam_id, 'stream' => $stream, 'candidate' => $candidate, 'entered_by' => $this->session->userdata('reg_number'), 'date_entered' => date('d-m-Y H:i:s'), ); } $this->db->where('reg_number',$reg_number); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$subject_id); $this->db->where('exam_id',$exam_id); $count = $this->db->count_all_results($table); if(strlen($reg_number) > 7){ ## Reg_number found in the database if($mark !== NULL){ if($count == 0){ $marks_entered++; $this->db->insert($table,$data); }else{ $marks_entered++; $this->db->where('reg_number',$reg_number); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('subject_id',$subject_id); $this->db->update($table,$data); } ########################################### $sum_mark=0; if($subject_id !== $main_subject_id){ $mark_grade=''; $this->db->select_sum('new_mark'); $this->db->where('school_id', $school); $this->db->where('reg_number',$reg_number); $this->db->where('month', $month); $this->db->where('academic_year',$academic_year); $this->db->where('main_subject_id', $main_subject_id); $this->db->where('category', $category); $this->db->where('candidate', $candidate); $this->db->where('class_level', $class); $this->db->where('district_id',$district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $get_new = $this->db->get('ca_sub'); foreach($get_new->result() as $nn){ $n=1; $this->db->where('region_id',$region); $this->db->where('category',$category); $this->db->where('examination_id',$exam_id); $this->db->where('main_subject_id',$main_subject_id); $n = $this->db->count_all_results('sub_subjects'); if($n == 0){ $n = 1; } $sum_mark = round(($nn->new_mark/$n),0); ## Finding the grade of entered mark, we should find from our own table $this->db->where('students_type',$category); $get_grades=$this->db->get('grade_settings'); foreach($get_grades->result() as $row_grade){ if($row_grade->start_mark<=round($sum_mark) && round($sum_mark)<=$row_grade->end_mark){ $mark_grade = $row_grade->grade; } } $this->db->where('students_type',$category); $this->db->where('grade',$mark_grade); $ff = $this->db->get('point_settings'); foreach($ff->result() as $p){ $point = $p->point; } } $data1 = array( 'school_id' => $school, 'district_id' => $district, 'region_id' => $region, 'exam_id' => $exam_id, 'reg_number' =>$reg_number, 'mark' =>round($sum_mark), 'month' => $month, 'academic_year' => $academic_year, 'subject_id' => $main_subject_id, 'class_level' => $class, 'category' => $category, 'grade' => $mark_grade, 'gpa' => $point, 'stream' => $stream, 'candidate' => $candidate, 'entered_by'=>$this->session->userdata('reg_number'), 'date_entered' => date('d-m-Y H:i:s'), ); $this->db->where('school_id', $school); $this->db->where('reg_number',$reg_number); $this->db->where('month', $month); $this->db->where('academic_year',$academic_year); $this->db->where('subject_id', $main_subject_id); $this->db->where('category', $category); $this->db->where('candidate', $candidate); $this->db->where('class_level', $class); $this->db->where('district_id',$district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $exist = $this->db->count_all_results('ca'); if($exist>0){ $this->db->where('school_id', $school); $this->db->where('reg_number',$reg_number); $this->db->where('month', $month); $this->db->where('academic_year',$academic_year); $this->db->where('subject_id', $main_subject_id); $this->db->where('category', $category); $this->db->where('candidate', $candidate); $this->db->where('class_level', $class); $this->db->where('district_id',$district); $this->db->where('region_id',$region); $this->db->where('exam_id',$exam_id); $this->db->update('ca', $data1); }else{ $this->db->insert('ca', $data1); } } ########################################### } } } redirect($_SERVER['HTTP_REFERER']."&uploaded=".$marks_entered); } catch(Exception $e) { $error = pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage(); redirect($_SERVER['HTTP_REFERER']."&error=".json_encode($error)); } } public function send_ca_excel_all(){ $inputFileName = $_FILES["file"]["tmp_name"]; $filename = $_FILES["file"]["name"]; $filetype = $_FILES["file"]["type"]; $ext = pathinfo($filename, PATHINFO_EXTENSION); $allowed = array( "xls" => array( "application/vnd.ms-excel" ), "xlsx" => array( "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) ); $file_allowed = false; // this checks also if mimetype of xlsx is just a mimetype of xlsx and nothing else if ( isset( $allowed[$ext] ) && in_array( $filetype, $allowed[$ext] ) ) { $file_allowed = true; } if(!$file_allowed){ // redirect($_SERVER['HTTP_REFERER']."&error=".json_encode('The submited file is invalid')); //exit(); } try { /// it will be your file name that you are posting with a form or can pass static name $_FILES["file"]["name"]; $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $data = array(); $data2 = array(); $valid_student = 0; $totalrows=$objPHPExcel->setActiveSheetIndex(0)->getHighestRow(); $objWorksheet=$objPHPExcel->setActiveSheetIndex(0); $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); // $template = $allDataInSheet[1]['A'].$allDataInSheet[1]['B'].$allDataInSheet[1]['C']; $A = strtoupper(str_replace(' ','',$allDataInSheet[1]['A'])); $B = strtoupper(str_replace(' ','',$allDataInSheet[1]['B'])); $C = strtoupper(str_replace(' ','',$allDataInSheet[1]['C'])); $D = strtoupper(str_replace(' ','',$allDataInSheet[1]['D'])); $E = strtoupper(str_replace(' ','',$allDataInSheet[1]['E'])); $F = strtoupper(str_replace(' ','',$allDataInSheet[1]['F'])); if($A != "REGNUMBER" || $B != "FIRSTNAME" || $C != "MIDDLENAME" || $D != "LASTNAME" || $E != "GENDER" || $F != "PHONENUMBER" ){ redirect($_SERVER['HTTP_REFERER']."&error=".json_encode('The submited file format is invalid')); exit(); } $region = $this->input->post('region'); $subject_id = $this->input->post('subject_id'); $main_subject_id = $this->input->post('main_subject_id'); $school =$this->input->post('school_id'); $candidate = $this->input->post('candidate'); $exam_id = $this->input->post('exam_id'); $district = $this->input->post('district'); $ids = $alpha = array(); foreach(range('G','Y') as $index){ if(isset($allDataInSheet[1][$index])){ $subject = $allDataInSheet[1][$index]; $subject = explode(' ',$subject); $subject = strtoupper(substr($subject[0],0,3)); if($subject == 'B/M' || $subject == 'BAS'){ $subject = "B/MATH"; } if($subject == 'BOO' || $subject == 'B/K' ){ $subject = "B/KEEP"; } if($subject == 'LIT'){ $subject = "LITERATURE"; } if($subject == 'BIB'){ $subject = "B/KNOW"; } if($subject == 'ISL'){ $subject = "I/KNOW"; } if($subject == 'INF'){ $subject = "ICS"; } if($subject == 'FOO' || $subject == 'F/N'){ $subject = "F/NUTR"; } if($subject == 'ADD' || $subject == 'AD/'){ $subject = "AD/MATH"; } if($subject == 'P/E'){ $subject = "P/EDU"; } if($main_subject_id == $subject_id){ $this->db->where('is_sub',0); }else{ $this->db->where('is_sub',1); } $this->db->where('short_name',$subject); $get = $this->db->get('all_subjects'); if($get->num_rows() > 1){ //echo "Confusing, more than 1
"; }elseif($get->num_rows() == 1){ foreach($get->result() as $res){ $ids[] = $res->subject_id; $alpha[] = $index; // echo $subject." - ".$res->subject_id." "; } }else{ //echo $subject." not found
"; } //echo $subject."
"; } } $table=""; $marks_entered=0; $empty_fields = 0; $data = array(); $this->db->where('examination_id', $exam_id); $get=$this->db->get('examination'); foreach($get->result() as $row){ $month = $row->month; $category = $row->category; $academic_year = $row->academic_year; $class = $row->class_level; } $academic_year = date('Y'); foreach($allDataInSheet as $result){ if($result['A'] == 'REG NUMBER') continue; $reg_number=$stream=""; $this->db->where('school_id',$school); $this->db->where('id_number',$result['A']); $this->db->where('admission_year',$academic_year); $this->db->where('class_admitted',$class); foreach($this->db->get('students')->result() as $student){ $reg_number = $student->reg_number; foreach($this->db->where('reg_number',$reg_number)->where('school_id',$school)->where('academic_year',$academic_year)->get('classes')->result() as $cla){ $stream = $cla->stream; } } $i=0; foreach($ids as $su_id){ $mark = $result[$alpha[$i]]; /* if(!is_numeric($mark)){ continue; } */ $subject_id = $su_id; $i++; $this->db->where('students_type',$category); $get_grades=$this->db->get('grade_settings'); foreach($get_grades->result() as $row_grade){ if($row_grade->start_mark<=round($mark) && round($mark)<=$row_grade->end_mark){ $mark_grade = $row_grade->grade; } } $point=10; $this->db->where('students_type',$category); $this->db->where('grade',$mark_grade); $ff = $this->db->get('point_settings'); foreach($ff->result() as $p){ $point = $p->point; } if($mark !== NULL && round($mark) ){ $mark = round($mark); $table = 'ca'; ## This subject has NO sub subject $data = array( 'school_id' => $school, 'district_id' => $district, 'region_id' => $region, 'exam_id' => $exam_id, 'reg_number' =>$reg_number, 'mark' =>$mark, 'month' => $month, 'academic_year' => $academic_year, 'subject_id' => $subject_id, 'class_level' => $class, 'category' => $category, 'grade' => $mark_grade, 'gpa' => $point, 'stream' => $stream, 'candidate' => $candidate, 'entered_by' => $this->session->userdata('reg_number'), 'date_entered' => date('d-m-Y H:i:s'), ); $this->db->where('reg_number',$reg_number); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->where('subject_id',$subject_id); $this->db->where('exam_id',$exam_id); $count = $this->db->count_all_results($table); if(strlen($reg_number) > 7){ ## Reg_number found in the database if($mark !== NULL){ if($count == 0){ $marks_entered++; $this->db->insert($table,$data); }else{ $marks_entered++; $this->db->where('reg_number',$reg_number); $this->db->where('school_id',$school); $this->db->where('candidate',$candidate); $this->db->where('exam_id',$exam_id); $this->db->where('subject_id',$subject_id); $this->db->update($table,$data); } } } } } } redirect($_SERVER['HTTP_REFERER']."&uploaded=".$marks_entered); } catch(Exception $e) { $error = pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage(); redirect($_SERVER['HTTP_REFERER']."&error=".json_encode($error)); } } public function check_exam(){ $exam_id = 37; $this->db->distinct()->select('reg_number'); $this->db->where('admission_year',2018); $this->db->where('region',0); $this->db->where('district',0); $gg = $this->db->get('students'); foreach($gg->result() as $students){ $this->db->where('reg_number',$students->reg_number); $this->db->where('exam_id',$exam_id); $this->db->where('region_id',3); $this->db->where('district_id',6); //$this->db->where('school_id','SS5ba8b376ed077'); //$this->db->delete('ca'); foreach($this->db->get('ca')->result() as $ca){ foreach($this->db->where('reg_number',$ca->reg_number)->get('students')->result() as $name){ echo $name->full_name." ".$ca->reg_number." ".$ca->school_id."
"; } } } } }