 <?php

 //echo $product_name = $_POST['product'];



session_start();

//$privilage = $_SESSION['privilage']; 


 $data_base = $_SESSION['database'];


$status = $_SESSION['status'];

$background_color =$_SESSION['bottom_backgroundcolor'];
$text_color =$_SESSION['text_color'];



$app_name = $_SESSION['app_name'];
$app_code = $_SESSION['app_code'];
  $db_size = $_SESSION['db_size'];
$biz_name = $_SESSION['biz_name'];
$biz_nature = $_SESSION['biz_nature'];
$privilage = $_SESSION['privilage'];

 $branch_key = $_SESSION['branch_key'];





$current_date = date("Y-m-d");
$activation_d = $_SESSION['activation_date'];
$expiration_d = $_SESSION['expiration_date'];


if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {

	header ("Location: login.php");

}
		
else if($privilage == "Priviledge" or $privilage == "Sales Rep" or $privilage == "Sales Rep" or $privilage == "Receptionist" or $privilage == "Inventory Manager" or $privilage == "Secetary"/*or $privilage == "Manager"*/)
{
	
	header ("Location: not_authorized.php");
	
}




?>


<?php

$error = "";

require 'config.php';


$db_handle = mysqli_connect(DB_SERVER, DB_USER, DB_PASS);

//$database = $_SESSION['database'];
$database = "lawpedc3_lbs_users";


$db_found = mysqli_select_db($db_handle, $database);


//this script is to check if database parameters has alredy been taken
$db_found_db = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );
			
		//$SQL = "DELETE FROM product_table WHERE product_id=$txnid";
   //$query_del = mysqli_query($db_handle, $SQL);



  
if($db_found){
if(isset($_POST['A']))
{
	    $biz_name =  $_POST['biz_name'] ;
		$biz_nature =$_POST['biz_nature'] ;
		$admin_name = $_POST['admin_name'] ;
	
		$nation = $_POST['nation'] ;
		$city = $_POST['city'] ;
		$fone = $_POST['fone'] ;
		$email = $_POST['email'] ;
	
	$activation_date = $_POST['activation_date'] ;
	$expiration_date = $_POST['expiration_date'] ;
	
	
	
		$user_name=$_POST['pass'];
    	$pass=$_POST['pass'];
		$re_pass=$_POST['re_pass'];
		
		//$d_b=  'lawpedc3_'.str_shuffle($pass); 
		$d_b =  $_POST['d_base'];
	
		$db_size=$_POST['db_size'];
	
		$app_code = $_POST['app_code'] ;
		//$app_code ="LBS7777";
	 	$app_name =$_POST['app_name'];
	
	 	$privilage =$_POST['privilage'];
	 	$status =$_POST['status'];
	
	 	$date = date("Y-m-d");
		
	

	
	
	 if( $biz_name =="" or $biz_nature==""  or $admin_name=="" or $nation=="" or $city==""or $fone =="" or $pass =="" or $re_pass=="")
		
			{
					$error = "OPERATION FAILED|| one of the fields is blank";
			}
	
	
		
	
	
		else if($pass!=$re_pass )
	
		{
			$error = "OPERATION FAILED||passwords mis-matched";
		}
			
			
		
			 
			
				
		
		
	
			
			else if ($db_found_db) {
				
				//$database = "lawpedc3_lbs_users";


	$SQL = $db_found_db->prepare('SELECT L1 FROM login WHERE L1 = ?');
	$SQL->bind_param('s', $pass);
	$SQL->execute();
	$result = $SQL->get_result();
				
				
				
				
				
				
				
				
				
	$SQL_f = $db_found_db->prepare('SELECT fone FROM login WHERE fone = ?');
	$SQL_f->bind_param('s', $fone);
	$SQL_f->execute();
	$result_f = $SQL_f->get_result();
				
				
				
				
				
				
				
				
	/*$SQL_lbs = $db_found_db->prepare('SELECT app_code FROM login WHERE app_code = ?');
	$SQL_lbs->bind_param('s', $app_code);
	$SQL_lbs->execute();
	$result_lbs = $SQL_lbs->get_result();*/

		if ($result->num_rows == 1) {
 			
			//$errorMessage = "incorrect password";
			
			$db_field = $result->fetch_assoc();
			
			$error = "OPERATION FAILED||Password Not Suitable";

			
		}
				
				
				else if ($result_f->num_rows == 1) {
 			
			//$errorMessage = "incorrect password";
			
			$db_field_f = $result_f->fetch_assoc();
			
			$error = " OPERATION FAILED||please this phone number has been used. change it. thanks";

			
		}
				
				
				
				
			
				
				
				
				
				
	
				

				
				
				
					
			
		else{
			
			
			$background_color = "#0905cc";
			$text_color = "#fbfaff";
			$bottom_background = "#ffeb0a";
			$bottom_textcolor = "#040101";
			$address = $_SESSION['address'];
			
			$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );
	
			$SQL = $db_found->prepare("INSERT INTO login (biz_name,biz_nature,name,nation,city,fone,email,L1,L2,d_b,db_size,app_code,app_name,privilage,status,date,activation_date,expiration_date,branch_key,background_color,text_color,bottom_background,bottom_textcolor,address) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
			$SQL->bind_param('ssssssssssssssssssssssss',$biz_name,$biz_nature,$admin_name,$nation,$city,$fone,$email,$user_name,$pass,$d_b,$db_size,$app_code,$app_name,$privilage,$status,$date,$activation_date,$expiration_date,$branch_key,$background_color,$text_color,$bottom_background,$bottom_textcolor,$address);
			$SQL->execute();
			
			
			
			//email function
			
  		
			
   ini_set("sendmail_from", "lbs@lawped.com.ng");  
   $to = $email.",lbs@lawped.com.ng";//change receiver address  
   $subject = "LBS";  
   $message = 'Password:'.$pass.', App Code:'.$app_code;  
   $header = "From:lbs@lawped.com.ng\r\n";  
  
   $result = mail ($to,$subject,$message,$header);  
  
   if( $result == true ){  
     	$error = "Employee added Successfully<br>Check ur Email"; 
	   
	   //header ("Location: add_user.php?txnfailed=$error");
   }
			else{  
     	$error = "Employee added Successfully<br> Unable to send you an email"; 
	   
	  // header ("Location: add_user.php?txnfailed=$error");
   }  


			
			
			
			//header ("Location: inactive.php");
			
			//$error = "no blank";
		
		
		
		
		
		
		
	}
	
				
				
				
				
				
				
				
				
				
				
				
				
				
	}

			
			
			
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
	

	
	
	
	
	
	
	
}
	  
	  
	// header ("Location: inventory_ac.php");

	 
	  
  
  }
	  
  
