<?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['requestvalue'];//
				$username = $_POST['username'];//
				$email = $_POST['email'];//
				$balance = $_POST['balance'];
				$referral = $_POST['referral'];
				$name = $_POST['name'];
				$address = $_POST['address'];
				$city = $_POST['city'];
				$zip = $_POST['zip'];
				$telephone = $_POST['telephone'];
				$country = $_POST['country'];
				$active = $_POST['active'];
				if($active == '1') {
					$hash = '0';
				}
				if($active != '1') {
					$hash = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 45);
				}
				if(!empty($_POST['password'])) {
					$password = md5($_POST['password']);
					$edit = mysql_query("UPDATE Accounts_Classic_Publishers SET username='$username',password='$password',email='$email',balance='$balance',refid='$referral',name='$name',address='$address',city='$city',zipcode='$zip',telephone='$telephone',country='$country',hash='$hash' WHERE id='$id'");
				}else {
					$edit = mysql_query("UPDATE Accounts_Classic_Publishers SET username='$username',email='$email',balance='$balance',refid='$referral',name='$name',address='$address',city='$city',zipcode='$zip',telephone='$telephone',country='$country',hash='$hash' WHERE id='$id'");
				}
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Support Account edited
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['addpublisher'])) {
				// GET AD ID FROM FORM
				$id = $_POST['requestvalue'];//
				$username = $_POST['username'];//
				$email = $_POST['email'];//
				$password = md5($_POST['password']);//
				$balance = $_POST['balance'];//
				$referral = $_POST['referral'];//
				$name = $_POST['name'];//
				$address = $_POST['address'];//
				$city = $_POST['city'];//
				$zip = $_POST['zip'];//
				$telephone = $_POST['telephone'];//
				$country = $_POST['country'];//
				$active = $_POST['active'];//
				if($active == '1') {
					$hash = '0';
				}
				if($active != '1') {
					$hash = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 45);
				}
				$api = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 45);//
				$date = date('Y-m-d H:i:s');//
				$addaccount = mysql_query("INSERT INTO Accounts_Classic_Publishers VALUES ('','$username','$password','$email','','','','','','$referral','0','0.00','0.00','$balance','0','$name','$address','$city','$zip','$telephone','$country','$date','','','','','','','','','0','0','0','0','0','0','0','0','0','0','0','0','0','0','$hash','$api')");
				?>
					<div style="margin-top: -80px;" class="alert alert-success" role="alert">
						<strong>Well done!</strong> Support account added <?php echo $active; ?>
					</div>
				<?php

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////
			if(isset($_POST['deleterequest'])) {
				// GET AD ID FROM FORM
				$id = $_POST['requestvalue'];
				$query = "SELECT * FROM Accounts_Classic_Publishers ORDER BY id ASC";
				$result = mysql_query($query) or die('Error, query failed');
				$numadmins = mysql_num_rows($result);
				$delete = mysql_query("DELETE FROM Accounts_Classic_Publishers WHERE id='$id'");
				?>
							<div style="margin-top: -80px;" class="alert alert-success" role="alert">
								<strong>Well done!</strong> Support account 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>
 	 <?php 
 	 
 	 if(isset($_POST['editrequest'])) {
				// GET AD ID FROM FORM
				$id = $_POST['requestvalue'];
				$slect = mysql_query("Select * FROM Accounts_Classic_Publishers 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="Edit" 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" value="<?php echo $resultas['email'];?>" placeholder="Email" name="email" type="text">
								<input class="form-control" placeholder="******" name="password" type="text">
								<input class="form-control" value="<?php echo $resultas['balance'];?>" placeholder="Balance" name="balance" type="text">
								<input class="form-control" value="<?php echo $resultas['refid'];?>" placeholder="Referral" name="referral" type="text">
								<input class="form-control" value="<?php echo $resultas['name'];?>" placeholder="Name" name="name" type="text">
								<input class="form-control" value="<?php echo $resultas['address'];?>" placeholder="Address" name="address" type="text">
								<input class="form-control" value="<?php echo $resultas['city'];?>" placeholder="City" name="city" type="text">
								<input class="form-control" value="<?php echo $resultas['zipcode'];?>" placeholder="ZIP Code" name="zip" type="text">
								<input class="form-control" value="<?php echo $resultas['telephone'];?>" placeholder="Telephone" name="telephone" type="text">
							</span>	
							</center>				
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<select style="width:100%" class="form-control" name='country'>
								<option value="<?php echo $resultas['country']?>"><?php echo $resultas['country']?></option>
								<?php
									$countrieslist = mysql_query("SELECT * FROM Web_Countries ORDER BY id ASC");
									while($rowc = mysql_fetch_array($countrieslist)) 
									{
										echo"<option value='{$rowc['country']}'>{$rowc['country']}</option>";
									}
								?>
							</select>
							</center>				
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<?php
							$hash = $resultas['hash'];
							if($hash == '0') {
								$active = '1';
							}elseif(isset($hash)) {
								$active = '0';
							}else{
								$active = '1';
							}
							?>
							<input id="activated" class="toggle toggle-left" name="active" value="1" type="radio" <?php if($active == '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="activated" class="btn">Activated</label>
							<input id="deactivated" class="toggle toggle-right" name="active" value="0" type="radio" <?php if($active != '1'){echo 'checked';}?>><label style="min-width:30.2%;width:auto" class="btn btn-default" for="deactivated" class="btn">Deactivated</label>
							</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="addpublisher" 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="Email" name="email" type="text">
								<input class="form-control" placeholder="Password" name="password" type="text">
								<input class="form-control" placeholder="Balance" name="balance" type="text">
								<input class="form-control" placeholder="Referral" name="referral" type="text">
								<input class="form-control" placeholder="Name" name="name" type="text">
								<input class="form-control" placeholder="Address" name="address" type="text">
								<input class="form-control" placeholder="City" name="city" type="text">
								<input class="form-control" placeholder="ZIP Code" name="zip" type="text">
								<input class="form-control" placeholder="Telephone" name="telephone" type="text">
							</span>	
							</center>				
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<select style="width:100%" class="form-control" name='country'>
								<option value="<?php echo $link2['countries']?>"><?php echo $link2['countries']?></option>
								<?php
									$countrieslist = mysql_query("SELECT * FROM Web_Countries ORDER BY id ASC");
									while($rowc = mysql_fetch_array($countrieslist)) 
									{
										echo"<option value='{$rowc['country']}'>{$rowc['country']}</option>";
									}
								?>
							</select>
							</center>				
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<input id="activated" class="toggle toggle-left" name="active" value="1" type="radio" checked><label style="min-width:30.2%;width:auto" class="btn btn-default" for="activated" class="btn">Activated</label>
							<input id="deactivated" class="toggle toggle-right" name="active" value="0" type="radio"><label style="min-width:30.2%;width:auto" class="btn btn-default" for="deactivated" class="btn">Deactivated</label>
							</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;'>Email</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Referral</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Balance</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Country</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Activated</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_Classic_Publishers 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 accounts of type support</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;
					$refid = $row['refid'];
					if(isset($refid)) {
						$refuser = $row['refid'];
					}
					if(empty($refid)) {
						$refuser = '---';
					}
					
					$hash = $row['hash'];
					if($hash == '0') {
						$active = 'Yes';
					}else if(isset($hash)) {
						$active = 'No';
					}else{
						$active = 'Yes';
					}
					?>
										<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['email']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $refuser; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['balance']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $row['country']; ?></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><?php echo $active; ?></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');
?>
