<?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['editrequest'])) {
				// GET AD ID FROM FORM
				$id = $_POST['requestvalue'];
				$slect = mysql_query("Select * FROM Web_Deposits WHERE id='$id'");
				$resultas = mysql_fetch_array($slect);
				?>
	<div class="row">
      <div class="col-md-8 col-md-offset-2">
        <div class="well">
			<div class="row">
				<center>
				<form name="csrf_form" id="campaignform" action="" method="POST">
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<input class="form-control" value="<?php echo $resultas['message']?>" placeholder="Message" name="message" type="text">
							</center>
							<center>
							<input id="activated" class="toggle toggle-left" name="active" value="1" type="radio" <?php if($resultas['status'] == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="activated" class="btn">Paid</label>
							<input id="deactivated" class="toggle toggle-right" name="active" value="0" type="radio" <?php if($resultas['status'] == '0'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="deactivated" class="btn">Unpaid</label>
							</center>
							<center>
							<p>Action:</p>
							<input id="add" class="toggle toggle-left" name="action" value="1" type="radio"><label style="min-width:30.2%;width:auto" class="btn btn-default" for="add" class="btn">Add</label>
							<input id="nothing" class="toggle toggle-center" name="action" value="0" type="radio" checked><label style="min-width:30.2%;width:auto" class="btn btn-default" for="nothing" class="btn">Nothing</label>
							<input id="subtract" class="toggle toggle-right" name="action" value="-1" type="radio"><label style="min-width:30.2%;width:auto" class="btn btn-default" for="subtract" class="btn">Subtract</label>
							</center>
							<span class="input-group-btn">
								<input value="Edit" class="btn btn-default" style="width: 150px;" name="editprocess" type="submit">
							</span>					
					</div>
					<input type="hidden" name="csrf_token" value="<?php echo $token; ?>">
					<input type="hidden" name="requestvalue" value="<?php echo $id; ?>">
				</form>
				</br>
				</center>
			</div>
        </div>
      </div>
    </div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['editprocess'])) {
				// GET AD ID FROM FORM
				$id = $_POST['requestvalue'];
				$messagea = $_POST['message'];
				$active = $_POST['active'];
				$action = $_POST['action'];
				$edit = mysql_query("UPDATE Web_Deposits SET status='$active',message='$messagea' WHERE id='$id'");
				if($action == 1){
					$slect = mysql_query("Select * FROM Web_Deposits WHERE id='$id'");
					$resultas = mysql_fetch_array($slect);
					$username = $resultas['username'];
					$acctype = $resultas['accounttype'];
					$amount = $resultas['amount'];
					if($acctype == 'publisher') {
						$selectuser = mysql_query("Select * FROM Accounts_Classic_Publishers WHERE username='$username'");
						$resultuser = mysql_fetch_array($selectuser);
						$balance = $resultuser['balance'];
						$newbalance = $balance + $amount;
						$edit = mysql_query("UPDATE Accounts_Classic_Publishers SET balance='$newbalance' WHERE username='$username'");
					}else if($acctype == 'advertiser') {
						$selectuser = mysql_query("Select * FROM Accounts_Classic_Advertisers WHERE username='$username'");
						$resultuser = mysql_fetch_array($selectuser);
						$balance = $resultuser['balance'];
						$newbalance = $balance + $amount;
						$edit = mysql_query("UPDATE Accounts_Classic_Advertisers SET balance='$newbalance' WHERE username='$username'");
					}
				}else if($action == -1) {
					$slect = mysql_query("Select * FROM Web_Deposits WHERE id='$id'");
					$resultas = mysql_fetch_array($slect);
					$username = $resultas['username'];
					$acctype = $resultas['accounttype'];
					$amount = $resultas['amount'];
					if($acctype == 'publisher') {
						$selectuser = mysql_query("Select * FROM Accounts_Classic_Publishers WHERE username='$username'");
						$resultuser = mysql_fetch_array($selectuser);
						$balance = $resultuser['balance'];
						$newbalance = $balance - $amount;
						$edit = mysql_query("UPDATE Accounts_Classic_Publishers SET balance='$newbalance' WHERE username='$username'");
					}else if($acctype == 'advertiser') {
						$selectuser = mysql_query("Select * FROM Accounts_Classic_Advertisers WHERE username='$username'");
						$resultuser = mysql_fetch_array($selectuser);
						$balance = $resultuser['balance'];
						$newbalance = $balance - $amount;
						$edit = mysql_query("UPDATE Accounts_Classic_Advertisers SET balance='$newbalance' WHERE username='$username'");
					}					
				}
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Deposit edited
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['deleterequest'])) {
				// GET AD ID FROM FORM
				$id = $_POST['requestvalue'];
				$delete = mysql_query("DELETE FROM Web_Deposits WHERE id='$id'");
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Deposit deleted
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
?>
  <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>List of paid deposits</small></h1>
 	</div>
		<div class="col-sm-12">
          <table class="table table-bordered" style="width:100%;max-width:100%"  data-effect="fade">
										<thead>
											<tr>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>#</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Username</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Account type</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Gateway</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Amount</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Status</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Message</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'><?php echo $a061; ?></th>
											</tr>
										</thead>
		<?php
			$query = "SELECT * FROM Web_Deposits WHERE status='1' ORDER BY id DESC";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   echo "
						<tr>
							<td>No campaigns</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
   ";
   }else{
	$numberoflink = 0;
     while($row = mysql_fetch_array($result))
				{
					$numberoflink = $numberoflink + 1;
					if (empty($row['message'])) {
									$row['message'] = "---";
					};
					
					if ($row['status'] == 1){
						$adstatus = 'Paid';
					}else if ($row['status'] == 0){
						$adstatus = 'Unpaid';
					}
					?>
										<tr>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $numberoflink; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['username']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['accounttype']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['gateway']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $acu['ISO']; ?> <?php echo $row['amount']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $adstatus; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['message']; ?></h5>
											</td>
					<?php
					echo "				<form name='actions' action='' method='POST'>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<input type='hidden' name='requestvalue' value='{$row['id']}'>
												<input style ='float:right' value='$a090' class='btn btn-default' name='editrequest' type='submit'>
												<input style ='float:right' value='$a111' class='btn btn-default' name='deleterequest' type='submit'>
											</td>
											</form>
										</tr>";

				}

       }
	?>
									</table>
        </div>
        
    <div class="text-center">
      <h1><small>List of unpaid deposits</small></h1>
 	</div>
		<div class="col-sm-12">
          <table class="table table-bordered" style="width:100%;max-width:100%"  data-effect="fade">
										<thead>
											<tr>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>#</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Username</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Account type</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Gateway</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Amount</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Status</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Message</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'><?php echo $a061; ?></th>
											</tr>
										</thead>
		<?php
			$query = "SELECT * FROM Web_Deposits WHERE status='0' ORDER BY id DESC";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   echo "
						<tr>
							<td>No campaigns</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
   ";
   }else{
	$numberoflink = 0;
     while($row = mysql_fetch_array($result))
				{
					$numberoflink = $numberoflink + 1;
					if (empty($row['message'])) {
									$row['message'] = "---";
					};
					
					if ($row['status'] == 1){
						$adstatus = 'Paid';
					}else if ($row['status'] == 0){
						$adstatus = 'Unpaid';
					}
					?>
										<tr>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $numberoflink; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['username']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['accounttype']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['gateway']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $acu['ISO']; ?> <?php echo $row['amount']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $adstatus; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['message']; ?></h5>
											</td>
					<?php
					echo "				<form name='actions' action='' method='POST'>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<input type='hidden' name='requestvalue' value='{$row['id']}'>
												<input style ='float:right' value='$a090' class='btn btn-default' name='editrequest' type='submit'>
												<input style ='float:right' value='$a111' class='btn btn-default' name='deleterequest' type='submit'>
											</td>
											</form>
										</tr>";

				}

       }
	?>
									</table>
        </div>
</div>

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