<?PHP

#####################################################################
##                                                                 ##
##                       Easy Banner Free                          ##
##                 http://www.phpwebscripts.com/                   ##
##                 e-mail: info@phpwebscripts.com                  ##
##                                                                 ##
##                                                                 ##
##                       copyright (c) 2003                        ##
##                                                                 ##
##                    This script is freeware                      ##
##                                                                 ##
##                You may distribute it by any way                 ##
##                   BUT! You may not modify it!                   ##
## Removing the link to PHPWebScripts.com is a copyright violation.##
##   Altering or removing any of the code that is responsible, in  ##
##   any way, for generating that link is strictly forbidden.      ##
##   Anyone violating the above policy will have their license     ##
##   terminated on the spot.  Do not remove that link - ever.      ##
##                                                                 ##
#####################################################################

include("../data/data.php"); include("../common.php"); session_start(); if ($HTTP_GET_VARS[action] == 'logout') log_out(); if ($s[kun]='UG93ZXJlZCBieSBFYXN5IEJhbm5lcg==') $x = 1; else $x = 0; $r = $s[phprath].$s[phpruth].$s[kun].'PC9hPjxicj4='; if ((strlen($r))!=104) exit;
if (!$HTTP_SESSION_VARS['admuser']) login($HTTP_POST_VARS); check_session ($HTTP_SESSION_VARS);

switch ($HTTP_GET_VARS[action]) {
case 'left_frame'		: left_frame();
case 'show_accounts'	: show_accounts($HTTP_GET_VARS[what]);
case 'home'				: home();
case 'password'			: password('');
case 'config'			: config_form();
case 'detail'			: detail($HTTP_GET_VARS[user]);
case 'resetstatsq'		: resetstatsq();
}
switch ($HTTP_POST_VARS[action]) {
case 'password'			: password($HTTP_POST_VARS);
case 'save_user'		: save_user($HTTP_POST_VARS);
case 'config'			: save_config($HTTP_POST_VARS);
case 'approve'			: approveuser($HTTP_POST_VARS[user]);
case 'delete'			: delete($HTTP_POST_VARS[user]);
case 'resetstats'		: resetstats();
}

function left_frame() { global $s; include("head.txt"); ?><table border=0 cellpadding=0 cellspacing=0 width="100%"><tr><td align="center" valign="top"><br><table border=0 width=95% cellspacing=2 cellpadding=0>
<TR><TD align="left" nowrap><span class="text13"><b>Menu</b><br><a target="right" href="index.php?action=show_accounts&what=all">All users</a><br><a target="right" href="index.php?action=show_accounts&what=approved">Approved users</a>
<br><a target="right" href="index.php?action=show_accounts&what=noapr">No-approved u.</a><br><a target="right" href="index.php?action=resetstatsq">Reset stats</a><br><a target="right" href="index.php?action=config">Configure</a>
<br><a target="right" href="index.php?action=password">Username/pass</a><br><br><a target="right" href="index.php?action=logout">Log out</a><br></td></tr></table></center><?PHP exit; }

function show_accounts($what) { global $s; if ($what == 'all') { $q = mysql_query("select * from ebfmembers order by number"); $info = 'All'; }
elseif ($what == 'approved') { $q = mysql_query("select * from ebfmembers where approved = 1 order by number"); $info = 'Approved'; }
elseif ($what == 'noapr') { $q = mysql_query("select * from ebfmembers where approved = 0 order by number"); $info = 'Unapproved'; }
include('./head.txt'); echo '<span class="text13blue"><b>'.$info.' Members</b></span><br>';
?><span class="text13">Sorted by join date</span><br><br><table border="0" width="98%" cellspacing="1" cellpadding="2" class="table1">
<tr><TD align="center" valign="top"><span class="text13">User<br>ID</span></TD><TD align="center" valign="top" nowrap><span class="text13">Members<br>site</span></TD><TD align="center" valign="top" nowrap><span class="text13">Banners<br>displayed by<br>this user</span></TD>
<TD align="center" valign="top" nowrap><span class="text13">Banners<br>displayed for<br>this user</span></TD><TD align="center" valign="top" nowrap><span class="text13">Not used<br>impressions</span></TD><TD align="center" valign="top" nowrap><span class="text13">Join date</span></TD></TR><?PHP
while ($data = mysql_fetch_array($q))
{ echo "<TR><TD align=\"center\"><span class=\"text13\"><a title=\"Click to view/edit details\" href=\"index.php?action=detail&user=$data[userid]\"><b>$data[userid]</b></span></TD><TD align=\"center\"><span class=\"text13\"><a title=\"Click to go to members site ($data[siteurl])\" target=\"_blank\" href=\"$data[siteurl]\">URL</a></span></TD>
  <TD align=\"center\"><span class=\"text13\">$data[meshows]</span></TD><TD align=\"center\"><span class=\"text13\">$data[weshow]</span></TD> <TD align=\"center\"><span class=\"text13\">$data[notused]</span></TD>
  <TD align=\"center\" nowrap><span class=\"text13\">$data[date]</span></TD></TR>"; $xzobr=$xzobr+$data[meshows]; $xmy=$xmy+$data[weshow]; $xnep=$xnep+$data[notused]; } ?>
<tr><TD colspan=2 align="center"><span class="text13"><b>TOTAL</b></span></TD><TD align="center"><span class="text13"><b><?PHP echo $xzobr; ?></b></span></TD><TD align="center"><span class="text13"><b><?PHP echo $xmy; ?></b></span></TD>
<TD align="center"><span class="text13"><b><?PHP echo $xnep; ?></b></span></TD><TD>&nbsp;</TD></TR></table><br><?PHP include('./footer.txt'); exit; }

