 <?php 
 include ('../includes/connection.php'); 
 // code for block exam    
if(isset($_GET['Id_3']))
{
$id=$_GET['Id_3'];
$status='Disable'; 
$sql =mysqli_query($conn,"update class_soes set class_status='$status' WHERE class_id='$id'");
header('location:admin.php?page=student"');
}

//code for active students
if(isset($_GET['Id_2']))
{
$id=$_GET['Id_2'];
$status='Enable'; 
$sql =mysqli_query($conn,"update class_soes set class_status='$status' WHERE class_id='$id'");
header('location:admin.php?page=student"');
}  

if (isset($_POST['submit'])){
$class_name = $_POST['class_name']; 
$class_code = md5($_POST['class_code']);  
$query=mysqli_query($conn,"INSERT INTO `class_soes`(`class_name`, `class_code`) VALUES('$class_name','$class_code')");
  
  if($query){ 
         ?>
         <script type="text/javascript">
             alert("Class Successed Added");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Class not Added Try Again");
        </script>
        <?php
    }
  } 
?>
 
  <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>Add Class</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">Class Management</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>
<br>
   <!-- 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">Class 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 Class 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>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 class_soes");
                                while($row = mysqli_fetch_array($school_query)){  
                             ?>
                            <tr>
                              <td class="text-center"><?php echo $i++ ?></td>
                              <td><?php echo $row['class_name']; ?></td> 
                              <td><?php echo $row['class_created_on']; ?></td> 
                              <td>
                            <?php
                              if($row["class_status"] == 'Enable')
                                 {?>
                                <a href="admin.php?page=class&Id_3=<?php echo $row['class_id']; ?>" onclick="return confirm('Are you sure you want to block a Class?');" >  <button class="btn btn-secondary"> Enable</button>
                                <?php } else if($row["class_status"]=='Disable'){?>
                                  <a href="admin.php?page=class&Id_2=<?php echo $row['class_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['id'] ?>' href="admin.php?page=update_class&id=<?php echo $row['class_id']; ?>" class="btn btn-primary btn-flat manage_class">
                              <i class="fas fa-edit"></i>
                            </a>
                             <a href="delete_cl.php?del=<?php echo $row['class_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>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 Class</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>Class Name</label>
                                        <input type="text" name="class_name" id="class_name" class="form-control" required data-parsley-pattern="/^[a-zA-Z0-9 \s]+$/" data-parsley-trigger="keyup" />
                                      </div>
                                  </div>
                                  <div class="modal-footer">
                                      <input type="hidden" name="class_code" id="class_code" value="123" /> 
                                      <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>  
