LICENSE: AGPLv2 # # CHANGES # # 70813-1526 - First Build # 71008-1436 - Added shift to be defined in dbconnect_mysqli.php # 71217-1128 - Changed method for calculating stats # 71228-1140 - added percentages, cross-day start/stop # 80328-1139 - adapted for basic fronter/closer stats # 90310-2132 - Added admin header # 90508-0644 - Changed to PHP long tags # 100214-1421 - Sort menu alphabetically # 100216-0042 - Added popup date selector # 100712-1324 - Added system setting slave server option # 100802-2347 - Added User Group Allowed Reports option validation # 100914-1326 - Added lookup for user_level 7 users to set to reports only which will remove other admin links # 110703-1828 - Added download option # 111104-1213 - Added user_group restrictions for selecting in-groups # 120224-0910 - Added HTML display option with bar graphs # 120705-2007 - Changed SALES to use sales status flag # 130414-0126 - Added report logging # 130610-0948 - Finalized changing of all ereg instances to preg # 130619-2339 - Added filtering of input to prevent SQL injection attacks and new user auth # 130901-1930 - Changed to mysqli PHP functions # 140108-0725 - Added webserver and hostname to report logging # $startMS = microtime(); require("dbconnect_mysqli.php"); require("functions.php"); $PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; $PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; $PHP_SELF=$_SERVER['PHP_SELF']; if (isset($_GET["DB"])) {$DB=$_GET["DB"];} elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} if (isset($_GET["group"])) {$group=$_GET["group"];} elseif (isset($_POST["group"])) {$group=$_POST["group"];} if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} if (isset($_GET["shift"])) {$shift=$_GET["shift"];} elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} if (isset($_GET["submit"])) {$submit=$_GET["submit"];} elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} if (strlen($shift)<2) {$shift='ALL';} $report_name = 'Fronter - Closer Report'; $db_source = 'M'; $JS_text="\n"; $HTML_head.="\n"; $HTML_head.="\n"; #if (strlen($group) > 0) # { # if (preg_match("/\|$group\|/i",$groups_string)) # { # # $HTML_head.="\n"; # } # else # { # # $HTML_head.="\n"; # $group=''; # } # } $HTML_head.="\n"; $HTML_head.="$report_name\n"; $short_header=1; # require("admin_header.php"); $HTML_text.="
"; $HTML_text.="
\n"; $HTML_text.=""; $HTML_text.="\n"; $HTML_text.="\n"; $HTML_text.="   "; $HTML_text.="\n"; $HTML_text.="\n"; $HTML_text.="\n"; $HTML_text.="\n"; $HTML_text.="           DOWNLOAD | MODIFY | REPORTS
Display as:
ASCII
HTML
\n"; $HTML_text.="
\n\n"; $HTML_text.="
\n\n";


if (!$group)
{
$HTML_text.="\n\n";
$HTML_text.="PLEASE SELECT AN IN-GROUP AND DATE ABOVE THEN CLICK SUBMIT\n";
}

