<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Exam extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('text');
$this->load->helper(array('form','url'));
date_default_timezone_set('Asia/Kolkata');
$this->load->model('StudentModel');
$this->load->model('ExamModel');
$this->load->model('WelcomeModel');
$this->load->model('NewFeeModel');
$this->load->model('FeeModel');
$this->load->helper('date');
$this->load->database();    
$this->load->library('form_validation');
$this->load->helper(array('form', 'url'));
$this->load->library('session');
//  $this->load->library('Pdf');
}

public function index(){
$data['success']=''; $data['error']='';
if(isset($_POST['update_roll_no'])){
$sid=$this->input->post('sid');
$roll_no=$this->input->post('roll_no');

$update_roll_no=$this->ExamModel->update_roll_no($sid,$roll_no);
if($update_roll_no){
$data['success']="Updated Successfully";
}

}


if(isset($_POST['update_house'])){
$sid=$this->input->post('sid');
$house=$this->input->post('house_info');
$update_house_info=$this->ExamModel->update_house_info($sid,$house);
if($update_house_info){
$data['success']="House Updated Successfully";
}

}

$this->load->view('erp/header');
$this->load->view('erp/sidebar');
$this->load->view('erp/exam/my_class_students',$data);
$this->load->view('erp/footer');
}

public function add_exam_subject(){

$data['success']="";  $data['error']="";
if(isset($_POST['add_subject'])){
$exam_subject=$this->input->post('exam_subject');
$exam_class=$this->input->post('exam_class');
$subject_order=$this->input->post('subject_order');
$exam_type=$this->input->post('exam_type');
$mm=$this->input->post('mm');
$y1=2020;$y2=2021;
$cat=date('Y-m-d H:i:s');
$created_by=$this->session->userdata('tid');
$table='exam_subjects';
$data_array=array("subject"=>$exam_subject,"class"=>$exam_class,"subject_order"=>$subject_order,"exam_type"=>$exam_type,"created_by"=>$created_by,"cat"=>$cat,"y1"=>$y1,"y2"=>$y2,"MM"=>$mm);

$add_subject=$this->ExamModel->add_exam_subject($data_array,$table);
if($add_subject){
$data['success']="Exam Subject Added Successfully !";
}else{$data['error']="Error in adding exam subject !";}
}    

$this->load->view('erp/header');
$this->load->view('erp/sidebar');
$this->load->view('erp/exam/add-exam-subject',$data);
$this->load->view('erp/footer');
}


