<?php
session_start();
include_once ('conn/session.php');
require_once 'conn/controller.php';
if(!isset($_SESSION['acc_no'])){
header("Location: auth_login.php");
exit(); 
}

$reg_user = new USER();

$stmt = $reg_user->runQuery("SELECT * FROM account WHERE acc_no=:acc_no");
$stmt->execute(array(":acc_no"=>$_SESSION['acc_no']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stat = $row['status'];
 

        if(isset($_POST['add_acc'])){

        $conn = mysqli_connect($host, $username, $password, $database);
        
        // Check connection
        
        if (!$conn) {
              die("Connection failed: " . mysqli_connect_error());
        }
         
        echo ""; 
        
        $db_select = mysqli_select_db($con, $database);

        
        $macc_no =$_REQUEST['macc_no'];
        $memail =$_REQUEST['memail'];
        $phone =$_REQUEST['phone'];
        $sacc_no =$_REQUEST['sacc_no'];  
        $s_type =$_REQUEST['s_type'];
        $s_currency =$_REQUEST['s_currency'];
        $s_bal =$_REQUEST['s_bal'];




$stmt = $reg_user->runQuery("SELECT * FROM s_account WHERE macc_no=:macc_no");
$stmt1 = $reg_user->runQuery("SELECT * FROM s_account WHERE memail=:memail");
$stmt->execute(array(":macc_no" => $macc_no));
$stmt1->execute(array(":memail" => $memail));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$row1 = $stmt1->fetch(PDO::FETCH_ASSOC);


if ($stmt->rowCount() > 0 || $stmt1->rowCount() > 0) {
$msg = "

                            <script type='text/javascript'>
							<!--
							function Redirect() {
							window.location='add_account.php';
							}
							document.write ('');
							setTimeout('Redirect()', 3000);
							//-->
							</script>
<div class='alert alert-danger'>
<button class='close' data-dismiss='alert'>&times;</button>
<strong>Sorry!</strong> You have a Sub Account Already
</div>
";
} else {            



            
            
$sql = "INSERT INTO `s_account` (`id`, `macc_no`, `memail`, `phone`, `sacc_no`,  `s_type`, `s_currency`, `s_bal`) 
VALUES (NULL, '$macc_no', '$memail', '$phone', '$sacc_no', '$s_type', '$s_currency', '$s_bal')";                                              
        



        
		 
		   $insert=mysqli_query($conn, $sql);
		   
		   if($insert){
		       
		       
			  	$msg = "
					<div class='alert alert-success'>
					
					<script type='text/javascript'>
							<!--
							function Redirect() {
							window.location='add_account.php';
							}
							document.write ('');
							setTimeout('Redirect()', 3000);
							//-->
							</script>
							
					<center><img src='icon/logo-ok-png-2.png' width='50px'  /></center>
					
                    
					<center>	<strong style='color:black;'>Your have Successfully Created a Sub Account.
                           </strong></center>
			  		</div>
					";
			   
		   }else{
		       
		       echo '<h3>Sub Account HAS FAILED!</h3>';
		       
		       
		   }
	   }
        }
 
                           
                           




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

 <style>
 

input[type=text], select, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  margin-top: 6px;
  margin-bottom: 16px;
  resize: vertical;
}

input[type=number], date{
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  margin-top: 6px;
  margin-bottom: 16px;
  resize: vertical;
}


input[type=submit] {
  padding: 12px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

input[type=submit]:hover {
  background-color: #45a049;
}

.container {
  border-radius: 5px;
  background-color: ;
  padding: 20px;
}
</style>
				
				
				
				
				
				<!-----------------------CONTENT STARTS HERE ------------------------------>
				

			
			<div style="font-size: 24px; font-weight: bold; color: rgb(4, 9, 63); line-height: 31px;"><img src="icon/wire.png" height="30" width="30" > Add Sub Account</div>
			
			<div style="font-size: 16px; color: rgb(81, 89, 120);">Carefully Open a Sub Account for your Business or fast offshore Transfer</div></div><div>
			
			<img src="theme/img/dashboard-plant.svg" alt=""></div></div><div class="row"><div class="col-md-12 col-xl-8">
		
	  
			
			
			<div class="custom-card">
		    
		    
		    
		    
            		    
            		    <div class="container">
                                                    
            
            <?php if (isset($msg)) echo $msg; ?>
            
           
           <form class="forms-sample" autocomplete="off" method="POST"> 
                                
                            
                      
                                                                <label for="location1">Choose Account Currency :</label>
                                             <select class="custom-select form-control"  name="s_currency"  required>
<option value="$">America (United States) Dollars – USD</option>
<option value="AFN">Afghanistan Afghanis – AFN</option>
<option value="ALL">Albania Leke – ALL</option>
<option value="DZD">Algeria Dinars – DZD</option>
<option value="ARS">Argentina Pesos – ARS</option>
<option value="AUD">Australia Dollars – AUD</option>
<option value="ATS">Austria Schillings – ATS</OPTION>
 
<option value="BSD">Bahamas Dollars – BSD</option>
<option value="BHD">Bahrain Dinars – BHD</option>
<option value="BDT">Bangladesh Taka – BDT</option>
<option value="BBD">Barbados Dollars – BBD</option>
<option value="BEF">Belgium Francs – BEF</OPTION>
<option value="BMD">Bermuda Dollars – BMD</option>
 
<option value="BRL">Brazil Reais – BRL</option>
<option value="BGN">Bulgaria Leva – BGN</option>
<option value="CAD">Canada Dollars – CAD</option>
<option value="XOF">CFA BCEAO Francs – XOF</option>
<option value="XAF">CFA BEAC Francs – XAF</option>
<option value="CLP">Chile Pesos – CLP</option>
 
<option value="CNY">China Yuan Renminbi – CNY</option>
<option value="CNY">RMB (China Yuan Renminbi) – CNY</option>
<option value="COP">Colombia Pesos – COP</option>
<option value="XPF">CFP Francs – XPF</option>
<option value="CRC">Costa Rica Colones – CRC</option>
<option value="HRK">Croatia Kuna – HRK</option>
 
<option value="CYP">Cyprus Pounds – CYP</option>
<option value="CZK">Czech Republic Koruny – CZK</option>
<option value="DKK">Denmark Kroner – DKK</option>
<option value="DEM">Deutsche (Germany) Marks – DEM</OPTION>
<option value="DOP">Dominican Republic Pesos – DOP</option>
<option value="NLG">Dutch (Netherlands) Guilders – NLG</OPTION>
 
<option value="XCD">Eastern Caribbean Dollars – XCD</option>
<option value="EGP">Egypt Pounds – EGP</option>
<option value="EEK">Estonia Krooni – EEK</option>
<option value="EUR">Euro – EUR</option>
<option value="FJD">Fiji Dollars – FJD</option>
<option value="FIM">Finland Markkaa – FIM</OPTION>
 
<option value="FRF*">France Francs – FRF*</OPTION>
<option value="DEM">Germany Deutsche Marks – DEM</OPTION>
<option value="XAU">Gold Ounces – XAU</option>
<option value="GRD">Greece Drachmae – GRD</OPTION>
<option value="GTQ">Guatemalan Quetzal – GTQ</OPTION>
<option value="NLG">Holland (Netherlands) Guilders – NLG</OPTION>
<option value="HKD">Hong Kong Dollars – HKD</option>
 
<option value="HUF">Hungary Forint – HUF</option>
<option value="ISK">Iceland Kronur – ISK</option>
<option value="XDR">IMF Special Drawing Right – XDR</option>
<option value="INR">India Rupees – INR</option>
<option value="IDR">Indonesia Rupiahs – IDR</option>
<option value="IRR">Iran Rials – IRR</option>
 
<option value="IQD">Iraq Dinars – IQD</option>
<option value="IEP*">Ireland Pounds – IEP*</OPTION>
<option value="ILS">Israel New Shekels – ILS</option>
<option value="ITL*">Italy Lire – ITL*</OPTION>
<option value="JMD">Jamaica Dollars – JMD</option>
<option value="JPY">Japan Yen – JPY</option>
 
<option value="JOD">Jordan Dinars – JOD</option>
<option value="KES">Kenya Shillings – KES</option>
<option value="KRW">Korea (South) Won – KRW</option>
<option value="KWD">Kuwait Dinars – KWD</option>
<option value="LBP">Lebanon Pounds – LBP</option>
<option value="LUF">Luxembourg Francs – LUF</OPTION>
 
<option value="MYR">Malaysia Ringgits – MYR</option>
<option value="MTL">Malta Liri – MTL</option>
<option value="MUR">Mauritius Rupees – MUR</option>
<option value="MXN">Mexico Pesos – MXN</option>
<option value="MAD">Morocco Dirhams – MAD</option>
<option value="NLG">Netherlands Guilders – NLG</OPTION>
 
<option value="NZD">New Zealand Dollars – NZD</option>
<option value="NOK">Norway Kroner – NOK</option>
<option value="OMR">Oman Rials – OMR</option>
<option value="PKR">Pakistan Rupees – PKR</option>
<option value="XPD">Palladium Ounces – XPD</option>
<option value="PEN">Peru Nuevos Soles – PEN</option>
 
<option value="PHP">Philippines Pesos – PHP</option>
<option value="XPT">Platinum Ounces – XPT</option>
<option value="PLN">Poland Zlotych – PLN</option>
<option value="PTE">Portugal Escudos – PTE</OPTION>
<option value="QAR">Qatar Riyals – QAR</option>
<option value="RON">Romania New Lei – RON</option>
 
<option value="ROL">Romania Lei – ROL</option>
<option value="RUB">Russia Rubles – RUB</option>
<option value="SAR">Saudi Arabia Riyals – SAR</option>
<option value="XAG">Silver Ounces – XAG</option>
<option value="SGD">Singapore Dollars – SGD</option>
<option value="SKK">Slovakia Koruny – SKK</option>
 
<option value="SIT">Slovenia Tolars – SIT</option>
<option value="ZAR">South Africa Rand – ZAR</option>
<option value="KRW">South Korea Won – KRW</option>
<option value="ESP">Spain Pesetas – ESP</OPTION> 
 
<option value="SDD">Sudan Dinars – SDD</option>
<option value="SEK">Sweden Kronor – SEK</option>
<option value="CHF">Switzerland Francs – CHF</option>
<option value="TWD">Taiwan New Dollars – TWD</option>
<option value="THB">Thailand Baht – THB</option>
<option value="TTD">Trinidad and Tobago Dollars – TTD</option>
 
<option value="TND">Tunisia Dinars – TND</option>
<option value="TRY">Turkey New Lira – TRY</option>
<option value="AED">United Arab Emirates Dirhams – AED</option>
<option value="GBP">United Kingdom Pounds – GBP</option>
<option value="$">United States Dollars – USD</option>
<option value="VEB">Venezuela Bolivares – VEB</option>
 
<option value="VND">Vietnam Dong – VND</option>
<option value="ZMK">Zambia Kwacha – ZMK</option>

                            </select>
					      
					      <label for="lname">Select Account Type</label>
					      <select  required  name="s_type">
                                        <option value="">Select Account Type</option>
                                        <option value="Beneficiary Account">Beneficiary Account</option>
                                        <option value="Savings">Savings Account</option>
                                        <option value="Current">Current Account</option>
                                        <option value="Checking">Checking Account</option>
                                        <option value="Fixed Deposit">Fixed Deposit</option>
                                        <option value="Non Resident">Non Resident Account</option>
                                        <option value="Online Banking">Online Banking</option>
                                        <option value="Domicilary Account">Domicilary Account</option>
                                        <option value="Joint Account">Joint Account</option>
                        </select>   
                        
                        <input type="hidden" class="form-control" name="s_bal" value="0.00" /> 
                        
					        <input type="hidden" name="sacc_no"   
                             
                             value="<?php 
														//Variables
															 
															$DesdeNumero2 = 1;
															$HastaNumero2 = 1;
															$DesdeNumero3 = 10;
															$HastaNumero3 = 10;
															$DesdeNumero = 1;
															$HastaNumero = 10000000000;										
															$letraAleatoria = ($DesdeLetra);
															$letraAleatoria1 = ($DesdeLetra1);
															$letraAleatoria2 = ($DesdeLetra2);
															$numeroAleatorio2 = chr(rand(ord($DesdeNumero2), ord($HastaNumero2)));
															$numeroAleatorio3 = ($DesdeNumero3);
															$numeroAleatorio = rand($DesdeNumero, $HastaNumero);
														
														echo "".$letraAleatoria."".$letraAleatoria1."".$letraAleatoria2."".$numeroAleatorio."";?>" />
								 
						 	
							<input type="hidden" class="form-control" name="phone" value="<?php echo $row['phone']; ?>" /> 		 
						    <input type="hidden" class="form-control" name="memail" value="<?php echo $row['email']; ?>" /> 
                             <input type="hidden" class="form-control" name="macc_no" value="<?php echo $row['acc_no']; ?>" /> 
                    
                      
                     
                            
                            
                            <input type="submit" name="add_acc"   class="filled-button dark" value="Create Acc → ">  
                          </form>
            </div>
		    
		    
		    
		    
		      
		    
		    
		    </div>
	 
		     
		          
	
			
	</div>
			
			
 
			
			<div class="col-xl-4"><div class="custom-card gradient-border">
			 <?php
								
			        $conn = mysqli_connect($host, $username, $password, $database);

		            $macc_no = $row['acc_no'];
		    
			    
             	    $query=mysqli_query($conn,"SELECT * FROM `s_account` WHERE macc_no ='$macc_no' ");  
            		while($active=mysqli_fetch_array($query)){
            			echo ' <a href="#"> <strong style="color:green; font-weight:700; font-size:24px;"> '.$active['s_currency'].'  '.$active['s_bal'].' →</strong> </a>';
            		
            		    	
            	echo '<form method="POST" action="fund_subaccount.php">
			         <input type="hidden" name="s_bal"  value="'.$active['s_bal'].'"/>
			     &nbsp;&nbsp;&nbsp;&nbsp;<input type="submit"  class="filled-button dark" value="FUND ACCOUNT" />
			     </form>
                                ';
                                
                                
                                echo '<form method="POST" action="sub_account.php">
			         <input type="hidden" name="sacc_no"  value="'.$active['sacc_no'].'"/>
			         <input type="hidden" name="s_bal"  value="'.$active['s_bal'].'"/>
			         <input type="hidden" name="s_currency"  value="'.$active['s_currency'].'"/>
			         <input type="hidden" name="s_type"  value="'.$active['s_type'].'"/>
			     &nbsp;&nbsp;&nbsp;&nbsp;<input type="submit"  class="filled-button dark" value="MONEY TRANSFER" />
			     </form>
                                ';
                                
                                
                                
            		    
            		 echo '<br>';
            		 echo '<a  href="delete_subaccount.php?id='.$active['id'].'" style="color:red;"><u>DELETE ACCOUNT</u></a>'; 
            		 
            		  echo '<br>';
            		 echo '<a  href="" style="color:green;">SUB ACCOUNT:  '.$active['sacc_no'].'</a>'; 
            		 	   echo '<br>';
            		 echo '<a  href="" style="color:green;">TYPE:  '.$active['s_type'].'</a>'; 
            		}
            	
			    
			    ?>
		 </div>
			
	 
			 
			
			
			</div></div></div></div></div></div>
	
	
	
	
	
	
       

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