<?php
// INCLUDE HEADER IN PAGE
include('other_header.php');
// GET CURRENT DATE AND TIME
$date = date('Y-m-d H:i:s');
if(isset($_POST['success'])) {
	if($_POST['success'] == 'loggedin') {
	?>
	<div style="margin-top: -80px;" class="alert alert-success" role="alert">
		<strong>Well done!</strong> Successfully logged in.
	</div>
	<?php
	}
}

if(isset($_POST['cancel'])) {
			$query = "SELECT * FROM Web_Withdraws WHERE gateway='2' AND manager_username='$session_username' AND status='-2' AND adminstatus='1' ORDER BY id ASC LIMIT 1";
			$result = mysql_query($query) or die('Error, query failed');

			if(mysql_num_rows($result)<1){
   		}else{
     		while($row = mysql_fetch_array($result))
				{
					$idCHECK = $row['id'];
					$usernameCHECK = $row['client_username'];
					$paymailCHECK = $row['client_paymail'];
					$amountCHECK = $row['amount'];
					$gatewayCHECK = $row['gateway'];
				}
			}
	$message = $_POST['message'];
	$message = AntiXSS::setEncoding($message, "UTF-8");
	$message = str_replace('"','',$message);
	$message = str_replace("'","",$message);
	$message = str_replace(">","",$message);
	$message = str_replace("<","",$message);
	$message = str_replace("</","",$message);
	$message = str_replace("&%","",$message);
	$message = str_replace("script","",$message);
	$message = str_replace("(","",$message);
	$message = str_replace(")","",$message);
	$withdrawid = $_POST['withdrawid'];
	$username = $_POST['username'];
	$paymail = $_POST['paymail'];
	$amount = $_POST['amount'];
	$gateway = $_POST['gateway'];
	if($withdrawid == $idCHECK) {
		if($username == $usernameCHECK) {
			if($paymail == $paymailCHECK) {
				if($amount == $amountCHECK) {
					if($gateway == $gatewayCHECK) {
						$edit = mysql_query("UPDATE Web_Withdraws SET message='$message',status='0' WHERE id='$withdrawid' AND client_username='$username' AND client_paymail='$paymail' AND amount='$amount' AND gateway='$gateway'");
						$edit = mysql_query("UPDATE Accounts_Premium_Payments SET payza_cashback=payza_cashback + '$amount' WHERE username='$session_username'");
					}
				}
			}
		}
	}
}

if(isset($_POST['markaspaid'])) {
			$query = "SELECT * FROM Web_Withdraws WHERE gateway='2' AND manager_username='$session_username' AND status='-2' AND adminstatus='1' ORDER BY id ASC LIMIT 1";
			$result = mysql_query($query) or die('Error, query failed');

			if(mysql_num_rows($result)<1){
   		}else{
     		while($row = mysql_fetch_array($result))
				{
					$idCHECK = $row['id'];
					$usernameCHECK = $row['client_username'];
					$paymailCHECK = $row['client_paymail'];
					$amountCHECK = $row['amount'];
					$gatewayCHECK = $row['gateway'];
				}
			}
	
	$withdrawid = $_POST['withdrawid'];
	$username = $_POST['username'];
	$paymail = $_POST['paymail'];
	$amount = $_POST['amount'];
	$gateway = $_POST['gateway'];
	$q1 = "SELECT `data5` FROM `Web_Gateways` WHERE `id` = '$gateway'";
	$r1 = mysql_query($q1) or die($q1."<br/><br/>".mysql_error());
	$d1 = mysql_result($r1, 0);
	$message = $d1;
	if($withdrawid == $idCHECK) {
		if($username == $usernameCHECK) {
			if($paymail == $paymailCHECK) {
				if($amount == $amountCHECK) {
					if($gateway == $gatewayCHECK) {
						$edit1 = mysql_query("UPDATE Web_Withdraws SET message='$message',status='1' WHERE id='$withdrawid' AND client_username='$username' AND client_paymail='$paymail' AND amount='$amount' AND gateway='$gateway'");
						$edit2 = mysql_query("UPDATE Accounts_Premium_Payments SET paid=paid + '$amount' WHERE username='$session_username'");
					}
				}
			}
		}
	}
	?>
	<div style="margin-top: -80px;" class="alert alert-success" role="alert">
		<strong>Well done!</strong> Payment marked as paid.
	</div>
	<?php
}
?>
  <div class="container">
    <div class="text-center">
      <h1><?php echo $title; ?>
      	<small>/Active is: Admin Account
			</small>
		</h1>
 	 </div>
		</br>
	<div class="text-center">
      <h1><small>Make this payout</small></h1>
 	</div>
		<?php
			$query = "SELECT * FROM Web_Withdraws WHERE gateway='2' AND manager_username='$session_username' AND status='-2' AND adminstatus='1' ORDER BY id ASC LIMIT 1";
			$result = mysql_query($query) or die('Error, query failed');

			if(mysql_num_rows($result)<1){
				?>
					<div class="jumbotron">
  						<h1>Thank you</h1>
  						<p>You paid all your assigned payments. Thank you for working for us.</p>
					</div>
					<?php
   		}else{
     		while($row = mysql_fetch_array($result))
				{
					$id = $row['id'];
					$username = $row['client_username'];
					$paymail = $row['client_paymail'];
					$amount = $row['amount'];
					$gateway = $row['gateway'];
					$q1 = "SELECT `name` FROM `Web_Gateways` WHERE `id` = '$gateway'";
					$r1 = mysql_query($q1) or die($q1."<br/><br/>".mysql_error());
					$gatewayname = mysql_result($r1, 0);
					?>
					<div class="jumbotron">
  						<h1><?php echo $gatewayname;?></h1>
  						<p>Client Username: <?php echo $username;?></p>
  						<p>Client Paymail: <?php echo $paymail;?></p>
  						<p>Payout amount: <?php echo $amount;?> <?php echo $acu['ISO']; ?></p>
  						<form method='post'>
  							<input class='btn btn-primary' type='hidden' name='withdrawid' value='<?php echo $id;?>'>
  							<input class='btn btn-primary' type='hidden' name='username' value='<?php echo $username;?>'>
  							<input class='btn btn-primary' type='hidden' name='paymail' value='<?php echo $paymail;?>'>
  							<input class='btn btn-primary' type='hidden' name='amount' value='<?php echo $amount;?>'>
  							<input class='btn btn-primary' type='hidden' name='gateway' value='<?php echo $gateway;?>'>
  							<div class="col-sm-6">
   					       <input type='submit' name='markaspaid' value='Mark as paid & Go to next' class='btn btn-primary'>
   						</div>
   						<div class="col-sm-6">
         					<center>
         						<div class='form-group has-success'>
										<div class="input-group">
               						<input type='text' name='message' placeholder='Message text' class='form-control'>
               						<span class="input-group-btn">
               							<input type='submit' name='cancel' value='Cancel and save message' class='btn btn-primary'>
            							</span>
           							</div>
									</div>
								</center>
  							</div></br></br></br></br>
  						</form>
  						<h2>Fast Messages</h2>
  						<p>Bad PayMail <input style='cursor:copy; opacity: 1' class='form-control autosize' rows='1' value="We can't send money to this payment email. Please check payment email and create withdraw request again." onmouseover='this.select()' readonly></p>
  					</div>
					<?php
				}
       	}
     	?>
</div>

<?php
include('other_footer.php');
?>