public function exam_log($sid){
$data['success']=''; $data['error']='';    
$this->load->view('erp/header');
$this->load->view('erp/sidebar');

$get_student_data=$this->ExamModel->get_student_data($sid);
if($get_student_data){
foreach($get_student_data as $student_data){
$std_class=$student_data['class'];

if($std_class==3 || $std_class==4 || $std_class==5){
$this->load->view('erp/exam/class-3-to-5-subjects');
}else if($std_class==6 || $std_class==7 || $std_class==8){
$this->load->view('erp/exam/class-6-to-8-subjects');
}else if($std_class==9){
// $this->load->view('erp/exam/class-9-subject');
$this->load->view('erp/exam/class-9-new-subjects');
}else if($std_class==1 || $std_class==2){
$this->load->view('erp/exam/class-1-to-2-subjects');
}

else if($std_class=='PG' || $std_class=='LKG' || $std_class=='UKG'){
$this->load->view('erp/exam/puffins');
}
// else if($std_class==6 || $std_class==7 || $std_class==8){
// $this->load->view('erp/exam/class-3-to-5-subjects');
// }

}
}


if(isset($_POST['add_remark'])){
// $remark_type=$this->input->post('remark_type');
$exam_type=$this->input->post('exam_type');
$remark_quote=$this->input->post('remark_quote');

$cat=date('Y-m-d H:i:s');
$tid=$this->session->userdata('tid');
$y1=y1;
$y2=y2;

$data_array=array("sid"=>$sid,"quote_for"=>$exam_type,"quote"=>$remark_quote,"cat"=>$cat,"cat_by"=>$tid,"y1"=>$y1,"y2"=>$y2);
$data_array_update=array("quote"=>$remark_quote,"uat"=>$cat,"upd_by"=>$tid);
$check_remark=$this->ExamModel->check_remark($sid,$exam_type,$y1,$y2);
if($check_remark){
$update_remark=$this->ExamModel->update_remark($sid,$exam_type,$y1,$y2,$data_array_update);
if($update_remark){
$data['success']="Updated Successfully";
}

}else{
$add_remark=$this->ExamModel->add_remarks($data_array);
if($add_remark){ $data['success'] = "Remark Added Successfully"; }

}
}

if(isset($_POST['update_attendance'])){
$sid=$this->input->post('sid');
$working_days=$this->input->post('working_days');
$present_days=$this->input->post('present_days');
$cat=date('Y-m-d H:i:s');
$tid=$this->session->userdata('tid');
$result_type1='yearly';
$data_array_result=array("sid"=>$sid,"annual_attendance"=>$present_days,"annual_working_days"=>$working_days,"result_type"=>$result_type1,"cat"=>$cat,"cat_by"=>$tid,"y1"=>2020,"y2"=>2021,"class"=>$class);
$data_update_result=array("attendance_day_half_yearly"=>$present_days,"uat"=>$cat,"updated_by"=>$tid);
$check_result_data=$this->ExamModel->get_annual_result_data($sid,$result_type1);
if($check_result_data){
$update_result_data=$this->ExamModel->update_result_data($sid,$data_update_result);
}else{
$add_result_data=$this->ExamModel->add_result_data($data_array_result);
}


}

// $this->load->view('erp/exam/add-remarks',$data);
$this->load->view('erp/exam/add-annual-remarks',$data);
$this->load->view('erp/footer');
}