function approveuser($user) { global $s; mysql_query("update ebfmembers set approved = 1 where userid = '$user'");
$q = mysql_query("select userid,approved from ebfmembers where userid = '$user'"); $data = mysql_fetch_array($q); if (!$data[userid]) problem ("User $user does not exist!");
if (($data[userid]) AND ($data[approved]!=1)) problem ("User $user can not be approved!<br>My sql error."); $s[info] = '<span class="text13blue"><b>Member has been approved.</b></span><br><br>'; detail($user); }

function save_user($data) { global $s; $q = mysql_query("update ebfmembers set siteurl = '$data[siteurl]',urlbanner = '$data[urlbanner]',email = '$data[email]',userpass = '$data[userpass]' where userid = '$data[user]'"); $s[info] = '<span class="text13blue"><b>Data has been saved</b></span><br><br>'; detail($data[user]); }
function delete($user) { global $s; mysql_query("delete from ebfmembers where userid = '$user'"); include('./head.txt'); echo "<br><br><br><center><span class=\"text13blue\"><b>Member $user has been deleted.</b></center><br><br>"; include('./footer.txt'); exit; }

function detail($user) { global $s; $q = mysql_query("select * from ebfmembers where userid = '$user'"); $data = mysql_fetch_array($q); if ($data[approved] == 1) $jeschvaleny = 'approved';
else { $jeschvaleny = 'not approved'; $schvalbutton = '<form METHOD="post" action="index.php"><input type="hidden" name="action" value="approve"><input type="hidden" name="user" value="'.$user.'"><input type="submit" name="co" value="Approve this user" class="button1" style="width=120"></form>';	}
if (!$data[userid]) problem ("User $user does not exist!");
$cas = date ("Y-m-j, H:i:s");include('./head.txt');echo $s[info].'<span class="text13blue"><b>User '.$data[userid].'</span></b><br><span class="text13blue">(This user is '.$jeschvaleny.')</span><br>'.
$schvalbutton.'<form method="POST" action="index.php"><input type="hidden" name="action" value="delete"><input type="hidden" name="user" value="'.$user.'"><INPUT type=submit value="Delete this user" name="co" class="button1" style="width=120"></form>';
?><table border="0" width="500" cellspacing="2" cellpadding="4" class="table1"><tr><td colspan=2 align="center"><span class="text13blue"><b>User's Details</b></span></td></tr>
<tr><td align="left" nowrap><span class="text13">URL</span></td><td align="left" nowrap><span class="text13"><a target="_blank" href="<?PHP echo "$data[siteurl]\">$data[siteurl]"; ?></a></span></td></tr>
<tr><td align="left" nowrap><span class="text13">Email</span></td><td align="left" nowrap><span class="text13"><a href="mailto:<?PHP echo "$data[email]\">$data[email]"; ?></a></span></td></tr>
<tr><td align="left" nowrap><span class="text13">Password</span></td><td align="left" nowrap><span class="text13"><?PHP echo $data[userpass]; ?></span></td></tr>
<tr><td align="left" nowrap><span class="text13">Date joined</span></td><td align="left" nowrap><span class="text13"><?PHP echo $data[date]; ?></span></td></tr>
<tr><td colspan="2" nowrap align="center"><span class="text13">Banner</span><br><?PHP echo "<img width=\"$s[bwidth]\" height=\"$s[bheight]\" src=\"$data[urlbanner]\">"; ?></td></tr></table>
<br><table border="0" width="500" cellspacing="2" cellpadding="4" class="table1"><tr><td colspan=2 align="center"><span class="text13blue"><b>Statistic</b></span></td></tr>
<tr><td align="left" nowrap><span class="text13">Banners displayed by this user </span></td><td align="left" nowrap><span class="text13"><?PHP echo $data[meshows]; ?></span></td></tr>
<tr><td align="left" nowrap><span class="text13">Credits earned </span></td><td align="left" nowrap><span class="text13"><?PHP echo $data[earned]; ?></span></td></tr>
<tr><td align="left" nowrap><span class="text13">Banners displayed for this user </span></td><td align="left" nowrap><span class="text13"><?PHP echo $data[weshow]; ?></span></td></tr>
<tr><td align="left" nowrap><span class="text13">Unused credits </span></td><td align="left" nowrap><span class="text13"><?PHP echo $data[notused]; ?></span></td></tr></table><br>
<form method="POST" action="index.php"><input type="hidden" name="action" value="save_user"><input type="hidden" name="user" value="<?PHP echo $data[userid]; ?>">
<table border="0" width="500" cellspacing="2" cellpadding="4" class="table1"><tr><td nowrap colspan=2 align="center"><span class="text13blue"><b>Here you can change user's details.</b></span></td></tr>
<tr><td align="left" nowrap><span class="text13">URL</span></td><td align="left" nowrap><INPUT maxLength=100 size=50 name="siteurl" value="<?PHP echo $data[siteurl]; ?>"></td></tr>
<tr><td align="left" nowrap><span class="text13">Banner URL</span></td><td align="left" nowrap><INPUT maxLength=100 size=50 name="urlbanner" value="<?PHP echo $data[urlbanner]; ?>"></td></tr>
<tr><td align="left" nowrap><span class="text13">Email</span></td><td align="left" nowrap><INPUT maxLength=70 size=50 name="email" value="<?PHP echo $data[email]; ?>"></td></tr>
<tr><td align="left" nowrap><span class="text13">Password</span></td><td align="left" nowrap><INPUT maxLength=8 size=10 name="userpass" value="<?PHP echo $data[userpass]; ?>"></td></tr><tr>
<td align="middle" width="100%" colSpan=2><INPUT type="submit" value="&nbsp;&nbsp;Save&nbsp;&nbsp;" name="m" class="button1"></span></TD></TR></TBODY></TABLE></FORM><?PHP include('./footer.txt'); exit(); }

function config_form() { global $info; include('../data/data.php'); $ratioprocent = $s[ratio]*100; include('./head.txt'); echo $info;
?><form method="POST" action="index.php"><input type="hidden" name="action" value="config"><table border="0" width="99%" cellspacing="2" cellpadding="4" class="table1">
<tr><td colspan=2 align="center"><span class="text13blue"><b>Configuration</b></span></td></tr>
<tr><td align="left"><span class="text13">Mysql database host</span></td><td align="left"><INPUT size=30 name="dbhost" value="<?PHP echo $s[dbhost]; ?>"></td></tr>
<tr><td align="left"><span class="text13">Your mysql database username</span></td><td align="left"><INPUT size=30 name="dbusername" value="<?PHP echo $s[dbusername]; ?>"></td></tr>
<tr><td align="left"><span class="text13">Mysql database password</span></td><td align="left"><INPUT size=30 name="dbpassword" value="<?PHP echo $s[dbpassword]; ?>"></td></tr>
<tr><td align="left"><span class="text13">Name of your mysql database</span></td><td align="left"><INPUT size=30 name="dbname" value="<?PHP echo $s[dbname]; ?>"></td></tr>
<tr><td align="left"><span class="text13">Full path to the folder where the scripts live. No trailing slash.</span></td><td align="left"><INPUT size=50 name="phppath" value="<?PHP echo $s[phppath]; ?>"><br><span class="text10">Sample: /htdocs/sites/user/html/easybannerfree</span></td></tr>
<tr><td align="left"><span class="text13">URL of the directory where your php scripts are installed. No trailing slash.</span></td><td align="left"><INPUT size=50 name="phpdirectory" value="<?PHP echo $s[phpdirectory]; ?>"><br><span class="text10">Sample: http://www.yourdomain.com/easybannerfree</span></td></tr>
<tr><td align="left"><span class="text13">URL of your default banner. It is displayed only if no one account has credits.</td><td align="left"><INPUT size=50 name="defaultbanner" value="<?PHP echo $s[defaultbanner]; ?>"><br><span class="text10">Sample: http://www.yourdomain.com/easybannerfree/banner.gif</span></span></td></tr>
<tr><td align="left"><span class="text13">Default URL. It gets surfer after clicking on your default banner.</span></td><td align="left"><INPUT size=50 name="defaulturl" value="<?PHP echo $s[defaulturl]; ?>"><input type="hidden" name="phprath" value="PGNlbnRlcj4="></td></tr>
<tr><td align="left"><span class="text13">Width of all banners</span></td><td align="left"><INPUT maxLength=4 size=5 name="bwidth" value="<?PHP echo $s[bwidth]; ?>"></td></tr>
<tr><td align="left"><span class="text13">Height of all banners</span></td><td align="left"><INPUT maxLength=4 size=5 name="bheight" value="<?PHP echo $s[bheight]; ?>"><input type="hidden" name="phpruth" value="PGEgaHJlZj0iaHR0cDovL3BocHdlYnNjcmlwdHMuY29tLyI+"></td></tr>
<tr><td align="left"><span class="text13">Exchange ratio. How many impressions get every member for showing 100 banners.</span></td><td align="left"><INPUT maxLength=5 size=5 name="ratioprocent" value="<?PHP echo $ratioprocent; ?>"></td></tr>
<tr><td align="left"><span class="text13">Your email address.</span></td><td align="left"><INPUT size=50 name="adminemail" value="<?PHP echo $s[adminemail]; ?>"></td></tr>
<tr><td align="middle" width="100%" colSpan=2><INPUT type=submit value="&nbsp;&nbsp;Save&nbsp;&nbsp;" name="D1" class="button1"></span></TD></TR></TBODY></TABLE></FORM>
<?PHP include('./footer.txt'); exit(); }

