blob: ed20fd448e4582849e98e7bd4643c41fd4fa1c83 [file] [log] [blame]
<?php
require_once("/home/data/httpd/eclipse-php-classes/system/app.class.php");
require_once("/home/data/httpd/eclipse-php-classes/people/ldapperson.class.php");
require_once("/home/data/httpd/eclipse-php-classes/menu/menu.class.php");
require_once("/home/data/httpd/eclipse-php-classes/system/dbconnection_rw.class.php");
#*****************************************************************************
#
# campaingManager.php
#
# Author: Donald Smith
# Date: 2008-01-02
#
# Description: Manage Campaigns
#
# HISTORY: Jan 2, 2008 Dons first public release
#
#****************************************************************************
function mysql_evaluate($query, $default_value="undefined") {
$result = mysql_query($query);
if (mysql_num_rows($result)==0)
return $default_value;
else
return mysql_result($result,0);
}
function count_clicks($c_name)
{
return mysql_evaluate("SELECT COUNT(*) FROM CampaignClicks WHERE CampaignKey='" . $c_name . "'");
}
function last_month_clicks($c_name, $mosString)
{
$prevMonthString = date("Y-m",strtotime($mosString." month"));
$dateSQL = "SELECT COUNT(*) FROM CampaignClicks WHERE CampaignKey='" . $c_name . "'" .
" and TimeClicked like '". $prevMonthString . "%'";
// echo "<br>DATE:" . $dateSQL . "<br>";
return mysql_evaluate($dateSQL);
}
$App = new App();
$App->runStdWebAppCacheable();
$ErrorMessage = "";
# get the incoming parameters
$_TAG = ($_GET['tag'] ? $_GET['tag'] : $_POST['tag']);
$_CNAME = ($_GET['cName'] ? $_GET['cName'] : $_POST['cName']);
$_CGROUP = ($_GET['cGroup'] ? $_GET['cGroup'] : $_POST['cGroup']);
$_CPASSCODE = ($_GET['passcode'] ? $_GET['passcode'] : $_POST['passcode']);
$_CDOMAINNAME = ($_GET['domainName'] ? $_GET['domainName'] : $_POST['domainName']);
$_CTARG = ($_GET['cTarget'] ? $_GET['cTarget'] : $_POST['cTarget']);
$_CEND = ($_GET['cEnd'] ? $_GET['cEnd'] : $_POST['cEnd']);
$_CPORTALID = ($_GET['cPortalID'] ? $_GET['cPortalID'] : $_POST['cPortalID']);
$_CDELETE = ($_GET['cDelete'] ? $_GET['cDelete'] : $_POST['cDelete']);
$_CONFIRMCDELETE = ($_GET['confirmCDelete'] ? $_GET['confirmCDelete'] : $_POST['confirmCDelete']);
$_CVIEWCLICKS = ($_GET['cViewClicks'] ? $_GET['cViewClicks'] : $_POST['cViewClicks']);
$_CVIEWGROUPCHANNEL = ($_GET['cViewGroupChannel'] ? $_GET['cViewGroupChannel'] : $_POST['cViewGroupChannel']);
$_CMAXCLICKS = ($_GET['cMaxClicks'] ? $_GET['cMaxClicks'] : $_POST['cMaxClicks']);
$_COMPANYNAME = ($_GET['companyName'] ? $_GET['companyName'] : $_POST['companyName']);
$_CNEWURL = ($_GET['newURL'] ? $_GET['newURL'] : $_POST['newURL']);
$_CNEWDATE = ($_GET['newDATE'] ? $_GET['newDATE'] : $_POST['newDATE']);
$_CNEWGROUP = ($_GET['newGROUP'] ? $_GET['newGROUP'] : $_POST['newGROUP']);
$_COMPANYLOGO = ($_GET['companyLOGOURL'] ? $_GET['companyLOGOURL'] : $_POST['companyLOGOURL']);
$_CPORTALID = ($_GET['cPortalID'] ? $_GET['cPortalID'] : $_POST['cPortalID']);
if ($_GET['postHack'] != "") {
$_POST['create'] = false;
$_POST['delete'] = false;
$_POST['viewClicks'] = false;
$_POST['viewCampaigns'] = false;
$_POST['create'] = false;
$_POST[$_GET['postHack']] = true;
}
$LDAPPerson = new LDAPPerson();
$LDAPPerson = $LDAPPerson->redirectIfNotLoggedIn();
include("../html/header.php");
$Menu = new Menu("en");
include("../modules/menu.php");
####################### WELCOME
echo '
<br />
<td width="100%" valign="top" class="normal">
<font class="large_title">Campaigns</font><br /><br />
This page is designed for Eclipse Foundation staff who need to manage click-tracking
campaigns and as an added bonus - it shortens most URLs. If you need help with
this feature, see help at bottom of page, and feel free to email donald, who works at eclipse.org.
v77.
<br>
';
####################### CONNECTIONS
# Connect to databases
$dbc_RW = new DBConnectionRW();
// echo "ERROR FROM NEW CONNECTION: " . mysql_error() . "<br>";
$dbh_RW = $dbc_RW->connect();
// echo "ERROR FROM CONNECT: " . mysql_error() . "<br>";
if ($_POST['create']) {
####################### CREATE CAMPAIGN
echo '<h3>Creating new campaign</h3>';
$SQL = "INSERT INTO Campaigns values (" .
"'" . $_CNAME . "', " .
"'" . $_CTARG . "', " .
"NOW(), " .
"'" . $_CEND . "'," .
"'" . $_CPORTALID . "'," .
"'" . $_CGROUP . "'" .
")";
echo "<br>SQL: " . $SQL;
$rs = mysql_query($SQL, $dbh_RW);
if ($rs)
echo "<br>DONE, Successfully added. Link is: http://eclipse.org/go/".$_CNAME."<br>";
else
echo "<br>THERE WAS AN ERROR: " . mysql_error() . "<br>";
} else if ($_POST['delete']) {
####################### DELETE CAMPAIGN
echo '<h3>Deleting Campaign</h3>';
if ($_CONFIRMCDELETE) {
$SQL = "DELETE FROM Campaigns WHERE CampaignKey='" . $_CDELETE . "'";
echo "<br>SQL: " . $SQL;
$rs = mysql_query($SQL, $dbh_RW);
if ($rs)
echo "<br>DONE, Successfully deleted.<br>" . mysql_error();
else
echo "<br>THERE WAS AN ERROR: " . mysql_error() . "<br>";
} else {
echo '<br> PLEASE CLICK THE CONFIRM CHECK BOX TO DELETE <br><br>';
}
} else if ($_POST['change']) {
####################### CHANGE CAMPAIGN URL
echo '<h3>CHAINGING Campaign URL...</h3>';
$SQL = "UPDATE Campaigns set TargetUrl = '" . $_CNEWURL . "', DateExpires ='" . $_CNEWDATE . "', CampaignGroup ='" . $_CNEWGROUP. "' WHERE CampaignKey='" . $_CVIEWCLICKS . "'";
echo '<br> SQL: ' . $SQL;
$rs = mysql_query($SQL, $dbh_RW);
if ($rs)
echo "<br>DONE, Successfully UPDATED.<br>" . mysql_error();
else
echo "<br>THERE WAS AN ERROR: " . mysql_error() . "<br>";
} else if ($_POST['deleteClicks']) {
####################### DELETE CLICKS
echo '<h3>Deleting CLICKS</h3>';
if ($_CPASSCODE == "fartbeans") {
$SQL = "DELETE FROM CampaignClicks WHERE HostName='" . $_CDOMAINNAME . "'";
echo "<br>SQL: " . $SQL;
$rs = mysql_query($SQL, $dbh_RW);
if ($rs) {
echo "<br>DONE, Successfully deleted " . mysql_affected_rows() . " clicks.<br>";
echo "<br>DONE, If there was an error, here it is:<br>" . mysql_error();
}
else
echo "<br>THERE WAS AN ERROR: " . mysql_error() . "<br>";
} else {
echo '<br> PLEASE ENTER THE CORRECT PASSCODE <br><br>';
}
} else if ($_POST['viewClicks']) {
####################### VIEW CLICKS
if($_CVIEWGROUPCHANNEL=="yes") {
$SQL = "SELECT * FROM CampaignClicks WHERE CampaignKey='" . $_CVIEWCLICKS . "' ORDER BY SubKey, TimeClicked DESC LIMIT ". $_CMAXCLICKS;
} else {
$SQL = "SELECT * FROM CampaignClicks WHERE CampaignKey='" . $_CVIEWCLICKS . "' ORDER BY TimeClicked DESC LIMIT ". $_CMAXCLICKS;
}
// echo "<br> <br>SQL: " . $SQL;
$rs = mysql_query($SQL, $dbh_RW);
// echo "ERROR FROM SQL: " . mysql_error() . "<br>";
$count = count_clicks($_CVIEWCLICKS);
echo '<br><h3>There are ' . $count . ' clicks for the ' . $_CVIEWCLICKS . ' campaign. ';
if ($_CMAXCLICKS < $count)
echo 'Showing the ' . $_CMAXCLICKS. ' most recent:';
echo '</h3>';
echo '<table border="1">';
echo '<tr><th>ClickID</th>';
echo '<th>Campaign Name</th>';
echo '<th>Channel Key</th>';
echo '<th>Domain Name</th>';
echo '<th>TimeStamp</th>';
echo '</tr>';
while ($myrow = mysql_fetch_array($rs)) {
echo '<tr>';
echo '<td>' . $myrow['ClickID'] . '</td>';
echo '<td>' . $myrow['CampaignKey'] . '</td>';
echo '<td>' . $myrow['SubKey'] . '</td>';
echo '<td>' . $myrow['HostName'] . '</td>';
echo '<td>' . $myrow['TimeClicked'] . '</td>';
echo '</tr>';
}
echo '</table><br><br>';
####################### CHANGE CAMPAIGN URL UI
$SQL = "SELECT * FROM Campaigns WHERE CampaignKey='" . $_CVIEWCLICKS . "'";
$rs = mysql_query($SQL, $dbh_RW);
$myrow = mysql_fetch_array($rs);
$oldurl = $myrow['TargetUrl'];
$olddate = $myrow['DateExpires'];
$oldgroup = $myrow['CampaignGroup'];
echo ' <br><br><h3>UPDATE CAMPAIGN URL AND/OR DATE</h3>
THIS WILL UPDATE THE URL AND DATE FOR THE CAMPAIGN<br/>
<form action="/committers/committertools/campaignManager.php" method="POST">
<table border="1">
<tr>
<td>OLD URL:</td>
<td>' . $oldurl . '</td>
</tr>
<tr>
<td>NEW URL: </td>
<td><input type="text" name="newURL" value="' . $oldurl . '"></td>
</tr>
<tr>
<td>OLD DATE:</td>
<td>' . $olddate . '</td>
</tr>
<tr>
<td>NEW DATE: </td>
<td><input type="text" name="newDATE" value="'. $olddate. '"></td>
</tr>
<tr>
<td>OLD GROUP: </td>
<td>' . $oldgroup . '</td>
</tr>
<tr>
<td>NEW GROUP: </td>
<td><input type="text" name="newGROUP" value'. $oldgroup. '"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Change" name="change"></td>
</tr>
</table>
<input type="hidden" name="cViewClicks" value="' . $_CVIEWCLICKS . '">
</form><br/>
';
} else if ($_POST['viewCampaigns']) {
####################### VIEW CAMPAIGNS
$SQL = "SELECT * FROM Campaigns";
if ($_CPORTALID != "" && $_CPORTALID != "ALL" && $_CGROUP == "")
$SQL .= " where CreatorPortalID = '" . $_CPORTALID . "'";
else if ($_CGROUP != "" && $_CGROUP != "ALL")
$SQL .= " where CampaignGroup = '" . $_CGROUP . "'";
$SQL .= " ORDER BY CampaignGroup, CampaignKey";
//echo "SQL: " . $SQL;
$rs = mysql_query($SQL, $dbh_RW);
//echo "ERROR FROM SQL: " . mysql_error() . "<br>";
if ($_CPORTALID == "ALL" || $_CGROUP == "ALL")
echo '<br><h3>ALL Campaigns</h3> ';
else {
echo '<br><h3>';
if ($_CPORTALID != "") echo $_CPORTALID; else echo $_CGROUP;
echo '\'s Campaigns</h3> ';
}
echo '<table border="1">';
echo '<tr><th width="75">Group</th><th width="75">Key</th> <th valign=middle>Clicks</th> <th width="100">Target URL</th> <th width="50">Created</th> <th width="50">Expires</th><th width="30">Owner</th><th width="30">Delete</th></tr>';
$totals = array();
while ($myrow = mysql_fetch_array($rs)) {
echo '<tr>';
echo '<td width="75">' . $myrow['CampaignGroup'] . '</td>';
echo '<td width="75"><a href="http://eclipse.org/go/' . $myrow['CampaignKey'] . '">' . $myrow['CampaignKey'] . '</a></td>';
$currentClicks = count_clicks($myrow['CampaignKey']);
echo '<td valign=middle> <form action="/committers/committertools/campaignManager.php" method="POST">
<input type="hidden" name="cViewClicks" value="' . $myrow['CampaignKey'] . '">
<input type="submit" value="View ' . $currentClicks . ' Clicks" name="viewClicks">
<br>Max:<input type="text" name="cMaxClicks" value="100" size="6" maxlength="6">';
for ($i=0;$i<6;$i++) {
$dte = date("Y-m",strtotime("-".$i." month"));
$lmc = last_month_clicks($myrow['CampaignKey'], "-".$i);
echo '<br>' . $dte . ': ' . $lmc;
$totals[$dte] = $totals[$dte] + $lmc;
}
echo '</form></td>';
echo '<td width="100">' . substr($myrow['TargetUrl'],0,80);
if (strlen($myrow['TargetUrl']) > 80) echo '...';
echo '</td>';
echo '<td width="50">' . $myrow['DateCreated'] . '</td>';
echo '<td width="50">' . $myrow['DateExpires'] . '</td>';
echo '<td width="30">' . $myrow['CreatorPortalID'] . '</td>';
echo '<td valign=middle> <form action="/committers/committertools/campaignManager.php" method="POST">
<input type="hidden" name="cDelete" value="' . $myrow['CampaignKey'] . '">
Confirm:<input type="checkbox" name="confirmCDelete">
<input type="submit" value="DELETE" name="delete"></form></td>';
echo '</tr>';
}
echo '</table>';
echo '<br> TOTALS:<br>';
foreach ($totals as $mos => $cnt) {
echo " " . $mos . " " . $cnt . "<br>";
}
}
#
# Done with POSTS, now showing stuff that is displayed on ALL Pages
#
####################### BY PERSON
$SQL = "SELECT distinct CreatorPortalID FROM Campaigns ORDER BY CreatorPortalID";
// echo "SQL: " . $SQL;
$rs = mysql_query($SQL, $dbh_RW);
// echo "ERROR FROM SQL: " . mysql_error() . "<br>";
echo '<br><h3>View Campaigns By Person</h3> ';
echo '<form action="/committers/committertools/campaignManager.php" method="POST">
<select name="cPortalID">
<option value="ALL">All</option>';
while ($myrow = mysql_fetch_array($rs)) {
echo ' <option value="' . $myrow['CreatorPortalID'] . '"';
if ($myrow['CreatorPortalID'] == $LDAPPerson->getuid())
echo "SELECTED";
echo '>' . $myrow['CreatorPortalID'] . "</option>";
}
echo '</select>
<input type="submit" value="View Campaigns" name="viewCampaigns">
</form>';
####################### BY GROUP
$SQL = "SELECT distinct CampaignGroup FROM Campaigns ORDER BY CampaignGroup";
// echo "SQL: " . $SQL;
$rs = mysql_query($SQL, $dbh_RW);
// echo "ERROR FROM SQL: " . mysql_error() . "<br>";
echo '<br><h3>View Campaigns By Group</h3> ';
echo '<form action="/committers/committertools/campaignManager.php" method="POST">
<select name="cGroup">
<option value="ALL">All</option>';
while ($myrow = mysql_fetch_array($rs)) {
if ($myrow['CampaignGroup'] != "" ) {
echo ' <option value="' . $myrow['CampaignGroup'] . '">';
echo $myrow['CampaignGroup'] . "</option>";
}
}
echo '</select>
<input type="submit" value="View Campaigns" name="viewCampaigns">
</form>';
####################### CREATE NEW CAMPAIGN
echo '<br><h3>Create A New Campaign</h3><form action="/committers/committertools/campaignManager.php" method="POST">
<table border="1">
<tr>
<td>Campaign Name:</td>
<td><input type="text" name="cName" value="' . $_COMPANYNAME . '"></td>
</tr>
<tr>
<td>Target URL: </td>
<td><input type="text" name="cTarget" value="';
if ($_POST['load'])
echo 'http://www.eclipse.org/membership/become_a_member/benefits.php?member=yes&image=' . base64_encode($_COMPANYLOGO);
else echo 'http://';
echo '"></td>
</tr>
<tr>
<td>Expiry Date: </td>
<td><input type="text" name="cEnd" value="' . date("Y-m-d", strtotime("+2 year")) . '"></td>
</tr>
<tr>
<td>Owner (Portal ID):</td>
<td><input type="text" name="cPortalID" value="' . $LDAPPerson->getuid() . '"></td>
</tr>
<tr>
<td>Group:</td>
<td><input type="text" name="cGroup" value="';
if ($_POST['load'])
echo 'MEMBER_RECRUIT';
else echo 'SOLO';
echo '"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Create Campaign" name="create"></td>
</tr>
</table>
</form><br/>
';
####################### HELP
echo '
<font class="large_title">How to Create a Campaign</font><br /><br />
A simple use case is:
<ol>
<li>Enter a campaign name such as "FOO". Keep it short and sweet, no spaces, just use Characters and numbers.</li>
<li>Enter a target URL (MUST put http://) such as http://obnoxiouslylogurl.com/long/boring/long/foo.php</li>
<li>Enter an expiry date (after that date clicks to the campaign will go to an "expired campaign" error page).</li>
<li>Enter your portal ID (some day we might integrate results to portal), but mainly this will help you quickly find all your own campaigns.</li>
<li>Enter Campaign Group (or leave at SOLO if it stands alone). This helps you manage related campaigns in a single newsletter for example.</li>
<li>Click "Create Campaign" Button</li>
<li>Point people to http://eclipse.org/go/FOO (where FOO is the campaign name), they will automatically be redirected to
the obnoxiouly long URL, and we will track who-clicked-what-when.</li>
<li>Come back to this page and click the "view clicks" button to see the clicks to your campaign!
</ol>
Notes: <ul>
<li>It is possible to add a SubKey (lets call it a "channel key") to URLs if you want to distinguish between
clicks coming from different channels. For example, eclipse.org/go/FOO@EM and eclipse.org/go/FOO@WB --
both will record and redirect
the FOO Campaign, but will tag the click with an "EM" (for Email)or "WB" (for Web)
in the click results to distinguish
clicks coming from channels.</li>
<li>For Email Campaings we could get really fancy with a "Mail Merge" tool and encode a
user ID after the @ in the URL to know *exactly* who is clicking on links. For example,
eclipse.org/go/FOO@1287 would record 1287 with the click and we could tell that
member 1287 clicked the url...</li>
</ul>
';
####################### DONALDS MEMBERSHIP UTILITY
echo '
<br><br><h3>Donald\'s New Member Campaign Utility</h3>
This is a little utility for Donald when he does Cold Calls. Enter a URL to a logo somewhere on the web
and it encodes a campaign that links to the membership benefits page with the cold-call prospect logo
on the page. Very Cute. Useful only to Donald.<br/>
<form action="/committers/committertools/campaignManager.php" method="POST">
<table border="1">
<tr>
<td>Company Name:</td>
<td><input type="text" name="companyName"></td>
</tr>
<tr>
<td>Company Logo: </td>
<td><input type="text" name="companyLOGOURL" value="http://"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Load" name="load"></td>
</tr>
</table>
</form><br/>
';
####################### DONALDS CLICK CLEANUP UTILITY
echo '
<br><br><h3>Donald\'s CLICK CLEANUP Utility</h3>
This cleans up bot-clicks -- it is dangerous to use this so please do not. Useful only to Donald.<br/>
<form action="/committers/committertools/campaignManager.php" method="POST">
<table border="1">
<tr>
<td>Domain Name:</td>
<td><input type="text" name="domainName"></td>
</tr>
<tr>
<td>Passcode: </td>
<td><input type="text" name="passcode" value="CODE"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Delete Clicks" name="deleteClicks"></td>
</tr>
</table>
</form><br/>
';
$dbc_RW->disconnect(); # disconnects all pending DB connections
$rs = null;
$dbh_RW = null;
$dbc_RW = null;
?>