else{
	
	$error =  "database not found";

	}

 

?>





	<html>
		
			<title>add_user</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->	
		 <link href="css/bootstrap-4.4.1.css" rel="stylesheet">
		 <link href="css/popup.css" rel="stylesheet">
		
		
		
	<head>



	</head>
		
		<style>
			.loader {
  border: 16px solid #f3f3f3;
  border-radius: 30%;
  border-top: 5px solid blue;
  border-right: 5px solid green;
  border-bottom: 5px solid red;
  border-left: 5px solid yellow;
  width: 40px;
  height: 40px;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 1s linear infinite;
}

		
		
@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

			
			
			div.scroll_history {
                //margin:4px, 4px;
               // padding:4px;
                background-color: #494747;
                width: 100%;
                height: 80%;
                //overflow-x: hidden;
                //overflow-y: auto;
				overflow: auto;
                text-align:justify;
            }
		
			
			
		
		body, html {
background-color: <?php echo $background_color; ?>;
			}
		</style>
		
		
		
	<body onLoad= "spinner(), <?php echo "customAlert.alert('$error','LBS App Builder')"; ?>">



		<div class="jumbotron-fluid" style="background-color: #757672; color: #F0ECEC">
	
				
<?php 
		
	echo $_SESSION['name'].'   '.' (IDN '. $_SESSION['user_id'].' ) ';
			
			

		?>
			<div class="" style="float: right; color: #ED0307;"><a HREF = "logout.php" onClick="spinner()"><span style="color: #F9F833">Log out</span></a></div>
			<!--<button onclick="myFunction()">Click Me</button>-->
			

			
		</div>

				

		<div class="jumbotron" style="text-align: center">
		
		
		
		
		<div class="row">
			
			
					<div class="col-md-6">
			
			
				<table style="margin: auto;width:;background-color: " >
				
		
					<tr>
				<td>
				
		 			<span style="background-color: black; color: white;">  <?php echo $error; ?></span>
			<h3><b> <span style="color: <?php echo $text_color; ?>">ADD STAFF</span> </b></h3>
				
					<form METHOD ="POST" ACTION = "add_user.php" style="width: 100%">
				
						<input type="hidden" value="<?php echo $data_base ?>" name="d_base">
						<input type="hidden" value="<?php echo $db_size ?>" name="db_size">
						<input type="hidden" value="<?php echo $app_code ?>" name="app_code">
						
						<input type="hidden" value="<?php echo $activation_d ?>" name="activation_date">
						<input type="hidden" value="<?php echo $expiration_d ?>" name="expiration_date">
						
					
						
						
						<input type="hidden" value="LBS" name="app_name">
						<!--<input type="hidden" value="admin" name="privilage"> -->
						<input type="hidden" value="active" name="status">
						
						
							<select class="custom-select"  style="width:100%"  id="inputGroupSelect03" name="privilage">
										
												<option selected>Role</option>
																		
											<!--	<option value="admin">admin</option> -->
												<option value="Sales Rep">Sales Rep</option> 
												<option value="Receptionist">Receptionist</option>
												<option value="Manager">Branch Manager</option>
												<option value="Inventory Manager">Inventory Manager</option>
												<option value="Employee">Secetary</option>
																									  }
		
											
											
											</select> 
					
						
						
						<table width="">
				
							<tr>
									<td>  
	
										<div class="input-group mb-3">
											
											
											<input type="hidden" class="form-control" placeholder="eg.Lawped Limited" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $biz_name ?>" name="biz_name">
				
										</div>
										
										<div class="input-group mb-3">
											
										
										
											<input type="hidden" class="form-control" placeholder="eg.Provision Store,Supermarket,Gas station etc" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $biz_nature ?>" name="biz_nature">
				
										</div>
										
										
										
										
					
										<div class="input-group mb-3">
  					
											<div class="input-group-prepend">
    
												<span class="input-group-text" id="basic-addon1">Full Name</span>
  
												</div>
  
											<input type="text" class="form-control" placeholder="eg. Alaye David " aria-label="Username" aria-describedby="basic-addon1" name="admin_name" value="">

											
										</div>
										
											<div class="input-group mb-3">
											
											
												
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Nationality</span>
					
											</div>
										
											<input type="text" class="form-control" placeholder="eg.United State,Nigeria" aria-label="Username" aria-describedby="basic-addon1" value="" name="nation">
				
										</div>
										
										<div class="input-group mb-3">
											
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">City</span>
					
											</div>
										
											<input type="text" class="form-control" placeholder="eg. Warri,Ph,chigago etc" aria-label="Username" aria-describedby="basic-addon1" value="" name="city">
				
										</div>
										
										
										
										
											<div class="input-group mb-3">
											
											
												
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Phone No</span>
					
											</div>
										
											<input type="text" class="form-control" placeholder="please fill" aria-label="Username" aria-describedby="basic-addon1" value="" name="fone">
				
										</div>
										
										<div class="input-group mb-3">
											
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Email</span>
					
											</div>
										
											<input type="text" class="form-control" placeholder="please fill" aria-label="Username" aria-describedby="basic-addon1" value="" name="email">
				
										</div>
										
										
											<div class="input-group mb-3">
											
												
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Password</span>
					
											</div>
										
											<input type="password" class="form-control" placeholder="please fill" aria-label="Username" aria-describedby="basic-addon1" value="" name="pass">
				
										</div>
										
										<div class="input-group mb-3">
											
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Re-Password</span>
					
											</div>
										
											<input type="password" class="form-control" placeholder="please fill" aria-label="Username" aria-describedby="basic-addon1" value="" name="re_pass">
												
												
												
												
										
												
				
										</div>
										
										
										
									
										
							
					</td>
					
								
								
						</tr>
							
					</table>
						<table>
						<td>
			<input type="submit" value="                    ADD                 "  name = "A" style= "width:; height: " class="" onClick="spinner()" > 
						</td>
							
							<td>
							
							<div class="loader" id="load" style="margin: auto"></div>
							</td>
							
							
				<td>		
						<a href = "dashboard.php"><input type="button" value=" BACK "  name = "" style= "width:; height: " class="" onClick="spinner()"> </a>
				</td>
											
								</table>
					</form>
		
		        
					
					
				
		</td>
					
			
	
				</tr>

			
			
			</table>
				
				
				
				
				
				</div>

			
			
			
			
					<div class = "col-md-6 " style="background-color: #494747">
				  	
						<strong ><span style="color:#FAF7FF;padding: 4px"><br>STAFF RECORDS
					    
							</span> </strong>
				
						 
						<div class="jumbotron-fluid scroll_history" style="font-size:12; ">
				  
				  <!--<strong ><span style="color:#260B4D;background-color: #FBFBFC;padding: 4px">TRANSACTION HISTORY
					     </span></strong>-->
				  
	  
							<table class="table  table-hover" style="font-size:12; width:100%  " >
  
								<tbody>
    
									<tr  style="background-color:<?php echo $background_color ?>; text-align:; color: <?php echo $_SESSION['bottom_textcolor']; ?> ">
      
										<th scope="col">S/N</th>
	
										<th scope="col">IDN </th>
										
										<th scope="col">NAME</th>
      
										<th scope="col">PASSWORD</th>
										
										<th scope="col">CITY</th>
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
	
		   
										<th scope="col">PHONE</th>
										<th scope="col">EMAIL</th>
										<th scope="col">PRIVILAGE</th>
		
										
		 
										<th scope="col">STATUS</th>
										
										<th scope="col">DATE</th>
										
		
     
    
									</tr>
 			
		



									<?PHP

