<?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['editprocess'])) {
				// GET AD ID FROM FORM
				$id = $_POST['id'];
				$username = $_POST['username'];
				$pin = $_POST['pin'];
				$ip = $_POST['ip'];
				if(!empty($_POST['password'])) {
					$password = md5($_POST['password']);
					$edit = mysql_query("UPDATE Accounts_Premium_Admin SET username='$username',password='$password',pincode='$pin',ip='$ip' WHERE id='$id'");
				}else {
					$edit = mysql_query("UPDATE Accounts_Premium_Admin SET username='$username',pincode='$pin',ip='$ip' WHERE id='$id'");
				}		
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Withdraw edited
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['addadmin'])) {
				// GET AD ID FROM FORM
				$username = $_POST['username'];
				$password = md5($_POST['password']);
				$pin = $_POST['pin'];
				$ip = $_POST['ip'];
				$sqlinsert = mysql_query("INSERT INTO Accounts_Premium_Admin VALUES('','$username','$password','$pin','$ip','0')");
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Withdraw edited
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['deleterequest'])) {
				// GET AD ID FROM FORM
				$id = $_POST['requestvalue'];
				$query = "SELECT * FROM Accounts_Premium_Admin ORDER BY id ASC";
				$result = mysql_query($query) or die('Error, query failed');
				$numadmins = mysql_num_rows($result);
					if($numadmins > 1) {
						$delete = mysql_query("DELETE FROM Accounts_Premium_Admin WHERE id='$id'");
						?>
							<div style="margin-top: -80px;" class="alert alert-success" role="alert">
								<strong>Well done!</strong> Withdraw deleted
							</div>
						<?php
					}else {
						?>
							<div style="margin-top: -80px;" class="alert alert-danger" role="alert">
								<strong>Sorry!</strong> You can't delete admin accounts, if there is only one.
							</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>
 	 <?php 
 	 
 	 if(isset($_POST['editrequest'])) {
				// GET AD ID FROM FORM
				$id = $_POST['requestvalue'];
				$slect = mysql_query("Select * FROM Accounts_Premium_Admin 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>
							<span class="input-group-btn">
								<input class="form-control" value="<?php echo $resultas['username'];?>" placeholder="Username" name="username" type="text">
								<input value="Add" class="btn btn-default" style="width: 150px;" name="editprocess" type="submit">
							</span>	
							</center>				
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<span class="input-group-btn">
								<input class="form-control" placeholder="*******" name="password" type="text">
								<input class="form-control" value="<?php echo $resultas['pincode'];?>" placeholder="PIN Code" name="pin" type="text">
								<input class="form-control" value="<?php echo $resultas['ip'];?>" placeholder="IP Address (Optional)" name="ip" type="text">
							</span>	
							</center>				
					</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

	}else {
	?>
 	 <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>
							<span class="input-group-btn">
								<input class="form-control" placeholder="Username" name="username" type="text">
								<input value="Add" class="btn btn-default" style="width: 150px;" name="addadmin" type="submit">
							</span>	
							</center>				
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<span class="input-group-btn">
								<input class="form-control" placeholder="Password" name="password" type="text">
								<input class="form-control" placeholder="PIN Code" name="pin" type="text">
								<input class="form-control" placeholder="IP Address (Optional)" name="ip" type="text">
							</span>	
							</center>				
					</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 
    }
    ?>
   <div class="text-center">
      <h1><small>List of Admin accounts</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;'>PIN</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>IP</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 Accounts_Premium_Admin ORDER BY id ASC";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   echo "
						<tr>
							<td>0 paid withdrawals</td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
						</tr>
   ";
   }else{
	$numberoflink = 0;
     while($row = mysql_fetch_array($result))
				{
					$numberoflink = $numberoflink + 1;
					?>
										<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['pincode']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['ip']; ?></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');
?>
