<?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['addcredits'])) {
				// GET AD ID FROM FORM
				$id = $_POST['requestvalue'];
				$id = AntiXSS::setEncoding($id, "UTF-8");
				$id = str_replace('"','',$id);
				$id = str_replace("'","",$id);
				$id = str_replace(">","",$id);
				$id = str_replace("<","",$id);
				$id = str_replace("</","",$id);
				$id = str_replace("&%","",$id);
				$id = str_replace("script","",$id);
				$id = str_replace("(","",$id);
				$id = str_replace(")","",$id);
				// GET VALUE CREDITS FROM FORM
				$credits = $_POST['credits'];
				$credits = AntiXSS::setEncoding($credits, "UTF-8");
				$credits = str_replace('"','',$credits);
				$credits = str_replace("'","",$credits);
				$credits = str_replace(">","",$credits);
				$credits = str_replace("<","",$credits);
				$credits = str_replace("</","",$credits);
				$credits = str_replace("&%","",$credits);
				$credits = str_replace("script","",$credits);
				$credits = str_replace("(","",$credits);
				$credits = str_replace(")","",$credits);
				// DEFINE WHICH AD WANT USER EDIT BY ID AND USERNAME
				$cc = mysql_query("SELECT * FROM Ads_All WHERE id='$id' and owner='$session_username'");
				$ccf = mysql_fetch_array($cc);
				// GET ALL ALLOWED COUNTRIES
				$adcountryf = $ccf['countries'];
				// GET AD TYPE FROM DB
				$adtypef = $ccf['adtype'];
				// DEFINE PRICE FOR COUNTRIES 
				$getprices = mysql_query("SELECT * FROM Web_Countries WHERE country='$adcountryf'");
				// GET ALL PRICES FOR ACTUAL AD
				$getprices2 = mysql_fetch_array($getprices);
				// IF AD TYPE IS INTERSTITATIAL
				if($adtypef == 'interstitial') 
				{
					// GET PRICES FOR INTERSTITATIAL
					$percredit = $getprices2['ppvadv'];
				}
				// IF AD TYPE IS video
				if($adtypef == 'video') 
				{
					// GET PRICES FOR INTERSTITATIAL
					$percredit = $getprices2['cpvvideo'];
				}
				// IF AD TYPE IS BANNER
				if($adtypef == 'banner') 
				{
					// GET PRICES FOR BANNER
					$percredit = $getprices2['ppvbadv'];
				}
				// CALCULATE FINAL PRICE
				$finalprice = $percredit * $credits;
				// WHEN FINAL PRICE VALUE IS LESS THAN USER BALANCE >> UPDATE AD
				if($finalprice <= $seeA['balance']) 
				{
					$changetoplay = mysql_query("UPDATE Ads_All SET credits=credits + '$credits' WHERE id='$id' and owner='$session_username'");
					$updatebalance = mysql_query("UPDATE Accounts_Classic_Advertisers SET balance=balance - '$finalprice' WHERE username='$session_username'");
					$updatestats = mysql_query("UPDATE Web_Stats SET advcash7=advcash7 + '$finalprice' WHERE id='1'");
					?>
						<div style="margin-top: -80px;" class="alert alert-success" role="alert">
							<strong>Well done!</strong> Campaign successfully edited.
						</div>
					<?php
				}else {
					?>
						<div style="margin-top: -80px;" class="alert alert-danger" role="alert">
							<strong>Sorry!</strong> You don't have required balance on your account.
						</div>
					<?php
				}

			}// WHEN FORM NOT SUBMITTED
///////////////////////////////////////////////////////////////////

