Guest User

Untitled

a guest
Oct 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. <?php
  2.  
  3. ?>
  4. <html>
  5. <head>
  6. <style type="text/css">
  7. body, th, td, input, textarea {
  8. font-family: Arial, Helvetica, sans-serif;
  9. font-size: 12px;
  10. color: #000000;
  11. }
  12.  
  13. body {
  14. text-align:center; /* for IE */
  15. }
  16.  
  17. div#wrapper {
  18. text-align:left; /* reset text alignment */
  19. width:400px; /* or a percentage, or whatever */
  20. //margin:0 auto; /* for the rest */
  21. }
  22.  
  23. table {
  24. border-width: 2px;
  25. border-spacing: 4px;
  26. border-style: outset;
  27. border-color: gray;
  28. border-collapse: collapse;
  29. background-color: rgb(255, 255, 240);
  30. }
  31. table th {
  32. border-width: 1px;
  33. padding: 1px;
  34. border-style: inset;
  35. border-color: gray;
  36. background-color: white;
  37. -moz-border-radius: ;
  38. }
  39.  
  40. table td {
  41. border-width: 1px;
  42. padding: 1px;
  43. border-style: inset;
  44. border-color: gray;
  45. background-color: #FFFFF0;
  46. -moz-border-radius: ;
  47. }
  48.  
  49. </style>
  50. </head>
  51. <body>
  52. <div id="wrapper">
  53. <br />
  54. <h2>
  55. <a href="adstats.php?key=1">Today</a>
  56. </h2>
  57.  
  58.  
  59.  
  60. <?php
  61.  
  62. if(array_key_exists("key", $_REQUEST)){
  63. date_default_timezone_set ( 'America/Los_Angeles' );
  64.  
  65. if(array_key_exists("mm", $_REQUEST)){
  66. $curTimeMonth = (int)$_REQUEST["mm"];
  67. } else {
  68. $curTimeMonth = (int)date('n');
  69. }
  70.  
  71. if(array_key_exists("dd", $_REQUEST)){
  72. $curTimeDay = (int)$_REQUEST["dd"];
  73. } else {
  74. $curTimeDay = (int)date('j');
  75. }
  76.  
  77. $curTimeHour = (int)date('G');
  78. //$curTimeDay = (int)date('j');
  79. //$curTimeMonth = (int)date('n');
  80. $curTimeYear = (int)date('Y');
  81.  
  82. echo($curTimeYear . "-" . $curTimeMonth . "-". $curTimeDay . "<br>");
  83.  
  84.  
  85. $auth_host = "yourserveriphere";
  86. $auth_user = "somedbuser";
  87. $auth_pass = "thepassword";
  88. $auth_dbase = "yourdbname";
  89. mysql_connect($auth_host, $auth_user, $auth_pass) or die("Could Not Connect to Database!: ".mysql_error());
  90. mysql_select_db($auth_dbase) or die("Could Not Select DB: ".mysql_error());
  91.  
  92.  
  93. $sql = "select DISTINCT site, timehour, count(id) as adcount,adstatus from adtracker
  94. where 1=1
  95. and MONTH(daytimestamp)=$curTimeMonth
  96. and DAY(daytimestamp)=$curTimeDay
  97. and YEAR(daytimestamp)=$curTimeYear
  98. group by site,timehour,adstatus
  99. order by timehour desc,site asc, adstatus asc";
  100. $result = mysql_query($sql);
  101. $numitems = mysql_num_rows($result);
  102. //echo("Num Items: " . $numitems . "<br />");
  103. //echo("<table width='300px' border=1>\n");
  104. $td = "<td>";
  105. $etd = "</td>";
  106. $br = "<br>\n";
  107.  
  108. $minadrev = 2.5/1000;
  109. $maxadrev = 4.50/1000;
  110.  
  111. for ($j = 0; $j < $numitems; $j++){
  112. $itemrow = mysql_fetch_array($result);
  113. $timehour = $itemrow["timehour"];
  114. $site = $itemrow["site"];
  115. $adcount = $itemrow["adcount"];
  116. $adstatus = $itemrow["adstatus"];
  117. $sites[$site][$timehour][$adstatus] = $adcount;
  118. /*
  119. echo("<tr>");
  120. echo($td . $timehour . $etd);
  121. echo($td . $site . $etd);
  122. echo($td . $adcount . $etd);
  123. echo($td . $adstatus . $etd);
  124. echo("</tr>\n");
  125. */
  126. }
  127. //echo "</table>";
  128. //echo $br;
  129.  
  130. $sitecount = count($sites);
  131. foreach ($sites as $key => $site) {
  132. //echo("site: " . $key) . $br;
  133. echo("<table width='100%' border=1>\n");
  134. echo("<th colspan='6'>Site: " . $key . "</th>\n");
  135. echo("<tr>\n");
  136. echo($td . "Hour" . $etd);
  137. echo($td . "Ads" . $etd);
  138. echo($td . "Blanks" . $etd);
  139. echo($td . "Total" . $etd);
  140. echo($td . "Success" . $etd);
  141. echo($td . "Ad Rev" . $etd);
  142. echo("</tr>\n");
  143.  
  144. $totalsiteattempts = 0;
  145. $totalsitesuccess = 0;
  146. $totalsitefailures = 0;
  147.  
  148. //print_r($sites[$key]);
  149. foreach($sites[$key] as $hkey=>$sitehours) {
  150. //echo($sitehour[1]);
  151. //echo($sitehour[2]);
  152. $numhours = count($sites[$key]);
  153. if($numhours > $totalnumhours)
  154. {
  155. $totalnumhours = $numhours;
  156. }
  157.  
  158. echo("<tr>\n");
  159. echo($td . $hkey . $etd);
  160. echo($td . $sitehours[1] . $etd);
  161. echo($td . $sitehours[2] . $etd);
  162.  
  163. //echo("Success:" . $sitehours[1] . $br);
  164. //echo("Fail:" . $sitehours[2] . $br);
  165. $success = $sitehours[1];
  166. $failure = $sitehours[2];
  167. $total = $success + $failure;
  168. $adrev = "$" . intval($minadrev * $success) . " - " . "$" . intval($maxadrev * $success);
  169.  
  170. $hoursuccess[$hkey] = $hoursuccess[$hkey] + $success;
  171. $hourfailure[$hkey] = $hourfailure[$hkey] + $failure;
  172.  
  173. $percentsuccess = intval(($success / $total) * 100);
  174. $totalsiteattempts = $totalsiteattempts + $total;
  175. $totalsitesuccess = $totalsitesuccess + $success;
  176. $totalsitefailures = $totalsitefailures + $failure;
  177. echo($td . $total . $etd);
  178. echo($td . $percentsuccess . "%" . $etd);
  179. echo($td . $adrev . $etd);
  180.  
  181. /*foreach ($sitehours as $sitehour) {
  182. $success = $sitehour[1] / $sitehour[2];
  183. echo("Hour [" . $sitehours . "]" . $success . $br);
  184. }
  185. */
  186. }
  187.  
  188. $totalsitepercentsuccess = intval(($totalsitesuccess / $totalsiteattempts) * 100);
  189. $totaladrev = "$" . intval($minadrev * $totalsitesuccess) . " - " . "$" . intval($maxadrev * $totalsitesuccess);
  190. $allsiteattempts = $allsiteattempts + $totalsiteattempts;
  191. $allsitesuccess = $allsitesuccess + $totalsitesuccess;
  192. $allsitefailures = $allsitefailures + $totalsitefailures;
  193. echo("</tr>\n");
  194. echo("<tr>\n");
  195. echo($td . "Total" . $etd);
  196. echo($td . $totalsitesuccess . $etd);
  197. echo($td . $totalsitefailures . $etd);
  198. echo($td . $totalsiteattempts . $etd);
  199. echo($td . $totalsitepercentsuccess . "%" . $etd);
  200. echo($td . $totaladrev);
  201. echo("</tr>\n");
  202. echo "</table>";
  203. echo $br;
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //----------------------- HOURLY TOTALS
  208. //----------------------------------------------------------------------------------------
  209.  
  210. echo("<table width='100%' border=1>\n");
  211. echo("<th colspan='6'>Hourly Totals</th>\n");
  212.  
  213. echo("<tr>\n");
  214. echo($td . "Hour" . $etd);
  215. echo($td . "Ads" . $etd);
  216. echo($td . "Blanks" . $etd);
  217. echo($td . "Total" . $etd);
  218. echo($td . "Success" . $etd);
  219. echo($td . "Ad Rev" . $etd);
  220. echo("</tr>\n");
  221.  
  222. foreach($hoursuccess as $hrkey=>$sitehoursuccess){
  223. echo("<tr>\n");
  224. echo($td . $hrkey . $etd);
  225. echo($td . $sitehoursuccess . $etd);
  226. echo($td . $hourfailure[$hrkey] . $etd);
  227.  
  228. $total = $sitehoursuccess + $hourfailure[$hrkey];
  229. $hourpercentsuccess = intval(($sitehoursuccess / $total) * 100);
  230. $houradrev = "$" . intval($minadrev * $sitehoursuccess) . " - " . "$" . intval($maxadrev * $sitehoursuccess);
  231.  
  232. echo($td . $total . $etd);
  233. echo($td . $hourpercentsuccess . "%" . $etd);
  234. echo($td . $houradrev . $etd);
  235. echo("</tr>\n");
  236.  
  237. //echo("1 " . $hrkey . $br);
  238. //echo("2 " . $sitehoursuccess . $br);
  239. //echo("3 " . $hourfailure[$hrkey] . $br);
  240.  
  241.  
  242. }
  243.  
  244. echo "</table>";
  245. echo $br;
  246.  
  247. //----------------------------------------------------------------------------------------
  248. //----------------------- TOTALS
  249. //----------------------------------------------------------------------------------------
  250.  
  251. $allsitepercentsuccess = intval(($allsitesuccess / $allsiteattempts) * 100);
  252. $allsiteadrevenue = "$" . intval($minadrev * $allsitesuccess) . " - " . "$" . intval($maxadrev * $allsitesuccess) ;
  253. echo("<table width='100%' border=1>\n");
  254.  
  255. echo("<th colspan='6'>Totals</th>\n");
  256.  
  257. echo("<tr>\n");
  258. echo($td . "" . $etd);
  259. echo($td . "Ads" . $etd);
  260. echo($td . "Blanks" . $etd);
  261. echo($td . "Total" . $etd);
  262. echo($td . "Success" . $etd);
  263. echo($td . "Ad Rev" . $etd);
  264. echo("</tr>\n");
  265.  
  266. echo("<tr>\n");
  267. echo($td . "Total" . $etd);
  268. echo($td . $allsitesuccess . $etd);
  269. echo($td . $allsitefailures . $etd);
  270. echo($td . $allsiteattempts . $etd);
  271. echo($td . $allsitepercentsuccess . "%" . $etd);
  272. echo($td . $allsiteadrevenue . $etd);
  273. echo("</tr>\n");
  274. echo "</table>";
  275. echo $br;
  276. //----------------------------------------------------------------------------------------
  277.  
  278.  
  279. //----------------------------------------------------------------------------------------
  280. //----------------------- PROJECTION
  281. //----------------------------------------------------------------------------------------
  282. //echo("numhours :" . $totalnumhours);
  283. $projallsitesuccess = intval(($allsitesuccess / $totalnumhours) * 24);
  284. $projallsitefailures = intval(($allsitefailures / $totalnumhours) * 24);
  285. $projallsiteattempts = intval($projallsitefailures + $projallsitesuccess);
  286. $projallsitepercentsuccess = intval(($projallsitesuccess / $projallsiteattempts) * 100);
  287. $projallsiteadrevenue = "$" . intval($minadrev * $projallsitesuccess) . " - " . "$" . intval($maxadrev * $projallsitesuccess) ;
  288. echo("<table width='100%' border=1>\n");
  289.  
  290. echo("<th colspan='6'>Projection</th>\n");
  291.  
  292. echo("<tr>\n");
  293. echo($td . "" . $etd);
  294. echo($td . "Ads" . $etd);
  295. echo($td . "Blanks" . $etd);
  296. echo($td . "Total" . $etd);
  297. echo($td . "Success" . $etd);
  298. echo($td . "Ad Rev" . $etd);
  299. echo("</tr>\n");
  300.  
  301. echo("<tr>\n");
  302. echo($td . "Total" . $etd);
  303. echo($td . $projallsitesuccess . $etd);
  304. echo($td . $projallsitefailures . $etd);
  305. echo($td . $projallsiteattempts . $etd);
  306. echo($td . $projallsitepercentsuccess . "%" . $etd);
  307. echo($td . $projallsiteadrevenue . $etd);
  308. echo("</tr>\n");
  309. echo "</table>";
  310. echo $br;
  311. //----------------------------------------------------------------------------------------
  312. }
  313. ?>
  314. <h2>
  315. <a href="adstats.php?key=1">Today</a>
  316. </h2>
  317. </div>
  318. </body>
  319. </html>
Add Comment
Please, Sign In to add comment