LICENSE: AGPLv2 # # CHANGES # 90522-0723 - First build # 90908-1103 - Added DEAD time stats # 100203-1147 - Added CUSTOMER time statistics # 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 # 101207-1634 - Changed limits on seconds to 65000 from 30000 in vicidial_agent_log # 101207-1719 - Fixed download file formatting bugs(issue 394) # 101208-0320 - Fixed issue 404 # 110307-1057 - Added user_case setting in options.php # 110623-0728 - Fixed user group selection bug # 110708-1727 - Added options.php setting for time precision # 111104-1248 - Added user_group restrictions for selecting in-groups # 120224-0910 - Added HTML display option with bar graphs # 121130-0957 - Fix for user group permissions issue #588 # 130414-0137 - Added report logging # 220414-2111 - Added counts on parked(hold) calls # 130610-0849 - Finalized changing of all ereg instances to preg # 130621-0821 - Added filtering of input to prevent SQL injection attacks and new user auth # 130704-0945 - Fixed issue #675 # $startMS = microtime(); require("dbconnect.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["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["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["file_download"])) {$file_download=$_GET["file_download"];} elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} if (isset($_GET["show_parks"])) {$show_parks=$_GET["show_parks"];} elseif (isset($_POST["show_parks"])) {$show_parks=$_POST["show_parks"];} 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["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';} if (strlen($stage)<2) {$stage='NAME';} $report_name = 'Agent Time Detail'; $db_source = 'M'; $JS_text="\n"; echo "\n"; echo "\n"; echo "\n"; echo "$report_name\n"; echo ""; $short_header=1; require("admin_header.php"); echo "\n"; echo "\n"; echo "
\n";
	}

if ( (strlen($group[0]) < 1) or (strlen($user_group[0]) < 1) )
	{
	echo "\n";
	echo "PLEASE SELECT A CAMPAIGN OR USER GROUP AND DATE-TIME ABOVE AND CLICK SUBMIT\n";
	echo " NOTE: stats taken from shift specified\n";
	}

else
	{
	if ($shift == 'TEST') 
		{
		$time_BEGIN = "09:45:00";  
		$time_END = "10:00:00";
		}
	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";

	if ($file_download < 1)
		{
		echo "Agent Time Detail                     $NOW_TIME\n";

		echo "Time range: $query_date_BEGIN to $query_date_END\n\n";
		}
	else
		{
		$file_output .= "Agent Time Detail                     $NOW_TIME\n";
		$file_output .= "Time range: $query_date_BEGIN to $query_date_END\n\n";
		}



	############################################################################
	##### BEGIN gathering information from the database section
	############################################################################

	### BEGIN gather user IDs and names for matching up later
	$stmt="select full_name,$userSQL from vicidial_users $whereLOGadmin_viewable_groupsSQL order by user limit 100000;";
	$rslt=mysql_query($stmt, $link);
	if ($DB) {echo "$stmt\n";}
	$users_to_print = mysql_num_rows($rslt);
	$i=0;
	$graph_stats=array();
	$max_calls=1;
	$max_timeclock=1;
	$max_agenttime=1;
	$max_wait=1;
	$max_talk=1;
	$max_dispo=1;
	$max_pause=1;
	$max_dead=1;
	$max_customer=1;
	$GRAPH="";
	$GRAPH2="";
	if ($show_parks) {
		$GRAPH2.="";
	}
	$GRAPH2.="";
	$graph_header="
CALLSTIME CLOCKAGENT TIMEPARKSPARKTIMEAVGPARKPARKS/CALLWAITWAIT %TALKTALKTIME%DISPODISPOTIME%PAUSEPAUSETIME%DEADDEADTIME%CUSTOMER
"; $CALLS_graph=$graph_header.""; $TIMECLOCK_graph=$graph_header.""; $AGENTTIME_graph=$graph_header.""; $WAIT_graph=$graph_header.""; $WAITPCT_graph=$graph_header.""; $TALK_graph=$graph_header.""; $TALKPCT_graph=$graph_header.""; $DISPO_graph=$graph_header.""; $DISPOPCT_graph=$graph_header.""; $PAUSE_graph=$graph_header.""; $PAUSEPCT_graph=$graph_header.""; $DEAD_graph=$graph_header.""; $DEADPCT_graph=$graph_header.""; $CUSTOMER_graph=$graph_header.""; $PARKS_graph=$graph_header.""; $PARKTIME_graph=$graph_header.""; $AVGPARK_graph=$graph_header.""; $PARKSCALL_graph=$graph_header.""; while ($i < $users_to_print) { $row=mysql_fetch_row($rslt); $ULname[$i] = $row[0]; $ULuser[$i] = $row[1]; $i++; } ### END gather user IDs and names for matching up later ### BEGIN gather timeclock records per agent $stmt="select $userSQL,sum(login_sec) from vicidial_timeclock_log where event IN('LOGIN','START') and event_date >= '$query_date_BEGIN' and event_date <= '$query_date_END' $TCuser_group_SQL group by user limit 10000000;"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $punches_to_print = mysql_num_rows($rslt); $i=0; while ($i < $punches_to_print) { $row=mysql_fetch_row($rslt); $TCuser[$i] = $row[0]; $TCtime[$i] = $row[1]; $i++; } ### END gather timeclock records per agent ### BEGIN gather pause code information by user IDs $sub_statuses='-'; $sub_statusesTXT=''; $sub_statusesHEAD=''; $sub_statusesHTML=''; $sub_statusesFILE=''; $sub_statusesARY=$MT; $sub_status_count=0; $PCusers='-'; $PCusersARY=$MT; $PCuser_namesARY=$MT; $user_count=0; if ($show_parks) { $park_HEADER=" PARKS | PARK TIME | AVG PARK | PARKS/CALL |"; $park_HEADER_DIV="+----------+------------+------------+------------"; $park_HEADER_CSV=",PARKS,PARK TIME,AVG PARK,PARKS/CALL"; } # Displays park info - need to run regardless so HTML view will populate $park_array=array(); $park_stmt="select user, count(*), sum(parked_sec) From park_log where parked_time <= '$query_date_END' and parked_time >= '$query_date_BEGIN' $park_log_SQL group by user"; if ($DB) {$ASCII_text.= "$park_stmt\n";} $park_rslt=mysql_query($park_stmt, $link); while ($park_row=mysql_fetch_row($park_rslt)) { $park_array[$park_row[0]][0]=$park_row[1]; $park_array[$park_row[0]][1]=$park_row[2]; } $stmt="select $userSQL,sum(pause_sec),sub_status from vicidial_agent_log where event_time <= '$query_date_END' and event_time >= '$query_date_BEGIN' and pause_sec > 0 and pause_sec < 65000 $group_SQL $user_group_SQL group by user,sub_status order by user,sub_status desc limit 10000000;"; $rslt=mysql_query($stmt, $link); if ($DB) {$ASCII_text.= "$stmt\n";} $subs_to_print = mysql_num_rows($rslt); $i=0; while ($i < $subs_to_print) { $row=mysql_fetch_row($rslt); $PCuser[$i] = $row[0]; $PCpause_sec[$i] = $row[1]; $sub_status[$i] = $row[2]; if (!preg_match("/\-$sub_status[$i]\-/i", $sub_statuses)) { $sub_statusesTXT = sprintf("%10s", $sub_status[$i]); $sub_statusesHEAD .= "------------+"; $sub_statusesHTML .= " $sub_statusesTXT |"; $sub_statusesFILE .= ",$sub_status[$i]"; $sub_statuses .= "$sub_status[$i]-"; $sub_statusesARY[$sub_status_count] = $sub_status[$i]; $sub_status_count++; $max_varname="max_".$sub_status[$i]; $$max_varname=1; } if (!preg_match("/\-$PCuser[$i]\-/i", $PCusers)) { $PCusers .= "$PCuser[$i]-"; $PCusersARY[$user_count] = $PCuser[$i]; $user_count++; } $i++; } ### END gather pause code information by user IDs ##### BEGIN Gather all agent time records and parse through them in PHP to save on DB load $stmt="select $userSQL,wait_sec,talk_sec,dispo_sec,pause_sec,lead_id,status,dead_sec from vicidial_agent_log where event_time <= '$query_date_END' and event_time >= '$query_date_BEGIN' $group_SQL $user_group_SQL limit 10000000;"; $rslt=mysql_query($stmt, $link); if ($DB) {$ASCII_text.= "$stmt\n";} $rows_to_print = mysql_num_rows($rslt); $i=0; $j=0; $k=0; $uc=0; while ($i < $rows_to_print) { $row=mysql_fetch_row($rslt); $user = $row[0]; $wait = $row[1]; $talk = $row[2]; $dispo = $row[3]; $pause = $row[4]; $lead = $row[5]; $status = $row[6]; $dead = $row[7]; if ($wait > 65000) {$wait=0;} if ($talk > 65000) {$talk=0;} if ($dispo > 65000) {$dispo=0;} if ($pause > 65000) {$pause=0;} if ($dead > 65000) {$dead=0;} $customer = ($talk - $dead); if ($customer < 1) {$customer=0;} $TOTwait = ($TOTwait + $wait); $TOTtalk = ($TOTtalk + $talk); $TOTdispo = ($TOTdispo + $dispo); $TOTpause = ($TOTpause + $pause); $TOTdead = ($TOTdead + $dead); $TOTcustomer = ($TOTcustomer + $customer); $TOTALtime = ($TOTALtime + $pause + $dispo + $talk + $wait); if ( ($lead > 0) and ((!preg_match("/NULL/i",$status)) and (strlen($status) > 0)) ) {$TOTcalls++;} $user_found=0; if ($uc < 1) { $Suser[$uc] = $user; $uc++; } $m=0; while ( ($m < $uc) and ($m < 50000) ) { if ($user == "$Suser[$m]") { $user_found++; $Swait[$m] = ($Swait[$m] + $wait); $Stalk[$m] = ($Stalk[$m] + $talk); $Sdispo[$m] = ($Sdispo[$m] + $dispo); $Spause[$m] = ($Spause[$m] + $pause); $Sdead[$m] = ($Sdead[$m] + $dead); $Scustomer[$m] = ($Scustomer[$m] + $customer); if ( ($lead > 0) and ((!preg_match("/NULL/i",$status)) and (strlen($status) > 0)) ) {$Scalls[$m]++;} } $m++; } if ($user_found < 1) { $Scalls[$uc] = 0; $Suser[$uc] = $user; $Swait[$uc] = $wait; $Stalk[$uc] = $talk; $Sdispo[$uc] = $dispo; $Spause[$uc] = $pause; $Sdead[$uc] = $dead; $Scustomer[$uc] = $customer; if ($lead > 0) {$Scalls[$uc]++;} $uc++; } $i++; } if ($DB) {echo "Done gathering $i records, analyzing...
\n";} ##### END Gather all agent time records and parse through them in PHP to save on DB load ############################################################################ ##### END gathering information from the database section ############################################################################ ##### BEGIN print the output to screen or put into file output variable if ($file_download < 1) { $ASCII_text.="AGENT TIME BREAKDOWN:\n"; $ASCII_text.="+-----------------+----------+----------+------------+------------$park_HEADER_DIV+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+ +$sub_statusesHEAD\n"; $ASCII_text.="| USER NAME | ID | CALLS | TIME CLOCK | AGENT TIME |$park_HEADER WAIT | WAIT % | TALK | TALK TIME %| DISPO | DISPOTIME %| PAUSE | PAUSETIME %| DEAD | DEAD TIME %| CUSTOMER | |$sub_statusesHTML\n"; $ASCII_text.="+-----------------+----------+----------+------------+------------$park_HEADER_DIV+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+ +$sub_statusesHEAD\n"; } else { $file_output .= "USER,ID,CALLS,TIME CLOCK,AGENT TIME$park_HEADER_CSV,WAIT,WAIT %,TALK,TALK TIME %,DISPO,DISPO TIME %,PAUSE,PAUSE TIME %,DEAD,DEAD TIME %,CUSTOMER$sub_statusesFILE\n"; } ##### END print the output to screen or put into file output variable ############################################################################ ##### BEGIN formatting data for output section ############################################################################ ##### BEGIN loop through each user formatting data for output $AUTOLOGOUTflag=0; $m=0; while ( ($m < $uc) and ($m < 50000) ) { $SstatusesHTML=''; $SstatusesFILE=''; $Stime[$m] = ($Swait[$m] + $Stalk[$m] + $Sdispo[$m] + $Spause[$m]); $Swaitpct[$m]=(100*$Swait[$m]/$Stime[$m]); $Stalkpct[$m]=(100*$Stalk[$m]/$Stime[$m]); $Sdispopct[$m]=(100*$Sdispo[$m]/$Stime[$m]); $Spausepct[$m]=(100*$Spause[$m]/$Stime[$m]); $Sdeadpct[$m]=(100*$Sdead[$m]/$Stime[$m]); $RAWuser = $Suser[$m]; $RAWcalls = $Scalls[$m]; $RAWtimeSEC = $Stime[$m]; if (trim($Scalls[$m])>$max_calls) {$max_calls=trim($Scalls[$m]);} if (trim($Stime[$m])>$max_agenttime) {$max_agenttime=trim($Stime[$m]);} if (trim($Swait[$m])>$max_wait) {$max_wait=trim($Swait[$m]);} if (trim($Stalk[$m])>$max_talk) {$max_talk=trim($Stalk[$m]);} if (trim($Sdispo[$m])>$max_dispo) {$max_dispo=trim($Sdispo[$m]);} if (trim($Spause[$m])>$max_pause) {$max_pause=trim($Spause[$m]);} if (trim($Sdead[$m])>$max_dead) {$max_dead=trim($Sdead[$m]);} if (trim($Scustomer[$m])>$max_customer) {$max_customer=trim($Scustomer[$m]);} if (trim($Swaitpct[$m])>$max_waitpct) {$max_waitpct=trim($Swaitpct[$m]);} if (trim($Stalkpct[$m])>$max_talkpct) {$max_talkpct=trim($Stalkpct[$m]);} if (trim($Sdispopct[$m])>$max_dispopct) {$max_dispopct=trim($Sdispopct[$m]);} if (trim($Spausepct[$m])>$max_pausepct) {$max_pausepct=trim($Spausepct[$m]);} if (trim($Sdeadpct[$m])>$max_deadpct) {$max_deadpct=trim($Sdeadpct[$m]);} $graph_stats[$m][1]=trim($Scalls[$m]); $graph_stats[$m][3]=trim($Stime[$m]); $graph_stats[$m][4]=trim($Swait[$m]); $graph_stats[$m][5]=trim($Stalk[$m]); $graph_stats[$m][6]=trim($Sdispo[$m]); $graph_stats[$m][7]=trim($Spause[$m]); $graph_stats[$m][8]=trim($Sdead[$m]); $graph_stats[$m][9]=trim($Scustomer[$m]); $graph_stats[$m][10]=trim(sprintf("%01.2f", $Stalkpct[$m])); $graph_stats[$m][11]=trim(sprintf("%01.2f", $Sdispopct[$m])); $graph_stats[$m][12]=trim(sprintf("%01.2f", $Spausepct[$m])); $graph_stats[$m][13]=trim(sprintf("%01.2f", $Sdeadpct[$m])); $graph_stats[$m][14]=trim(sprintf("%01.2f", $Swaitpct[$m])); $Swaitpct[$m]= sprintf("%01.2f", $Swaitpct[$m]); $Stalkpct[$m]= sprintf("%01.2f", $Stalkpct[$m]); $Sdispopct[$m]= sprintf("%01.2f", $Sdispopct[$m]); $Spausepct[$m]= sprintf("%01.2f", $Spausepct[$m]); $Sdeadpct[$m]= sprintf("%01.2f", $Sdeadpct[$m]); $Swait[$m]= sec_convert($Swait[$m],$TIME_agenttimedetail); $Stalk[$m]= sec_convert($Stalk[$m],$TIME_agenttimedetail); $Sdispo[$m]= sec_convert($Sdispo[$m],$TIME_agenttimedetail); $Spause[$m]= sec_convert($Spause[$m],$TIME_agenttimedetail); $Sdead[$m]= sec_convert($Sdead[$m],$TIME_agenttimedetail); $Scustomer[$m]= sec_convert($Scustomer[$m],$TIME_agenttimedetail); $Stime[$m]= sec_convert($Stime[$m],$TIME_agenttimedetail); $RAWtime = $Stime[$m]; $RAWwait = $Swait[$m]; $RAWtalk = $Stalk[$m]; $RAWdispo = $Sdispo[$m]; $RAWpause = $Spause[$m]; $RAWdead = $Sdead[$m]; $RAWcustomer = $Scustomer[$m]; $RAWwaitpct = $Swaitpct[$m]; $RAWtalkpct = $Stalkpct[$m]; $RAWdispopct = $Sdispopct[$m]; $RAWpausepct = $Spausepct[$m]; $RAWdeadpct = $Sdeadpct[$m]; $n=0; $user_name_found=0; while ($n < $users_to_print) { if ($Suser[$m] == "$ULuser[$n]") { $user_name_found++; $RAWname = $ULname[$n]; $Sname[$m] = $ULname[$n]; } $n++; } if ($user_name_found < 1) { $RAWname = "NOT IN SYSTEM"; $Sname[$m] = $RAWname; } $n=0; $punches_found=0; while ($n < $punches_to_print) { if ($Suser[$m] == "$TCuser[$n]") { $punches_found++; $RAWtimeTCsec = $TCtime[$n]; $TOTtimeTC = ($TOTtimeTC + $TCtime[$n]); if (trim($RAWtimeTCsec)>$max_timeclock) {$max_timeclock=trim($RAWtimeTCsec);} $graph_stats[$m][2]=trim($RAWtimeTCsec); $StimeTC[$m]= sec_convert($TCtime[$n],$TIME_agenttimedetail); $RAWtimeTC = $StimeTC[$m]; $StimeTC[$m] = sprintf("%10s", $StimeTC[$m]); } $n++; } if ($punches_found < 1) { $RAWtimeTCsec = "0"; $graph_stats[$m][2]=0; $StimeTC[$m] = "0:00"; if ($TIME_agenttimedetail == 'HF') {$StimeTC[$m] = "0:00:00";} $RAWtimeTC = $StimeTC[$m]; $StimeTC[$m] = sprintf("%10s", $StimeTC[$m]); } ### Check if the user had an AUTOLOGOUT timeclock event during the time period $TCuserAUTOLOGOUT = ' '; $stmt="select count(*) from vicidial_timeclock_log where event='AUTOLOGOUT' and user='$Suser[$m]' and event_date >= '$query_date_BEGIN' and event_date <= '$query_date_END';"; $rslt=mysql_query($stmt, $link); if ($DB) {echo "$stmt\n";} $autologout_results = mysql_num_rows($rslt); if ($autologout_results > 0) { $row=mysql_fetch_row($rslt); if ($row[0] > 0) { $TCuserAUTOLOGOUT = '*'; $AUTOLOGOUTflag++; } } ### BEGIN loop through each status ### $n=0; while ($n < $sub_status_count) { $Sstatus=$sub_statusesARY[$n]; $SstatusTXT=''; $varname=$Sstatus."_graph"; $$varname=$graph_header.""; $max_varname="max_".$Sstatus; ### BEGIN loop through each stat line ### $i=0; $status_found=0; while ( ($i < $subs_to_print) and ($status_found < 1) ) { if ( ($Suser[$m]=="$PCuser[$i]") and ($Sstatus=="$sub_status[$i]") ) { $USERcodePAUSE_MS = sec_convert($PCpause_sec[$i],$TIME_agenttimedetail); if (strlen($USERcodePAUSE_MS)<1) {$USERcodePAUSE_MS='0';} $pfUSERcodePAUSE_MS = sprintf("%10s", $USERcodePAUSE_MS); if ($PCpause_sec[$i]>$$max_varname) {$$max_varname=$PCpause_sec[$i];} $graph_stats_sub[$m][$n]=$PCpause_sec[$i]; $SstatusTXT = sprintf("%10s", $pfUSERcodePAUSE_MS); $SstatusesHTML .= " $SstatusTXT |"; $SstatusesFILE .= ",$USERcodePAUSE_MS"; $status_found++; } $i++; } if ($status_found < 1) { if ($TIME_agenttimedetail == 'HF') { $SstatusesHTML .= " 0:00:00 |"; $SstatusesFILE .= ",0:00:00"; } else { $SstatusesHTML .= " 0:00 |"; $SstatusesFILE .= ",0:00"; } } ### END loop through each stat line ### $n++; } ### END loop through each status ### $Swaitpct[$m]= sprintf("%9s", $Swaitpct[$m])."%"; $Stalkpct[$m]= sprintf("%9s", $Stalkpct[$m])."%"; $Sdispopct[$m]= sprintf("%9s", $Sdispopct[$m])."%"; $Spausepct[$m]= sprintf("%9s", $Spausepct[$m])."%"; $Sdeadpct[$m]= sprintf("%9s", $Sdeadpct[$m])."%"; $Swait[$m]= sprintf("%10s", $Swait[$m]); $Stalk[$m]= sprintf("%10s", $Stalk[$m]); $Sdispo[$m]= sprintf("%10s", $Sdispo[$m]); $Spause[$m]= sprintf("%10s", $Spause[$m]); $Sdead[$m]= sprintf("%10s", $Sdead[$m]); $Scustomer[$m]= sprintf("%10s", $Scustomer[$m]); $Scalls[$m]= sprintf("%8s", $Scalls[$m]); $Stime[$m]= sprintf("%10s", $Stime[$m]); # PARK INFO if ($show_parks) { $user_holds=$park_array[$Suser[$m]][0]+0; $total_hold_time=$park_array[$Suser[$m]][1]+0; $TOTuser_holds+=$park_array[$Suser[$m]][0]; $TOTtotal_hold_time+=$park_array[$Suser[$m]][1]; $avg_hold_time=round($total_hold_time/$user_holds); $user_hpc=sprintf("%.2f", ($user_holds/$Scalls[$m])); $total_hold_time=sec_convert($total_hold_time,$TIME_agenttimedetail); $avg_hold_time=sec_convert($avg_hold_time,$TIME_agenttimedetail); $user_holds= sprintf("%8s", $user_holds); $total_hold_time= sprintf("%10s", $total_hold_time); $avg_hold_time= sprintf("%10s", $avg_hold_time); $user_hpc= sprintf("%10s", $user_hpc); $park_AGENT_INFO=" $user_holds | $total_hold_time | $avg_hold_time | $user_hpc |"; $park_AGENT_INFO_CSV="$user_holds,$total_hold_time,$avg_hold_time,$user_hpc,"; } if (trim($user_holds)>$max_user_holds) {$max_user_holds=trim($user_holds);} if (trim($park_array[$Suser[$m]][1]+0)>$max_total_hold_time) {$max_total_hold_time=trim($park_array[$Suser[$m]][1]+0);} if (trim(round(($park_array[$Suser[$m]][1]+0)/$user_holds))>$max_avg_hold_time) {$max_avg_hold_time=trim(round(($park_array[$Suser[$m]][1]+0)/$user_holds));} if (trim($user_hpc)>$max_user_hpc) {$max_user_hpc=trim($user_hpc);} $graph_stats[$m][15]=trim($user_holds); $graph_stats[$m][16]=trim($park_array[$Suser[$m]][1]+0); $graph_stats[$m][17]=trim(round(($park_array[$Suser[$m]][1]+0)/$user_holds)); $graph_stats[$m][18]=trim($user_hpc); if ($non_latin < 1) { $Sname[$m]= sprintf("%-15s", $Sname[$m]); while(strlen($Sname[$m])>15) {$Sname[$m] = substr("$Sname[$m]", 0, -1);} $Suser[$m] = sprintf("%-8s", $Suser[$m]); while(strlen($Suser[$m])>8) {$Suser[$m] = substr("$Suser[$m]", 0, -1);} } else { $Sname[$m]= sprintf("%-45s", $Sname[$m]); while(mb_strlen($Sname[$m],'utf-8')>15) {$Sname[$m] = mb_substr("$Sname[$m]", 0, -1,'utf-8');} $Suser[$m] = sprintf("%-24s", $Suser[$m]); while(mb_strlen($Suser[$m],'utf-8')>8) {$Suser[$m] = mb_substr("$Suser[$m]", 0, -1,'utf-8');} } if ($file_download < 1) { $Toutput = "| $Sname[$m] | $Suser[$m] | $Scalls[$m] | $StimeTC[$m]$TCuserAUTOLOGOUT| $Stime[$m] |$park_AGENT_INFO $Swait[$m] | $Swaitpct[$m] | $Stalk[$m] | $Stalkpct[$m] | $Sdispo[$m] | $Sdispopct[$m] | $Spause[$m] | $Spausepct[$m] | $Sdead[$m] | $Sdeadpct[$m] | $Scustomer[$m] | |$SstatusesHTML\n"; $graph_stats[$m][0]=trim("$Suser[$m] - $Sname[$m]"); #CALLS | TIME CLOCK | AGENT TIME | WAIT | TALK | DISPO | PAUSE | DEAD | CUSTOMER | | LOGIN | TRAIN | TOILET | PRECAL | BREAK | | LUNCH | LAGGED } else { if (strlen($RAWtime)<1) {$RAWtime='0';} if (strlen($RAWwait)<1) {$RAWwait='0';} if (strlen($RAWwaitpct)<0) {$RAWwaitpct='0.0%';} if (strlen($RAWtalk)<1) {$RAWtalk='0';} if (strlen($RAWtalkpct)<0) {$RAWtalkpct='0.0%';} if (strlen($RAWdispo)<1) {$RAWdispo='0';} if (strlen($RAWdispopct)<0) {$RAWdispopct='0.0%';} if (strlen($RAWpause)<1) {$RAWpause='0';} if (strlen($RAWpausepct)<0) {$RAWpausepct='0.0%';} if (strlen($RAWdead)<1) {$RAWdead='0';} if (strlen($RAWdeadpct)<0) {$RAWdeadpct='0.0%';} if (strlen($RAWcustomer)<1) {$RAWcustomer='0';} $user_holds=trim($user_holds); $total_hold_time=trim($total_hold_time); $avg_hold_time=trim($avg_hold_time); $user_hpc=trim($user_hpc); $fileToutput = "$RAWname,$RAWuser,$RAWcalls,$RAWtimeTC,$RAWtime,$park_AGENT_INFO_CSV$RAWwait,$RAWwaitpct %,$RAWtalk,$RAWtalkpct %,$RAWdispo,$RAWdispopct %,$RAWpause,$RAWpausepct %,$RAWdead,$RAWdeadpct %,$RAWcustomer$SstatusesFILE\n"; } $TOPsorted_output[$m] = $Toutput; $TOPsorted_outputFILE[$m] = $fileToutput; if ($stage == 'NAME') { $TOPsort[$m] = '' . sprintf("%020s", $RAWname) . '-----' . $m . '-----' . sprintf("%020s", $RAWuser); $TOPsortTALLY[$m]=$RAWcalls; } if ($stage == 'ID') { $TOPsort[$m] = '' . sprintf("%08s", $RAWuser) . '-----' . $m . '-----' . sprintf("%020s", $RAWuser); $TOPsortTALLY[$m]=$RAWcalls; } if ($stage == 'LEADS') { $TOPsort[$m] = '' . sprintf("%08s", $RAWcalls) . '-----' . $m . '-----' . sprintf("%020s", $RAWuser); $TOPsortTALLY[$m]=$RAWcalls; } if ($stage == 'TIME') { $TOPsort[$m] = '' . sprintf("%010s", $RAWtimeSEC) . '-----' . $m . '-----' . sprintf("%020s", $RAWuser); $TOPsortTALLY[$m]=$RAWtimeSEC; } if ($stage == 'TCLOCK') { $TOPsort[$m] = '' . sprintf("%010s", $RAWtimeTCsec) . '-----' . $m . '-----' . sprintf("%020s", $RAWuser); $TOPsortTALLY[$m]=$RAWtimeTCsec; } if (!preg_match('/NAME|ID|TIME|LEADS|TCLOCK/',$stage)) if ($file_download < 1) {$ASCII_text.="$Toutput";} else {$file_output .= "$fileToutput";} if ($TOPsortMAX < $TOPsortTALLY[$m]) {$TOPsortMAX = $TOPsortTALLY[$m];} # echo "$Suser[$m]|$Sname[$m]|$Swait[$m]|$Stalk[$m]|$Sdispo[$m]|$Spause[$m]|$Scalls[$m]\n"; $m++; } ##### END loop through each user formatting data for output $TOT_AGENTS = $m; $hTOT_AGENTS = sprintf("%4s", $TOT_AGENTS); $k=$m; if ($DB) {echo "Done analyzing... $TOTwait|$TOTtalk|$TOTdispo|$TOTpause|$TOTdead|$TOTcustomer|$TOTALtime|$TOTcalls|$uc|
\n";} ### BEGIN sort through output to display properly ### if ( ($TOT_AGENTS > 0) and (preg_match('/NAME|ID|TIME|LEADS|TCLOCK/',$stage)) ) { if (preg_match('/ID/',$stage)) {sort($TOPsort, SORT_NUMERIC);} if (preg_match('/TIME|LEADS|TCLOCK/',$stage)) {rsort($TOPsort, SORT_NUMERIC);} if (preg_match('/NAME/',$stage)) {rsort($TOPsort, SORT_STRING);} $m=0; while ($m < $k) { $sort_split = explode("-----",$TOPsort[$m]); $i = $sort_split[1]; $sort_order[$m] = "$i"; if ($file_download < 1) {$ASCII_text.="$TOPsorted_output[$i]";} else {$file_output .= "$TOPsorted_outputFILE[$i]";} $m++; } } ### END sort through output to display properly ### ############################################################################ ##### END formatting data for output section ############################################################################ ############################################################################ ##### BEGIN last line totals output section ############################################################################ $SUMstatusesHTML=''; $SUMstatusesFILE=''; $TOTtotPAUSE=0; $n=0; while ($n < $sub_status_count) { $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); $USERsumstatPAUSE_MS = sec_convert($Scalls,$TIME_agenttimedetail); $pfUSERsumstatPAUSE_MS = sprintf("%11s", $USERsumstatPAUSE_MS); $$total_var="$pfUSERsumstatPAUSE_MS"; $SUMstatusTXT = sprintf("%10s", $pfUSERsumstatPAUSE_MS); $SUMstatusesHTML .= "$SUMstatusTXT |"; $SUMstatusesFILE .= ",$USERsumstatPAUSE_MS"; } $n++; } ### END loop through each status ### ### call function to calculate and print dialable leads $TOTwaitpct=sprintf("%01.2f", (100*$TOTwait/$TOTALtime)); $TOTtalkpct=sprintf("%01.2f", (100*$TOTtalk/$TOTALtime)); $TOTdispopct=sprintf("%01.2f", (100*$TOTdispo/$TOTALtime)); $TOTpausepct=sprintf("%01.2f", (100*$TOTpause/$TOTALtime)); $TOTdeadpct=sprintf("%01.2f", (100*$TOTdead/$TOTALtime)); $TOTwait = sec_convert($TOTwait,$TIME_agenttimedetail); $TOTtalk = sec_convert($TOTtalk,$TIME_agenttimedetail); $TOTdispo = sec_convert($TOTdispo,$TIME_agenttimedetail); $TOTpause = sec_convert($TOTpause,$TIME_agenttimedetail); $TOTdead = sec_convert($TOTdead,$TIME_agenttimedetail); $TOTcustomer = sec_convert($TOTcustomer,$TIME_agenttimedetail); $TOTALtime = sec_convert($TOTALtime,$TIME_agenttimedetail); $TOTtimeTC = sec_convert($TOTtimeTC,$TIME_agenttimedetail); if ($show_parks) { $TOTavg_hold_time=round($TOTtotal_hold_time/$TOTuser_holds); $TOTuser_hpc=sprintf("%.2f", ($TOTuser_holds/$TOTcalls)); $TOTtotal_hold_time=sec_convert($TOTtotal_hold_time,$TIME_agenttimedetail); $TOTavg_hold_time=sec_convert($TOTavg_hold_time,$TIME_agenttimedetail); $hTOTuser_holds= sprintf("%8s", $TOTuser_holds); $hTOTtotal_hold_time= sprintf("%10s", $TOTtotal_hold_time); $hTOTavg_hold_time= sprintf("%10s", $TOTavg_hold_time); $hTOTuser_hpc= sprintf("%10s", $TOTuser_hpc); $park_TOTALS=" $hTOTuser_holds | $hTOTtotal_hold_time | $hTOTavg_hold_time | $hTOTuser_hpc |"; $park_TOTALS_CSV="$TOTuser_holds,$TOTtotal_hold_time,$TOTavg_hold_time,$TOTuser_hpc,"; } $hTOTwaitpct = sprintf("%10s", $TOTwaitpct)."%"; $hTOTtalkpct = sprintf("%10s", $TOTtalkpct)."%"; $hTOTdispopct = sprintf("%10s", $TOTdispopct)."%"; $hTOTpausepct = sprintf("%10s", $TOTpausepct)."%"; $hTOTdeadpct = sprintf("%10s", $TOTdeadpct)."%"; $hTOTcalls = sprintf("%8s", $TOTcalls); $hTOTwait = sprintf("%11s", $TOTwait); $hTOTtalk = sprintf("%11s", $TOTtalk); $hTOTdispo = sprintf("%11s", $TOTdispo); $hTOTpause = sprintf("%11s", $TOTpause); $hTOTdead = sprintf("%11s", $TOTdead); $hTOTcustomer = sprintf("%11s", $TOTcustomer); $hTOTALtime = sprintf("%11s", $TOTALtime); $hTOTtimeTC = sprintf("%11s", $TOTtimeTC); ###### END LAST LINE TOTALS FORMATTING ########## if ($file_download < 1) { $ASCII_text.="+-----------------+----------+----------+------------+------------$park_HEADER_DIV+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+ +$sub_statusesHEAD\n"; $ASCII_text.="| TOTALS AGENTS:$hTOT_AGENTS | $hTOTcalls |$hTOTtimeTC |$hTOTALtime |$park_TOTALS$hTOTwait |$hTOTwaitpct |$hTOTtalk |$hTOTtalkpct |$hTOTdispo |$hTOTdispopct |$hTOTpause |$hTOTpausepct |$hTOTdead |$hTOTdeadpct |$hTOTcustomer | |$SUMstatusesHTML\n"; $ASCII_text.="+-----------------+----------+----------+------------+------------$park_HEADER_DIV+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+------------+ +$sub_statusesHEAD\n"; if ($AUTOLOGOUTflag > 0) {echo " * denotes AUTOLOGOUT from timeclock\n";} $ASCII_text.="\n\n"; for ($e=0; $e$SstatusTXT"; } for ($d=0; $d"; $TIMECLOCK_graph.=" "; $AGENTTIME_graph.=" "; $WAIT_graph.=" "; $TALK_graph.=" "; $DISPO_graph.=" "; $PAUSE_graph.=" "; $DEAD_graph.=" "; $CUSTOMER_graph.=" "; $TALKPCT_graph.=" "; $DISPOPCT_graph.=" "; $PAUSEPCT_graph.=" "; $DEADPCT_graph.=" "; $WAITPCT_graph.=" "; $PARKS_graph.=" "; $PARKTIME_graph.=" "; $AVGPARK_graph.=" "; $PARKSCALL_graph.=" "; for ($e=0; $e\n"; $$varname.=" "; } } $CALLS_graph.="
AGENT TIME BREAKDOWN
STATUSCALLS
TIME CLOCK
AGENT TIME
WAIT
WAIT %
TALK
TALK TIME %
DISPO
DISPO TIME %
PAUSE
PAUSE TIME %
DEAD
DEAD TIME %
CUSTOMER
PARKS
PARKTIME
AVGPARK
PARKSCALL
$Sstatus
".$graph_stats[$d][1]."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][2], 'HF')."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][3], 'HF')."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][4], 'HF')."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][5], 'HF')."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][6], 'HF')."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][7], 'HF')."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][8], 'HF')."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][9], 'HF')."
".$graph_stats[$d][0]."".$graph_stats[$d][10]." %
".$graph_stats[$d][0]."".$graph_stats[$d][11]." %
".$graph_stats[$d][0]."".$graph_stats[$d][12]." %
".$graph_stats[$d][0]."".$graph_stats[$d][13]." %
".$graph_stats[$d][0]."".$graph_stats[$d][14]." %
".$graph_stats[$d][0]."".$graph_stats[$d][15]."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][16],'HF')."
".$graph_stats[$d][0]."".sec_convert($graph_stats[$d][17],'HF')."
".$graph_stats[$d][0]."".$graph_stats[$d][18]."
".$graph_stats[$d][0]."".sec_convert($graph_stats_sub[$d][$e], 'HF')."
TOTAL:".trim($hTOTcalls)."
"; $TIMECLOCK_graph.="TOTAL:".trim($hTOTtimeTC).""; $AGENTTIME_graph.="TOTAL:".trim($hTOTALtime).""; $WAIT_graph.="TOTAL:".trim($hTOTwait).""; $TALK_graph.="TOTAL:".trim($hTOTtalk).""; $DISPO_graph.="TOTAL:".trim($hTOTdispo).""; $PAUSE_graph.="TOTAL:".trim($hTOTpause).""; $DEAD_graph.="TOTAL:".trim($hTOTdead).""; $CUSTOMER_graph.="TOTAL:".trim($hTOTcustomer).""; $WAITPCT_graph.="AVERAGE:".trim($hTOTwaitpct).""; $TALKPCT_graph.="AVERAGE:".trim($hTOTtalkpct).""; $DISPOPCT_graph.="AVERAGE:".trim($hTOTdispopct).""; $PAUSEPCT_graph.="AVERAGE:".trim($hTOTpausepct).""; $DEADPCT_graph.="AVERAGE:".trim($hTOTdeadpct).""; $PARKS_graph.="TOTAL:".trim($hTOTuser_holds).""; $PARKTIME_graph.="TOTAL:".trim($hTOTtotal_hold_time).""; $AVGPARK_graph.="AVERAGE:".trim($hTOTavg_hold_time).""; $PARKSCALL_graph.="AVERAGE:".trim($hTOTuser_hpc).""; for ($e=0; $e"; # $JS_text.="var ".$Sstatus."_graph=\"".$$graph_var."\";\n"; } $JS_onload.="\tDrawGraph('CALLS', '1');\n"; $JS_text.="function DrawGraph(graph, th_id) {\n"; $JS_text.=" var CALLS_graph=\"$CALLS_graph\";\n"; $JS_text.=" var TIMECLOCK_graph=\"$TIMECLOCK_graph\";\n"; $JS_text.=" var AGENTTIME_graph=\"$AGENTTIME_graph\";\n"; $JS_text.=" var WAIT_graph=\"$WAIT_graph\";\n"; $JS_text.=" var TALK_graph=\"$TALK_graph\";\n"; $JS_text.=" var DISPO_graph=\"$DISPO_graph\";\n"; $JS_text.=" var PAUSE_graph=\"$PAUSE_graph\";\n"; $JS_text.=" var DEAD_graph=\"$DEAD_graph\";\n"; $JS_text.=" var CUSTOMER_graph=\"$CUSTOMER_graph\";\n"; $JS_text.=" var WAITPCT_graph=\"$WAITPCT_graph\";\n"; $JS_text.=" var TALKPCT_graph=\"$TALKPCT_graph\";\n"; $JS_text.=" var DISPOPCT_graph=\"$DISPOPCT_graph\";\n"; $JS_text.=" var PAUSEPCT_graph=\"$PAUSEPCT_graph\";\n"; $JS_text.=" var DEADPCT_graph=\"$DEADPCT_graph\";\n"; $JS_text.=" var PARKS_graph=\"$PARKS_graph\";\n"; $JS_text.=" var PARKTIME_graph=\"$PARKTIME_graph\";\n"; $JS_text.=" var AVGPARK_graph=\"$AVGPARK_graph\";\n"; $JS_text.=" var PARKSCALL_graph=\"$PARKSCALL_graph\";\n"; for ($e=0; $e
 


"; # echo $GRAPH.$GRAPH2.$GRAPH3.$max; } else { $file_output .= "TOTALS,$TOT_AGENTS,$TOTcalls,$TOTtimeTC,$TOTALtime,$park_TOTALS_CSV$TOTwait,$TOTwaitpct %,$TOTtalk,$TOTtalkpct %,$TOTdispo,$TOTpause,$TOTdead,$TOTcustomer$SUMstatusesFILE\n"; } } ############################################################################ ##### END formatting data for output section ############################################################################ if ($file_download > 0) { $FILE_TIME = date("Ymd-His"); $CSVfilename = "AGENT_TIME$US$FILE_TIME.csv"; // 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 "$file_output"; if ($db_source == 'S') { mysql_close($link); $use_slave_server=0; $db_source = 'M'; require("dbconnect.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_query($stmt, $link); exit; } $NWB = "   \"HELP\""; ############################################################################ ##### BEGIN HTML form section ############################################################################ $JS_onload.="}\n"; $JS_text.=$JS_onload; $JS_text.="\n"; if ($report_display_type=="HTML") { echo $JS_text; echo $GRAPH.$GRAPH2.$GRAPH3.$max; } else { echo $ASCII_text; } echo "
\n"; echo "
Dates:
"; echo "\n"; echo ""; ?> to
"; ?>
Campaigns:
"; echo "\n"; echo "
User Groups:
"; echo "\n"; echo "
Shift:
"; echo "
\n"; echo "Show parks-holds
"; echo "Display as:
"; echo "\n

