<?php

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



session_start();

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


 $data_base = $_SESSION['database'];


$status = $_SESSION['status'];





$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'];




$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 == "Iventory 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);

//echo $database = $_SESSION['database'];
 $database = "lawpedc3_lbs_users";
$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );
//$db_found = mysqli_select_db($db_handle, $database);

//$db_found = 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 === false){
	echo "it connect";
	
}




if(isset($_POST['A']))
{
	 
	 $privilag =$_POST['privilage'];
	 $branch_key =$_POST['address'];
	
	
	 $ID =$_POST['ID'];
	

$SQl_update = "UPDATE login SET privilage = '$privilag' , branch_key = '$branch_key' WHERE ID = $ID ";
	
	//mysqli_query ($db_found,$SQl_update);
	mysqli_query($db_found,$SQl_update);
	
	header ("Location: add_user.php");
	
}

	
	

  
 

?>






	<html>
		
			<title>Delete_script</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">
		
		
		
	<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: #000000;
			}
		</style>
		
		
		
	<body onLoad="spinner()">


			

		<div class="jumbotron" style="text-align: center">
		
		
		
		
		<div class="row">
			
			
					<div class="col-md-6">
			
			
				<table style="margin: auto;width:;background-color: " >
				
		
					<tr>
				<td>
				
		 		
			<h3><b><span style="color: #8996C9"> <span style="color: red">Modify Access</span> </b></h3>
				
					<form METHOD ="POST" ACTION = "modify_priviledge.php" style="width: 100%">
				
						<input type="hidden" value="<?php echo $txnid= $_GET['txnId']; ?>" name="ID">
						
						
						<label>Switch Role</label> <br>
						
							<select class=""  style="width:100%"  id="inputGroupSelect03" name="privilage">
										
								
								
												<option selected>Priviledge</option>
																		
												<option value="suspend">Suspend App</option>  
												<option value="Sales Rep">Sales Rep</option> 
												<option value="Receptionist">Receptionist</option>
												<option value="Manager">Manager</option>
												<option value="Inventory Manager">Inventory Manager</option>
												<option value="Secetary">Secetary</option>
																									  }
		
											
											
											</select> 
						
<p></p>
						
						
						
						
						
						
						<label>Switch Address</label> <br>
						
						
 <select class=""  style="width: 100%"   name="address" id="product" onchange="showUser(this.value) " >
										
											<option value="" selected><?php echo $_SESSION['address']; ?></option>
		
											<?php
	 
	 $databas = $_SESSION['database'];
	 
	 $app_code = $_SESSION['app_code'];
//$database = "lawpedc3_lbs_users";

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

	 
	 
											
											$SQL = "SELECT  DISTINCT address, branch_key FROM location where app_code = '$app_code' ORDER BY ID ASC ";
											
											$result = mysqli_query($db_handle, $SQL);
											
											//$i =1;

											
											while ( $db_found = mysqli_fetch_assoc($result) ) {
											
												/*echo'<option value="'. $db_found['product_name'].'">'. $db_found['product_name'].'(Qty'. $db_found['unit_q'].', Amt '. $db_found['unit_p'].')</option>'; */
												
												echo'<option value="'. $db_found['branch_key'].'">'. $db_found['address'].'</option>'; 
																									  }
		
											?>
											
											</select> 
					
						
						
						<table width="">
				
							<tr>
									<td>  
	
										
										
					
								
										
									
									
										
										
										
											<div class="input-group mb-3">
											
											
									
										</div>
										
								
									
										
										
									
										
							
					</td>
					
	
						</tr>
							
					</table>
						<table>
						<td>
			<input type="submit" value="                    EXECUTE                 "  name = "A" style= "width:auto; height: 70px" class="" onClick="spinner()" > 
						</td>
							
							<td>
							
							<div class="loader" id="load" style="margin: auto"></div>
							</td>
							
							
				<td>		
						<a href = "add_user.php"><input type="button" value=" BACK "  name = "" style= "width:auto; height: 70px" class="" onClick="spinner()"> </a>
				</td>
											
								</table>
					</form>
		
		        
					
					
				
		</td>
					
			
	
				</tr>

			
			
			</table>
				
				
				
				
				
				</div>

			
			
			
			
					<div class = "col-md-6 " style="background-color: #494747">
				  	
				
					</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>