Bug 2658 - [Campaign Manager] - Store url when an ad is clicked/printed

Change-Id: I46721477af789952ed2642320f23bccaa6e499c3
Signed-off-by: Christopher Guindon <chris.guindon@eclipse-foundation.org>
diff --git a/redirector.php b/redirector.php
index 0d08249..33ed6c3 100644
--- a/redirector.php
+++ b/redirector.php
@@ -1,125 +1,29 @@
-<?php 
-/*******************************************************************************
- * Copyright (c) 2007-2013 Eclipse Foundation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+<?php
+/**
+ * Copyright (c) 2007, 2013, 2018, 2019 Eclipse Foundation.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
  * Contributors:
- *    Denis Roy (Eclipse Foundation)- initial implementation
- *******************************************************************************/
- 
- 
-    #*****************************************************************************
-    #
-    # redirector.php
-    #
-    # Author:       Denis Roy
-    # Date:         2007-09-07
-    #
-    # Description:  redirector for campaign URL tracking
-    #
-    #
-    #*****************************************************************************
+ * Denis Roy (Eclipse Foundation) - initial implementation
+ * Christopher Guindon (Eclipse Foundation)
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
 
-	function showErrorPage() {
-		require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php");
-		require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php");
-		$App 	= new App();	$Nav	= new Nav();	$Menu 	= new Menu();		
-		
-		$html = '<div id="maincontent">
-				<div id="midcolumn">
-					<h1>Expired Link</h1>
-			<p> There was an error processing this link.  It is likely you are following an old link to an expired campaign activity.  For example,
-			you may have clicked on a link to a survey that is now closed or to a special offer that is no longer applicable.  If you believe 
-			this link should work, please contact the source of the link.  While you are here, please browse some of our website by 
-			clicking on the appropriate tab at the top of the page.
-			</p>  
-			
-			<hr class="clearer" />
-			</div>
-		</div>';
-		$App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html);
-	}
+require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/ads/redirector.class.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php");
 
+$App = new App();
+$ts = gmdate("D, d M Y H:i:s") . " GMT";
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+header("Last-Modified: ". $ts);
+header("Expires:" . $ts);
 
-
-
-	require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php");
-	require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection_rw.class.php";
-	$App 	= new App();
-	
-	  # get the incoming parameters 
-	  # and Making sure the $_TAG is always uppercase
-    $_TAG = strtoupper($App->getHTTPParameter("tag", "GET"));
-
-	if(strlen($_TAG) < 1) {
-    	# error
-    	# header("Location: /");
-    	showErrorPage();
-    }
-    
-    
-    $x = stripos($_TAG, '@'); 
-    if ( $x !== FALSE) {
-    	$_SUBTAG = substr($_TAG, $x + 1);
-    	$_TAG = substr($_TAG, 0, $x);
-    	}
-     
-    # echo 'SUBTAG:' . $_SUBTAG . ' TAG:' . $_TAG . '<br>';
-    
-    # strip potentially bad characters from file
-    if ($_SUBTAG != "") $_SUBTAG = preg_replace('/["\'?%$#@!;*&]/i', '', $_SUBTAG);
-	$_TAG = preg_replace('/["\'?%$#@!;*&]/i', '', $_TAG);
-
-
-
-	
-
-	# Connect to databases
-	$dbc_RW 	= new DBConnectionRW();
-	$dbh_RW		= $dbc_RW->connect();
-
-
-	$SQL = "SELECT TargetUrl FROM Campaigns WHERE CampaignKey = " . $App->returnQuotedString($_TAG) . " AND DateExpires > CURDATE()";
-	$rs 	= mysql_query($SQL, $dbh_RW);
-	
-	if($myrow = mysql_fetch_assoc($rs)) {
-		# redirect the browser now
-		if($_SUBTAG != "") {
-			header("Location: " . $myrow['TargetUrl'] . "?" . $_SUBTAG);
-		}
-		else {
-			header("Location: " . $myrow['TargetUrl']);
-		}
-		
-		# track the click
-		# Do a reverse lookup on the client IP
-		$client_hostname = @gethostbyaddr($_SERVER['REMOTE_ADDR']) ;
-		$SQL = "INSERT /* /go/redirector.php */ INTO CampaignClicks (
-					ClickID,
-  					CampaignKey,
-  					SubKey,
-  					HostName,
-  					TimeClicked) VALUES (
-  					NULL,
-  					" . $App->returnQuotedString($_TAG) . ",
-  					" . $App->returnQuotedString($_SUBTAG) . ",
-  					" . $App->returnQuotedString($client_hostname) . ",
-  					NOW())";
-		
-		mysql_query($SQL, $dbh_RW);
-	}
-	else {
-		# error finding Campaign
-		#header("Location: /");
-		showErrorPage();
-	}
-	
-	$dbc_RW->disconnect();  # disconnects all pending DB connections
-	$rs 	= null;
-	$dbh_RW	= null;
-	$dbc_RW = null;
-
-?>
\ No newline at end of file
+$Redirector = new Redirector();
+$Redirector->setTags($App->getHTTPParameter("tag", "GET"));
+$Redirector->setImpressionId($App->getHTTPParameter("impression_id", "GET"));
+$Redirector->redirect();
\ No newline at end of file