diff --git a/agc_2-X/trunk/www/vicidial/AST_agent_performance_detail_mobile.php b/agc_2-X/trunk/www/vicidial/AST_agent_performance_detail_mobile.php new file mode 100644 index 00000000..8b2939f3 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/AST_agent_performance_detail_mobile.php @@ -0,0 +1,2192 @@ + LICENSE: AGPLv2 +# +# CHANGES +# +# 200318-1122 - First build, based upon AST_agent_performance_detail.php +# + +$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["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} + elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} +if (isset($_GET["query_time"])) {$query_time=$_GET["query_time"];} + elseif (isset($_POST["query_time"])) {$query_time=$_POST["query_time"];} +if (isset($_GET["end_time"])) {$end_time=$_GET["end_time"];} + elseif (isset($_POST["end_time"])) {$end_time=$_POST["end_time"];} +if (isset($_GET["group"])) {$group=$_GET["group"];} + elseif (isset($_POST["group"])) {$group=$_POST["group"];} +if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} + elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} +if (isset($_GET["users"])) {$users=$_GET["users"];} + elseif (isset($_POST["users"])) {$users=$_POST["users"];} +if (isset($_GET["shift"])) {$shift=$_GET["shift"];} + elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} +if (isset($_GET["stage"])) {$stage=$_GET["stage"];} + elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +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 (isset($_GET["live_agents"])) {$live_agents=$_GET["live_agents"];} + elseif (isset($_POST["live_agents"])) {$live_agents=$_POST["live_agents"];} +if (isset($_GET["show_percentages"])) {$show_percentages=$_GET["show_percentages"];} + elseif (isset($_POST["show_percentages"])) {$show_percentages=$_POST["show_percentages"];} +if (isset($_GET["time_in_sec"])) {$time_in_sec=$_GET["time_in_sec"];} + elseif (isset($_POST["time_in_sec"])) {$time_in_sec=$_POST["time_in_sec"];} +if (isset($_GET["breakdown_by_date"])) {$breakdown_by_date=$_GET["breakdown_by_date"];} + elseif (isset($_POST["breakdown_by_date"])) {$breakdown_by_date=$_POST["breakdown_by_date"];} +if (isset($_GET["search_archived_data"])) {$search_archived_data=$_GET["search_archived_data"];} + elseif (isset($_POST["search_archived_data"])) {$search_archived_data=$_POST["search_archived_data"];} +if (isset($_GET["show_defunct_users"])) {$show_defunct_users=$_GET["show_defunct_users"];} + elseif (isset($_POST["show_defunct_users"])) {$show_defunct_users=$_POST["show_defunct_users"];} + +if (strlen($shift)<2) {$shift='--';} +if ($search_archived_data=="checked") {$agent_log_table="vicidial_agent_log_archive";} else {$agent_log_table="vicidial_agent_log";} + +$TIME_HF_agentperfdetail = 'HF'; +$TIME_H_agentperfdetail = 'H'; +$TIME_M_agentperfdetail = 'M'; + +if ($file_download == 1) + { + $TIME_HF_agentperfdetail = 'HF'; + $TIME_H_agentperfdetail = 'HF'; + $TIME_M_agentperfdetail = 'HF'; + } + +if ($time_in_sec) + { + $TIME_HF_agentperfdetail = 'S'; + $TIME_H_agentperfdetail = 'S'; + $TIME_M_agentperfdetail = 'S'; + } + +$report_name = 'Agent Performance Detail'; +$db_source = 'M'; +$JS_text="\n"; +$HTML_head.="\n"; +$HTML_head.="\n"; +require("chart_button.php"); +$HTML_head.="\n"; +$HTML_head.="\n"; +$HTML_head.="\n"; +$HTML_head.= "\n"; + + + +$HTML_head.="\n"; +$HTML_head.="
";
+# $HTML_text.=""._QXZ("$report_name")." $NWB#agent_performance_detail$NWE\n";
+
+$HTML_text.="\n\n";
+
+
+$HTML_text.="";
+
+if (!$group)
+ {
+ $HTML_text.="";
+# $HTML_text.=_QXZ("PLEASE SELECT A CAMPAIGN AND DATE-TIME ABOVE AND CLICK SUBMIT")."\n";
+ $HTML_text.=" "._QXZ("NOTE: stats taken from shift specified")."\n";
+ }
+
+else
+{
+
+$time_BEGIN=$query_time;
+$time_END=$end_time;
+
+if ($shift == 'AM')
+ {
+ $time_BEGIN=$AM_shift_BEGIN;
+ $time_END=$AM_shift_END;
+ if (strlen($time_BEGIN) < 6) {$time_BEGIN = "03:45:00";}
+ if (strlen($time_END) < 6) {$time_END = "15:14:59";}
+ }
+if ($shift == 'PM')
+ {
+ $time_BEGIN=$PM_shift_BEGIN;
+ $time_END=$PM_shift_END;
+ if (strlen($time_BEGIN) < 6) {$time_BEGIN = "15:15:00";}
+ if (strlen($time_END) < 6) {$time_END = "23:15:00";}
+ }
+if ($shift == 'ALL')
+ {
+ $time_BEGIN = "00:00:00";
+ $time_END = "23:59:59";
+ }
+$query_date_BEGIN = "$query_date $time_BEGIN";
+$query_date_END = "$end_date $time_END";
+
+$HTML_text.=_QXZ("Agent Performance Detail",47)." $NOW_TIME\n";
+
+$HTML_text.=_QXZ("Time range").": $query_date_BEGIN "._QXZ("to")." $query_date_END\n\n";
+$HTML_text.="---------- "._QXZ("AGENTS Details")." -------------\n\n";
+
+
+
+$statuses='-';
+$statusesTXT='';
+$statusesHEAD='';
+
+## Breakdown by date text
+if ($breakdown_by_date)
+ {
+ $BBD_header="------------+";
+ $BBD_text=" | "._QXZ("CALL DATE",10);
+ $BBD_filler=" | ".sprintf("%-10s", " ");
+ $BBD_csv=_QXZ("CALL DATE",10)."\",\"";
+ $BBD_csv_filler="\",\"";
+ }
+else
+ {
+ $BBD_header="";
+ $BBD_text="";
+ $BBD_filler="";
+ $BBD_csv="";
+ $BBD_csv_filler="";
+ }
+
+
+$CSV_header="\""._QXZ("Agent Performance Detail",47)." $NOW_TIME\"\n";
+$CSV_header.="\""._QXZ("Time range").": $query_date_BEGIN "._QXZ("to")." $query_date_END\"\n\n";
+$CSV_header.="\"---------- "._QXZ("AGENTS Details")." -------------\"\n";
+if ($show_percentages) {
+ $CSV_header.='"'._QXZ("USER NAME").'","'._QXZ("ID").'","'._QXZ("CURRENT USER GROUP").'","'._QXZ("MOST RECENT USER GROUP").'","'.$BBD_csv._QXZ("CALLS").'","'._QXZ("TIME").'","'._QXZ("PAUSE").'","'._QXZ("PAUSE").' %","'._QXZ("PAUSAVG").'","'._QXZ("WAIT").'","'._QXZ("WAIT").' %","'._QXZ("WAITAVG").'","'._QXZ("TALK").'","'._QXZ("TALK").' %","'._QXZ("TALKAVG").'","'._QXZ("DISPO").'","'._QXZ("DISPO").' %","'._QXZ("DISPAVG").'","'._QXZ("DEAD").'","'._QXZ("DEAD").' %","'._QXZ("DEADAVG").'","'._QXZ("CUSTOMER").'","'._QXZ("CUSTOMER").' %","'._QXZ("CUSTAVG").'"';
+} else {
+ $CSV_header.='"'._QXZ("USER NAME").'","'._QXZ("ID").'","'._QXZ("CURRENT USER GROUP").'","'._QXZ("MOST RECENT USER GROUP").'","'.$BBD_csv._QXZ("CALLS").'","'._QXZ("TIME").'","'._QXZ("PAUSE").'","'._QXZ("PAUSAVG").'","'._QXZ("WAIT").'","'._QXZ("WAITAVG").'","'._QXZ("TALK").'","'._QXZ("TALKAVG").'","'._QXZ("DISPO").'","'._QXZ("DISPAVG").'","'._QXZ("DEAD").'","'._QXZ("DEADAVG").'","'._QXZ("CUSTOMER").'","'._QXZ("CUSTAVG").'"';
+}
+
+
+$statusesHTML='';
+$statusesARY[0]='';
+$j=0;
+$users='-';
+$usersARY[0]='';
+$user_namesARY[0]='';
+$k=0;
+
+$live_agents_ary=array();
+$live_user_SQL="";
+$live_user_SQLvu="";
+if ($live_agents) {
+ $active_stmt="SELECT user from vicidial_live_agents";
+ $active_rslt=mysql_to_mysqli($active_stmt, $link);
+ while($active_row=mysqli_fetch_row($active_rslt)) {
+ array_push($live_agents_ary, "$active_row[0]");
+ }
+ $live_user_SQL=" and user in ('".implode("','", $live_agents_ary)."') ";
+ $live_user_SQLvu=" and vicidial_users.user in ('".implode("','", $live_agents_ary)."') ";
+}
+
+$recent_UG_stmt="SELECT max(agent_log_id), user from ".$agent_log_table." where event_time <= '$query_date_END' and event_time >= '$query_date_BEGIN' and pause_sec<65000 and wait_sec<65000 and talk_sec<65000 and dispo_sec<65000 $group_SQL $user_group_agent_log_SQL $user_agent_log_SQL group by user";
+if ($DB) {$HTML_text.="$recent_UG_stmt\n";}
+$recent_UG_rslt=mysql_to_mysqli($recent_UG_stmt, $link);
+while ($UG_row=mysqli_fetch_row($recent_UG_rslt)) {
+ $agent_log_id=$UG_row[0];
+ $al_stmt="SELECT user_group from ".$agent_log_table." where agent_log_id='$agent_log_id'";
+ if ($DB) {$HTML_text.="$al_stmt\n";}
+ $al_rslt=mysql_to_mysqli($al_stmt, $link);
+ $Ugrp_row=mysqli_fetch_row($al_rslt);
+ $recent_user_groups[$UG_row[1]]=$Ugrp_row[0];
+}
+
+$graph_stats=array();
+$max_calls=1;
+$max_time=1;
+$max_pause=1;
+$max_pauseavg=1;
+$max_wait=1;
+$max_waitavg=1;
+$max_talk=1;
+$max_talkavg=1;
+$max_dispo=1;
+$max_dispoavg=1;
+$max_dead=1;
+$max_deadavg=1;
+$max_customer=1;
+$max_customeravg=1;
+
+ if ($show_defunct_users=="checked")
+ {
+ $user_stmt="SELECT distinct '' as full_name, user from ".$agent_log_table." where event_time <= '$query_date_END' and event_time >= '$query_date_BEGIN' $live_user_SQL $group_SQL $user_agent_log_SQL order by user asc";
+ }
+ else
+ {
+ $user_stmt="SELECT distinct full_name,vicidial_users.user,vicidial_users.user_group from vicidial_users,".$agent_log_table." where event_time <= '$query_date_END' and event_time >= '$query_date_BEGIN' and vicidial_users.user=".$agent_log_table.".user $live_user_SQLvu $group_SQL $user_group_SQL $user_agent_log_SQL order by full_name asc";
+ }
+ if ($DB) {echo "$user_stmt\n";}
+ $user_rslt=mysql_to_mysqli($user_stmt, $link);
+ $q=0;
+ while($q | $Sstatus | "; + $max_varname="max_".$Sstatus; + ### BEGIN loop through each stat line ### + $i=0; $status_found=0; + while ($i < $subs_to_print) + { + if ( ($Suser=="$PCuser[$i]") and ($Sstatus=="$sub_status[$i]") ) + { + $Spause_sec = ($Spause_sec + $PCpause_sec[$i]); + $Snon_pause_sec = ($Snon_pause_sec + $PCnon_pause_sec[$i]); + $Stotal_sec = ($Stotal_sec + $PCnon_pause_sec[$i] + $PCpause_sec[$i]); + + $USERcodePAUSE_MS = sec_convert($PCpause_sec[$i],$TIME_H_agentperfdetail); + $pfUSERcodePAUSE_MS = sprintf("%6s", $USERcodePAUSE_MS); + + $SstatusTXT = sprintf("%8s", $pfUSERcodePAUSE_MS); + $SstatusesHTML .= " $SstatusTXT |"; + + if ($PCpause_sec[$i]>$$max_varname) {$$max_varname=$PCpause_sec[$i];} + $graph_stats[$m][(4+$n)]=$PCpause_sec[$i]; + + $CSV_statuses.=",\"$USERcodePAUSE_MS\""; + $status_found++; + } + $i++; + } + if ($status_found < 1) + { + $SstatusesHTML .= " 0:00 |"; + $CSV_statuses.=",\"0:00:00\""; + $graph_stats[$m][(4+$n)]=0; + } + ### END loop through each stat line ### + $n++; + } + ### END loop through each status ### + $TOTtotPAUSE=($TOTtotPAUSE + $Spause_sec); + $Sfull_nameRAW = $Sfull_name; + $SuserRAW = $Suser; + $graph_stats[$m][0]="$Sfull_name - $SuserRAW"; + + if ($non_latin < 1) + { + $Sfull_name= sprintf("%-15s", $Sfull_name); + while(strlen($Sfull_name)>15) {$Sfull_name = substr("$Sfull_name", 0, -1);} + $Suser_group= sprintf("%-20s", $Suser_group); + while(strlen($Suser_group)>20) {$Suser_group = substr("$Suser_group", 0, -1);} + $Slast_user_group= sprintf("%-20s", $Slast_user_group); + while(strlen($Slast_user_group)>20) {$Slast_user_group = substr("$Slast_user_group", 0, -1);} + $Suser = sprintf("%-8s", $Suser); + while(strlen($Suser)>8) {$Suser = substr("$Suser", 0, -1);} + } + else + { + $Sfull_name= sprintf("%-45s", $Sfull_name); + while(mb_strlen($Sfull_name,'utf-8')>15) {$Sfull_name = mb_substr("$Sfull_name", 0, -1,'utf-8');} + $Suser_group= sprintf("%-60s", $Suser_group); + while(mb_strlen($Suser_group,'utf-8')>20) {$Suser_group = mb_substr("$Suser_group", 0, -1,'utf-8');} + $Slast_user_group= sprintf("%-60s", $Slast_user_group); + while(mb_strlen($Slast_user_group,'utf-8')>20) {$Slast_user_group = mb_substr("$Slast_user_group", 0, -1,'utf-8');} + $Suser = sprintf("%-24s", $Suser); + while(mb_strlen($Suser,'utf-8')>8) {$Suser = mb_substr("$Suser", 0, -1,'utf-8');} + } + + $TOTtotNONPAUSE = ($TOTtotNONPAUSE + $Snon_pause_sec); + $TOTtotTOTAL = ($TOTtotTOTAL + $Stotal_sec); + + if (trim($Stotal_sec)>$max_total) {$max_total=trim($Stotal_sec);} + if (trim($Snon_pause_sec)>$max_nonpause) {$max_nonpause=trim($Snon_pause_sec);} + if (trim($Spause_sec)>$max_pause) {$max_pause=trim($Spause_sec);} + $graph_stats[$m][1]="$Stotal_sec"; + $graph_stats[$m][2]="$Snon_pause_sec"; + $graph_stats[$m][3]="$Spause_sec"; + + $USERtotPAUSE_MS = sec_convert($Spause_sec,$TIME_H_agentperfdetail); + $USERtotNONPAUSE_MS = sec_convert($Snon_pause_sec,$TIME_H_agentperfdetail); + $USERtotTOTAL_MS = sec_convert($Stotal_sec,$TIME_H_agentperfdetail); + + $pfUSERtotPAUSE_MS = sprintf("%8s", $USERtotPAUSE_MS); + $pfUSERtotNONPAUSE_MS = sprintf("%8s", $USERtotNONPAUSE_MS); + $pfUSERtotTOTAL_MS = sprintf("%10s", $USERtotTOTAL_MS); + + $BOTTOMoutput = "| $Sfull_name | $Suser | $Suser_group | $Slast_user_group | $pfUSERtotTOTAL_MS | $pfUSERtotNONPAUSE_MS | $pfUSERtotPAUSE_MS | |$SstatusesHTML\n"; + + $BOTTOMsorted_output[$m] = $BOTTOMoutput; + + $ASCII_text.="$BOTTOMoutput"; + $CSV_lines.="\"$Sfull_nameRAW\"".preg_replace('/\s/', '', ",\"$SuserRAW\",\"$Suser_group\",\"$Slast_user_group\",\"$pfUSERtotTOTAL_MS\",\"$pfUSERtotNONPAUSE_MS\",\"$pfUSERtotPAUSE_MS\",$CSV_statuses"); + $CSV_lines.="\n"; + $m++; + } +### END loop through each user ### + + + +### BEGIN sort through output to display properly ### +#if (preg_match('/ID|TIME|LEADS/',$stage)) +# { +# $n=0; +# while ($n <= $m) +# { +# $i = $sort_order[$m]; +# echo "$BOTTOMsorted_output[$i]"; +# $m--; +# } +# } +### END sort through output to display properly ### + + + +###### LAST LINE FORMATTING ########## +### BEGIN loop through each status ### +$SUMstatusesHTML=''; +$CSVSUMstatuses=''; +$TOTtotPAUSE=0; +$n=0; +while ($n < $j) + { + $Scalls=0; + $Sstatus=$sub_statusesARY[$n]; + $SUMstatusTXT=''; + $total_var=$Sstatus."_total"; + ### BEGIN loop through each stat line ### + $i=0; $status_found=0; + while ($i < $subs_to_print) + { + if ($Sstatus=="$sub_status[$i]") + { + $Scalls = ($Scalls + $PCpause_sec[$i]); + $status_found++; + } + $i++; + } + ### END loop through each stat line ### + if ($status_found < 1) + { + $SUMstatusesHTML .= " 0 |"; + $$total_var=0; + } + else + { + $TOTtotPAUSE = ($TOTtotPAUSE + $Scalls); + $$total_var=$Scalls; + + $USERsumstatPAUSE_MS = sec_convert($Scalls,$TIME_H_agentperfdetail); + $pfUSERsumstatPAUSE_MS = sprintf("%8s", $USERsumstatPAUSE_MS); + + $SUMstatusTXT = sprintf("%8s", $pfUSERsumstatPAUSE_MS); + $SUMstatusesHTML .= " $SUMstatusTXT |"; + $CSVSUMstatuses.=",\"$USERsumstatPAUSE_MS\""; + } + $n++; + } +### END loop through each status ### + + $TOT_AGENTS = sprintf("%-4s", $m); + + $TOTtotPAUSE_MS = sec_convert($TOTtotPAUSE,$TIME_H_agentperfdetail); + $TOTtotNONPAUSE_MS = sec_convert($TOTtotNONPAUSE,$TIME_H_agentperfdetail); + $TOTtotTOTAL_MS = sec_convert($TOTtotTOTAL,$TIME_H_agentperfdetail); + + $TOTtotPAUSE_MS = sprintf("%10s", $TOTtotPAUSE_MS); + $TOTtotNONPAUSE_MS = sprintf("%10s", $TOTtotNONPAUSE_MS); + $TOTtotTOTAL_MS = sprintf("%12s", $TOTtotTOTAL_MS); + + if ($file_download == 0 || !$file_download) + { + while(strlen($TOTtotPAUSE_MS)>10) {$TOTtotPAUSE_MS = substr("$TOTtotPAUSE_MS", 0, -1);} + while(strlen($TOTtotNONPAUSE_MS)>10) {$TOTtotNONPAUSE_MS = substr("$TOTtotNONPAUSE_MS", 0, -1);} + while(strlen($TOTtotTOTAL_MS)>12) {$TOTtotTOTAL_MS = substr("$TOTtotTOTAL_MS", 0, -1);} + } + +$ASCII_text.="+-----------------+----------+----------------------+----------------------+------------+----------+----------+ +$sub_statusesHEAD\n"; +$ASCII_text.="| "._QXZ("TOTALS",33)." "._QXZ("AGENTS",32,"r").":$TOT_AGENTS |$TOTtotTOTAL_MS|$TOTtotNONPAUSE_MS|$TOTtotPAUSE_MS| |$SUMstatusesHTML\n"; +$ASCII_text.="+-----------------+----------+----------------------+----------------------+------------+----------+----------+ +$sub_statusesHEAD\n"; + +# USE THIS FOR COMBINED graphs, use pipe-delimited array elements, dataset_name|index|link_name|graph_override +# You have to hard code the graph name in where it is overridden and mind the data indices. No other way to do it. +$multigraph_text=""; +$graph_id++; +$graph_array=array("APD_TOTALdata|1|TOTAL|time|", "APD_NONPAUSEdata|2|NONPAUSE|time|", "APD_PAUSEdata|3|PAUSE|time|"); + +for ($e=0; $e
|---|