Advertisement
Guest User

leaderboard_v2

a guest
Feb 19th, 2014
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.26 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. if ($query_date_D < $NOW_DATE) { $timeout = null; }
  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="60"; // 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. if ($query_date_D < $NOW_DATE) { $timeout = null; }
  240. $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
  241. $auto='checked'; //for the data form
  242. } else {
  243. $auto='';
  244. $HTML_auto_refresh="";
  245. }
  246.  
  247.  
  248. ############################
  249. ?><style>
  250. .odd{background-color:#b7cfdc;}
  251. .tover{background-color:red;}
  252. .tover{background-color:yellow;}
  253. </style>
  254. <script>
  255. function updateURLParameter(url, param, paramVal)
  256. {
  257. var TheAnchor = null;
  258. var newAdditionalURL = "";
  259. var tempArray = url.split("?");
  260. var baseURL = tempArray[0];
  261. var additionalURL = tempArray[1];
  262. var temp = "";
  263.  
  264. if (additionalURL)
  265. {
  266. var tmpAnchor = additionalURL.split("#");
  267. var TheParams = tmpAnchor[0];
  268. TheAnchor = tmpAnchor[1];
  269. if(TheAnchor)
  270. additionalURL = TheParams;
  271.  
  272. tempArray = additionalURL.split("&");
  273.  
  274. for (i=0; i<tempArray.length; i++)
  275. {
  276. if(tempArray[i].split('=')[0] != param)
  277. {
  278. newAdditionalURL += temp + tempArray[i];
  279. temp = "&";
  280. }
  281. }
  282. }
  283. else
  284. {
  285. var tmpAnchor = baseURL.split("#");
  286. var TheParams = tmpAnchor[0];
  287. TheAnchor = tmpAnchor[1];
  288.  
  289. if(TheParams)
  290. baseURL = TheParams;
  291. }
  292.  
  293. if(TheAnchor)
  294. paramVal += "#" + TheAnchor;
  295.  
  296. var rows_txt = temp + "" + param + "=" + paramVal;
  297. return baseURL + "?" + newAdditionalURL + rows_txt;
  298. }
  299. </script>
  300.  
  301. <?php
  302. function remove_querystring_var($url, $key) {
  303. $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
  304. $url = substr($url, 0, -1);
  305. return $url;
  306. }
  307. $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  308. $url = remove_querystring_var($url, "sort_by");
  309. function truncateString($str, $chars, $to_space, $replacement="...") {
  310. if($chars > strlen($str)) return $str;
  311.  
  312. $str = substr($str, 0, $chars);
  313.  
  314. $space_pos = strrpos($str, " ");
  315. if($to_space && $space_pos >= 0) {
  316. $str = substr($str, 0, strrpos($str, " "));
  317. }
  318.  
  319. return($str . $replacement);
  320. }
  321.  
  322. $HTML_head.="<HTML>\n";
  323. $HTML_head.="<HEAD>\n";
  324. $HTML_head.="<STYLE type=\"text/css\">\n";
  325. $HTML_head.="<!--\n";
  326. $HTML_head.=" .green {color: white; background-color: green}\n";
  327. $HTML_head.=" .red {color: white; background-color: red}\n";
  328. $HTML_head.=" .blue {color: white; background-color: blue}\n";
  329. $HTML_head.=" .purple {color: white; background-color: purple}\n";
  330. $HTML_head.="-->\n";
  331. $HTML_head.=" </STYLE>\n";
  332.  
  333. $query_date="$query_date_D $query_date_T";
  334. $end_date="$end_date_D $end_date_T";
  335.  
  336. $HTML_head.="<script language=\"JavaScript\" src=\"calendar_db.js\"></script>\n";
  337. $HTML_head.="<link rel=\"stylesheet\" href=\"calendar.css\">\n";
  338. $HTML_head.="<link rel=\"stylesheet\" href=\"horizontalbargraph.css\">\n";
  339.  
  340. $HTML_head.="<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n";
  341. $HTML_head.=$HTML_auto_refresh;
  342. $HTML_head.="<TITLE>$report_name</TITLE></HEAD><BODY BGCOLOR=WHITE marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>$group_S\n";
  343.  
  344. ###IF QUERY SUBMIT HIDE SELECTION OPTIONS###
  345.  
  346. if (!$SUBMIT) {
  347. $HTML_text.="<TABLE CELLPADDING=4 CELLSPACING=0><TR><TD>";
  348.  
  349. $HTML_text.="<FORM ACTION=\"$PHP_SELF\" METHOD=GET name=vicidial_report id=vicidial_report>\n";
  350. $HTML_text.="<TABLE CELLSPACING=3><TR><TD VALIGN=TOP> <BR>";
  351. $HTML_text.="<INPUT TYPE=HIDDEN NAME=DB VALUE=\"$DB\">\n";
  352. $HTML_text.="Date Range:<BR>\n";
  353.  
  354. $HTML_text.="<INPUT TYPE=hidden NAME=query_date ID=query_date VALUE=\"$query_date\">\n";
  355. $HTML_text.="<INPUT TYPE=hidden NAME=end_date ID=end_date VALUE=\"$end_date\">\n";
  356. $HTML_text.="<INPUT TYPE=TEXT NAME=query_date_D SIZE=11 MAXLENGTH=10 VALUE=\"$query_date_D\">";
  357.  
  358. $HTML_text.="<script language=\"JavaScript\">\n";
  359. $HTML_text.="var o_cal = new tcal ({\n";
  360. $HTML_text.=" // form name\n";
  361. $HTML_text.=" 'formname': 'vicidial_report',\n";
  362. $HTML_text.=" // input name\n";
  363. $HTML_text.=" 'controlname': 'query_date_D'\n";
  364. $HTML_text.="});\n";
  365. $HTML_text.="o_cal.a_tpl.yearscroll = false;\n";
  366. $HTML_text.="// o_cal.a_tpl.weekstart = 1; // Monday week start\n";
  367. $HTML_text.="</script>\n";
  368.  
  369. $HTML_text.=" &nbsp; <INPUT TYPE=TEXT NAME=query_date_T SIZE=9 MAXLENGTH=8 VALUE=\"$query_date_T\">";
  370.  
  371. $HTML_text.="<BR> to <BR><INPUT TYPE=TEXT NAME=end_date_D SIZE=11 MAXLENGTH=10 VALUE=\"$end_date_D\">";
  372.  
  373. $HTML_text.="<script language=\"JavaScript\">\n";
  374. $HTML_text.="var o_cal = new tcal ({\n";
  375. $HTML_text.=" // form name\n";
  376. $HTML_text.=" 'formname': 'vicidial_report',\n";
  377. $HTML_text.=" // input name\n";
  378. $HTML_text.=" 'controlname': 'end_date_D'\n";
  379. $HTML_text.="});\n";
  380. $HTML_text.="o_cal.a_tpl.yearscroll = false;\n";
  381. $HTML_text.="// o_cal.a_tpl.weekstart = 1; // Monday week start\n";
  382. $HTML_text.="</script>\n";
  383.  
  384. $HTML_text.=" &nbsp; <INPUT TYPE=TEXT NAME=end_date_T SIZE=9 MAXLENGTH=8 VALUE=\"$end_date_T\">";
  385.  
  386. $HTML_text.="<TD VALIGN=TOP> <BR>";
  387. $HTML_text.="Auto refresh: <input type=\"checkbox\" name=\"auto\" value=\"y\" ".$auto." /> <BR>";
  388. $HTML_text.="seconds: <input type=\"text\" name=\"timeout\" value=\"".$timeout."\" size=\"3\" /> \n";
  389. $HTML_text.="</TD>\n";
  390.  
  391. $HTML_text.="</TD><TD VALIGN=TOP> Campaigns:<BR>";
  392. $HTML_text.="<SELECT SIZE=15 NAME=group[] multiple>\n";
  393. if (eregi("--ALL--",$group_string))
  394. {$HTML_text.="<option value=\"--ALL--\" selected>-- ALL CAMPAIGNS --</option>\n";}
  395.  
  396. elseif ($group == '')
  397. {$HTML_text.="<option value=\"--ALL--\" selected>-- ALL CAMPAIGNS --</option>\n";}
  398. else
  399. {$HTML_text.="<option value=\"--ALL--\">-- ALL CAMPAIGNS --</option>\n";}
  400. $o=0;
  401. while ($campaigns_to_print > $o)
  402. {
  403. if (eregi("$groups[$o]\|",$group_string))
  404. {$HTML_text.="<option selected value=\"$groups[$o]\">$groups[$o]</option>\n";}
  405. else
  406. {$HTML_text.="<option value=\"$groups[$o]\">$groups[$o]</option>\n";}
  407. $o++;
  408. }
  409. $HTML_text.="</SELECT>\n";
  410.  
  411. $HTML_text.="</TD><TD VALIGN=TOP>Teams/User Groups:<BR>";
  412. $HTML_text.="<SELECT SIZE=15 NAME=user_group[] multiple>\n";
  413.  
  414. if (eregi("--ALL--",$user_group_string))
  415. {$HTML_text.="<option value=\"--ALL--\" selected>-- ALL USER GROUPS --</option>\n";}
  416. elseif ($user_group == '')
  417. {$HTML_text.="<option value=\"--ALL--\" selected>-- ALL USER GROUPS --</option>\n";}
  418. else
  419. {$HTML_text.="<option value=\"--ALL--\">-- ALL USER GROUPS --</option>\n";}
  420. $o=0;
  421. while ($user_groups_to_print > $o)
  422. {
  423. if (eregi("\|$user_groups[$o]\|",$user_group_string))
  424. {$HTML_text.="<option selected value=\"$user_groups[$o]\">$user_groups[$o]</option>\n";}
  425. else
  426. {$HTML_text.="<option value=\"$user_groups[$o]\">$user_groups[$o]</option>\n";}
  427. $o++;
  428. }
  429. $HTML_text.="</SELECT>\n";
  430. $HTML_text.="</TD>\n";
  431.  
  432.  
  433. $HTML_text.="<TD VALIGN=TOP>\n";
  434. $HTML_text.="<option value='TEXT'>TEXT</option></select>\n<BR><BR>";
  435. $HTML_text.="<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=SUBMIT>\n";
  436. $HTML_text.="<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\n";
  437. //$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> |";
  438. //$HTML_text.=" <a href=\"./admin.php?ADD=999999\">REPORTS</a> </FONT>\n";
  439. $HTML_text.="</FONT>\n";
  440. $HTML_text.="</TD><TD VALIGN=BOTTOM><a href=\"$PHP_SELF\">clear</a>\n";
  441. $HTML_text.="</TD><TD VALIGN=TOP> &nbsp; &nbsp; &nbsp; &nbsp; ";
  442.  
  443. $HTML_text.="</TD></TR></TABLE>";
  444. $HTML_text.="</FORM>\n\n";
  445. }
  446. ###END IF QUERY SUBMIT HIDE SELECTION OPTIONS###
  447. if ($SUBMIT=="SUBMIT")
  448. {
  449.  
  450. $HTML_text.="<PRE><FONT SIZE=3>";
  451.  
  452.  
  453. ##### DOMEDAN STUFF ######
  454. ##########################
  455.  
  456. $user_list=array();
  457. $total_dsum=array();
  458. $total_upsum=array();
  459. $sale_count=array();
  460. $other_HA_count=array();
  461. $ni_count=array();
  462. $upsale_count=array();
  463. $open_count=array();
  464. $ptime=array();
  465.  
  466. if (strtotime($query_date)<=strtotime('-30 days')){
  467. $vl = "vicidial_log_archive";
  468. $val = "vicidial_agent_log_archive";
  469. } else {
  470. $vl = "vicidial_log";
  471. $val = "vicidial_agent_log";
  472. }
  473. if ($agentpstats) {
  474. $agentidSQL = "AND vl.user in ('$agentpstats')";
  475. }
  476.  
  477.  
  478. #### QUERY TO ALL DATA
  479. $stmt = "SELECT vl.call_date,vi.status,vl.user,vl.campaign_id,vi.list_id,vl.user_group,vi.lead_id
  480. FROM $vl vl,vicidial_list vi
  481. INNER JOIN asterisk.vicidial_statuses s on s.status=vi.status
  482. WHERE vi.lead_id=vl.lead_id
  483. AND vi.user=vl.user AND DATE(vi.last_local_call_time)=DATE(vl.call_date)
  484. AND vl.call_date >= '$query_date'
  485. AND vl.call_date <= '$end_date'
  486. AND s.human_answered = 'Y'
  487. AND vl.campaign_id in ($group_SQL_str)
  488. AND vl.user_group in ($user_group_SQL_str)
  489. $agentidSQL
  490. GROUP BY vi.lead_id
  491. ;";
  492.  
  493.  
  494. //$stmt="SELECT l.lead_id, l.user, l.status, l.call_date, i.list_id FROM $vl l
  495. //LEFT JOIN vicidial_list i on i.lead_id=l.lead_id
  496. //AND i.user=l.user AND DATE(i.last_local_call_time)=DATE(l.call_date) /* AND i.status='SALE' */
  497. //INNER JOIN asterisk.vicidial_statuses s on s.status=l.status
  498. //WHERE l.call_date >= '$query_date'
  499. //AND l.call_date <= '$end_date'
  500. //AND s.human_answered = 'Y'
  501. //AND l.campaign_id in ($group_SQL_str)
  502. //AND l.user_group in ($user_group_SQL_str)
  503. //$agentidSQL
  504. // /* AND l.user in ('tht') */";
  505. if ($DB) {$ASCII_text.="$stmt\n";}
  506. $rslt=mysql_query($stmt, $link_stats);
  507. while ($row=mysql_fetch_array($rslt)) {
  508. //print_r($row['user']);
  509. // create list of users
  510. if ( !in_array($row['user'], $user_list) ) {
  511. $full_name_stmt="SELECT full_name from vicidial_users WHERE user='".$row['user']."';";
  512. $full_name_rslt = mysql_query($full_name_stmt, $link_stats);
  513. while ($full_name_row=mysql_fetch_array($full_name_rslt)) {
  514. $user_list[$row['user']] = truncateString($full_name_row['full_name'], 14, false);
  515. $user_listid[$row['user']] = $row['user'];
  516. }
  517. }
  518. $numcallcount[$row['user']]++;
  519. if ($row['status'] == 'SALE') {
  520.  
  521. $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']."';";
  522. if ($DB) {$ASCII_text.="$get_amount_stmt\n";}
  523. $get_amount_rslt = mysql_query($get_amount_stmt, $link_stats);
  524. $get_amount_row=mysql_fetch_array($get_amount_rslt);
  525. //echo $row[list_id]. "<br>";
  526. //$leads_with_SALE[]=$row['lead_id'];
  527.  
  528. #$row['security_phrase']=$row['security_phrase']-25; // this is just a silly rule, if you dont want it you can remove it
  529.  
  530. $SALE_time=date("H:i:s", strtotime($row['call_date'])); // get time of SALE
  531.  
  532. $sale_count[$row['user']]++; // count SALE
  533. $total_dsum[$row['user']]=$total_dsum[$row['user']]+$get_amount_row['d_amt']+0; // sum Donation Sales
  534. $total_upsum[$row['user']]=$total_upsum[$row['user']]+$get_amount_row['up_amt']+0; // sum UpSales
  535. $total_msum[$row['user']]=$total_msum[$row['user']]+$get_amount_row['md_amt']+0; // sum Monthly Sales
  536.  
  537. if ($get_amount_row['cc_num'] > 5 OR $get_amount_row['bank_act'] > 5){
  538. $total_vsum[$row['user']]=$total_vsum[$row['user']]+$get_amount_row['d_amt']+$get_amount_row['up_amt']+0; // sum Monthly Sales
  539. $v_count[$row['user']]++; // count Verified
  540. }
  541. if ($get_amount_row['up_amt'] >= 1){ // count upsales
  542. $upsale_count[$row['user']]++;}
  543. if ($get_amount_row['d_amt'] < 1){ // count OPENS
  544. $open_count[$row['user']]++;}
  545. if ($get_amount_row['md_amt'] >= 1){ // count monthly
  546. $md_count[$row['user']]++;}
  547.  
  548. } elseif ($row['status'] == 'NI') {
  549. $ni_count[$row['user']]++; // count NI
  550. } else {
  551. $other_HA_count[$row['user']]++; // count other human answer statuses
  552. }
  553. $snitt[$row['user']]=($total_dsum[$row['user']]/($sale_count[$row['user']]-$open_count[$row['user']])); // Calc AVG Sale
  554.  
  555. }
  556. // add users that havent made any SALE
  557. foreach ($user_list as $user => $full_name) {
  558. if ( !array_key_exists($user, $sale_count) ) {
  559. $sale_count[$user] = "0";
  560. }
  561. if ( !array_key_exists($user, $total_dsum) ) {
  562. $total_dsum[$user] = "0";
  563. }
  564. if ( !array_key_exists($user, $total_upsum) ) {
  565. $total_upsum[$user] = "0";
  566. }
  567. if ( !array_key_exists($user, $total_msum) ) {
  568. $total_msum[$user] = "0";
  569. }
  570. if ( !array_key_exists($user, $total_vsum) ) {
  571. $total_vsum[$user] = "0";
  572. }
  573. if ( !array_key_exists($user, $md_count) ) {
  574. $md_count[$user] = "0";
  575. }
  576. if ( !array_key_exists($user, $open_count) ) {
  577. $open_count[$user] = "0";
  578. }
  579. if ( !array_key_exists($user, $upsale_count) ) {
  580. $upsale_count[$user] = "0";
  581. }
  582. if ( !array_key_exists($user, $v_count) ) {
  583. $v_count[$user] = "0";
  584. }
  585. if ( !array_key_exists($user, $SALE_HR) ) {
  586. $SALE_HR[$user] = "0";
  587. }
  588. if ($DB) {$ASCII_text.="USER - ".$user_list[$user]."\n";}
  589. }
  590. //$time_user_stmt="SELECT l.user, l.user_group, l.call_date FROM $vl l
  591. //WHERE l.call_date >= '$query_date'
  592. //AND l.call_date <= '$end_date'
  593. //AND l.user_group in ($user_group_SQL_str)
  594. //AND l.campaign_id in ($group_SQL_str)
  595. //$agentidSQL
  596. //GROUP BY l.user
  597. ///* AND l.user in ('tht') */";
  598. //if ($DB) {$ASCII_text.="$$agentidSQL\n";}
  599. //$time_user_rslt=mysql_query($time_user_stmt, $link_stats);
  600. //while ($time_user_row = mysql_fetch_assoc($time_user_rslt)) {
  601. foreach ($user_listid as $userid => $user) {
  602. $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
  603. FROM $val
  604. WHERE user='" . mysql_real_escape_string($user_listid[$userid]) . "'
  605. AND campaign_id in ($group_SQL_str)
  606. AND event_time >= '" . mysql_real_escape_string($query_date) . " 0:00:01'
  607. AND event_time <= '" . mysql_real_escape_string($end_date) . " 23:59:59'
  608. AND ( (pause_sec > 0) or (wait_sec > 0) or (talk_sec > 0) or (dispo_sec > 0) )
  609. limit 10000;";
  610. if ($DB) {$ASCII_text.="agent activity|$time_stmt|\n";}
  611. $time_rslt=mysql_query($time_stmt, $link);
  612. $time_row = mysql_fetch_assoc($time_rslt);
  613.  
  614. $ptime[$userid] = $time_row['psec'];
  615. $dtime[$userid] = ($time_row['dsec']+$time_row['dedsec']);
  616. $ttime[$userid] = ($time_row['dsec']+$time_row['psec']+$time_row['wsec']+$time_row['tsec']+$time_row['dedsec']);
  617. $numcallshr[$userid] = ($numcallcount[$userid]/($ttime[$userid] / 3600));
  618. $SALE_HR[$userid] = ((($total_dsum[$userid])+$total_upsum[$userid])/($ttime[$userid] / 3600));
  619. $SALE_count_HR[$userid] = (($sale_count[$userid])/($ttime[$userid] / 3600));
  620. $wrap_per[$userid] = ((($dtime[$userid])/($ttime[$userid]))*100);
  621. $percent_SALE[$userid]=($sale_count[$userid]/($sale_count[$userid]+$ni_count[$userid])*100);
  622.  
  623. $txteamgoal = 125;
  624. $user_group_stmt="SELECT user_group from vicidial_users WHERE user='".$user_listid[$userid]."';";
  625. $user_group_rslt = mysql_query($user_group_stmt, $link_stats);
  626. while ($user_group_row=mysql_fetch_array($user_group_rslt)) {
  627. // CAN USE IF TEAMS SPLIT AMT HR GOAL if ($user_group_row['user_group'] == 'TX-Tina' OR $user_group_row['user_group'] == 'TX-Jasey') {
  628. if (substr($user_group_row['user_group'],0,3) == 'TX-'){
  629. $amthrkey = "<br>Amount per hour goal: $$txteamgoal<br>";
  630. if ($SALE_HR[$userid] >= $txteamgoal) {
  631. $amthrunder[$userid] = "#5BFF19";
  632. }
  633. if ($SALE_HR[$userid] < $txteamgoal AND $SALE_HR[$userid] >= 100) {
  634. $amthrunder[$userid] = "yellow";
  635. }
  636. if ($SALE_HR[$userid] < 100) {
  637. $amthrunder[$userid] = "red";
  638. }
  639. }
  640. }
  641. }
  642.  
  643.  
  644. if ($get_sort) {$sorttable = $$get_sort;} else {$sorttable = $SALE_HR;}
  645. //echo $get_sort;
  646. // asort keep key
  647. asort($sorttable, SORT_NUMERIC);
  648.  
  649. // reverse order, "true" keeps key
  650. $sorttable = array_reverse($sorttable, true);
  651. if ($agentfullstats){
  652. $resetlink = " ";
  653. }else{
  654. $resetlink = "<a href=\"$PHP_SELF\">RESET</a>";
  655. }
  656.  
  657. ####START TV STATS###
  658. if (!$agentpstats){
  659. $ASCII_text.="+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+$HTMLborderheader\n";
  660. $ASCII_text.="|STATS FOR DATE RANGE: $query_date_D to $end_date_D FOR $user_group_string$HTMLborderheader\n";
  661. $ASCII_text.="+--------------------------------+--------------------+-------------------------+--------+-----------+----------+-----------+--------+-----------------------------------------+$HTMLborderheader\n";
  662. $ASCII_text.="| $resetlink TOTAL | Donations | Hourly Stats | | Up Sales | Monthlys | Verified | | Time Spent |$HTMLborderheader\n";
  663. $ASCII_text.="+--------------------------------+---------+-----+----+----------+------+-------+--------+------+----+-----+----+------+----+--------+-----------+---------+-------+-----------+$HTMLborderheader\n";
  664. $ASCII_text.="| Agent Name ";
  665. $ASCII_text.=" | ".sprintf("%13s", "<b>$".round((array_sum($total_dsum)+array_sum($total_upsum)))."</b>");
  666. $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";
  667. $ASCII_text.="+--------------------------------+---------+-----+----+----------+------+-------+--------+------+----+-----+----+------+----+--------+-----------+---------+-------+-----------+$HTMLborderheader\n";
  668. $CSV_text.="\"Agent Name\",\"Total\",\"Donation $\",\"# of Donations\",\"# of Opens\",\"Amt HR\",\"Sales HR\",\"Calls HR\",\"Avg Sale Amount\",\"Up Sale $\",\"# of Up Sales\",\"Monthly $\",\"# of Monthlys\",\"Verified $\",\"# of Verified\",\"SA %\",\"Pause Time\",\"Wrap Time\",\"Wrap %\",\"Dial Time \",\"AgentID\"$CSVstatusheader\n";
  669. foreach($sorttable as $user => $amount) {
  670. $countusers++;
  671. if ($sale_count[$user] == 0) {
  672. $snitt[$user]=0;
  673. $percent_SALE[$user]=0;
  674. $open_count[$user] = 0;
  675. }
  676. if ($ptime[$user] >= 2700){$ptimehigh = "red";} elseif ($ptime[$user] >= 2400){$ptimehigh = "yellow"; } else { $ptimehigh = null;}
  677. if ($wrap_per[$user] >= 1.999){$dtimehigh = "red";} elseif ($wrap_per[$user] >= 1.499){$dtimehigh = "yellow"; } else { $dtimehigh = null;}
  678. if ($agentfullstats == $user){$rowoddeven = '<span style="background-color:#ff8c66;"'.(($c = !$c)?' class="odd"':'').">";
  679. } else {$rowoddeven = '<span'.(($c = !$c)?' class="odd"':'').">";}
  680. if ($countusers <= 9){$countusers = "0$countusers";}
  681. $firstplaces = "";
  682. $secondplaces = "";
  683. if ($countusers == 01) {$firstplaces = "<font color=green><B>"; $firstplacee = "</font></B>";}
  684. if ($countusers == 02) {$secondplaces = "<font color=orange><B>"; $secondplacee = "</font></B>";}
  685. $ASCII_text.="$rowoddeven|$firstplaces$secondplaces$countusers ".utf_8_sprintf("%-18s", $user_list[$user])."$secondplacee$firstplacee";
  686. $ASCII_text.=" - <b>$".sprintf("%6s", ($total_dsum[$user])+$total_upsum[$user]);
  687. $ASCII_text.="</b> | ".sprintf("%8s", "$".sprintf('%0.2f',$total_dsum[$user]))."</b>";
  688. $ASCII_text.=" ".sprintf("%4s", ($sale_count[$user]+0));
  689. $ASCII_text.=" ".sprintf("%4s", ($open_count[$user]+0));
  690. $ASCII_text.=" |<span STYLE='background-color: $amthrunder[$user]'> ".sprintf("%8s", "$".sprintf('%0.2f', $SALE_HR[$user]."/hr"));
  691. $ASCII_text.=" </span>| ".sprintf("%4s", sprintf('%0.2f',$SALE_count_HR[$user]."/hr"));
  692. $ASCII_text.=" | ".sprintf("%5s", sprintf('%0.2f',($numcallshr[$user])));
  693. $ASCII_text.=" | ".sprintf("%6s", "$".sprintf('%0.2f', $snitt[$user]));
  694. $ASCII_text.=" | ".sprintf("%5s", "$".$total_upsum[$user]);
  695. $ASCII_text.=" ".sprintf("%3s", ($upsale_count[$user]+0));
  696. $ASCII_text.=" | ".sprintf("%4s", "$".$total_msum[$user]);
  697. $ASCII_text.=" ".sprintf("%3s", ($md_count[$user]+0));
  698. $ASCII_text.=" | ".sprintf("%5s", "$".$total_vsum[$user]);
  699. $ASCII_text.=" ".sprintf("%3s", ($v_count[$user]+0));
  700. # $ASCII_text.=" | ".sprintf("%8s", ($other_HA_count[$user]+$sale_count[$user]+$ni_count[$user]));
  701. # $ASCII_text.=" | ".sprintf("%4s", ($ni_count[$user]+0));
  702. $ASCII_text.=" | ".sprintf("%6s", sprintf('%0.2f', $percent_SALE[$user])."%");
  703. $ASCII_text.=" |<span STYLE='background-color: $ptimehigh'> ".sprintf("%9s", sprintf( "%02d:%02d:%02d", $ptime[$user] / 3600, $ptime[$user] / 60 % 60, $ptime[$user] % 60 ));
  704. $ASCII_text.=" </span>|<span STYLE='background-color: $dtimehigh'> ".sprintf("%8s", sprintf( "%02d:%02d:%02d", $dtime[$user] / 3600, $dtime[$user] / 60 % 60, $dtime[$user] % 60 ));
  705. $ASCII_text.=" ".sprintf("%5s", sprintf('%0.2f', $wrap_per[$user])."%");
  706. $ASCII_text.=" </span>| ".sprintf("%9s", sprintf( "%02d:%02d:%02d", $ttime[$user] / 3600, $ttime[$user] / 60 % 60, $ttime[$user] % 60 )." |");
  707. $ASCII_text.="</span>\n";
  708.  
  709. $CSV_text.="\"$user_list[$user]\",\"$".round(($total_dsum[$user])+$total_upsum[$user])."\",\"$".round($total_dsum[$user])."\",\"".($sale_count[$user]+0)."\",\"".($open_count[$user]+0)."\",\"$$SALE_HR[$user]\",\"".sprintf('%0.2f',$SALE_count_HR[$user])."\",\"".round($numcallshr[$user])."\",\"$$snitt[$user]\",\"$$total_upsum[$user]\",\"".($upsale_count[$user]+0)."\",\"$$total_msum[$user]\",\"".($md_count[$user]+0)."\",\"$$total_vsum[$user]\",\"".($v_count[$user]+0)."\",\"$percent_SALE[$user]\",\"".sprintf("%9s", sprintf( "%02d:%02d:%02d", $ptime[$user] / 3600, $ptime[$user] / 60 % 60, $ptime[$user] % 60 ))."\",\"".sprintf("%8s", sprintf( "%02d:%02d:%02d", $dtime[$user] / 3600, $dtime[$user] / 60 % 60, $dtime[$user] % 60 ))."\",\"".sprintf('%0.2f',$wrap_per[$user])."%\",\"".sprintf( "%02d:%02d:%02d", $ttime[$user] / 3600, $ttime[$user] / 60 % 60, $ttime[$user] % 60 )."\",\"$user_listid[$user]\"\n";
  710. $rowoddeven++;
  711. }
  712. }
  713. ###END TV STATS###
  714.  
  715. if (!$agentpstats) {
  716. if (array_sum($sale_count) == 0) {
  717. $sum_snitt=0;
  718. $sum_percent_SALE=0;
  719. $sum_SALE_HR=0;
  720. } else {
  721. $sum_snitt=(array_sum($total_dsum)/(array_sum($sale_count)-array_sum($open_count)));
  722. $sum_percent_SALE=(array_sum($sale_count)/(array_sum($sale_count)+array_sum($ni_count))*100);
  723. $sum_SALE_HR=((array_sum($total_dsum)+array_sum($total_upsum))/(array_sum($ttime) / 3600));
  724. }
  725. $ASCII_text.="+--------------------------------+---------+-----+----+----------+------+-------+--------+------+----+-----+----+------+----+--------+-----------+---------+-------+-----------+$HTMLborderheader\n";
  726. $ASCII_text.="<span style=\"background-color:#FFFF66;\">| Agents: $countusers".sprintf("%-11s", "");
  727. $ASCII_text.=" | ".sprintf("%13s", "<b>$".round((array_sum($total_dsum)+array_sum($total_upsum)))."</b>");
  728. $ASCII_text.=" | ".sprintf("%8s", "$".sprintf('%0.2f',array_sum($total_dsum)));
  729. $ASCII_text.=" ".sprintf("%4s", (array_sum($sale_count)+0));
  730. $ASCII_text.=" ".sprintf("%4s", (array_sum($open_count)+0));
  731. $ASCII_text.=" | ".sprintf("%8s", "$".sprintf('%0.2f',$sum_SALE_HR));
  732. $ASCII_text.=" | ".sprintf("%4s", sprintf('%0.2f',array_sum($SALE_count_HR) / $countusers));
  733. $ASCII_text.=" | ".sprintf("%5s", sprintf('%0.2f',array_sum($numcallshr) / $countusers));
  734. $ASCII_text.=" | ".sprintf("%6s", "$".sprintf('%0.2f',$sum_snitt));
  735. $ASCII_text.=" | ".sprintf("%5s", "$".array_sum($total_upsum));
  736. $ASCII_text.=" ".sprintf("%3s", (array_sum($upsale_count)+0));
  737. $ASCII_text.=" | ".sprintf("%4s", "$".array_sum($total_msum));
  738. $ASCII_text.=" ".sprintf("%3s", (array_sum($md_count)+0));
  739. $ASCII_text.=" | ".sprintf("%5s", "$".array_sum($total_vsum));
  740. $ASCII_text.=" ".sprintf("%3s", (array_sum($v_count)+0));
  741. # $ASCII_text.=" | ".sprintf("%8s", (array_sum($other_HA_count)+array_sum($sale_count)+array_sum($ni_count)));
  742. # $ASCII_text.=" | ".sprintf("%4s", (array_sum($ni_count)+0));
  743. $ASCII_text.=" | ".sprintf("%6s", sprintf('%0.2f',$sum_percent_SALE)."%");
  744. $ASCII_text.=" | ".sprintf("%9s", sprintf( "%03d:%02d:%02d", array_sum($ptime) / 3600, array_sum($ptime) / 60 % 60, array_sum($ptime) % 60 ));
  745. $ASCII_text.=" | ".sprintf("%8s", sprintf( "%02d:%02d:%02d", array_sum($dtime) / 3600, array_sum($dtime) / 60 % 60, array_sum($dtime) % 60 ));
  746. $ASCII_text.=" ".sprintf("%5s", sprintf('%0.2f', array_sum($wrap_per) / $countusers)."%");
  747. $ASCII_text.=" | ".sprintf("%9s", sprintf( "%03d:%02d:%02d", array_sum($ttime) / 3600, array_sum($ttime) / 60 % 60, array_sum($ttime) % 60 )." |");
  748. $ASCII_text.="</span>\n";
  749.  
  750.  
  751. $CSV_text.="\"ALL:\",\"$".round((array_sum($total_dsum)+array_sum($total_upsum)))."\",\"$".array_sum($total_dsum)."\",\"".(array_sum($sale_count)+0)."\",\"".(array_sum($open_count)+0)."\",\"$$sum_SALE_HR\",\"".sprintf('%0.2f',array_sum($SALE_count_HR) / $countusers)."\",\"".round(array_sum($numcallshr) / $countusers)."\",\"$".$sum_snitt."\",\"$".array_sum($total_upsum)."\",\"".(array_sum($upsale_count)+0)."\",\"$".array_sum($total_msum)."\",\"".(array_sum($md_count)+0)."\",\"$".array_sum($total_vsum)."\",\"".(array_sum($v_count)+0)."\",\"$sum_percent_SALE%\",\"".sprintf( "%03d:%02d:%02d", array_sum($ptime) / 3600, array_sum($ptime) / 60 % 60, array_sum($ptime) % 60 )."\",\"".sprintf( "%02d:%02d:%02d", array_sum($dtime) / 3600, array_sum($dtime) / 60 % 60, array_sum($dtime) % 60 )."\",\"".sprintf('%0.1f', array_sum($wrap_per) / $countusers)."%\",\"".sprintf( "%03d:%02d:%02d", array_sum($ttime) / 3600, array_sum($ttime) / 60 % 60, array_sum($ttime) % 60 )."\"\n";
  752. $CSV_text.="\n\n";
  753. $ASCII_text.="+--------------------------------+---------+-----+----+----------+------+-------+--------+------+----+-----+----+------+----+--------+-----------+---------+-------+-----------+$HTMLborderheader\n";
  754. $ASCII_text.="| $resetlink TOTAL | Donations | Hourly Stats | | Up Sales | Monthlys | Verified | | Time Spent |$HTMLborderheader\n";
  755. $ASCII_text.="+--------------------------------+--------------------+-------------------------+--------+-----------+----------+-----------+--------+-----------------------------------------+$HTMLborderheader\n";
  756. // compare starttime with current time and show result
  757. }
  758. $totaltime = (microtime(1) - $starttime);
  759. $ASCII_text.= $amthrkey;
  760. if ($timeout){$ASCII_text.= "<Br>Stats refresh every $timeout Seconds<br>";}
  761. $ASCII_text.= "Last Update: ".DATE('m-d-Y h:i:s');
  762. $ASCII_text.= "<br /><br />Execution-time: ".$totaltime."S - ".$db_source."\n\n";
  763. if (!$agentpstats AND !$agentfullstats) {
  764. $ASCII_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>";
  765. }
  766. $ASCII_text.="</FONT></PRE>";
  767. $ASCII_text.="</BODY>\n";
  768. $ASCII_text.="</HTML>\n";
  769.  
  770.  
  771.  
  772. # for debugging and developing
  773. /*
  774. echo "<pre>";
  775. print_r($total_count);
  776. echo "\nuser_list\n";
  777. print_r($user_list);
  778. echo "\ntotal_sum\n";
  779. print_r($total_dsum);
  780. echo "\nsale_count\n";
  781. print_r($sale_count);
  782. echo "\nni_count\n";
  783. print_r($ni_count);
  784. echo "\nother_HA_count\n";
  785. print_r($other_HA_count);
  786. echo "\np1_sum\n";
  787. print_r($p1_sum);
  788. echo "\np2_sum\n";
  789. print_r($p2_sum);
  790. echo "\np3_sum\n";
  791. print_r($p3_sum);
  792. echo "\np4_sum\n";
  793. print_r($p4_sum);
  794. echo "\np5_sum\n";
  795. print_r($p5_sum);
  796. echo "\np6_sum\n";
  797. print_r($p6_sum);
  798. echo "\np7_sum\n";
  799. print_r($p7_sum);
  800. echo "\np8_sum\n";
  801. print_r($p8_sum);
  802. echo "\np0_sum\n";
  803. print_r($p0_sum);
  804. echo "</pre>";
  805. */
  806.  
  807.  
  808.  
  809.  
  810. }
  811.  
  812. if ($file_download>0)
  813. {
  814. $FILE_TIME = date("Ymd-His");
  815. $CSVfilename = "leaderboard_$US$FILE_TIME.csv";
  816. $CSV_text=preg_replace('/\n +,/', ',', $CSV_text);
  817. $CSV_text=preg_replace('/ +\"/', '"', $CSV_text);
  818. $CSV_text=preg_replace('/\" +/', '"', $CSV_text);
  819.  
  820. // We'll be outputting a TXT file
  821. header('Content-type: application/octet-stream');
  822. // It will be called LIST_101_20090209-121212.txt
  823. header("Content-Disposition: attachment; filename=\"$CSVfilename\"");
  824. header('Expires: 0');
  825. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  826. header('Pragma: public');
  827. ob_clean();
  828. flush();
  829.  
  830. echo "$CSV_text";
  831.  
  832. exit;
  833. }
  834. else
  835. {
  836. header("Content-type: text/html; charset=utf-8");
  837.  
  838. $HTML_text.=$ASCII_text;
  839.  
  840. echo $HTML_head;
  841. $short_header=1;
  842. if (!$SUBMIT){
  843. require("admin_header.php");
  844. }
  845. echo $HTML_text;
  846. flush();
  847. }
  848. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement