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"
$alttext
"; } } /********************************************/ /* Function to redirect the clicks to the */ /* correct url and add 1 click */ /********************************************/ function clickbanner($bid) { global $prefix, $dbi; $bresult = sql_query("select clickurl from ".$prefix."_banner where bid='$bid'", $dbi); list($clickurl) = sql_fetch_row($bresult, $dbi); sql_query("update ".$prefix."_banner set clicks=clicks+1 where bid='$bid'", $dbi); Header("Location: $clickurl"); } /********************************************/ /* Function to let your client login to see */ /* the stats */ /********************************************/ function clientlogin() { echo"




Advertising Statistics
Login:
Password:
Please type your client information
"; } /*********************************************/ /* Function to display the banners stats for */ /* each client */ /*********************************************/ function bannerstats($login, $pass) { global $prefix, $dbi, $sitename; $result = sql_query("select cid, name, passwd from ".$prefix."_bannerclient where login='$login'", $dbi); list($cid, $name, $passwd) = sql_fetch_row($result, $dbi); if($login=="" AND $pass=="" OR $pass=="") { echo "

Login Incorrect!!!

Back to Login Screen
"; } else { if ($pass==$passwd) { echo"
Current Active Banners for $name

"; $result = sql_query("select bid, imptotal, impmade, clicks, date from ".$prefix."_banner WHERE cid='$cid' AND active='1'", $dbi); while(list($bid, $imptotal, $impmade, $clicks, $date) = sql_fetch_row($result, $dbi)) { if($impmade==0) { $percent = 0; } else { $percent = substr(100 * $clicks / $impmade, 0, 5); } if($imptotal==0) { $left = "Unlimited"; } else { $left = $imptotal-$impmade; } echo " "; } echo "
ID
Imp. Made
Imp. Total
Imp. Left
Clicks
% Clicks
Functions
$bid $impmade $imptotal $left $clicks $percent% E-mail Stats


Following are your running Banners in $sitename

"; $result = sql_query("select bid, imageurl, clickurl, alttext from ".$prefix."_banner WHERE cid='$cid' AND active='1'", $dbi); while(list($bid, $imageurl, $clickurl, $alttext) = sql_fetch_row($result, $dbi)) { $numrows = sql_num_rows($result, $dbi); if ($numrows>1) { echo "

"; } echo "
Banner ID: $bid
Send E-Mail Stats for this Banner
This Banners points to this URL
Change URL:
Change Text:
"; } echo "
"; /* Finnished Banners */ echo "

Banners Finished for $name

"; $result = sql_query("select bid, impmade, clicks, imageurl, date, dateend from ".$prefix."_banner where cid='$cid' AND active='0'", $dbi); while(list($bid, $impmade, $clicks, $imageurl, $date, $dateend) = sql_fetch_row($result, $dbi)) { $percent = substr(100 * $clicks / $impmade, 0, 5); echo " "; } echo "
ID
Impressions
Clicks
% Clicks
Start Date
End Date
Functions
$bid $impmade $clicks $percent% $date $dateend View Banner

\"This "; } else { echo "

Login Incorrect!!!

Back to Login Screen
"; } } } /*********************************************/ /* Function to let the client E-mail his */ /* banner Stats */ /*********************************************/ function EmailStats($login, $cid, $bid, $pass) { global $prefix, $dbi; $result2 = sql_query("select name, email from ".$prefix."_bannerclient where cid='$cid'", $dbi); list($name, $email) = sql_fetch_row($result2, $dbi); if ($email=="") { echo "



Statistics for Banner No. $bid can't be send because
there isn't an email associated with client $name
Please contact the Administrator

Back to Banners Stats "; } else { $result = sql_query("select bid, imptotal, impmade, clicks, imageurl, clickurl, date from ".$prefix."_banner where bid='$bid' and cid='$cid'", $dbi); list($bid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date) = sql_fetch_row($result, $dbi); if($impmade==0) { $percent = 0; } else { $percent = substr(100 * $clicks / $impmade, 0, 5); } if($imptotal==0) { $left = "Unlimited"; $imptotal = "Unlimited"; } else { $left = $imptotal-$impmade; } $fecha = date("F jS Y, h:iA."); $subject = "Your Banner Statistics at $sitename"; $message = "Following are the complete stats for your advertising investment at $sitename:\n\n\nClient Name: $name\nBanner ID: $bid\nBanner Image: $imageurl\nBanner URL: $clickurl\n\nImpressions Purchased: $imptotal\nImpressions Made: $impmade\nImpressions Left: $left\nClicks Received: $clicks\nClicks Percent: $percent%\n\n\nReport Generated on: $fecha"; $from = "$sitename"; mail($email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion()); echo "



Statistics for Banner No. $bid has been send to
$email of $name

Back to Banners Stats "; } } /*********************************************/ /* Function to let the client to change the */ /* url for his banner */ /*********************************************/ function change_banner_url_by_client($login, $pass, $cid, $bid, $url, $alttext) { global $prefix, $dbi; $result = sql_query("select passwd from ".$prefix."_bannerclient where cid='$cid'", $dbi); list($passwd) = sql_fetch_row($result, $dbi); if (!empty($pass) AND $pass==$passwd) { $alttext = ereg_replace("\"", "", $alttext); $alttext = ereg_replace("'", "", $alttext); sql_query("update ".$prefix."_banner set clickurl='$url', alttext='$alttext' where bid='$bid'", $dbi); echo "
"; if ($url != "") { echo "You changed the URL
"; } if ($alttext != "") { echo "You changed the Alternate Text"; } echo "

Back to Stats Page
"; } else { echo "

Your login/password doesn't match.

Please login again
"; } } switch($op) { case "click": clickbanner($bid); break; case "login": clientlogin(); break; case "Ok": bannerstats($login, $pass); break; case "Change": change_banner_url_by_client($login, $pass, $cid, $bid, $url, $alttext); break; case "EmailStats": EmailStats($login, $cid, $bid, $pass); break; default: viewbanner(); break; } ?>