<?php  

include ('../includes/connection.php');  
if (isset($_POST['submit'])){
$class_id = $_POST['class_id'];   
$exam_name = $_POST['exam_name'];   
$year=date("Y");
 
$query=mysqli_query($conn,"INSERT INTO `exam_srms`(`exam_name`,`class_id`,`year` ) VALUES('$exam_name','$class_id','$year' )");
  
  if($query){ 
         ?>
         <script type="text/javascript">
             alert("Exam Successed Added");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Exam not Added Try Again");
        </script>
        <?php
    }  
  }  

if(isset($_GET['del']))
{
  
$id= $_GET['del'];
$q =mysqli_query($conn,"DELETE FROM `exam_srms` WHERE exam_id = $id ");
header('location:admin.php?page=exam');
}

if(isset($_GET['Id_3']))
{
$id=$_GET['Id_3'];
$status='Disabled'; 
$sql =mysqli_query($conn,"update exam_srms set exam_status='$status' WHERE exam_id='$id'");
header('location:admin.php?page=exam');
}

if(isset($_GET['Id_2']))
{
$id=$_GET['Id_2'];
$status='Enable'; 
$sql =mysqli_query($conn,"update exam_srms set exam_status='$status' WHERE exam_id='$id'");
header('location:admin.php?page=exam');
}  
?> 
   
 
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <a><strong>Examination</strong></a>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li> 
              <li class="breadcrumb-item active">Examination Detail</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

   <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row"> 
          <!-- /.col -->
          <div class="col-md-12">
            <div class="card"> 
              <!-- /.card-header --> 
              <div class="card-body"> 
              <div class="tab-content">
              <!-- /.tab-pane -->
              <div class="active tab-pane" id="teacher">
              <div class="container-fluid">
                <div class="row">
                  <div class="col-sm-12">  
                    <div class="card">
                     <div class="card-header">
                      <h3 class="card-title">Examination List</h3>
                      <div class="float-right mb-2">
                        <a data-toggle="modal" href="#add" class="btn btn-secondary btn-xs float-right ml-2" >
                            <i class="fa fa-plus"></i> Add Exam Here
                        </a>
                        </div>
                         </div> 
                         <!-- /.card-header -->
                          <div class="card-body">
                           <div class="table-responsive">
                            <table id="example1" class="table table-striped display table-bordered" >
                            <thead>  
                            <tr>
                                <th>#</th>
                                <th>Exam Name</th> 
                                <th>Class Name</th>  
                                <th>Created On</th> 
                                <th>Status</th> 
                                <th>Action</th>
                            </tr>
                            </thead>
                            <tbody>
                               <?php 
                                    $i = 1;
                                   $school_query = mysqli_query($conn,"SELECT * FROM exam_srms,class_srms WHERE exam_srms.class_id=class_srms.class_id");
                                while($row = mysqli_fetch_array($school_query)){  
                             ?>
                            <tr>
                              <td class="text-center"><?php echo $i++ ?></td> 
                              <td><?php echo $row['exam_name']; ?></td> 
                              <td><?php echo $row['class_name']; ?></td> 
                              <td><?php echo $row['year']; ?></td> 
                              <td>
                            <?php
                              if($row["exam_status"] == 'Enable')
                                 {?>
                                <a href="admin.php?page=program&Id_3=<?php echo $row['exam_id']; ?>" onclick="return confirm('Are you sure you want to block a Class?');" >  <button class="btn btn-secondary"> Enable</button>
                                <?php } else if($row["exam_status"]=='Disable'){?>
                                  <a href="admin.php?page=program&Id_2=<?php echo $row['exam_id']; ?>" onclick="return confirm('Are you sure you want to active a Class?');"><button class="btn btn-danger">Disable</button> 
                                 <?php } ?>

                             </td>
                          <td>
                             <div class="btn-group">
                            <a  data-id='<?php echo $row['exam_id'] ?>' href="admin.php?page=update_program&id=<?php echo $row[' exam_id']; ?>" class="btn btn-primary btn-flat manage_class">
                              <i class="fas fa-edit"></i>
                            </a>
                             <a href="admin.php?page=exam&del=<?php echo $row['exam_id']; ?>" onclick="return confirm('Are you sure you want to delete?');" class="btn btn-danger btn-flat delete_student">
                              <i class="fas fa-trash"></i>
                            </a>   
                        </div> </td>
                          </tr> 
                            <?php }?>
                            </tbody>
                            <tfoot>
                             <tr>
                                <th>#</th>
                                <th>Exam Name</th> 
                                <th>Class Name</th>  
                                <th>Created On</th> 
                                <th>Status</th> 
                                <th>Action</th>
                            </tr>
                          </tfoot>
                        </table>
                        <div class="modal fade" id="add">
                          <div class="modal-dialog">
                            <form method="post" action="">
                                <div class="modal-content">
                                  <div class="modal-header">
                                      <h4 class="modal-title" id="modal_title">Add Exam</h4>
                                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                                  </div>
                                  <div class="modal-body">
                                    <span id="form_message"></span>  
                                      <div class="form-group">
                                        <label>Exam Name</label>
                                        <input type="text" name="exam_name" id="exam_name" class="form-control" required data-parsley-pattern="/^[a-zA-Z0-9 \s]+$/" data-parsley-trigger="keyup" />
                                       </div>   
                                      <div class="form-group">
                                        <label>Class Name</label>
                                        <?php  
                                        $query = "SELECT * FROM class_srms WHERE class_name!='GRADUATOR' AND class_status='Enable' ORDER BY class_name ASC"; 
                                         $result = $conn->query($query);      
                                         ?> 
                                        <select name="class_id" id="class_id" class="form-control" required>
                                            <option value="">Select Class</option>
                                            <?php 
                                            if($result->num_rows > 0){ 
                                                while($row = $result->fetch_assoc()){  
                                                    echo '<option value="'.$row['class_id'].'">'.$row['class_name'].'</option>'; 
                                                } 
                                            }else{ 
                                                echo '<option value="">Class not available</option>'; 
                                            } 
                                          ?>
                                        </select> 
                                    </div>  
                                  </div>
                                  <div class="modal-footer"> 
                                      <input type="submit" name="submit" class="btn btn-secondary" value="Add" />
                                      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                  </div>
                                </div>
                            </form>
                            </div>
                       </div><!-- /.modal -->
                       </div>
                     </div>
                    </div> <!-- end card body-->
                    </div> <!-- end card --> 
                    </div>
                  <!-- /.card -->
                  </div>
                 </div> 
                </div>
                <!-- /.tab-content -->
             </div><!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <script src="../stp_con/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../stp_con/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables  & Plugins -->
<script src="../stp_con/datatables/jquery.dataTables.min.js"></script>
<script src="../stp_con/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../stp_con/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../stp_con/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../stp_con/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../stp_con/jszip/jszip.min.js"></script>
<script src="../stp_con/pdfmake/pdfmake.min.js"></script>
<script src="../stp_con/pdfmake/vfs_fonts.js"></script>  
<script src="../stp_con/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.colVis.min.js"></script>
 
<script src="../assets/js/adminlte.min.js"></script>   
 
 <script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)'); 
  });
</script>  
 