<?php
// INCLUDE HEADER IN PAGE
include('other_header.php');
// GET CURRENT DATE AND TIME
$date = date('Y-m-d H:i:s');
if($proofmove == '1') {
	$move = '-21px';
}else {
	$move = '-80px';
}
?>
<?php
if(isset($_POST['success'])) {
	if($_POST['success'] == 'loggedout') {
	?>
	<div style="margin-top: <?php echo $move;?>;" class="alert alert-success" role="alert">
		<strong><?php echo $a252; ?>!</strong> <?php echo $a241; ?>
	</div>
	<?php
	}
	if($_POST['success'] == 'accountsignedup') {
	?>
	<div style="margin-top: <?php echo $move;?>;" class="alert alert-success" role="alert">
		<strong><?php echo $a252; ?>!</strong> <?php echo $a230; ?>
	</div>
	<?php
	}
	if($_POST['success'] == 'accountactivated') {
	?>
	<div style="margin-top: <?php echo $move;?>;" class="alert alert-success" role="alert">
		<strong><?php echo $a252; ?>!</strong> <?php echo $a264; ?>
	</div>
	<?php
	}
	if($_POST['success'] == 'checkmail') {
	?>
	<div style="margin-top: <?php echo $move;?>;" class="alert alert-success" role="alert">
		<strong><?php echo $a252; ?>!</strong> <?php echo $a344; ?>
	</div>
	<?php
	}
}
?>
<?php
if(isset($_POST['error'])) {
	if($_POST['error'] == 'notexist') {
	?>
	<div style="margin-top: <?php echo $move;?>;" class="alert alert-danger" role="alert">
		<strong><?php echo $a343; ?>!</strong> <?php echo $a265; ?>
	</div>
	<?php
	}
	if($_POST['error'] == 'activate') {
	?>
	<div style="margin-top: <?php echo $move;?>;" class="alert alert-danger" role="alert">
		<strong><?php echo $a343; ?>!</strong> <?php echo $a266; ?>
	</div>
	<?php
	}
	if($_POST['error'] == 'fillall') {
	?>
	<div style="margin-top: <?php echo $move;?>;" class="alert alert-danger" role="alert">
		<strong><?php echo $a343; ?>!</strong> <?php echo $a267; ?>
	</div>
	<?php
	}
	if($_POST['error'] == 'userexist') {
	?>
	<div style="margin-top: <?php echo $move;?>;" class="alert alert-danger" role="alert">
		<strong><?php echo $a343; ?>!</strong> <?php echo $a268; ?>
	</div>
	<?php
	}
	if($_POST['error'] == 'repeatpassword') {
	?>
	<div style="margin-top: <?php echo $move;?>;" class="alert alert-danger" role="alert">
		<strong><?php echo $a343; ?>!</strong> <?php echo $a269; ?>
	</div>
	<?php
	}
}

if($_POST['submit']) {
$url = $_POST['url'];
	$badurl = 0;
	// Remove all illegal characters from a url
	$url = filter_var($url, FILTER_SANITIZE_URL);
	
	if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&#\/%?=~_|!:,.;]*[-a-z0-9+&#\/%=~_|]/i",$url)) {
  		$badurl = 1;
  		?>
  		<div style="margin-top: <?php echo $move;?>;" class="alert alert-danger" role="alert">
			<strong><?php echo $a265; ?>!</strong> <?php echo $a270; ?> http://google.com
		</div>
		<?php
	}elseif (!preg_match("*[.]*",$url)) {
  		$badurl = 1;
  		?>
  		<div style="margin-top: <?php echo $move;?>;" class="alert alert-danger" role="alert">
			<strong><?php echo $a265; ?>!</strong> <?php echo $a270; ?> http://google.com
		</div>
		<?php
	}elseif (!isset($url)) {
	   $badurl = 1;
	   ?>
  		<div style="margin-top: <?php echo $move;?>;" class="alert alert-danger" role="alert">
			<strong><?php echo $a265; ?>!</strong> <?php echo $a270; ?> http://google.com
		</div>
		<?php
	}elseif (!filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === true) {
		$badurl = 1;
		?>
  		<div style="margin-top: <?php echo $move;?>;" class="alert alert-danger" role="alert">
			<strong><?php echo $a265; ?>!</strong> <?php echo $a270; ?> http://google.com
		</div>
		<?php
	}else {
		?>
  		<div style="margin-top: <?php echo $move;?>;" class="alert alert-success" role="alert">
			<strong><?php echo $a252; ?>!</strong> <?php echo $a271; ?>
		</div>
		<?php
	}
}
?>
  <div class="container">
  	<?php 
  	if($showlogo == '1') { 
  	?>
	<div class="col-md-8 col-md-offset-2">
		<center>	 	
	 		<a target="_blank" href="f.home"><img style="width: <?php echo $logowidth; ?>%" src="<?php echo $logourl; ?>"></a>
		</center>	 
	 </div>
	 </br>
	 <?php
	 }
	 ?>
	 <div class="col-md-8 col-md-offset-2 text-center">
	 	<h1><?php echo $title; ?> <small>/ <?php echo $a026; ?></small></h1>
	 </div>
	</br>

    <!-- BASE CSS   =========================================================== -->

    <!-- Tables -->