else
{
#	$time_BEGIN=$AM_shift_BEGIN;
#	$time_END=$AM_shift_END;
#$query_date_BEGIN = "$query_date $time_BEGIN";   
#$query_date_END = "$query_date $time_END";

$Cqdate = explode('-',$query_date);

if ($shift == 'AM') 
	{
	$query_date_BEGIN = date("Y-m-d H:i:s", mktime(1, 0, 0, $Cqdate[1], $Cqdate[2], $Cqdate[0]));
	$query_date_END = date("Y-m-d H:i:s", mktime(17, 45, 0, $Cqdate[1], $Cqdate[2], $Cqdate[0]));
	}
if ($shift == 'PM') 
	{
	$query_date_BEGIN = date("Y-m-d H:i:s", mktime(17, 45, 1, $Cqdate[1], $Cqdate[2], $Cqdate[0]));
	$query_date_END = date("Y-m-d H:i:s", mktime(24, 59, 59, $Cqdate[1], $Cqdate[2], $Cqdate[0]));
	}
if ($shift == 'ALL') 
	{
	$query_date_BEGIN = date("Y-m-d H:i:s", mktime(1, 0, 0, $Cqdate[1], $Cqdate[2], $Cqdate[0]));
	$query_date_END = date("Y-m-d H:i:s", mktime(24, 59, 59, $Cqdate[1], $Cqdate[2], $Cqdate[0]));
	}

$HTML_text.="In-Group Fronter-Closer Stats Report                      $NOW_TIME\n";

$HTML_text.="\n";
$HTML_text.="---------- TOTALS FOR $query_date_BEGIN to $query_date_END\n";

$sale_dispo_stmt="select distinct status from vicidial_campaign_statuses where sale='Y' and campaign_id in (SELECT campaign_id from vicidial_campaigns where closer_campaigns LIKE \"% " . mysqli_real_escape_string($link, $group) . " %\" $LOGallowed_campaignsSQL) UNION select distinct status from vicidial_statuses where sale='Y'";
if ($DB) {$HTML_text.="$sale_dispo_stmt\n";}
$sale_dispo_rslt=mysql_to_mysqli($sale_dispo_stmt, $link);
$sale_dispos="'SALE'"; $sale_dispo_str="|SALE";
while ($ssrow=mysqli_fetch_row($sale_dispo_rslt)) {
	$sale_dispos.=",'$ssrow[0]'";
	$sale_dispo_str.="|$ssrow[0]";
}
$sale_dispo_str.="|";
if ($DB) {$HTML_text.="Sale dispo string: $sale_dispo_str\n";}

$stmt="select count(*) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='" . mysqli_real_escape_string($link, $group) . "' and status in ($sale_dispos);";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {$HTML_text.="$stmt\n";}
$row=mysqli_fetch_row($rslt);
$A1_points = ($row[0] * 1);
$A1_points =	sprintf("%10s", $A1_points);
$A1_tally =	sprintf("%10s", $row[0]);

$TOT_tally = ($A1_tally + $A2_tally + $A3_tally + $A4_tally);
$TOT_points = ($A1_points + $A2_points + $A3_points + $A4_points);
$TOT_tally =	sprintf("%10s", $TOT_tally);
$TOT_points =	sprintf("%10s", $TOT_points);

$HTML_text.="STATUS   CUSTOMERS\n";
$HTML_text.="SALES:   $A1_tally\n";

$HTML_text.="\n";









##############################
#########  FRONTER STATS

$TOTagents=0;
$TOTcalls=0;
$TOTsales=0;
$totA1=0;
$totA2=0;
$totA3=0;
$totA4=0;
$totA5=0;
$totA6=0;
$totA7=0;
$totA8=0;
$totA9=0;
$totDROP=0;
$totOTHER=0;

$CSV_fronter_header="\"TOTALS FOR $query_date_BEGIN to $query_date_END\"\n";
$CSV_fronter_header.="\"STATUS   CUSTOMERS\"\n";
$CSV_fronter_header.="\"SALES:   $A1_tally\"\n\n";
$CSV_fronter_header.="\"FRONTER STATS\"\n";
$CSV_fronter_header.="\"AGENT\",\"SUCCESS\",\"XFERS\",\"SUCCESS%\",\"SALE\",\"DROP\",\"OTHER\"\n";
$CSV_fronter_lines="";
$CSV_fronter_footer="";

$ASCII_text="\n";
$ASCII_text.="---------- FRONTER STATS\n";
$ASCII_text.="+--------------------------+-------+--------+--------+------+------+------+\n";
$ASCII_text.="| AGENT                    |SUCCESS| XFERS  |SUCCESS%| SALE | DROP |OTHER |\n";
$ASCII_text.="+--------------------------+-------+--------+--------+------+------+------+\n";

######## GRAPHING #########
$graph_stats=array();
$max_success=1;
$max_xfers=1;
$max_success_pct=1;
$max_sales=1;
$max_drops=1;
$max_other=1;
$GRAPH="";
$GRAPH.="";
$GRAPH.="
SUCCESSXFERSSUCCESS %SALEDROPOTHER

 


"; $graph_header=""; $SUCCESS_graph=$graph_header.""; $XFERS_graph=$graph_header.""; $SUCCESSPCT_graph=$graph_header.""; $SALE_graph=$graph_header.""; $DROP_graph=$graph_header.""; $OTHER_graph=$graph_header.""; ########################### #$stmt="select vicidial_xfer_log.user,full_name,count(*) from vicidial_xfer_log,vicidial_users where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='" . mysqli_real_escape_string($link, $group) . "' and vicidial_xfer_log.user is not null and vicidial_xfer_log.user=vicidial_users.user group by vicidial_xfer_log.user;"; $stmt="select user,count(distinct lead_id) from vicidial_xfer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='" . mysqli_real_escape_string($link, $group) . "' and user is not null group by user;"; if ($non_latin > 0) {$rslt=mysql_to_mysqli("SET NAMES 'UTF8'", $link);} $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {$ASCII_text.="$stmt\n";} $users_to_print = mysqli_num_rows($rslt); $i=0; while ($i < $users_to_print) { $row=mysqli_fetch_row($rslt); $TOTcalls = ($TOTcalls + $row[1]); $userRAW[$i]=$row[0]; $user[$i] = sprintf("%-6s", $row[0]);while(strlen($user[$i])>6) {$user[$i] = substr("$user[$i]", 0, -1);} $USERcallsRAW[$i] = $row[1]; $USERcalls[$i] = sprintf("%6s", $row[1]); $i++; } $i=0; while ($i < $users_to_print) { $stmt="select full_name from vicidial_users where user='$userRAW[$i]' $LOGadmin_viewable_groupsSQL;"; if ($non_latin > 0) {$rslt=mysql_to_mysqli("SET NAMES 'UTF8'", $link);} $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {$ASCII_text.="$stmt\n";} $names_to_print = mysqli_num_rows($rslt); if ($names_to_print > 0) { $row=mysqli_fetch_row($rslt); if ($non_latin < 1) { $full_name[$i] = sprintf("%-15s", $row[0]); while(strlen($full_name[$i])>15) {$full_name[$i] = substr("$full_name[$i]", 0, -1);} } else { $full_name[$i] = sprintf("%-45s", $row[0]); while(mb_strlen($full_name[$i],'utf-8')>15) {$full_name[$i] = mb_substr("$full_name[$i]", 0, -1,'utf-8');} } } else {$full_name[$i] = ' ';} $A1=0; $A2=0; $A3=0; $A4=0; $A5=0; $A6=0; $A7=0; $A8=0; $A9=0; $DROP=0; $OTHER=0; $sales=0; $stmt="select vc.status,count(distinct vc.lead_id) from vicidial_xfer_log vx, vicidial_closer_log vc where vx.call_date >= '$query_date_BEGIN' and vx.call_date <= '$query_date_END' and vc.call_date >= '$query_date_BEGIN' and vc.call_date <= '$query_date_END' and vc.campaign_id='" . mysqli_real_escape_string($link, $group) . "' and vx.campaign_id='" . mysqli_real_escape_string($link, $group) . "' and vx.user='$userRAW[$i]' and vc.lead_id=vx.lead_id and vc.xfercallid=vx.xfercallid group by vc.status;"; if ($non_latin > 0) {$rslt=mysql_to_mysqli("SET NAMES 'UTF8'", $link);} $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {$ASCII_text.="$stmt\n";} $lead_ids_to_print = mysqli_num_rows($rslt); $j=0; while ($j < $lead_ids_to_print) { $row=mysqli_fetch_row($rslt); $recL=0; if ( (preg_match("/\|$row[0]\|/", $sale_dispo_str)) and ($recL < 1) ) {$A1=$row[1]; $recL++; $sales=($sales + $row[1]);} # if ( ($row[0]=='A2') and ($recL < 1) ) {$A2=$row[1]; $recL++; $sales=($sales + $row[1]);} # if ( ($row[0]=='A3') and ($recL < 1) ) {$A3=$row[1]; $recL++; $sales=($sales + $row[1]);} # if ( ($row[0]=='A4') and ($recL < 1) ) {$A4=$row[1]; $recL++; $sales=($sales + $row[1]);} # if ( ($row[0]=='A5') and ($recL < 1) ) {$A5=$row[1]; $recL++;} # if ( ($row[0]=='A6') and ($recL < 1) ) {$A6=$row[1]; $recL++;} # if ( ($row[0]=='A7') and ($recL < 1) ) {$A7=$row[1]; $recL++;} # if ( ($row[0]=='A8') and ($recL < 1) ) {$A8=$row[1]; $recL++;} # if ( ($row[0]=='A9') and ($recL < 1) ) {$A9=$row[1]; $recL++;} if ( ($row[0]=='DROP') and ($recL < 1) ) {$DROP=$row[1]; $recL++;} if ($recL < 1) {$OTHER=($row[1] + $OTHER); $recL++;} $j++; } $totA1 = ($totA1 + $A1); $totA2 = ($totA2 + $A2); $totA3 = ($totA3 + $A3); $totA4 = ($totA4 + $A4); $totA5 = ($totA5 + $A5); $totA6 = ($totA6 + $A6); $totA7 = ($totA7 + $A7); $totA8 = ($totA8 + $A8); $totA9 = ($totA9 + $A9); $totDROP = ($totDROP + $DROP); $totOTHER = ($totOTHER + $OTHER); $TOTsales = ($TOTsales + $sales); if ( ($USERcallsRAW[$i] > 0) and ($sales > 0) ) {$Spct = ( ($sales / $USERcallsRAW[$i]) * 100);} else {$Spct=0;} $Spct = round($Spct, 2); $Spct = sprintf("%01.2f", $Spct); if ($sales>$max_success) {$max_success=$sales;} if ($USERcalls[$i]>$max_xfers) {$max_xfers=$USERcalls[$i];} if ($Spct>$max_success_pct) {$max_success_pct=$Spct;} if ($A1>$max_sales) {$max_sales=$A1;} if ($DROP>$max_drops) {$max_drops=$DROP;} if ($OTHER>$max_other) {$max_other=$OTHER;} $graph_stats[$i][0]="$user[$i] - $full_name[$i]"; $graph_stats[$i][1]=$sales; $graph_stats[$i][2]=$USERcalls[$i]; $graph_stats[$i][3]=$Spct; $graph_stats[$i][4]=$A1; $graph_stats[$i][5]=$DROP; $graph_stats[$i][6]=$OTHER; $A1 = sprintf("%4s", $A1); $A2 = sprintf("%4s", $A2); $A3 = sprintf("%4s", $A3); $A4 = sprintf("%4s", $A4); $A5 = sprintf("%4s", $A5); $A6 = sprintf("%4s", $A6); $A7 = sprintf("%4s", $A7); $A8 = sprintf("%4s", $A8); $A9 = sprintf("%4s", $A9); $DROP = sprintf("%4s", $DROP); $OTHER = sprintf("%4s", $OTHER); $sales = sprintf("%5s", $sales); $Spct = sprintf("%6s", $Spct); $ASCII_text.="| $user[$i] - $full_name[$i] | $sales | $USERcalls[$i] | $Spct%| $A1 | $DROP | $OTHER |\n"; $CSV_fronter_lines.="\"$user[$i] - $full_name[$i]\",\"$sales\",\"$USERcalls[$i]\",\"$Spct%\",\"$A1\",\"$DROP\",\"$OTHER\"\n"; $i++; } if ( ($TOTcalls > 0) and ($TOTsales > 0) ) {$totSpct = ( ($TOTsales / $TOTcalls) * 100);} else {$totSpct=0;} $totSpct = round($totSpct, 2); $totSpct = sprintf("%01.2f", $totSpct); $totSpct = sprintf("%6s", $totSpct); $TOTagents = sprintf("%6s", $i); $TOTcalls = sprintf("%6s", $TOTcalls); $TOTsales = sprintf("%5s", $TOTsales); $totA1 = sprintf("%5s", $totA1); $totA2 = sprintf("%5s", $totA2); $totA3 = sprintf("%5s", $totA3); $totA4 = sprintf("%5s", $totA4); $totA5 = sprintf("%5s", $totA5); $totA6 = sprintf("%5s", $totA6); $totA7 = sprintf("%5s", $totA7); $totA8 = sprintf("%5s", $totA8); $totA9 = sprintf("%5s", $totA9); $totDROP = sprintf("%5s", $totDROP); $totOTHER = sprintf("%5s", $totOTHER); $stmt="select avg(queue_seconds) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='" . mysqli_real_escape_string($link, $group) . "';"; $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {$ASCII_text.="$stmt\n";} $row=mysqli_fetch_row($rslt); $AVGwait = $row[0]; $AVGwait_M = ($AVGwait / 60); $AVGwait_M = round($AVGwait_M, 2); $AVGwait_M_int = intval("$AVGwait_M"); $AVGwait_S = ($AVGwait_M - $AVGwait_M_int); $AVGwait_S = ($AVGwait_S * 60); $AVGwait_S = round($AVGwait_S, 0); if ($AVGwait_S < 10) {$AVGwait_S = "0$AVGwait_S";} $AVGwait_MS = "$AVGwait_M_int:$AVGwait_S"; $AVGwait = sprintf("%6s", $AVGwait_MS); $ASCII_text.="+--------------------------+-------+--------+--------+------+------+------+\n"; $ASCII_text.="| TOTAL FRONTERS: $TOTagents | $TOTsales | $TOTcalls | $totSpct%|$totA1 |$totDROP |$totOTHER |\n"; $ASCII_text.="+--------------------------+-------+--------+--------+------+------+------+\n"; $ASCII_text.="| Average time in Queue for customers: $AVGwait |\n"; $ASCII_text.="+--------------------------+-------+--------+--------+------+------+------+\n"; $CSV_fronter_footer.="\"TOTAL FRONTERS: $TOTagents\",\"$TOTsales\",\"$TOTcalls\",\"$totSpct%\",\"$totA1\",\"$totDROP\",\"$totOTHER\"\n"; $CSV_fronter_footer.="\"Average time in Queue for customers: $AVGwait\"\n\n\n"; for ($d=0; $d"; $XFERS_graph.=" "; $SUCCESSPCT_graph.=" "; $SALE_graph.=" "; $DROP_graph.=" "; $OTHER_graph.=" "; } $SUCCESS_graph.="
FRONTER STATS
AGENTSUCCESS
XFERS
SUCCESS %
SALE
DROP
OTHER
".$graph_stats[$d][1]."
".$graph_stats[$d][0]."".$graph_stats[$d][2]."
".$graph_stats[$d][0]."".$graph_stats[$d][3]."
".$graph_stats[$d][0]."".$graph_stats[$d][4]."
".$graph_stats[$d][0]."".$graph_stats[$d][5]."
".$graph_stats[$d][0]."".$graph_stats[$d][5]."
TOTAL:".trim($TOTsales)."
"; $XFERS_graph.="
TOTAL:".trim($TOTcalls)."
"; $SUCCESSPCT_graph.="TOTAL:".trim($totSpct)."%"; $SALE_graph.="TOTAL:".trim($totA1).""; $DROP_graph.="TOTAL:".trim($totDROP).""; $OTHER_graph.="TOTAL:".trim($totOTHER).""; $JS_onload.="\tDrawFronterGraph('SUCCESS', '1');\n"; $JS_text.="function DrawFronterGraph(graph, th_id) {\n"; $JS_text.=" var SUCCESS_graph=\"$SUCCESS_graph\";\n"; $JS_text.=" var XFERS_graph=\"$XFERS_graph\";\n"; $JS_text.=" var SUCCESSPCT_graph=\"$SUCCESSPCT_graph\";\n"; $JS_text.=" var SALE_graph=\"$SALE_graph\";\n"; $JS_text.=" var DROP_graph=\"$DROP_graph\";\n"; $JS_text.=" var OTHER_graph=\"$OTHER_graph\";\n"; $JS_text.="\n"; $JS_text.=" for (var i=1; i<=6; i++) {\n"; $JS_text.=" var cellID=\"frontergraph\"+i;\n"; $JS_text.=" document.getElementById(cellID).style.backgroundColor='#DDDDDD';\n"; $JS_text.=" }\n"; $JS_text.=" var cellID=\"frontergraph\"+th_id;\n"; $JS_text.=" document.getElementById(cellID).style.backgroundColor='#999999';\n"; $JS_text.=" var graph_to_display=eval(graph+\"_graph\");\n"; $JS_text.=" document.getElementById('fronter_graph').innerHTML=graph_to_display;\n"; $JS_text.="}\n"; $GRAPH_text.=$GRAPH; ############################## ######### CLOSER STATS $TOTagents=0; $TOTcalls=0; $totA1=0; $totA2=0; $totA3=0; $totA4=0; $totA5=0; $totA6=0; $totA7=0; $totA8=0; $totA9=0; $totDROP=0; $totOTHER=0; $TOTsales=0; $CSV_closer_header=""; $CSV_closer_lines=""; $CSV_closer_footer=""; $ASCII_text.="\n"; $ASCII_text.="---------- CLOSER STATS\n"; $ASCII_text.="+--------------------------+--------+------+------+------+------+-------+\n"; $ASCII_text.="| AGENT | CALLS | SALE | DROP |OTHER | SALE | CONV %|\n"; $ASCII_text.="+--------------------------+--------+------+------+------+------+-------+\n"; $CSV_closer_header="\"CLOSER STATS\"\n"; $CSV_closer_header.="\"AGENT\",\"CALLS\",\"SALE\",\"DROP\",\"OTHER\",\"SALE\",\"CONV %\"\n"; ######## GRAPHING ######### $max_calls=1; $max_sales=1; $max_drops=1; $max_other=1; $max_sales2=1; $max_conv_pct=1; $GRAPH="

"; $GRAPH.=""; $GRAPH.="
CALLSSALESDROPOTHERSALESCONV %

 


"; $graph_header=""; $CALLS_graph=$graph_header.""; $SALES_graph=$graph_header.""; $DROP_graph=$graph_header.""; $OTHER_graph=$graph_header.""; $SALES2_graph=$graph_header.""; $CONVPCT_graph=$graph_header.""; ########################### $stmt="select user,count(*) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='" . mysqli_real_escape_string($link, $group) . "' and user is not null group by user;"; if ($non_latin > 0) {$rslt=mysql_to_mysqli("SET NAMES 'UTF8'", $link);} $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {$ASCII_text.="$stmt\n";} $users_to_print = mysqli_num_rows($rslt); $i=0; while ($i < $users_to_print) { $row=mysqli_fetch_row($rslt); $TOTcalls = ($TOTcalls + $row[1]); $userRAW[$i]=$row[0]; $user[$i] = sprintf("%-6s", $row[0]);while(strlen($user[$i])>6) {$user[$i] = substr("$user[$i]", 0, -1);} $USERcalls[$i] = sprintf("%6s", $row[1]); $USERcallsRAW[$i] = $row[1]; $i++; } $i=0; while ($i < $users_to_print) { $stmt="select full_name from vicidial_users where user='$userRAW[$i]' $LOGadmin_viewable_groupsSQL;"; if ($non_latin > 0) {$rslt=mysql_to_mysqli("SET NAMES 'UTF8'", $link);} $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {$ASCII_text.="$stmt\n";} $names_to_print = mysqli_num_rows($rslt); if ($names_to_print > 0) { $row=mysqli_fetch_row($rslt); if ($non_latin < 1) { $full_name[$i] = sprintf("%-15s", $row[0]); while(strlen($full_name[$i])>15) {$full_name[$i] = substr("$full_name[$i]", 0, -1);} } else { $full_name[$i] = sprintf("%-45s", $row[0]); while(mb_strlen($full_name[$i],'utf-8')>15) {$full_name[$i] = mb_substr("$full_name[$i]", 0, -1,'utf-8');} } } else {$full_name[$i] = ' ';} $A1=0; $A2=0; $A3=0; $A4=0; $A5=0; $A6=0; $A7=0; $A8=0; $A9=0; $DROP=0; $OTHER=0; $sales=0; $uTOP=0; $uBOT=0; $points=0; $stmt="select status,count(*) from vicidial_closer_log where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' and campaign_id='" . mysqli_real_escape_string($link, $group) . "' and user='$userRAW[$i]' group by status;"; if ($non_latin > 0) {$rslt=mysql_to_mysqli("SET NAMES 'UTF8'", $link);} $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {$ASCII_text.="$stmt\n";} $lead_ids_to_print = mysqli_num_rows($rslt); $j=0; while ($j < $lead_ids_to_print) { $row=mysqli_fetch_row($rslt); $recL=0; if ( preg_match("/\|$row[0]\|/", $sale_dispo_str) and ($recL < 1) ) { $A1=$row[1]; $recL++; $sales=($sales + $row[1]); $points = ($points + ($row[1] * 1) ); } /* if ( ($row[0]=='A2') and ($recL < 1) ) { $A2=$row[1]; $recL++; $sales=($sales + $row[1]); $uTOP=($uTOP + $row[1]); $points = ($points + ($row[1] * 2) ); } if ( ($row[0]=='A3') and ($recL < 1) ) { $A3=$row[1]; $recL++; $sales=($sales + $row[1]); $uBOT=($uBOT + $row[1]); $points = ($points + ($row[1] * 2) ); } if ( ($row[0]=='A4') and ($recL < 1) ) { $A4=$row[1]; $recL++; $sales=($sales + $row[1]); $uTOP=($uTOP + $row[1]); $uBOT=($uBOT + $row[1]); $points = ($points + ($row[1] * 3) ); } */ # if ( ($row[0]=='A5') and ($recL < 1) ) {$A5=$row[1]; $recL++;} # if ( ($row[0]=='A6') and ($recL < 1) ) {$A6=$row[1]; $recL++;} # if ( ($row[0]=='A7') and ($recL < 1) ) {$A7=$row[1]; $recL++;} # if ( ($row[0]=='A8') and ($recL < 1) ) {$A8=$row[1]; $recL++;} # if ( ($row[0]=='A9') and ($recL < 1) ) {$A9=$row[1]; $recL++;} if ( ($row[0]=='DROP') and ($recL < 1) ) {$DROP=$row[1]; $recL++;} if ($recL < 1) {$OTHER=($row[1] + $OTHER); $recL++;} $j++; } $totA1 = ($totA1 + $A1); $TOTsales = ($TOTsales + $A1); $totA2 = ($totA2 + $A2); $TOTsales = ($TOTsales + $A2); $totTOP = ($totTOP + $A2); $totA3 = ($totA3 + $A3); $TOTsales = ($TOTsales + $A3); $totBOT = ($totBOT + $A3); $totA4 = ($totA4 + $A4); $TOTsales = ($TOTsales + $A4); $totTOP = ($totTOP + $A4); $totBOT = ($totBOT + $A4); $totA5 = ($totA5 + $A5); $totA6 = ($totA6 + $A6); $totA7 = ($totA7 + $A7); $totA8 = ($totA8 + $A8); $totA9 = ($totA9 + $A9); $totDROP = ($totDROP + $DROP); $totOTHER = ($totOTHER + $OTHER); $totPOINTS = ($totPOINTS + $points); if ( ($USERcallsRAW[$i] > 0) and ($sales > 0) ) {$Cpct = ( ($sales / ( ($USERcallsRAW[$i] - 0) - $DROP) ) * 100);} else {$Cpct=0;} $Cpct = round($Cpct, 2); $Cpct = sprintf("%01.2f", $Cpct); $Cpct = sprintf("%6s", $Cpct); if ( ($sales > 0) and ($uTOP > 0) ) {$TOP = ( ($uTOP / $sales) * 100);} else {$TOP=0;} $TOP = round($TOP, 0); $TOP = sprintf("%01.0f", $TOP); $TOP = sprintf("%3s", $TOP); if ( ($sales > 0) and ($uBOT > 0) ) {$BOT = ( ($uBOT / $sales) * 100);} else {$BOT=0;} $BOT = round($BOT, 0); $BOT = sprintf("%01.0f", $BOT); $BOT = sprintf("%3s", $BOT); if ( ($USERcallsRAW[$i] > 0) and ($points > 0) ) {$ppc = ($points / ( ($USERcallsRAW[$i] - 0) - $DROP) );} else {$ppc=0;} $ppc = round($ppc, 2); $ppc = sprintf("%01.2f", $ppc); $ppc = sprintf("%4s", $ppc); if ($USERcalls[$i]>$max_calls) {$max_calls=$USERcalls[$i];} if ($A1>$max_sales) {$max_sales=$A1;} if ($DROP>$max_drops) {$max_drops=$DROP;} if ($OTHER>$max_other) {$max_other=$OTHER;} if ($sales>$max_sales2) {$max_sales2=$sales;} if ($Cpct>$max_conv_pct) {$max_conv_pct=$Cpct;} $graph_stats[$i][0]="$user[$i] - $full_name[$i]"; $graph_stats[$i][1]=$USERcalls[$i]; $graph_stats[$i][2]=$A1; $graph_stats[$i][3]=$DROP; $graph_stats[$i][4]=$OTHER; $graph_stats[$i][5]=$sales; $graph_stats[$i][6]=$Cpct; $A1 = sprintf("%4s", $A1); $A2 = sprintf("%4s", $A2); $A3 = sprintf("%4s", $A3); $A4 = sprintf("%4s", $A4); $A5 = sprintf("%4s", $A5); $A6 = sprintf("%4s", $A6); $A7 = sprintf("%4s", $A7); $A8 = sprintf("%4s", $A8); $A9 = sprintf("%4s", $A9); $DROP = sprintf("%4s", $DROP); $OTHER = sprintf("%4s", $OTHER); $sales = sprintf("%4s", $sales); $ASCII_text.="| $user[$i] - $full_name[$i] | $USERcalls[$i] | $A1 | $DROP | $OTHER | $sales |$Cpct%|\n"; $CSV_closer_lines.="\"$user[$i] - $full_name[$i]\",\"$USERcalls[$i]\",\"$A1\",\"$DROP\",\"$OTHER\",\"$sales\",\"$Cpct%\"\n"; $i++; } if ( ($TOTcalls > 0) and ($TOTsales > 0) ) {$totCpct = ( ($TOTsales / ( ($TOTcalls - 0) - $totDROP) ) * 100);} else {$totCpct=0;} $totCpct = round($totCpct, 2); $totCpct = sprintf("%01.2f", $totCpct); $totCpct = sprintf("%6s", $totCpct); if ( ($TOTcalls > 0) and ($totPOINTS > 0) ) {$ppc = ($totPOINTS / ( ($TOTcalls - $totOTHER) - $totDROP) );} else {$ppc=0;} $ppc = round($ppc, 2); $ppc = sprintf("%01.2f", $ppc); $ppc = sprintf("%4s", $ppc); if ( ($TOTsales > 0) and ($totTOP > 0) ) {$TOP = ( ($totTOP / $TOTsales) * 100);} else {$TOP=0;} $TOP = round($TOP, 0); $TOP = sprintf("%01.0f", $TOP); $TOP = sprintf("%3s", $TOP); if ( ($TOTsales > 0) and ($totBOT > 0) ) {$BOT = ( ($totBOT / $TOTsales) * 100);} else {$BOT=0;} $BOT = round($BOT, 0); $BOT = sprintf("%01.0f", $BOT); $BOT = sprintf("%3s", $BOT); $TOTagents = sprintf("%6s", $i); $TOTcalls = sprintf("%6s", $TOTcalls); $totA1 = sprintf("%5s", $totA1); $totA2 = sprintf("%5s", $totA2); $totA3 = sprintf("%5s", $totA3); $totA4 = sprintf("%5s", $totA4); $totA5 = sprintf("%5s", $totA5); $totA6 = sprintf("%5s", $totA6); $totA7 = sprintf("%5s", $totA7); $totA8 = sprintf("%5s", $totA8); $totA9 = sprintf("%5s", $totA9); $totDROP = sprintf("%5s", $totDROP); $totOTHER = sprintf("%5s", $totOTHER); $TOTsales = sprintf("%5s", $TOTsales); $ASCII_text.="+--------------------------+--------+------+------+------+------+-------+\n"; $ASCII_text.="| TOTAL CLOSERS: $TOTagents | $TOTcalls |$totA1 |$totDROP |$totOTHER |$TOTsales |$totCpct%|\n"; $ASCII_text.="+--------------------------+--------+------+------+------+------+-------+\n"; $CSV_closer_footer.="\"TOTAL CLOSERS: $TOTagents\",\"$TOTcalls\",\"$totA1\",\"$totDROP\",\"$totOTHER\",\"$TOTsales\",\"$totCpct%\"\n"; for ($d=0; $d"; $SALES_graph.=" "; $DROP_graph.=" "; $OTHER_graph.=" "; $SALES2_graph.=" "; $CONVPCT_graph.=" "; } $CALLS_graph.="
CLOSER STATS
AGENTCALLS
SALES
DROP
OTHER
SALES
CONV %
".$graph_stats[$d][1]."
".$graph_stats[$d][0]."".$graph_stats[$d][2]."
".$graph_stats[$d][0]."".$graph_stats[$d][3]."
".$graph_stats[$d][0]."".$graph_stats[$d][4]."
".$graph_stats[$d][0]."".$graph_stats[$d][5]."
".$graph_stats[$d][0]."".$graph_stats[$d][6]."%
TOTAL:".trim($TOTcalls)."
"; $SALES_graph.="TOTAL:".trim($totA1).""; $DROP_graph.="TOTAL:".trim($totDROP).""; $OTHER_graph.="TOTAL:".trim($totOTHER).""; $SALES2_graph.="TOTAL:".trim($TOTsales).""; $CONVPCT_graph.="TOTAL:".trim($totCpct)."%"; $JS_onload.="\tDrawCloserGraph('CALLS', '1');\n"; $JS_text.="function DrawCloserGraph(graph, th_id) {\n"; $JS_text.=" var CALLS_graph=\"$CALLS_graph\";\n"; $JS_text.=" var SALES_graph=\"$SALES_graph\";\n"; $JS_text.=" var DROP_graph=\"$DROP_graph\";\n"; $JS_text.=" var OTHER_graph=\"$OTHER_graph\";\n"; $JS_text.=" var SALES2_graph=\"$SALES2_graph\";\n"; $JS_text.=" var CONVPCT_graph=\"$CONVPCT_graph\";\n"; $JS_text.="\n"; $JS_text.=" for (var i=1; i<=6; i++) {\n"; $JS_text.=" var cellID=\"closergraph\"+i;\n"; $JS_text.=" document.getElementById(cellID).style.backgroundColor='#DDDDDD';\n"; $JS_text.=" }\n"; $JS_text.=" var cellID=\"closergraph\"+th_id;\n"; $JS_text.=" document.getElementById(cellID).style.backgroundColor='#999999';\n"; $JS_text.=" var graph_to_display=eval(graph+\"_graph\");\n"; $JS_text.=" document.getElementById('closer_graph').innerHTML=graph_to_display;\n"; $JS_text.="}\n"; $GRAPH_text.=$GRAPH; $ENDtime = date("U"); $RUNtime = ($ENDtime - $STARTtime); if ($report_display_type=="HTML") { $HTML_text.=$GRAPH_text; } else { $HTML_text.=$ASCII_text; } if ($DB) {$HTML_text.="\nRun Time: $RUNtime seconds|$db_source\n";} $HTML_text.="\n"; $HTML_text.="\n"; $HTML_text.="\n"; if ($file_download > 0) { $FILE_TIME = date("Ymd-His"); $CSVfilename = "FCSTATS_$US$FILE_TIME.csv"; $CSV_text=$CSV_fronter_header.$CSV_fronter_lines.$CSV_fronter_footer.$CSV_closer_header.$CSV_closer_lines.$CSV_closer_footer; $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); $CSV_text=preg_replace('/\" +/', '"', $CSV_text); // We'll be outputting a TXT file header('Content-type: application/octet-stream'); // It will be called LIST_101_20090209-121212.txt header("Content-Disposition: attachment; filename=\"$CSVfilename\""); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); ob_clean(); flush(); echo "$CSV_text"; } else { $JS_onload.="}\n"; $JS_text.=$JS_onload; $JS_text.="\n"; echo $HTML_head; echo $JS_text; require("admin_header.php"); echo $HTML_text; } #$CSV_report=fopen("fcstats.csv", "w"); #$CSV_head=preg_replace('/\s+,/', ',', $CSV_fronter_header.$CSV_fronter_lines.$CSV_fronter_footer.$CSV_closer_header.$CSV_closer_lines.$CSV_closer_footer); #fwrite($CSV_report, $CSV_head); #fclose($CSV_report); if ($db_source == 'S') { mysqli_close($link); $use_slave_server=0; $db_source = 'M'; require("dbconnect_mysqli.php"); } $endMS = microtime(); $startMSary = explode(" ",$startMS); $endMSary = explode(" ",$endMS); $runS = ($endMSary[0] - $startMSary[0]); $runM = ($endMSary[1] - $startMSary[1]); $TOTALrun = ($runS + $runM); $stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; if ($DB) {echo "|$stmt|\n";} $rslt=mysql_to_mysqli($stmt, $link); exit; } ?>