<?php 

include('../dbconnect.php');
ob_start();
session_start();

if( !isset($_SESSION['user']) ) {
 header("Location: ../index.php");
 exit;
}
$ID = $_GET['ID'];

$sql = "SELECT * FROM `individualshared` WHERE id= '$ID'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$getname = $row['name'];
$getdescription = $row['description'];
$gettype = $row['type'];
$getusername = $row['username'];
$getpass = $row['password'];

$name = $_POST['name'];
$uname = $_POST['username'];
$description = $_POST['description'];
$type = $_POST['type'];
$password = $_POST['password'];


if(isset($_POST['savetools'])){
    $vvq = "SELECT * FROM individualshared WHERE name = '$name' AND description = '$description' AND id !='$ID'";
    $resultvv = mysqli_query($conn, $vvq);
    if (mysqli_num_rows($resultvv) > 0) {
  
      $alert = '<div class="alert alert-danger">Name and description exist </div>';
  
    }else{
        
        $updatesql ="UPDATE `individualshared` SET `name`='$name',`description`='$description',`username`='$uname',`password`='$password' WHERE id='$ID'";
      
        
        if (mysqli_query($conn, $updatesql)) {
            $alert = '<div class="alert alert-success">Employee Tools Information Successfully Save </div>';
            header('location: updatetools.php?ID='.$ID.'&alert='.$alert.'');
        } 


    }

}



?>
<!DOCTYPE html>
<html lang="en">

  <head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Super Admin | Dashboard</title>

    <!-- Bootstrap core CSS-->
    <link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom fonts for this template-->
    <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

    <!-- Page level plugin CSS-->
    <link href="../vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">

    <!-- Custom styles for this template-->
        <link href="../css/sb-admin.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <link rel="icon" href="../images/logo.jpg" type="image/gif" sizes="16x16">


  </head>

  <body id="page-top" onload=display_ct();>

    <?php include('uppernav.php')?>



      <!-- Sidebar -->
      
      <?php 
       $dashboard = "active";
      include('sidebar.php');
      ?>
      <div id="content-wrapper">

        <div class="container-fluid">

          <!-- Breadcrumbs-->
          <ol class="breadcrumb">
            <li class="breadcrumb-item">
              <a href="tools.php"> Employee Tools</a>
            </li>
            <li class="breadcrumb-item active">Update </li>
          </ol>
          <form method="post" enctype="multipart/form-data">  
                <div class="row p-3" >
                    <div class="col-sm-12 form-group required">
                        <?php echo $alert; echo $_GET['alert'];?>
                        <h4> Update Employee Tools </h4>
                    </div>

              
                        
                            <div class="col-sm-6 form-group required">
                                <label class="control-label">Name</label> <br>
                                <input type="text"  class="form-control" name="name"  id="indid" placeholder="Name" value="<?php echo $getname?>" required >
                            </div>
                            <div class="col-sm-6 form-group required">
                                <label class="control-label">Description</label> <br>
                                <input type="text"  class="form-control" name="description"  id="indid" placeholder="Description" value="<?php echo $getdescription?>" required>
                            </div>
                            <div class="col-sm-4 form-group required">
                                <label class="control-label">Type</label> <br>
                                <input type="text"  class="form-control" name="type"  id="indid" placeholder="Type" value="<?php echo $gettype?>" readonly>
                            </div>
                            <div class="col-sm-4 form-group required">
                                <label class="control-label">Username</label> <br>
                                <input type="text"  class="form-control" name="username"  id="indid" placeholder="Username" value="<?php echo $getusername?>" required>
                            </div>
                            <div class="col-sm-4 form-group required">
                                <label class="control-label">Password</label> <br>
                                <input type="text"  class="form-control" name="password"  id="indid" placeholder="Password" value="<?php echo $getpass?>" required>
                            </div>
                            <div class="col-sm-12 form-group">
          
                                <div class="row justify-content-end">
                                            
                                <button type="button" class="btn btn-success" data-toggle="modal" data-target="#updatetools"><i class="fa fa-check"></i>  Save </button> &nbsp
                        
                                <a href="tools.php" class="btn btn-danger" role="button" style="margin-right: 5px;"> <i class="fa fa-close"></i> Cancel </a>
                            </div>
                            <div class="modal fade" id="updatetools" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                    <div class="modal-dialog modal-dialog-centered" role="document">
                                        <div class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel">Update Employee Tools</h5>
                                            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                            </button>
                                        </div>
                                            <div class="modal-body">Are you sure you want to update employee tools?</div>
                                                <div class="modal-footer">
                                                <button type="submit" name="savetools" class="btn btn-success" name="createemp"  style="margin-right: 5px;" > <i class="fa fa-check"></i>  Yes </button>
                                                    <button class="btn btn-danger" type="button" data-dismiss="modal"><i class='fas fa-close'></i> No</button>
                                                                
                                                </div>
                                            </div>
                                    </div>
                                </div>

       
                    
                
                </div>
            </form>



          <!-- Icon Cards-->
      
        <!-- /.container-fluid -->

        <!-- Sticky Footer -->


      </div>
      <!-- /.content-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fas fa-angle-up"></i>
    </a>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
            <a class="btn btn-primary" href="login.html">Logout</a>
          </div>
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="../vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Page level plugin JavaScript-->
    <script src="../vendor/chart.js/Chart.min.js"></script>
    <script src="../vendor/datatables/jquery.dataTables.js"></script>
    <script src="../vendor/datatables/dataTables.bootstrap4.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="../js/sb-admin.min.js"></script>

    <!-- Demo scripts for this page-->
    <script src="../js/demo/datatables-demo.js"></script>
    <script src="../js/demo/chart-area-demo.js"></script>

          <script language="javascript" type="text/javascript">
            $(document).ready(function(){
            $("form").on("submit", function(){
                $("#pageloader").fadeIn();
            });//submit

             $('#preloader').fadeOut();
            });//document ready



        </script>
</body>

</html>