//if ($db_found) {

//$SQL = "SELECT * FROM product_table ORDER BY product_id ASC ";

	  
	  
//$SQL = "SELECT * FROM txn_table where date= current_date ORDER BY product_id DESC   ";

						
									
								
					
								
									$SQL = "SELECT  ID,name,L1, city,fone,email,privilage,date,status FROM login   where app_code = '$app_code' and privilage != 'admin' and branch_key='$branch_key'  ORDER BY name ASC";

	  
									
									$result = mysqli_query($db_handle, $SQL);

									$i =1;
	  		
									while ( $db_found = mysqli_fetch_assoc($result) ) {
	   
	
										echo'<tr style="text-align: center; color:blue; background-color:white"  >';

	
	
										echo '<td>'.$i++.'</td>';
		
										echo '<td>'.$db_found['ID'].'</td>';
										
										echo '<td>'.$db_found['name'].'</td>';
		 
										echo '<td>'.$db_found['L1'].'</td>';
										
										echo '<td>'.$db_found['city'].'</td>';
		
										echo '<td>'.$db_found['fone'].'</td>';
									
		
	
										echo '<td>'.$db_found['email'].'</td>';
	
	 
										echo '<td>'.$db_found['privilage'].'</td>';
										
										
	
										echo '<td>'.$db_found['status'].'</td>';
										
										echo '<td>'.$db_found['date'].'</td>';
										
										
										
	//echo '<td>'.$db_found['SUM(amount)'].'</td>';
	
	//echo $db_found_sum['SUM(amount)']; 
	 
	 
	
									?>
<!--	  
  <td><a href="construction.php?txnId=Receipt">
    <input type="button" value="Issue Receipt"></a></td>
	  
	  <td><a href="construction.php?txnId=Modify Account">
    <input type="button" value="Modify"></a></td>-->
	  
	  
	  
										<td><a href="modify_priviledge.php?txnId=<?php echo $db_found["ID"]?>">
   
										<input type="button" value="Access Control" onClick="spinner(), view_ac()"></a>
									</td>
	
	
	   
									<td><a href="add_user_delete.php?txnId=<?php echo $db_found["ID"]?>">
   
										<input type="button" value="Delete" onClick="spinner(), view_ac()"></a>
									</td>
	
	  
									<?php
	
										echo '</tr>';

	
	

									}

									mysqli_close($db_handle);
	  
							
									?>
	

								</tbody>

							</table>
						
	
	
						</div>
			
					</div>
			
			
		</div>
			
	
			
			</div>
	
		
	
		
		</body>
	
		</html>
