<?php
    session_start();
    include("../connection/Functions.php");
	$operation = new Functions();
    if(!isset($_SESSION['user']) || empty($_SESSION['user'])){
        header("location:login.php");
        die();
    }

    $user_id = $_SESSION['user'];
    $user = $operation->retrieveSingle("SELECT *FROM users WHERE user_id = '$user_id'");
    $users = $operation->retrieveMany("SELECT *FROM users");
?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<title>BlessedHandz - Home of Creativity</title>
	<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport' />
	<link rel="stylesheet" href="assets/css/bootstrap.min.css">
	<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i">
	<link rel="stylesheet" href="assets/css/ready.css">
	<link rel="stylesheet" href="assets/css/demo.css">
        <!-- Datatable CSS -->
<link href='//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css' rel='stylesheet' type='text/css'>

</head>
<body>
	<div class="wrapper">
		<div class="main-header">
			<div class="logo-header">
				<a href="index.php" class="logo text-danger" >
					BlessedHandz
				</a>
				<button class="navbar-toggler sidenav-toggler ml-auto" type="button" data-toggle="collapse" data-target="collapse" aria-controls="sidebar" aria-expanded="false" aria-label="Toggle navigation">
					<span class="navbar-toggler-icon"></span>
				</button>
				<button class="topbar-toggler more"><i class="la la-ellipsis-v"></i></button>
			</div>
			<nav class="navbar navbar-header navbar-expand-lg">
				<div class="container-fluid">
					
					
					<ul class="navbar-nav topbar-nav ml-md-auto align-items-center">
				
						
						<li class="nav-item dropdown">
							<a class="dropdown-toggle profile-pic" data-toggle="dropdown" href="#" aria-expanded="false">
                                
                                <?php
                                if($user['img_url'] != ''){
                                    echo '<img height="50px" alt="user-img" width="50" class="img-circle" src="../images/users/'.$user['img_url'].'"/>';
                                }else{
                                    echo '<img height="50px" alt="user-img" width="50" class="img-circle" src="../images/users/no_profile.jpeg"/>';
                                }
                            ?>
                               
                                <span ><?=$user['fullname']?></span> </a>
							<ul class="dropdown-menu dropdown-user">
								<li>
									<div class="user-box">
										<div class="u-img">
                                            <?php
                                                if($user['img_url'] != ''){
                                                    echo '<img height="100px" src="../images/users/'.$user['img_url'].'"/>';
                                                }else{
                                                    echo '<img height="100px" src="../images/users/no_profile.jpeg"/>';
                                                }
                                            ?>
                                        </div>
										<div class="u-text">
											<h4><?=$user['fullname']?></h4>
											<p class="text-muted"><?=$user['email']?></p><a data-toggle='modal' data-target='#modalUser<?=$user_id?>' href="#" class="btn btn-rounded btn-danger btn-sm">View Profile</a></div>
										</div>
									</li>
									
									<div class="dropdown-divider"></div>
									<a class="dropdown-item" href="logout.php"><i class="fa fa-power-off"></i> Logout</a>
                                
								</ul>
								<!-- /.dropdown-user -->
                        </li></ul>
					</div>
				</nav>
			</div>
			<div class="sidebar">
				<div class="scrollbar-inner sidebar-wrapper">
					<div class="user">
						<div class="photo">
                            <?php
                                if($user['img_url'] != ''){
                                    echo '<img height="128px" src="../images/users/'.$user['img_url'].'"/>';
                                }else{
                                    echo '<img height="128px" src="../images/users/no_profile.jpeg"/>';
                                }
                            ?>
							
						</div>
						<div class="info">
							<a class="" data-toggle="collapse" href="#collapseExample" aria-expanded="true">
								<span>
									<?=$user['fullname']?>
									<span class="user-level">Admin</span>
									<span class="caret"></span>
								</span>
							</a>
							<div class="clearfix"></div>

							<div class="collapse in" id="collapseExample" aria-expanded="true" style="">
								<ul class="nav">
									<li>
										<a data-toggle='modal' data-target='#modalUser<?=$user_id?>' href="#">
											<span class="link-collapse">My Profile</span>
										</a>
									</li>
									
									
								</ul>
							</div>
						</div>
					</div>
					<ul class="nav">
						<li class="nav-item ">
							<a href="index.php">
								<i class="la la-dashboard"></i>
								<p>Dashboard</p>
							</a>
						</li>
                        
                        <li class="nav-item active">
							<a href="users.php">
								<i class="la la-users"></i>
								<p>Users</p>
								<span class="badge badge-count"><?php echo $operation->countAll("SELECT *FROM users"); ?></span>
							</a>
						</li>
                       <li class="nav-item">
							<a href="team.php">
								<i class="la la-user"></i>
								<p>Our Team</p>
								<span class="badge badge-count"><?php echo $operation->countAll("SELECT *FROM team"); ?></span>
							</a>
						</li>
                       
						<li class="nav-item">
							<a href="landing_page.php">
								<i class="la la-bookmark"></i>
								<p>Landing Page</p>
								<span class="badge badge-count"><?php echo $operation->countAll("SELECT *FROM corousel"); ?></span>
							</a>
						</li>
                        
                        <li class="nav-item">
							<a href="adverts.php">
								<i class="la la-delicious"></i>
								<p>Adverts</p>
								<span class="badge badge-count"><?php echo $operation->countAll("SELECT *FROM adverts"); ?></span>
							</a>
						</li>
                        
						<li class="nav-item">
							<a href="company_profiles.php">
								<i class="la la-book"></i>
								<p>Company Profiles</p>
								<span class="badge badge-count"><?php echo $operation->countAll("SELECT *FROM profiles"); ?></span>
							</a>
						</li>
                     
					</ul>
				</div>
			</div>
			<div class="main-panel">
				<div class="content">
					<div class="container-fluid">
						<h4 class="page-title text-center">Users</h4>
						<div class="row">
							<div class="col-12">
                                <a class="btn btn-danger text-light pull-right mb-2" data-toggle="modal" data-target="#exampleModal">Add</a>
                             
                                <!-- Table -->
                                <table id='empTable' class='table   '>

                                  <thead>
                                    <tr>
                                      <th>Fullname</th>
                                      <th>Email</th>
                                      <th>Phone</th>
                                      <th></th>
                                      <th></th>
                                    </tr>
                                  </thead>
                                    <tbody>
                                        <?php
                                            foreach($users as $row){
                                                if($row['user_id'] != $user_id){
                                                echo "<tr>
                                                        <td>".$row['fullname']."</td>
                                                        <td>".$row['email']."</td>
                                                        <td>".$row['phone']."</td>
                                                        <td><a data-toggle='modal' data-target='#modalUser".$row['user_id']."' class='btn btn-secondary' href='#'>Edit</a></td>
                                                        <td><a data-toggle='modal' data-target='#modalDelete".$row['user_id']."' class='btn btn-danger' href='#'>Delete</a></td>
                                                    </tr>";
                                                ?>
                                                    <!-- Modal Edit-->
                                                    <div class="modal fade" id="modalUser<?=$row['user_id']?>" 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">Edit User</h5>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                              <span aria-hidden="true">&times;</span>
                                                            </button>
                                                          </div>
                                                            <form action="" method="post" id="editUserForm<?=$row['user_id']?>">
                                                                <input type="hidden" id="eUid" name="eUid" value="<?=$row['user_id']?>" />
                                                              <div class="modal-body">
                                                                <div id="userEditResponse<?=$row['user_id']?>"></div>
                                                                <div class="form-group">
                                                                    <label for="email">Fullname</label>
                                                                    <input type="text" required class="form-control" name="efullname" id="efullname" placeholder="Enter Fullname" value="<?=$row['fullname']?>">
                                                                </div>
                                                                <div class="form-group">
                                                                    <label for="email">Email Address</label>
                                                                    <input type="eemail" required class="form-control" name="eemail" id="eemail" placeholder="Enter Email" value="<?=$row['email']?>" />
                                                                </div>
                                                                <div class="form-group">
                                                                    <label for="email">Phone Number</label>
                                                                    <input type="tel" required class="form-control" name="ephone" id="ephone" placeholder="Enter Phone Number" value="<?=$row['phone']?>" />
                                                                </div>
                                                                <div class="form-group">
                                                                    <label for="password">Password</label>
                                                                    <input type="password" class="form-control" id="epassword" name="epassword" placeholder="Password">
                                                                </div>
                                                              </div>
                                                              <div class="modal-footer">
                                                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                                <button type="submit" id="editUserBtn<?=$row['user_id']?>" onclick="editUser('<?=$row['user_id']?>')" class="btn btn-danger">Save changes</button>
                                                              </div>
                                                        </form>
                                                        </div>
                                                      </div>
                                                    </div>
                                                    
                                                    <!-- Modal Delete-->
                                                    <div class="modal fade" id="modalDelete<?=$row['user_id']?>" 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">Delete User</h5>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                              <span aria-hidden="true">&times;</span>
                                                            </button>
                                                          </div>
                                                            <p class="text-center">Are you sure to delete?</p>
                                                                <div id="userDelResponse<?=$row['user_id']?>"></div>
                                                          <div class="modal-footer">
                                                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                            <button type="button" id="delBtn<?=$row['user_id']?>" onclick="deleteUser('<?=$row['user_id']?>')" class="btn btn-danger">Save changes</button>
                                                          </div>
                                                        </div>
                                                      </div>
                                                    </div>
                                                <?php
                                                }
                                            }
                                        ?>
                                    </tbody>
                                </table>
							</div>
							
						</div>
				</div>
				</div>

			</div>
		</div>



