<?php   
include "urlmo_common/config.php" ;
include "urlmo_common/database.class.php";

$path = $_SERVER['REQUEST_URI'];

/* strip the subdirectories until /go/  */

 $path = preg_replace("@.*?(/go/.*?)@","$1", $path); 


$var_array = explode("/",$path);

$var1 = $var_array[1];
$var2 = $var_array[2];

$campaign_name = $var2;

$db = new database();

// Read from the file and find the alias
     $q = "select destination_url, campaign_name, clicks from campaigns where campaign_name='$campaign_name'"; 
	$r = $db->get_a_line($q);
	@extract($r);
	
// Write Click to the file.
     $clicks++;
     $q = "update campaigns set clicks = $clicks where campaign_name = '$campaign_name'";	
     $r = $db->insert($q);
   
   if($destination_url<>""){
       // create the html here
       echo "<html>";
       echo "<head>";
       echo "<title>URL Makeover</title>";
       echo "</head>";
       echo "<frameset BORDER='0' FRAMESPACING='0' FRAMEBORDER='0' rows='0,*'><frame NAME='top' SCROLLING='no' MARGINWIDTH='0' MARGINHEIGHT='0'><frame NAME='main' SRC='$destination_url' SCROLLING='yes' MARGINWIDTH='0' MARGINHEIGHT='0'>";
       echo "<noframes>";
       echo "<head>";
       echo "<title>URL Makeover</title>";
       echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=$destination_url'>";
       echo "</head>";
       echo "<body>";
       echo "</body>";
       echo "</noframes>";
       echo "</frameset>";
       echo "</html>";
       exit;
   }

echo "<center><h1>The Redirect Destination URL does not exist. Please report this error to the web admin.</h1></center>";

?>