<?php
include '../functions.php';
if (isset($_GET['id']) == true) {
	$id = $_GET['id'];

	$sel_withdrawal = $conn->query("SELECT * FROM withdrawals WHERE id = '$id' ");
	$sel = mysqli_fetch_array($sel_withdrawal);
	$amount = $sel['amount'];
	$email = $sel['email'];
	$username = $sel['username'];
	$acc_no = $sel['acc_no'];
	$account_name = $sel['account_name'];
	$bank_name = $sel['bank_name'];
	$status = $sel['status'];
	$date_added = $sel['date_added'];
	$date = date_default_timezone_set('Africa/Lagos');
	$date = date('h:i:a d F Y');

	// var_dump($sel);

	$from = " ".strtoupper(sitename)." TEAM";
	$to = $email;

	$msg = "
<html>
<head>
	<title>Withdrawal Processed</title>
</head>

<style type='text/css'>
	@media only screen and (max-width : 640px) {
	
	table[class='container'] {
        width: 98% !important;
    } 
    td[class='bodyCopy'] p {
		padding: 0 15px !important; 
		text-align: left !important;
	}
    td[class='spacer'] {
	    width: 15px !important;
    }
    td[class='belowFeature'] {
	    width: 95% !important;
	    display: inline-block;
	    padding-left: 15px;
	    margin-bottom: 20px;
    }
    td[class='belowFeature'] img {
	    float: left;
	    margin-right: 15px;
    }
    
    table[class='belowConsoles'] {
		width: 100% !important;
		display: inline-block;
	}

	table[class='belowConsoles'] img {
		margin-right: 15px;
		margin-bottom: 15px;
		float: left;
	}
   
	
	}
	
	@media only screen and (min-width: 481px) and (max-width: 560px) {
	
	td[class='Logo'] {
		width: 560px !important;
		text-align: center;
	}
	
	td[class='viewWebsite'] {
		width: 560px !important;
		height: inherit !important;
		text-align: center;
	}    

	}
	
	@media only screen and (min-width: 250px) and (max-width: 480px) {
	
	td[class='Logo'] {
		width: 480px !important;
		text-align: center;
	}
	
	td[class='viewWebsite'] {
		width: 480px !important;
		height: inherit !important;
		text-align: center;
	}
	
	td[class='spacer'] {
	    display: none !important;
    }
	
	td[class='bodyCopy'] p {
		padding: 0 15px !important; 
		text-align: left !important;
	}
	
	td[class='bodyCopy'] h1 {
		padding: 0 10px !important;
	}
	
	h1, h2 {
		line-height: 120% !important;
	}
	
	td[class='force-width'] {width: 98% !important; padding: 0 10px;}
	
	[class='consoleImage'] {
		display: inline-block;
	}

	[class='consoleImage'] img {
		text-align: center !important;
		display: inline-block;
	}

	table[class='belowConsoles'] {
		text-align: center;
		float: none;
		margin-bottom: 15px;
		width: 100% !important;
	}

	table[class='belowConsoles'] img {
		margin-bottom: 0;
	}
	
	}
</style>

<body bgcolor='#f6f6f6' style='font-family: Arial; background-color: #f6f6f6;'>

<table width='630' bgcolor='#fcfcfc' style='border: 1px solid #dddddd; line-height: 135%;' class='container' align='center' cellpadding='0' cellspacing='0'>
	<tr>
		<td bgcolor='#fcfcfc' colspan='3' width='100%' height='10'>&nbsp;</td>
	</tr>
	<tr>
		<td bgcolor='#fcfcfc' colspan='3' align='center'>
			<img src='".sitelink."/images/logo.jpg' width='15%' style='border-radius: 50%;'>
		</td>
	</tr>
	<tr>
		<td colspan='3' height='15'>&nbsp;</td>
	</tr>
	<tr>
		<td bgcolor='#fcfcfc' colspan='3'>
			<table>
				<tr>
					<td width='30' class='spacer'>&nbsp;</td>
					<td align='center' class='bodyCopy'>
						<h1 style='font-family: Arial, Helvetica, sans-serif; font-size: 32px; color: #404040; margin-top: 0; margin-bottom: 20px; padding: 0; line-height: 135%' class='headline'>Withdrawal Processed</h1>
						<p style='font-family: Arial, Helvetica, sans-serif; color: #555555; font-size: 14px; padding: 0 40px;'>Your withdrawal request of ₦".$amount." has been completed. Thank you for using ".strtoupper(sitename)." FORUM</p>
					</td>
					<td width='30' class='spacer'>&nbsp;</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td colspan='3' class='force-width'>

			<div style='border:3px solid ; margin-right: 100px; margin-left: 100px; margin:50px;'>
				<div style='padding-left: 40px;'>
					<p><strong>Amount:</strong> ₦".$amount."</p>
					<p><strong>Account No:</strong> ".$acc_no."</p>
					<p><strong>Account Name:</strong> ".$account_name."</p>
					<p><strong>Bank Name:</strong> ".$bank_name."</p>
					<p><strong>Requested at:</strong> ".$date_added."</p>
					<p><strong>Status:</strong> ".$status."</p>
				</div>
				
			</div>


			<div style='text-align: center; border: 1px solid #dddddd; background-color: #6e6666; color:white; font-weight: bold; margin-left: 200px; margin-right: 200px; border-radius: 4px;'>
				<a href='".sitelink."/account/member' style='color: white; text-decoration: none;'><p>OPEN DASHBOARD</p></a>
			</div><br><br><br>

			<p style='text-align: center;'>If you did not initiate this withdrawal, please contact us immediately at ".sitemail."</p>
			<table width='213' align='left' style='border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;' class='belowConsoles'>
				<tr>
					<td width='35' class='spacer'></td>
					<td>
					</td>
				</tr>
			</table>
			<table width='193' align='left' style='border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;' class='belowConsoles'>
				<tr>
					<td width='15' class='spacer'></td>
					<td>
					</td>
				</tr>
			</table>
			<table width='193' align='left' style='border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;' class='belowConsoles'>
				<tr>
					<td width='15' class='spacer'></td>
					<td>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</body>
</html>
	";

	$headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    // Additional headers
	$headers .= 'From: '.strtoupper(sitename). " . " .sitemail."\r\n" .
	'Reply-To: '.sitemail."\r\n" .
    'Date: '.$date;

	// echo $msg;

	$sql = $conn->query("UPDATE withdrawals SET status = 'Paid' WHERE id = '$id' ");
	$send = mail($to, $from, $msg, $headers);
	// var_dump($send);
	if (isset($send) == true) {
		echo "<script>alert('Withdrawal has been Paid')</script>";
		echo "<script>window.open('withdrawals', '_self')</script>";
	}else{
		echo "<script>alert('Failed to update status')</script>";
		echo "<script>window.open('withdrawals', '_self')</script>";
	}
}