public function add_exam_log($sid,$sub_id){
$data['success']=''; $data['error']='';
    
if(isset($_POST['add_marks'])){
$tid=$this->session->userdata('tid');
$cat=date('Y-m-d H:i:s');
// $exam_head=$this->input->post('exam_head');
// $obt_marks=$this->input->post('obt_marks');
$check_subject_data=$this->ExamModel->get_subject_data($sub_id);
$class='';
if($check_subject_data){
foreach($check_subject_data as $subject_data){
$class=$subject_data['class'];
    
}
}

$get_exam_heads=$this->ExamModel->get_exam_heads($class);
if($get_exam_heads){
foreach($get_exam_heads as $exam_heads){
$exam_head = $exam_heads['id'];
$obt_marks=$this->input->post($exam_heads['id']);
$mm=$exam_heads['mm'];
// echo $exam_heads['id']; echo $exam_heads['exam_head']; echo $obt_marks; echo "<br>";

if($check_subject_data){
foreach($check_subject_data as $subject_data){
$exam_type=$subject_data['exam_type'];

if($exam_type=='marks'){
$data_array=array("subject_id"=>$sub_id,"student_id"=>$sid,"exam_head"=>$exam_head,"obtained_marks"=>$obt_marks,"cat"=>$cat,"inserted_by"=>$tid,"mm"=>$mm);
$data_array_update=array("obtained_marks"=>$obt_marks,"uat"=>$cat,"updated_by"=>$tid,"mm"=>$mm);
}else if($exam_type=='grade'){
$data_array=array("subject_id"=>$sub_id,"student_id"=>$sid,"exam_head"=>$exam_head,"grade"=>$obt_marks,"cat"=>$cat,"inserted_by"=>$tid,"mm"=>$mm);
$data_array_update=array("grade"=>$obt_marks,"uat"=>$cat,"updated_by"=>$tid,"mm"=>$mm);
}
    
}
}

$check_log=$this->ExamModel->check_exam_log($sid,$sub_id,$exam_head);
if($check_log){
$update_exam_log=$this->ExamModel->update_exam_log($data_array_update,$sid,$sub_id,$exam_head);
if($update_exam_log){
$data['success']="Updated Successfully";
}else{
$data['error']="Error in updating exam log.";
}

}else{
$add_exam_log=$this->ExamModel->add_exam_log($data_array);
if($add_exam_log){
$data['success']="Added Successfully";
}else{
$data['error']="Error in adding exam log.";
}


}

// header("refresh: 15"); 
}
}

// $check_subject_data=$this->ExamModel->get_subject_data($sub_id);
// if($check_subject_data){
// foreach($check_subject_data as $subject_data){
// $exam_type=$subject_data['exam_type'];
// if($exam_type=='marks'){
// $data_array=array("subject_id"=>$sub_id,"student_id"=>$sid,"exam_head"=>$exam_head,"obtained_marks"=>$obt_marks,"cat"=>$cat,"inserted_by"=>$tid);

// $data_array_update=array("obtained_marks"=>$obt_marks,"uat"=>$cat,"updated_by"=>$tid);
// }else if($exam_type=='grade'){
// $data_array=array("subject_id"=>$sub_id,"student_id"=>$sid,"exam_head"=>$exam_head,"grade"=>$obt_marks,"cat"=>$cat,"inserted_by"=>$tid);

// $data_array_update=array("grade"=>$obt_marks,"uat"=>$cat,"updated_by"=>$tid);
    
// }

// $check_log=$this->ExamModel->check_exam_log($sid,$sub_id,$exam_head);
// if($check_log){
// $update_exam_log=$this->ExamModel->update_exam_log($data_array_update,$sid,$sub_id,$exam_head);
// if($update_exam_log){
// $data['success']="Updated Successfully";
// }else{
// $data['error']="Error in updating exam log.";
// }

// }else{
// $add_exam_log=$this->ExamModel->add_exam_log($data_array);
// if($add_exam_log){
// $data['success']="Added Successfully";
// }else{
// $data['error']="Error in adding exam log.";
// }


// }


// }
// }
}
    
$this->load->view('erp/header');
$this->load->view('erp/new/sidebar');
$this->load->view('erp/exam/add-exam-log',$data);
$get_student_data=$this->ExamModel->get_student_data($sid);
if($get_student_data){
foreach($get_student_data as $student_data){
$std_class=$student_data['class'];
}

if($std_class==3 || $std_class==4 || $std_class==5){
$this->load->view('erp/exam/class-3-to-5-subjects');
}else if($std_class==6 || $std_class==7 || $std_class==8){
$this->load->view('erp/exam/class-6-to-8-subjects');
}else if($std_class==9){
// $this->load->view('erp/exam/class-9-subject');
$this->load->view('erp/exam/class-9-new-subjects');
}else if($std_class==1 || $std_class==2){
$this->load->view('erp/exam/class-1-to-2-subjects');
}else if($std_class=='PG' || $std_class=='LKG' || $std_class=='UKG'){
$this->load->view('erp/exam/puffins');
}

}


$this->load->view('erp/footer');
}


public function add_exam_head(){
$data['success']=''; $data['error']='';
    
if(isset($_POST['add_exam_head'])){
$tid=$this->session->userdata('tid');
$cat=date('Y-m-d H:i:s');

$class=$this->input->post('class');
$mm=$this->input->post('max_marks');
// $subject_id=$this->input->post('subject');
$exam_head=$this->input->post('exam_head');
$head_order=$this->input->post('head_order');
$exam_mode=$this->input->post('exam_mode');

$data_array=array("class"=>$class,"exam_head"=>$exam_head,"mm"=>$mm,"cat"=>$cat,"created_by"=>$tid,"head_order"=>$head_order,"exam_mode"=>$exam_mode);
$add_exam_head=$this->ExamModel->add_exam_head($data_array);
if($add_exam_head){
$data['success']="Exam Head Added Successfully !";
}else{$data['error']="Error in adding exam head";}
}
$this->load->view('erp/header');
$this->load->view('erp/sidebar');
$this->load->view('erp/exam/add-exam-head',$data);
$this->load->view('erp/footer');
} 

