<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard</title>

    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/bootstrap.css">
	
	<link rel="stylesheet" href="assets/vendors/toastify/toastify.css">
	<link href="https://unpkg.com/filepond/dist/filepond.css" rel="stylesheet">
<link rel="stylesheet" href="assets/vendors/toastify/toastify.css">

    <link rel="stylesheet" href="assets/vendors/perfect-scrollbar/perfect-scrollbar.css">
    <link rel="stylesheet" href="assets/vendors/bootstrap-icons/bootstrap-icons.css">
    <link rel="stylesheet" href="assets/css/app.css">
    <link rel="shortcut icon" href="assets/images/favicon.svg" type="image/x-icon">
</head>

<!--summernote library------>
<link rel="stylesheet" href="assets/vendors/summernote/summernote-lite.min.css">
<script src="assets/vendors/jquery/jquery.min.js"></script>



<!--summer note library--->

<body>

        
		<?php include_once("assets/resources/side-includer.php"); ?>


			<?php include_once("assets/resources/top_navigator.php"); ?>
			<!-- body content -->
            <div id="main-content">




                <div class="page-heading">
                    <div class="page-title">
                        <div class="row">
                            <div class="col-12 col-md-6 order-md-1 order-last">
                                <h3>Add User Page</h3>
                                <p class="text-subtitle text-muted">Navbar will appear in top of the page.</p>
                            </div>
                            <div class="col-12 col-md-6 order-md-2 order-first">
                                <nav aria-label="breadcrumb" class="breadcrumb-header float-start float-lg-end">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item"><a href="index.html">Dashboard</a></li>
                                        <li class="breadcrumb-item active" aria-current="page">Layout Vertical Navbar
                                        </li>
                                    </ol>
                                </nav>
                            </div>
                        </div>
                    </div>
								
					<section id="basic-horizontal-layouts">
                    <div class="row match-height">
                        <div class="col-md-12 col-12">
                            <div class="card">
                                <div class="card-header">
								<?php
							if(isset($_GET['amnsfrk'])) {
							
							$admtbs_frgnky = $view->decrypt($_GET['amnsfrk']);
							?>
							 <h4 class="card-title">Edit / Update Information</h4>	
							<?php
						if(isset($_POST['update_admnuser']) && $_POST['update_admnuser'] == "Update User" 
						&& isset($_POST['adm_uusername'])
						&& isset($_POST['user_passwrd'])) {
						?>	
								
						<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" class="form form-horizontal">
                                            <div class="form-body">
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <label>User Id</label>
                                                    </div>
                                                    <div class="col-md-8 form-group">
                                                        <input type="text"  class="form-control" name="adm_uusername" value="<?php echo $_POST['adm_uusername']; ?>" 
														placeholder="User Id">
														   <?php
		$adunm_nme = $isValid->iValid($_POST['adm_uusername'], 'Error. Invalide Text or Blank Field', 'str');
?>
                                                    </div>
                                                    <div class="col-md-4 mt-3">
                                                        <label>User Password</label>
                                                    </div>
                                                    <div class="col-md-8 form-group mt-3">
                                                        <input type="Text" id="titleimage" class="form-control" name="user_passwrd" value="<?php echo $_POST['user_passwrd']; ?>"                                              placeholder="User Password">
				
												<?php
										$adus_scrtwrd = $isValid->iValid($_POST['user_passwrd'], 'Error. Invalide Text or Blank Field', 'str');
								?>
                                                    </div>
                                                   
                                          
														<div class="col-md-4 mt-3">
                                                        <label>Admin Privileges</label>
                                                    </div>
                                                    <div class="col-md-8 form-group">
                                                      	<div class="m-2 d-inline-block">
													 <input type="checkbox" class="form-check-input"  name="create_usr" <?php if(isset($_POST['create_usr']) && $_POST['create_usr'] == "on"){?> checked="checked" <?php } ?> />
													 
													 <?php
								if(isset($_POST['create_usr']) && $_POST['create_usr'] == "on"){
								 $adnwu_sre = 1;
								}else{
								 $adnwu_sre = 0;
								 
								}
							   ?>
									  <label for="Create User">Create User</label>
                                             </div>
											 <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"  name="create_usr" <?php if(isset($_POST['create_usr']) && $_POST['create_usr'] == "on"){?> checked="checked" <?php } ?>/>
								 <?php
							if(isset($_POST['create_usr']) && $_POST['create_usr'] == "on"){
							 $adnwu_sre = 1;
							}else{
							 $adnwu_sre = 0;
							 
							}
							?>
									  <label for="Allow Store"> Allow Store</label>
                                             </div>
											  <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"   name="al_walstr" <?php if(isset($_POST['al_walstr']) && $_POST['al_walstr'] == "on"){?> checked="checked" <?php } ?>/>
									<?php
								if(isset($_POST['al_walstr']) && $_POST['al_walstr'] == "on"){
								 $grantstoreaccess = 1;
								}else{
								 $grantstoreaccess = 0;
								 }
								?>
									  <label for="Block User"> Block User</label>
                                             </div>
										
											   <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input" name="block_usr" <?php if(isset($_POST['block_usr']) && $_POST['block_usr'] == "on"){?> checked="checked" <?php } ?>/>
								<?php
								if(isset($_POST['block_usr']) && $_POST['block_usr'] == "on"){
								 $adu_status = 1;
								}else{
								 $adu_status = 0;
								}
								?>
									  <label for="Allow Category"> Allow Category</label>
                                             </div>
											   <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"  name="alw_ctgr" <?php if(isset($_POST['alw_ctgr']) && $_POST['alw_ctgr'] == "on"){?> checked="checked" <?php } ?>/>
									<?php
								if(isset($_POST['alw_ctgr']) && $_POST['alw_ctgr'] == "on"){
								 $grantcatgry = 1;
								}else{
								 $grantcatgry = 0;
								 }
								?>


									  <label for="Allow All Access"> Allow All Access</label>
                                             </div>
                                                    
													</div>
													
													<!--catgory module--->											
											
											  		
	   
												    <div class="col-sm-12 mt-3 d-flex justify-content-end">
                                                        
								  <input type="submit" class="btn btn-primary me-1 mb-1" name="update_admnuser" value="Update User">
														
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
										
									<?php
if(isset($adunm_nme) && $adunm_nme != ''
	&& isset($adus_scrtwrd) && $adus_scrtwrd != ''
	&& isset($adu_status) && isset($adnwu_sre)
	
	&& isset($admtbs_frgnky) && $admtbs_frgnky != ''){

	$tab = "cpn_admstrx";
	$content = array("_admnnm" => $adunm_nme,
					"_scrwrdz" => $adus_scrtwrd, "_lgnip" => $_SERVER['REMOTE_ADDR'], "us_rstuts" => $adu_status, 
					"_unk_ky" => $adnwu_sre, "_sndr" => $_SESSION['logner_bot'], "lw_stro" => $grantstoreaccess, 
					"alw_ctg" => $grantcatgry);
					
	$needle = array("_admnnm");
	$updated_heystack = array("_frgn_ky" => $admtbs_frgnky);
	// check heystack. can we use content array here too just like $content[0] for heystack
					
	//if(mysql_num_rows($query->queryBuilder($needle, $tab, $heystack)) == 0 ) {
		if($query->queryUpdater($tab, $content, $updated_heystack)) { 
		
		echo "<div class='alert alert-success alert-dismissible show fade'>
           User  Has Been Updated Successfully
           <button type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'></button></div>"; 
		 
		$err->logHandler(" Alert: User Created By: '".$_SESSION['logner_bot']."' on ".date("d-m-Y")." ".date("H:i:s",time())." {Page: Admin View}  ) <--> ( ", "cerr.php");
		 }else{ 
		 echo "<div id='dup_alert'>Q-Error </div>"; 
		 }
	//}else{
		
		//$dup =  "<div id='cg_dup_alert'>Error: Duplicate Entry</div>";
		//echo $dup;
		//$err->logHandler(" Error: Duplicate Entry By: '".$_SESSION['logner_bot']."' on ".date("d-m-Y")." ".date("H:i:s",time())." {Page: Category}  ) <--> ( ", "cerr.php");
	//} // dup if

}// end 2nd if

// $admns_unqky $admtbs_frgnky

}else{
$needle = array("_admnnm", "_scrwrdz", "us_rstuts", "_unk_ky", "lw_stro", "alw_ctg", "grnt_flacs");
$tb = "cpn_admstrx";
$heystack = array("_frgn_ky" => $admtbs_frgnky); 
$editquery = $query->queryBuilder($needle, $tb, $heystack);
while($viewadmin = mysqli_fetch_array($editquery, MYSQLI_NUM)){
?>

			
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" class="form form-horizontal">
                                            <div class="form-body">
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <label>User Id</label>
                                                    </div>
                                                    <div class="col-md-8 form-group">
                                                        <input type="text"  class="form-control" 
                                                         name="adm_uusername" value="<?php echo $viewadmin[0]; ?>" placeholder="User Id">
														   
                                                    </div>
                                                    <div class="col-md-4 mt-3">
                                                        <label>User Password</label>
                                                    </div>
                                                    <div class="col-md-8 form-group mt-3">
                                                        <input type="Text" id="titleimage" class="form-control" 
                                                          name="user_passwrd" value="<?php echo $viewadmin[1]; ?>"  placeholder="User Password">
														  </div>
                                                   
                                          
														<div class="col-md-4 mt-3">
                                                        <label>Admin Privileges</label>
                                                    </div>
                                                    <div class="col-md-8 form-group">
                                                      	<div class="m-2 d-inline-block">
													 <input type="checkbox" class="form-check-input"  name="create_usr" <?php if(isset($viewadmin[3]) && $viewadmin[3] == 1){ ?> checked="checked" <?php } ?>/>
													
									  <label for="Create User">Create User</label>
									 
                                             </div>
											 <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"  name="al_walstr" <?php if(isset($viewadmin[4]) && $viewadmin[4] == 1){ ?> checked="checked" <?php } ?> />
								
									  <label for="Allow Store"> Allow Store</label>
                                             </div>
											  <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"   name="block_usr" <?php if(isset($viewadmin[2]) && $viewadmin[2] == 1){ ?> checked="checked" <?php } ?>/>
									 
									  <label for="Block User"> Block User</label>
                                             </div>
										
											   <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input" name="alw_ctgr" <?php if(isset($viewadmin[6]) && $viewadmin[6] == 1){ ?> checked="checked" <?php } ?> />
									
									  <label for="Allow Category"> Allow Category</label>
                                             </div>
											   <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"   name="alwo_fulalacs" <?php if(isset($viewadmin[9]) && $viewadmin[9] == 1){ ?> checked="checked" <?php } ?>/>
									 
									  <label for="Allow All Access"> Allow All Access</label>
                                             </div>
                                                    
													</div>
													
													<!--catgory module--->											
											
											  		
	   
												    <div class="col-sm-12 mt-3 d-flex justify-content-end">
                                                        
                                                         <input type="submit" class="btn btn-primary me-1 mb-1" name="update_admnuser" value="Update User">
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
												
								
								
				<?php
	} // end while
} // end if

////////////////// end editor  
}else{
?>				
                                   
			 
								    <h4 class="card-title">Add New User</h4>
									<?php
								if(isset($_POST['admit_admnuser']) && $_POST['admit_admnuser'] == "Create User" 
								&& isset($_POST['adm_uusername'])
								&& isset($_POST['user_passwrd'])) {
								?>
                                </div>
                                <div class="card-content">
                                    <div class="card-body">
                                        <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" class="form form-horizontal">
                                            <div class="form-body">
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <label>User Id</label>
                                                    </div>
                                                    <div class="col-md-8 form-group">
                                                        <input type="text"  class="form-control" value="<?php echo $_POST['adm_uusername']; ?>"
                                                           name="adm_uusername" placeholder="User Id">
														   <?php
		$adunm_nme = $isValid->iValid($_POST['adm_uusername'], 'Error. Invalide Text or Blank Field', 'str');
?>
                                                    </div>
                                                    <div class="col-md-4 mt-3">
                                                        <label>User Password</label>
                                                    </div>
                                                    <div class="col-md-8 form-group mt-3">
                                                        <input type="Text" id="titleimage" class="form-control" value="<?php echo $_POST['user_passwrd']; ?>"
                                                           name="user_passwrd" placeholder="User Password">
														   <?php
		$adus_scrtwrd = $isValid->iValid($_POST['user_passwrd'], 'Error. Invalide Text or Blank Field', 'str');
?>
                                                    </div>
                                                   
                                          
														<div class="col-md-4 mt-3">
                                                        <label>Admin Privileges</label>
                                                    </div>
                                                    <div class="col-md-8 form-group">
                                                      	<div class="m-2 d-inline-block">
													 <input type="checkbox" class="form-check-input"  name="create_usr" <?php if(isset($_POST['create_usr']) && $_POST['create_usr'] == "on"){?> checked="checked" <?php } ?> />
													 
													 <?php
								if(isset($_POST['create_usr']) && $_POST['create_usr'] == "on"){
								 $adnwu_sre = 1;
								}else{
								 $adnwu_sre = 0;
								 
								}
							   ?>
									  <label for="Create User">Create User</label>
                                             </div>
											 <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"  name="al_walstr" <?php if(isset($_POST['al_walstr']) && $_POST['al_walstr'] == "on"){?> checked="checked" <?php } ?>/>
								 <?php
								if(isset($_POST['al_walstr']) && $_POST['al_walstr'] == "on"){
								 $grantstoreaccess = 1;
								}else{
								 $grantstoreaccess = 0;
								 }
								?>
									  <label for="Allow Store"> Allow Store</label>
                                             </div>
											  <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"   name="block_usr" <?php if(isset($_POST['block_usr']) && $_POST['block_usr'] == "on"){?> checked="checked" <?php } ?>/>
									 <?php
									if(isset($_POST['block_usr']) && $_POST['block_usr'] == "on"){
									 $adu_status = 1;
									}else{
									 $adu_status = 0;
									 }
									?>
									  <label for="Block User"> Block User</label>
                                             </div>
										
											   <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"  name="alw_ctgr"  <?php if(isset($_POST['alw_ctgr']) && $_POST['alw_ctgr'] == "on"){?> checked="checked" <?php } ?>/>
									 <?php
									if(isset($_POST['alw_ctgr']) && $_POST['alw_ctgr'] == "on"){
									 $grantcatgry = 1;
									}else{
									 $grantcatgry = 0;
									 }
									?>
									  <label for="Allow Category"> Allow Category</label>
                                             </div>
											   <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"    name="alwo_fulalacs" <?php if(isset($_POST['alwo_fulalacs']) && $_POST['alwo_fulalacs'] == "on"){?> checked="checked" <?php } ?>/>
									 <?php
									if(isset($_POST['alwo_fulalacs']) && $_POST['alwo_fulalacs'] == "on"){
									 $allowusefullacess = 1;
									}else{
									 $allowusefullacess  = 0;
									 }
									?>


									  <label for="Allow All Access"> Allow All Access</label>
                                             </div>
                                                    
													</div>
													
													<!--catgory module--->											
											
											  		
	   
												    <div class="col-sm-12 mt-3 d-flex justify-content-end">
                                                      
													   <input type="submit" class="btn btn-primary me-1 mb-1" name="admit_admnuser" value="Create User">
                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
										
								<?php
if(isset($adunm_nme) && $adunm_nme != '' && isset($adnwu_sre) && $adnwu_sre != ''
	&& isset($adus_scrtwrd) && $adus_scrtwrd != ''
	&& isset($adu_status)){

	$tab = "cpn_admstrx";
	$content = array("_admnnm" => $adunm_nme,
					"_scrwrdz" => $adus_scrtwrd, "_lgnip" => $_SERVER['REMOTE_ADDR'], "us_rstuts" => $adu_status, 
					"_unk_ky" => $adnwu_sre,"_frgn_ky" => $key->fid(), "_sndr" => $_SESSION['logner_bot'], "lw_stro" => $grantstoreaccess,
					"alw_ctg" => $grantcatgry, "grnt_flacs" => $allowusefullacess);
	$needle = array("_admnnm");
	$heystack = array("_admnnm" => $adunm_nme);
	// check heystack. can we use content array here too just like $content[0] for heystack
					
	if(mysqli_num_rows($query->queryBuilder($needle, $tab, $heystack)) == 0 ) {
		if($query->queryhandler($tab, $content)) { 
		
		echo "<div class='alert alert-success alert-dismissible show fade'>
           User ( '".$adunm_nme."' ) Has Been Created Successfully
           <button type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'></button></div>"; 
		
		
		$err->logHandler(" Alert: User Created By: '".$_SESSION['logner_bot']."' on ".date("d-m-Y")." ".date("H:i:s",time())." {Page: Admin View}  ) <--> ( ", "cerr.php");
		 }else{ echo "<div id='dup_alert'>Q-Error </div>"; }
	}else{
		
		$dup =  "<div id='cg_dup_alert'>Error: Duplicate Entry</div>";
		echo $dup;
		$err->logHandler(" Error: Duplicate Entry By: '".$_SESSION['logner_bot']."' on ".date("d-m-Y")." ".date("H:i:s",time())." {Page: Category}  ) <--> ( ", "cerr.php");
	} // dup if

}// end 2nd if

}else{
?>		
	<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" class="form form-horizontal">
                                            <div class="form-body">
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <label>User Id</label>
                                                    </div>
                                                    <div class="col-md-8 form-group">
                                                        <input type="text"  class="form-control" 
                                                           name="adm_uusername" placeholder="User Id">
														   
                                                    </div>
                                                    <div class="col-md-4 mt-3">
                                                        <label>User Password</label>
                                                    </div>
                                                    <div class="col-md-8 form-group mt-3">
                                                        <input type="Text" id="titleimage" class="form-control" \
                                                           name="user_passwrd" placeholder="User Password">
														  </div>
                                                   
                                          
														<div class="col-md-4 mt-3">
                                                        <label>Admin Privileges</label>
                                                    </div>
                                                    <div class="col-md-8 form-group">
                                                      	<div class="m-2 d-inline-block">
													 <input type="checkbox" class="form-check-input"  name="create_usr"/>
													
									  <label for="Create User">Create User</label>
                                             </div>
											 <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"  name="al_walstr" />
								
									  <label for="Allow Store"> Allow Store</label>
                                             </div>
											  <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"   name="block_usr" />
									 
									  <label for="Block User"> Block User</label>
                                             </div>
										
											   <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"  name="alw_ctgr" />
									
									  <label for="Allow Category"> Allow Category</label>
                                             </div>
											   <div class="m-2 d-inline-block">
                                     <input type="checkbox" class="form-check-input"    name="alwo_fulalacs"/>
									 
									  <label for="Allow All Access"> Allow All Access</label>
                                             </div>
                                                    
													</div>
													
													<!--catgory module--->											
											
											  		
	   
												    <div class="col-sm-12 mt-3 d-flex justify-content-end">
                                                        <input type="submit" class="btn btn-primary me-1 mb-1" name="admit_admnuser" value="Create User">
                                                       
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
									<?php
} // end if
}
?>	
										
										
										
										
										
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                    </div>
                </section>
					
                </div><!-- page-head -->

			
            </div><!-- main-content -->
			
			 <?php include_once("assets/resources/footer_includer.php"); ?>

    <script src="assets/vendors/perfect-scrollbar/perfect-scrollbar.min.js"></script>
    <script src="assets/js/bootstrap.bundle.min.js"></script>

    <script src="assets/js/main.js"></script>
	
	<!--summnernot-->
	    <script src="assets/vendors/summernote/summernote-lite.min.js"></script>
    <script>
        $('#summernote').summernote({
            tabsize: 2,
            height: 120,
        })
        $("#hint").summernote({
            height: 100,
            toolbar: false,
            placeholder: 'type with apple, orange, watermelon and lemon',
            hint: {
                words: ['apple', 'orange', 'watermelon', 'lemon'],
                match: /\b(\w{1,})$/,
                search: function (keyword, callback) {
                    callback($.grep(this.words, function (item) {
                        return item.indexOf(keyword) === 0;
                    }));
                }
            }
        });

    </script>
	
	<!--summmernote-->
</body>

</html>