<?php
if($_POST['submit']) {
$url = $_POST['url'];
$adtitle = $sa['nologintitle'];
$url = AntiXSS::setEncoding($url, "UTF-8");
$url = str_replace('"','',$url);
$url = str_replace("'","",$url);
$url = str_replace(">","",$url);
$url = str_replace("<","",$url);
$url = str_replace("</","",$url);
$url = str_replace("&%","",$url);
$url = str_replace("script","",$url);
$url = str_replace("(","",$url);
$url = str_replace(")","",$url);
	
	if($badurl == 1){
		?>
		<div class="row">
      <div class="col-md-8 col-md-offset-2">
		<div class="well">
			<div class="row">
				<form name="csrf_form" id="shrinkform" action="" method="POST">
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="" class="input-group">
							<input class="form-control" placeholder="http://" name="url" type="text">
							<span class="input-group-btn">
								<input value="<?php echo $a012; ?>" class="btn btn-default" style="width: 150px;" name="submit" type="submit">
							</span>				
					</div>
					<input type="hidden" name="csrf_token" value="<?php echo $token; ?>">
				</form>
				</br>
				<div class="col-md-10 col-md-offset-2">
					<h4><?php echo $a015; ?> (http://google.com)</h4>
				</div>
			</div>
        </div>
      </div>
    </div>
    <?php
	}elseif ($url){

	// THESE CHARACTERS ARE ALLOWED IN SHORTENED LINK ex. adp.ay/CHARACTER >> adp.ay/d6w8s9a4
  $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);
  }

	$url = mysql_real_escape_string($url);
  mysql_query("INSERT INTO Links_All VALUES ('', '$url', '$code','$uip','interstitial','0','0.00','$adtitle','')");
  $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){

?>
	<div class="row">
      <div class="col-md-8 col-md-offset-2">
		<div class="well">
			<div class="row">
				<form name="csrf_form" id="shrinkform" action="" method="POST">
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="" class="input-group">
							<input readonly="readonly" onmouseover="this.select()" style="cursor:copy; opacity: 1;text-align: center;" class="form-control" value='<?php echo"$mainurl$code"; ?>' name="url" type="text">
							<span class="input-group-btn">
								<input value="<?php echo $a013; ?>" class="btn btn-default" style="width: 150px;" name="createanother" type="submit">
							</span>				
					</div>
					<center>
					<div style="top: -5px;" class="fb-share-button" data-href="<?php echo"$mainurl$code"; ?>" data-layout="button"></div>
					<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php echo"$mainurl$code"; ?>" data-count="none">Tweet</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
					<div class="g-plus" data-action="share" data-annotation="none" data-href="<?php echo"$mainurl$code"; ?>"></div>
					<script src="https://apis.google.com/js/platform.js" async defer>
  						{lang: 'en-GB'}
					</script>		
					<center>
					<input type="hidden" name="csrf_token" value="<?php echo $token; ?>">
				</form>
				</br>
				<div class="col-md-10 col-md-offset-2">
					<h4><?php echo $a021; ?> <?php echo $title; ?></h4>
				</div>
			</div>
        </div>
      </div>
    </div>	

<?php
  }
  else{
  echo"aaaaa";
  }     
 }
 else"<script type='text/javascript'>window.location='f.home'</script>";
}
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="shrinkform" action="" method="POST">
					<div data-original-title="Enter your long URL" data-toggle="tooltip" data-placement="top" title="" class="input-group">
							<input class="form-control" placeholder="http://" name="url" type="text">
							<span class="input-group-btn">
								<input value="<?php echo $a012; ?>" class="btn btn-default" style="width: 150px;" name="submit" type="submit">
							</span>				
					</div>
					<input type="hidden" name="csrf_token" value="<?php echo $token; ?>">
				</form>
				</br>
				</center>
				<center>
					<h4><?php echo $a016; ?></h4>
				</center>
			</div>
        </div>
      </div>
    </div>	
<?php
}
?>
<div class="col-sm-12">
		<center>
         <?php
		$homeblocks = $sa['homeblocks']; 
		if($homeblocks != '0') {        
         $query = "SELECT * FROM Web_Home_Blocks ORDER BY ordernum ASC LIMIT 3";
			$result = mysql_query($query) or die('Error, query failed');
			$numrows = mysql_num_rows($result);
			$cols = 12 / $numrows;
			
			$query = "SELECT * FROM Web_Home_Blocks WHERE ordernum='1' ORDER BY ordernum ASC LIMIT 1";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   		}else{
     		while($row = mysql_fetch_array($result))
				{
					?>
   				<div class="col-sm-<?php echo $cols; ?>">
   					<div class="well">
   						<h1><?php echo $row['name'];?></h1>
   						<p><?php echo $row['html'];?></p>
   					</div>
   				</div>
   				<?php
				}
       	}
			?>
			<?php
			$query = "SELECT * FROM Web_Home_Blocks WHERE ordernum='2' ORDER BY ordernum ASC LIMIT 1";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   		}else{
     		while($row = mysql_fetch_array($result))
				{
					?>
   				<div class="col-sm-<?php echo $cols; ?>">
   					<div class="well">
   						<h1><?php echo $row['name'];?></h1>
   						<p><?php echo $row['html'];?></p>
   					</div>
   				</div>
   				<?php
				}
       	}
			?>
			<?php
			$query = "SELECT * FROM Web_Home_Blocks WHERE ordernum='3' ORDER BY ordernum ASC LIMIT 1";
			$result = mysql_query($query) or die('Error, query failed');

			// print the random numbers
			
			if(mysql_num_rows($result)<1){
   		}else{
     		while($row = mysql_fetch_array($result))
				{
					?>
   				<div class="col-sm-<?php echo $cols; ?>">
   					<div class="well">
   						<h1><?php echo $row['name'];?></h1>
   						<p><?php echo $row['html'];?></p>
   					</div>
   				</div>
   				<?php
				}
       	}
       }
			?>
        </center>
        </div>
</div>
<?php
include('other_footer.php');
?>
