 <?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 subject set program_stutus='$status' WHERE id='$id'");
header('location:admin.php?page=program"');
}

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

if (isset($_POST['submit'])){
$class_id = $_POST['class_id']; 
$program = $_POST['program'];
 

// $student= mysqli_query($conn,"SELECT code,program  FROM subject WHERE code='$code' AND program='$program'")or die(mysqli_error());
// $check = mysqli_fetch_array($student);
 
// if ($check) {
$query=mysqli_query($conn,"INSERT INTO `subject`(`class_id`, `program` ) VALUES('$class_id','$program')");
  
  if($query){ 
         ?>
         <script type="text/javascript">
             alert("Subject Successed Added");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Subject 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 Time Table</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">Time Table Management</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">Time table 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 Time-table 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>Subject Name</th> 
                                <th>Class</th>  
                                <th>Time</th> 
                                <th>Status</th> 
                                <th>Action</th>
                            </tr>
                            </thead>
                            <tbody>
                               <?php 
                                    $i = 1;
                                   $school_query = mysqli_query($conn,"SELECT * FROM subject,class_srms WHERE subject.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['program']; ?></td> 
                              <td><?php echo $row['class_name']; ?></td> 
                              <td><?php echo $row['program_created_on']; ?></td> 
                              <td>
                            <?php
                              if($row["program_stutus"] == 'Enable')
                                 {?>
                                <a href="admin.php?page=program&Id_3=<?php echo $row['id']; ?>" onclick="return confirm('Are you sure you want to block a Class?');" >  <button class="btn btn-secondary"> Enable</button>
                                <?php } else if($row["program_stutus"]=='Disable'){?>
                                  <a href="admin.php?page=program&Id_2=<?php echo $row['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_program&id=<?php echo $row['id']; ?>" class="btn btn-primary btn-flat manage_class">
                              <i class="fas fa-edit"></i>
                            </a>
                             <a href="delete_pr.php?del=<?php echo $row['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>Subject Name</th> 
                                <th>Class</th>  
                                <th>Time</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 Subject</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>Subject Name</label>
                                        <input type="text" name="program" id="program" 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_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>  
 