<!-- Modal -->
<div class="modal fade" id="exampleModal" 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">Add User</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
        <form action="" method="post" id="addUserForm">
          <div class="modal-body">
            <div id="userAddResponse"></div>
            <div class="form-group">
                <label for="email">Fullname</label>
                <input type="text" required class="form-control" name="fullname" id="fullname" placeholder="Enter Fullname">
            </div>
            <div class="form-group">
                <label for="email">Email Address</label>
                <input type="email" required class="form-control" name="email" id="email" placeholder="Enter Email">
            </div>
            <div class="form-group">
                <label for="email">Phone Number</label>
                <input type="tel" required class="form-control" name="phone" id="phone" placeholder="Enter Phone Number">
            </div>
            <div class="form-group">
                <label for="password">Password</label>
                <input required type="password" class="form-control" id="password" name="password" placeholder="Password">
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="submit" id="addUserBtn" class="btn btn-danger">Save changes</button>
          </div>
    </form>
    </div>
  </div>
</div>
    
<!--edit my profile-->
<div class="modal fade" id="modalUser<?=$user_id?>" 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">Edit My Profile</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
            <form action="" method="post" id="editUserForm<?=$user_id?>">
                <input type="hidden" id="eUid" name="eUid" value="<?=$user_id?>" />
              <div class="modal-body">
                <div id="userEditResponse<?=$user_id?>"></div>
                <div class="form-group">
                    <label for="email">Fullname</label>
                    <input type="text" required class="form-control" name="efullname" id="efullname" placeholder="Enter Fullname" value="<?=$user['fullname']?>">
                </div>
                <div class="form-group">
                    <label for="email">Email Address</label>
                    <input type="eemail" required class="form-control" name="eemail" id="eemail" placeholder="Enter Email" value="<?=$user['email']?>" />
                </div>
                <div class="form-group">
                    <label for="email">Phone Number</label>
                    <input type="tel" required class="form-control" name="ephone" id="ephone" placeholder="Enter Phone Number" value="<?=$user['phone']?>" />
                </div>
                <div class="form-group">
                    <label for="password">Password</label>
                    <input type="password" class="form-control" id="epassword" name="epassword" placeholder="Password">
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" id="editUserBtn<?=$user['user_id']?>" onclick="editUser('<?=$user['user_id']?>')" class="btn btn-danger">Save changes</button>
              </div>
        </form>
        </div>
      </div>
    </div>

    
    
