<?php
// $exam_id=$this->uri->segment(3);
$exam_id=4;
?>

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

<style>
    body{background: #EAEDED;}
    /*.teachers-container{background:#fff;padding:20px;min-height:500px; margin-bottom:20px;}*/
    a{color:black;}
    a:hover{text-decoration:none;}
    tr th,tr td{
        text-align:center;
    }
</style>

<div class="container-fluid teachers-container mt-3 mb-3 pt-3 pb-3 bg-white">
    <div class="row">
        <div class="col-sm-12">

            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Welcome">Home</a></li> 
                <li class="breadcrumb-item">All Courses And Sections</li> 
            </ul>           
    
            <div class="view-teachers">
                <div class="table-responsive">
                    <table class="table table-striped table-bordered" id="mytable">
                        <thead>
                            <tr>
                                <th>#</th>    
                                <th>Name</th>
                                <th>Class Teacher</th>
                                <th>Students</th>
                                <!--<th>PDF</th>-->
                                <!--<th>Final PDF</th>-->
                                <!--<th>Result</th>-->
                                <th>Result</th>
                                <th>PDF</th>
                                <th>Admit Cards</th>
                            </tr>
                        </thead>    
                        <tbody>
                        <?php 
                        $teacher_data = $this->SchoolModel->all_teachers();
                        $acedemic_session=$this->session->userdata('acedemic_session');
                        $count=0;
                        $class="";
                        if($teacher_data){
                        foreach($teacher_data as $teacher){
                        if($teacher['user_status'] == 1){ 
                        $tid=$teacher['id'];
                        $get_course_info=$this->SchoolModel->get_teacher_course_profile($tid,$acedemic_session);
                        if($get_course_info){
                        foreach($get_course_info as $course_info){
                        $class=$course_info['class'];
                        $section=$course_info['section'];
                        $course_id=$course_info['course_id'];
                                            
                                            
                        // $all_students=$this->WelcomeModel->get_students_ac_session_by_class($acedemic_session,$class,$section);
                        
                        $all_students=$this->NewExamModel->get_students_ac_session_by_course_and_class($acedemic_session,$class,$section);
                        $scount=0;
                        if($all_students){
                        foreach($all_students as $data){
                        $student_table='student';
                        $get_student_data=$this->NewExamModel->get_item_data($data['sid'],$student_table);
                        if($get_student_data ){
                            foreach($get_student_data as $students){
                                if($students['status'] ==1){
                                    $scount++;
                                }
                            }
                        }
                        }
                        }   
                        $count++;
                        ?>
                        
                        
                            <tr>
                                <td><?php echo $count; ?></td>
                                <td><?php echo $teacher['name']; ?></td>
                                <td class="text-center"><?php echo $course_info['class']; ?>-<?php echo $course_info['section'];?></td>
                                <td>
                                    <?php 
                                    if($class == 1 || $class == 2 || $class == 3 || $class == 4 || $class == 5 || $class == 6 || $class == 7 || $class == 8 || $class == 9 || $class == 11){
                                    ?>
                                    <a href="<?php echo base_url(); ?>Examination/view_exam_result/<?php echo $course_info['class']."/".$course_info['section']."/".$exam_id; ?>" class="btn btn-sm btn-info" target="_blank">View Result</a>      
                                    <?PHP
                                    } 
                                    ?>
                                </td>
                                
                                
                                <td>
                                    <?php
                                    $classs=$course_info['class'];
                                    if($class == 11 ){
                                    ?>
                                    <button class="btn btn-sm btn-info generate-result-annual-1" section="<?php echo $course_info['section']; ?>" exam_class="<?php echo $course_info['class']; ?>" exam_id="<?php echo $exam_id; ?>" acedemic_session="3">Generate Result</button>
                                    <?php
                                    }else if( $classs == 10 || $classs == 12){
                                    ?>
                                    
                                    <?php
                                    }else if($class == 9){
                                    ?>
                                    <button class="btn btn-sm btn-info generate-result-annual-9" section="<?php echo $course_info['section']; ?>" exam_class="<?php echo $course_info['class']; ?>" exam_id="<?php echo $exam_id; ?>" acedemic_session="3">Generate Result</button>
                                    <?php
                                    }else if($classs == 6 || $classs == 7 || $classs == 8){
                                    ?>
                                    <button class="btn btn-sm btn-info generate-result-annual-1-to-9" section="<?php echo $course_info['section']; ?>" exam_class="<?php echo $course_info['class']; ?>" exam_id="<?php echo $exam_id; ?>" acedemic_session="3">Generate Result</button>    
                                    <?php    
                                    }else if($classs == 1 || $classs == 2 || $classs == 3 || $classs == 4 || $classs == 5){
                                    ?>
                                    <button class="btn btn-sm btn-info generate-result-annual-1-to-5" section="<?php echo $course_info['section']; ?>" exam_class="<?php echo $course_info['class']; ?>" exam_id="<?php echo $exam_id; ?>" acedemic_session="3">Generate Result</button>    
                                    <?php    
                                    }
                                    
                                    ?>
                                    
                                </td>
                                <td>
                                    <!--<a href="<?php echo base_url(); ?>Report/annual_report_card_final/<?php echo $class."/".$course_info['section']; ?>" class="btn btn-sm btn-outline-danger" target="_blank">View</a>-->
                                    <?php 
                                    if($class == 1 || $class == 2 || $class == 3 || $class == 4 || $class == 5 || $class == 6 || $class == 7 || $class == 8 || $class == 9 || $class == 11){
                                    ?>
                                    <a href="<?php echo base_url(); ?>Report/annual_report_card_final/<?php echo $class."/".$course_info['section']; ?>" class="btn btn-sm btn-outline-danger" target="_blank">View</a>
                                    <?php 
                                    }
                                    ?>
                                </td>
                                
                                <td>
                                    <a href="<?php echo base_url(); ?>Examination/admit_cards/<?php echo $course_info['class']."/".$course_info['section']; ?>" target="_blank" class="btn btn-sm btn-info">view</a>
                                </td>
                            </tr>
                        <?php           }
                                    }
                                }
                            }    
                        }
                        ?>
                        </tbody>
                    </table>       
                </div>
 
    
            </div>    
        </div>    
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title text-warning" id="exampleModalLabel" style="text-align:center;width:100%;"></h5>
        <button type="button" class="btn-close btn btn-sm btn-rounded" data-bs-dismiss="modal" aria-label="Close"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-circle" viewBox="0 0 16 16"><path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/><path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"/></svg></button>
      </div>
      <div class="modal-body success-response" style="text-align:center;">
            <h5 class="text-warning"><b>Generting Result. Keep Your Screen On. Don't Close and Change Your Screen</b></h5>
            <div class="spinner-border text-primary" role="status">
                <span class="visually-hidden">...</span>
            </div>
            <div class="spinner-border text-secondary" role="status">
                <span class="visually-hidden">...</span>
            </div>
            <div class="spinner-border text-success" role="status">
                <span class="visually-hidden">...</span>
            </div>
            <div class="spinner-border text-danger" role="status">
                <span class="visually-hidden">...</span>
            </div>
            <div class="spinner-border text-warning" role="status">
                <span class="visually-hidden">...</span>
            </div>
            <div class="spinner-border text-info" role="status">
                <span class="visually-hidden">...</span>
            </div>
            <div class="spinner-border text-light" role="status">
                <span class="visually-hidden">...</span>
            </div>
            <div class="spinner-border text-dark" role="status">
                <span class="visually-hidden">...</span>
            </div>
          
      </div>
      <div class="modal-footer">
        <!--<a href="<?php echo base_url(); ?>Register" class="btn btn-primary">Register Now</a>-->
        <!--<a class="btn btn-success"  href="<?php echo base_url(); ?>Login">Login</a>-->
        <!--<button type="button" class="btn btn-primary">Save changes</button>-->
      </div>
    </div>
  </div>
</div>


<script>
    $(document).ready(function(){
        
        
        
        $(document).on("click",".generate-result-annual-1",function(){
            var exam_class =$(this).attr("exam_class");
            var section =$(this).attr("section");
            // var course_id=$(this).attr("course_id");
            var exam_id=$(this).attr("exam_id");
            
            var acedemic_session=$(this).attr("acedemic_session");
            $('#exampleModal').modal({
                backdrop: 'static',
                // keyboard: false,
                // mouse:false
            });
            
            
            $('#exampleModal').modal('show');
            $.ajax({
                url: '<?php echo base_url();?>AnnualExam/generate_result_hsc_class_11_annual',
                type: 'POST',
                data: {exam_class:exam_class,section:section,exam_id:exam_id,acedemic_session:acedemic_session},
                success: function(data){
                    // alert(data);
                    if(data == "success"){
                        $(".btn-close").css("display","block");
                        $(".success-response").html("<span class='text-success text-center'>Result Generated Successfully</span>");
                    }
            
                }
            });    
        });
        
        
        $(document).on("click",".generate-result-annual-1-to-9",function(){
            var exam_class =$(this).attr("exam_class");
            var section =$(this).attr("section");
            // var course_id=$(this).attr("course_id");
            var exam_id=$(this).attr("exam_id");
            
            var acedemic_session=$(this).attr("acedemic_session");
            $('#exampleModal').modal({
                backdrop: 'static',
                // keyboard: false,
                // mouse:false
            });
            
            
            $('#exampleModal').modal('show');
            $.ajax({
                url: '<?php echo base_url();?>AnnualExam/generate_result_1_to_9',
                type: 'POST',
                data: {exam_class:exam_class,section:section,exam_id:exam_id,acedemic_session:acedemic_session},
                success: function(data){
                    // alert(data);
                    if(data == "success"){
                        $(".btn-close").css("display","block");
                        $(".success-response").html("<span class='text-success text-center'>Result Generated Successfully</span>");
                    }
            
                }
            });    
        });
        
        $(document).on("click",".generate-result-annual-9",function(){
            var exam_class =$(this).attr("exam_class");
            var section =$(this).attr("section");
            // var course_id=$(this).attr("course_id");
            var exam_id=$(this).attr("exam_id");
            
            var acedemic_session=$(this).attr("acedemic_session");
            $('#exampleModal').modal({
                backdrop: 'static',
                // keyboard: false,
                // mouse:false
            });
            
            
            $('#exampleModal').modal('show');
            $.ajax({
                url: '<?php echo base_url();?>AnnualExam/generate_result_class_9',
                type: 'POST',
                data: {exam_class:exam_class,section:section,exam_id:exam_id,acedemic_session:acedemic_session},
                success: function(data){
                    // alert(data);
                    if(data == "success"){
                        $(".btn-close").css("display","block");
                        $(".success-response").html("<span class='text-success text-center'>Result Generated Successfully</span>");
                    }
            
                }
            });    
        });
        
        
        $(document).on("click",".generate-result-annual-1-to-5",function(){
            var exam_class =$(this).attr("exam_class");
            var section =$(this).attr("section");
            // var course_id=$(this).attr("course_id");
            var exam_id=$(this).attr("exam_id");
            
            var acedemic_session=$(this).attr("acedemic_session");
            $('#exampleModal').modal({
                backdrop: 'static',
                // keyboard: false,
                // mouse:false
            });
            
            
            $('#exampleModal').modal('show');
            $.ajax({
                url: '<?php echo base_url();?>AnnualExam/generate_result_class_1_to_5',
                type: 'POST',
                data: {exam_class:exam_class,section:section,exam_id:exam_id,acedemic_session:acedemic_session},
                success: function(data){
                    // alert(data);
                    if(data == "success"){
                        $(".btn-close").css("display","block");
                        $(".success-response").html("<span class='text-success text-center'>Result Generated Successfully</span>");
                    }
            
                }
            });    
        });
        
        // $(document).on("click",".generate-result-second-term-1",function(){
        //     var exam_class =$(this).attr("exam_class");
        //     var section =$(this).attr("section");
        //     // var course_id=$(this).attr("course_id");
        //     var exam_id=$(this).attr("exam_id");
            
        //     var acedemic_session=$(this).attr("acedemic_session");
        //     $('#exampleModal').modal({
        //         backdrop: 'static',
        //         // keyboard: false,
        //         // mouse:false
        //     });
            
            
        //     $('#exampleModal').modal('show');
        //     $.ajax({
        //         url: '<?php echo base_url();?>AnnualExam/generate_result_hsc',
        //         type: 'POST',
        //         data: {exam_class:exam_class,section:section,exam_id:exam_id,acedemic_session:acedemic_session},
        //         success: function(data){
        //             // alert(data);
        //             if(data == "success"){
        //                 $(".btn-close").css("display","block");
        //                 $(".success-response").html("<span class='text-success text-center'>Result Generated Successfully</span>");
        //             }
            
        //         }
        //     });    
        // });   
        
      
        // $(document).on("click",".generate-result-second-term",function(){
        //     var exam_class =$(this).attr("exam_class");
        //     var section =$(this).attr("section");
            
        //     // var course_id=$(this).attr("course_id");
        //     var exam_id=$(this).attr("exam_id");
            
        //     var acedemic_session=$(this).attr("acedemic_session");
        //     $('#exampleModal').modal({
        //         backdrop: 'static',
        //         // keyboard: false,
        //         // mouse:false
        //     });
            
            
        //     $('#exampleModal').modal('show');
        //     $.ajax({
        //         url: '<?php echo base_url();?>AnnualExam/generate_result_lower_classes',
        //         type: 'POST',
        //         data: {exam_class:exam_class,section:section,exam_id:exam_id,acedemic_session:acedemic_session},
        //         success: function(data){
        //             // alert(data);
        //             if(data == "success"){
        //                 $(".btn-close").css("display","block");
        //                 $(".success-response").html("<span class='text-success text-center'>Result Generated Successfully</span>");
        //             }
            
        //         }
        //     });    
        // });  
        
        
        
        $(".btn-close").click(function(){
            $('#exampleModal').modal('hide');
            location.reload();
        })
    });
</script>
