<?php 
include 'dheader.php';
$success = "";
$danger = "";
if (isset($_POST['submitf'])) {
 	# code...
 	//var_dump($_POST);
 	extract($_POST, EXTR_OVERWRITE);
 	$countQuery = $db->query("SELECT count(*) totalCount FROM users WHERE name = '$username'");
 	$rowcount = $countQuery->fetchArray();
 	$totalCount = $rowcount['totalCount'];
 	if ($totalCount < 1) {
 		$sql = $db->query("INSERT INTO users (name, pass) VALUES ('$username', '$password')");

 		$GetID = $db->query("SELECT * FROM users ORDER BY id DESC LIMIT 1");
 		$ID = $GetID->fetchArray();

 		$permissions = implode(',', $permissions_actions);
 		$update = $db->query("UPDATE users SET rights = '$permissions' WHERE id = '".$ID['id']."'");

 		$success = "<strong>Success!</strong> User added successfully."; 
 	}else{
 		$danger = "<strong>Warning!</strong> This User name already exist.";
 	} 
 }  
?>
	<div class="modal fade hidden-print" id="myModal" tabindex="-1" role="dialog" aria-hidden="true"></div>
	<div class="wrapper ">
		<?php include 'leftbar.php'; ?>
		<!-- left-bar -->
		<?php include 'topbar.php'; ?>
			<!-- top-bar -->
			<div class="main-content">

<div class="row" id="form">
	<div class="spinner" id="grid-loader" style="display:none">
	  <div class="rect1"></div>
	  <div class="rect2"></div>
	  <div class="rect3"></div>
	</div>
	
	<div class="col-md-12">
			
		
			<form action="" id="customer_form" class="form-horizontal" enctype="multipart/form-data" method="post" accept-charset="utf-8" novalidate="novalidate">

			<div class="panel panel-piluku">
				<div class="panel-heading">
		                <h3 class="panel-title">
		                    <i class="ion-edit"></i> 
		                    User Information							<small>(Fields in red are required)</small>
		                </h3>
		        </div>

			<div class="panel-body">
					<?php
                    if (isset($_POST['submitf'])) {
                    ?>
                    <div class="alert alert-<?php echo ($success) ? "success" : "danger"; ?>"> 
                            <?php echo ($success) ? $success : $danger; ?>                          
                    </div>
                 <?php } ?>

				<div class="row">
	<div class="col-md-12">
		<div class="form-group">
			<label for="first_name" class="required col-sm-3 col-md-3 col-lg-2 control-label ">Username :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
				<input type="text" name="username" list="listCustomers"  value="" class="form-control" id="username">
				<datalist id="listCustomers">
						<?php
							$listItems = $db->query("SELECT * FROM users");
							while($listrow = $listItems->fetchArray()){
						?>
							<option value="<?php echo $listrow['name']; ?>">
						<?php } ?>
				</datalist>
			</div>
		</div>

		<div class="form-group">
			<label for="password" class="col-sm-3 col-md-3 col-lg-2 control-label required">Password :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
			<input type="text" name="password" value="" class="form-control" id="password">
			</div>
		</div>
		<div class="panel-body form-group">
					
						<ul id="permission_list" class="list-unstyled">
												<li>	
						
<input type="checkbox" name="permissions_actions[]" value="customertab" id="permissionssales" class="module_checkboxes ">
<label for="permissionssales"><span></span></label>						<span class="text-success">Customer:</span>
						<span class="text-warning">Add, Update, Delete, Show Ledger, Make Payment</span>
							<ul class="list-unstyled list-permission-actions">
															<li>
								<input type="checkbox" name="permissions_actions[]" value="customeradd" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|add">
<label for="permissions_actionscustomers|add"><span></span></label>								<span class="text-info">Add</span>
								</li>
								<li>
								<input type="checkbox" name="permissions_actions[]" value="customeredit" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|edit">
<label for="permissions_actionscustomers|edit"><span></span></label>								<span class="text-info">Edit</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="customerdelete" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|delete">
<label for="permissions_actionscustomers|delete"><span></span></label>								<span class="text-info">Delete</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="customershowledger" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|showledger">
<label for="permissions_actionscustomers|showledger"><span></span></label>								<span class="text-info">Show Ledger</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="customermakepayment" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|makepayment">
<label for="permissions_actionscustomers|makepayment"><span></span></label>								<span class="text-info">Make Payment</span>
								</li>				
							</ul>
						</li>
												

					<input type="checkbox" name="permissions_actions[]" value="suppliertab" id="permissionssales" class="module_checkboxes ">
<label for="permissionssales"><span></span></label>						<span class="text-success">Supplier:</span>
						<span class="text-warning">Add, Update, Delete, Show Ledger, Make Payment</span>
							<ul class="list-unstyled list-permission-actions">
															<li>
								<input type="checkbox" name="permissions_actions[]" value="supplieradd" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|add">
<label for="permissions_actionscustomers|add"><span></span></label>								<span class="text-info">Add</span>
								</li>
								<li>
								<input type="checkbox" name="permissions_actions[]" value="supplieredit" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|edit">
<label for="permissions_actionscustomers|edit"><span></span></label>								<span class="text-info">Edit</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="supplierdelete" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|delete">
<label for="permissions_actionscustomers|delete"><span></span></label>								<span class="text-info">Delete</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="suppliershowledger" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|showledger">
<label for="permissions_actionscustomers|showledger"><span></span></label>								<span class="text-info">Show Ledger</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="suppliermakepayment" data-module-checkbox-id="permissionscustomers" class="module_action_checkboxes" id="permissions_actionscustomers|makepayment">
<label for="permissions_actionscustomers|makepayment"><span></span></label>								<span class="text-info">Make Payment</span>
								</li>				
							</ul>
						</li


					<li>	
						
<input type="checkbox" name="permissions_actions[]" value="itemstab" id="permissionssales" class="module_checkboxes ">
<label for="permissionssales"><span></span></label>						<span class="text-success">Items:</span>
						<span class="text-warning">Add, Edit<،</span>
							<ul class="list-unstyled list-permission-actions">
								<li>
								<input type="checkbox" name="permissions_actions[]" value="itemsadd" data-module-checkbox-id="permissionsitems" class="module_action_checkboxes" id="permissions_actionsitems|add">
<label for="permissions_actionsitems|add"><span></span></label>								<span class="text-info">Add</span>
								</li>

								<li>
								<input type="checkbox" name="permissions_actions[]" value="itemsedit" data-module-checkbox-id="permissionsitems" class="module_action_checkboxes" id="permissions_actionsitems|edit">
<label for="permissions_actionsitems|edit"><span></span></label>								<span class="text-info">Edit</span>
								</li>																		
													
						</ul>

						</li>
												<?php /*
												<li>	
						
<input type="checkbox" name="permissions_actions[]" value="kitstab" id="permissionssales" class="module_checkboxes ">
<label for="permissionssales"><span></span></label>							<span class="text-success">Item Kits:</span>
						<span class="text-warning">Add, Edit</span>
							<ul class="list-unstyled list-permission-actions">
															<li>
								<input type="checkbox" name="permissions_actions[]" value="item_kitsadd" data-module-checkbox-id="permissionsitem_kits" class="module_action_checkboxes" id="permissions_actionsitem_kits|add">
<label for="permissions_actionsitem_kits|add"><span></span></label>								<span class="text-info">Add</span>
								</li>

								<li>
								<input type="checkbox" name="permissions_actions[]" value="item_kitsedit" data-module-checkbox-id="permissionsitem_kits" class="module_action_checkboxes" id="permissions_actionsitem_kits|edit">
<label for="permissions_actionsitem_kits|edit"><span></span></label>								<span class="text-info">Edit</span>
								</li>
											
														</ul>
						</li> */ ?>
												<li>	
						<input type="checkbox" name="permissions_actions[]" value="reportstab" id="permissionsreports" class="module_checkboxes ">
<label for="permissionsreports"><span></span></label>						<span class="text-success">Reports:</span>
						<span class="text-warning">View and generate reports</span>
							<ul class="list-unstyled list-permission-actions">
							
							<li>
								<input type="checkbox" name="permissions_actions[]" value="reportscashinhand" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|cashinhand">