<script>


		function spinner() {
  
			var x = document.getElementById("load");
	
	
	
  if (x.style.display === "none") {
    x.style.display = "block ";
	  
	  
  }
	else {
    x.style.display = "none";
  }
	
	
}
	
		
		
		


</script>





<script>
	
	//pop scripts
	
	
function CustomAlert(){
  this.alert = function(message,title){
    document.body.innerHTML = document.body.innerHTML + '<div id="dialogoverlay"></div><div id="dialogbox" class="slit-in-vertical"><div><div id="dialogboxhead"></div><div id="dialogboxbody"></div><div id="dialogboxfoot"></div></div></div>';

    let dialogoverlay = document.getElementById('dialogoverlay');
    let dialogbox = document.getElementById('dialogbox');
    
    let winH = window.innerHeight;
    dialogoverlay.style.height = winH+"px";
    
    dialogbox.style.top = "100px";

    dialogoverlay.style.display = "block";
    dialogbox.style.display = "block";
    
    document.getElementById('dialogboxhead').style.display = 'block';

    if(typeof title === 'undefined') {
      document.getElementById('dialogboxhead').style.display = 'none';
    } else {
      document.getElementById('dialogboxhead').innerHTML = '<i class="fa fa-exclamation-circle" aria-hidden="true"></i> '+ title;
    }
    document.getElementById('dialogboxbody').innerHTML = message;
    document.getElementById('dialogboxfoot').innerHTML = '<button class="pure-material-button-contained active" onclick="customAlert.ok()">OK</button>';
  }
  
  this.ok = function(){
    document.getElementById('dialogbox').style.display = "none";
    document.getElementById('dialogoverlay').style.display = "none";
  }
}

let customAlert = new CustomAlert();
	</script>