<?php
	include("../utilities/UtilitiesManagers.php");
	include("../utilities/UtilitiesReporting.php");
	include("../utilities/UtilitiesClients.php");
	include("../utilities/UtilitiesEncryption.php");
	include("../utilities/UtilitiesSystem.php");
	include("../utilities/UtilitiesPDF.php");
	include("../utilities/UtilitiesAdmin.php");
	include("../include/session.php");
	global $database;
	
	date_default_timezone_set('America/New_York');

	if($session->isAdmin())
	{
?>
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script> 
<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="js/jquery.autogrowtextarea.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number]', '.form').iTextClear();
	
	$("#form-children").autoGrow();
	$("#form-noteshistory").autoGrow();
	$("#form-ChecksIssued").autoGrow();
	
	
		$('#disaplyUsers').dataTable({
			"sPaginationType": "full_numbers"
		});
	var data = "<?php echo $admin->getUsernames();?>".split(" ");
	$("#form-Username").autocomplete(data);
	$("#form-delUsername").autocomplete(data);
		
});
</script>
	
	<h1 class="page-title">User Administration</h1>
	<div class="container_12 clearfix leading">
		<div class="grid_12">
			

			<div class="tabs leading">
				<ul class="clearfix">
					<li><a href="#">Users</a></li>
					<li><a href="#">Register A User</a></li>
					<li><a href="#">Delete A User</a></li>
					<li><a href="#">Update User Levels</a></li>
				</ul>
				<section>
					<!-- Display Users -->
					<section class="clearfix">
						<table class="display" id="disaplyUsers"> 
                                <thead> 
                                    <tr> 
                                        <th>Username</th> 
                                        <th>Level</th> 
                                        <th>Email</th> 
                                        <th>Last Active</th> 
                                    </tr> 
                                </thead> 
                                <tbody> 
									<?php echo $admin->showAllUsers(); ?> 
                                    
                                </tbody> 
                            </table> 
					</section>
					<!-- END Display Users -->
					
					<!-- Register A User -->
					<section class="clearfix">
						<form class="form has-validation" method="POST" action="process.php">
							<div class="clearfix">
								<h4>Register A User</h4>
							</div>
							<div class="clearfix">
								<label for="form-newName" class="form-label">Name<em>*</em></label>
								<div class="form-input"><input type="text" id="form-newName" name="name" value="<?php echo $form->value("name"); ?>" placeholder="Enter Name" /></div>
								<?php echo $form->error("name"); ?>
							</div>	
							<div class="clearfix">
								<label for="form-newUser" class="form-label">Username<em>*</em></label>
								<div class="form-input"><input type="text" id="form-newUser" name="user" value="<?php echo $form->value("user"); ?>" placeholder="Enter Username" /></div>
								<?php echo $form->error("user"); ?>
							</div>	
							<div class="clearfix">
								<label for="form-newPass" class="form-label">Password<em>*</em></label>
								<div class="form-input"><input type="text" id="form-newPass" name="pass" value="<?php echo $form->value("pass"); ?>" placeholder="Enter Password" /></div>
								<?php echo $form->error("pass"); ?>
							</div>	
							<div class="clearfix">
								<label for="form-newEmail" class="form-label">Email<em>*</em></label>
								<div class="form-input"><input type="text" id="form-newEmail" name="email" value="<?php echo $form->value("email"); ?>" placeholder="Enter Email Address" /></div>
								<?php echo $form->error("email"); ?>
							</div>	
							
							<div class="form-action clearfix">
								<input type="hidden" name="subjoin" value="1">
								<input type="hidden" name="username" value="<?php echo $session->username; ?>">
								<button class="button" type="submit">OK</button>
							</div>
						</form>
					
					
					</section>
					<!-- END Register A User -->
					
					<!-- Delete A User -->
					<section class="clearfix">
						<form class="form has-validation" method="POST" action="process.php">
							<div class="clearfix">
								<h4>Delete User</h4>
							</div>
							<div class="clearfix">

								<label for="form-delUsername" class="form-label">Username<em>*</em></label>

								<div class="form-input"><input type="text" id="form-delUsername" name="delUsername" placeholder="Enter Username" /></div>

							</div>	
							<div class="form-action clearfix">
								<input type="hidden" name="procDeleteUser" value="1">
								<input type="hidden" name="username" value="<?php echo $session->username; ?>">
								<button class="button" type="submit">OK</button>
							</div>
						</form>
					</section>
					<!-- END Delete A User -->
					
					<!-- Update User Level -->
					<section class="clearfix">
						<form class="form has-validation" method="POST" action="process.php">
							<div class="clearfix">
								<h4>Update User Level</h4>
							</div>
							<div class="clearfix">
								<label for="form-UserLevel" class="form-label">User Level</label>
								<div class="form-input">
									<select id="form-UserLevel" name="cUserLevel">
										<option value="0">Select User Level</option>
										<option value="1">User</option>
										<option value="9">Admin</option>
									</select>
								</div>
							</div>
							
							<div class="clearfix">

								<label for="form-Username" class="form-label">Username<em>*</em></label>

								<div class="form-input"><input type="text" id="form-Username" name="cUsername" placeholder="Enter Username" /></div>

							</div>	
							<div class="form-action clearfix">
								<input type="hidden" name="procUpdateUserLevel" value="1">
								<input type="hidden" name="username" value="<?php echo $session->username; ?>">
								<button class="button" type="submit">OK</button>
							</div>
						</form>
					</section>
					<!-- Update User Level -->
				</section>
			</div>
			<!-- END TABS -->
			<br/>
			<br/>

			
		</div>
	</div>
	<?php
	}
	else
	{
		header("Location: index.php#dashboard.php");
	}
	?>