<?php 
$exam_id=$this->uri->segment("3");
?>
<div class="container-fluid bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            <ul class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="<?php echo base_url(); ?>Welcome">Home</a>
                </li>
                <li class="breadcrumb-item">Examination</li>
                <li class="breadcrumb-item">All class and section</li>
            </ul>
            
            <div class="table-responsive">
                <table class="table table-bordered" id="mytable">
                    <thead>
                        <tr>
                            <th class="sl_no">Sl.No</th>
                            <th>Class-Section</th>
                            <th>Class Teacher</th>
                            <th>Exam Log Sheet</th>
                            <th>Students</th>
                            <th>Result</th>
                            <th>PDF</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $i=0;
                        $academic_session=$this->session->userdata("acedemic_session");
                        $all_class_and_sections=$this->ExamManagementModel->get_class_section_structure($academic_session);
                        if($all_class_and_sections){
                            foreach($all_class_and_sections as $data){
                                $i=$i + 1;
                                $class=$data["class"];
                                $section=$data["section"];
                        ?>
                        <tr>
                            <td><?php echo $i; ?></td>
                            <td><?php echo $data['class']."-".$data['section']; ?></td>
                            <td><?php echo $data['salutation']." ".$data['name']; ?></td>
                            <td>
                                <a href="<?php echo base_url(); ?>ExamManagement/class_section_sheet/<?php echo $data['class']."/".$data['section']."/".$exam_id; ?>" class="btn btn-sm btn-outline-danger" target="_blank">View Sheet</a>
                            </td>
                            <td>
                                <a href="<?php echo base_url(); ?>ExamManagement/class_section_students/<?php echo $data['class']."/".$data['section']."/".$exam_id; ?>" class="btn btn-sm btn-outline-info" target="_blank">View</a>
                            </td>
                            <td>
                                <button class="btn btn-sm btn-info generate-result" section="<?php echo $section; ?>" exam_class="<?php echo $class; ?>" exam_id="<?php echo $exam_id; ?>" acedemic_session="<?php echo $academic_session; ?>">Generate Result</button>    
                            </td>
                            <td>
                                <a href="<?php echo base_url(); ?>ExamReport/first_term_report_card/<?php echo $class."/".$section."/".$exam_id; ?>" class="btn btn-sm btn-outline-danger" target="_blank">View</a>
                            </td>
                        </tr>
                        <?php
                            }
                        }
                        ?>
                    </tbody>
                </table>
            </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",function(){
            var exam_class =$(this).attr("exam_class");
            var section =$(this).attr("section");
            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();?>ExamManagement/generate_exam_result',
                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>");
                    }
            
                }
            });    
        });  
    });
</script>