// public function add_sub_short(){
// $eclass='PG';
// $get_subjects=$this->ExamModel->get_active_subject_data($eclass);
// if($get_subjects){
// foreach($get_subjects as $subjects){
// $exam_subject=$subjects['subject'];
// $exam_class='UKG';
// $subject_order=$subjects['subject_order'];
// $exam_type=$subjects['exam_type'];
// $created_by=$subjects['created_by'];
// $cat=date('Y-m-d H:i:s'); $y1=2020;$y2=2021; $mm=$subjects['MM'];
// $data_array=array("subject"=>$exam_subject,"class"=>$exam_class,"subject_order"=>$subject_order,"exam_type"=>$exam_type,"created_by"=>$created_by,"cat"=>$cat,"y1"=>$y1,"y2"=>$y2,"MM"=>$mm);

// $table='exam_subjects';

// $add_subject=$this->ExamModel->add_exam_subject($data_array,$table);
// if($add_subject){
// echo "Exam Subject Added Successfully !";
// }else{echo "Error in adding exam subject !";}

    
// }
// }
    

// }


public function all_exams(){
$this->load->view('erp/header');
$this->load->view('erp/sidebar');
$this->load->view('erp/exam/all-classes');
$this->load->view('erp/footer');
}

public function marks_for_class($eclass,$section,$acedemic_session){
$this->load->view('erp/header');
$this->load->view('erp/sidebar');
$this->load->view('erp/exam/class-student-list');
$this->load->view('erp/footer');
}

// public function add_remarks(){
// $this->load->view('erp/header');
// $this->load->view('erp/new/sidebar');
// $this->load->view('erp/exam/add-remarks');
// $this->load->view('erp/footer');
// }

