<?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 (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);
			// 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);
			// 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);
			if($badurlmedia == 0){
				if($badurlredir == 0){
					if ($urlredir&&$advtypeedit){
						// Update vales in DB
						?>
						<div style="margin-top: -80px;" class="alert alert-success" role="alert">
							<strong>Well done!</strong> Ad successfully created! <input value="Open" onclick="window.open('<?php echo $mainurl;?>get/testad.php?adtype=<?php echo $advtypeedit; ?>&url=<?php echo $urlredir; ?>&urlmedia=<?php echo $urlmedia; ?>')" class="btn btn-default" style="width: 150px;" type="button">
						</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
						</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
			}

}// WHEN FORM NOT SUBMITTED
?>
  <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>
	<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 style="width:100%" data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<input style="width:100%" class="form-control" placeholder="Media URL [Video or Banner]" name="urlmedia" type="text">
							</br>
							<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>
							<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>
							<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>
							</center>					
					</div>
					<input type="hidden" name="csrf_token" value="<?php echo $token; ?>">
				</form>
				</br>
				</center>
				<center>
					<h4>Create and test your ad campaign before publishing to public.</h4>
				</center>
			</div>
        </div>
      </div>
    </div>
</div>

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