function viewbanner() {
global $prefix, $dbi, $admin, $sitename, $adminmail, $nukeurl;
$bresult = sql_query("select * from ".$prefix."_banner WHERE type='0' AND active='1'", $dbi);
$numrows = sql_num_rows($bresult, $dbi);
/* Get a random banner if exist any. */
/* More efficient random stuff, thanks to Cristian Arroyo from
http://www.planetalinux.com.ar */
if($bid=="1")
{
echo "<script language=\"javascript\">
document.write('<s'+'cript language=\"JavaScript\" src=\"http://ad.altervista.org/alternet.ad?c=0&f=0&'+new Date().getTime()+'\"></s'+'cript>');
</script> ";
}
elseif($bid=="2")
{
echo "<script language=\"javascript\">
document.write('<s'+'cript language=\"JavaScript\" src=\"http://ad.altervista.org/alternet.ad?c=0&f=0&'+new Date().getTime()+'\"></s'+'cript>');
</script>";
}
elseif($bid=="3")
{
echo "<script language=\"javascript\">
document.write('<s'+'cript language=\"JavaScript\" src=\"http://ad.altervista.org/alternet.ad?c=0&f=0&'+new Date().getTime()+'\"></s'+'cript>');
</script>";
}
elseif($bid=="4")
{
echo "<script language=\"javascript\"> document.write('<s'+'cript language=\"JavaScript\" src=\"http://ad.altervista.org/alternet.ad?c=0&f=0&'+new Date().getTime()+'\"></s'+'cript>');
</script>";
}
else
{
echo"<center><a href=\"banners.php?op=click&amp;bid=$bid\" target=\"_blank\"><img src=\"$imageurl\" border=\"0\" alt='$alttext' title='$alttext'></a></center>";
}
if ($numrows>1) {
$numrows = $numrows-1;
mt_srand((double)microtime()*1000000);
$bannum = mt_rand(0, $numrows);
} else {
$bannum = 0;
}
$bresult2 = sql_query("select bid, imageurl, clickurl, alttext from ".$prefix."_banner WHERE type='0' AND active='1' limit $bannum,1", $dbi);
list($bid, $imageurl, $clickurl, $alttext) = sql_fetch_row($bresult2, $dbi);
if (!is_admin($admin)) {
sql_query("update ".$prefix."_banner set impmade=impmade+1 where bid='$bid'", $dbi);
}
if($numrows>0) {
$aborrar = sql_query("select cid, imptotal, impmade, clicks, date from ".$prefix."_banner where bid='$bid'", $dbi);
list($cid, $imptotal, $impmade, $clicks, $date) = sql_fetch_row($aborrar, $dbi);
/* Check if this impression is the last one and print the banner */
if (($imptotal <= $impmade) AND ($imptotal != 0)) {
sql_query("update ".$prefix."_banner set active='0' WHERE bid='$bid'", $dbi);
$result = sql_query("select name, contact, email from ".$prefix."_bannerclient where cid='$cid'", $dbi);
list($c_name, $c_contact, $c_email) = sql_fetch_row($result, $dbi);
if ($c_email != "") {
$from = "$sitename <$adminmail>";
$to = "$c_contact <$c_email>";
$message = ""._HELLO." $c_contact:\n\n";
$message .= ""._THISISAUTOMATED."\n\n";
$message .= ""._THERESULTS."\n\n";
$message .= ""._TOTALIMPRESSIONS." $imptotal\n";
$message .= ""._CLICKSRECEIVED." $clicks\n";
$message .= ""._IMAGEURL." $imageurl\n";
$message .= ""._CLICKURL." $clickurl\n";
$message .= ""._ALTERNATETEXT." $alttext\n\n";
$message .= ""._HOPEYOULIKED."\n\n";
$message .= ""._THANKSUPPORT."\n\n";
$message .= "- $sitename "._TEAM."\n";
$message .= "$nukeurl";
$subject = "$sitename: "._BANNERSFINNISHED."";
mail($to, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());
}
}
echo"<center><a href=\"banners.php?op=click&amp;bid=$bid\" target=\"_blank\"><img src=\"$imageurl\" border=\"0\" alt='$alttext' title='$alttext'></a></center>";
}
}