<?php
include("include/vars.php");
require("include/functions.php");
$lang=setlanguage();
require("language/$lang");
$menu=setmenu();
if (file_exists("setup.php") || file_exists("upgrade.php")) {
errormsg("Security alert: immediatly delete setup.php and upgrade.php before you start running your service!");
}
if ( ( !isset($PHP_AUTH_USER)) || (!isset($PHP_AUTH_PW)) || ($PHP_AUTH_USER!=$adminusername) || ($PHP_AUTH_PW!=$adminpasswd)) {
header( 'WWW-Authenticate: Basic realm="Administration area"' );
header( 'HTTP/1.0 401 Unauthorized' );
errormsg("Authorization Required!");
exit;
}
if (!$do) {
$do="main";
}
if ($do=='edit') {
$standardad=htmlspecialchars(stripslashes($standardad));
$main="<form method=\"post\" action=\"admin.php\">
<table cellspacing=\"1\" cellpadding=\"4\" border=\"0\" width=\"500\" align=\"center\">
<tr>
<td>
<p align=\"center\"><b>Change variables and options</b></p>
<p><i>All fields are required!</i></p>
<p>Administrator username:<br>
<input type=\"text\" name=\"adminusername2\" value=\"$adminusername\"></p>
<p>Administrator password:<br>
<input type=\"password\" name=\"adminpasswd2\" value=\"$adminpasswd\"></p>
<p>Only in case you want to change your password<br>
New password:<br>
<input type=\"password\" name=\"passwd1\" maxlength=\"25\"><br>
New password again:<br>
<input type=\"password\" name=\"passwd2\" maxlength=\"25\"><br>
</p>
<p>Default startpage:<br>
<input type=\"text\" name=\"startpage2\" value=\"$startpage\"><br>
Where should youre users be redirected if they mistyped an url?<br>What is the main page of your website?<br>
For example main.html</p>
<p>Your website's title:<br>
<input type=\"text\" name=\"sitetitle2\" value=\"$pagetitle\"></p>
<p>Your main domainname (without "http://www."):<br>
<input type=\"text\" name=\"maindomain2\" value=\"$maindomain\"></p>
<p>Your server's ip (not necessary):<br>
<input type=\"text\" name=\"domainip2\" value=\"$domainip\"></p>
<p>Your E-mail Address:<br>
<input type=\"text\" name=\"adminemail2\" value=\"$adminmail\"><br></p>
<p>Your standard-ad (in case no other ads are active):<br>
<input type=\"text\" name=\"standardad2\" value=\"$standardad\" size=\"40\"><br>
(HTML allowed)</p>
</td>
</tr>
<tr>
<td align=\"center\">
<input type=\"hidden\" name=\"do\" value=\"do_edit\">
<input type=\"submit\" name=\"submit\" value=\"Save\">
</td>
</tr>
<tr>
<td align=\"center\">
<b><a href=\"admin.php\">Back to the main page</a></b>
</td>
</tr>
</table>
</form>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='do_edit') {
if (!$adminusername2) {
$admin_error="You forgot to fill in the administrator username.<br>";
}
if (!$adminpasswd2) {
$admin_error.="You forgot to fill in the administrator password.<br>";
}
if ($passwd1 != $passwd2) {
$admin_error.="For changing the password you have to enter the new password twice just the same way.<br>";
}
if (!$startpage2) {
$admin_error.="You forgot to fill in the startpage.<br>";
}
if (!$sitetitle2) {
$admin_error.="You forgot to fill in your website title.<br>";
}
if (!$maindomain2) {
$admin_error.="You forgot to fill in your main domainname.<br>";
}
if (!$adminemail2 || verify_email($adminemail2)!=1) {
$admin_error.="You have to provide a valid administrator emailaddress.<br>";
}
if ($passwd1!="") {
$adminpasswd2=$passwd1;
}
if (!$standardad2) {
$admin_error.="Please type in a text to use as standard-ad.<br>";
}
if ($admin_error) {
errormsg($admin_error);
exit;
}
else {
$standardad2=addslashes($standardad2);
mysql_query("UPDATE $options_table SET home='$startpage2',sitetitle='$sitetitle2',adminemail='$adminemail2',username='$adminusername2',password='$adminpasswd2',maindomain='$maindomain2',domainip='$domainip2', standardad='$standardad2'");
$result_message = "Changes have been saved";
$do="main";
}
}
if ($do == 'searchmember') {
if ($searchstring=="") {
errormsg("Please type in a string to search for.");
exit;
}
$main="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"450\" align=\"center\">
<tr>
<td><b>Search result:</b></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>";
$searchresult=mysql_query("SELECT * FROM $redir_table WHERE host LIKE '%$searchstring%'");
$countmembers=mysql_num_rows($searchresult);
if ($countmembers < 1) {
$main.="No match!<br>";
} else {
while($rowmembers=mysql_fetch_array($searchresult)) {
$domain=$rowmembers[host];
$main.="<a href=\"admin.php?do=showdetail&domain=$domain\">$domain</a><br>";
}
}
$main.="<p align=\"center\"><b><a href=\"admin.php\">Back to the main page</a></b></p>
</td></tr></table>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do == 'category') {
$main="<form action=\"admin.php?do=addcat\" method=\"post\">
<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"300\" align=\"center\">
<tr>
<td>";
$catresult=mysql_query("SELECT * FROM $category_table ORDER BY category ASC");
$countcat=mysql_num_rows($catresult);
$main.="<br><b>Your categories:</b><br><br>";
if ($countcat < 1) {
$main.="You havn't specified any categories.<br>";
} else {
while($rowcat=mysql_fetch_array($catresult)) {
$cat=$rowcat[category];
$main.="<b>$cat</b> (<a href=\"admin.php?do=deletecat&cat=$cat\">delete</a>)<br>";
}
}
$main.="</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Add additional category <input type=\"text\" name=\"cat\" maxlength=\"50\"><input type=\"submit\" name=\"submit\" value=\"Add category\"></td>
</tr>
<tr>
<td>
<p align=\"center\"><b><a href=\"admin.php\">Back to the main page</a></b></p>
</td>
</tr>
</table>
</form>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='deletecat') {
mysql_query("DELETE FROM $category_table WHERE category='$cat'") or die ("mysql_error");
$result_message = "Category <b>$cat</b> has been deleted!<br>";
$do="main";
}
if ($do=='addcat') {
if ($cat=="") {
errormsg("Please fill in a category.");
exit;
}
$checkinput=mysql_num_rows(mysql_query("SELECT * FROM $category_table WHERE category='$cat'"));
if ($checkinput > 0) {
errormsg("This category already exists in your database!");
exit;
}
mysql_query("INSERT INTO $category_table (category) VALUES ('$cat')") or die ("mysql_error");
$result_message = "Category <b>$cat</b> has been added to your list!<br>";
$do="main";
}
if ($do == 'add') {
$main="<form action=\"admin.php?do=addtld\" method=\"post\">
<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"300\" align=\"center\">
<tr>
<td>";
$tldresult=mysql_query("SELECT * FROM $domain_table ORDER BY domain ASC");
$counttld=mysql_num_rows($tldresult);
$main.="<br><b>Your domains:</b><br><br>";
if ($counttld < 1) {
$main.="You have no domains actice where people may register.<br>";
} else {
while($rowtld=mysql_fetch_array($tldresult)) {
$tld=$rowtld[domain];
$main.="<b>$tld</b> (<a href=\"admin.php?do=deletetld&tld=$tld\">delete</a>)<br>";
}
}
$main.="</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Add additional domain (only "domain.tld", NO http://www.)<br><input type=\"text\" name=\"tld\" maxlength=\"50\"> <input type=\"submit\" name=\"submit\" value=\"Add domain\"></td>
</tr>
<tr>
<td>
<p align=\"center\"><b><a href=\"admin.php\">Back to the main page</a></b></p>
</td>
</tr>
</table>
</form>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='deletetld') {
mysql_query("DELETE FROM $domain_table WHERE domain='$tld'") or die ("mysql_error");
$result_message = "Domain <b>$tld</b> has been deleted!<br>";
$do="main";
}
if ($do=='addtld') {
if ($tld=="") {
errormsg("Please fill in a domain.");
exit;
}
$checkinput=mysql_num_rows(mysql_query("SELECT * FROM $domain_table WHERE domain='$tld'"));
if ($checkinput > 0) {
errormsg("This domain already exists in your database!");
exit;
}
mysql_query("INSERT INTO $domain_table (domain) VALUES ('$tld')") or die ("mysql_error");
$result_message = "Domain <b>$tld</b> has been added to your list!<br>";
$do="main";
}
if ($do == 'listmembers') {
$main="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"450\" align=\"center\">
<tr>
<td><b>Currently active members:</b></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>";
$listresult=mysql_query("SELECT * FROM $redir_table");
$countmembers=mysql_num_rows($listresult);
if ($countmembers < 1) {
$main.="You have no members in your database.<br>";
} else {
while($rowmembers=mysql_fetch_array($listresult)) {
$domain=$rowmembers[host];
$main.="<a href=\"admin.php?do=showdetail&domain=$domain\">$domain</a><br>";
}
}
$main.="<p align=\"center\"><b><a href=\"admin.php\">Back to the main page</a></b></p>
</td>
</tr>
</table>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='addetails') {
$addetail_query = mysql_query("SELECT * FROM $adverts_table WHERE adid='$adid'");
if (mysql_num_rows($addetail_query) < 1) {
errormsg("<b>This advert does not exist!</b>");
exit;
}
$adresult_query=mysql_fetch_array($addetail_query);
$adid = $adresult_query[adid];
$userid = $adresult_query[userid];
$adlink = $adresult_query[adlink];
$linktext = $adresult_query[linktext];
$adtext = $adresult_query[adtext];
if ($adresult_query[maxhits] > 0) {
$hitsviews=$adresult_query[maxhits];
$ad_type="maxhits";
}
if ($adresult_query[maxviews] > 0) {
$hitsviews=$adresult_query[maxviews];
$ad_type="maxviews";
}
$user_query=mysql_fetch_array(mysql_query("SELECT * FROM $advertiser_table WHERE userid='$userid'"));
$cname=$user_query[realname];
$main="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" align=\"center\">
<tr>
<td>
<p>This is how this advert will look like (without the border, of course):</p>
</td>
</tr>
</table>
<table cellspacing=\"1\" cellpadding=\"3\" border=\"1\" width=\"100%\" align=\"center\">
<tr>
<td><font size=\"2\"><div align=\"center\"><a href=\"$adlink\" target=\"_blank\"><b>$linktext</b></a> $adtext</td>
</tr>
</table>
<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" align=\"center\">
<tr>
<td>
<p>Ordered by: <b><a href=\"admin.php?do=showclient&userid=$userid\">$cname</a></b> (userID: <a href=\"admin.php?do=showclient&userid=$userid\">$userid</a>)</p>
</td>
</tr>
<tr>
<td>
<p>Ad-type: $hitsviews <b> $ad_type</b></p>
</td>
</tr>
<tr>
<td>
<p><a href=\"admin.php?do=adactivate&adid=$adid\">activate advert</a> | <a href=\"admin.php?do=addelete&adid=$adid\">delete advert</a><br></p>
</td>
</tr>
<tr>
<td><td> </td>
</tr>
<tr>
<td>
<p><b><a href=\"admin.php?do=admanager\">Back to the ad administration page</a><br><br><a href=\"admin.php\">Back to the main page</a></b></p>
</td>
</tr>
</table>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='adverts') {
mysql_query("UPDATE $options_table SET ads='$adtype'") or die ("mysql_error");
$result_message = "Adtype has been set to $adtype.<br>";
$ads=$adtype;
$do="main";
}
if ($do=='news') {
if ($towho=="newsletterowners") {
$countaddress=mysql_num_rows(mysql_query("SELECT DISTINCT email FROM $redir_table WHERE news='on'"));
}
elseif ($towho=="adclients") {
$countaddress=mysql_num_rows(mysql_query("SELECT DISTINCT email FROM $advertiser_table"));
}
else {
$countaddress=mysql_num_rows(mysql_query("SELECT DISTINCT email FROM $redir_table"));
}
$main="<form action=\"admin.php?do=sendnews\" method=\"post\">
<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"500\" align=\"center\">
<tr>
<td align=\"center\" colspan=\"2\">Send an email to <b> $towho</b></td>
</tr>
<tr>
<td colspan=\"2\"> </td>
</tr>
<tr>
<td colspan=\"2\">Sending mail to <b>$countaddress</b> member(s) - duplicates have been ignored</td>
</tr>
<tr>
<td>Message title</td>
<td>
<input type=\"text\" name=\"mailsubject\" size=\"30\">
</td>
</tr>
<tr>
<td valign=\"top\" colspan=\"2\"><div align=\"center\">Your message:</div></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
<textarea name=\"mailbody\" cols=\"40\" rows=\"15\" nowrap></textarea>
</td>
</tr>
<tr>
<td align=\"center\" colspan=\"2\">
<input type=\"hidden\" name=\"towho\" value=\"$towho\">
<input type=\"submit\" name=\"submit\" value=\"send email\">
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
<b><a href=\"admin.php\">Back to the main page</a></b>
</td>
</tr>
</table>
</form>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='sendnews') {
if (!$mailsubject) {
$admin_error.="You forgot to fill in the emails subject.<br>";
}
if (!$mailbody) {
$admin_error.="Please, don't send an empty mail...<br>";
}
if ($admin_error) {
errormsg($admin_error);
exit;
}
if ($towho=="newsletterowners") {
$getaddress=mysql_query("SELECT DISTINCT email FROM $redir_table WHERE news='on'");
}
if ($towho=="adclients") {
$getaddress=mysql_query("SELECT DISTINCT email FROM $advertiser_table");
}
else {
$getaddress=mysql_query("SELECT DISTINCT email FROM $redir_table");
}
$mailbody=stripslashes($mailbody);
while($emailarray=mysql_fetch_array($getaddress)) {
$email=$emailarray[0];
mail($email,$mailsubject,$mailbody,"From: $adminmail\nReply-To: $adminmail");
}
$result_message = "All emails have been sent to <b>$towho</b>";
$do="main";
}
if ($do=='showclient') {
$showclient=mysql_query("SELECT * FROM $advertiser_table WHERE userid='$userid'");
if (mysql_num_rows($showclient) < 1) {
errormsg("This client does not exist.");
}
$client_array=mysql_fetch_array($showclient);
$userid = $client_array[userid];
$cname = $client_array[realname];
$address = $client_array[address];
$mail = $client_array[email];
$password = $client_array[password];
$zipcode = $client_array[zipcode];
$town = $client_array[town];
$country = $client_array[country];
$ip = $client_array[ip];
$regdate = $client_array[regdate];
$regdate = date($dateformat, $regdate);
$main="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"400\" align=\"center\">
<tr>
<td><b>UserID $userid - Company $cname ?></b> - <a href=\"admin.php?do=deleteclient&userid=$userid\">Delete this client</a></td>
</tr>
<tr>
<td><b>Real name:</b> $cname</td>
</tr>
<tr>
<td><b>Password:</b> $password</td>
</tr>
<tr>
<td><b>Client's emailaddress:</b> <a href=\"mailto:$mail\">$mail</a></td>
</tr>
<tr>
<td><b>Address:</b> $address</td>
</tr>
<tr>
<td><b>Zip:</b> $zipcode</td>
</tr>
<tr>
<td><b>Town:</b> $town</td>
</tr>
<tr>
<td><b>Country:</b> $country</td>
</tr>
<tr>
<td><b>Client's IP-address:</b> $ip</td>
</tr>
<tr>
<td><b>Registration date:</b> $regdate</td>
</tr>
<tr>
<td><td> </td>
</tr>
<tr>
<td>
<p><b><a href=\"admin.php?do=admanager\">Back to the ad administration page</a><br><br><a href=\"admin.php\">Back to the main page</a></b></p>
</td>
</tr>
</table>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='adstats') {
$adstats_query=mysql_query("SELECT * FROM $adverts_table WHERE adid='$adid'");
if (mysql_num_rows($adstats_query) < 1) {
errormsg("This advert does not exist.");
}
$ad_array=mysql_fetch_array($adstats_query);
$adid = $ad_array[adid];
$userid = $ad_array[userid];
$adlink = $ad_array[adlink];
$linktext = $ad_array[linktext];
$adtext = $ad_array[adtext];
$maxviews = $ad_array[maxviews];
$views = $ad_array[views];
$maxhits = $ad_array[maxhits];
$hits = $ad_array[hits];
$active = $ad_array[active];
$startdate = $ad_array[startdate];
$startdate = date($dateformat, $startdate);
$getuser=mysql_fetch_array(mysql_query("SELECT * FROM $advertiser_table WHERE userid='$userid'"));
$main="<table cellspacing=\"1\" cellpadding=\"3\" border=\"1\" width=\"100%\" align=\"center\">
<tr>
<td><font size=\"2\"><div align=\"center\"><a href=\"$adlink\" target=\"_blank\"><b>$linktext</b></a> $adtext</td>
</tr>
</table>
<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"400\" align=\"center\">
<tr>
<td><td> </td>
</tr>
<tr>
<td><b>Stats for adID $adid - by company <a href=\"admin.php?do=showclient&userid=$userid\">$getuser[realname]</a></b> - UserID <a href=\"admin.php?do=showclient&userid=$userid\">$userid</a></td>
</tr>
<tr>
<td><a href=\"admin.php?do=adstats3&adid=$adid\">view detailed click stats</a> <a href=\"admin.php?do=adstats4&adid=$adid\">view detailed view stats</a></td>
</tr>
<tr>
<td><b>Current views:</b> $views</td>
</tr>
<tr>
<td><b>Maximum views:</b> $maxviews ("0" means it has no maximum views)</td>
</tr>
<tr>
<td><b>Current hits:</b> $hits</td>
</tr>
<tr>
<td><b>Maximum hits:</b> $maxhits ("0" means it has no maximum hits)</td>
</tr>
<tr>
<td><b>Active:</b> $active</td>
</tr>
<tr>
<td><b>Started:</b> $startdate</td>
</tr>
<tr>
<td><td> </td>
</tr>
<tr>
<td>
<p><b><a href=\"admin.php?do=admanager\">Back to the ad administration page</a><br><br><a href=\"admin.php\">Back to the main page</a></b></p>
</td>
</tr>
</table>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='adstats3') {
$adstats_query2=mysql_query("SELECT * FROM $adclicks_table WHERE adid='$adid'");
if (mysql_num_rows($adstats_query2)<1) {
errormsg("No clicks for that advertisment!");
exit;
}
$main="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"350\" align=\"center\">
<tr>
<td align=\"center\"><b>Click-stats for advertisment-id $adid</b></td>
</tr>
</table>";
$main.=detailstats($adid, $adclicks_table);
$main.="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"350\" align=\"center\">
<tr>
<td align=\"center\">
<p><b><a href=\"admin.php?do=admanager\">Back to the ad administration page</a><br><br><a href=\"admin.php\">Back to the main page</a></b></p>
</td>
</tr>
</table>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='adstats4') {
$adstats_query2=mysql_query("SELECT * FROM $adviews_table WHERE adid='$adid'");
if (mysql_num_rows($adstats_query2)<1) {
errormsg("No views for that advertisment!");
exit;
}
$main="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"350\" align=\"center\">
<tr>
<td align=\"center\"><b>View-stats for advertisment-id $adid</b></td>
</tr>
</table>";
$main.=detailstats($adid, $adviews_table);
$main.="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"350\" align=\"center\">
<tr>
<td align=\"center\">
<p><b><a href=\"admin.php?do=admanager\">Back to the ad administration page</a><br><br><a href=\"admin.php\">Back to the main page</a></b></p>
</td>
</tr>
</table>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='deleteclient') {
$delete_client=mysql_query("DELETE FROM $advertiser_table WHERE userid='$userid'") OR DIE (mysql_error());
if (mysql_error()) {
errormsg("This client does not exist.");
exit;
}
$ad_resultmsg="Client $userid deleted.";
$do="admanager";
}
if ($do=='addelete') {
$delete_ad=mysql_query("DELETE FROM $adverts_table WHERE adid='$adid'") OR DIE (mysql_error());
$delete_ad2=mysql_query("DELETE FROM $adviews_table WHERE adid='$adid'") OR DIE (mysql_error());
$delete_ad3=mysql_query("DELETE FROM $adclicks_table WHERE adid='$adid'") OR DIE (mysql_error());
if (mysql_error()) {
errormsg("This advert does not exist.");
exit;
}
$ad_resultmsg="Advert $adid deleted.";
$do="admanager";
}
if ($do=='adactivate') {
$date=time();
$activate_ad=mysql_query("UPDATE $adverts_table SET active='yes',startdate='$date' WHERE adid='$adid'") OR DIE (mysql_error());
if (mysql_error()) {
errormsg("This advert does not exist.");
exit;
}
$usersearch1=mysql_fetch_array(mysql_query("SELECT userid FROM $adverts_table WHERE adid='$adid'")) OR DIE (mysql_error());
$userid=$usersearch1[0];
$usersearch2=mysql_fetch_array(mysql_query("SELECT email FROM $advertiser_table WHERE userid='$userid'")) OR DIE (mysql_error());
$mailto=$usersearch2[0];
// Mail the client that his ad has been activated
$subject = "Your ad has been activated!";
$message = "Dear customer,
Your ordered ad with the id $adid has been proven and activated.
We will send you a second notice when this ad expires.
Greetings
The webmaster
";
mail($mailto,$subject,$message,"From: $adminmail\nReply-To: $adminmail");
$ad_resultmsg="Advert $adid activated.";
$do="admanager";
}
if ($do=='addeactivate') {
$deactivate_ad=mysql_query("UPDATE $adverts_table SET active='no' WHERE adid='$adid'") OR DIE (mysql_error());
if (mysql_error()) {
errormsg("This advert does not exist.");
exit;
}
$usersearch1=mysql_fetch_array(mysql_query("SELECT userid FROM $adverts_table WHERE adid='$adid'")) OR DIE (mysql_error());
$userid=$usersearch1[0];
$usersearch2=mysql_fetch_array(mysql_query("SELECT email FROM $advertiser_table WHERE userid='$userid'")) OR DIE (mysql_error());
$mailto=$usersearch2[0];
// Mail the client that his ad has been deactivated
$subject = "Your ad has been deactivated!";
$message = "Dear customer,
Your ad with the id $adid has been deactivated for certain reasons.
Please send any questions concerning this ad to $adminmail.
Greetings
The webmaster
";
mail($mailto,$subject,$message,"From: $adminmail\nReply-To: $adminmail");
$ad_resultmsg="Advert $adid expired.";
$do="admanager";
}
if ($do=='showdetail') {
$showmemberdetail=mysql_query("SELECT * FROM $redir_table WHERE host='$domain'");
if (mysql_num_rows($showmemberdetail) < 1) {
errormsg("This domain name was not found.");
}
$detail_array=mysql_fetch_array($showmemberdetail);
$host = $detail_array[host];
$name = $detail_array[name];
$firstname = $detail_array[vname];
$passwd = $detail_array[passwd];
$mail = $detail_array[email];
$sitetitle = $detail_array[title];
$description = $detail_array[descr];
$keywords = $detail_array[keyw];
$url = $detail_array[url];
$revisit = $detail_array[revisit];
$robot = $detail_array[robots];
$news = $detail_array[news];
$counter = $detail_array[counter];
$ip = $detail_array[ip];
$date = $detail_array[time];
$lasttime = $detail_array[lasttime];
$cat = $detail_array[cat];
$date = date($dateformat, $date);
$lasttime = date($dateformat, $lasttime);
$main="<form action=\"admin.php\" method=\"post\">
<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"400\" align=\"center\">
<tr>
<td><b>$host</b> - <a href=\"admin.php?do=delete&host=$host\">Delete this domain name</a></td>
</tr>
<tr>
<td><b>Last name:</b> $name</td>
</tr>
<tr>
<td><b>First name:</b> $firstname</td>
</tr>
<tr>
<td><b>Registrant's emailaddress:</b> <a href=\"mailto:$mail\">$mail</a></td>
</tr>
<tr>
<td><b>Registrant's IP-address:</b> $ip</td>
</tr>
<tr>
<td><b>Registration date:</b> $date</td>
</tr>
<tr>
<td><b>Last active use:</b> $lasttime</td>
</tr>
<tr>
<td><b>Password:</b> $passwd</td>
</tr>
<tr>
<td><b>Target-URL:</b> <a href=\"$url\" target=\"_blank\">$url</a></td>
</tr>
<tr>
<td><b>Title:</b> $sitetitle</td>
</tr>
<tr>
<td><b>Description:</b> $description</td>
</tr>
<tr>
<td><b>Keywords:</b> $keywords</td>
</tr>
<tr>
<td><b>Category:</b> $cat</td>
</tr>
<tr>
<td><b>Robots:</b> $robot</td>
</tr>
<tr>
<td><b>Revisit:</b> $revisit</td>
</tr>
<tr>
<td><b>Counter:</b> $counter</td>
</tr>
<tr>
<td><b>Newsletter:</b>";
if ($news=="on") {
$main.="$news";
}
else {
$main.="off";
}
$main.="</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
<input type=\"hidden\" name=\"host\" value=\"$host\">
<input type=\"hidden\" name=\"do\" value=\"editmember\">
<input type=\"submit\" name=\"submit\" value=\"Edit member\">
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
<b><a href=\"admin.php\">Back to the main page</a></b>
</td>
</tr>
</table>
</form>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='delete') {
mysql_query("DELETE FROM $redir_table WHERE host='$host'") or die ("mysql_error");
$result_message = "Domain name <b>$host</b> has been deleted!<br>";
$do="main";
}
if ($do=='delinactive') {
$date=time();
mysql_query("DELETE FROM $redir_table WHERE ($date-lasttime>5184000)") or die ("mysql_error");
$result_message = "All inactive Accounts have been deleted!<br>";
$do="main";
}
if ($do=='editmember') {
$edit_query = mysql_query("SELECT * FROM $redir_table WHERE host='$host'");
if (mysql_num_rows($edit_query) < 1) {
errormsg("<b>This domain name does not exist!</b>");
exit;
}
$result_query=mysql_fetch_array($edit_query);
$host = $result_query[host];
$name = $result_query[name];
$firstname = $result_query[vname];
$passwd = $result_query[passwd];
$mail = $result_query[email];
$title = $result_query[title];
$description = $result_query[descr];
$keywords = $result_query[keyw];
$url = $result_query[url];
$revisit = $result_query[revisit];
$counter = $result_query[counter];
$robot = $result_query[robots];
$news = $result_query[news];
$cat = $result_query[cat];
if($news=="on") {
$checkbox=" checked";
}
else {
$checkbox="";
}
$main="<form action=\"admin.php\" method=\"post\">
<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"400\" align=\"center\">
<tr>
<td colspan=\"2\">
<p><b>$change</b></p>
<p>This domain has <b>$counter</b> visitors.</p>
<p><i>Fields marked like this * are required fields</i><br></p>
</td>
</tr>
<tr>
<td><br>Domain Name:</td>
<td>
<br><b>$host</b>
</td>
</tr>
<tr>
<td><br><br><b>Personal data:</b></td>
<td> </td>
</tr>
<tr>
<td>* Last name:</td>
<td><input type=\"text\" name=\"name\" value=\"$name\" maxlength=\"25\"></td>
</tr>
<tr>
<td>* First name:</td>
<td><input type=\"text\" name=\"firstname\" value=\"$firstname\" maxlength=\"25\"></td>
</tr>
<tr>
<td>* Email:</td>
<td><input type=\"text\" name=\"mail\" value=\"$mail\" maxlength=\"100\"></td>
</tr>
<tr>
<td>* Password:</td>
<td><input type=\"password\" name=\"passwd\" value=\"$passwd\" maxlength=\"25\"></td>
</tr>
<tr>
<td colspan=\"2\">Important: Please use a valid emailaddress.</td>
</tr>
<tr>
<td><br><br><b>Domain data:</b></td>
<td> </td>
</tr>
<tr>
<td>* Title (<a href=\"javascript:openwindow('help.php?do=title');\">help</a>):</td>
<td><input type=\"text\" name=\"title\" value=\"$title\" maxlength=\"100\"></td>
</tr>
<tr>
<td>Description (<a href=\"javascript:openwindow('help.php?do=description');\">help</a>):</td>
<td><input type=\"text\" name=\"description\" value=\"$description\" maxlength=\"270\"></td>
</tr>
<tr>
<td>Keywords (<a href=\"javascript:openwindow('help.php?do=keywords');\">help</a>):</td>
<td><input type=\"text\" name=\"keywords\" value=\"$keywords\" maxlength=\"270\"></td>
</tr>
<tr>
<td>* Category (<a href=\"javascript:openwindow('help.php?do=cat');\">help</a>):</td>
<td>
<select name=\"cat\">";
// Hurray: the difficult query :-)
$cat_query = mysql_query("SELECT * FROM $category_table ORDER BY category ASC");
while ($cats = mysql_fetch_array($cat_query)) {
$main.="<option>$cats[0]</option>";
}
$main.="<option value=\"$cat\" selected>$cat</option>
</select>
</td>
</tr>
<tr>
<td>* Target-URL (<a href=\"javascript:openwindow('help.php?do=target');\">help</a>):</td>
<td><input type=\"text\" name=\"url\" value=\"$url\" maxlength=\"100\"></td>
</tr>
<tr>
<td>Revisit (<a href=\"javascript:openwindow('help.php?do=revisit');\">help</a>):</td>
<td><input type=\"text\" name=\"revisit\" value=\"$revisit\"></td>
</tr>
<tr>
<td>Robots (<a href=\"javascript:openwindow('help.php?do=robots');\">help</a>):</td>
<td><select name=\"robot\">
<option value=\"INDEX, FOLLOW\">INDEX, FOLLOW</option>
<option value=\"NOINDEX, FOLLOW\">NOINDEX, FOLLOW</option>
<option value=\"NOINDEX\">NOINDEX</option>
<option value=\"INDEX\">INDEX</option>
<option value=\"FOLLOW\">FOLLOW</option>
<option value=\"ALL\">ALL</option>
<option value=\"$robot\" selected>$robot</option>
</select></td>
</tr>
<tr>
<td>Counter:</td>
<td><input type=\"text\" name=\"counter\" value=\"$counter\" maxlength=\"12\"></td>
</tr>
<tr>
<td colspan=\"2\"><input type=\"checkbox\" name=\"newsletter\" $checkbox style=\"border:none\">Yes, I want to recieve news about your services by email (you may change that anytime).</td>
</tr>
<td colspan=\"2\" align=\"center\">
<input type=\"hidden\" name=\"host\" value=\"$host\">
<input type=\"hidden\" name=\"do\" value=\"do_editmember\">
<input type=\"submit\" name=\"submit\" value=\"Save changes\">
<input type=\"reset\" value=\"reset\">
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
<b><a href=\"admin.php\">Back to the main page</a></b>
</td>
</tr>
</table>
</form>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='do_editmember') {
if (!$firstname) {
$admin_error="You forgot to fill in the first name.<br>";
}
if (!$name) {
$admin_error.="You forgot to fill in the last name.<br>";
}
if (!$mail || verify_email($mail)!=1) {
$admin_error.="You have to provide a valid emailaddress.<br>";
}
if (!$passwd) {
$admin_error.="You forgot to fill in the password.<br>";
}
if (!$title) {
$admin_error.="You didn't give this website a title.<br>";
}
if($url=="http://" || $url=="") {
$admin_error.="Please provide a valid target url.<br>";
}
if(ereg("[^0-9]",$counter) || !$counter) {
$admin_error.="Please only use numbers in the counter-field.<br>";
}
if ($admin_error) {
errormsg($admin_error);
exit;
}
mysql_query("UPDATE $redir_table SET name='$name',vname='$firstname',passwd='$passwd',email='$mail',url='$url',title='$title',descr='$description',keyw='$keywords',robots='$robot',news='$newsletter',revisit='$revisit',counter='$counter',cat='$cat' WHERE host='$host'") or die ("mysql_error");
$do="main";
$result_message="The member's data has been changed.";
}
if ($do == 'admanager') {
$main="<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"500\" align=\"center\">
<tr>
<td><b><div align=\"center\">$ad_resultmsg</div></b></td>
</tr>
<tr>
<td><b><div align=\"center\">Advertising administration</div></b></td>
</tr>
<tr>
<td><b>Pending adverts:</b></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>";
$listresult=mysql_query("SELECT * FROM $adverts_table WHERE active='no' AND views='0'");
$countadvert=mysql_num_rows($listresult);
if ($countadvert < 1) {
$main.="You have no active adverts in your database.<br>";
} else {
while($rowadvert=mysql_fetch_array($listresult)) {
$adid=$rowadvert[adid];
$userid=$rowadvert[userid];
$getuser=mysql_fetch_array(mysql_query("SELECT * FROM $advertiser_table WHERE userid='$userid'"));
$main.="ID: $adid, by <a href=\"admin.php?do=showclient&userid=$userid\">$getuser[realname]</a> (userID <a href=\"admin.php?do=showclient&userid=$userid\">$userid</a>) <a href=\"admin.php?do=addetails&adid=$adid\">details</a> | <a href=\"admin.php?do=adactivate&adid=$adid\">activate advert</a> | <a href=\"admin.php?do=addelete&adid=$adid\">delete advert</a><br>";
}
}
$main.="</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><b>Active adverts:</b></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>";
$listresult=mysql_query("SELECT * FROM $adverts_table WHERE active='yes'");
$countadvert=mysql_num_rows($listresult);
if ($countadvert < 1) {
$main.="You have no active adverts in your database.<br>";
} else {
while($rowadvert=mysql_fetch_array($listresult)) {
$adid=$rowadvert[adid];
$userid=$rowadvert[userid];
$getuser=mysql_fetch_array(mysql_query("SELECT * FROM $advertiser_table WHERE userid='$userid'"));
$main.="ID: $adid, by <a href=\"admin.php?do=showclient&userid=$userid\">$getuser[realname]</a> (userID <a href=\"admin.php?do=showclient&userid=$userid\">$userid</a>) <a href=\"admin.php?do=adstats&adid=$adid\">stats</a> | <a href=\"admin.php?do=addeactivate&adid=$adid\">expire advert</a><br>";
}
}
$main.="</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><b>Expired adverts:</b></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>";
$listresult=mysql_query("SELECT * FROM $adverts_table WHERE active='no' AND views!='0'");
$countadvert=mysql_num_rows($listresult);
if ($countadvert < 1) {
$main.="You have no expired adverts in your database.<br>";
} else {
while($rowadvert=mysql_fetch_array($listresult)) {
$adid=$rowadvert[adid];
$userid=$rowadvert[userid];
$getuser=mysql_fetch_array(mysql_query("SELECT * FROM $advertiser_table WHERE userid='$userid'"));
$main.="ID: $adid, by <a href=\"admin.php?do=showclient&userid=$userid\">$getuser[realname]</a> (userID <a href=\"admin.php?do=showclient&userid=$userid\">$userid</a>) <a href=\"admin.php?do=adstats&adid=$adid\">stats</a> | <a href=\"admin.php?do=adactivate&adid=$adid\">activate advert</a> | <a href=\"admin.php?do=addelete&adid=$adid\">delete advert</a><br>";
}
}
$main.="</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><b>Client list:</b></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>";
$listresult=mysql_query("SELECT * FROM $advertiser_table");
$countadvertiser=mysql_num_rows($listresult);
if ($countadvertiser < 1) {
$main.="You have no clients in your database.<br>";
} else {
while($rowadvertiser=mysql_fetch_array($listresult)) {
$userid=$rowadvertiser[userid];
$cname=$rowadvertiser[realname];
$main.="userID: $userid - <a href=\"admin.php?do=showclient&userid=$userid\">$cname</a><br>";
}
}
$main.="<p align=\"center\"><b><a href=\"admin.php\">Back to the main page</a></b></p>
</td>
</tr>
</table>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
if ($do=='main') {
$main_query=mysql_query("SELECT * FROM $redir_table");
$count_members=mysql_num_rows($main_query);
$main="<br>
<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"500\" align=\"center\">
<tr>
<td colspan=\"2\"><b>Members in your database:</b> $count_members <a href=\"admin.php?do=listmembers\">List</a></td>
</tr>
</table>
<form action=\"admin.php\" method=\"post\">
<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"600\" align=\"center\">
<tr>
<td align=\"center\" colspan=\"2\"><b>$result_message</b></td>
</tr>
<tr>
<td align=\"center\" colspan=\"2\"><b>Administration</b></td>
</tr>
<tr>
<td align=\"center\">
<input type=\"radio\" name=\"do\" value=\"edit\" style=\"border:none\">
</td>
<td>
Edit options
</td>
</tr>
<tr>
<td align=\"center\">
<input type=\"radio\" name=\"do\" value=\"add\" style=\"border:none\">
</td>
<td>
Add/delete domains (tlds) for using in your service
</td>
</tr>
<tr>
<td align=\"center\">
<input type=\"radio\" name=\"do\" value=\"category\" style=\"border:none\">
</td>
<td>
Add/delete categories (users have to categorize their subdomains)
</td>
</tr>
<tr>
<td align=\"center\">
<input type=\"radio\" name=\"do\" value=\"adverts\" style=\"border:none\">
</td>
<td>
Set advertising to
<select name=\"adtype\">
<option value=\"upperframe\" selected>upperframe</option>
<option value=\"lowerframe\">lowerframe</option>
<option value=\"ad-free\">ad-free</option>
</select>
(currently active: <b>$ads</b>)
</td>
</tr>
<tr>
<td align=\"center\">
<input type=\"radio\" name=\"do\" value=\"admanager\" style=\"border:none\">
</td>
<td>
Advertising management
</td>
</tr>
<tr>
<td align=\"center\">
<input type=\"radio\" name=\"do\" value=\"news\" style=\"border:none\">
</td>
<td>
Send an email to
<select name=\"towho\">
<option value=\"newsletterowners\" selected>newletter-owners</option>
<option value=\"allmembers\">all members</option>
<option value=\"adclients\">adclients</option>
</select>
</td>
</tr>
<tr>
<td align=\"center\">
<input type=\"radio\" name=\"do\" value=\"searchmember\" style=\"border:none\">
</td>
<td>
Search for members containing
<input type=\"text\" name=\"searchstring\">
</td>
</tr>
<tr>
<td align=\"center\">
<input type=\"radio\" name=\"do\" value=\"delinactive\" style=\"border:none\">
</td>
<td>
Delete all accounts not active since more than 60 days
</td>
</tr>
<tr>
<td align=\"center\" colspan=\"2\" align=\"center\">
<br>
<input type=\"submit\" name=\"submit\" value=\"Go!\">
</td>
</tr>
</table>
</form>";
$template = new MyredTemplate("template/template.html");
$template->assign("TITLE", $pagetitle);
$template->assign("MENU", $menu);
$template->assign("MAIN", $main);
$template->myred_print() or die($template->error);
exit;
}
?>