function resetstats() { global $s; $q = mysql_query("update ebfmembers set weshow = 0, notused  = 0, meshows = 0, earned = 0");$a = fopen("$s[phppath]/data/resettime","w"); fwrite ($a,time()); fclose ($a);include('./head.txt'); echo '<br><br><center><span class="text13blue"><b>All stats has been reseted to zero.</b></span><br>'; include('./footer.txt'); exit; }
function resetstatsq() { global $s;include('./head.txt');echo '<br><br><center><span class="text13blue"><b>This function resets all stats to zero. Are you sure?</b></span><form action="index.php" method="POST"><input type="hidden" name="action" value="resetstats"><input type="submit" name="xx" value="Yes, reset it" class="button1"></form>'; include('./footer.txt'); exit; }
function save_config($form) { global $info; set_magic_quotes_runtime(0); $form[ratio] = $form[ratioprocent]/100; unset ($form[submit],$form[action],$form[D1],$form[ratioprocent]); reset ($form); while (list ($key, $val) = each ($form)) { $val = strip_replace_once($val); $val = ereg_replace('"','\"',$val); if ($val=='on') $val = 1; $data .= "\$s[$key] = \"$val\";"; } 
$data = "<?PHP $data ?>"; if (!$sb = fopen("$form[phppath]/data/data.php","w")) problem ("Cannot write to file 'data.php' in your data directory. Please make sure that your data directory exists and has 777 permission and the file 'data.php' inside has permission 666. Cannot continue."); $zapis = fwrite ($sb, $data); fclose($sb); if (!$zapis) $info = "<span class=\"text13blue\"><b>Can not write to file 'data.php'.<br>Please make sure that your data directory exists and has 777 permission and the file 'data.php' inside has permission 666. Cannot continue.</b></span><br><br>"; else $info = "<span class=\"text13blue\"><b>Your setting has been updated</b></span><br><br>"; config_form(); }
function home() {global $s; include("head.txt");?><table border=0 cellpadding=0 cellspacing=0 width="100%"><tr><td width=750 align="center" valign="top"><br><br><br><br><br><span class="text13blue"><b>Welcome to the Admin Area</b></span><br><br><span class="text13">Please select a function from the menu on the left</span></td></tr></table></center><?PHP exit; }
function log_out() { global $s; session_destroy(); if (!$s[info]) $s[info] = '<span class="text13"><font color="red"><b>You have been logged out</b></font></span><br><br>'; login (0); exit;  }
function strip_replace_array ($a) { if (!$a) return $a; reset ($a); while (list ($k, $v) = each ($a)) { if (is_array($v)) continue;$a[$k] = ereg_replace("''","'",strip_tags($v));$a[$k] = htmlspecialchars(ereg_replace("[\]",'',$a[$k]));$a[$k] = eregi_replace('&amp;','&',$a[$k]); } return $a; }
function strip_replace_once ($x) { if (!$x) return $x; $x = ereg_replace("''","'",$x);$x = stripslashes($x);$x = eregi_replace('&amp;','&',$x);return $x; }
function check_session($data) { global $s;$a = file("$s[phppath]/data/.htpasswd");$b = split (':',trim($a[0])); if ($data[admuser]!=$b[0]) { session_destroy();$s[info] = '<span class="text13"><font color="red"><b>An error has occurred. Please login again.</b></span><br><br>';login(0); } }

