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

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

if (isset($_POST['add'])){   
    $subject_name = $_POST['subject_name']; 
     $user_type = $_POST['user_type']; 
    $course_code = $_POST['course_code']; 
    $description = mysqli_real_escape_string($conn, $_POST['description']); 
    
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name = addslashes($_FILES['image']['name']);
    $image_size = getimagesize($_FILES['image']['tmp_name']);
    
    move_uploaded_file($_FILES["image"]["tmp_name"], "../assets/img/academy/" . $_FILES["image"]["name"]);
    $adminthumbnails = "assets/img/academy/" . $_FILES["image"]["name"];

   $query=mysqli_query($conn," INSERT INTO `subject_soes`(`subject_name`,`user_type`,`course_code`,`certificate`, `description`) VALUES('$subject_name','$user_type','$course_code','$adminthumbnails','$description')") 
    or die(mysqli_error()); 
    if($query){ 
         ?>
         <script type="text/javascript">
             alert("Course Successed Added");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Course not Added Try Again");
        </script>
        <?php
    }
  }
  if (isset($_POST['save'])){     
   $course_code = $_POST['course_code']; 
   $code = $_POST['code']; 
   $descrpt = mysqli_real_escape_string($conn, $_POST['description']); 
   
   $query1= mysqli_query($conn,"SELECT course_code,subject_id FROM subject_soes WHERE course_code='$course_code'")or die(mysqli_error());
    $row = mysqli_fetch_array($query1);
    $subject_id=$row['subject_id']; 
   $query=mysqli_query($conn,"INSERT INTO `module_soes`(`course_code`,`subject_id`, `code`,`description`) VALUES('$course_code','$subject_id','$code','$descrpt')") 
    or die(mysqli_error()); 
    if($query){ 
         ?>
         <script type="text/javascript">
             alert("Module Successed Added");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Module 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 Course</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">Course 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">
              <div class="card-header p-2">
                <ul class="nav nav-pills ">
                  <li class="nav-item"><a class="nav-link active" href="#course" data-toggle="tab"><i class="fas fa-th-list"></i> Course List</a></li> 
                  <li class="nav-item"><a class="nav-link" href="#module" data-toggle="tab"><i class="fas fa-list mr-1"></i> Module</a></li>  
                </ul>
              </div> 
              <div class="card-body"> 
              <div class="tab-content"> 
              <div class="active tab-pane" id="course">
              <div class="container-fluid">
                <div class="row">
                  <div class="col-sm-12">  
                    <div class="card">  
                      <div class="card-header">
                      <h3 class="card-title">Course List</h3>
                      <div class="float-right mb-2"> 
                         <a data-toggle="modal" href="#update" class="btn btn-info btn-xs float-right ml-2" >
                            <i class="fa fa-edit"></i>  Add Course Here
                        </a>
                        </div>
                    </div>
                  <div class="card-body">
                <div class="table-responsive">
                    <table id="example1" class="table table-striped display table-bordered" >
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>Image</th> 
                          <th>Course</th> 
                          <th>Course name</th>
                          <th>Course Description</th>  
                          <th>Course Type</th>
                          <th>Created On</th> 
                          <th>Status</th> 
                          <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                               <?php 
                                    $i = 1;
                                   $school_query = mysqli_query($conn,"SELECT * FROM subject_soes");
                                while($row = mysqli_fetch_array($school_query)){  
                             ?>
                            <tr>
                              <td class="text-center"><?php echo $i++ ?></td>
                              <td><img src="../<?php echo $row['course_image']; ?>" class="img-thumbnail" width="75" height="75" /></td>
                              <td><?php echo $row['course_code']; ?></td> 
                              <td><?php echo $row['subject_name']; ?></td> 
                              <td><?php echo $row['description']; ?></td> 
                              <td><?php echo $row['user_type']; ?></td> 
                              <td><?php echo $row['subject_created_on']; ?></td> 
                              <td>
                            <?php
                              if($row["subject_status"] == 'Enable')
                                 {?>
                                <a href="admin.php?page=course&Id_3=<?php echo $row['subject_id']; ?>" onclick="return confirm('Are you sure you want to block a Class?');" >  <button class="btn btn-secondary"> Enable</button>
                                <?php } else if($row["subject_status"]=='Disable'){?>
                                  <a href="admin.php?page=course&Id_2=<?php echo $row['subject_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_couse&id=<?php echo $row['subject_id']; ?>" class="btn btn-primary btn-flat manage_class">
                              <i class="fas fa-edit"></i>
                            </a>
                             <a href="delete_course.php?del=<?php echo $row['subject_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>Image</th> 
                          <th>Course</th> 
                          <th>Course name</th>
                          <th>Course Description</th>
                          <th>Course Type</th>
                          <th>Created On</th> 
                          <th>Status</th> 
                          <th>Action</th>
                        </tr>
                      </tfoot>
                    </table> 
                 </div>
               </div>
              </div> <!-- end card body-->
            </div> <!-- end card --> 
            </div>
            <!-- /.card -->
          </div>
          </div>
          <div class="modal fade" id="update">
                <div class="modal-dialog">
                  <form method="post" action="" enctype="multipart/form-data">
                      <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title" id="modal_title">Add Course</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>Course<span style="color: red;">*</span></label>
                                <input type="text" name="course_code" id="course_code" class="form-control select2" required>
                              </div>
                              <div class="form-group">
                               <label>Course Name <span style="color: red;">*</span></label>
                                <input type="text" name="subject_name" id="subject_name" class="form-control select2" required>
                              </div>
                              <div class="form-group">
                               <label>Course Type <span style="color: red;">*</span></label>
                                <select name="user_type" id="user_type" class="form-control select2" required>
                                    <option >select course Type</option>
                                    <option value="Professional">Professional Cybershield</option>
                                    <option value="Digital">Digital User</option> 
                                </select>
                              </div>
                              <div class="form-group">
                                  <label>Course Description <span style="color: red;">*</span></label>
                                  <textarea type="text" name="description" id="description" class="form-control select2" required></textarea> 
                              </div>
                               <div class="form-group">
                                  <label>Upload Certificate <span style="color: red;">*</span></label>
                                      <input type="file" class="form-control" name="image"  id="fileInput" placeholder="Change profile picture">
                                </div>
                            </div>
                           <div class="modal-footer"> 
                            <button type="submit" name="add" class="btn btn-secondary">Add</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        </div>
                      </div>
                  </form>
               </div>
             </div><!-- /.modal -->
            <div class="tab-pane" id="module">
              <div class="container-fluid">
                <div class="row">
                  <div class="col-sm-12">  
                    <div class="card">  
                      <div class="card-header">
                      <h3 class="card-title">Module List</h3>
                      <div class="float-right mb-2"> 
                         <a data-toggle="modal" href="#modal" class="btn btn-secondary btn-xs float-right ml-2" >
                            <i class="fa fa-edit"></i>  Add Module Here
                        </a>
                        </div>
                    </div>
                  <div class="card-body">
                  <div class="table-responsive">
                    <table id="example2" class="table table-striped display table-bordered" >
                      <thead>
                        <tr>
                          <th>#</th> 
                          <th>Course</th> 
                          <th>Course Code</th> 
                          <th>Module Description</th>   
                          <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                               <?php 
                                    $i = 1;
                                   $school_query = mysqli_query($conn,"SELECT * FROM module_soes");
                                while($row = mysqli_fetch_array($school_query)){  
                             ?>
                            <tr>
                              <td class="text-center"><?php echo $i++ ?></td> 
                              <td><?php echo $row['course_code']; ?></td> 
                               <td><?php echo $row['code']; ?></td>   
                              <td><?php echo $row['description']; ?></td>   
                          <td>
                             <div class="btn-group">
                            <a  data-id='<?php echo $row['id'] ?>' href="admin.php?page=update_module&id=<?php echo $row['module_id']; ?>" class="btn btn-primary btn-flat manage_class">
                              <i class="fas fa-edit"></i>
                            </a>
                             <a href="delete_module.php?del=<?php echo $row['module_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>Course</th>
                          <th>Course Code</th>  
                          <th>Module Description</th>   
                          <th>Action</th>
                        </tr>
                      </tfoot>
                    </table> 
                 </div>
               </div>
              </div> <!-- end card body-->
            </div> <!-- end card --> 
            </div>
            <!-- /.card -->
          </div>
          </div>

        <div class="modal fade" id="modal">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">Course Module</h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
           
              <form method="post" action="" enctype="multipart/form-data"> 
                 <div class="modal-body">
                <div class="modal-body">
                  <span id="form_message"></span> 
                      <div class="form-group">
                         <label>Course<span style="color: red;">*</span></label>
                           <div class="select2-purple"> 
                              <?php  
                              $query = "SELECT * FROM subject_soes ORDER BY subject_name ASC"; 
                              $result = $conn->query($query);      
                               ?> 
                             <select name="course_code" id="course_code" class="form-control select2" required>
                              <option value="">Select Course</option>
                                <?php 
                              if($result->num_rows > 0){ 
                                  while($row = $result->fetch_assoc()){  
                                      echo '<option value="'.$row['course_code'].'">'.$row['course_code'].' | '.$row['subject_name'].'</option>'; 
                                  } 
                              }else{ 
                                  echo '<option value="">Course not available</option>'; 
                              } 
                              ?>
                            </select>
                          </div> 
                        </div>
                        <div class="form-group">
                       <label>Course Code<span style="color: red;">*</span></label> 
                       <input type="text" name="code" class="form-control select2" placeholder="Please Enter a Coursecode Eg: WDFO_012" required> 
                      </div>
                      <div class="form-group">
                       <label>Course Description <span style="color: red;">*</span></label> 
                            <textarea id="summernote" name="description" class="form-control select2">
                              Place <em>some</em> <u>text</u> <strong>here</strong>
                            </textarea> 
                      </div> 
                    </div>  
                </div>
              <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <button type="submit"  name="save" class="btn btn-primary">Save</button>
            </div>
            </form>
          </div>
          <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
      </div>
             
             </div>
                <!-- /.tab-content -->
             </div><!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section> 
  </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="../stp_con/summernote/summernote-bs4.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)'); 
  });
   $(function () {
    $("#example2").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example2_wrapper .col-md-6:eq(0)'); 
  });
</script>  
<script>
  $(function () {
    // Summernote
    $('#summernote').summernote()

    // CodeMirror
    CodeMirror.fromTextArea(document.getElementById("codeMirrorDemo"), {
      mode: "htmlmixed",
      theme: "monokai"
    });
  })
</script>