public function result($sid){

$old_limit = ini_set("memory_limit", "256M");
$dompdf = new Pdf();
        
$dompdf->set_paper('A4', 'landscape'); //landscape , portrait
// $html_content=$this->FeeModel->pdf_header();

$html_content ="<html><head>";
$html_content .='<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >


<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>
</head><body>';
// background-color:#fcb19f;
// $html_content .='<div class="col-sm-12" style="border:1px solid;padding-top:20px;">';

$html_content .='<div class="container-fluid"><div class="row"><div class="col-sm-12">';
// $html_content .= '<div class="table-responsive "><table class='table-striped table-bordered' width='100%'>';
$html_content .="
<p  style='width:100%;font-size:22px;text-align:center;font-weight:600;'><img src='".school_logo."' width='100px' height='70px'style='padding:0px;float:left;' /><span>".school_full_name."</span></p>
<p style='width:100%;font-size:16px;text-align:center;font-weight:500;padding-bottom:10px; border-bottom:1px solid;'>".school_address."</p>";

// $html_content.="</table></div>";

// $html_content.= '<h3 class="text-center">SESSION 2020 - 21</h3>';

// $html_content.= '<div class="">';
// $html_content.= '<table class="table table-bordered table-striped" >

// <tbody>';
$class='';
$get_student_data=$this->ExamModel->get_student_data($sid);
if($get_student_data){
foreach($get_student_data as $student_data){
$class=$student_data['class'];

$html_content.= '<div style="width:100%;height:35px;font-size:16px;" >';
$html_content.= '<p style="float:left;width:50%;"><b>Name : </b>'.$student_data['student_name'].'</p>';


$html_content.= '<p style="float:left;width:25%;"><b>Sch. No. : </b>'.$student_data['sch_no'].'</p>';

$html_content.= '<p style="float:left;width:25%;"><b>D.O.B. : </b>'.date('d-M-Y',strtotime($student_data['dob'])).'</p></div>';

$html_content.= '<div style="width:100%;height:35px;font-size:16px;" >';
$html_content.= '<p style="float:left;width:25%;"><b>Class : </b>'.$student_data['class'].'-'.$student_data['section'].'</p>';
$html_content.= '<p style="float:left;width:25%;"><b>House: </b> '.$student_data['house'].'</p>';
$html_content.= '<p style="float:left;width:50%;"><b>Attendance :</b>';

$exam_result_data=$this->ExamModel->get_exam_result_data($sid); 
if($exam_result_data){
foreach($exam_result_data as $result_data){
$working_days=$result_data['working_days_half_yearly'];
$present_days=$result_data['attendance_day_half_yearly'];
$html_content.=  $present_days; 
$html_content.= " / "; 
$html_content.= $working_days;
$html_content.= ' ( '.round($present_days*100/$working_days,2).' % ) ';


}
}
$html_content.= '</p></div>';

}
}




$html_content.='
<table class="table table-bordered table-striped" >
<thead>
<tr >
<td colspan="9" class="text-center font-weight-bold">HALF YEARLY PROGRESS REPORT CARD (2020-21)</td>
</tr>
<tr>
<th>Subjects</th>
<th>MM</th>';
$get_exam_heads=$this->ExamModel->get_exam_heads($class);
if($get_exam_heads){
foreach($get_exam_heads as $exam_heads){
if($exam_heads['mm'] ==0 ||  $exam_heads['mm'] ==50){
}else{
$html_content.= '<th>'.$exam_heads['exam_head'].'</th>';
}
}
}

$html_content.='<th>Total</th>
</tr>
</thead>
<tbody>';

 
$count=0;
if($class !='9'){
$total_mm=0;    
}else{
$total_mm=-100;    
}

$grand_total=0;
$get_subjects=$this->ExamModel->get_active_subject_data($class);
if($get_subjects){
foreach($get_subjects as $subjects){
$count= $count + 1;
$subject_id=$subjects['id'];
$exam_type=$subjects['exam_type'];

// $max_marks=$subjects['MM'];

if($subjects['subject_type'] =='main_subject'){
$max_marks=$subjects['MM'];
$total_mm=$total_mm + $max_marks;
}

// $total_mm=$total_mm + $max_marks;

$html_content.='<tr style="padding:0px !important;line-height:10px !important;">';
$html_content.='<td style="padding:5px !important;">'.$subjects['subject'].'</td>';
// $html_content.='<td></td>';
$html_content.='<td>';
if($exam_type=='marks'){
$html_content.=$subjects['MM']; 
}
else if($exam_type=='grade'){$html_content.="Grd";}

$html_content.='</td>';

$all_heads=$this->ExamModel->get_exam_heads($class);
if($all_heads){
foreach($all_heads as $exam_heads){
$exam_head_id=$exam_heads['id'];

if($exam_heads['mm'] !=0 &&  $exam_heads['mm'] !=50){
$html_content.='<td>';
$student_log_data = $this->ExamModel->student_exam_log($sid,$exam_head_id,$subject_id);

if($student_log_data){
foreach($student_log_data as $student_log){



if($exam_type == 'marks'){
$html_content.=''.$student_log['obtained_marks'].'';
}
else if($exam_type == 'grade'){
$html_content.="<span class='text-uppercase'>".$student_log['grade']."</span>";
}





}
}else{
$html_content.='...';
}


$html_content.='</td>';

}

}
}


$html_content.='<td>';
$total=0;
if($all_heads){
foreach($all_heads as $exam_heads){
$ehid=$exam_heads['id'];

$get_all_marks_total_data=$this->ExamModel->student_exam_log($sid,$ehid,$subject_id);
if($get_all_marks_total_data){
foreach($get_all_marks_total_data as $total_data){
$total = $total + $total_data['obtained_marks'];
}
}

}
}
if($exam_type=='marks'){
$html_content.=''.$total.'';
if($subjects['subject_type'] =='main_subject'){
$grand_total=$grand_total + $total;

}
}else if($exam_type == 'grade'){
if($all_heads){
foreach($all_heads as $exam_heads){
$ehid=$exam_heads['id'];    
    
if($exam_heads['mm'] ==0 || $exam_heads['mm'] ==50){

$get_marks=$this->ExamModel->student_exam_log($sid,$ehid,$subject_id);
if($get_marks){foreach($get_marks as $get_marks_data){
$html_content.= ''.$get_marks_data['grade'].'';    
}
}

}
    
}
    
}
}
$html_content.='
</td>
</tr>';

}
}

$html_content.='<tr><td></td>';
$html_content.='<td>'.$total_mm.'</td>';
$html_content.='<td colspan="5"></td>';
$html_content.='<td>'.round(($grand_total * 100)/$total_mm,2).' %</td>';
$html_content.='<td>'.$grand_total.'</td>';
$html_content.='</tr>';   


$html_content.='<tr><td colspan="2">COMMENT:</td>';
$html_content.='<td colspan="7">';
$get_student_remark=$this->ExamModel->get_student_remark($sid);
if($get_student_remark){
foreach($get_student_remark as $student_remark){
$html_content.='"'.$student_remark['quote'].'".';
}
}


$html_content.='</td></tr>';
$html_content.='</tbody></table>';





// $html_content .="<p style='padding:10px;font-size:18px;text-align:right;margin-top:10px;'><b>(PRINCIPAL)</b></p>";

$html_content .="<p style='text-align:center;padding:5px;'><b>website :".school_website."<b></p>";
$html_content .="</div></div></div></body></html>";
$this->pdf->loadHtml($html_content);
$this->pdf->render();
$this->pdf->stream("".$id.".pdf", array("Attachment"=>0));

    
}

