   <?php
    include("../scripts/functions.php");
    require ('../includes/PHPMailer.php');
    require ('../includes/SMTP.php');
    require ('../includes/Exception.php');       
    //defining name spacess
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    use PHPMailer\PHPMailer\SMTP;
    $j = $_SESSION['creditUserDetails'];
    if($j[0] == ""){
    	echo"<script>window.location.href='../admin/fund_user'</script>";
    }
    $id = $j[0]; $amount = $j[1]; $memo = $j[2]; $frequency= $j[3]; $scope= $j[4]; $emailNotify= $j[5]; $firstname= $j[6]; $lastname= $j[7]; $middlename= $j[8]; $email= $j[9]; $accountnumber= $j[10]; $accountbalance = $j[11];   
    for ($i=0; $i < $frequency; $i++) { 
		     $query = $conn->query("SELECT * FROM users WHERE id = '$id'");
            $row = mysqli_fetch_array($query);
            $accountbalance = $row['accountbalance'];
            $phone = $row['phone']; 
		     $transferToken = randomString(64);
            $ref = randomString(9);
            $dd = date("my");
            $dc = substr($sitename, 0, 3);
            $refNumber = strtoupper("$dc/$ref-$dd");
            $otp = randomNumber(6);
            $dated = date("d M Y, g:i a");
            $acctBal = $accountbalance + ($amount);
            $queryForTransfer = $conn->query("INSERT INTO transactions (scope, type, otp, refNumber, dated, amount, accountbalance, userid, description, token) VALUES ('$scope', 'Credit', '$otp', '$refNumber', '$dated', '$amount', '$acctBal', '$id', '$memo', '$transferToken')");
                $queryForBalUpdate = $conn->query("UPDATE users SET accountbalance = '$acctBal' WHERE id = '$id'");

     if ($emailNotify == "Yes") {
     $fullname = "$firstname $middlename $lastname";	
     $mail = new PHPMailer();
    $mail->isSMTP();
    $mail->Host = $smtp_host;
    $mail->SMTPAuth = true;
    $mail->CharSet = "UTF-8";
    $mail->Username = $smtp_username; 
    $mail->Password = $smtp_password;
    $mail->SMTPSecure = $smtp_auth;
    $mail->Port = $smtp_port;
    $mail->setFrom($smtp_username, $display_name);
    $mail->addReplyTo($smtp_username, $display_name);
    $mail->addAddress($email);
    $mail->Subject = "Credit alert Notification[$money $amount]";
    $mail->isHTML(true);
    $mail->Body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="x-apple-disable-message-reformatting" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="color-scheme" content="light dark" />
    <meta name="supported-color-schemes" content="light dark" />
    <title></title>
  
    <style>
th, td {
  border: 1px solid white;
  border-radius: 8px;
}
</style>
 
  </head>
  <body>
   <center style="width: 100%; background-color: #f5f6fa;">
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#f5f6fa">
<tbody>
<tr>
<td style="padding: 40px 0;">
<table style="width: 100%; max-width: 620px; margin: 0 auto;">
<tbody>
<tr>
<td style="text-align: center; padding-bottom: 25px;"><img style="float: right;" src="https://my.westoverholdingsllc.com/logo.png" alt="" width="118" height="24" /><a href="#"><img src="./?_task=mail&amp;_from=compose&amp;_id=96339455663ac51f7ef473&amp;_action=display-attachment&amp;_file=rcmfile70381672237678036753700" alt="" /></a></td>
</tr>
</tbody>
</table>
<table style="width: 100.16%; max-width: 620px; margin: 0px auto; background-color: #ffffff; height: 797px;">
<tbody>
<tr style="height: 753px;">
<td style="padding: 0px 30px 20px; height: 753px;">
<p style="margin-bottom: 10px;">Dear, '.$fullname.',</p>
<p style="margin-bottom: 10px; padding-left: 40px; text-align: center;">Your account has been credited</p>
<p style="margin-bottom: 10px; padding-left: 40px; text-align: center;"><span style="font-size: 12pt;"><strong>'.$money.' '.$amount.'</strong></span></p>
<p style="margin-bottom: 10px; padding-left: 40px; text-align: center;">&nbsp;</p>
<p style="margin-bottom: 10px; padding-left: 40px; text-align: center;">Transaction Summary</p>
<table style="height: 189px; width: 100%; border-collapse: collapse;" border="0">
<tbody>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">A/C Number:</span></td>
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">&nbsp; '.$accountnumber.'</span></td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">Account Name:</span></td>
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">&nbsp; '.$fullname.'</span></td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">Sender Name:</span></td>
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">&nbsp; '.$memo.'</span></td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">Reference Number:</span></td>
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">&nbsp; '.$acctBal.'Ilb'.$accountnumber.'7Qzx</span></td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">Transaction Branch:</span></td>
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">&nbsp; HEAD OFFICE</span></td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 21px; text-align: left;"><span style="font-size: 8pt;">Transaction Date:</span></td>
<td style="width: 50%; height: 21px; text-align: left;"><span style="font-size: 8pt;">&nbsp; '.date("d M Y").'</span></td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">Value Date:</span></td>
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">&nbsp; '.date("d M Y").'</span></td>
</tr>
<tr style="height: 24px;">
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">Available Balance:</span></td>
<td style="width: 50%; height: 24px; text-align: left;"><span style="font-size: 8pt;">&nbsp; '.$money.' '.$acctBal.'</span></td>
</tr>
</tbody>
</table>
<p><img src="https://my.westoverholdingsllc.com/1.jpeg" alt="" width="100%" /></p>
<p><img src="https://my.westoverholdingsllc.com/2.jpeg" alt="" width="100%" /></p>
</td>
</tr>
</tbody>
</table>
<table style="width: 100%; max-width: 620px; margin: 0 auto;">
<tbody>
<tr>
<td style="text-align: center; padding: 25px 20px 0;">
<p style="font-size: 13px;">&nbsp;</p>
<p style="padding-top: 15px; font-size: 12px;"><span style="font-size: 8pt;">Remember: Wintrust would <strong>NEVER </strong>call, SMS or email requesting for your card details, PIN, token codes, mobile/internet banking login details or other account related information. Pls DO NOT respond to such messages and contact us via livechat on our <a href="https://my.westoverholdingsllc.com/en/">website</a>, or email.</span>&nbsp;</p>
<p style="padding-top: 15px; font-size: 12px;">&nbsp;</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</center>
  </body>
</html>';
         $recipient = str_replace("+", "", $phone);
         $recipient = str_replace(" ", "", $phone);
         $des = $memo;
         $dex = "".strtoupper(substr($sitename, 0,3))."/".randomString(6)."/$des";
         $dated = date("d/m/Y, H:ia");
         $msg = "Credit alert\nAcct: ".substr($accountnumber, 0,3)."****".substr($accountnumber, 7,10)."\nAmt: $money ".number_format($amount)." CR\nDesc: $dex\nAcct Balance: $money ".number_format($acctBal)."\nTotal: $money ".number_format($acctBal)."\nDate: $dated";
         $sendSms = alertNotification($sms, $api, $sender_id, $msg, $recipient);
    if(!$mail->Send() && $sendSms == 0)
    {
    	unset($_SESSION['creditUserDetails']);
    echo "<script>window.location.href='../admin/user_profile?id=$id';</script>";
    }
    else
    {
    	unset($_SESSION['creditUserDetails']);
     echo "<script>window.location.href='../admin/user_profile?id=$id';</script>";   	
    }  
   }
     else{
     	unset($_SESSION['creditUserDetails']);
        echo "<script>window.location.href='../admin/user_profile?id=$id';</script>";
      } 
   
}
?>