Advertisement
Guest User

leaderboard_v2

a guest
Feb 3rd, 2014
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.49 KB | None | 0 0
  1. <?php
  2. # domedan_leaderboard.php
  3. #
  4. # Copyright (C) 2012 Dan <domedan@gmail.com> LICENSE: AGPLv2
  5. #
  6. # Based on:
  7. # AST_team_performance_detail.php
  8. # Copyright (C) 2012 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
  9. #
  10. #
  11. # CHANGES
  12. #
  13. # 2012-08-16 created based on AST_team_performance_detail.php and my old version
  14. # 2012-09-11 added ereg_replace on all user input and some small fixes
  15.  
  16. // set starttime to check execution-time for this script
  17. $starttime = microtime(1);
  18.  
  19. require("dbconnect.php");
  20. require("functions.php");
  21. mysql_select_db("asterisk");
  22.  
  23. function utf_8_sprintf ($format) {
  24. # http://www.php.net/manual/en/function.sprintf.php#86304
  25. # Formats string using sprintf, but correctly handles %s with space paddings
  26. # uses conversion to iso-8859-2 and back
  27. # it is, however, much slower, so use only when needed!
  28. # @param string $format
  29.  
  30. $args = func_get_args();
  31.  
  32. for ($i = 1; $i < count($args); $i++) {
  33. $args [$i] = iconv('UTF-8', 'ISO-8859-2', $args [$i]);
  34. }
  35.  
  36. return iconv('ISO-8859-2', 'UTF-8', call_user_func_array('sprintf', $args));
  37. }
  38.  
  39.  
  40.  
  41. $PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
  42. $PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
  43. $PHP_SELF=$_SERVER['PHP_SELF'];
  44. if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];}
  45. elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];}
  46. if (isset($_GET["end_date_D"])) {$end_date_D=$_GET["end_date_D"];}
  47. elseif (isset($_POST["end_date_D"])) {$end_date_D=$_POST["end_date_D"];}
  48. if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];}
  49. elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];}
  50. if (isset($_GET["end_date_T"])) {$end_date_T=$_GET["end_date_T"];}
  51. elseif (isset($_POST["end_date_T"])) {$end_date_T=$_POST["end_date_T"];}
  52. if (isset($_GET["group"])) {$group=$_GET["group"];}
  53. elseif (isset($_POST["group"])) {$group=$_POST["group"];}
  54. if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];}
  55. elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];}
  56. if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];}
  57. elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];}
  58. if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
  59. elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
  60. if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];}
  61. elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];}
  62. if (isset($_GET["day"])) {$get_day=$_GET["day"];}
  63. elseif (isset($_POST["day"])) {$get_day=$_POST["day"];}
  64. if (isset($_GET["evening"])) {$get_evening=$_GET["evening"];}
  65. elseif (isset($_POST["evening"])) {$get_evening=$_POST["evening"];}
  66. if (isset($_GET["auto"])) {$get_auto=$_GET["auto"];}
  67. elseif (isset($_POST["auto"])) {$get_auto=$_POST["auto"];}
  68. if (isset($_GET["timeout"])) {$get_timeout=$_GET["timeout"];}
  69. elseif (isset($_POST["timeout"])) {$get_timeout=$_POST["timeout"];}
  70. if (isset($_GET["user"])) {$get_user=$_GET["user"];}
  71. elseif (isset($_POST["user"])) {$get_user=$_POST["user"];}
  72. if (isset($_GET["sort_by"])) {$get_sort=$_GET["sort_by"];}
  73. elseif (isset($_POST["sort_by"])) {$get_sort=$_POST["sort_by"];}
  74. if (isset($_GET["agentfullstats"])) {$agentfullstats=$_GET["agentfullstats"];}
  75. elseif (isset($_POST["agentfullstats"])) {$agentfullstats=$_POST["agentfullstats"];}
  76. if (isset($_GET["agentpstats"])) {$agentpstats=$_GET["agentpstats"];}
  77. elseif (isset($_POST["agentpstats"])) {$agentpstats=$_POST["agentpstats"];}
  78. if (isset($_GET["agentcc"])) {$agentcc=$_GET["agentcc"];}
  79. elseif (isset($_POST["agentcc"])) {$agentcc=$_POST["agentcc"];}
  80.  
  81. $query_date_D = ereg_replace("[^0-9\-]","",$query_date_D);
  82. $end_date_D = ereg_replace("[^0-9\-]","",$end_date_D);
  83. $query_date_T = ereg_replace("[^0-9\:]","",$query_date_T);
  84. $end_date_T = ereg_replace("[^0-9\:]","",$end_date_T);
  85. #foreach($group as $replaceme) {
  86. # $group[]=ereg_replace("[^a-öA-Ö0-9\-]","",$replaceme);
  87. #}
  88. #foreach($user_group as $user_group_link) {
  89. # $user_group[]=ereg_replace("[^0-9\:]","",$user_group_link);
  90. #}
  91. $file_download = ereg_replace("[^0-9]","",$file_download);
  92. $DB = ereg_replace("[^0-9]","",$DB);
  93. $SUBMIT = ereg_replace("[^a-öA-Ö]","",$SUBMIT);
  94. $get_day = ereg_replace("[^y]","",$get_day);
  95. $get_evening = ereg_replace("[^y]","",$get_evening);
  96. $get_auto = ereg_replace("[^y]","",$get_auto);
  97. $get_timeout = ereg_replace("[^0-9]","",$get_timeout);
  98.  
  99. $report_name = 'Leaderboard';
  100. $db_source = 'M';
  101.  
  102. #############################################
  103. ##### START SYSTEM_SETTINGS LOOKUP #####
  104. $stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db FROM system_settings;";
  105. $rslt=mysql_query($stmt, $link);
  106. if ($DB) {$HTML_text.="$stmt\n";}
  107. if ($archive_tbl) {$agent_log_table="vicidial_agent_log_archive";} else {$agent_log_table="vicidial_agent_log";}
  108. $qm_conf_ct = mysql_num_rows($rslt);
  109. if ($qm_conf_ct > 0)
  110. {
  111. $row=mysql_fetch_row($rslt);
  112. $non_latin = $row[0];
  113. $outbound_autodial_active = $row[1];
  114. $slave_db_server = $row[2];
  115. $reports_use_slave_db = $row[3];
  116. }
  117. ##### END SETTINGS LOOKUP #####
  118. ###########################################
  119.  
  120. $MT[0]='';
  121. $NOW_DATE = date("Y-m-d");
  122. $NOW_TIME = date("Y-m-d H:i:s");
  123. $STARTtime = date("U");
  124. if (!isset($group)) {$group = '';}
  125. if (!isset($query_date_D) || $query_date_D == '') {$query_date_D=$NOW_DATE;}
  126. if (!isset($end_date_D) || $end_date_D == '') {$end_date_D=$NOW_DATE;}
  127. if (!isset($query_date_T) || $query_date_T == '') {$query_date_T="00:00:00";}
  128. if (!isset($end_date_T) || $end_date_T == '') {$end_date_T="23:59:59";}
  129.  
  130.  
  131. $i=0;
  132. $group_string='|';
  133. $group_ct = count($group);
  134. while($i < $group_ct)
  135. {
  136. $group_string .= "$group[$i]|";
  137. $i++;
  138. }
  139.  
  140. $stmt="select campaign_id from vicidial_campaigns order by campaign_id;";
  141. $rslt=mysql_query($stmt, $link);
  142. if ($DB) {$HTML_text.="$stmt\n";}
  143. $campaigns_to_print = mysql_num_rows($rslt);
  144. $i=0;
  145. while ($i < $campaigns_to_print)
  146. {
  147. $row=mysql_fetch_row($rslt);
  148. $groups[$i] =$row[0];
  149. if (ereg("-ALL",$group_string) )
  150. {$group[$i] = $groups[$i];}
  151. $i++;
  152. }
  153.  
  154.  
  155. #######################################
  156. for ($i=0; $i<count($user_group); $i++)
  157. {
  158. //echo "COUNT UG".count($user_group);
  159. if (eregi("--ALL--", $user_group[$i])) {$all_user_groups=1; $user_group="";}
  160. }
  161.  
  162. $stmt="select user_group from vicidial_user_groups order by user_group;";
  163. $rslt=mysql_query($stmt, $link);
  164. if ($DB) {$HTML_text.="$stmt\n";}
  165. $user_groups_to_print = mysql_num_rows($rslt);
  166. $i=0;
  167. while ($i < $user_groups_to_print)
  168. {
  169. $row=mysql_fetch_row($rslt);
  170. $user_groups[$i] =$row[0];
  171. if ($all_user_groups) {$user_group[$i]=$row[0];}
  172. $i++;
  173. }
  174.  
  175. $i=0;
  176. $group_string='|';
  177. $group_ct = count($group);
  178. while($i < $group_ct)
  179. {
  180.  
  181. $group_string .= "$group[$i]|";
  182. $group_SQL .= "'$group[$i]',";
  183. $groupQS .= "&group[]=$group[$i]";
  184. $i++;
  185. }
  186.  
  187. if ( (ereg("--ALL--",$group_string) ) or ($group_ct < 1) )
  188. {$group_SQL = "";}
  189. else
  190. {
  191. $group_SQL = eregi_replace(",$",'',$group_SQL);
  192. $group_SQL_str=$group_SQL;
  193. $group_SQL = "and campaign_id IN($group_SQL)";
  194. }
  195.  
  196.  
  197.  
  198. $i=0;
  199. $user_group_string='|';
  200. $user_group_ct = count($user_group);
  201. while($i < ($user_group_ct))
  202. {
  203. $user_group_string .= "$user_group[$i]|";
  204. $user_group_SQL .= "'$user_group[$i]',";
  205. $user_groupQS .= "&user_group[]=$user_group[$i]";
  206. $i++;
  207. }
  208.  
  209. if ( (ereg("--ALL--",$user_group_string) ) or ($user_group_ct < 1) )
  210. {$user_group_SQL = "";}
  211. else
  212. {
  213. $user_group_SQL = eregi_replace(",$",'',$user_group_SQL);
  214. $user_group_SQL_str = $user_group_SQL;
  215. $user_group_SQL = "and vicidial_agent_log.user_group IN($user_group_SQL)";
  216. }
  217. ######################################
  218. if ($DB) {$HTML_text.="$user_group_string|$user_group_ct|$user_groupQS|$i<BR>";}
  219.  
  220.  
  221. ###########################
  222.  
  223. ##### DOMEDAN STUFF ######
  224. ##########################
  225.  
  226. // check it auto is set
  227. // and prevent auto from being set before 09:00 and after 21:00 (uncomment if you like that idea) (maybe i could get that info from shift-settings...)
  228. $minimum_auto="30"; // minimum auto in sec
  229. if ( ( date("H") >= '06' && date("H") <= '23') && ($query_date_D == $end_date_D) ) {
  230. if ($get_timeout) {
  231. if ($get_auto == 'y' && ($get_timeout < $minimum_auto)) {
  232. $timeout = $minimum_auto;
  233. } else {
  234. $timeout=$get_timeout; // else accept user input
  235. }
  236. } else {
  237. $timeout='60'; // default timeout when no timeout is set
  238. }
  239. $HTML_auto_refresh="<META HTTP-EQUIV=\"refresh\" CONTENT=\"".$timeout."\" charset=utf-8>\n"; // yeah i know it ain't no AJAX, but I'm gonna try it later in
  240. $auto='checked'; //for the data form
  241. } else {
  242. $auto='';
  243. $HTML_auto_refresh="";
  244. }
  245.  
  246.  
  247. ############################
  248. ?><style>
  249. .odd{background-color:#b7cfdc;}
  250. .tover{background-color:red;}
  251. .tover{background-color:yellow;}
  252. </style>
  253. <script>
  254. function updateURLParameter(url, param, paramVal)
  255. {
  256. var TheAnchor = null;
  257. var newAdditionalURL = "";
  258. var tempArray = url.split("?");
  259. var baseURL = tempArray[0];
  260. var additionalURL = tempArray[1];
  261. var temp = "";
  262.  
  263. if (additionalURL)
  264. {
  265. var tmpAnchor = additionalURL.split("#");
  266. var TheParams = tmpAnchor[0];
  267. TheAnchor = tmpAnchor[1];
  268. if(TheAnchor)
  269. additionalURL = TheParams;
  270.  
  271. tempArray = additionalURL.split("&");
  272.  
  273. for (i=0; i<tempArray.length; i++)
  274. {
  275. if(tempArray[i].split('=')[0] != param)
  276. {
  277. newAdditionalURL += temp + tempArray[i];
  278. temp = "&";
  279. }
  280. }
  281. }
  282. else
  283. {
  284. var tmpAnchor = baseURL.split("#");
  285. var TheParams = tmpAnchor[0];
  286. TheAnchor = tmpAnchor[1];
  287.  
  288. if(TheParams)
  289. baseURL = TheParams;
  290. }
  291.  
  292. if(TheAnchor)
  293. paramVal += "#" + TheAnchor;
  294.  
  295. var rows_txt = temp + "" + param + "=" + paramVal;
  296. return baseURL + "?" + newAdditionalURL + rows_txt;
  297. }
  298. </script>
  299.  
  300. <?php
  301. function remove_querystring_var($url, $key) {
  302. $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
  303. $url = substr($url, 0, -1);
  304. return $url;
  305. }
  306. $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  307. $url = remove_querystring_var($url, "sort_by");
  308. function truncateString($str, $chars, $to_space, $replacement="...") {
  309. if($chars > strlen($str)) return $str;
  310.  
  311. $str = substr($str, 0, $chars);
  312.  
  313. $space_pos = strrpos($str, " ");
  314. if($to_space && $space_pos >= 0) {
  315. $str = substr($str, 0, strrpos($str, " "));
  316. }
  317.  
  318. return($str . $replacement);
  319. }
  320.  
  321. $HTML_head.="<HTML>\n";
  322. $HTML_head.="<HEAD>\n";
  323. $HTML_head.="<STYLE type=\"text/css\">\n";
  324. $HTML_head.="<!--\n";
  325. $HTML_head.=" .green {color: white; background-color: green}\n";
  326. $HTML_head.=" .red {color: white; background-color: red}\n";
  327. $HTML_head.=" .blue {color: white; background-color: blue}\n";
  328. $HTML_head.=" .purple {color: white; background-color: purple}\n";
  329. $HTML_head.="-->\n";
  330. $HTML_head.=" </STYLE>\n";
  331.  
  332. $query_date="$query_date_D $query_date_T";
  333. $end_date="$end_date_D $end_date_T";
  334.  
  335. $HTML_head.="<script language=\"JavaScript\" src=\"calendar_db.js\"></script>\n";
  336. $HTML_head.="<link rel=\"stylesheet\" href=\"calendar.css\">\n";
  337. $HTML_head.="<link rel=\"stylesheet\" href=\"horizontalbargraph.css\">\n";
  338.  
  339. $HTML_head.="<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n";
  340. $HTML_head.=$HTML_auto_refresh;
  341. $HTML_head.="<TITLE>$report_name</TITLE></HEAD><BODY BGCOLOR=WHITE marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>$group_S\n";
  342.  
  343. ###IF QUERY SUBMIT HIDE SELECTION OPTIONS###
  344.  
  345. if (!$SUBMIT) {
  346. $HTML_text.="<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>";
  347.  
  348. $HTML_text.="<FORM ACTION=\"$PHP_SELF\" METHOD=GET name=vicidial_report id=vicidial_report>\n";
  349. $HTML_text.="<TABLE CELLSPACING=3><TR><TD VALIGN=TOP> <BR>";
  350. $HTML_text.="<INPUT TYPE=HIDDEN NAME=DB VALUE=\"$DB\">\n";
  351. $HTML_text.="Date Range:<BR>\n";
  352.  
  353. $HTML_text.="<INPUT TYPE=hidden NAME=query_date ID=query_date VALUE=\"$query_date\">\n";
  354. $HTML_text.="<INPUT TYPE=hidden NAME=end_date ID=end_date VALUE=\"$end_date\">\n";
  355. $HTML_text.="<INPUT TYPE=TEXT NAME=query_date_D SIZE=11 MAXLENGTH=10 VALUE=\"$query_date_D\">";
  356.  
  357. $HTML_text.="<script language=\"JavaScript\">\n";
  358. $HTML_text.="var o_cal = new tcal ({\n";
  359. $HTML_text.=" // form name\n";
  360. $HTML_text.=" 'formname': 'vicidial_report',\n";
  361. $HTML_text.=" // input name\n";
  362. $HTML_text.=" 'controlname': 'query_date_D'\n";
  363. $HTML_text.="});\n";
  364. $HTML_text.="o_cal.a_tpl.yearscroll = false;\n";
  365. $HTML_text.="// o_cal.a_tpl.weekstart = 1; // Monday week start\n";
  366. $HTML_text.="</script>\n";
  367.  
  368. $HTML_text.=" &nbsp; <INPUT TYPE=TEXT NAME=query_date_T SIZE=9 MAXLENGTH=8 VALUE=\"$query_date_T\">";
  369.  
  370. $HTML_text.="<BR> to <BR><INPUT TYPE=TEXT NAME=end_date_D SIZE=11 MAXLENGTH=10 VALUE=\"$end_date_D\">";
  371.  
  372. $HTML_text.="<script language=\"JavaScript\">\n";
  373. $HTML_text.="var o_cal = new tcal ({\n";
  374. $HTML_text.=" // form name\n";
  375. $HTML_text.=" 'formname': 'vicidial_report',\n";
  376. $HTML_text.=" // input name\n";
  377. $HTML_text.=" 'controlname': 'end_date_D'\n";
  378. $HTML_text.="});\n";
  379. $HTML_text.="o_cal.a_tpl.yearscroll = false;\n";
  380. $HTML_text.="// o_cal.a_tpl.weekstart = 1; // Monday week start\n";
  381. $HTML_text.="</script>\n";
  382.  
  383. $HTML_text.=" &nbsp; <INPUT TYPE=TEXT NAME=end_date_T SIZE=9 MAXLENGTH=8 VALUE=\"$end_date_T\">";
  384.  
  385. $HTML_text.="<TD VALIGN=TOP> <BR>";
  386. $HTML_text.="Auto refresh: <input type=\"checkbox\" name=\"auto\" value=\"y\" ".$auto." /> <BR>";
  387. $HTML_text.="seconds: <input type=\"text\" name=\"timeout\" value=\"".$timeout."\" size=\"3\" /> \n";
  388. $HTML_text.="</TD>\n";
  389.  
  390. $HTML_text.="</TD><TD VALIGN=TOP> Campaigns:<BR>";
  391. $HTML_text.="<SELECT SIZE=15 NAME=group[] multiple>\n";
  392. if (eregi("--ALL--",$group_string))
  393. {$HTML_text.="<option value=\"--ALL--\" selected>-- ALL CAMPAIGNS --</option>\n";}
  394.  
  395. elseif ($group == '')
  396. {$HTML_text.="<option value=\"--ALL--\" selected>-- ALL CAMPAIGNS --</option>\n";}
  397. else
  398. {$HTML_text.="<option value=\"--ALL--\">-- ALL CAMPAIGNS --</option>\n";}
  399. $o=0;
  400. while ($campaigns_to_print > $o)
  401. {
  402. if (eregi("$groups[$o]\|",$group_string))
  403. {$HTML_text.="<option selected value=\"$groups[$o]\">$groups[$o]</option>\n";}
  404. else
  405. {$HTML_text.="<option value=\"$groups[$o]\">$groups[$o]</option>\n";}
  406. $o++;
  407. }
  408. $HTML_text.="</SELECT>\n";
  409.  
  410. $HTML_text.="</TD><TD VALIGN=TOP>Teams/User Groups:<BR>";
  411. $HTML_text.="<SELECT SIZE=15 NAME=user_group[] multiple>\n";
  412.  
  413. if (eregi("--ALL--",$user_group_string))
  414. {$HTML_text.="<option value=\"--ALL--\" selected>-- ALL USER GROUPS --</option>\n";}
  415. elseif ($user_group == '')
  416. {$HTML_text.="<option value=\"--ALL--\" selected>-- ALL USER GROUPS --</option>\n";}
  417. else
  418. {$HTML_text.="<option value=\"--ALL--\">-- ALL USER GROUPS --</option>\n";}
  419. $o=0;
  420. while ($user_groups_to_print > $o)
  421. {
  422. if (eregi("\|$user_groups[$o]\|",$user_group_string))
  423. {$HTML_text.="<option selected value=\"$user_groups[$o]\">$user_groups[$o]</option>\n";}
  424. else
  425. {$HTML_text.="<option value=\"$user_groups[$o]\">$user_groups[$o]</option>\n";}
  426. $o++;
  427. }
  428. $HTML_text.="</SELECT>\n";
  429. $HTML_text.="</TD>\n";
  430.  
  431.  
  432. $HTML_text.="<TD VALIGN=TOP>\n";
  433. $HTML_text.="<option value='TEXT'>TEXT</option></select>\n<BR><BR>";
  434. $HTML_text.="<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=SUBMIT>\n";
  435. $HTML_text.="<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\n";
  436. $HTML_text.="<a href=\"$PHP_SELF?DB=$DB&query_date=$query_date&end_date=$end_date&query_date_D=$query_date_D&query_date_T=$query_date_T&end_date_D=$end_date_D&end_date_T=$end_date_T$groupQS$user_groupQS&file_download=1&SUBMIT=$SUBMIT\">DOWNLOAD</a> |";
  437. $HTML_text.=" <a href=\"./admin.php?ADD=999999\">REPORTS</a> </FONT>\n";
  438. $HTML_text.="</FONT>\n";
  439. $HTML_text.="</TD><TD VALIGN=BOTTOM><a href=\"$PHP_SELF\">clear</a>\n";
  440. $HTML_text.="</TD><TD VALIGN=TOP> &nbsp; &nbsp; &nbsp; &nbsp; ";
  441.  
  442. $HTML_text.="</TD></TR></TABLE>";
  443. $HTML_text.="</FORM>\n\n";
  444. }
  445. ###END IF QUERY SUBMIT HIDE SELECTION OPTIONS###
  446. if ($SUBMIT=="SUBMIT")
  447. {
  448.  
  449. $HTML_text.="<PRE><FONT SIZE=3>";
  450.  
  451.  
  452. ##### DOMEDAN STUFF ######
  453. ##########################
  454.  
  455. $user_list=array();
  456. $total_dsum=array();
  457. $total_upsum=array();
  458. $sale_count=array();
  459. $other_HA_count=array();
  460. $ni_count=array();
  461. $upsale_count=array();
  462. $open_count=array();
  463. $ptime=array();
  464.  
  465. if (strtotime($query_date)<=strtotime('-30 days')){
  466. $vl = "vicidial_log_archive";
  467. $val = "vicidial_agent_log_archive";
  468. } else {
  469. $vl = "vicidial_log";
  470. $val = "vicidial_agent_log";
  471. }
  472. if ($agentpstats) {
  473. $agentidSQL = "AND vl.user in ('$agentpstats')";
  474. }
  475.  
  476.  
  477. #### QUERY TO ALL DATA
  478. $stmt = "SELECT vl.call_date,vi.status,vl.user,vl.campaign_id,vi.list_id,vl.user_group,vi.lead_id
  479. FROM $vl vl,vicidial_list vi
  480. INNER JOIN asterisk.vicidial_statuses s on s.status=vi.status
  481. WHERE vi.lead_id=vl.lead_id
  482. AND vi.user=vl.user AND DATE(vi.last_local_call_time)=DATE(vl.call_date)
  483. AND vl.call_date >= '$query_date'
  484. AND vl.call_date <= '$end_date'
  485. AND s.human_answered = 'Y'
  486. AND vl.campaign_id in ($group_SQL_str)
  487. AND vl.user_group in ($user_group_SQL_str)
  488. $agentidSQL
  489. GROUP BY vi.lead_id
  490. ;";
  491.  
  492.  
  493. //$stmt="SELECT l.lead_id, l.user, l.status, l.call_date, i.list_id FROM $vl l
  494. //LEFT JOIN vicidial_list i on i.lead_id=l.lead_id
  495. //AND i.user=l.user AND DATE(i.last_local_call_time)=DATE(l.call_date) /* AND i.status='SALE' */
  496. //INNER JOIN asterisk.vicidial_statuses s on s.status=l.status
  497. //WHERE l.call_date >= '$query_date'
  498. //AND l.call_date <= '$end_date'
  499. //AND s.human_answered = 'Y'
  500. //AND l.campaign_id in ($group_SQL_str)
  501. //AND l.user_group in ($user_group_SQL_str)
  502. //$agentidSQL
  503. // /* AND l.user in ('tht') */";
  504. if ($DB) {$ASCII_text.="$stmt\n";}
  505. $rslt=mysql_query($stmt, $link_stats);
  506. while ($row=mysql_fetch_array($rslt)) {
  507. //print_r($row['user']);
  508. // create list of users
  509. if ( !in_array($row['user'], $user_list) ) {
  510. $full_name_stmt="SELECT full_name from vicidial_users WHERE user='".$row['user']."';";
  511. $full_name_rslt = mysql_query($full_name_stmt, $link_stats);
  512. while ($full_name_row=mysql_fetch_array($full_name_rslt)) {
  513. $user_list[$row['user']] = truncateString($full_name_row['full_name'], 14, false);
  514. $user_listid[$row['user']] = $row['user'];
  515. }
  516. }
  517. $numcallcount[$row['user']]++;
  518. if ($row['status'] == 'SALE') {
  519.  
  520. $get_amount_stmt="SELECT d_amt, up_amt, md_amt, cc_num, bank_act from custom_$row[list_id] WHERE lead_id='".$row['lead_id']."';";
  521. if ($DB) {$ASCII_text.="$get_amount_stmt\n";}
  522. $get_amount_rslt = mysql_query($get_amount_stmt, $link_stats);
  523. $get_amount_row=mysql_fetch_array($get_amount_rslt);
  524. //echo $row[list_id]. "<br>";
  525. //$leads_with_SALE[]=$row['lead_id'];
  526.  
  527. #$row['security_phrase']=$row['security_phrase']-25; // this is just a silly rule, if you dont want it you can remove it
  528.  
  529. $SALE_time=date("H:i:s", strtotime($row['call_date'])); // get time of SALE
  530.  
  531. $sale_count[$row['user']]++; // count SALE
  532. $total_dsum[$row['user']]=$total_dsum[$row['user']]+$get_amount_row['d_amt']+0; // sum Donation Sales
  533. $total_upsum[$row['user']]=$total_upsum[$row['user']]+$get_amount_row['up_amt']+0; // sum UpSales
  534. $total_msum[$row['user']]=$total_msum[$row['user']]+$get_amount_row['md_amt']+0; // sum Monthly Sales
  535.  
  536. if ($get_amount_row['cc_num'] > 5 OR $get_amount_row['bank_act'] > 5){
  537. $total_vsum[$row['user']]=$total_vsum[$row['user']]+$get_amount_row['d_amt']+$get_amount_row['up_amt']+0; // sum Monthly Sales
  538. $v_count[$row['user']]++; // count Verified
  539. }
  540. if ($get_amount_row['up_amt'] >= 1){ // count upsales
  541. $upsale_count[$row['user']]++;}
  542. if ($get_amount_row['d_amt'] < 1){ // count OPENS
  543. $open_count[$row['user']]++;}
  544. if ($get_amount_row['md_amt'] >= 1){ // count monthly
  545. $md_count[$row['user']]++;}
  546.  
  547. } elseif ($row['status'] == 'NI') {
  548. $ni_count[$row['user']]++; // count NI
  549. } else {
  550. $other_HA_count[$row['user']]++; // count other human answer statuses
  551. }
  552. $snitt[$row['user']]=round($total_dsum[$row['user']]/($sale_count[$row['user']]-$open_count[$row['user']])); // Calc AVG Sale
  553.  
  554. }
  555. // add users that havent made any SALE
  556. foreach ($user_list as $user => $full_name) {
  557. if ( !array_key_exists($user, $sale_count) ) {
  558. $sale_count[$user] = "0";
  559. }
  560. if ( !array_key_exists($user, $total_dsum) ) {
  561. $total_dsum[$user] = "0";
  562. }
  563. if ( !array_key_exists($user, $total_upsum) ) {
  564. $total_upsum[$user] = "0";
  565. }
  566. if ( !array_key_exists($user, $total_msum) ) {
  567. $total_msum[$user] = "0";
  568. }
  569. if ( !array_key_exists($user, $total_vsum) ) {
  570. $total_vsum[$user] = "0";
  571. }
  572. if ( !array_key_exists($user, $md_count) ) {
  573. $md_count[$user] = "0";
  574. }
  575. if ( !array_key_exists($user, $open_count) ) {
  576. $open_count[$user] = "0";
  577. }
  578. if ( !array_key_exists($user, $upsale_count) ) {
  579. $upsale_count[$user] = "0";
  580. }
  581. if ( !array_key_exists($user, $v_count) ) {
  582. $v_count[$user] = "0";
  583. }
  584. if ( !array_key_exists($user, $SALE_HR) ) {
  585. $SALE_HR[$user] = "0";
  586. }
  587. if ($DB) {$ASCII_text.="USER - ".$user_list[$user]."\n";}
  588. }
  589. //$time_user_stmt="SELECT l.user, l.user_group, l.call_date FROM $vl l
  590. //WHERE l.call_date >= '$query_date'
  591. //AND l.call_date <= '$end_date'
  592. //AND l.user_group in ($user_group_SQL_str)
  593. //AND l.campaign_id in ($group_SQL_str)
  594. //$agentidSQL
  595. //GROUP BY l.user
  596. ///* AND l.user in ('tht') */";
  597. //if ($DB) {$ASCII_text.="$$agentidSQL\n";}
  598. //$time_user_rslt=mysql_query($time_user_stmt, $link_stats);
  599. //while ($time_user_row = mysql_fetch_assoc($time_user_rslt)) {
  600. foreach ($user_listid as $userid => $user) {
  601. $time_stmt="select sum(pause_sec) as psec,sum(wait_sec) as wsec,sum(talk_sec) as tsec,sum(dispo_sec) as dsec,sum(dead_sec) as dedsec
  602. FROM $val
  603. WHERE user='" . mysql_real_escape_string($user_listid[$userid]) . "'
  604. AND event_time >= '" . mysql_real_escape_string($query_date) . " 0:00:01'
  605. AND event_time <= '" . mysql_real_escape_string($end_date) . " 23:59:59'
  606. AND ( (pause_sec > 0) or (wait_sec > 0) or (talk_sec > 0) or (dispo_sec > 0) )
  607. limit 10000;";
  608. if ($DB) {$ASCII_text.="agent activity|$time_stmt|\n";}
  609. $time_rslt=mysql_query($time_stmt, $link);
  610. $time_row = mysql_fetch_assoc($time_rslt);
  611.  
  612. $ptime[$userid] = $time_row['psec'];
  613. $dtime[$userid] = ($time_row['dsec']+$time_row['dedsec']);
  614. $ttime[$userid] = ($time_row['dsec']+$time_row['psec']+$time_row['wsec']+$time_row['tsec']+$time_row['dedsec']);
  615. $numcallshr[$userid] = ($numcallcount[$userid]/($ttime[$userid] / 3600));
  616. $SALE_HR[$userid] = round((($total_dsum[$userid])+$total_upsum[$userid])/($ttime[$userid] / 3600));
  617. $SALE_count_HR[$userid] = (($sale_count[$userid])/($ttime[$userid] / 3600));
  618. $wrap_per[$userid] = ((($dtime[$userid])/($ttime[$userid]))*100);
  619. $percent_SALE[$userid]=round($sale_count[$userid]/($sale_count[$userid]+$ni_count[$userid])*100);
  620.  
  621. $txteamgoal = 125;
  622. $user_group_stmt="SELECT user_group from vicidial_users WHERE user='".$user_listid[$userid]."';";
  623. $user_group_rslt = mysql_query($user_group_stmt, $link_stats);
  624. while ($user_group_row=mysql_fetch_array($user_group_rslt)) {
  625. // CAN USE IF TEAMS SPLIT AMT HR GOAL if ($user_group_row['user_group'] == 'TX-Tina' OR $user_group_row['user_group'] == 'TX-Jasey') {
  626. if (substr($user_group_row['user_group'],0,3) == 'TX-'){
  627. $amthrkey = "<br>Amount per hour goal: $$txteamgoal<br>";
  628. if ($SALE_HR[$userid] >= $txteamgoal) {
  629. $amthrunder[$userid] = "#5BFF19";
  630. }
  631. if ($SALE_HR[$userid] < $txteamgoal AND $SALE_HR[$userid] >= 100) {
  632. $amthrunder[$userid] = "yellow";
  633. }
  634. if ($SALE_HR[$userid] < 100) {
  635. $amthrunder[$userid] = "red";
  636. }
  637. }
  638. }
  639. }
  640.  
  641.  
  642. if ($get_sort) {$sorttable = $$get_sort;} else {$sorttable = $SALE_HR;}
  643. //echo $get_sort;
  644. // asort keep key
  645. asort($sorttable, SORT_NUMERIC);
  646.  
  647. // reverse order, "true" keeps key
  648. $sorttable = array_reverse($sorttable, true);
  649. if ($agentfullstats){
  650. $resetlink = " ";
  651. }else{
  652. $resetlink = "<a href=\"$PHP_SELF\">RESET</a>";
  653. }
  654.  
  655. ####START TV STATS###
  656. if (!$agentpstats){
  657. $ASCII_text.="+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+$HTMLborderheader\n";
  658. $ASCII_text.="|STATS FOR DATE RANGE: $query_date_D to $end_date_D FOR $user_group_string$HTMLborderheader\n";
  659. $ASCII_text.="+--------------------------------+------------------+------------------------+------+-----------+-----------+-----------+------+-----------------------------------------+$HTMLborderheader\n";
  660. $ASCII_text.="| $resetlink TOTAL | Donations | Hourly Stats | | Up Sales | Monthlys | Verified | | Time Spent |$HTMLborderheader\n";
  661. $ASCII_text.="+--------------------------------+-------+-----+----+----------+-------+-----+------+------+----+------+----+------+----+------+-----------+---------+-------+-----------+$HTMLborderheader\n";
  662. $ASCII_text.="| Agent Name ";
  663. $ASCII_text.=" | ".sprintf("%13s", "<b>$".round((array_sum($total_dsum)+array_sum($total_upsum)))."</b>");
  664. $ASCII_text.=" | <a href=\"$url&sort_by=total_dsum\">$</a> | <a href=\"$url&sort_by=sale_count\">#</a> | <a href=\"$url&sort_by=open_count\">OP</a> | <a href=\"$url&sort_by=SALE_HR\">Amt Hr</a> | <a href=\"$url&sort_by=SALE_count_HR\">SA Hr</a> | <a href=\"$url&sort_by=numcallshr\">C/H</a> | <a href=\"$url&sort_by=snitt\">Avg$</a> | <a href=\"$url&sort_by=total_upsum\">$</a> | <a href=\"$url&sort_by=upsale_count\">#</a> | <a href=\"$url&sort_by=total_msum\">$</a> | <a href=\"$url&sort_by=md_count\">#</a> | <a href=\"$url&sort_by=total_vsum\">$</a> | <a href=\"$url&sort_by=v_count\">#</a> | <a href=\"$url&sort_by=percent_SALE\">SA %</a> | Pause | Wrap | <a href=\"$url&sort_by=wrap_per\">WR%</a> | Dial |$HTMLstatusheader\n";
  665. $ASCII_text.="+--------------------------------+-------+-----+----+----------+-------+-----+------+------+----+------+----+------+----+------+-----------+---------+-------+-----------+$HTMLborderheader\n";
  666. $CSV_text.="\"Agent Name\",\"Total\",\"SALE\",\"Average\",\"Up Sale\",\"Contacts\",\"SALE %\",\"NI\",\"Other HA\"$CSVstatusheader\n";
  667. foreach($sorttable as $user => $amount) {
  668. $countusers++;
  669. if ($sale_count[$user] == 0) {
  670. $snitt[$user]=0;
  671. $percent_SALE[$user]=0;
  672. $open_count[$user] = 0;
  673. }
  674. if ($ptime[$user] >= 2700){$ptimehigh = "red";} elseif ($ptime[$user] >= 2400){$ptimehigh = "yellow"; } else { $ptimehigh = null;}
  675. if ($wrap_per[$user] >= 1.999){$dtimehigh = "red";} elseif ($wrap_per[$user] >= 1.499){$dtimehigh = "yellow"; } else { $dtimehigh = null;}
  676. if ($agentfullstats == $user){$rowoddeven = '<span style="background-color:#ff8c66;"'.(($c = !$c)?' class="odd"':'').">";
  677. } else {$rowoddeven = '<span'.(($c = !$c)?' class="odd"':'').">";}
  678. if ($countusers <= 9){$countusers = "0$countusers";}
  679. $firstplaces = "";
  680. $secondplaces = "";
  681. if ($countusers == 01) {$firstplaces = "<font color=green><B>"; $firstplacee = "</font></B>";}
  682. if ($countusers == 02) {$secondplaces = "<font color=orange><B>"; $secondplacee = "</font></B>";}
  683. $ASCII_text.="$rowoddeven|$firstplaces$secondplaces$countusers ".utf_8_sprintf("%-18s", $user_list[$user])."$secondplacee$firstplacee";
  684. $ASCII_text.=" - <b>$".sprintf("%6s", round(($total_dsum[$user])+$total_upsum[$user]));
  685. $ASCII_text.="</b> | ".sprintf("%6s", "$".round($total_dsum[$user]))."</b>";
  686. $ASCII_text.=" ".sprintf("%4s", ($sale_count[$user]+0));
  687. $ASCII_text.=" ".sprintf("%4s", ($open_count[$user]+0));
  688. $ASCII_text.=" |<span STYLE='background-color: $amthrunder[$user]'> ".sprintf("%8s", "$".$SALE_HR[$user]."/hr");
  689. $ASCII_text.=" </span>| ".sprintf("%5s", sprintf('%0.2f',$SALE_count_HR[$user]."/hr"));
  690. $ASCII_text.=" | ".sprintf("%3s", round($numcallshr[$user]));
  691. $ASCII_text.=" | ".sprintf("%4s", "$".$snitt[$user]);
  692. $ASCII_text.=" | ".sprintf("%5s", "$".$total_upsum[$user]);
  693. $ASCII_text.=" ".sprintf("%3s", ($upsale_count[$user]+0));
  694. $ASCII_text.=" | ".sprintf("%5s", "$".$total_msum[$user]);
  695. $ASCII_text.=" ".sprintf("%3s", ($md_count[$user]+0));
  696. $ASCII_text.=" | ".sprintf("%5s", "$".$total_vsum[$user]);
  697. $ASCII_text.=" ".sprintf("%3s", ($v_count[$user]+0));
  698. # $ASCII_text.=" | ".sprintf("%8s", ($other_HA_count[$user]+$sale_count[$user]+$ni_count[$user]));
  699. # $ASCII_text.=" | ".sprintf("%4s", ($ni_count[$user]+0));
  700. $ASCII_text.=" | ".sprintf("%4s", $percent_SALE[$user]."%");
  701. $ASCII_text.=" |<span STYLE='background-color: $ptimehigh'> ".sprintf("%9s", sprintf( "%02d:%02d:%02d", $ptime[$user] / 3600, $ptime[$user] / 60 % 60, $ptime[$user] % 60 ));
  702. $ASCII_text.=" </span>|<span STYLE='background-color: $dtimehigh'> ".sprintf("%8s", sprintf( "%02d:%02d:%02d", $dtime[$user] / 3600, $dtime[$user] / 60 % 60, $dtime[$user] % 60 ));
  703. $ASCII_text.=" ".sprintf("%5s", sprintf('%0.1f', $wrap_per[$user])."%");
  704. $ASCII_text.=" </span>| ".sprintf("%9s", sprintf( "%02d:%02d:%02d", $ttime[$user] / 3600, $ttime[$user] / 60 % 60, $ttime[$user] % 60 )." |");
  705. $ASCII_text.="</span>\n";
  706.  
  707. $CSV_text.="\"$user_list[$user]\",\"$amount\",\"".($sale_count[$user]+0)."\",\"$snitt\",\"".($other_HA_count[$user]+$sale_count[$user]+$ni_count[$user])."\",\"$percent_SALE\",\"".($ni_count[$user]+0)."\",\"".($other_HA_count[$user]+0)."\"\n";
  708. $rowoddeven++;
  709. }
  710. }
  711. ###END TV STATS###
  712. ###START PERSONAL STATS###
  713. if ($agentpstats) {
  714.  
  715. $ASCII_text.="<FONT SIZE=2> | |Donatio| AMT | | Up Sales | Verified | Time Spent |$HTMLborderheader\n";
  716. $ASCII_text.=" | TOTAL | $ | HR | Avg$ | $ | # | $ | # | Pause | Wrap | WR% |$HTMLstatusheader\n";
  717. $ASCII_text.="+----------+-------+------+------+------+----+------+----+-----------+---------+-------+$HTMLborderheader\n";
  718. foreach($sorttable as $user => $amount) {
  719. $countusers++;
  720. if ($sale_count[$user] == 0) {
  721. $snitt=0;
  722. $percent_SALE=0;
  723. } else {
  724. $snitt=round($total_dsum[$user]/($sale_count[$user]-$open_count[$user]));
  725. $percent_SALE=round($sale_count[$user]/($sale_count[$user]+$ni_count[$user])*100);
  726. }
  727. if ($ptime[$user] >= 2700){$ptimehigh = "red";} elseif ($ptime[$user] >= 2400){$ptimehigh = "yellow"; } else { $ptimehigh = null;}
  728. if ($wrap_per[$user] > 1.9){$dtimehigh = "red";} elseif ($wrap_per[$user] > 1.5){$dtimehigh = "yellow"; } else { $dtimehigh = null;}
  729. if ($agentfullstats == $user){$rowoddeven = '<span style="background-color:#ff8c66;"'.(($c = !$c)?' class="odd"':'').">";
  730. } else {$rowoddeven = '<span'.(($c = !$c)?' class="odd"':'').">";}
  731. $ASCII_text.="$rowoddeven| <b>$".sprintf("%7s", round(($total_dsum[$user])+$total_upsum[$user]));
  732. $ASCII_text.="</b> |".sprintf("%6s", "$".round($total_dsum[$user]))."</b>";
  733. #$ASCII_text.=" ".sprintf("%4s", ($sale_count[$user]+0));
  734. #$ASCII_text.=" ".sprintf("%4s", ($open_count[$user]+0));
  735. $ASCII_text.=" | ".sprintf("%4s", "$".$SALE_HR[$user]);
  736. #$ASCII_text.=" | ".sprintf("%5s", sprintf('%0.2f',$SALE_count_HR[$user]."/hr"));
  737. #$ASCII_text.=" | ".sprintf("%3s", round($numcallshr[$user]));
  738. $ASCII_text.=" | ".sprintf("%4s", "$".$snitt);
  739. $ASCII_text.=" | ".sprintf("%5s", "$".$total_upsum[$user]);
  740. $ASCII_text.=" ".sprintf("%3s", ($upsale_count[$user]+0));
  741. #$ASCII_text.=" | ".sprintf("%5s", "$".$total_msum[$user]);
  742. #$ASCII_text.=" ".sprintf("%3s", ($md_count[$user]+0));
  743. $ASCII_text.=" | ".sprintf("%5s", "$".$total_vsum[$user]);
  744. $ASCII_text.=" ".sprintf("%3s", ($v_count[$user]+0));
  745. # $ASCII_text.=" | ".sprintf("%8s", ($other_HA_count[$user]+$sale_count[$user]+$ni_count[$user]));
  746. # $ASCII_text.=" | ".sprintf("%4s", ($ni_count[$user]+0));
  747. #$ASCII_text.=" | ".sprintf("%4s", $percent_SALE."%");
  748. $ASCII_text.=" |<span STYLE='background-color: $ptimehigh'> ".sprintf("%9s", sprintf( "%02d:%02d:%02d", $ptime[$user] / 3600, $ptime[$user] / 60 % 60, $ptime[$user] % 60 ));
  749. $ASCII_text.=" </span>|<span STYLE='background-color: $dtimehigh'> ".sprintf("%8s", sprintf( "%02d:%02d:%02d", $dtime[$user] / 3600, $dtime[$user] / 60 % 60, $dtime[$user] % 60 ));
  750. $ASCII_text.=" ".sprintf("%5s", sprintf('%0.1f', $wrap_per[$user])."%");
  751. #$ASCII_text.=" </span>| ".sprintf("%9s", sprintf( "%02d:%02d:%02d", $ttime[$user] / 3600, $ttime[$user] / 60 % 60, $ttime[$user] % 60 )." |");
  752. $ASCII_text.="</span> |</span>\n";
  753.  
  754. $CSV_text.="\"$user_list[$user]\",\"$amount\",\"".($sale_count[$user]+0)."\",\"$snitt\",\"".($other_HA_count[$user]+$sale_count[$user]+$ni_count[$user])."\",\"$percent_SALE\",\"".($ni_count[$user]+0)."\",\"".($other_HA_count[$user]+0)."\"\n";
  755. $rowoddeven++;
  756. }
  757. }
  758. ####END PERSONAL STATS#####
  759.  
  760. if (!$agentpstats) {
  761. if (array_sum($sale_count) == 0) {
  762. $sum_snitt=0;
  763. $sum_percent_SALE=0;
  764. $sum_SALE_HR=0;
  765. } else {
  766. $sum_snitt=round(array_sum($total_dsum)/(array_sum($sale_count)-array_sum($open_count)));
  767. $sum_percent_SALE=round(array_sum($sale_count)/(array_sum($sale_count)+array_sum($ni_count))*100);
  768. $sum_SALE_HR=round((array_sum($total_dsum)+array_sum($total_upsum))/(array_sum($ttime) / 3600));
  769. }
  770. $ASCII_text.="+--------------------------------+-------+-----+----+----------+-------+-----+------+------+----+------+----+------+----+------+-----------+---------+-------+-----------+$HTMLborderheader\n";
  771. $ASCII_text.="<span style=\"background-color:#FFFF66;\">| Agents: $countusers".sprintf("%-11s", "");
  772. $ASCII_text.=" | ".sprintf("%13s", "<b>$".round((array_sum($total_dsum)+array_sum($total_upsum)))."</b>");
  773. $ASCII_text.=" | ".sprintf("%6s", "$".round(array_sum($total_dsum)));
  774. $ASCII_text.=" ".sprintf("%4s", (array_sum($sale_count)+0));
  775. $ASCII_text.=" ".sprintf("%4s", (array_sum($open_count)+0));
  776. $ASCII_text.=" | ".sprintf("%8s", "$".$sum_SALE_HR."/hr");
  777. $ASCII_text.=" | ".sprintf("%5s", sprintf('%0.2f',array_sum($SALE_count_HR) / $countusers."/hr"));
  778. $ASCII_text.=" | ".sprintf("%3s", round(array_sum($numcallshr) / $countusers));
  779. $ASCII_text.=" | ".sprintf("%4s", "$".$sum_snitt);
  780. $ASCII_text.=" | ".sprintf("%5s", "$".array_sum($total_upsum));
  781. $ASCII_text.=" ".sprintf("%3s", (array_sum($upsale_count)+0));
  782. $ASCII_text.=" | ".sprintf("%5s", "$".array_sum($total_msum));
  783. $ASCII_text.=" ".sprintf("%3s", (array_sum($md_count)+0));
  784. $ASCII_text.=" | ".sprintf("%5s", "$".array_sum($total_vsum));
  785. $ASCII_text.=" ".sprintf("%3s", (array_sum($v_count)+0));
  786. # $ASCII_text.=" | ".sprintf("%8s", (array_sum($other_HA_count)+array_sum($sale_count)+array_sum($ni_count)));
  787. # $ASCII_text.=" | ".sprintf("%4s", (array_sum($ni_count)+0));
  788. $ASCII_text.=" | ".sprintf("%4s", $sum_percent_SALE."%");
  789. $ASCII_text.=" | ".sprintf("%9s", sprintf( "%03d:%02d:%02d", array_sum($ptime) / 3600, array_sum($ptime) / 60 % 60, array_sum($ptime) % 60 ));
  790. $ASCII_text.=" | ".sprintf("%8s", sprintf( "%02d:%02d:%02d", array_sum($dtime) / 3600, array_sum($dtime) / 60 % 60, array_sum($dtime) % 60 ));
  791. $ASCII_text.=" ".sprintf("%5s", sprintf('%0.1f', array_sum($wrap_per) / $countusers)."%");
  792. $ASCII_text.=" | ".sprintf("%9s", sprintf( "%03d:%02d:%02d", array_sum($ttime) / 3600, array_sum($ttime) / 60 % 60, array_sum($ttime) % 60 )." |");
  793. $ASCII_text.="</span>\n";
  794.  
  795.  
  796. $CSV_text.="\"ALL:\",\"\",\"".array_sum($total_dsum)."\",\"".(array_sum($sale_count)+0)."\",\"".$sum_snitt."\",\"".(array_sum($other_HA_count)+array_sum($sale_count)+array_sum($ni_count))."\",\"$sum_percent_SALE\",\"".(array_sum($ni_count)+0)."\",\"".(array_sum($other_HA_count)+0)."\"\n";
  797. $CSV_text.="\n\n";
  798. $ASCII_text.="+--------------------------------+-------+-----+----+----------+-------+-----+------+------+----+------+----+------+----+------+-----------+---------+-------+-----------+$HTMLborderheader\n";
  799. $ASCII_text.="| $resetlink TOTAL | Donations | Hourly Stats | | Up Sales | Monthlys | Verified | | Time Spent |$HTMLborderheader\n";
  800. $ASCII_text.="+--------------------------------+------------------+------------------------+------+-----------+-----------+-----------+------+-----------------------------------------+$HTMLborderheader\n";
  801. // compare starttime with current time and show result
  802. }
  803. $totaltime = (microtime(1) - $starttime);
  804. $ASCII_text.= $amthrkey;
  805. if ($timeout){$ASCII_text.= "<Br>Stats refresh every $timeout Seconds<br>";}
  806. $ASCII_text.= "Last Update: ".DATE('m-d-Y h:i:s');
  807. $ASCII_text.= "<br /><br />Execution-time: ".$totaltime."S - ".$db_source."\n\n";
  808.  
  809. $ASCII_text.="</FONT></PRE>";
  810. $ASCII_text.="</BODY>\n";
  811. $ASCII_text.="</HTML>\n";
  812.  
  813.  
  814.  
  815. # for debugging and developing
  816. /*
  817. echo "<pre>";
  818. print_r($total_count);
  819. echo "\nuser_list\n";
  820. print_r($user_list);
  821. echo "\ntotal_sum\n";
  822. print_r($total_dsum);
  823. echo "\nsale_count\n";
  824. print_r($sale_count);
  825. echo "\nni_count\n";
  826. print_r($ni_count);
  827. echo "\nother_HA_count\n";
  828. print_r($other_HA_count);
  829. echo "\np1_sum\n";
  830. print_r($p1_sum);
  831. echo "\np2_sum\n";
  832. print_r($p2_sum);
  833. echo "\np3_sum\n";
  834. print_r($p3_sum);
  835. echo "\np4_sum\n";
  836. print_r($p4_sum);
  837. echo "\np5_sum\n";
  838. print_r($p5_sum);
  839. echo "\np6_sum\n";
  840. print_r($p6_sum);
  841. echo "\np7_sum\n";
  842. print_r($p7_sum);
  843. echo "\np8_sum\n";
  844. print_r($p8_sum);
  845. echo "\np0_sum\n";
  846. print_r($p0_sum);
  847. echo "</pre>";
  848. */
  849.  
  850.  
  851.  
  852.  
  853. }
  854.  
  855. if ($file_download>0)
  856. {
  857. $FILE_TIME = date("Ymd-His");
  858. $CSVfilename = "domedan_leaderboard_$US$FILE_TIME.csv";
  859. $CSV_text=preg_replace('/\n +,/', ',', $CSV_text);
  860. $CSV_text=preg_replace('/ +\"/', '"', $CSV_text);
  861. $CSV_text=preg_replace('/\" +/', '"', $CSV_text);
  862.  
  863. // We'll be outputting a TXT file
  864. header('Content-type: application/octet-stream');
  865. // It will be called LIST_101_20090209-121212.txt
  866. header("Content-Disposition: attachment; filename=\"$CSVfilename\"");
  867. header('Expires: 0');
  868. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  869. header('Pragma: public');
  870. ob_clean();
  871. flush();
  872.  
  873. echo "$CSV_text";
  874.  
  875. exit;
  876. }
  877. else
  878. {
  879. header("Content-type: text/html; charset=utf-8");
  880.  
  881. $HTML_text.=$ASCII_text;
  882.  
  883. echo $HTML_head;
  884. $short_header=1;
  885. if (!$SUBMIT){
  886. require("admin_header.php");
  887. }
  888. echo $HTML_text;
  889. flush();
  890. }
  891. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement