<?php
session_start();
require_once ('class.admin.php');
include_once ('session.php');

$reg_user = new USER();

if(!isset($_SESSION['email'])){
	
header("Location: login.php");

exit(); 
}

$stmt = $reg_user->runQuery("SELECT * FROM account");
$stmt->execute();

if(isset($_POST['set']))
{
	
	$uname = trim($_POST['uname']);
	$uname = strip_tags($uname);
	$uname = htmlspecialchars($uname);
	
	$billing_code = trim($_POST['billing_code']);
	$billing_code = strip_tags($billing_code);
	$billing_code = htmlspecialchars($billing_code);
	
			$set= $reg_user->runQuery("UPDATE account SET uname = '$uname', billing_code = '$billing_code' WHERE uname = '$uname'");
			$set->execute();
			
			$id = $reg_user->lasdID();		
			
			
			$msg= "<div class='alert alert-info'>
				<button class='close' data-dismiss='alert'>&times;</button>
					<strong>Settings Saved Successfully to <b>$billing_code</b>!</strong> 
			  </div>";	

}

?>

 <?php
include 'dbconnect.php';

$sql = "SELECT * FROM account ORDER BY id";
$sql1 = "SELECT * FROM ticket ";
$sql2 = "SELECT * FROM transfer";
$sql3 = "SELECT * FROM account WHERE verify ='N' ORDER BY id DESC LIMIT 200";


if ($result = mysqli_query($connection, $sql)) {
    // Return the number of rows in result set
    $rowcount = mysqli_num_rows($result);

    // Free result set
    mysqli_free_result($result);

    if ($result1 = mysqli_query($connection, $sql1)) {
        // Return the number of rows in result set
        $rowcount1 = mysqli_num_rows($result1);

        // Free result set
        mysqli_free_result($result1);

        if ($result2 = mysqli_query($connection, $sql2)) {
            // Return the number of rows in result set
            $rowcount2 = mysqli_num_rows($result2);

            // Free result set
            mysqli_free_result($result2);

            if ($result3 = mysqli_query($connection, $sql3)) {
                // Return the number of rows in result set
                $rowcount3 = mysqli_num_rows($result3);

                // Free result set
                mysqli_free_result($result3);
            }
        }
    }
}

mysqli_close($connection);
?>
       <?php include 'headeradmin.php'; ?>
 

 <!---begin of Mobile View Here   only from Team-->
 
       <?php include 'menu.php'; ?>
  
  <!---End of Mobile View Here   only from Team-->
  
 
      <script type="text/javascript" src="paginator.js"></script>
        <script type="text/javascript" src="table.js"></script>
     
     
  
    <div class="container-fluid mt--7">
     <!-- Table -->
      <div class="row">
        <div class="col">
          <div class="card shadow" >
            <div class="card-header border-0">
              <h3 class="mb-0"><a href=""   class="btn btn-danger">CHANGE USER BILLING CODE</a></h3>
            </div>
          
           <div class="card-body">
               
               <?php if(isset($msg)) echo $msg;  ?> 
              
            
              <form method="POST">
               
                 <div class="col-lg-6">
                      <div class="form-group">
				 
						<label>Select Client</label>
						<select name="uname" class="form-control input-sm validate[required]">
						<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)){?>
							<option value="<?php echo $row['uname']; ?>"><?php echo $row['fname']; ?> <?php echo $row['mname']; ?> <?php echo $row['lname']; ?></option>
						<?php } ?>
					   </select>
				 
			 </div></div>
			
			  <div class="col-lg-6">
                      <div class="form-group">
						<label>Transfer Billing Status <span style="color:red;">ACTIVE means client will need all billing codes during Transfer and Deactivate means No Billing Code</span></label>
						<select  name="billing_code" class="form-control input-sm validate[required]">
							<option value="1">ACTIVE WITH ALL BILLING CODES</option>
							<option value="0">DEACTIVATE (ONLY OTP)</option> 
							<option value="2">MOVE-TO-COT-PAGE</option>
							<option value="3">MOVE-TO-TAX-PAGE</option>
							<option value="4">MOVE-TO-IMF-PAGE</option>
							<option value="5">MOVE-TO-IBF-PAGE</option>
							<option value="6">MOVE-TO-ERM-PAGE</option>
						</select>
				 
                </div></div>
                <br/>
					<button type="submit" name="set" class="btn btn-info ">Set/Diable Billing Code</button>
				</form>
               
               <hr>
               	<article>
				<ul>
					<li><b>Active</b> <p> This means that the client can make transfer with all billing codes (COT, TAX, IMF, IBF, ERM)</p></li>
					<li><b>Deactivate</b> <p>Means the client can make transfer without billing code (OTP only)</p></li>
					<li><b>MOVE-TO-COT-PAGE</b> <p>Client will be redirected to COT code page</p></li>
					<li><b>MOVE-TO-TAX-PAGE</b> <p>Client will be redirected to TAX code page</p></li>
					<li><b>MOVE-TO-IMF-PAGE</b> <p>Client will be redirected to IMF code page</p></li>
					<li><b>MOVE-TO-IBF-PAGE</b> <p>Client will be redirected to IBF (Intermediary Bank Fees) code page</p></li>
					<li><b>MOVE-TO-ERM-PAGE</b> <p>Client will be redirected to ERM (Exchange Rate Margins) code page</p></li>
			 
    </ul>
				</article>
               
               
               
               
          </div>
        </div>
      </div>
     </div>
 
    
       <?php include 'foot.php'; ?>