public function exam_subjects(){
$data['success']='';  $data['error']='';    
if(isset($_POST['update_subject_type'])){
$subject_id=$this->input->post('subject_id');
$subject_type=$this->input->post('subject_type');

$update_subject_info=$this->ExamModel->update_subject_info($subject_id,$subject_type);
if($update_subject_info){
$data['success']="Updated Successfully";
}else{$data['error']="Error in updating subject information";}

}
$this->load->view('erp/header');
$this->load->view('erp/sidebar');
$this->load->view('erp/exam/all-subjects',$data);
$this->load->view('erp/footer');
}


public function attendance(){
$this->load->view('erp/header');
$this->load->view('erp/new/sidebar');
$this->load->view('erp/exam/students-for-attendance');
$this->load->view('erp/footer');
}

public function mark_attendance($sid){
$this->load->view('erp/header');
$this->load->view('erp/new/sidebar');
$this->load->view('erp/exam/attendance-view');
$this->load->view('erp/footer');
}

public function get_exam_log_for(){
$this->load->view('erp/header');
$this->load->view('erp/new/sidebar');
$this->load->view('erp/exam/elog_data');
$this->load->view('erp/footer');
}

// public function delete_single_record(){
// $id=27645;
// $del_data=$this->ExamModel->delete_single_data($id);
// if($del_data){
// echo "deleted";
// }

// }


public function markin(){
$sid = $_POST['sid'];
$val=$_POST['val'];
$ehid=$_POST['ehid'];
$sub_id=$_POST['sub_id'];
$log_id=$_POST['log_id'];
$tid=$this->session->userdata('tid');
$cat=date('Y-m-d H:i:s');
$data_array_update=array("attendance"=>$val,"updated_by"=>$tid,"uat"=>$cat);
// $data_array=array("cat"=>$cat,"attendance"=>$val);

$data_array=array("attendance"=>$val,"subject_id"=>$sub_id,"student_id"=>$sid,"exam_head"=>$ehid,"cat"=>$cat,"inserted_by"=>$tid);

$check_log_data=$this->ExamModel->check_exam_log($sid,$sub_id,$ehid);

// check_exam_log($sid,$sub_id,$exam_head)

if($check_log_data){
$update_exam_log=$this->ExamModel->update_exam_log($data_array_update,$sid,$sub_id,$ehid);
if($update_exam_log){echo "Updated";}else{ echo "error update";}
}else{
$add_new_log=$this->ExamModel->add_exam_log($data_array);
if($add_new_log){echo "Added";}else{echo "error";}
}

}


