<?php
include ('include/header.php');
?>
        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <link href="assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap-summernote/summernote.css" rel="stylesheet" type="text/css" />
        <!-- END PAGE LEVEL PLUGINS -->


</head>
<body class="page-header-fixed page-sidebar-closed-hide-logo">


<?php
include ('include/sidebar.php');
?>

 

		
            <!-- BEGIN CONTENT -->
            <div class="page-content-wrapper">
                <!-- BEGIN CONTENT BODY -->
                <div class="page-content">
                    <!-- BEGIN PAGE HEADER-->
                   
                    <!-- BEGIN PAGE TITLE-->
                    <h3 class="page-title"> Debit Client Balance
                        <small></small>
                    </h3>
                    <!-- END PAGE TITLE-->

					<hr>

					
					
					
					
					
			<div class="row">
			<div class="col-md-12">
                            <!-- BEGIN SAMPLE FORM PORTLET-->
                            <div class="portlet light bordered">
                                
                                <div class="portlet-body form">
                                    <form class="form-horizontal" action="" method="post" role="form">
                                        <div class="form-body">

		   
<?php

if($_POST)
{

$email = mysql_real_escape_string($_POST["email"]);
$amount = mysql_real_escape_string($_POST["amount"]);
//$msg = mysql_real_escape_string($_POST["msg"]);


$err1=0;
$err2=0;


$exist = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM user WHERE accountnumber='".$email."'"));

if($exist[0]!=1)
      {
$err1=1;
}

///if($amount<=0){
    ///$err2=1;
///}



$error = $err1;


if ($error == 0){
$cbal = mysql_fetch_array(mysql_query("SELECT wallet, firstname, lastname, email FROM user WHERE accountnumber='".$email."'"));
$newbal = $cbal[0]-$amount;
$res = mysql_query("UPDATE user SET wallet='".$newbal."' WHERE accountnumber='".$email."'");
echo mysql_error();
if($res){
	
	
echo "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>	

&#36;$amount Successfully Debited From $firstname $lastname ($email) ! <br>
Balance Updated &#36;$cbal[0] TO &#36;$newbal

</div>";



mysql_query("INSERT INTO transaction SET accountnumber='".$email."', amount='".$amount."', prebalance='".$cbal[0]."', postbalance='$newbal', status='Debited Successfully', ref='".$trx."', date='".$date."', time='".$time."', description= 'Debit Alert Of &#36;".$amount."', sig ='-'");

 //$mcred= $site_url.'/include/email/debit.php';
           //file_get_contents($mcred);
           
$from = $site_email;
$to = $cbal[3];
$subject = 'Debit Alert';

 
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
// Create email headers
$headers .= 'From: '.$from."\r\n".
    'Reply-To: '.$from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
 
$message = '

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <meta name="x-apple-disable-message-reformatting">
  <title></title>
  <!--[if mso]>
  <style>
    table {border-collapse:collapse;border-spacing:0;border:none;margin:0;}
    div, td {padding:0;}
    div {margin:0 !important;}
  </style>
  <noscript>
    <xml>
      <o:OfficeDocumentSettings>
        <o:PixelsPerInch>96</o:PixelsPerInch>
      </o:OfficeDocumentSettings>
    </xml>
  </noscript>
  <![endif]-->
  <style>
    table, td, div, h1, p {
      font-family: Arial, sans-serif;
    }
    @media screen and (max-width: 530px) {
      .unsub {
        display: block;
        padding: 8px;
        margin-top: 14px;
        border-radius: 6px;
        background-color: #555555;
        text-decoration: none !important;
        font-weight: bold;
      }
      .col-lge {
        max-width: 100% !important;
      }
    }
    @media screen and (min-width: 531px) {
      .col-sml {
        max-width: 27% !important;
      }
      .col-lge {
        max-width: 73% !important;
      }
    }
  </style>
</head>

<body style="margin:0;padding:0;word-spacing:normal;background-color:#939297;">
  <div role="article" aria-roledescription="email" lang="en" style="text-size-adjust:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;background-color:#939297;">
    <table role="presentation" style="width:100%;border:none;border-spacing:0;">
      <tr>
        <td align="center" style="padding:0;">
          <!--[if mso]>
          <table role="presentation" align="center" style="width:600px;">
          <tr>
          <td>
          <![endif]-->
          <table role="presentation" style="width:94%;max-width:600px;border:none;border-spacing:0;text-align:left;font-family:Arial,sans-serif;font-size:16px;line-height:22px;color:#363636;">
            <tr>
              <td style="padding:40px 30px 30px 30px;text-align:center;font-size:24px;font-weight:bold;">
                <a href="'.$site_url.'" style="text-decoration:none;"><img src="'.$site_image.'" width="10" alt="Logo" style="width:10%">&nbsp;<span style="color:black;">'.$site_name.'</a>
              </td>
            </tr>
            
            
<tr>
              <td style="padding:30px;background-color:#ffffff;">
                <h1 style="margin-top:0;margin-bottom:16px;font-size:26px;line-height:32px;font-weight:bold;letter-spacing:-0.02em;"><span style="color:red">Debit Alert</span></h1>
                <br>
               
                <a href="#" style="text-decoration:none;"><img src="'.$site_url.'/admin/deb.jpg" width="500" alt="" style="width:100%;height:auto;display:block;border:none;text-decoration:none;color:#363636;"></a>
                <br>
                <h4>Dear <b>'.$cbal[1].' '.$cbal[2].'</b></h4>
                <br>

                    <p>You have been debited a sum of $'.$amount.' from your account.
                    </p>
                    <br>
                    
                 <p>Time Of Transaction:  '.$date .' '.$time .'</p>
                    <br>
                    
                    <p> Current Balance:   '.$newbal.'</p>
                    <br>
                    
                    
                    <p>Available Balance:  '.$newbal.'</p>
                    <br>
                    
              </td>
            </tr>
            <tr>
              <td style="padding:35px 30px 11px 30px;font-size:0;background-color:#ffffff;border-bottom:1px solid #f0f0f5;border-color:rgba(201,201,207,.35);">
                <!--[if mso]>
                <table role="presentation" width="100%">
                <tr>
                <td style="width:145px;" align="left" valign="top">
                <![endif]-->
                
                <div class="col-lge" style="display:inline-block;width:100%;max-width:395px;vertical-align:top;padding-bottom:20px;font-family:Arial,sans-serif;font-size:16px;line-height:22px;color:#363636;">
                  <p style="margin-top:0;margin-bottom:12px;">You have received this email regarding to your account creation on '.$site_name.'. If you did not initiate such action, please Disregard this email.</p>
                  
                  <p style="margin:0;"><a href="'.$site_url.'" style="background: #ff3884; text-decoration: none; padding: 10px 25px; color: #ffffff; border-radius: 4px; display:inline-block; mso-padding-alt:0;text-underline-color:#ff3884"><!--[if mso]><i style="letter-spacing: 25px;mso-font-width:-100%;mso-text-raise:20pt">&nbsp;</i><![endif]--><span style="mso-text-raise:10pt;font-weight:bold;">See Home Page</span><!--[if mso]><i style="letter-spacing: 25px;mso-font-width:-100%">&nbsp;</i><![endif]--></a></p>
                  <br><br>
                  
                  <p>Best of luck!</p>
                  
            <h4>'.$site_name.' Team</h4>
            </div>
                </div>
                
                
             
              </td>
            </tr>
            
        <br>

            
              <td style="padding:30px;text-align:center;font-size:12px;background-color:#404040;color:#cccccc;">
                <p style="margin:0 0 8px 0;"><a href="http://www.facebook.com/" style="text-decoration:none;"><img src="https://assets.codepen.io/210284/facebook_1.png" width="40" height="40" alt="f" style="display:inline-block;color:#cccccc;"></a> <a href="http://www.twitter.com/" style="text-decoration:none;"><img src="https://assets.codepen.io/210284/twitter_1.png" width="40" height="40" alt="t" style="display:inline-block;color:#cccccc;"></a></p>
                <p style="margin:0;font-size:14px;line-height:20px;"><b>Legal:</b> This email message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please delete it from your device. '.$site_name.', does not accept responsibility for changes made to this message after it was sent. Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is acepted by '.$site_name.' in this regard and the recipient should carry out such virus and other checks as it considers appropriate. <br><br><a class="unsub" href="#" style="color:#cccccc;text-decoration:underline;"><b>&copy; '.$site_name.' 2022 </b></a></p>
              </td>
            </tr>
          </table>
          <!--[if mso]>
          </td>
          </tr>
          </table>
          <![endif]-->
        </td>
      </tr>
    </table>
  </div>
</body>
</html>


';

mail($to, $subject, $message, $headers);


}else{
	echo "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>	

Some Problem Occurs, Please Try Again. 

</div>";
}
} else {
	
if ($err1 == 1){
echo "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>    

ACCOUNT NUMBER $email NOT FOUND !!!

</div>";
}       
    
if ($err2 == 1){
echo "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>	

Amount Should Be a Positive Number!!!

</div>";
}		
	
}




}

