<?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();
	$("#genBackupStatusWrapper").hide();
	
	$("#generateBackup").click(function(){
	
		$("#genBackupStatusWrapper").show();
		$("#genBackMsg").html("<font color='red'>The Backup Is Being Created</font>");
		$("#genBackupStatus").html("<font color='red'><b>Do Not Close/Navigate Away From This Page Or Else Your Backup Will Not Complete</b></font>");
		
		$.ajax({
			type: 'POST', 
			url: "process.php",
			data: $('#frmGenBackup').serialize(), 
			success: function(data) {
				$("#genBackupStatus").html("<div class='genBackupMsg'><font color='green'><b>Backup Generated Successfully</b></font><br/><br/></div>");
				$("#genBackMsg").html("<font color='green'>The Backup Successful</font>");
			},
			error: function(){
            
			}
		});
	});

	
	$(".tabs ul li #lstGenBackupsLink").click(function(){
		$('#listFoundBackups').fadeOut('slow').load('views/listBackups.php').fadeIn("slow");
	});
	
	
	
		
});
</script>
	
	<h1 class="page-title">System Settings</h1>
	<div class="container_12 clearfix leading">
		<div class="grid_12">
			

			<div class="tabs leading">
				<ul class="clearfix">
					<li><a href="#">Backups</a></li>
					<li><a id="lstGenBackupsLink" href="#">List Backups</a></li>
					<!--<li><a href="#">Register A User</a></li>-->
				</ul>
				
				<section>
					<!-- Backups -->
					<section class="clearfix">
						<form id="frmGenBackup" name="frmGenBackup" class="form has-validation" method="POST" action="process.php">
							<div class="clearfix">
								<h4>Generate Database Backup</h4>
							</div>
							
							<div class="clearfix">

								<label for="form-delUsername" class="form-label">Create SQL Backup</label>

								<div class="form-inputReports">
									<a target="_blank" id="generateBackup" class="button" >Generate Backup</a>
								</div>

							</div>	
							
							<div class="clearfix" id="genBackupStatusWrapper">

								<label id="genBackMsg" for="form-delUsername" class="form-label"><font color="red">The Backup Is Being Created</font></label>

								<div class="form-inputReports" id="genBackupStatus">
									<font color="red"><b>Do Not Close/Navigate Away From This Page Or Else Your Backup Will Not Complete</b></font>
								</div>

							</div>	
							
							
							
							<div class="form-action clearfix">
								<input type="hidden" name="procGenerateBackup" value="1">
							</div>
						</form>
					</section>
					<!-- END Display Users -->
					
					<!-- List Backups -->
					<section id="listFoundBackups" class="clearfix">
						<div >
						<?php
							date_default_timezone_set('America/New_York');
							if ($handle = opendir('../views/backups/')) {
								while (false !== ($entry = readdir($handle))) {
									if ($entry != "." && $entry != "..") {
										$fname = "backups/$entry";
										if (file_exists($fname))
										{
											$d = date ("m/d/Y g:i:s", filectime($fname));
											echo "<a href='views/backups/$entry'>Click To Download Backup From $d: $entry</a>";
											echo "<hr/>";
										}
									}
								}
								closedir($handle);
							}
						?>
						</div>
					</section>
					<!-- END List Backups -->
					<!-- 
					<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 -->
					
		
					
					
				</section>
			</div>
			<!-- END TABS -->
			<br/>
			<br/>

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