public function load_students_for_attendance(){
$count=0;
$sid=$_POST['sid'];
$class=$_POST['eclass'];
$get_subjects=$this->ExamModel->get_active_subject_data($class);
if($get_subjects){
foreach($get_subjects as $subjects){

$subject_id=$subjects['id'];
$exam_type=$subjects['exam_type'];
$all_heads=$this->ExamModel->get_exam_heads($class);
if($all_heads){
foreach($all_heads as $exam_heads){
$no_log=0;
$count= $count + 1;
$ehid=$exam_heads['id'];
$log_id='';
$log_value='';
$log_atd='';
$get_exam_log=$this->ExamModel->student_exam_log($sid,$ehid,$subject_id);
if($get_exam_log){
foreach($get_exam_log as $exam_log){
$log_id=$exam_log['id'];    
$log_atd=$exam_log['attendance'];
if($exam_type =='marks'){
$log_value=$exam_log['obtained_marks'];
}else if($exam_type =='grade'){
$log_value=$exam_log['grade'];
}
}
}else{$no_log=$no_log + 1;}

echo "<tr>";
echo "<td>".$count."</td>";
echo "<td>".$subjects['subject']."</td>";
echo "<td>".$exam_heads['exam_head']."</td>";
echo "<td>".$log_value."</td>";
echo "<td>";
if($log_atd =='A' || $log_atd =='ML'){
echo "<button class='btn btn-success' id='mark_present' log_id='".$log_id."' ehid='".$ehid."' sub_id='".$subject_id."' sid='".$sid."'>Present</button>";
}
echo "<button class='btn btn-danger' id='mark_absent' log_id='".$log_id."' ehid='".$ehid."' sub_id='".$subject_id."' sid='".$sid."'>Absent</button>";
echo "<button class='btn btn-warning text-white' id='mark_leave' log_id='".$log_id."' ehid='".$ehid."' sub_id='".$subject_id."' sid='".$sid."'>Med.Leave</button>";
    
echo "</td>";
echo "<td>";

// echo $no_log;
$get_exam_log=$this->ExamModel->student_exam_log($sid,$ehid,$subject_id);
if($get_exam_log){
foreach($get_exam_log as $exam_log){

$atd=$exam_log['attendance'];
if($atd =='A'){
echo "<span class='btn btn-sm btn-danger'>Absent</span>";
}else if($atd =='ML'){
echo "<span class='btn btn-sm btn-warning'>ML</span>";
}else if($atd =='P'){
echo "<span class='btn btn-sm btn-success'>Present</span>";
}

}
}


    
    
echo "</td>";
echo "</tr>";

}
}

}
}
}
public function my_class_result(){
$this->load->view('erp/header');
$this->load->view('erp/new/sidebar');
// $this->load->view('erp/exam/class-ranking');
$this->load->view('erp/exam/exam-results-data');
$this->load->view('erp/footer');
}

public function annual_ranking_and_result(){
$this->load->view('erp/header');
$this->load->view('erp/new/sidebar');
// $this->load->view('erp/exam/class-ranking');
$this->load->view('erp/exam/annual-ranking');
$this->load->view('erp/footer');
}
public function half_yearly_ranking_and_result(){
$this->load->view('erp/header');
$this->load->view('erp/new/sidebar');
$this->load->view('erp/exam/class-ranking');
$this->load->view('erp/footer');
}

public function result_for_class($acedemic_session,$eclass,$section){
$this->load->view('erp/header');
$this->load->view('erp/sidebar');
$this->load->view('erp/exam/exam-result-classwise');
$this->load->view('erp/footer');
}

public function report_card($sid){
$this->load->view('erp/header');
$this->load->view('erp/new/sidebar');
$this->load->view('erp/exam/result-view');
$this->load->view('erp/footer');
}

public function update_student_data(){
$get_annual_students=$this->ExamModel->get_all_annual_students();
if($get_annual_students){
foreach($get_annual_students as $annual_students){
$sid=$annual_students['sid'];
$get_student_info=$this->ExamModel->get_student_data($sid);
if($get_student_info){
foreach($get_student_info as $info){
$eclass=$info['class'];
$esection=$info['section'];
$data_array=array("class"=>$eclass,"section"=>$esection);
$exam_mode='yearly';
$update_result_data=$this->ExamModel->update_result($sid,$exam_mode,$data_array);
if($update_result_data){
echo $update_result_data;
}


}
}

}
}


}
    
}
?>