"; echo "$NWB#agent_time_detail$NWE\n"; echo "
        "; echo "          \n"; echo " DOWNLOAD | \n"; echo " REPORTS \n"; echo "\n"; echo "
"; echo "
\n\n
$db_source"; ############################################################################ ##### END HTML form section ############################################################################ $ENDtime = date("U"); $RUNtime = ($ENDtime - $STARTtime); echo "$RUNtime\n"; ##### BEGIN horizontal yellow transparent bar graph overlay on top of agent stats echo "\n"; echo "\n"; echo "
\n\n\n\n\n\n\n\n";

if ($stage == 'NAME') {$k=0;}
$m=0;
while ($m < $k)
	{
	$sort_split = explode("-----",$TOPsort[$m]);
	$i = $sort_split[1];
	$sort_order[$m] = "$i";

	if ( ($TOPsortTALLY[$i] < 1) or ($TOPsortMAX < 1) )
		{echo "                              \n";}
	else
		{
		echo "                              ";
		$TOPsortPLOT = ( ($TOPsortTALLY[$i] / $TOPsortMAX) * 110 );
		$h=0;
		while ($h <= $TOPsortPLOT)
			{
			echo " ";
			$h++;
			}
		echo "\n";
		}
	$m++;
	}

echo "\n";
##### END horizontal yellow transparent bar graph overlay on top of agent stats

if ($db_source == 'S')
	{
	mysql_close($link);
	$use_slave_server=0;
	$db_source = 'M';
	require("dbconnect.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_query($stmt, $link);

?>