?>										
										
										
										
										
										
                                        
                    <div class="form-group">
                    <label class="col-md-3 control-label"><strong>ACCOUNT NUMBER</strong></label>
                    <div class="col-md-6">
                     <input class="form-control input-lg" name="email" placeholder="" type="text">
                    </div>
                    </div>

                     
										
					<div class="form-group">
                    <label class="col-md-3 control-label"><strong>AMOUNT</strong></label>
                    <div class="col-md-6">

                    <div class="input-group mb15">
                      <input class="form-control input-md" name="amount" placeholder="" type="number">
                      <span class="input-group-addon">$</span>
                    </div>


                    </div>
                    </div>

                    



					 
                                            <div class="row">
                                                <div class="col-md-offset-3 col-md-6">
                                                    <button type="submit" class="btn blue btn-block">Submit</button>
                                                </div>
                                            </div>
											
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>		
                        </div><!---ROW-->		
					
					
					
					
					
					
			
					
					
					
					
					
					
                </div>
                <!-- END CONTENT BODY -->
            </div>
            <!-- END CONTENT -->
            
			


<?php
 include ('include/footer.php');
 ?>

        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <script src="assets/global/plugins/bootstrap-wysihtml5/wysihtml5-0.3.0.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap-markdown/lib/markdown.js" type="text/javascript"></script>
        <script src="./assets/global/plugins/bootstrap-markdown/js/bootstrap-markdown.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap-summernote/summernote.min.js" type="text/javascript"></script>
        <!-- END PAGE LEVEL PLUGINS -->
        <script>
        
    
        
        </script>
        
        <!-- BEGIN PAGE LEVEL SCRIPTS -->
        <script src="assets/pages/scripts/components-editors.min.js" type="text/javascript"></script>
        <!-- END PAGE LEVEL SCRIPTS -->

</body>
</html>