function password($a) { global $s; include("./head.txt");
if (($a[newuser]) AND ($a[newpass])) { $sb = fopen("$s[phppath]/data/.htpasswd","w"); $zapis = fwrite ($sb, "$a[newuser]:" . MD5($a[newpass])); fclose($sb);@chmod(".htpasswd", 0666);if (!$zapis) problem ("Can not write to the .htpasswd file. Please make sure that the data directory has 777 permission and the .htaccess file has 666 permission.");echo '<br><br><center><span class="text13blue"><b>Admin username and password have been updated.<br>If you have modified your username, you now have to log in again.</b></span><br><br>'; include("footer.txt"); exit(); }
if (($a[newuser]) OR ($a[newpass])) echo '<div align=center><center><br><span class="text13blue"><b>Both fields are required</b></span><br>'; ?>
<br><table border="0" width="200" cellspacing="10" cellpadding="2" class="table1"><form action="index.php" method="post"><input type="hidden" name="action" value="password">
<TR><td align="center" nowrap colspan=2><span class="text13blue"><b>Change admin username/password</b></span></td></tr>
<TR><td align="right" nowrap><span class="text13">New username </span></td><td align="left"><input type="text" size="10" name="newuser" value=<?PHP echo $a[newuser]; ?>></td></tr>
<tr><td align="right" nowrap><span class="text13">New password </span></td><td align="left"><input type="text" size="10" name="newpass" value=<?PHP echo $a[newpass]; ?>></td></tr>
<tr><td align="center" colspan=2><input type="submit" name="A1" value="&nbsp;&nbsp;&nbsp;Submit&nbsp;&nbsp;&nbsp;" class="button1"></td></tr></table></form></center></div> <?PHP include("footer.txt"); exit; }

function login($form) { global $s,$HTTP_SESSION_VARS; 
if (!$form) { echo '<script>
<!--
if (window!= top)
top.location.href=location.href
// -->
</script>'; include("head.txt"); 
echo $s[info]; ?><table border="0" width="200" cellspacing="2" cellpadding="4" class="table1"><form method="POST" action="index.php">
<tr><td align="left"><span class="text13">Username</span></td><td align="left"><input name="username" size=15 maxlength=15 value="<?PHP echo $s[pusername] ?>"></td></tr>
<tr><td align="left"><span class="text13">Password</span></td><td align="left"><input type="password" name="password" size=15 maxlength=15></td></tr>
<tr><td colspan=2 align="center"><input type="submit" value="&nbsp;&nbsp;&nbsp;Submit&nbsp;&nbsp;&nbsp;" name="B1" class="button1"></td></tr></form></table>
<?PHP exit; }
$form[password] = md5($form[password]); $a = file("$s[phppath]/data/.htpasswd"); $b = split (':',trim($a[0]));
if ( ($form[username]!=$b[0]) OR ($form[password]!=$b[1]) ) { $s[info] = '<span class="text13blue"><font color="red"><b>Wrong username or password. Please try again.</b></span><br><br>'; $s[pusername] = $form[username]; login (0); exit; }
$HTTP_SESSION_VARS['admuser'] = $form['username']; 
header ("Location: index.html"); }

?>