</body>
<script src="assets/js/core/jquery.3.2.1.min.js"></script>

<!-- jQuery Library -->
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>-->

<!-- Datatable JS -->
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

<script src="assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>

<script src="assets/js/core/popper.min.js"></script>
<script src="assets/js/core/bootstrap.min.js"></script>
<script src="assets/js/plugin/chartist/chartist.min.js"></script>
<script src="assets/js/plugin/chartist/plugin/chartist-plugin-tooltip.min.js"></script>
<!--<script src="assets/js/plugin/bootstrap-notify/bootstrap-notify.min.js"></script>-->
<script src="assets/js/plugin/bootstrap-toggle/bootstrap-toggle.min.js"></script>
<script src="assets/js/plugin/jquery-mapael/jquery.mapael.min.js"></script>
<script src="assets/js/plugin/jquery-mapael/maps/world_countries.min.js"></script>
<script src="assets/js/plugin/chart-circle/circles.min.js"></script>
<script src="assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
<script src="assets/js/ready.min.js"></script>
<script src="assets/js/js.js"></script>
<!--<script src="assets/js/demo.js"></script>-->
<script type="text/javascript">

     $(document).ready(function(){
        var table = $('#empTable').DataTable({
          columnDefs: [
            {bSortable: false, targets: [3,4]} 
          ],
             bFilter:false    

        });
    });
</script>
    
</html>