<?php
error_reporting(0);
session_start();
if(isset($_SESSION['username'])){

?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <meta charset="utf-8" />
    <?php include('includes/styles.php'); ?>
    <title>Add Conference Officer | <?php echo $church_name; ?></title>
   
</head>

<?php

?>
<style>
    ul.parsley-errors-list.filled {
        padding: 0;
        list-style: none;
        color: red;
        padding-right: 20px;
        position: relative;
        float: right;
        margin: 0;
    }


    span.select2.select2-container.select2-container--default {
        width: 100% !important;
    }


    ul#parsley-id-5, ul#parsley-id-9, ul#parsley-id-11, ul#parsley-id-15, ul#parsley-id-21, ul#parsley-id-23 {
        animation:signup-response 0.5s 1;
        -webkit-animation:signup-response 0.5s 1;
        animation-fill-mode: forwards;

        animation-delay:5s;
        -webkit-animation-delay:5s; /* Safari and Chrome */
        -webkit-animation-fill-mode: forwards;

    }

    @keyframes signup-response{
        from {opacity :1;}
        to {opacity :0;  height: 0px;}
    }

    @-webkit-keyframes signup-response{
        from {opacity :1;}
        to {opacity :0;  height: 0px;}
    }
</style>
<body class="fixed-header dashboard">
<?php include('includes/sidebar.php'); ?>