if (mysql_real_escape_string($_POST['submitad'])){
			// GET URL OF REDIRECTION FROM FORM
			$urlredir = $_POST['urlredir'];
			$urlredir = AntiXSS::setEncoding($urlredir, "UTF-8");
			$urlredir = str_replace('"','',$urlredir);
			$urlredir = str_replace("'","",$urlredir);
			$urlredir = str_replace(">","",$urlredir);
			$urlredir = str_replace("<","",$urlredir);
			$urlredir = str_replace("</","",$urlredir);
			$urlredir = str_replace("&%","",$urlredir);
			$urlredir = str_replace("script","",$urlredir);
			$urlredir = str_replace("(","",$urlredir);
			$urlredir = str_replace(")","",$urlredir);
			$urlredir = filter_var($urlredir, FILTER_SANITIZE_URL);
			
	$badurlredir = 0;	
	if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&#\/%?=~_|!:,.;]*[-a-z0-9+&#\/%=~_|]/i",$urlredir)) {
  		$badurlredir = 1;
	}
	if (!preg_match("*[.]*",$urlredir)) {
  		$badurlredir = 2;
	}
	if (!isset($urlredir)) {
	   $badurlredir = 3;
	}
	if (!filter_var($urlredir, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === true) {
		$badurlredir = 4;
	}
			// GET URL OF MEDIA FROM FORM
			$urlmedia = $_POST['urlmedia'];
			$urlmedia = AntiXSS::setEncoding($urlmedia, "UTF-8");
			$urlmedia = str_replace('"','',$urlmedia);
			$urlmedia = str_replace("'","",$urlmedia);
			$urlmedia = str_replace(">","",$urlmedia);
			$urlmedia = str_replace("<","",$urlmedia);
			$urlmedia = str_replace("</","",$urlmedia);
			$urlmedia = str_replace("&%","",$urlmedia);
			$urlmedia = str_replace("script","",$urlmedia);
			$urlmedia = str_replace("(","",$urlmedia);
			$urlmedia = str_replace(")","",$urlmedia);
			$urlmedia = filter_var($urlmedia, FILTER_SANITIZE_URL);
			if($urlmedia == '') {
				$urlmedia = 'http://urlurlemptyurl.com';
			}
	$badurlmedia = 0;
	if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&#\/%?=~_|!:,.;]*[-a-z0-9+&#\/%=~_|]/i",$urlmedia)) {
  		$badurlmedia = 1;
	}
	if (!preg_match("*[.]*",$urlmedia)) {
  		$badurlmedia = 2;
	}
	if (!isset($urlmedia)) {
	   $badurlmedia = 3;
	}
	if (!filter_var($urlmedia, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === true) {
		$badurlmedia = 4;
	}
			// GET ACTIVE STATUS FROM FORM
			$active = $_POST['active'];
			$active = AntiXSS::setEncoding($active, "UTF-8");
			$active = str_replace('"','',$active);
			$active = str_replace("'","",$active);
			$active = str_replace(">","",$active);
			$active = str_replace("<","",$active);
			$active = str_replace("</","",$active);
			$active = str_replace("&%","",$active);
			$active = str_replace("script","",$active);
			$active = str_replace("(","",$active);
			$active = str_replace(")","",$active);
			// GET AD TYPE FROM FORM
			$advtypeedit = $_POST['adtype'];
			$advtypeedit = AntiXSS::setEncoding($advtypeedit, "UTF-8");
			$advtypeedit = str_replace('"','',$advtypeedit);
			$advtypeedit = str_replace("'","",$advtypeedit);
			$advtypeedit = str_replace(">","",$advtypeedit);
			$advtypeedit = str_replace("<","",$advtypeedit);
			$advtypeedit = str_replace("</","",$advtypeedit);
			$advtypeedit = str_replace("&%","",$advtypeedit);
			$advtypeedit = str_replace("script","",$advtypeedit);
			$advtypeedit = str_replace("(","",$advtypeedit);
			$advtypeedit = str_replace(")","",$advtypeedit);
			// GET COUNTRY FROM FORM
			$countryinput = $_POST['countryinput'];
			$countryinput = AntiXSS::setEncoding($countryinput, "UTF-8");
			$countryinput = str_replace('"','',$countryinput);
			$countryinput = str_replace("'","",$countryinput);
			$countryinput = str_replace(">","",$countryinput);
			$countryinput = str_replace("<","",$countryinput);
			$countryinput = str_replace("</","",$countryinput);
			$countryinput = str_replace("&%","",$countryinput);
			$countryinput = str_replace("script","",$countryinput);
			$countryinput = str_replace("(","",$countryinput);
			$countryinput = str_replace(")","",$countryinput);
			$titlead = $_POST['title'];
			$titlead = AntiXSS::setEncoding($titlead, "UTF-8");
			$titlead = str_replace('"','',$titlead);
			$titlead = str_replace("'","",$titlead);
			$titlead = str_replace(">","",$titlead);
			$titlead = str_replace("<","",$titlead);
			$titlead = str_replace("</","",$titlead);
			$titlead = str_replace("&%","",$titlead);
			$titlead = str_replace("script","",$titlead);
			$titlead = str_replace("(","",$titlead);
			$titlead = str_replace(")","",$titlead);
			if($badurlmedia == 0){
				if($badurlredir == 0){
					if ($urlredir&&$active&&$advtypeedit&&$countryinput&&$titlead){
						// Update vales in DB
						$sqledit = mysql_query("INSERT INTO Ads_All VALUES('','$titlead','$session_username','$advtypeedit','$urlredir','$urlmedia','0','$countryinput','','','$active','0')");
						// Link Successfully edited
						?>
						<div style="margin-top: -80px;" class="alert alert-success" role="alert">
							<strong>Well done!</strong> Ad successfully created!
						</div>
						<?php
					}else {
						?>
						<div style="margin-top: -80px;" class="alert alert-danger" role="alert">
							<strong>Sorry!</strong> Please fill all required inputs!
						</div>
						<?php
					}
				}else {
						?>
						<div style="margin-top: -80px;" class="alert alert-danger" role="alert">
							<strong>Sorry!</strong> Please enter URL in right format, ex: http://google.com. You entered:<?php echo $urlredir;?> (<?php echo $badurlredir; ?>)
						</div>
						<?php
				}
			}else {
						?>
						<div style="margin-top: -80px;" class="alert alert-danger" role="alert">
							<strong>Sorry!</strong> Please enter media URL in right format, ex: http://google.com. You entered:<?php echo $urlmedia;?> (<?php echo $badurlmedia; ?>)
						</div>
						<?php
			}

}// WHEN FORM NOT SUBMITTED
 	 if(isset($_POST['editrequestcomplete'])) {
	$campaignid = $_POST['requestvalue'];
	$newtitle = $_POST['title'];
	$newtitle = AntiXSS::setEncoding($newtitle, "UTF-8");
	$newtitle = str_replace('"','',$newtitle);
	$newtitle = str_replace("'","",$newtitle);
	$newtitle = str_replace(">","",$newtitle);
	$newtitle = str_replace("<","",$newtitle);
	$newtitle = str_replace("</","",$newtitle);
	$newtitle = str_replace("&%","",$newtitle);
	$newtitle = str_replace("script","",$newtitle);
	$newtitle = str_replace("(","",$newtitle);
	$newtitle = str_replace(")","",$newtitle);
	$countryinput = $_POST['countryinput'];
	$countryinput = AntiXSS::setEncoding($countryinput, "UTF-8");
	$countryinput = str_replace('"','',$countryinput);
	$countryinput = str_replace("'","",$countryinput);
	$countryinput = str_replace(">","",$countryinput);
	$countryinput = str_replace("<","",$countryinput);
	$countryinput = str_replace("</","",$countryinput);
	$countryinput = str_replace("&%","",$countryinput);
	$countryinput = str_replace("script","",$countryinput);
	$countryinput = str_replace("(","",$countryinput);
	$countryinput = str_replace(")","",$countryinput);
	$urlredir = $_POST['urlredir'];
	$urlredir = AntiXSS::setEncoding($urlredir, "UTF-8");
	$urlredir = str_replace('"','',$urlredir);
	$urlredir = str_replace("'","",$urlredir);
	$urlredir = str_replace(">","",$urlredir);
	$urlredir = str_replace("<","",$urlredir);
	$urlredir = str_replace("</","",$urlredir);
	$urlredir = str_replace("&%","",$urlredir);
	$urlredir = str_replace("script","",$urlredir);
	$urlredir = str_replace("(","",$urlredir);
	$urlredir = str_replace(")","",$urlredir);
	$badurl = 0;	
	if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&#\/%?=~_|!:,.;]*[-a-z0-9+&#\/%=~_|]/i",$urlredir)) {
  		$badurl = 1;
	}elseif (!preg_match("*[.]*",$urlredir)) {
  		$badurl = 1;
	}elseif (!isset($urlredir)) {
	   $badurl = 1;
	}else if (!filter_var($urlredir, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === true) {
		$badurl = 1;
	}
	$urlmedia = $_POST['urlmedia'];
	$urlmedia = AntiXSS::setEncoding($urlmedia, "UTF-8");
	$urlmedia = str_replace('"','',$urlmedia);
	$urlmedia = str_replace("'","",$urlmedia);
	$urlmedia = str_replace(">","",$urlmedia);
	$urlmedia = str_replace("<","",$urlmedia);
	$urlmedia = str_replace("</","",$urlmedia);
	$urlmedia = str_replace("&%","",$urlmedia);
	$urlmedia = str_replace("script","",$urlmedia);
	$urlmedia = str_replace("(","",$urlmedia);
	$urlmedia = str_replace(")","",$urlmedia);
	if($urlmedia == '') {
		$urlmedia = 'http://urlurlemptyurl.com';
	}
	$badurlmedia = 0;	
	if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&#\/%?=~_|!:,.;]*[-a-z0-9+&#\/%=~_|]/i",$urlmedia)) {
  		$badurlmedia = 1;
	}elseif (!preg_match("*[.]*",$urlmedia)) {
  		$badurlmedia = 1;
	}elseif (!isset($urlmedia)) {
	   $badurlmedia = 1;
	}else if (!filter_var($urlmedia, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === true) {
		$badurlmedia = 1;
	}
	$advtype = $_POST['adtype'];
	if($advtype == 'interstitial') {
		$advtypeedit = 'interstitial';
	}elseif($advtype == 'video') {
		$advtypeedit = 'video';
	}elseif($advtype == 'banner') {
		$advtypeedit = 'banner';
	}else {
		$advtypeedit = 'interstitial';
	}
	$activeedit = $_POST['active'];
	if($activeedit == 1) {
		$activeupdate = 1;
	}elseif($activeedit == 0) {
		$activeupdate = 0;
	}else {
		$activeupdate = 1;
	}
	if($badurlmedia == 0){
		if($badurl == 0){
		$sqledit = mysql_query("UPDATE Ads_All SET title='$newtitle', adtype='$advtypeedit', url='$urlredir', imageurl='$urlmedia', countries='$countryinput', active='$activeupdate' WHERE id='$campaignid' AND owner='$session_username'");
		?>
		<div style="margin-top: -80px;" class="alert alert-success" role="alert">
			<strong>Well done!</strong> Campaign successfully edited.
		</div>
		<?php	
		}else {
		?>
		<div style="margin-top: -80px;" class="alert alert-danger" role="alert">
			<strong>Sorry!</strong> Please enter URL in right format, ex: http://google.com
		</div>
		<?php	
		}
	}else {
		?>
		<div style="margin-top: -80px;" class="alert alert-danger" role="alert">
			<strong>Sorry!</strong> Please enter Media URL in right format, ex: http://google.com
		</div>
		<?php	
	}
}
if(isset($_POST['deleterequest'])) {
	$campaignid = $_POST['requestvalue'];
	$link1 = mysql_query("SELECT * FROM Ads_All WHERE id='$campaignid' AND owner='$session_username'") or die('1');
	$link2 = mysql_fetch_array($link1);
	$credits = $link2['credits'];
	$country = $link2['countries'];
	// DEFINE PRICE FOR COUNTRIES 
	$getprices = mysql_query("SELECT * FROM Web_Countries WHERE country='$country'");
	// GET ALL PRICES FOR ACTUAL AD
	$getprices2 = mysql_fetch_array($getprices);
	// IF AD TYPE IS INTERSTITATIAL
	if($link2['adtype'] == 'interstitial') 
	{
		// GET PRICES FOR INTERSTITATIAL
		$percredit = $getprices2['ppvadv'];
	}
	// IF AD TYPE IS video
	if($link2['adtype'] == 'video') 
	{
		// GET PRICES FOR INTERSTITATIAL
		$percredit = $getprices2['cpvvideo'];
	}
	// IF AD TYPE IS BANNER
	if($link2['adtype'] == 'banner') 
	{
		// GET PRICES FOR BANNER
		$percredit = $getprices2['ppvbadv'];
	}
	$toaddmoney = $credits * $percredit;
	$updatebalance = mysql_query("UPDATE Accounts_Classic_Advertisers SET balance=balance + '$toaddmoney' WHERE username='$session_username'");
	$delete = mysql_query("DELETE FROM Ads_All WHERE id='$campaignid' AND owner='$session_username'");
	?>
	<div style="margin-top: -80px;" class="alert alert-success" role="alert">
		<strong>Well done!</strong> Campaign successfully deleted.
	</div>
	<?php
}
?>
  <div class="container">
    <div class="text-center">
      <h1><?php echo $title; ?>
      	<small>/
      			<?php
						$accounttypenow = $_SESSION['acctype'];
						if($accounttypenow == 0){//Publisher
					?>
							Active is: Publisher Account
					<?php
						}
						if($accounttypenow == 1){//Advertiser
					?>
							Active is: Advertiser Account
					<?php
						}
					?>
			</small>
		</h1>
 	 </div>
 	 </br>
 	 <?php
 	 	if(isset($_POST['editrequest'])) {
		$campaignid = $_POST['requestvalue'];
		$link1 = mysql_query("SELECT * FROM Ads_All WHERE id='$campaignid' AND owner='$session_username'") or die('1');
		$link2 = mysql_fetch_array($link1);
		$country = $link2['countries'];
		// DEFINE PRICE FOR COUNTRIES 
		$getprices = mysql_query("SELECT * FROM Web_Countries WHERE country='$country'");
		// GET ALL PRICES FOR ACTUAL AD
		$getprices2 = mysql_fetch_array($getprices);
		// IF AD TYPE IS INTERSTITATIAL
		if($link2['adtype'] == 'interstitial') 
		{
			// GET PRICES FOR INTERSTITATIAL
			$percredit = $getprices2['ppvadv'];
		}
		// IF AD TYPE IS video
		if($link2['adtype'] == 'video') 
		{
			// GET PRICES FOR INTERSTITATIAL
			$percredit = $getprices2['cpvvideo'];
		}
		// IF AD TYPE IS BANNER
		if($link2['adtype'] == 'banner') 
		{
			// GET PRICES FOR BANNER
			$percredit = $getprices2['ppvbadv'];
		}
	?>
		<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">
							<input class="form-control" value="<?php echo $link2['url']?>" placeholder="Iframe URL [Interstitial], Redirect URL [Video or Banner]" name="urlredir" type="text">
							<span class="input-group-btn">
								<input value="Edit" class="btn btn-default" style="width: 150px;" name="editrequestcomplete" type="submit">
							</span>
							<input type='hidden' name='requestvalue' value='<?php echo $campaignid; ?>'>
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<input style="width:50%" class="form-control" value="<?php echo $link2['imageurl']?>" placeholder="Media URL [Video or Banner]" name="urlmedia" type="text">
							<input style="width:50%" class="form-control" value="<?php echo $link2['title']?>" placeholder="Title" name="title" type="text">
							<select style="width:100%" class="form-control" name='countryinput'>
								<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>
							</br>
							<?php if($sa['interstitialactive'] == '1') {
							?>
							<input id="interstitial" class="toggle toggle-left" name="adtype" value="interstitial" type="radio" <?php if($link2['adtype'] == 'interstitial'){echo 'checked';}?>><label style="min-width:20%;width:auto" class="btn btn-default" for="interstitial" class="btn">Interstitial</label>
							<?php
							}
							?>
							<?php if($sa['banneractive'] == '1') {
							?>
							<input id="banner" class="toggle toggle-right" name="adtype" value="banner" type="radio" <?php if($link2['adtype'] == 'banner'){echo 'checked';}?>><label style="min-width:20%;width:auto" class="btn btn-default" for="banner" class="btn">Banner</label>
							<?php
							}
							?>
							<?php if($sa['videoactive'] == '1') {
							?>
							<input id="video" class="toggle toggle-right" name="adtype" value="video" type="radio" <?php if($link2['adtype'] == 'video'){echo 'checked';}?>><label style="min-width:20%;width:auto" class="btn btn-default" for="video" class="btn">Video</label>
							<?php
							}
							?>
							</br>
							<input id="activated" class="toggle toggle-left" name="active" value="1" type="radio" <?php if($link2['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($link2['active'] == '0'){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; ?>">
				</form>
				</br>
				</center>
			</div>
        </div>
        
        <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">
							<input class="form-control" placeholder="How much credits you want add?" name="credits" type="number">
							<span class="input-group-btn">
								<input value="Add" class="btn btn-default" style="width: 150px;" name="addcredits" type="submit">
							</span>
							<input type='hidden' name='requestvalue' value='<?php echo $campaignid; ?>'>
					</div>
					<div style="width:40%" data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<span style='padding: 10px;' class='label label-success'><b><?php echo $link2['countries']?> /1 credit/ = <?php echo $acu['ISO']." ".$percredit;?> </b></span></br>
							<span style='padding: 10px;' class='label label-success'><b>With your current balance, you can add max <?php $max = $seeA['balance']/$percredit; echo floor($max); ?> credits</b></span>
							</center>					
					</div>
					<input type="hidden" name="csrf_token" value="<?php echo $token; ?>">
				</form>
				</br>
				</center>
			</div>
        </div>
      </div>
    </div>
	<?php
	}
	if(!isset($_POST['editrequest'])) {
 	 ?>
	<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">
							<input class="form-control" placeholder="Iframe URL [Interstitial], Redirect URL [Video or Banner]" name="urlredir" type="text">
							<span class="input-group-btn">
								<input value="Create ad" class="btn btn-default" style="width: 150px;" name="submitad" type="submit">
							</span>
					</div>
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<input style="width:50%" class="form-control" placeholder="Media URL [Video or Banner]" name="urlmedia" type="text">
							<input style="width:50%" class="form-control" placeholder="Title" name="title" type="text">
							<select style="width:100%" class="form-control" name='countryinput'>
								<option value='ALL'>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>
							</br>
							<?php if($sa['interstitialactive'] == '1') {
							?>
								<input id="interstitial" class="toggle toggle-left" name="adtype" value="interstitial" type="radio" checked><label style="min-width:20%;width:auto" class="btn btn-default" for="interstitial" class="btn">Interstitial</label>
							<?php
							}
							?>
							<?php if($sa['banneractive'] == '1') {
							?>
							<input id="banner" class="toggle toggle-right" name="adtype" value="banner" type="radio"><label style="min-width:20%;width:auto" class="btn btn-default" for="banner" class="btn">Banner</label>
							<?php
							}
							?>
							<?php if($sa['videoactive'] == '1') {
							?>
							<input id="video" class="toggle toggle-right" name="adtype" value="video" type="radio"><label style="min-width:20%;width:auto" class="btn btn-default" for="video" class="btn">Video</label>
							<?php
							}
							?>
							</br>
							<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; ?>">
				</form>
				</br>
				</center>
				<center>
					<h4>Create traffic on your website, we will boost your business.</h4>
				</center>
			</div>
        </div>
      </div>
    </div>
    	<?php
 		}
	 	?>
	<div class="text-center">
      <h1><small>Advertiser's campaigns</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;'>ID</th>
												<th style='max-width:140px;color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'><?php echo $a004; ?></th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'><?php echo $a132; ?></th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Media URL</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'><?php echo $a025; ?></th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Credits</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Countries</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Active</th>
												<th style='color: #DF691A; background-color: #2B3E50;border-collapse: collapse;border: 1px solid #DF691A;'>Approved</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 Ads_All WHERE owner='$session_username' 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>
							<td></td>
							<td></td>
						</tr>
   ";
   }else{
	$numberoflink = 0;
     while($row = mysql_fetch_array($result))
				{
					$numberoflink = $numberoflink + 1;
					if (empty($row['title'])) {
									$row['title'] = "---";
					};
					if ($row['adtype'] == "interstitial"){
						$adtypenow = $a022;
					}else if ($row['adtype'] == "video"){
						$adtypenow = $a023;
					}else if ($row['adtype'] == "banner"){
						$adtypenow = $a062;
					}else $adtypenow = "Error";
					
					if ($row['active'] == 1){
						$adstatus = 'Yes';
					}else if ($row['active'] == 0){
						$adstatus = 'No';
					}
					
					if ($row['approved'] == 1){
						$adapproval = 'Yes';
					}else if ($row['approved'] == 0){
						$adapproval = 'Waiting';
					}
					$mediaurl = $row['imageurl'];
					if($mediaurl == 'http://urlurlemptyurl.com') {
						$mediaurl = $LANG['254']['definition'];
					}
					echo "
										<tr>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5>$numberoflink</h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5>{$row['id']}</h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5><a href='editcampaign.{$row['code']}'> {$row['title']}</a></h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<input style='cursor:copy; opacity: 1' class='form-control autosize' rows='1' value='" . $row['url'] . "' onmouseover='this.select()' readonly>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<input style='cursor:copy; opacity: 1' class='form-control autosize' rows='1' value='" . $mediaurl . "' onmouseover='this.select()' readonly>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<strong>$adtypenow</strong>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<span style='padding: 10px;' class='label label-success'>{$row['credits']}</span>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5>{$row['countries']}</h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5>$adstatus</h5>
											</td>
											<td style='color: #FFF; background-color: #DF691A;border-collapse: collapse;border: 1px solid #2B3E50;'>
												<h5>$adapproval</h5>
											</td>
											<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 value='$a090' class='btn btn-default' name='editrequest' type='submit'>
												<input value='$a111' class='btn btn-default' name='deleterequest' type='submit'>
											</td>
											</form>
										</tr>";

				}

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

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