<label for="permissions_actionsreports|cashinhand"><span></span></label>								<span class="text-info">Closeout</span>
								</li>

							<li>
								<input type="checkbox" name="permissions_actions[]" value="reportscloseout" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|closeout">
<label for="permissions_actionsreports|closeout"><span></span></label>								<span class="text-info">Closeout</span>
								</li>
							<li>
								<input type="checkbox" name="permissions_actions[]" value="reportssales" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|sales">
<label for="permissions_actionsreports|sales"><span></span></label>								<span class="text-info">Sales</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportsstock" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|stock">
<label for="permissions_actionsreports|stock"><span></span></label>								<span class="text-info">Stock</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportscustomers" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|customers">
<label for="permissions_actionsreports|customers"><span></span></label>								<span class="text-info">Customer Report</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportssupplier" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|supplier">
<label for="permissions_actionsreports|supplier"><span></span></label>								<span class="text-info">Supplier Report</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportsemployee" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|employee">
<label for="permissions_actionsreports|employee"><span></span></label>								<span class="text-info">Employee</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportsexpenses" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|expenses">
<label for="permissions_actionsreports|expenses"><span></span></label>								<span class="text-info">Expenses</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportsotheraccount" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|otheraccount">
<label for="permissions_actionsreports|otheraccount"><span></span></label>								<span class="text-info">Other Accounts</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportsitems" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|items">
<label for="permissions_actionsreports|items"><span></span></label>								<span class="text-info">Item</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportsitemkits" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|itemkits">
<label for="permissions_actionsreports|itemkits"><span></span></label>								<span class="text-info">Item Kits</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportspayments" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|payments">
<label for="permissions_actionsreports|payments"><span></span></label>								<span class="text-info">اPayment Report</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportsbankreport" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|bankreport">
<label for="permissions_actionsreports|bankreport"><span></span></label>								<span class="text-info">Banks Report</span>
								</li>
															<li>
								<input type="checkbox" name="permissions_actions[]" value="reportsprofitloss" data-module-checkbox-id="permissionsreports" class="module_action_checkboxes" id="permissions_actionsreports|profitloss">
<label for="permissions_actionsreports|profitloss"><span></span></label>								<span class="text-info">Profit & Lose Report</span>
								</li>
													
							</ul>
						</li>
												
												<li>	
						<input type="checkbox" name="permissions_actions[]" value="salestab" id="permissionssales" class="module_checkboxes ">
<label for="permissionssales"><span></span></label>						<span class="text-success">Sales Area:</span>
						
						</li>

						<li>	
						<input type="checkbox" name="permissions_actions[]" value="purchasetab" id="permissionssales" class="module_checkboxes ">
<label for="permissionssales"><span></span></label>						<span class="text-success">purchase Area:</span>
						
						</li>
												<li>	
						<input type="checkbox" name="permissions_actions[]" value="expensestab" id="permissionsexpenses" class="module_checkboxes ">
<label for="permissionsexpenses"><span></span></label>						<span class="text-success">Expenses:</span>
						
						</li>

						<li>	
						<input type="checkbox" name="permissions_actions[]" value="otheraccounttab" id="permissionsexpenses" class="module_checkboxes ">
<label for="permissionsexpenses"><span></span></label>							<span class="text-success">Other Account:</span>
						
						</li>
						<li>	
						<input type="checkbox" name="permissions_actions[]" value="storetab" id="permissionsexpenses" class="module_checkboxes ">
<label for="permissionsexpenses"><span></span></label>							<span class="text-success">Store Config:</span>
						
						</li>

						<li>	
						<input type="checkbox" name="permissions_actions[]" value="usertab" id="permissionsexpenses" class="module_checkboxes ">
<label for="permissionsexpenses"><span></span></label>							<span class="text-success">User:</span>
						
						</li>
												</ul>
					
					</div>



		


 
	</div><!-- /col-md-12 -->
</div><!-- /row -->				
							

						<div class="form-actions pull-right">
														
							<input type="submit" name="submitf" value="Submit" id="submitf" class=" submit_button btn btn-primary">
						</div>
					</div>
				</div>
										</form>
			</div>
		</div><!-- /row -->


	

			
<?php include 'dfooter.php'; ?>