<?php include("cn.php");?>
<?php $title = "Users";?>
<!DOCTYPE html>
<html lang="en">

<?php include("head-tag.php");
$sql = mysqli_query($connect, "select count(*) as total from users where Type='user'");
$data = mysqli_fetch_assoc($sql);

?>
<body>

<div class="inner-wrapper">
<?php include("pre-loader.php");?>

<?php include("header.php");?>

<div class="page-wrapper">
<div class="container-fluid">
<div class="row">
    <div class="col-xl-12 col-lg-12 col-md-12">
        <div class="card shadow-sm ctm-border-radius">
                    <div class="card-body">
                        <h4 class="card-title mb-0 mt-2"><?php echo $data["total"]?> Users
                            
                        <?php
                        // 	if($_SESSION['username']=="mainadmin")
                        	{
                        	    
                        	    if ($data["total"]>=$ulimit)
                        	    echo '
                        	    <span id="message1">Your User limit has been reached. Please contact your Administrator to Increase limit.</span>
                        	    <script>
                        	    $("#yourbuttonid").attr("disabled", "disabled");
                        	    $("#yourbuttonid").hide();
                        	    </script>
                        	    ';
                        	    else
                        	    echo '
                        	<a id="yourbuttonid" href="javascript:void(0)" class="btn btn-theme ctm-border-radius text-white btn-sm float-right" data-toggle="modal" data-target="#add-user">
                        	<i class="fa fa-plus" aria-hidden="true"></i> Add User
                        	</a>
                        	';
                        	
                        	}
                        	 ?>
                        	
                        </h4>
                    </div>
                </div>
                
        <div class="ctm-border-radius shadow-sm card">
            <div class="card-body">
                <div class="table-responsive">
                    <table id="users" class="table table-striped table-bordered ">
						<thead>
						<tr>
						  <th class="text-center">Image</th>
						  <th class="text-center">Name</th>
						  <th class="text-center">User Name</th>
						  <th class="text-center">Password</th>
						  <th class="text-center">Email</th>
						  <th class="text-center">Address</th>
						  <th class="text-center">Phone</th>
						  <th class="text-center">Role</th>
						  <th class="text-center">Representative</th>
                          <th class="text-center">Action</th>
						</tr>
						</thead>
						<tbody>
										<?php
										$sql = mysqli_query($connect, "select *
										from users where Type='user'");
                                           
										while($data = mysqli_fetch_assoc($sql)){?>
											<tr>
											    
                                            <td class="text-center">
                                                <div style="width:50px;height:50px;">
                                                    <img class="img-responsive img-thumbnail" src="<?php echo  $data["Image"]?>">
                                                </div>
                                                
                                                
                                            </td>
                                            <td class="text-center"> <?php echo $data["FullName"]?> </td>
                                            <td class="text-center"> <?php echo $data["Username"]?> </td>
                                            <td class="text-center"><?php echo $data["Password"]?></td>
                                            <td class="text-center"> <?php echo $data["Email"]?></td>
                                            <td class="text-center"> <?php echo $data["Address"]?></td>
                                            <td class="text-center"> <?php echo $data["Phone"]?></td>
                                            <td class="text-center"> <?php echo $data["Role"]?></td>
                                            <td class="text-center"> <?php echo $data["Representative"]?></td>
                                            <td class="text-center">
   <a href="javascript:void(0)" class="btn btn-theme button-1 ctm-border-radius text-white btn-sm float-center" 
   data-toggle="modal" data-target="#edit-user<?php echo $data['Id']?>"><i class="fa fa-pencil" aria-hidden="true"></i></a>

                                            <div class="modal fade" id="edit-user<?php echo $data['Id']?>">
                                                <div class="modal-dialog modal-dialog-centered">
                                                    <div class="modal-content">
                                                        <div class="modal-body float-left text-left">
                                                            <form method = "post" action="ajax/edit-user.php" enctype='multipart/form-data'>
                                            				<input type="hidden" name="id" value="<?php echo $data['Id']?>">
                                                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                            <h4 class="modal-title mb-3">Edit User</h4>
                                                            <div class="row">
                                                                <div class="col-md-12 col-sm-12 col-xs-12">
                        											<div class="form-group">
                        												<input type="file" name="photo" id="photo" class="dropify" data-height="220"
                        												data-default-file='<?php echo $data['Image']?>'
                        												data-allowed-file-extensions='["jpg", "png", "jpeg"]'/>
                        											</div>
                        										</div>
                                                               
                                                                <div class="col-md-6 col-sm-12 col-xs-12">
                                                                <div class="form-group">
                                                                 <input type="text" class="form-control " placeholder="Name"  name="fname" value='<?php echo $data['FullName'] ?>' />
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6 col-sm-12 col-xs-12">
                                                                <div class="form-group">
                                                                    <input class="form-control" name="email" type="email" placeholder="Email" value='<?php echo $data['Email'] ?>' />
                                                                </div>
                                                            </div>
                                                           
                                                            <div class="col-md-6 col-sm-12 col-xs-12">
                                                                <div class="form-group">
                                                                <input type="text" class="form-control" placeholder="User Name" readonly name="username"value='<?php echo $data['Username'] ?>' />
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6 col-sm-12 col-xs-12">
                                                                <div class="form-group">
                                                                    <input type="text" class="form-control" placeholder="Password" name="password" value='<?php echo $data['Password'] ?>' />
                                                                </div>
                                                            </div>
                                                            
                                                            <div class="col-md-6 col-sm-12 col-xs-12">
                                                                <div class="form-group">
                                                                <input type="text" class="form-control" placeholder="Address" name="address" value='<?php echo $data['Address'] ?>'/>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6 col-sm-12 col-xs-12">
                                                                <div class="form-group">
                                                                    <input type="text" class="form-control" placeholder="Phone" name="phone" value='<?php echo $data['Phone'] ?>'/>
                                                                </div>
                                                            </div>
                                                            
                                                            <div class="col-md-12 col-sm-12 col-xs-12">
                                                                <div class="form-group">
                                                                    <input type="text" class="form-control" placeholder="Representative" name="representative" value='<?php echo $data['Representative'] ?>' />
                                                                </div>
                                                            </div>
                                                            
                                                            <div class="col-md-12 col-sm-12 col-xs-12">
                                                            <button type="button" class="btn btn-danger float-left ml-3 ctm-border-radius" data-dismiss="modal">Cancel</button>
                                                            <button type="submit" class="btn btn-theme  button-1 text-white ctm-border-radius float-left">Save</button>
                                                            </div>
                                                            </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                    </form>
                                                </div>
                                               </div>
                                             </div>
                                           </div>
                                            
                                            </td>
                                        </tr>
										<?php }?>
										
                        </tbody>
					</table>
                       
                </div>
            </div>
            
        </div>
    </div>
</div>


</div>
</div>
<div class="modal fade" id="add-user">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-body">
                <form method = "post" action="ajax/save-user.php" enctype='multipart/form-data'>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title mb-3">Add User</h4>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
						<div class="form-group">
							<input type="file" name="photo" id="photo" class="dropify" data-height="220"
							data-allowed-file-extensions='["jpg", "png", "jpeg"]'/>
						</div>
                    </div>
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                         <input type="text" class="form-control " placeholder="Name"  name="fname"  required/>
                        </div>
                    </div>
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <input class="form-control" name="email" type="email" placeholder="Email" />
                        </div>
                    </div>
                   
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                        <input type="text" class="form-control" placeholder="User Name" name="username" />
                        </div>
                    </div>
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Password" name="password"  />
                        </div>
                    </div>
                    
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                        <input type="text" class="form-control" placeholder="Address" name="address" />
                        </div>
                    </div>
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Phone" name="phone"  />
                        </div>
                    </div>
                    
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Representative" name="representative"  />
                        </div>
                    </div>

                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <select class="form-control custom-select" name="user_role" id="user_role" required>
                            <option value="" disabled selected >-- Select Role --</option>
                            <option value="hotel" >Hotel</option>
                            <option value="supervisor" >Supervisor</option>
                            </select>
                        </div>
                    </div>
                    </div>
                    

                <button type="button" class="btn btn-danger float-right ml-3 ctm-border-radius" data-dismiss="modal">Cancel</button>
                <button type="submit" class="btn btn-theme  button-1 text-white ctm-border-radius float-right">Save</button>
                                </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="sidebar-overlay" id="sidebar_overlay"></div>

</div>

<?php include("scripts.php");?>

</body>
<script>
$('#users').DataTable( {
            dom: 'B<clear>frtip',
            "bFilter": true,
            "bSort": true,
            "bPaginate": true,
            "order": [ 0, 'desc' ],
            "lengthMenu": [ [10, 50, 100, -1], [10, 50, 100, "All"] ],
            columnDefs: [
                {
                    targets: 1,
                    className: 'noVis'
                }
            ],
            buttons: [
                {
                    extend: 'copy',
                    title: 'Users Report',
                    exportOptions: {
                        columns: ':visible'
                    }
                    
                },
                {
                    extend: 'excel',
                    title: 'Users Report',
                    exportOptions: {
                        columns: ':visible'
                    }
                },
                {
                extend: 'print',
                orientation: 'landscape',
                title: '<h3 style="text-align:center">Users Report </h3>',
                pageSize: 'LEGAL',
                exportOptions: {
                    columns: ':visible'
                }
                
            },
                {
                    extend: 'pdf',
                    title: 'Users Report',
                    orientation: 'portrait',
                    pageSize: 'A4',
                    exportOptions: {
                        columns: ':visible'
                    }
                    
                },
                
                {
                extend: 'colvis',
                collectionLayout: 'fixed three-column',
                columns: ':not(.noVis)',
                postfixButtons: [ 'colvisRestore' ]
            }
            ],
            language: {
            buttons: {
                colvis: 'Select Fields'
                }
            },
           
        } );
    $(document).ready(function() {
        
    });
</script>
</html>