<div class="page-container ">
    <?php include('includes/header.php'); ?>
    <!-- END HEADER -->
    <!-- START PAGE CONTENT WRAPPER -->
    <div class="page-content-wrapper ">
        <!-- START PAGE CONTENT -->
        <div class="content ">
            <!-- START CONTAINER FLUID -->
            <div class=" container-fluid   container-fixed-lg">
                <!-- START BREADCRUMB -->
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="<?php echo $base_url; ?>">Home</a></li>
                    <li class="breadcrumb-item active">Add Conference Officer</li>
                </ol>
                <!-- END BREADCRUMB -->
                <div class="row m-t-50">
                    <div class="col-xl-12 col-lg-12">
                    <!-- <div class="alert alert-danger" role="alert">
                      <button aria-label="" class="close" data-dismiss="alert"></button>
                      <strong>Note: </strong>Create a teacher before creating a class
                    </div> -->
                        <!-- START card -->
                        <div class="card">
                            <div class="card-header ">
                                <div class="card-title">
                                <?php
                                $sql = "SELECT type FROM admin WHERE username =:username";
                                $conn->query($sql);
                                $conn->bind(":username", $_SESSION['username']);
                                $user_type = $conn->fetchColumn();

                                if($user_type != 'superadmin'){
                                    ?> You are not permitted to add conference officer. Only super admin can do that
                                    <?php
                                }else {
                                    ?> Add Conference Officer
                                <?php
                                }
                            ?>
                                </div>
                            </div>
                            <div class="card-body">
                                <?php
                                   $sql = "SELECT type FROM admin WHERE username =:username";
                                   $conn->query($sql);
                                   $conn->bind(":username", $_SESSION['username']);
                                   $user_type = $conn->fetchColumn(); 

                                   if($user_type == 'superadmin'){
                                    ?> 
                                <form action="" class="" method="post" id="officer-add">
                                    <h3 style="margin-bottom: 0" class="mw-80">Enter Conference Officer Data Below</h3>
                                    <p class="mw-80 m-b-50">All fields marked <span style="color: red">*</span> must be filled
                                    
                                        <div class="form-group form-group-default required">
                                            <label>Name</label>
                                            <input type="text" class="form-control" id="name" placeholder="Enter admin name here" required name="name">
                                        </div>


                                        <div class="form-group form-group-default required">
                                            <label>Username</label>
                                            <input type="text" class="form-control" id="username" placeholder="Enter username here" required name="username">
                                        </div>


                                        <div class="form-group form-group-default input-group required" id="show_hide_password">
                                        <div class="form-input-group">
                                            <label>Password </label> 
                                            <input type="password"  name="password" id="password" class="form-control" placeholder="Enter Password here"  required data-parsley-trigger="keyup">
                                        </div>
                                        <div class="input-group-append ">
                                            <a href="javascript:;" class="input-group-text"><i class="fa fa-eye-slash"></i></a>
                                        </div>
                                        </div>
                                        

        
                                    <div class="row m-t-50">
                                        <div class="col-xl-6">
                                            <p class="small-text hint-text">Note: Please crosscheck all data provided before submitting to database </p>
                                        </div>
                                        <div class="col-xl-6">
                                            <input aria-label="" type="submit" value="Add Conference Officer" name="add-officer" id="submit" class="btn btn-primary pull-right btn-lg btn-block btn-animated from-left">
                                                
                                        </div>
                                    </div>


                                    <div id="success-msg"></div>

                                </form>
                            </div>
                        </div>
                        <!-- END card -->
                    </div>
                    


                </div>



                <div class="row m-t-50">
                    <div class="col-xl-12 col-lg-12">
                    <!-- <div class="alert alert-danger" role="alert">
                      <button aria-label="" class="close" data-dismiss="alert"></button>
                      <strong>Note: </strong>Create a teacher before creating a class
                    </div> -->
                        <!-- START card -->
                        <div class="card">
                            <div class="card-header ">
                                <div class="card-title">Manage System Admins
                                </div>
                            </div>
                            <div class="card-body">
                                        <?php
                                        $sql = "SELECT * FROM officer ORDER BY id DESC";
                                        $conn->query($sql);

                                        if($conn->rowCount() > 0){
                                            $result = $conn->fetchMultiple();   

                                        ?>
                                <table id="system-admin" class="table table-bordered table-striped">
                                    <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>Name</th>
                                        <th>Username</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    $i = 1;
                                    if($conn->rowCount()){
                                        foreach ($result as $officer){
                                            $officer_id = $officer->id;
                                            $name = $officer->name;
                                            $username = $officer->username;
                                            $officer_type = $officer->type;

                                            ?>
                                            <tr>
                                                <td><?php echo $i++; ?></td>
                                                <td><?php echo $name; ?></td>
                                                <td><?php echo $username; ?></td>
                                                
                                                <td>
                                                    <a href="javascript:void(0);" data-toggle="modal" data-target="#delete-system-admin<?php echo $officer_id;?>">
                                                        <i class="fa fa-trash" data-toggle="tooltip" title="Delete"></i>
                                                    </a>
                                                </td>
                                            </tr>
                                        
                                        <?php
                                    }
                                    }else{ 
                                        ?>
                                        <tr>
                                            <td colspan="4" class="text-center">No Data in table</td>
                                        </tr>
                                        <?php
                                    }
                                    ?>
                                    </tbody>

                                    <tfoot>
                                    <tr>
                                        <th>#</th>
                                        <th>Name</th>
                                        <th>Username</th>
                                        <th>Action</th>
                                    </tr>
                                    </tfoot>

                                </table>
                            </div>
                        </div>
                        <!-- END card -->
                    </div>
                    


                </div>
                </div>
            </div>
            <!-- END CONTAINER FLUID -->
        </div>
        <!-- END PAGE CONTENT -->


        <?php include('includes/foot.php'); ?>
    </div>
    <!-- END PAGE CONTENT WRAPPER -->
</div>





<!-- END QUICKVIEW-->

<?php include('includes/footer.php'); ?>
<?php
foreach ($result as $officer){
    $officer_id = $officer->id;
    $name = $officer->name;
    $username = $officer->username;
?>

        <!--        Delete Teacher Modal Start-->
    <div class="modal fade slide-up disable-scroll" id="delete-system-admin<?php echo $officer_id; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content-wrapper">
                <div class="modal-content text-center">
                    <div class="modal-header clearfix" style="display: block">
                        <button aria-label="" type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-icon">close</i>
                        </button>
                        <h5 style="margin-bottom: -6px"><span class="semi-bold">Delete Admin 😞</span></h5>
                </div>
                <div class="modal-body">
                    <p class="p-b-10 p-t-30"><span>Are You Sure You Want To Delete <br></span> <span style="color: #f00; text-transform: uppercase"><?php echo $name; ?></span></p>
                    <form action="" method="post">
                        <div class="form-group">
                            <input type="hidden" name="id" value="<?php echo $officer_id; ?>">
                        </div>

                        <div class="col-xl-12 m-t-50">
                            <button aria-label="" type="submit" name="delete_officer" id="submit" class="btn btn-danger btn-lg btn-animated from-left">
                                <span>Delete</span>
                                <span class="hidden-block">
													<i class="pg-icon">trash_alt</i>
												</span></button>
                        </div>
                    </form>


                </div>
                </div>
            </div>
        </div>
    </div>
    <!--        Delete Student Modal End-->

       

        <?php
    }

    //delete teacher script

if(isset($_POST['delete_officer'])){
    $officer_id = $_POST['id'];
    //sql
    $sql = "DELETE FROM officer WHERE id =:id";
    $conn->query($sql);
    $conn->bind(":id", $officer_id);

    try{
        $conn->execute();
        echo "<script>
$(function () { //ready
          toastr.options.progressBar = true, toastr.options.preventDuplicates = true,
          toastr.success('Conference Officer&#39;s Data Deleted Successfully');
      });
</script> <meta http-equiv='refresh' content='5; conference-officer'>";
    }catch (PDOException $err){
        $error = $err->getMessage();

        echo "<script>
$(function () { //ready
          toastr.options.progressBar = true, toastr.options.preventDuplicates = true,
          toastr.error('An Error Occured $error');
      });
</script>";
    }
}
?>


<script>
   $(document).ready(function() {
    $("#show_hide_password a").on('click', function(event) {
        event.preventDefault();
        if($('#show_hide_password input').attr("type") == "text"){
            $('#show_hide_password input').attr('type', 'password');
            $('#show_hide_password i').addClass( "fa-eye-slash" );
            $('#show_hide_password i').removeClass( "fa-eye" );
        }else if($('#show_hide_password input').attr("type") == "password"){
            $('#show_hide_password input').attr('type', 'text');
            $('#show_hide_password i').removeClass( "fa-eye-slash" );
            $('#show_hide_password i').addClass( "fa-eye" );
        }
    });
});
</script>
<script>
        $(function () {
            $("#system-admin").DataTable({
                "responsive": true, "lengthChange": false, "autoWidth": false,
                "buttons": ["copy", "csv", "pdf", "print"]
            }).buttons().container().appendTo('#system-admin_wrapper .col-md-6:eq(0)');
            $('#example2').DataTable({
                "paging": true,
                "lengthChange": false,
                "searching": true,
                "ordering": true,
                "info": true,
                "autoWidth": false,
                "responsive": true
            });
        });
    </script>


<script>
        $('#officer-add').parsley();
        $('#officer-add').on('submit', function(event){
            event.preventDefault();
            if ($('#officer-add').parsley().isValid()){
                $.ajax({
                    url: "<?php echo $base_url; ?>process-add-conference-officer.php",
                    method: "POST",
                    data: new FormData(this),
                    contentType: false,
                    processData: false,
                    beforeSend: function () {
                        $('#submit').attr('disabled', 'disabled');
                        $('#submit').val('Adding Details, Please Wait...');

                    },

                    success:function (data) {
                        $('#officer-add').parsley().reset();
                        $('#submit').attr('disabled', false);
                        $('#submit').val('Add Conference Officer');
                        $('#success-msg').html(data);
                    }
                })
            }

        })
    </script>


<!-- <script>
document.getElementById('username').addEventListener("keyup", function() {
  this.value = document.getElementById('adm_no').value;
});
</script> -->


<?php
}else{
    ?>
    
  <?php include('session.php'); ?>

    <?php

    }

    ?>



    

<?php
}}

?>