Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ?>
- <html>
- <head>
- <style type="text/css">
- body, th, td, input, textarea {
- font-family: Arial, Helvetica, sans-serif;
- font-size: 12px;
- color: #000000;
- }
- body {
- text-align:center; /* for IE */
- }
- div#wrapper {
- text-align:left; /* reset text alignment */
- width:400px; /* or a percentage, or whatever */
- //margin:0 auto; /* for the rest */
- }
- table {
- border-width: 2px;
- border-spacing: 4px;
- border-style: outset;
- border-color: gray;
- border-collapse: collapse;
- background-color: rgb(255, 255, 240);
- }
- table th {
- border-width: 1px;
- padding: 1px;
- border-style: inset;
- border-color: gray;
- background-color: white;
- -moz-border-radius: ;
- }
- table td {
- border-width: 1px;
- padding: 1px;
- border-style: inset;
- border-color: gray;
- background-color: #FFFFF0;
- -moz-border-radius: ;
- }
- </style>
- </head>
- <body>
- <div id="wrapper">
- <br />
- <h2>
- <a href="adstats.php?key=1">Today</a>
- </h2>
- <?php
- if(array_key_exists("key", $_REQUEST)){
- date_default_timezone_set ( 'America/Los_Angeles' );
- if(array_key_exists("mm", $_REQUEST)){
- $curTimeMonth = (int)$_REQUEST["mm"];
- } else {
- $curTimeMonth = (int)date('n');
- }
- if(array_key_exists("dd", $_REQUEST)){
- $curTimeDay = (int)$_REQUEST["dd"];
- } else {
- $curTimeDay = (int)date('j');
- }
- $curTimeHour = (int)date('G');
- //$curTimeDay = (int)date('j');
- //$curTimeMonth = (int)date('n');
- $curTimeYear = (int)date('Y');
- echo($curTimeYear . "-" . $curTimeMonth . "-". $curTimeDay . "<br>");
- $auth_host = "yourserveriphere";
- $auth_user = "somedbuser";
- $auth_pass = "thepassword";
- $auth_dbase = "yourdbname";
- mysql_connect($auth_host, $auth_user, $auth_pass) or die("Could Not Connect to Database!: ".mysql_error());
- mysql_select_db($auth_dbase) or die("Could Not Select DB: ".mysql_error());
- $sql = "select DISTINCT site, timehour, count(id) as adcount,adstatus from adtracker
- where 1=1
- and MONTH(daytimestamp)=$curTimeMonth
- and DAY(daytimestamp)=$curTimeDay
- and YEAR(daytimestamp)=$curTimeYear
- group by site,timehour,adstatus
- order by timehour desc,site asc, adstatus asc";
- $result = mysql_query($sql);
- $numitems = mysql_num_rows($result);
- //echo("Num Items: " . $numitems . "<br />");
- //echo("<table width='300px' border=1>\n");
- $td = "<td>";
- $etd = "</td>";
- $br = "<br>\n";
- $minadrev = 2.5/1000;
- $maxadrev = 4.50/1000;
- for ($j = 0; $j < $numitems; $j++){
- $itemrow = mysql_fetch_array($result);
- $timehour = $itemrow["timehour"];
- $site = $itemrow["site"];
- $adcount = $itemrow["adcount"];
- $adstatus = $itemrow["adstatus"];
- $sites[$site][$timehour][$adstatus] = $adcount;
- /*
- echo("<tr>");
- echo($td . $timehour . $etd);
- echo($td . $site . $etd);
- echo($td . $adcount . $etd);
- echo($td . $adstatus . $etd);
- echo("</tr>\n");
- */
- }
- //echo "</table>";
- //echo $br;
- $sitecount = count($sites);
- foreach ($sites as $key => $site) {
- //echo("site: " . $key) . $br;
- echo("<table width='100%' border=1>\n");
- echo("<th colspan='6'>Site: " . $key . "</th>\n");
- echo("<tr>\n");
- echo($td . "Hour" . $etd);
- echo($td . "Ads" . $etd);
- echo($td . "Blanks" . $etd);
- echo($td . "Total" . $etd);
- echo($td . "Success" . $etd);
- echo($td . "Ad Rev" . $etd);
- echo("</tr>\n");
- $totalsiteattempts = 0;
- $totalsitesuccess = 0;
- $totalsitefailures = 0;
- //print_r($sites[$key]);
- foreach($sites[$key] as $hkey=>$sitehours) {
- //echo($sitehour[1]);
- //echo($sitehour[2]);
- $numhours = count($sites[$key]);
- if($numhours > $totalnumhours)
- {
- $totalnumhours = $numhours;
- }
- echo("<tr>\n");
- echo($td . $hkey . $etd);
- echo($td . $sitehours[1] . $etd);
- echo($td . $sitehours[2] . $etd);
- //echo("Success:" . $sitehours[1] . $br);
- //echo("Fail:" . $sitehours[2] . $br);
- $success = $sitehours[1];
- $failure = $sitehours[2];
- $total = $success + $failure;
- $adrev = "$" . intval($minadrev * $success) . " - " . "$" . intval($maxadrev * $success);
- $hoursuccess[$hkey] = $hoursuccess[$hkey] + $success;
- $hourfailure[$hkey] = $hourfailure[$hkey] + $failure;
- $percentsuccess = intval(($success / $total) * 100);
- $totalsiteattempts = $totalsiteattempts + $total;
- $totalsitesuccess = $totalsitesuccess + $success;
- $totalsitefailures = $totalsitefailures + $failure;
- echo($td . $total . $etd);
- echo($td . $percentsuccess . "%" . $etd);
- echo($td . $adrev . $etd);
- /*foreach ($sitehours as $sitehour) {
- $success = $sitehour[1] / $sitehour[2];
- echo("Hour [" . $sitehours . "]" . $success . $br);
- }
- */
- }
- $totalsitepercentsuccess = intval(($totalsitesuccess / $totalsiteattempts) * 100);
- $totaladrev = "$" . intval($minadrev * $totalsitesuccess) . " - " . "$" . intval($maxadrev * $totalsitesuccess);
- $allsiteattempts = $allsiteattempts + $totalsiteattempts;
- $allsitesuccess = $allsitesuccess + $totalsitesuccess;
- $allsitefailures = $allsitefailures + $totalsitefailures;
- echo("</tr>\n");
- echo("<tr>\n");
- echo($td . "Total" . $etd);
- echo($td . $totalsitesuccess . $etd);
- echo($td . $totalsitefailures . $etd);
- echo($td . $totalsiteattempts . $etd);
- echo($td . $totalsitepercentsuccess . "%" . $etd);
- echo($td . $totaladrev);
- echo("</tr>\n");
- echo "</table>";
- echo $br;
- }
- //----------------------------------------------------------------------------------------
- //----------------------- HOURLY TOTALS
- //----------------------------------------------------------------------------------------
- echo("<table width='100%' border=1>\n");
- echo("<th colspan='6'>Hourly Totals</th>\n");
- echo("<tr>\n");
- echo($td . "Hour" . $etd);
- echo($td . "Ads" . $etd);
- echo($td . "Blanks" . $etd);
- echo($td . "Total" . $etd);
- echo($td . "Success" . $etd);
- echo($td . "Ad Rev" . $etd);
- echo("</tr>\n");
- foreach($hoursuccess as $hrkey=>$sitehoursuccess){
- echo("<tr>\n");
- echo($td . $hrkey . $etd);
- echo($td . $sitehoursuccess . $etd);
- echo($td . $hourfailure[$hrkey] . $etd);
- $total = $sitehoursuccess + $hourfailure[$hrkey];
- $hourpercentsuccess = intval(($sitehoursuccess / $total) * 100);
- $houradrev = "$" . intval($minadrev * $sitehoursuccess) . " - " . "$" . intval($maxadrev * $sitehoursuccess);
- echo($td . $total . $etd);
- echo($td . $hourpercentsuccess . "%" . $etd);
- echo($td . $houradrev . $etd);
- echo("</tr>\n");
- //echo("1 " . $hrkey . $br);
- //echo("2 " . $sitehoursuccess . $br);
- //echo("3 " . $hourfailure[$hrkey] . $br);
- }
- echo "</table>";
- echo $br;
- //----------------------------------------------------------------------------------------
- //----------------------- TOTALS
- //----------------------------------------------------------------------------------------
- $allsitepercentsuccess = intval(($allsitesuccess / $allsiteattempts) * 100);
- $allsiteadrevenue = "$" . intval($minadrev * $allsitesuccess) . " - " . "$" . intval($maxadrev * $allsitesuccess) ;
- echo("<table width='100%' border=1>\n");
- echo("<th colspan='6'>Totals</th>\n");
- echo("<tr>\n");
- echo($td . "" . $etd);
- echo($td . "Ads" . $etd);
- echo($td . "Blanks" . $etd);
- echo($td . "Total" . $etd);
- echo($td . "Success" . $etd);
- echo($td . "Ad Rev" . $etd);
- echo("</tr>\n");
- echo("<tr>\n");
- echo($td . "Total" . $etd);
- echo($td . $allsitesuccess . $etd);
- echo($td . $allsitefailures . $etd);
- echo($td . $allsiteattempts . $etd);
- echo($td . $allsitepercentsuccess . "%" . $etd);
- echo($td . $allsiteadrevenue . $etd);
- echo("</tr>\n");
- echo "</table>";
- echo $br;
- //----------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------
- //----------------------- PROJECTION
- //----------------------------------------------------------------------------------------
- //echo("numhours :" . $totalnumhours);
- $projallsitesuccess = intval(($allsitesuccess / $totalnumhours) * 24);
- $projallsitefailures = intval(($allsitefailures / $totalnumhours) * 24);
- $projallsiteattempts = intval($projallsitefailures + $projallsitesuccess);
- $projallsitepercentsuccess = intval(($projallsitesuccess / $projallsiteattempts) * 100);
- $projallsiteadrevenue = "$" . intval($minadrev * $projallsitesuccess) . " - " . "$" . intval($maxadrev * $projallsitesuccess) ;
- echo("<table width='100%' border=1>\n");
- echo("<th colspan='6'>Projection</th>\n");
- echo("<tr>\n");
- echo($td . "" . $etd);
- echo($td . "Ads" . $etd);
- echo($td . "Blanks" . $etd);
- echo($td . "Total" . $etd);
- echo($td . "Success" . $etd);
- echo($td . "Ad Rev" . $etd);
- echo("</tr>\n");
- echo("<tr>\n");
- echo($td . "Total" . $etd);
- echo($td . $projallsitesuccess . $etd);
- echo($td . $projallsitefailures . $etd);
- echo($td . $projallsiteattempts . $etd);
- echo($td . $projallsitepercentsuccess . "%" . $etd);
- echo($td . $projallsiteadrevenue . $etd);
- echo("</tr>\n");
- echo "</table>";
- echo $br;
- //----------------------------------------------------------------------------------------
- }
- ?>
- <h2>
- <a href="adstats.php?key=1">Today</a>
- </h2>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment