<?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
	}
}
?>
  <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="text-center">
      <h1><small>Bulk Shortening</small></h1>
 	</div>
		<div class="col-sm-8 col-md-offset-2">
         <?php
         if(isset($_POST['urlshorter']))
			{
				$bigtext = checkerr($_POST['urlshorter']);
				$bigtext = AntiXSS::setEncoding($bigtext, "UTF-8");
				$bigtext = str_replace('"','',$bigtext);
				$bigtext = str_replace("'","",$bigtext);
				$bigtext = str_replace(">","",$bigtext);
				$bigtext = str_replace("<","",$bigtext);
				$bigtext = str_replace("</","",$bigtext);
				$bigtext = str_replace("&%","",$bigtext);
				$bigtext = str_replace("script","",$bigtext);
				$bigtext = str_replace("(","",$bigtext);
				$bigtext = str_replace(")","",$bigtext);
				$urlst = explode(",", $bigtext);
				$icount = 0;
				$adtype = $_POST['adtype'];
				if($adtype == 'interstitial') {
					$adverttype = 'interstitial';
				}elseif($adtype == 'banner') {
					$adverttype = 'banner';
				}elseif($adtype == 'video') {
					$adverttype = 'video';
				}elseif($adtype == 'none') {
					$adverttype = 'none';
				}else {
					$adverttype = 'interstitial';
				}
				$password = md5($_POST['password']);
				$passworddecoded = $_POST['password'];
				$passworddecoded = AntiXSS::setEncoding($passworddecoded, "UTF-8");
				while($icount < sizeof($urlst))
				{
					$cuntl = trim($urlst[$icount]);
					$icount++;
					if(!validLink($cuntl))
					{  
						echo"<div class='form-group has-error has-feedback'>
									<label class='control-label' for='inputError'>$cuntl</label>
									<input style='cursor:copy; opacity: 1' value='Error - Try again, and don&#39;t forget http:// at beginning >>> http://$cuntl' class='form-control' id='inputError' type='text' onmouseover='this.select()' readonly>
									<span class='glyphicon glyphicon-remove form-control-feedback'></span>
								</div>";
					}
					else
					{
						$charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    					$len = 5;
    					$numrows = 1;
  						while ($numrows != 0){
    						for ($i = 0; $i <= $len; $i++) {
      						$rand = rand() % strlen($charset);
      						$tmp = substr($charset,$rand, 1);
      						$code .= $tmp;
    						}
  							$query = mysql_query("SELECT * FROM Links_All WHERE code='$code'");
    						$numrows = mysql_num_rows($query);
						}
						mysql_query("INSERT INTO Links_All VALUES ('', '$cuntl', '$code','$session_username','$adverttype','0','0.00','BulkShortened{$icount}','$password')");
 						$qstats = mysql_query("UPDATE Web_Stats SET sclinks7=sclinks7 + '1' WHERE id='1'");
  						$query = mysql_query("SELECT * FROM Links_All WHERE code='$code'");
  						$numrows = mysql_num_rows($query);
  						if($numrows == 1){
  							$site = $_SERVER['HTTP_HOST'];
  							?>
  							<div class="panel panel-default">
            				<div class="panel-heading">
              					<h3 class="panel-title"><?php echo $icount; ?>. <?php echo $cuntl; ?></h3>
              					<small style="float:left">/Ad Type: <?php echo $adverttype; ?></small>
              					<small style="float:right">/Password: <?php echo $passworddecoded; ?></small><br>
            				</div>
            				<div class="panel-body">
            					<input style='cursor:copy; opacity: 1' value='<?php echo $mainurl.$code; ?>' class='form-control' id='inputSuccess' type='text' onmouseover='this.select()' readonly>
           					</div>
          				</div>
          				<?php
  						}
  						else
  						{
  							?>
  							<div class="panel panel-default">
            				<div class="panel-heading">
              					<h3 class="panel-title"><?php echo $icount; ?> <?php echo $cuntl; ?></h3>
              					<small style="float:left">/Ad Type: <?php echo $adverttype; ?>/small>
              					<small style="float:right">/Password: <?php echo $passworddecoded; ?></small><br>
            				</div>
            				<div class="panel-body">
            					Error, Link wasn't successfully imported into database, please try again
           					</div>
          				</div>
          				<?php
  						}
  					}
				$code = "";
				}
				?>
				<br/>
				<form action="" method="POST">
					<input class="ios_btn_spinner btn btn-primary" type="submit" name="submit" value='<?php echo $a191 ?>'>
				</form>
				<?php
			}
			else 
			{
			?>
				<p><?php echo $a190?></p>
				<form action="" method="POST">
					<textarea class="form-control" placeholder="http://google.com, http://youtube.com, http://twitter.com - Seperate them with commas" name="urlshorter" style="width:100%;height:35px;"></textarea><br />
					<div style="width: 100%;" data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="555" class="input-group">
							<center>
							<input class="form-control" placeholder="Password" name="password" type="text">
							<input id="interstitial" class="toggle toggle-left" name="adtype" value="interstitial" type="radio" checked><label class="btn btn-default" for="interstitial" class="btn">Interstitial</label>
							<input id="banner" class="toggle toggle-right" name="adtype" value="banner" type="radio"><label class="btn btn-default" for="banner" class="btn">Banner</label>
							<input id="video" class="toggle toggle-right" name="adtype" value="video" type="radio"><label class="btn btn-default" for="video" class="btn">Video</label>
							<input id="none" class="toggle toggle-right" name="adtype" value="none" type="radio"><label class="btn btn-default" for="none" class="btn">None</label>
							</center>					
					</div>
					<input class="ios_btn_spinner btn btn-primary" type="submit" name="submit" value='<?php echo $a091 ?>'>
				</form>
			<?php
			} 
			?>
      </div>
</div>

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