 <?php 
 include ('includes/connection.php'); 
 include('sms.php');
 
if(isset($_GET['Id_3']))
{
$id=$_GET['Id_3'];
$status='Disable'; 
$sql =mysqli_query($conn,"update user_soes set user_status='$status' WHERE user_id='$id'");
header('location:admin.php?page=facilitator');
}

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

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

if(isset($_GET['Id_4']))
{
$id=$_GET['Id_4'];
$Role_id='facilitator'; 
$sql =mysqli_query($conn,"update user_soes set Role='$Role_id' WHERE user_id='$id'");
header('location:admin.php?page=facilitator');
}

//code for active students
if(isset($_GET['Id_5']))
{
$id=$_GET['Id_5'];
$Role_id='admistrator'; 
$sql =mysqli_query($conn,"update user_soes set Role='$Role_id' WHERE user_id='$id'");
header('location:admin.php?page=facilitator');
}

if (isset($_POST['submit'])){
$user_name = $_POST['user_name']; 
$user_email = $_POST['user_email']; 
$email = mysqli_real_escape_string($conn, $_POST['user_email']);
$password = $_POST['PasswordHash']; 
$user_contact_no = $_POST['user_contact_no'];  
$PasswordHash = md5($_POST['PasswordHash']);
$IndustrialCategory = $_POST['IndustrialCategory']; 

$query=mysqli_query($conn,"INSERT INTO `user_soes`(`user_name`, `user_contact_no`, `user_email`, `PasswordHash`,`IndustrialCategory`) VALUES('$user_name','$user_contact_no','$user_email','$PasswordHash','$IndustrialCategory')");
  
  if($query){ 
      $s_mobile = substr($user_contact_no, 1);
      $s_mobile = "255$s_mobile";
      $message = "Dear $user_name, Congratulation for being register to Cybercode Orbital username and password is $email and $password resp,Use Url: https://cybershield.co.tz/orbital/login.php";
      send_message($s_mobile, $message);
         ?>
         <script type="text/javascript">
             alert("Facilitator Successed Added");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Facilitator not Added Try Again");
        </script>
        <?php
    }
  } 
?> 
<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper"> 
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <a><strong>Facilitator information</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"><a href="#">USER MANAGEMENT</a></li>
              <li class="breadcrumb-item active">Facilitator</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">Facilitator 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 new facilitator
                        </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>Image</th>  
                            <th>Full Name</th>
                            <th>Email</th>
                            <th>Mobile</th> 
                            <th>Category</th>
                            <th>Role</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                          <?php 
                            $i = 1;
                            $selected = mysqli_query($conn,"SELECT * From user_soes ");
                             while($row = mysqli_fetch_array($selected)){ 
                        
                            ?> 
                           
                        <tr>
                          <td class="text-center"><?php echo $i++ ?></td> 
                           <td> 
                          <img src="../<?php echo $row['user_profile']; ?>" class="img-thumbnail" width="75" height="75" /></td> 
                          <td><?php echo $row['user_name']; ?></td>
                          <td><?php echo $row['user_email']; ?></td>
                          <td><?php echo $row['user_contact_no']; ?></td>  
                          <td><?php echo $row['IndustrialCategory']; ?></td>  
                          <td>
                            <?php
                              if($row["Role"] == 'admistrator')
                                 {?>
                                <a href="admin.php?page=facilitator&Id_4=<?php echo $row['user_id']; ?>" onclick="return confirm('Are you sure you want to Authorizy a user?');" >  <button class="btn btn-info"> Admin</button>
                                <?php } else if($row["Role"]=='facilitator'){?>
                                  <a href="admin.php?page=facilitator&Id_5=<?php echo $row['user_id']; ?>" onclick="return confirm('Are you sure you want to Authorizy a Admin?');"><button class="btn btn-success"> Facilitator</button> 
                                 <?php } ?>

                             </td>  
                          <td>
                            <?php
                              if($row["user_status"] == 'Enable')
                                 {?>
                                <a href="admin.php?page=facilitator&Id_3=<?php echo $row['user_id']; ?>" onclick="return confirm('Are you sure you want to block a User?');" >  <button class="btn btn-secondary"> Enable</button>
                                <?php } else if($row["user_status"]=='Disable'){?>
                                  <a href="admin.php?page=facilitator&Id_2=<?php echo $row['user_id']; ?>" onclick="return confirm('Are you sure you want to active a User?');"><button class="btn btn-danger"> Disable</button> 
                                 <?php } ?>

                             </td>
                          <td>
                             <div class="btn-group">
                            <a data-id='<?php echo $row['user_id'] ?>' href="admin.php?page=update_user&id=<?php echo $row['user_id']; ?>" class="btn btn-primary btn-flat manage_class">
                              <i class="fas fa-edit"></i>
                            </a>
                             <a href="admin.php?page=facilitator&del=<?php echo $row['user_id']; ?>" onclick="return confirm('Are you sure you want to delete?');" class="btn btn-danger btn-flat">
                              <i class="fas fa-trash"></i>
                            </a>   
                        </div> </td>
                      </tr> 
                      <?php }?> 
                        </tbody>
                        <tfoot>
                        <tr>
                           <th>#</th>  
                           <th>Image</th>
                            <th>Full Name</th>
                            <th>Email</th>
                            <th>Mobile</th> 
                            <th>Category</th>
                            <th>Role</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 Facilitator</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>Facilitator Name</label>
                                        <input type="text" name="user_name" id="user_name" class="form-control" required data-parsley-trigger="keyup" />
                                      </div>
                                      <div class="form-group">
                                        <label>Facilitator E-mail</label>
                                        <input type="Email" name="user_email" id="user_email" class="form-control"required data-parsley-trigger="keyup" />
                                      </div>
                                      <div class="form-group">
                                        <label>Mobile</label>
                                        <input type="text" name="user_contact_no" id="user_contact_no" class="form-control" required data-parsley-trigger="keyup" />
                                      </div>
                                      <div class="form-group">
                                        <label>Category</label>
                                        <input type="text" name="IndustrialCategory" id="IndustrialCategory" class="form-control" required   data-parsley-trigger="keyup" /> 
                                      </div>
                                       <input type="hidden" name="PasswordHash" id="PasswordHash" value="CyberCoder123">
                                  </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>
<a href="#" class="back-to-top"><i class="fa fa-chevron-up"></i></a>
<div id="preloader"></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>