";
$HTML_text.="\n\n";
$HTML_text.="\n";
if (!$group)
{
$HTML_text.="\n";
$HTML_text.="PLEASE SELECT A CAMPAIGN AND DATE-TIME ABOVE AND CLICK SUBMIT\n";
$HTML_text.=" NOTE: stats taken from shift specified\n";
}
else
{
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')
{
if (strlen($time_BEGIN) < 6) {$time_BEGIN = "00:00:00";}
if (strlen($time_END) < 6) {$time_END = "23:59:59";}
}
$query_date_BEGIN = "$query_date $time_BEGIN";
$query_date_END = "$end_date $time_END";
$HTML_text.="Agent Performance Detail $NOW_TIME\n";
$HTML_text.="Time range: $query_date_BEGIN to $query_date_END\n\n";
$HTML_text.="---------- AGENTS Details -------------\n\n";
### BEGIN gather all statuses that are in status flags ###
$sale_statuses='';
$sale_pattern_match="|";
$stmt="select status from vicidial_statuses where sale='Y' UNION select status from vicidial_campaign_statuses where sale='Y' and selectable IN('Y','N') $group_SQLand;";
if ($DB) {$HTML_text.="$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$statha_to_print = mysqli_num_rows($rslt);
$i=0;
while ($i < $statha_to_print)
{
$row=mysqli_fetch_row($rslt);
$temp_status=$row[0];
$sale_statuses .= "'$temp_status',";
$sale_pattern_match .= "$temp_status|";
$i++;
}
if ($DB) {$HTML_text.="$sale_pattern_match\n";}
$statuses='-';
$statusesTXT='';
$statusesHEAD='';
$CSV_header="\"Agent Performance Detail $NOW_TIME\"\n";
$CSV_header.="\"Time range: $query_date_BEGIN to $query_date_END\"\n\n";
$CSV_header.="\"---------- AGENTS Details -------------\"\n";
$CSV_header.='"USER NAME","ID","CURRENT USER GROUP","MOST RECENT USER GROUP","SALES/CALLS %","SALES PER HOUR","TOTAL SALES","CALLS","TIME","PAUSE","PAUSAVG","WAIT","WAITAVG","TALK","TALKAVG","DISPO","DISPAVG","DEAD","DEADAVG","CUSTOMER","CUSTAVG"';
$statusesHTML='';
$statusesARY[0]='';
$j=0;
$users='-';
$usersARY[0]='';
$user_namesARY[0]='';
$k=0;
$recent_UG_stmt="select max(agent_log_id), user from vicidial_agent_log 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 vicidial_agent_log 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];
}
$stmt="select count(*) as calls,sum(talk_sec) as talk,full_name,vicidial_users.user,sum(pause_sec),sum(wait_sec),sum(dispo_sec),status,sum(dead_sec), vicidial_users.user_group from vicidial_users,vicidial_agent_log where event_time <= '$query_date_END' and event_time >= '$query_date_BEGIN' and vicidial_users.user=vicidial_agent_log.user and pause_sec<65000 and wait_sec<65000 and talk_sec<65000 and dispo_sec<65000 $group_SQL $user_group_SQL $user_SQL group by user,full_name,user_group,status order by full_name,user,status desc limit 500000;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {$HTML_text.="$stmt\n";}
$rows_to_print = mysqli_num_rows($rslt);
$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;
$GRAPH="
";
$GRAPH2="| CALLS | TIME | PAUSE | PAUSE AVG | WAIT | WAIT AVG | TALK | TALK AVG | DISPO | DISPO AVG | DEAD | DEAD AVG | CUST | CUST AVG | ";
$graph_header="CALL STATS BREAKDOWN: (Statistics related to handling of calls only)| USER | ";
$CALLS_graph=$graph_header."CALLS | ";
$TIME_graph=$graph_header."TIME | ";
$PAUSE_graph=$graph_header."PAUSE | ";
$PAUSEAVG_graph=$graph_header."PAUSE AVG | ";
$WAIT_graph=$graph_header."WAIT | ";
$WAITAVG_graph=$graph_header."WAIT AVG | ";
$TALK_graph=$graph_header."TALK | ";
$TALKAVG_graph=$graph_header."TALK AVG | ";
$DISPO_graph=$graph_header."DISPO | ";
$DISPOAVG_graph=$graph_header."DISPO AVG | ";
$DEAD_graph=$graph_header."DEAD | ";
$DEADAVG_graph=$graph_header."DEAD AVG | ";
$CUST_graph=$graph_header."CUST | ";
$CUSTAVG_graph=$graph_header."CUST AVG | ";
$i=0;
while ($i < $rows_to_print)
{
$row=mysqli_fetch_row($rslt);
# $row[0] = ($row[0] - 1); # subtract 1 for login/logout event compensation
$calls[$i] = $row[0];
$talk_sec[$i] = $row[1];
$full_name[$i] = $row[2];
$user[$i] = $row[3];
$pause_sec[$i] = $row[4];
$wait_sec[$i] = $row[5];
$dispo_sec[$i] = $row[6];
$status[$i] = strtoupper($row[7]);
$dead_sec[$i] = $row[8];
$user_group[$i] = $row[9];
$customer_sec[$i] = ($talk_sec[$i] - $dead_sec[$i]);
if (preg_match("/\|$status[$i]\|/i", $sale_pattern_match)) {
$sale_counts[$row[3]]+=$row[0];
}
$max_varname="max_".$status[$i];
$$max_varname=1;
if ($customer_sec[$i] < 1)
{$customer_sec[$i]=0;}
if ( (!preg_match("/\-$status[$i]\-/i", $statuses)) and (strlen($status[$i])>0) )
{
if (preg_match("/\|$status[$i]\|/i", $sale_pattern_match))
{
$statusesTXT = sprintf("%8s", $status[$i]);
$statusesHEAD .= "----------+";
$statusesHTML .= " $statusesTXT |";
$CSV_header.=",\"$status[$i]\"";
}
$statuses .= "$status[$i]-";
$statusesARY[$j] = $status[$i];
$j++;
}
if (!preg_match("/\-$user[$i]\-/i", $users))
{
$users .= "$user[$i]-";
$usersARY[$k] = $user[$i];
$user_namesARY[$k] = $full_name[$i];
$user_groupsARY[$k] = $user_group[$i];
$k++;
}
$i++;
}
$CSV_header.="\n";
$CSV_lines='';
$ASCII_text.="CALL STATS BREAKDOWN: (Statistics related to handling of calls only) [DOWNLOAD]\n";
$ASCII_text.="+-----------------+----------+----------------------+----------------------+---------------+----------------+-------------+--------+-----------+----------+--------+----------+--------+----------+--------+----------+--------+----------+--------+----------+--------+$statusesHEAD\n";
$ASCII_text.="| USER NAME | ID | CURRENT USER GROUP | MOST RECENT USER GRP | SALES/CALLS % | SALES PER HOUR | TOTAL SALES | CALLS | TIME | PAUSE |PAUSAVG | WAIT |WAITAVG | TALK |TALKAVG | DISPO |DISPAVG | DEAD |DEADAVG | CUSTOMER |CUSTAVG |$statusesHTML\n";
$ASCII_text.="+-----------------+----------+----------------------+----------------------+---------------+----------------+-------------+--------+-----------+----------+--------+----------+--------+----------+--------+----------+--------+----------+--------+----------+--------+$statusesHEAD\n";
### BEGIN loop through each user ###
$m=0;
while ($m < $k)
{
$Suser=$usersARY[$m];
$Slast_user_group=$recent_user_groups[$Suser];
# $recent_UG_stmt="select max(event_time) as most_recent_event, user_group from vicidial_agent_log where user='$Suser' and 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 group by user_group order by most_recent_event desc limit 1";
# 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)) {
# $Slast_user_group=$UG_row[1];
# $recent_user_groups[$Suser]=$UG_row[1];
# }
$Sfull_name=$user_namesARY[$m];
$Suser_group=$user_groupsARY[$m];
$Stotal_sales=$sale_counts[$Suser]+0;
$Sgrand_total_sales+=$Stotal_sales;
$Stime=0;
$Scalls=0;
$Stalk_sec=0;
$Spause_sec=0;
$Swait_sec=0;
$Sdispo_sec=0;
$Sdead_sec=0;
$Scustomer_sec=0;
$SstatusesHTML='';
$CSVstatuses='';
### BEGIN loop through each status ###
$n=0;
while ($n < $j)
{
$Sstatus=$statusesARY[$n];
$SstatusTXT='';
$varname=$Sstatus."_graph";
$$varname=$graph_header."$Sstatus | ";
$max_varname="max_".$Sstatus;
### BEGIN loop through each stat line ###
$i=0; $status_found=0;
while ($i < $rows_to_print)
{
if ( ($Suser=="$user[$i]") and ($Sstatus=="$status[$i]") )
{
$Scalls = ($Scalls + $calls[$i]);
$Stalk_sec = ($Stalk_sec + $talk_sec[$i]);
$Spause_sec = ($Spause_sec + $pause_sec[$i]);
$Swait_sec = ($Swait_sec + $wait_sec[$i]);
$Sdispo_sec = ($Sdispo_sec + $dispo_sec[$i]);
$Sdead_sec = ($Sdead_sec + $dead_sec[$i]);
$Scustomer_sec = ($Scustomer_sec + $customer_sec[$i]);
if (preg_match("/\|$Sstatus\|/i", $sale_pattern_match))
{
$SstatusTXT = sprintf("%8s", $calls[$i]);
$SstatusesHTML .= " $SstatusTXT |";
$CSVstatuses.=",\"$calls[$i]\"";
}
if ($calls[$i]>$$max_varname) {$$max_varname=$calls[$i];}
$graph_stats[$m][(15+$n)]=($calls[$i]+0);
$status_found++;
}
$i++;
}
if ($status_found < 1 and preg_match("/\|$Sstatus\|/i", $sale_pattern_match))
{
$SstatusesHTML .= " 0 |";
$CSVstatuses.=",\"0\"";
$graph_stats[$m][(15+$n)]=0;
}
### END loop through each stat line ###
$n++;
}
### END loop through each status ###
$Stime = ($Stalk_sec + $Spause_sec + $Swait_sec + $Sdispo_sec);
$TOTcalls=($TOTcalls + $Scalls);
$TOTtime=($TOTtime + $Stime);
$TOTtotTALK=($TOTtotTALK + $Stalk_sec);
$TOTtotWAIT=($TOTtotWAIT + $Swait_sec);
$TOTtotPAUSE=($TOTtotPAUSE + $Spause_sec);
$TOTtotDISPO=($TOTtotDISPO + $Sdispo_sec);
$TOTtotDEAD=($TOTtotDEAD + $Sdead_sec);
$TOTtotCUSTOMER=($TOTtotCUSTOMER + $Scustomer_sec);
$Stime = ($Stalk_sec + $Spause_sec + $Swait_sec + $Sdispo_sec);
if ( ($Scalls > 0) and ($Stalk_sec > 0) ) {$Stalk_avg = ($Stalk_sec/$Scalls);}
else {$Stalk_avg=0;}
if ( ($Scalls > 0) and ($Spause_sec > 0) ) {$Spause_avg = ($Spause_sec/$Scalls);}
else {$Spause_avg=0;}
if ( ($Scalls > 0) and ($Swait_sec > 0) ) {$Swait_avg = ($Swait_sec/$Scalls);}
else {$Swait_avg=0;}
if ( ($Scalls > 0) and ($Sdispo_sec > 0) ) {$Sdispo_avg = ($Sdispo_sec/$Scalls);}
else {$Sdispo_avg=0;}
if ( ($Scalls > 0) and ($Sdead_sec > 0) ) {$Sdead_avg = ($Sdead_sec/$Scalls);}
else {$Sdead_avg=0;}
if ( ($Scalls > 0) and ($Scustomer_sec > 0) ) {$Scustomer_avg = ($Scustomer_sec/$Scalls);}
else {$Scustomer_avg=0;}
$RAWuser = $Suser;
$RAWcalls = $Scalls;
$Scalls = sprintf("%6s", $Scalls);
$Sfull_nameRAW = $Sfull_name;
$SuserRAW = $Suser;
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("%-45s", $Suser_group);
while(mb_strlen($Suser_group,'utf-8')>15) {$Suser_group = mb_substr("$Suser_group", 0, -1,'utf-8');}
$Suser = sprintf("%-24s", $Suser);
while(mb_strlen($Suser,'utf-8')>8) {$Suser = mb_substr("$Suser", 0, -1,'utf-8');}
}
if (trim($Scalls)>$max_calls) {$max_calls=trim($Scalls);}
if (trim($Stime)>$max_time) {$max_time=trim($Stime);}
if (trim($Spause_sec)>$max_pause) {$max_pause=trim($Spause_sec);}
if (trim($Spause_avg)>$max_pauseavg) {$max_pauseavg=trim($Spause_avg);}
if (trim($Swait_sec)>$max_wait) {$max_wait=trim($Swait_sec);}
if (trim($Swait_avg)>$max_waitavg) {$max_waitavg=trim($Swait_avg);}
if (trim($Stalk_sec)>$max_talk) {$max_talk=trim($Stalk_sec);}
if (trim($Stalk_avg)>$max_talkavg) {$max_talkavg=trim($Stalk_avg);}
if (trim($Sdispo_sec)>$max_dispo) {$max_dispo=trim($Sdispo_sec);}
if (trim($Sdispo_avg)>$max_dispoavg) {$max_dispoavg=trim($Sdispo_avg);}
if (trim($Sdead_sec)>$max_dead) {$max_dead=trim($Sdead_sec);}
if (trim($Sdead_avg)>$max_deadavg) {$max_deadavg=trim($Sdead_avg);}
if (trim($Scustomer_sec)>$max_customer) {$max_customer=trim($Scustomer_sec);}
if (trim($Scustomer_avg)>$max_customeravg) {$max_customeravg=trim($Scustomer_avg);}
$graph_stats[$m][0]=trim($Sfull_name)." - ".trim($Suser);
$graph_stats[$m][1]=trim($Scalls);
$graph_stats[$m][2]=trim($Stime);
$graph_stats[$m][3]=trim($Spause_sec);
$graph_stats[$m][4]=trim($Spause_avg);
$graph_stats[$m][5]=trim($Swait_sec);
$graph_stats[$m][6]=trim($Swait_avg);
$graph_stats[$m][7]=trim($Stalk_sec);
$graph_stats[$m][8]=trim($Stalk_avg);
$graph_stats[$m][9]=trim($Sdispo_sec);
$graph_stats[$m][10]=trim($Sdispo_avg);
$graph_stats[$m][11]=trim($Sdead_sec);
$graph_stats[$m][12]=trim($Sdead_avg);
$graph_stats[$m][13]=trim($Scustomer_sec);
$graph_stats[$m][14]=trim($Scustomer_avg);
$pfUSERtime_MS = sec_convert($Stime,'H');
$pfUSERtotTALK_MS = sec_convert($Stalk_sec,'H');
$pfUSERavgTALK_MS = sec_convert($Stalk_avg,'M');
$USERtotPAUSE_MS = sec_convert($Spause_sec,'H');
$USERavgPAUSE_MS = sec_convert($Spause_avg,'M');
$USERtotWAIT_MS = sec_convert($Swait_sec,'H');
$USERavgWAIT_MS = sec_convert($Swait_avg,'M');
$USERtotDISPO_MS = sec_convert($Sdispo_sec,'H');
$USERavgDISPO_MS = sec_convert($Sdispo_avg,'M');
$USERtotDEAD_MS = sec_convert($Sdead_sec,'H');
$USERavgDEAD_MS = sec_convert($Sdead_avg,'M');
$USERtotCUSTOMER_MS = sec_convert($Scustomer_sec,'H');
$USERavgCUSTOMER_MS = sec_convert($Scustomer_avg,'M');
$pfUSERtime_MS = sprintf("%9s", $pfUSERtime_MS);
$pfUSERtotTALK_MS = sprintf("%8s", $pfUSERtotTALK_MS);
$pfUSERavgTALK_MS = sprintf("%6s", $pfUSERavgTALK_MS);
$pfUSERtotPAUSE_MS = sprintf("%8s", $USERtotPAUSE_MS);
$pfUSERavgPAUSE_MS = sprintf("%6s", $USERavgPAUSE_MS);
$pfUSERtotWAIT_MS = sprintf("%8s", $USERtotWAIT_MS);
$pfUSERavgWAIT_MS = sprintf("%6s", $USERavgWAIT_MS);
$pfUSERtotDISPO_MS = sprintf("%8s", $USERtotDISPO_MS);
$pfUSERavgDISPO_MS = sprintf("%6s", $USERavgDISPO_MS);
$pfUSERtotDEAD_MS = sprintf("%8s", $USERtotDEAD_MS);
$pfUSERavgDEAD_MS = sprintf("%6s", $USERavgDEAD_MS);
$pfUSERtotCUSTOMER_MS = sprintf("%8s", $USERtotCUSTOMER_MS);
$pfUSERavgCUSTOMER_MS = sprintf("%6s", $USERavgCUSTOMER_MS);
$PAUSEtotal[$m] = $pfUSERtotPAUSE_MS;
$total_hours=($Stime/3600);
$Ssales_per_call=sprintf("%.2f", (100*($Stotal_sales/$Scalls)))." %";
$Ssales_per_hour=sprintf("%.2f", ($Stotal_sales/$total_hours));
$Ssales_per_call=sprintf("%13s", $Ssales_per_call);
$Ssales_per_hour=sprintf("%14s", $Ssales_per_hour);
$Stotal_sales=sprintf("%11s", $Stotal_sales);
$Toutput = "| $Sfull_name | $Suser | $Suser_group | $Slast_user_group | $Ssales_per_call | $Ssales_per_hour | $Stotal_sales | $Scalls | $pfUSERtime_MS | $pfUSERtotPAUSE_MS | $pfUSERavgPAUSE_MS | $pfUSERtotWAIT_MS | $pfUSERavgWAIT_MS | $pfUSERtotTALK_MS | $pfUSERavgTALK_MS | $pfUSERtotDISPO_MS | $pfUSERavgDISPO_MS | $pfUSERtotDEAD_MS | $pfUSERavgDEAD_MS | $pfUSERtotCUSTOMER_MS | $pfUSERavgCUSTOMER_MS |$SstatusesHTML\n";
$CSV_lines.="\"$Sfull_nameRAW\",";
$CSV_lines.=preg_replace('/\s/', '', "\"$SuserRAW\",\"$Suser_group\",\"$Slast_user_group\",\"$Ssales_per_call\",\"$Ssales_per_hour\",\"$Stotal_sales\",\"$Scalls\",\"$pfUSERtime_MS\",\"$pfUSERtotPAUSE_MS\",\"$pfUSERavgPAUSE_MS\",\"$pfUSERtotWAIT_MS\",\"$pfUSERavgWAIT_MS\",\"$pfUSERtotTALK_MS\",\"$pfUSERavgTALK_MS\",\"$pfUSERtotDISPO_MS\",\"$pfUSERavgDISPO_MS\",\"$pfUSERtotDEAD_MS\",\"$pfUSERavgDEAD_MS\",\"$pfUSERtotCUSTOMER_MS\",\"$pfUSERavgCUSTOMER_MS\"$CSVstatuses");
$CSV_lines.="\n";
$TOPsorted_output[$m] = $Toutput;
if ($stage == 'ID')
{$TOPsort[$m] = '' . sprintf("%08s", $RAWuser) . '-----' . $m . '-----' . sprintf("%020s", $RAWuser);}
if ($stage == 'LEADS')
{$TOPsort[$m] = '' . sprintf("%08s", $RAWcalls) . '-----' . $m . '-----' . sprintf("%020s", $RAWuser);}
if ($stage == 'TIME')
{$TOPsort[$m] = '' . sprintf("%08s", $Stime) . '-----' . $m . '-----' . sprintf("%020s", $RAWuser);}
if (!preg_match('/ID|TIME|LEADS/',$stage))
{$ASCII_text.="$Toutput";}
$m++;
}
### END loop through each user ###
### BEGIN sort through output to display properly ###
if (preg_match('/ID|TIME|LEADS/',$stage))
{
if (preg_match('/ID/',$stage))
{sort($TOPsort, SORT_NUMERIC);}
if (preg_match('/TIME|LEADS/',$stage))
{rsort($TOPsort, SORT_NUMERIC);}
$m=0;
while ($m < $k)
{
$sort_split = explode("-----",$TOPsort[$m]);
$i = $sort_split[1];
$sort_order[$m] = "$i";
$ASCII_text.="$TOPsorted_output[$i]";
$m++;
}
}
### END sort through output to display properly ###
###### LAST LINE FORMATTING ##########
### BEGIN loop through each status ###
$SUMstatusesHTML='';
$CSVSUMstatuses='';
$n=0;
while ($n < $j)
{
$Scalls=0;
$Sstatus=$statusesARY[$n];
$SUMstatusTXT='';
$total_var=$Sstatus."_total";
### BEGIN loop through each stat line ###
$i=0; $status_found=0;
while ($i < $rows_to_print)
{
if ($Sstatus=="$status[$i]")
{
$Scalls = ($Scalls + $calls[$i]);
$status_found++;
}
$i++;
}
### END loop through each stat line ###
if (preg_match("/\|$Sstatus\|/i", $sale_pattern_match))
{
if ($status_found < 1)
{
$SUMstatusesHTML .= " 0 |";
$$total_var=0;
}
else
{
$SUMstatusTXT = sprintf("%8s", $Scalls);
$SUMstatusesHTML .= " $SUMstatusTXT |";
$CSVSUMstatuses.=",\"$Scalls\"";
$$total_var=$Scalls;
}
}
$n++;
}
### END loop through each status ###
$TOTcalls = sprintf("%7s", $TOTcalls);
$TOT_AGENTS = sprintf("%-4s", $m);
if ($TOTtotTALK < 1) {$TOTavgTALK = '0';}
else {$TOTavgTALK = ($TOTtotTALK / $TOTcalls);}
if ($TOTtotDISPO < 1) {$TOTavgDISPO = '0';}
else {$TOTavgDISPO = ($TOTtotDISPO / $TOTcalls);}
if ($TOTtotDEAD < 1) {$TOTavgDEAD = '0';}
else {$TOTavgDEAD = ($TOTtotDEAD / $TOTcalls);}
if ($TOTtotPAUSE < 1) {$TOTavgPAUSE = '0';}
else {$TOTavgPAUSE = ($TOTtotPAUSE / $TOTcalls);}
if ($TOTtotWAIT < 1) {$TOTavgWAIT = '0';}
else {$TOTavgWAIT = ($TOTtotWAIT / $TOTcalls);}
if ($TOTtotCUSTOMER < 1) {$TOTavgCUSTOMER = '0';}
else {$TOTavgCUSTOMER = ($TOTtotCUSTOMER / $TOTcalls);}
$TOTtime_MS = sec_convert($TOTtime,'H');
$TOTtotTALK_MS = sec_convert($TOTtotTALK,'H');
$TOTtotDISPO_MS = sec_convert($TOTtotDISPO,'H');
$TOTtotDEAD_MS = sec_convert($TOTtotDEAD,'H');
$TOTtotPAUSE_MS = sec_convert($TOTtotPAUSE,'H');
$TOTtotWAIT_MS = sec_convert($TOTtotWAIT,'H');
$TOTtotCUSTOMER_MS = sec_convert($TOTtotCUSTOMER,'H');
$TOTavgTALK_MS = sec_convert($TOTavgTALK,'M');
$TOTavgDISPO_MS = sec_convert($TOTavgDISPO,'H');
$TOTavgDEAD_MS = sec_convert($TOTavgDEAD,'H');
$TOTavgPAUSE_MS = sec_convert($TOTavgPAUSE,'H');
$TOTavgWAIT_MS = sec_convert($TOTavgWAIT,'H');
$TOTavgCUSTOMER_MS = sec_convert($TOTavgCUSTOMER,'H');
$TOTtime_MS = sprintf("%10s", $TOTtime_MS);
$TOTtotTALK_MS = sprintf("%10s", $TOTtotTALK_MS);
$TOTtotDISPO_MS = sprintf("%10s", $TOTtotDISPO_MS);
$TOTtotDEAD_MS = sprintf("%10s", $TOTtotDEAD_MS);
$TOTtotPAUSE_MS = sprintf("%10s", $TOTtotPAUSE_MS);
$TOTtotWAIT_MS = sprintf("%10s", $TOTtotWAIT_MS);
$TOTtotCUSTOMER_MS = sprintf("%10s", $TOTtotCUSTOMER_MS);
$TOTavgTALK_MS = sprintf("%6s", $TOTavgTALK_MS);
$TOTavgDISPO_MS = sprintf("%6s", $TOTavgDISPO_MS);
$TOTavgDEAD_MS = sprintf("%6s", $TOTavgDEAD_MS);
$TOTavgPAUSE_MS = sprintf("%6s", $TOTavgPAUSE_MS);
$TOTavgWAIT_MS = sprintf("%6s", $TOTavgWAIT_MS);
$TOTavgCUSTOMER_MS = sprintf("%6s", $TOTavgCUSTOMER_MS);
while(strlen($TOTtime_MS)>10) {$TOTtime_MS = substr("$TOTtime_MS", 0, -1);}
while(strlen($TOTtotTALK_MS)>10) {$TOTtotTALK_MS = substr("$TOTtotTALK_MS", 0, -1);}
while(strlen($TOTtotDISPO_MS)>10) {$TOTtotDISPO_MS = substr("$TOTtotDISPO_MS", 0, -1);}
while(strlen($TOTtotDEAD_MS)>10) {$TOTtotDEAD_MS = substr("$TOTtotDEAD_MS", 0, -1);}
while(strlen($TOTtotPAUSE_MS)>10) {$TOTtotPAUSE_MS = substr("$TOTtotPAUSE_MS", 0, -1);}
while(strlen($TOTtotWAIT_MS)>10) {$TOTtotWAIT_MS = substr("$TOTtotWAIT_MS", 0, -1);}
while(strlen($TOTtotCUSTOMER_MS)>10) {$TOTtotCUSTOMER_MS = substr("$TOTtotCUSTOMER_MS", 0, -1);}
while(strlen($TOTavgTALK_MS)>6) {$TOTavgTALK_MS = substr("$TOTavgTALK_MS", 0, -1);}
while(strlen($TOTavgDISPO_MS)>6) {$TOTavgDISPO_MS = substr("$TOTavgDISPO_MS", 0, -1);}
while(strlen($TOTavgDEAD_MS)>6) {$TOTavgDEAD_MS = substr("$TOTavgDEAD_MS", 0, -1);}
while(strlen($TOTavgPAUSE_MS)>6) {$TOTavgPAUSE_MS = substr("$TOTavgPAUSE_MS", 0, -1);}
while(strlen($TOTavgWAIT_MS)>6) {$TOTavgWAIT_MS = substr("$TOTavgWAIT_MS", 0, -1);}
while(strlen($TOTavgCUSTOMER_MS)>6) {$TOTavgCUSTOMER_MS = substr("$TOTavgCUSTOMER_MS", 0, -1);}
$grand_total_hours=($TOTtime/3600);
$STOTsales_per_call=sprintf("%.2f", (100*($Sgrand_total_sales/$TOTcalls)))." %";
$STOTsales_per_hour=sprintf("%.2f", ($Sgrand_total_sales/$grand_total_hours));
$STOTsales_per_call=sprintf("%13s", $STOTsales_per_call);
$STOTsales_per_hour=sprintf("%14s", $STOTsales_per_hour);
$Sgrand_total_sales=sprintf("%11s", $Sgrand_total_sales);
$ASCII_text.="+-----------------+----------+----------------------+----------------------+---------------+----------------+-------------+--------+-----------+----------+--------+----------+--------+----------+--------+----------+--------+----------+--------+----------+--------+$statusesHEAD\n";
$ASCII_text.="| TOTALS AGENTS:$TOT_AGENTS | $STOTsales_per_call | $STOTsales_per_hour | $Sgrand_total_sales | $TOTcalls| $TOTtime_MS|$TOTtotPAUSE_MS| $TOTavgPAUSE_MS |$TOTtotWAIT_MS| $TOTavgWAIT_MS |$TOTtotTALK_MS| $TOTavgTALK_MS |$TOTtotDISPO_MS| $TOTavgDISPO_MS |$TOTtotDEAD_MS| $TOTavgDEAD_MS |$TOTtotCUSTOMER_MS| $TOTavgCUSTOMER_MS |$SUMstatusesHTML\n";
$ASCII_text.="+-----------------+----------+----------------------+----------------------+---------------+----------------+-------------+--------+-----------+----------+--------+----------+--------+----------+--------+----------+--------+----------+--------+----------+--------+$statusesHEAD\n";
for ($e=0; $e$SstatusTXT";
}
for ($d=0; $d".$graph_stats[$d][0]." | ".$graph_stats[$d][1]." | ";
$TIME_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][2], 'HF')." | ";
$PAUSE_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][3], 'HF')." | ";
$PAUSEAVG_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][4], 'HF')." | ";
$WAIT_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][5], 'HF')." | ";
$WAITAVG_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][6], 'HF')." | ";
$TALK_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][7], 'HF')." | ";
$TALKAVG_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][8], 'HF')." | ";
$DISPO_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][9], 'HF')." | ";
$DISPOAVG_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][10], 'HF')." | ";
$DEAD_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][11], 'HF')." | ";
$DEADAVG_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][12], 'HF')." | ";
$CUST_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][13], 'HF')." | ";
$CUSTAVG_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][14], 'HF')." | ";
for ($e=0; $e ".$$max_varname." //-->\n";
$$varname.=" | ".$graph_stats[$d][0]." | ".$graph_stats[$d][($e+15)]." | ";
}
}
$CALLS_graph.="| TOTAL: | ".trim($TOTcalls)." |
|---|
";
$TIME_graph.="
|---|
| TOTAL: | ".trim($TOTtime_MS)." |
|---|
";
$PAUSE_graph.="| TOTAL: | ".trim($TOTtotPAUSE_MS)." |
|---|
|