";
+
+if ($DB > 0)
+ {
+ $MAIN.=" \n";
+ $MAIN.="$group_ct|$group_string|$group_SQL\n";
+ $MAIN.=" \n";
+ $MAIN.="$shift|$query_date|$end_date\n";
+ $MAIN.=" \n";
+ }
+
+$MAIN.="\n\n";
+$MAIN.="\n\n";
+
+
+if ($groups_to_print < 1)
+ {
+ $MAIN.="\n\n";
+ if ($CHAT=='Y')
+ {$MAIN.=_QXZ("PLEASE SELECT A CHAT IN-GROUP AND DATE RANGE ABOVE AND CLICK SUBMIT")."\n";}
+ if ($EMAIL=='Y')
+ {$MAIN.=_QXZ("PLEASE SELECT AN EMAIL ACCOUNT AND DATE RANGE ABOVE AND CLICK SUBMIT")."\n";}
+ if ($DID=='Y')
+ {$MAIN.=_QXZ("PLEASE SELECT A DID AND DATE RANGE ABOVE AND CLICK SUBMIT")."\n";}
+ else
+ {$MAIN.=_QXZ("PLEASE SELECT AN IN-GROUP AND DATE RANGE ABOVE AND CLICK SUBMIT")."\n";}
+ }
+
+else
+{
+$call_time_ranges=array();
+
+$ct_stmt="select * from vicidial_call_times where call_time_id='$shift'";
+if ($DB) {$MAIN.=$ct_stmt."\n";}
+$ct_rslt=mysql_to_mysqli($ct_stmt, $link);
+if (mysqli_num_rows($ct_rslt)>0)
+ {
+ $ct_row=mysqli_fetch_array($ct_rslt);
+ $default_time_BEGIN=$ct_row["ct_default_start"];
+ $default_time_END=$ct_row["ct_default_stop"];
+ while (strlen($default_time_BEGIN)<4) {$default_time_BEGIN="0".$default_time_BEGIN;}
+ while (strlen($default_time_END)<4) {$default_time_END="0".$default_time_END;}
+ $default_time_BEGIN=substr($default_time_BEGIN,0,2).":".substr($default_time_BEGIN,2,2).":00";
+ # In case default time ends after midnight the next day
+ if ($default_time_END>2400) {
+ $multiday_default="yes";
+ $multiday_default_END=($default_time_END-2400);
+ while(strlen($multiday_default_END)<4) {
+ $multiday_default_END="0".$multiday_default_END;
+ }
+ $multiday_default_END=substr($multiday_default_END,0,2).":".substr($multiday_default_END,2,2).":00";
+ # Result: Default start time is: current-day default_time_BEGIN to current-day 23:59:59 and next-day 00:00:00 to next-day multiday_default_END
+ }
+ $default_time_END=substr($default_time_END,0,2).":".substr($default_time_END,2,2).":00";
+ $time_BEGIN=$default_time_BEGIN;
+ $time_END=$default_time_END;
+
+ if ($ct_row["ct_sunday_start"]==0 && $ct_row["ct_sunday_stop"]==0) {
+ if ($multiday_default=="yes") {
+ array_push($call_time_ranges, array("1", "$default_time_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("2", "00:00:00", "$multiday_default_END"));
+ } else {
+ array_push($call_time_ranges, array("1", "$default_time_BEGIN", "$default_time_END"));
+ }
+ } else {
+ $sunday_BEGIN=$ct_row["ct_sunday_start"];
+ $sunday_END=$ct_row["ct_sunday_stop"];
+ while (strlen($sunday_BEGIN)<4) {$sunday_BEGIN="0".$sunday_BEGIN;}
+ while (strlen($sunday_END)<4) {$sunday_END="0".$sunday_END;}
+ $sunday_BEGIN=substr($sunday_BEGIN,0,2).":".substr($sunday_BEGIN,2,2).":00";
+ $sunday_END=substr($sunday_END,0,2).":".substr($sunday_END,2,2).":00";
+
+ if($ct_row["ct_sunday_stop"]>2400) {
+ $sunday_multiday_END=$ct_row["ct_sunday_stop"]-2400;
+ while(strlen($sunday_multiday_END)<4) {
+ $sunday_multiday_END="0".$sunday_multiday_END;
+ }
+ $sunday_multiday_END=substr($sunday_multiday_END,0,2).":".substr($sunday_multiday_END,2,2).":00";
+ array_push($call_time_ranges, array("1", "$sunday_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("2", "00:00:00", "$sunday_multiday_END"));
+ } else {
+ array_push($call_time_ranges, array("1", "$sunday_BEGIN", "$sunday_END"));
+ }
+ }
+
+ if ($ct_row["ct_monday_start"]==0 && $ct_row["ct_monday_stop"]==0) {
+ if ($multiday_default=="yes") {
+ array_push($call_time_ranges, array("2", "$default_time_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("3", "00:00:00", "$multiday_default_END"));
+ } else {
+ array_push($call_time_ranges, array("2", "$default_time_BEGIN", "$default_time_END"));
+ }
+ } else {
+ $monday_BEGIN=$ct_row["ct_monday_start"];
+ $monday_END=$ct_row["ct_monday_stop"];
+ while (strlen($monday_BEGIN)<4) {$monday_BEGIN="0".$monday_BEGIN;}
+ while (strlen($monday_END)<4) {$monday_END="0".$monday_END;}
+ $monday_BEGIN=substr($monday_BEGIN,0,2).":".substr($monday_BEGIN,2,2).":00";
+ $monday_END=substr($monday_END,0,2).":".substr($monday_END,2,2).":00";
+
+ if($ct_row["ct_monday_stop"]>2400) {
+ $monday_multiday_END=$ct_row["ct_monday_stop"]-2400;
+ while(strlen($monday_multiday_END)<4) {
+ $monday_multiday_END="0".$monday_multiday_END;
+ }
+ $monday_multiday_END=substr($monday_multiday_END,0,2).":".substr($monday_multiday_END,2,2).":00";
+ array_push($call_time_ranges, array("2", "$monday_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("3", "00:00:00", "$monday_multiday_END"));
+ } else {
+ array_push($call_time_ranges, array("2", "$monday_BEGIN", "$monday_END"));
+ }
+ }
+
+ if ($ct_row["ct_tuesday_start"]==0 && $ct_row["ct_tuesday_stop"]==0) {
+ if ($multiday_default=="yes") {
+ array_push($call_time_ranges, array("3", "$default_time_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("4", "00:00:00", "$multiday_default_END"));
+ } else {
+ array_push($call_time_ranges, array("3", "$default_time_BEGIN", "$default_time_END"));
+ }
+ } else {
+ $tuesday_BEGIN=$ct_row["ct_tuesday_start"];
+ $tuesday_END=$ct_row["ct_tuesday_stop"];
+ while (strlen($tuesday_BEGIN)<4) {$tuesday_BEGIN="0".$tuesday_BEGIN;}
+ while (strlen($tuesday_END)<4) {$tuesday_END="0".$tuesday_END;}
+ $tuesday_BEGIN=substr($tuesday_BEGIN,0,2).":".substr($tuesday_BEGIN,2,2).":00";
+ $tuesday_END=substr($tuesday_END,0,2).":".substr($tuesday_END,2,2).":00";
+
+ if($ct_row["ct_tuesday_stop"]>2400) {
+ $tuesday_multiday_END=$ct_row["ct_tuesday_stop"]-2400;
+ while(strlen($tuesday_multiday_END)<4) {
+ $tuesday_multiday_END="0".$tuesday_multiday_END;
+ }
+ $tuesday_multiday_END=substr($tuesday_multiday_END,0,2).":".substr($tuesday_multiday_END,2,2).":00";
+ array_push($call_time_ranges, array("3", "$tuesday_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("4", "00:00:00", "$tuesday_multiday_END"));
+ } else {
+ array_push($call_time_ranges, array("3", "$tuesday_BEGIN", "$tuesday_END"));
+ }
+ }
+
+ if ($ct_row["ct_wednesday_start"]==0 && $ct_row["ct_wednesday_stop"]==0) {
+ if ($multiday_default=="yes") {
+ array_push($call_time_ranges, array("4", "$default_time_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("5", "00:00:00", "$multiday_default_END"));
+ } else {
+ array_push($call_time_ranges, array("4", "$default_time_BEGIN", "$default_time_END"));
+ }
+ } else {
+ $wednesday_BEGIN=$ct_row["ct_wednesday_start"];
+ $wednesday_END=$ct_row["ct_wednesday_stop"];
+ while (strlen($wednesday_BEGIN)<4) {$wednesday_BEGIN="0".$wednesday_BEGIN;}
+ while (strlen($wednesday_END)<4) {$wednesday_END="0".$wednesday_END;}
+ $wednesday_BEGIN=substr($wednesday_BEGIN,0,2).":".substr($wednesday_BEGIN,2,2).":00";
+ $wednesday_END=substr($wednesday_END,0,2).":".substr($wednesday_END,2,2).":00";
+
+ if($ct_row["ct_wednesday_stop"]>2400) {
+ $wednesday_multiday_END=$ct_row["ct_wednesday_stop"]-2400;
+ while(strlen($wednesday_multiday_END)<4) {
+ $wednesday_multiday_END="0".$wednesday_multiday_END;
+ }
+ $wednesday_multiday_END=substr($wednesday_multiday_END,0,2).":".substr($wednesday_multiday_END,2,2).":00";
+ array_push($call_time_ranges, array("4", "$wednesday_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("5", "00:00:00", "$wednesday_multiday_END"));
+ } else {
+ array_push($call_time_ranges, array("4", "$wednesday_BEGIN", "$wednesday_END"));
+ }
+ }
+
+ if ($ct_row["ct_thursday_start"]==0 && $ct_row["ct_thursday_stop"]==0) {
+ if ($multiday_default=="yes") {
+ array_push($call_time_ranges, array("5", "$default_time_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("6", "00:00:00", "$multiday_default_END"));
+ } else {
+ array_push($call_time_ranges, array("5", "$default_time_BEGIN", "$default_time_END"));
+ }
+ } else {
+ $thursday_BEGIN=$ct_row["ct_thursday_start"];
+ $thursday_END=$ct_row["ct_thursday_stop"];
+ while (strlen($thursday_BEGIN)<4) {$thursday_BEGIN="0".$thursday_BEGIN;}
+ while (strlen($thursday_END)<4) {$thursday_END="0".$thursday_END;}
+ $thursday_BEGIN=substr($thursday_BEGIN,0,2).":".substr($thursday_BEGIN,2,2).":00";
+ $thursday_END=substr($thursday_END,0,2).":".substr($thursday_END,2,2).":00";
+
+ if($ct_row["ct_thursday_stop"]>2400) {
+ $thursday_multiday_END=$ct_row["ct_thursday_stop"]-2400;
+ while(strlen($thursday_multiday_END)<4) {
+ $thursday_multiday_END="0".$thursday_multiday_END;
+ }
+ $thursday_multiday_END=substr($thursday_multiday_END,0,2).":".substr($thursday_multiday_END,2,2).":00";
+ array_push($call_time_ranges, array("5", "$thursday_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("6", "00:00:00", "$thursday_multiday_END"));
+ } else {
+ array_push($call_time_ranges, array("5", "$thursday_BEGIN", "$thursday_END"));
+ }
+ }
+
+ if ($ct_row["ct_friday_start"]==0 && $ct_row["ct_friday_stop"]==0) {
+ if ($multiday_default=="yes") {
+ array_push($call_time_ranges, array("6", "$default_time_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("7", "00:00:00", "$multiday_default_END"));
+ } else {
+ array_push($call_time_ranges, array("6", "$default_time_BEGIN", "$default_time_END"));
+ }
+ } else {
+ $friday_BEGIN=$ct_row["ct_friday_start"];
+ $friday_END=$ct_row["ct_friday_stop"];
+ while (strlen($friday_BEGIN)<4) {$friday_BEGIN="0".$friday_BEGIN;}
+ while (strlen($friday_END)<4) {$friday_END="0".$friday_END;}
+ $friday_BEGIN=substr($friday_BEGIN,0,2).":".substr($friday_BEGIN,2,2).":00";
+ $friday_END=substr($friday_END,0,2).":".substr($friday_END,2,2).":00";
+
+ if($ct_row["ct_friday_stop"]>2400) {
+ $friday_multiday_END=$ct_row["ct_friday_stop"]-2400;
+ while(strlen($friday_multiday_END)<4) {
+ $friday_multiday_END="0".$friday_multiday_END;
+ }
+ $friday_multiday_END=substr($friday_multiday_END,0,2).":".substr($friday_multiday_END,2,2).":00";
+ array_push($call_time_ranges, array("6", "$friday_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("7", "00:00:00", "$friday_multiday_END"));
+ } else {
+ array_push($call_time_ranges, array("6", "$friday_BEGIN", "$friday_END"));
+ }
+ }
+
+ if ($ct_row["ct_saturday_start"]==0 && $ct_row["ct_saturday_stop"]==0) {
+ if ($multiday_default=="yes") {
+ array_push($call_time_ranges, array("7", "$default_time_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("1", "00:00:00", "$multiday_default_END"));
+ } else {
+ array_push($call_time_ranges, array("7", "$default_time_BEGIN", "$default_time_END"));
+ }
+ } else {
+ $saturday_BEGIN=$ct_row["ct_saturday_start"];
+ $saturday_END=$ct_row["ct_saturday_stop"];
+ while (strlen($saturday_BEGIN)<4) {$saturday_BEGIN="0".$saturday_BEGIN;}
+ while (strlen($saturday_END)<4) {$saturday_END="0".$saturday_END;}
+ $saturday_BEGIN=substr($saturday_BEGIN,0,2).":".substr($saturday_BEGIN,2,2).":00";
+ $saturday_END=substr($saturday_END,0,2).":".substr($saturday_END,2,2).":00";
+
+ if($ct_row["ct_saturday_stop"]>2400) {
+ $saturday_multiday_END=$ct_row["ct_saturday_stop"]-2400;
+ while(strlen($saturday_multiday_END)<4) {
+ $saturday_multiday_END="0".$saturday_multiday_END;
+ }
+ $saturday_multiday_END=substr($saturday_multiday_END,0,2).":".substr($saturday_multiday_END,2,2).":00";
+ array_push($call_time_ranges, array("7", "$saturday_BEGIN", "23:59:59"));
+ array_push($call_time_ranges, array("1", "00:00:00", "$saturday_multiday_END"));
+ } else {
+ array_push($call_time_ranges, array("7", "$saturday_BEGIN", "$saturday_END"));
+ }
+ }
+
+ }
+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";}
+ }
+ # CREATE CALL TIME ARRAYS
+ for ($i=1; $i<=7; $i++)
+ {
+ array_push($call_time_ranges, array("$i", "$time_BEGIN", "$time_END"));
+ }
+
+ }
+$query_date_BEGIN = "$query_date $time_BEGIN";
+$query_date_END = "$end_date $time_END";
+
+# GENERATE CALL TIME CLAUSE - GET MAX/MIN TIMES FOR GRAPH
+$orig_call_time_clause="and ( ";
+for ($x=0; $x)='".$call_time_ranges[$x][0]."' and time()>='".$call_time_ranges[$x][1]."' and time()<='".$call_time_ranges[$x][2]."') OR ";
+
+ $graph_start_time = $call_time_ranges[$x][1];
+ $graph_start_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $graph_start_time);
+ sscanf($graph_start_time, "%d:%d:%d", $hours, $minutes, $seconds);
+ $graph_seconds = $hours * 3600 + $minutes * 60 + $seconds;
+ if (!$min_graph_seconds || $graph_seconds<$min_graph_seconds) {$min_graph_seconds=$graph_seconds; $min_graph_start_time=$graph_start_time;}
+
+ $graph_end_time = $call_time_ranges[$x][2];
+ $graph_end_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $graph_end_time);
+ sscanf($graph_end_time, "%d:%d:%d", $hours, $minutes, $seconds);
+ $graph_seconds = $hours * 3600 + $minutes * 60 + $seconds;
+ if (!$max_graph_seconds || $graph_seconds>$max_graph_seconds) {$max_graph_seconds=$graph_seconds; $max_graph_end_time=$graph_end_time;}
+}
+$orig_call_time_clause=preg_replace('/ OR $/', '', $orig_call_time_clause);
+$orig_call_time_clause.=" )";
+$calldate_call_time_clause=preg_replace('//', 'call_date', $orig_call_time_clause);
+$starttime_call_time_clause=preg_replace('//', 'start_time', $orig_call_time_clause);
+
+
+# Calculate first record in interval and last
+if (!$min_graph_start_time){$min_graph_start_time="00:00:00";}
+if (!$max_graph_start_time){$max_graph_start_time="23:59:59";}
+$time_BEGIN_array=explode(":", $min_graph_start_time);
+$first_shift_record=(4*$time_BEGIN_array[0])+(ceil($time_BEGIN_array[1]/15));
+$time_END_array=explode(":", $max_graph_end_time);
+$last_shift_record=(4*$time_END_array[0])+(ceil($time_END_array[1]/15));
+
+if ($CHAT=='Y')
+ {
+ $MAIN.=_QXZ("Inbound Chat Stats").": $group_string $NOW_TIME "._QXZ("DOWNLOAD")."\n";
+ $CSV_text1.="\""._QXZ("Inbound Chat Stats").":\",\"$group_string\",\"$NOW_TIME\"\n";
+ }
+elseif ($EMAIL=='Y')
+ {
+ $MAIN.=_QXZ("Inbound Email Stats").": $group_string $NOW_TIME "._QXZ("DOWNLOAD")."\n";
+ $CSV_text1.="\""._QXZ("Inbound Email Stats").":\",\"$group_string\",\"$NOW_TIME\"\n";
+ }
+else
+ {
+ $MAIN.=_QXZ("Inbound Call Stats").": $group_string $NOW_TIME "._QXZ("DOWNLOAD")."\n";
+ $CSV_text1.="\""._QXZ("Inbound Call Stats").":\",\"$group_string\",\"$NOW_TIME\"\n";
+ }
+
+
+
+if ($DID=='Y')
+ {
+ $stmt="select did_id from vicidial_inbound_dids where did_pattern IN($group_SQL) $LOGadmin_viewable_groupsSQL;";
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$MAIN.="$stmt\n";}
+ $dids_to_print = mysqli_num_rows($rslt);
+ $i=0;
+ while ($i < $dids_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+ $did_id[$i] = $row[0];
+ $did_SQL .= "'$row[0]',";
+ $i++;
+ }
+ $did_SQL = preg_replace('/,$/i', '',$did_SQL);
+ if (strlen($did_SQL)<3) {$did_SQL="''";}
+
+ $stmt="select uniqueid from ".$vicidial_did_log_table." where did_id IN($did_SQL);";
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$MAIN.="$stmt\n";}
+ $unids_to_print = mysqli_num_rows($rslt);
+ $i=0;
+ while ($i < $unids_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+ $unid_SQL .= "'$row[0]',";
+ $i++;
+ }
+ $unid_SQL = preg_replace('/,$/i', '',$unid_SQL);
+ if (strlen($unid_SQL)<3) {$unid_SQL="''";}
+
+ if ($DB > 0)
+ {$MAIN.="|$did_SQL|$unid_SQL|\n";}
+
+ }
+
+if ($group_ct > 1)
+ {
+ $ASCII_text.="\n";
+ $ASCII_text.="---------- "._QXZ("MULTI-GROUP BREAKDOWN").":\n";
+
+ $CSV_text1.="\n\""._QXZ("MULTI-GROUP BREAKDOWN").":\"\n";
+
+ if ($CHAT=='Y')
+ {
+ $ASCII_text.="+----------------------+---------+---------+---------+---------+\n";
+ $ASCII_text.="| "._QXZ("CHAT",20)." | "._QXZ("CHATS",7)." | "._QXZ("DROPS",7)." | "._QXZ("DROP",5)." % | "._QXZ("IVR",7)." |\n";
+ $ASCII_text.="+----------------------+---------+---------+---------+---------+\n";
+ $CSV_text1.="\""._QXZ("CHAT")."\",\""._QXZ("CALLS")."\",\""._QXZ("DROPS")."\",\""._QXZ("DROP")." %\",\""._QXZ("IVR")."\"\n";
+ }
+ else if ($EMAIL=='Y')
+ {
+ $ASCII_text.="+----------------------+---------+---------+---------+---------+\n";
+ $ASCII_text.="| "._QXZ("EMAIL",20)." | "._QXZ("EMAILS",7)." | "._QXZ("DROPS",7)." | "._QXZ("DROP",5)." % | "._QXZ("IVR",7)." |\n";
+ $ASCII_text.="+----------------------+---------+---------+---------+---------+\n";
+ $CSV_text1.="\""._QXZ("EMAIL")."\",\""._QXZ("CALLS")."\",\""._QXZ("DROPS")."\",\""._QXZ("DROP")." %\",\""._QXZ("IVR")."\"\n";
+ }
+ else if ($DID=='Y')
+ {
+ $ASCII_text.="+----------------------+---------+---------+---------+---------+\n";
+ $ASCII_text.="| "._QXZ("DID",20)." | "._QXZ("CALLS",7)." | "._QXZ("DROPS",7)." | "._QXZ("DROP",5)." % | "._QXZ("IVR",7)." |\n";
+ $ASCII_text.="+----------------------+---------+---------+---------+---------+\n";
+ $CSV_text1.="\""._QXZ("DID")."\",\""._QXZ("CALLS")."\",\""._QXZ("DROPS")."\",\""._QXZ("DROP")." %\",\""._QXZ("IVR")."\"\n";
+ }
+ else
+ {
+ $ASCII_text.="+----------------------+---------+---------+---------+---------+\n";
+ $ASCII_text.="| "._QXZ("IN-GROUP",20)." | "._QXZ("CALLS",7)." | "._QXZ("DROPS",7)." | "._QXZ("DROP",5)." % | "._QXZ("IVR",7)." |\n";
+ $ASCII_text.="+----------------------+---------+---------+---------+---------+\n";
+ $CSV_text1.="\""._QXZ("IN-GROUP")."\",\""._QXZ("CALLS")."\",\""._QXZ("DROPS")."\",\""._QXZ("DROP")." %\",\""._QXZ("IVR")."\"\n";
+ }
+
+ $i=0;
+ while($i < $group_ct)
+ {
+ $did_id[$i]='0';
+ $DIDunid_SQL='';
+ $stmt="select did_id from vicidial_inbound_dids where did_pattern='$group[$i]';";
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$ASCII_text.="$stmt\n";}
+ $Sdids_to_print = mysqli_num_rows($rslt);
+ if ($Sdids_to_print > 0)
+ {
+ $row=mysqli_fetch_row($rslt);
+ $did_id[$i] = $row[0];
+ }
+
+ $stmt="select uniqueid from ".$vicidial_did_log_table." where did_id='$did_id[$i]';";
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$ASCII_text.="$stmt\n";}
+ $DIDunids_to_print = mysqli_num_rows($rslt);
+ $k=0;
+ while ($k < $DIDunids_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+ $DIDunid_SQL .= "'$row[0]',";
+ $k++;
+ }
+ $DIDunid_SQL = preg_replace('/,$/i', '',$DIDunid_SQL);
+ if (strlen($DIDunid_SQL)<3) {$DIDunid_SQL="''";}
+
+ $stmt="select count(*),sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id='$group[$i]';";
+ if ($DID=='Y')
+ {
+ $stmt="select count(*),sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($DIDunid_SQL);";
+ }
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$ASCII_text.="$stmt\n";}
+ $row=mysqli_fetch_row($rslt);
+
+ $stmt="select count(*) from ".$live_inbound_log_table." where start_time >= '$query_date_BEGIN' and start_time <= '$query_date_END' $starttime_call_time_clause and comment_a='$group[$i]' and comment_b='START';";
+ if ($DID=='Y')
+ {
+ $stmt="select count(*) from ".$live_inbound_log_table." where start_time >= '$query_date_BEGIN' and start_time <= '$query_date_END' $starttime_call_time_clause and uniqueid IN($DIDunid_SQL);";
+ }
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$ASCII_text.="$stmt\n";}
+ $rowx=mysqli_fetch_row($rslt);
+
+ $stmt="select count(*),sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id='$group[$i]' and status IN('DROP','XDROP') and (length_in_sec <= 49999 or length_in_sec is null);";
+ if ($DID=='Y')
+ {
+ $stmt="select count(*),sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and status IN('DROP','XDROP') and (length_in_sec <= 49999 or length_in_sec is null) and uniqueid IN($DIDunid_SQL);";
+ }
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$ASCII_text.="$stmt\n";}
+ $rowy=mysqli_fetch_row($rslt);
+ if ($row[0]>$max_value) {$max_value=$row[0];}
+
+ $groupDISPLAY = sprintf("%20s", $group[$i]);
+ $gTOTALcalls = sprintf("%7s", $row[0]);
+ $gIVRcalls = sprintf("%7s", $rowx[0]);
+ $gDROPcalls = sprintf("%7s", $rowy[0]);
+ $gDROPpercent = (MathZDC($gDROPcalls, $gTOTALcalls) * 100);
+ $gDROPpercent = round($gDROPpercent, 2);
+ $gDROPpercent = sprintf("%6s", $gDROPpercent);
+
+ $ASCII_text.="| $groupDISPLAY | $gTOTALcalls | $gDROPcalls | $gDROPpercent% | $gIVRcalls |\n";
+ $CSV_text1.="\"$groupDISPLAY\",\"$gTOTALcalls\",\"$gDROPcalls\",\"$gDROPpercent%\",\"$gIVRcalls\"\n";
+ $graph_data_ary[$i][0]=$groupDISPLAY;
+ $graph_data_ary[$i][1]=$gTOTALcalls;
+ $graph_data_ary[$i][2]=$gDROPcalls;
+ $graph_data_ary[$i][3]=$gDROPpercent;
+ $graph_data_ary[$i][4]=$gIVRcalls;
+
+ $i++;
+ }
+
+ $ASCII_text.="+----------------------+---------+---------+---------+---------+\n";
+
+ }
+
+ if ($report_display_type=="HTML") {
+ $max_value=1;
+ $graph_height=240;
+ $scale = 1;
+ $w=0;
+ for ($i=0; $i$max_value) {$max_value=$graph_data_ary[$i][1];}
+ if ($graph_data_ary[$i][1]>0) {$w++;}
+ }
+ $scale = MathZDC($graph_height, $max_value);
+
+
+ $GRAPH_text.=""._QXZ("MULTI-GROUP BREAKDOWN")."| "._QXZ("GROUP")." | "._QXZ("IVRS")." / "._QXZ("DROPS")." / "._QXZ("CALLS")."  | ";
+ for ($d=0; $d0) {
+ $graph_data_ary[$d][0]=preg_replace('/\s/', "", $graph_data_ary[$d][0]);
+ $GRAPH_text.=" ".$graph_data_ary[$d][0]." ".$graph_data_ary[$d][3]."% drops | \n";
+ if ($graph_data_ary[$d][1]>0) {
+ $GRAPH_text.="- ".$graph_data_ary[$d][1]."
";
+ if ($graph_data_ary[$d][2]>0) {
+ $GRAPH_text.="- ".$graph_data_ary[$d][2]."
";
+ }
+ if ($graph_data_ary[$d][4]>0) {
+ $GRAPH_text.="- ".$graph_data_ary[$d][4]."
";
+ }
+ $GRAPH_text.=" \n";
+ } else {
+ $GRAPH_text.="0";
+ }
+ $GRAPH_text.=" | \n";
+ }
+ }
+ $GRAPH_text.="
";
+
+
+ $MAIN.=$GRAPH_text;
+ }
+ else
+ {
+ $MAIN.=$ASCII_text;
+ }
+
+$MAIN.="\n";
+$MAIN.=_QXZ("Time range").": $query_date_BEGIN "._QXZ("to")." $query_date_END\n\n";
+$MAIN.="---------- "._QXZ("TOTALS")."\n";
+
+$CSV_text1.="\n\""._QXZ("Time range").":\",\"$query_date_BEGIN\",\""._QXZ("to")."\",\"$query_date_END\"\n\n";
+
+$stmt="select count(*),sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL);";
+if ($DID=='Y')
+ {
+ $stmt="select count(*),sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL);";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$MAIN.="$stmt\n";}
+$row=mysqli_fetch_row($rslt);
+
+$stmt="select count(*),sum(queue_seconds) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');";
+if ($DID=='Y')
+ {
+ $stmt="select count(*),sum(queue_seconds) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL') and uniqueid IN($unid_SQL);";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$MAIN.="$stmt\n";}
+$rowy=mysqli_fetch_row($rslt);
+
+$stmt="select count(*) from ".$live_inbound_log_table." where start_time >= '$query_date_BEGIN' and start_time <= '$query_date_END' $starttime_call_time_clause and comment_a IN($group_SQL) and comment_b='START';";
+if ($DID=='Y')
+ {
+ $stmt="select count(*) from ".$live_inbound_log_table." where start_time >= '$query_date_BEGIN' and start_time <= '$query_date_END' $starttime_call_time_clause and uniqueid IN($unid_SQL);";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$MAIN.="$stmt\n";}
+$rowx=mysqli_fetch_row($rslt);
+
+$TOTALcalls = sprintf("%10s", $row[0]);
+$IVRcalls = sprintf("%10s", $rowx[0]);
+$TOTALsec = $row[1];
+
+$average_call_seconds = MathZDC($TOTALsec, $row[0]);
+$average_call_seconds = round($average_call_seconds, 0);
+$average_call_seconds = sprintf("%10s", $average_call_seconds);
+
+$ANSWEREDcalls = sprintf("%10s", $rowy[0]);
+
+$ANSWEREDpercent = (MathZDC($ANSWEREDcalls, $TOTALcalls) * 100);
+$ANSWEREDpercent = round($ANSWEREDpercent, 0);
+
+$average_answer_seconds = MathZDC($rowy[1], $rowy[0]);
+$average_answer_seconds = round($average_answer_seconds, 2);
+$average_answer_seconds = sprintf("%10s", $average_answer_seconds);
+
+if ($CHAT=='Y')
+ {
+ $MAIN.=_QXZ("Total Chats taken in to this In-Group:",47)."$TOTALcalls\n";
+ $MAIN.=_QXZ("Average Chat Length for all Chats:",47)."$average_call_seconds "._QXZ("seconds")."\n";
+ $MAIN.=_QXZ("Answered Chats:",47)."$ANSWEREDcalls $ANSWEREDpercent%\n";
+ $MAIN.=_QXZ("Average queue time for Answered Chats:",47)."$average_answer_seconds "._QXZ("seconds")."\n";
+ $MAIN.=_QXZ("Chats taken into the IVR for this In-Group:",47)."$IVRcalls\n";
+
+ $CSV_text1.="\""._QXZ("Total Chats taken in to this In-Group").":\",\"$TOTALcalls\"\n";
+ $CSV_text1.="\""._QXZ("Average Chat Length for all Chats").":\",\"$average_call_seconds "._QXZ("seconds")."\"\n";
+ $CSV_text1.="\""._QXZ("Answered Chats").":\",\"$ANSWEREDcalls\",\"$ANSWEREDpercent%\"\n";
+ $CSV_text1.="\""._QXZ("Average queue time for Answered Chats").":\",\"$average_answer_seconds "._QXZ("seconds")."\"\n";
+ $CSV_text1.="\""._QXZ("Chats taken into the IVR for this In-Group").":\",\"$IVRcalls\"\n";
+ }
+elseif ($EMAIL=='Y')
+ {
+ $MAIN.=_QXZ("Total Emails taken in to this In-Group:",47)."$TOTALcalls\n";
+ $MAIN.=_QXZ("Average Email Length for all Emails:",47)."$average_call_seconds "._QXZ("seconds")."\n";
+ $MAIN.=_QXZ("Answered Emails:",47)."$ANSWEREDcalls $ANSWEREDpercent%\n";
+ $MAIN.=_QXZ("Average queue time for Answered Emails:",47)."$average_answer_seconds "._QXZ("seconds")."\n";
+ $MAIN.=_QXZ("Emails taken into the IVR for this In-Group:",47)."$IVRcalls\n";
+
+ $CSV_text1.="\""._QXZ("Total Emails taken in to this In-Group").":\",\"$TOTALcalls\"\n";
+ $CSV_text1.="\""._QXZ("Average Email Length for all Emails").":\",\"$average_call_seconds "._QXZ("seconds")."\"\n";
+ $CSV_text1.="\""._QXZ("Answered Emails").":\",\"$ANSWEREDcalls\",\"$ANSWEREDpercent%\"\n";
+ $CSV_text1.="\""._QXZ("Average queue time for Answered Emails").":\",\"$average_answer_seconds "._QXZ("seconds")."\"\n";
+ $CSV_text1.="\""._QXZ("Emails taken into the IVR for this In-Group").":\",\"$IVRcalls\"\n";
+ }
+else
+ {
+ $MAIN.=_QXZ("Total calls taken in to this In-Group:",47)."$TOTALcalls\n";
+ $MAIN.=_QXZ("Average Call Length for all Calls:",47)."$average_call_seconds "._QXZ("seconds")."\n";
+ $MAIN.=_QXZ("Answered Calls:",47)."$ANSWEREDcalls $ANSWEREDpercent%\n";
+ $MAIN.=_QXZ("Average queue time for Answered Calls:",47)."$average_answer_seconds "._QXZ("seconds")."\n";
+ $MAIN.=_QXZ("Calls taken into the IVR for this In-Group:",47)."$IVRcalls\n";
+
+ $CSV_text1.="\""._QXZ("Total calls taken in to this In-Group").":\",\"$TOTALcalls\"\n";
+ $CSV_text1.="\""._QXZ("Average Call Length for all Calls").":\",\"$average_call_seconds "._QXZ("seconds")."\"\n";
+ $CSV_text1.="\""._QXZ("Answered Calls").":\",\"$ANSWEREDcalls\",\"$ANSWEREDpercent%\"\n";
+ $CSV_text1.="\""._QXZ("Average queue time for Answered Calls").":\",\"$average_answer_seconds "._QXZ("seconds")."\"\n";
+ $CSV_text1.="\""._QXZ("Calls taken into the IVR for this In-Group").":\",\"$IVRcalls\"\n";
+ }
+
+$MAIN.="\n";
+$MAIN.="---------- "._QXZ("DROPS")."\n";
+
+$CSV_text1.="\n\""._QXZ("DROPS")."\"\n";
+
+$stmt="select count(*),sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status IN('DROP','XDROP') and (length_in_sec <= 49999 or length_in_sec is null);";
+if ($DID=='Y')
+ {
+ $stmt="select count(*),sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and status IN('DROP','XDROP') and (length_in_sec <= 49999 or length_in_sec is null) and uniqueid IN($unid_SQL);";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$MAIN.="$stmt\n";}
+$row=mysqli_fetch_row($rslt);
+
+$DROPcalls = sprintf("%10s", $row[0]);
+$DROPpercent = (MathZDC($DROPcalls, $TOTALcalls) * 100);
+$DROPpercent = round($DROPpercent, 0);
+
+$average_hold_seconds = MathZDC($row[1], $row[0]);
+$average_hold_seconds = round($average_hold_seconds, 0);
+$average_hold_seconds = sprintf("%10s", $average_hold_seconds);
+
+$DROP_ANSWEREDpercent = (MathZDC($DROPcalls, $ANSWEREDcalls) * 100);
+$DROP_ANSWEREDpercent = round($DROP_ANSWEREDpercent, 0);
+
+if ($CHAT=='Y')
+ {
+ $MAIN.=_QXZ("Total DROP Chats:",47)."$DROPcalls $DROPpercent% "._QXZ("drop/answered").": $DROP_ANSWEREDpercent%\n";
+ $MAIN.=_QXZ("Average hold time for DROP Chats:",47)."$average_hold_seconds "._QXZ("seconds")."\n";
+
+ $CSV_text1.="\"Total DROP Chats:\",\"$DROPcalls\",\"$DROPpercent%\",\""._QXZ("drop/answered").":\",\"$DROP_ANSWEREDpercent%\"\n";
+ $CSV_text1.="\"Average hold time for DROP Chats:\",\"$average_hold_seconds "._QXZ("seconds")."\"\n";
+ }
+elseif ($EMAIL=='Y')
+ {
+ $MAIN.=_QXZ("Total DROP Emails:",47)."$DROPcalls $DROPpercent% "._QXZ("drop/answered").": $DROP_ANSWEREDpercent%\n";
+ $MAIN.=_QXZ("Average hold time for DROP Emails:",47)."$average_hold_seconds "._QXZ("seconds")."\n";
+
+ $CSV_text1.="\"Total DROP Emails:\",\"$DROPcalls\",\"$DROPpercent%\",\""._QXZ("drop/answered").":\",\"$DROP_ANSWEREDpercent%\"\n";
+ $CSV_text1.="\"Average hold time for DROP Emails:\",\"$average_hold_seconds "._QXZ("seconds")."\"\n";
+ }
+else
+ {
+ $MAIN.=_QXZ("Total DROP Calls:",47)."$DROPcalls $DROPpercent% "._QXZ("drop/answered").": $DROP_ANSWEREDpercent%\n";
+ $MAIN.=_QXZ("Average hold time for DROP Calls:",47)."$average_hold_seconds "._QXZ("seconds")."\n";
+
+ $CSV_text1.="\""._QXZ("Total DROP Calls").":\",\"$DROPcalls\",\"$DROPpercent%\",\""._QXZ("drop/answered").":\",\"$DROP_ANSWEREDpercent%\"\n";
+ $CSV_text1.="\""._QXZ("Average hold time for DROP Calls").":\",\"$average_hold_seconds "._QXZ("seconds")."\"\n";
+ }
+
+if (strlen($group_SQL)>3)
+ {
+ if ($DID!='Y')
+ {
+ $stmt = "SELECT answer_sec_pct_rt_stat_one,answer_sec_pct_rt_stat_two from vicidial_inbound_groups where group_id IN($group_SQL) order by answer_sec_pct_rt_stat_one desc limit 1;";
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$MAIN.="$stmt\n";}
+ $row=mysqli_fetch_row($rslt);
+ $Sanswer_sec_pct_rt_stat_one = $row[0];
+ $Sanswer_sec_pct_rt_stat_two = $row[1];
+
+ $stmt = "SELECT count(*) from ".$vicidial_closer_log_table." where campaign_id IN($group_SQL) and call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and queue_seconds <= $Sanswer_sec_pct_rt_stat_one and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');";
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$MAIN.="$stmt\n";}
+ $row=mysqli_fetch_row($rslt);
+ $answer_sec_pct_rt_stat_one = $row[0];
+
+ $stmt = "SELECT count(*) from ".$vicidial_closer_log_table." where campaign_id IN($group_SQL) and call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and queue_seconds <= $Sanswer_sec_pct_rt_stat_two and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL');";
+ $rslt=mysql_to_mysqli($stmt, $link);
+ if ($DB) {$MAIN.="$stmt\n";}
+ $row=mysqli_fetch_row($rslt);
+ $answer_sec_pct_rt_stat_two = $row[0];
+
+ $PCTanswer_sec_pct_rt_stat_one = (MathZDC($answer_sec_pct_rt_stat_one, $ANSWEREDcalls) * 100);
+ $PCTanswer_sec_pct_rt_stat_one = round($PCTanswer_sec_pct_rt_stat_one, 0);
+ #$PCTanswer_sec_pct_rt_stat_one = sprintf("%10s", $PCTanswer_sec_pct_rt_stat_one);
+ $PCTanswer_sec_pct_rt_stat_two = (MathZDC($answer_sec_pct_rt_stat_two, $ANSWEREDcalls) * 100);
+ $PCTanswer_sec_pct_rt_stat_two = round($PCTanswer_sec_pct_rt_stat_two, 0);
+ #$PCTanswer_sec_pct_rt_stat_two = sprintf("%10s", $PCTanswer_sec_pct_rt_stat_two);
+ }
+ }
+
+if ($CHAT=='Y')
+ {
+ $MAIN.="\n";
+ $MAIN.="---------- "._QXZ("CUSTOM INDICATORS")."\n";
+ $MAIN.="GDE "._QXZ("(Answered/Total chats taken in to this In-Group):",50)." $ANSWEREDpercent%\n";
+ $MAIN.="ACR "._QXZ("(Dropped/Answered):",50)." $DROP_ANSWEREDpercent%\n";
+
+ $CSV_text1.="\n\""._QXZ("CUSTOM INDICATORS")."\"\n";
+ $CSV_text1.="\"GDE "._QXZ("(Answered/Total chats taken in to this In-Group)").":\",\"$ANSWEREDpercent%\"\n";
+ $CSV_text1.="\"ACR "._QXZ("(Dropped/Answered)").":\",\"$DROP_ANSWEREDpercent%\"\n";
+ }
+elseif ($EMAIL=='Y')
+ {
+ $MAIN.="\n";
+ $MAIN.="---------- "._QXZ("CUSTOM INDICATORS")."\n";
+ $MAIN.="GDE "._QXZ("(Answered/Total emails taken in to this In-Group):",50)." $ANSWEREDpercent%\n";
+ $MAIN.="ACR "._QXZ("(Dropped/Answered):",50)." $DROP_ANSWEREDpercent%\n";
+
+ $CSV_text1.="\n\""._QXZ("CUSTOM INDICATORS")."\"\n";
+ $CSV_text1.="\"GDE "._QXZ("(Answered/Total emails taken in to this In-Group)").":\",\"$ANSWEREDpercent%\"\n";
+ $CSV_text1.="\"ACR "._QXZ("(Dropped/Answered)").":\",\"$DROP_ANSWEREDpercent%\"\n";
+ }
+else
+ {
+ $MAIN.="\n";
+ $MAIN.="---------- "._QXZ("CUSTOM INDICATORS")."\n";
+ $MAIN.="GDE "._QXZ("(Answered/Total calls taken in to this In-Group):",50)." $ANSWEREDpercent%\n";
+ $MAIN.="ACR "._QXZ("(Dropped/Answered):",50)." $DROP_ANSWEREDpercent%\n";
+
+ $CSV_text1.="\n\""._QXZ("CUSTOM INDICATORS")."\"\n";
+ $CSV_text1.="\"GDE "._QXZ("(Answered/Total calls taken in to this In-Group)").":\",\"$ANSWEREDpercent%\"\n";
+ $CSV_text1.="\"ACR "._QXZ("(Dropped/Answered)").":\",\"$DROP_ANSWEREDpercent%\"\n";
+ }
+
+if ($DID!='Y')
+ {
+ $MAIN.="TMR1 "._QXZ("(Answered within %1s seconds/Answered):",50,'',$Sanswer_sec_pct_rt_stat_one)." $PCTanswer_sec_pct_rt_stat_one%\n";
+ $MAIN.="TMR2 "._QXZ("(Answered within %1s seconds/Answered):",50,'',$Sanswer_sec_pct_rt_stat_two)." $PCTanswer_sec_pct_rt_stat_two%\n";
+ $CSV_text1.="\"TMR1 "._QXZ("(Answered within %1s seconds/Answered)",0,'',$Sanswer_sec_pct_rt_stat_one).":\",\"$PCTanswer_sec_pct_rt_stat_one%\"\n";
+ $CSV_text1.="\"TMR2 "._QXZ("(Answered within %1s seconds/Answered)",0,'',$Sanswer_sec_pct_rt_stat_two).":\",\"$PCTanswer_sec_pct_rt_stat_two%\"\n";
+ }
+
+
+# GET LIST OF ALL STATUSES and create SQL from human_answered statuses
+$q=0;
+$stmt = "SELECT status,status_name,human_answered,category from vicidial_statuses;";
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$MAIN.="$stmt\n";}
+$statuses_to_print = mysqli_num_rows($rslt);
+$p=0;
+while ($p < $statuses_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+ $status[$q] = $row[0];
+ $status_name[$q] = $row[1];
+ $human_answered[$q] = $row[2];
+ $category[$q] = $row[3];
+ $statname_list["$status[$q]"] = "$status_name[$q]";
+ $statcat_list["$status[$q]"] = "$category[$q]";
+ $q++;
+ $p++;
+ }
+$stmt = "SELECT status,status_name,human_answered,category from vicidial_campaign_statuses;";
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$MAIN.="$stmt\n";}
+$statuses_to_print = mysqli_num_rows($rslt);
+$p=0;
+while ($p < $statuses_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+ $status[$q] = $row[0];
+ $status_name[$q] = $row[1];
+ $human_answered[$q] = $row[2];
+ $category[$q] = $row[3];
+ $statname_list["$status[$q]"] = "$status_name[$q]";
+ $statcat_list["$status[$q]"] = "$category[$q]";
+ $q++;
+ $p++;
+ }
+
+##############################
+######### CALL QUEUE STATS
+$MAIN.="\n";
+$MAIN.="---------- "._QXZ("QUEUE STATS")."\n";
+
+$CSV_text1.="\n\""._QXZ("QUEUE STATS")."\"\n";
+
+$stmt="select count(*),sum(queue_seconds) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and (queue_seconds > 0);";
+if ($DID=='Y')
+ {
+ $stmt="select count(*),sum(queue_seconds) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and (queue_seconds > 0) and uniqueid IN($unid_SQL);";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$MAIN.="$stmt\n";}
+$row=mysqli_fetch_row($rslt);
+
+$QUEUEcalls = sprintf("%10s", $row[0]);
+$QUEUEpercent = (MathZDC($QUEUEcalls, $TOTALcalls) * 100);
+$QUEUEpercent = round($QUEUEpercent, 0);
+
+$average_queue_seconds = MathZDC($row[1], $row[0]);
+$average_queue_seconds = round($average_queue_seconds, 2);
+$average_queue_seconds = sprintf("%10.2f", $average_queue_seconds);
+
+$average_total_queue_seconds = MathZDC($row[1], $TOTALcalls);
+$average_total_queue_seconds = round($average_total_queue_seconds, 2);
+$average_total_queue_seconds = sprintf("%10.2f", $average_total_queue_seconds);
+
+if ($CHAT=='Y')
+ {
+ $MAIN.=_QXZ("Total Chats That entered Queue:",46)." $QUEUEcalls $QUEUEpercent%\n";
+ $MAIN.=_QXZ("Average QUEUE Length for queue chats:",46)." $average_queue_seconds "._QXZ("seconds")."\n";
+ $MAIN.=_QXZ("Average QUEUE Length across all chats:",46)." $average_total_queue_seconds "._QXZ("seconds")."\n";
+
+ $CSV_text1.="\""._QXZ("Total Chats That entered Queue").":\",\"$QUEUEcalls\",\"$QUEUEpercent%\"\n";
+ $CSV_text1.="\""._QXZ("Average QUEUE Length for queue chats").":\",\"$average_queue_seconds "._QXZ("seconds")."\"\n";
+ $CSV_text1.="\""._QXZ("Average QUEUE Length across all chats").":\",\"$average_total_queue_seconds "._QXZ("seconds")."\"\n";
+ }
+elseif ($EMAIL=='Y')
+ {
+ $MAIN.=_QXZ("Total Emails That entered Queue:",46)." $QUEUEcalls $QUEUEpercent%\n";
+ $MAIN.=_QXZ("Average QUEUE Length for queue emails:",46)." $average_queue_seconds "._QXZ("seconds")."\n";
+ $MAIN.=_QXZ("Average QUEUE Length across all emails:",46)." $average_total_queue_seconds "._QXZ("seconds")."\n";
+
+ $CSV_text1.="\""._QXZ("Total Emails That entered Queue").":\",\"$QUEUEcalls\",\"$QUEUEpercent%\"\n";
+ $CSV_text1.="\""._QXZ("Average QUEUE Length for queue emails").":\",\"$average_queue_seconds "._QXZ("seconds")."\"\n";
+ $CSV_text1.="\""._QXZ("Average QUEUE Length across all emails").":\",\"$average_total_queue_seconds "._QXZ("seconds")."\"\n";
+ }
+else
+ {
+ $MAIN.=_QXZ("Total Calls That entered Queue:",46)." $QUEUEcalls $QUEUEpercent%\n";
+ $MAIN.=_QXZ("Average QUEUE Length for queue calls:",46)." $average_queue_seconds "._QXZ("seconds")."\n";
+ $MAIN.=_QXZ("Average QUEUE Length across all calls:",46)." $average_total_queue_seconds "._QXZ("seconds")."\n";
+
+ $CSV_text1.="\""._QXZ("Total Calls That entered Queue").":\",\"$QUEUEcalls\",\"$QUEUEpercent%\"\n";
+ $CSV_text1.="\""._QXZ("Average QUEUE Length for queue calls").":\",\"$average_queue_seconds "._QXZ("seconds")."\"\n";
+ $CSV_text1.="\""._QXZ("Average QUEUE Length across all calls").":\",\"$average_total_queue_seconds "._QXZ("seconds")."\"\n";
+ }
+
+if ($CHAT=='Y')
+ {
+ $rpt_type_verbiage=_QXZ("CHAT",6);
+ $rpt_type_verbiages=_QXZ("CHATS",6);
+ }
+elseif ($EMAIL=='Y')
+ {
+ $rpt_type_verbiage=_QXZ("EMAIL",6);
+ $rpt_type_verbiages=_QXZ("EMAILS",6);
+ }
+else
+ {
+ $rpt_type_verbiage=_QXZ("CALL",6);
+ $rpt_type_verbiages=_QXZ("CALLS",6);
+ }
+
+##############################
+######### CALL HOLD TIME BREAKDOWN IN SECONDS
+
+$TOTALcalls = 0;
+
+$ASCII_text="\n";
+$ASCII_text.="---------- $rpt_type_verbiage "._QXZ("HOLD TIME BREAKDOWN IN SECONDS",36)." "._QXZ("DOWNLOAD")."\n";
+$ASCII_text.="+-------------------------------------------------------------------------------------------+------------+\n";
+$ASCII_text.="| 0 5 10 15 20 25 30 35 40 45 50 55 60 90 +90 | TOTAL |\n";
+$ASCII_text.="+-------------------------------------------------------------------------------------------+------------+\n";
+
+$CSV_text2.="\n\"$rpt_type_verbiage "._QXZ("HOLD TIME BREAKDOWN IN SECONDS")."\"\n";
+$CSV_text2.="\"\",\"0\",\"5\",\"10\",\"15\",\"20\",\"25\",\"30\",\"35\",\"40\",\"45\",\"50\",\"55\",\"60\",\"90\",\"+90\",\"TOTAL\"\n";
+
+
+$stmt="select count(*),queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) group by queue_seconds;";
+if ($DID=='Y')
+ {
+ $stmt="select count(*),queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) group by queue_seconds;";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$ASCII_text.="$stmt\n";}
+$reasons_to_print = mysqli_num_rows($rslt);
+$i=0;
+$hd_5=0; $hd10=0; $hd15=0; $hd20=0; $hd25=0; $hd30=0; $hd35=0; $hd40=0; $hd45=0; $hd50=0; $hd55=0; $hd60=0; $hd90=0; $hd99=0;
+
+while ($i < $reasons_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+
+ $TOTALcalls = ($TOTALcalls + $row[0]);
+
+ if ($row[1] == 0) {$hd_0 = ($hd_0 + $row[0]);}
+ if ( ($row[1] > 0) and ($row[1] <= 5) ) {$hd_5 = ($hd_5 + $row[0]);}
+ if ( ($row[1] > 5) and ($row[1] <= 10) ) {$hd10 = ($hd10 + $row[0]);}
+ if ( ($row[1] > 10) and ($row[1] <= 15) ) {$hd15 = ($hd15 + $row[0]);}
+ if ( ($row[1] > 15) and ($row[1] <= 20) ) {$hd20 = ($hd20 + $row[0]);}
+ if ( ($row[1] > 20) and ($row[1] <= 25) ) {$hd25 = ($hd25 + $row[0]);}
+ if ( ($row[1] > 25) and ($row[1] <= 30) ) {$hd30 = ($hd30 + $row[0]);}
+ if ( ($row[1] > 30) and ($row[1] <= 35) ) {$hd35 = ($hd35 + $row[0]);}
+ if ( ($row[1] > 35) and ($row[1] <= 40) ) {$hd40 = ($hd40 + $row[0]);}
+ if ( ($row[1] > 40) and ($row[1] <= 45) ) {$hd45 = ($hd45 + $row[0]);}
+ if ( ($row[1] > 45) and ($row[1] <= 50) ) {$hd50 = ($hd50 + $row[0]);}
+ if ( ($row[1] > 50) and ($row[1] <= 55) ) {$hd55 = ($hd55 + $row[0]);}
+ if ( ($row[1] > 55) and ($row[1] <= 60) ) {$hd60 = ($hd60 + $row[0]);}
+ if ( ($row[1] > 60) and ($row[1] <= 90) ) {$hd90 = ($hd90 + $row[0]);}
+ if ($row[1] > 90) {$hd99 = ($hd99 + $row[0]);}
+ $i++;
+ }
+
+$hd_0 = sprintf("%5s", $hd_0);
+$hd_5 = sprintf("%5s", $hd_5);
+$hd10 = sprintf("%5s", $hd10);
+$hd15 = sprintf("%5s", $hd15);
+$hd20 = sprintf("%5s", $hd20);
+$hd25 = sprintf("%5s", $hd25);
+$hd30 = sprintf("%5s", $hd30);
+$hd35 = sprintf("%5s", $hd35);
+$hd40 = sprintf("%5s", $hd40);
+$hd45 = sprintf("%5s", $hd45);
+$hd50 = sprintf("%5s", $hd50);
+$hd55 = sprintf("%5s", $hd55);
+$hd60 = sprintf("%5s", $hd60);
+$hd90 = sprintf("%5s", $hd90);
+$hd99 = sprintf("%5s", $hd99);
+
+$TOTALcalls = sprintf("%10s", $TOTALcalls);
+
+$ASCII_text.="| $hd_0 $hd_5 $hd10 $hd15 $hd20 $hd25 $hd30 $hd35 $hd40 $hd45 $hd50 $hd55 $hd60 $hd90 $hd99 | $TOTALcalls |\n";
+$ASCII_text.="+-------------------------------------------------------------------------------------------+------------+\n";
+
+$CSV_text2.="\"\",\"$hd_0\",\"$hd_5\",\"$hd10\",\"$hd15\",\"$hd20\",\"$hd25\",\"$hd30\",\"$hd35\",\"$hd40\",\"$hd45\",\"$hd50\",\"$hd55\",\"$hd60\",\"$hd90\",\"$hd99\",\"$TOTALcalls\"\n";
+
+
+if ($report_display_type=="HTML") {
+ $stmt="select count(*),round(queue_seconds) as rd_sec from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) group by rd_sec order by rd_sec asc;";
+ $ms_stmt="select queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) order by queue_seconds desc limit 1;";
+ $mc_stmt="select count(*) as ct from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) group by queue_seconds order by ct desc limit 1;";
+ if ($DID=='Y')
+ {
+ $stmt="select count(*),round(queue_seconds) as rd_sec from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) group by rd_sec;";
+ $ms_stmt="select queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) order by queue_seconds desc limit 1;";
+ $mc_stmt="select count(*) as ct from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) group by queue_seconds order by ct desc limit 1;";
+ }
+ if ($DB) {$GRAPH_text.=$stmt."\n";}
+ $ms_rslt=mysql_to_mysqli($ms_stmt, $link);
+ $ms_row=mysqli_fetch_row($ms_rslt);
+ $max_seconds=$ms_row[0];
+ if ($max_seconds>90) {$max_seconds=91;}
+ for ($i=0; $i<=$max_seconds; $i++) {
+ $sec_ary[$i]=0;
+ }
+
+ $mc_rslt=mysql_to_mysqli($mc_stmt, $link);
+ $mc_row=mysqli_fetch_row($mc_rslt);
+ $max_calls=$ms_row[0];
+ if ($max_calls<=10) {
+ while ($maxcalls%5!=0) {
+ $maxcalls++;
+ }
+ } else if ($max_calls<=100) {
+ while ($maxcalls%10!=0) {
+ $maxcalls++;
+ }
+ } else if ($max_calls<=1000) {
+ while ($maxcalls%50!=0) {
+ $maxcalls++;
+ }
+ } else {
+ while ($maxcalls%500!=0) {
+ $maxcalls++;
+ }
+ }
+ $rslt=mysql_to_mysqli($stmt, $link);
+
+ $GRAPH_text="\n";
+ $GRAPH_text.="";
+ $MAIN.=$GRAPH_text;
+ }
+else
+ {
+ $MAIN.=$ASCII_text;
+ }
+
+
+##############################
+######### CALL DROP TIME BREAKDOWN IN SECONDS
+
+$BDdropCALLS = 0;
+
+$ASCII_text="\n";
+$ASCII_text.="---------- $rpt_type_verbiage "._QXZ("DROP TIME BREAKDOWN IN SECONDS")."\n";
+$ASCII_text.="+-------------------------------------------------------------------------------------------+------------+\n";
+$ASCII_text.="| 0 5 10 15 20 25 30 35 40 45 50 55 60 90 +90 | "._QXZ("TOTAL",10)." |\n";
+$ASCII_text.="+-------------------------------------------------------------------------------------------+------------+\n";
+
+$CSV_text2.="\n\"$rpt_type_verbiage "._QXZ("DROP TIME BREAKDOWN IN SECONDS")."\"\n";
+$CSV_text2.="\"\",\"0\",\"5\",\"10\",\"15\",\"20\",\"25\",\"30\",\"35\",\"40\",\"45\",\"50\",\"55\",\"60\",\"90\",\"+90\",\""._QXZ("TOTAL")."\"\n";
+
+$stmt="select count(*),queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status IN('DROP','XDROP') group by queue_seconds;";
+if ($DID=='Y')
+ {
+ $stmt="select count(*),queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) and status IN('DROP','XDROP') group by queue_seconds;";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$ASCII_text.="$stmt\n";}
+$reasons_to_print = mysqli_num_rows($rslt);
+$i=0;
+$dd_0=0; $dd_5=0; $dd10=0; $dd15=0; $dd20=0; $dd25=0; $dd30=0; $dd35=0; $dd40=0; $dd45=0; $dd50=0; $dd55=0; $dd60=0; $dd90=0; $dd99=0;
+
+while ($i < $reasons_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+
+ $BDdropCALLS = ($BDdropCALLS + $row[0]);
+
+ if ($row[1] == 0) {$dd_0 = ($dd_0 + $row[0]);}
+ if ( ($row[1] > 0) and ($row[1] <= 5) ) {$dd_5 = ($dd_5 + $row[0]);}
+ if ( ($row[1] > 5) and ($row[1] <= 10) ) {$dd10 = ($dd10 + $row[0]);}
+ if ( ($row[1] > 10) and ($row[1] <= 15) ) {$dd15 = ($dd15 + $row[0]);}
+ if ( ($row[1] > 15) and ($row[1] <= 20) ) {$dd20 = ($dd20 + $row[0]);}
+ if ( ($row[1] > 20) and ($row[1] <= 25) ) {$dd25 = ($dd25 + $row[0]);}
+ if ( ($row[1] > 25) and ($row[1] <= 30) ) {$dd30 = ($dd30 + $row[0]);}
+ if ( ($row[1] > 30) and ($row[1] <= 35) ) {$dd35 = ($dd35 + $row[0]);}
+ if ( ($row[1] > 35) and ($row[1] <= 40) ) {$dd40 = ($dd40 + $row[0]);}
+ if ( ($row[1] > 40) and ($row[1] <= 45) ) {$dd45 = ($dd45 + $row[0]);}
+ if ( ($row[1] > 45) and ($row[1] <= 50) ) {$dd50 = ($dd50 + $row[0]);}
+ if ( ($row[1] > 50) and ($row[1] <= 55) ) {$dd55 = ($dd55 + $row[0]);}
+ if ( ($row[1] > 55) and ($row[1] <= 60) ) {$dd60 = ($dd60 + $row[0]);}
+ if ( ($row[1] > 60) and ($row[1] <= 90) ) {$dd90 = ($dd90 + $row[0]);}
+ if ($row[1] > 90) {$dd99 = ($dd99 + $row[0]);}
+ $i++;
+ }
+
+$dd_0 = sprintf("%5s", $dd_0);
+$dd_5 = sprintf("%5s", $dd_5);
+$dd10 = sprintf("%5s", $dd10);
+$dd15 = sprintf("%5s", $dd15);
+$dd20 = sprintf("%5s", $dd20);
+$dd25 = sprintf("%5s", $dd25);
+$dd30 = sprintf("%5s", $dd30);
+$dd35 = sprintf("%5s", $dd35);
+$dd40 = sprintf("%5s", $dd40);
+$dd45 = sprintf("%5s", $dd45);
+$dd50 = sprintf("%5s", $dd50);
+$dd55 = sprintf("%5s", $dd55);
+$dd60 = sprintf("%5s", $dd60);
+$dd90 = sprintf("%5s", $dd90);
+$dd99 = sprintf("%5s", $dd99);
+
+$BDdropCALLS = sprintf("%10s", $BDdropCALLS);
+
+$ASCII_text.="| $dd_0 $dd_5 $dd10 $dd15 $dd20 $dd25 $dd30 $dd35 $dd40 $dd45 $dd50 $dd55 $dd60 $dd90 $dd99 | $BDdropCALLS |\n";
+$ASCII_text.="+-------------------------------------------------------------------------------------------+------------+\n";
+
+
+$CSV_text2.="\"\",\"$dd_0\",\"$dd_5\",\"$dd10\",\"$dd15\",\"$dd20\",\"$dd25\",\"$dd30\",\"$dd35\",\"$dd40\",\"$dd45\",\"$dd50\",\"$dd55\",\"$dd60\",\"$dd90\",\"$dd99\",\"$BDdropCALLS\"\n";
+
+if ($report_display_type=="HTML") {
+ $stmt="select count(*),round(queue_seconds) as rd_sec from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status IN('DROP','XDROP') group by rd_sec order by rd_sec asc;";
+ $ms_stmt="select queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status IN('DROP','XDROP') order by queue_seconds desc limit 1;";
+ $mc_stmt="select count(*) as ct from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status IN('DROP','XDROP') group by queue_seconds order by ct desc limit 1;";
+ if ($DID=='Y')
+ {
+ $stmt="select count(*),round(queue_seconds) as rd_sec from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) and status IN('DROP','XDROP') group by rd_sec;";
+ $ms_stmt="select queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) and status IN('DROP','XDROP') order by queue_seconds desc limit 1;";
+ $mc_stmt="select count(*) as ct from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) and status IN('DROP','XDROP') group by queue_seconds order by ct desc limit 1;";
+ }
+ if ($DB) {$GRAPH_text.=$stmt."\n";}
+ $ms_rslt=mysql_to_mysqli($ms_stmt, $link);
+ $ms_row=mysqli_fetch_row($ms_rslt);
+ $max_seconds=$ms_row[0];
+ if ($max_seconds>90) {$max_seconds=91;}
+ for ($i=0; $i<=$max_seconds; $i++) {
+ $sec_ary[$i]=0;
+ }
+
+ $mc_rslt=mysql_to_mysqli($mc_stmt, $link);
+ $mc_row=mysqli_fetch_row($mc_rslt);
+ $max_calls=$ms_row[0];
+ if ($max_calls<=10) {
+ while ($maxcalls%5!=0) {
+ $maxcalls++;
+ }
+ } else if ($max_calls<=100) {
+ while ($maxcalls%10!=0) {
+ $maxcalls++;
+ }
+ } else if ($max_calls<=1000) {
+ while ($maxcalls%50!=0) {
+ $maxcalls++;
+ }
+ } else {
+ while ($maxcalls%500!=0) {
+ $maxcalls++;
+ }
+ }
+ $rslt=mysql_to_mysqli($stmt, $link);
+
+ $GRAPH_text="\n";
+ $GRAPH_text.="";
+ $MAIN.=$GRAPH_text;
+ }
+else
+ {
+ $MAIN.=$ASCII_text;
+ }
+
+
+
+##############################
+######### CALL ANSWERED TIME AND PERCENT BREAKDOWN IN SECONDS
+
+$BDansweredCALLS = 0;
+
+$ASCII_text="\n";
+$ASCII_text.=" $rpt_type_verbiage "._QXZ("ANSWERED TIME AND PERCENT BREAKDOWN IN SECONDS")."\n";
+$ASCII_text.=" +-------------------------------------------------------------------------------------------+------------+\n";
+$ASCII_text.=" | 0 5 10 15 20 25 30 35 40 45 50 55 60 90 +90 | "._QXZ("TOTAL",10)." |\n";
+$ASCII_text.="----------+-------------------------------------------------------------------------------------------+------------+\n";
+
+$CSV_text2.="\n\"$rpt_type_verbiage "._QXZ("ANSWERED TIME AND PERCENT BREAKDOWN IN SECONDS")."\"\n";
+$CSV_text2.="\"\",\"0\",\"5\",\"10\",\"15\",\"20\",\"25\",\"30\",\"35\",\"40\",\"45\",\"50\",\"55\",\"60\",\"90\",\"+90\",\""._QXZ("TOTAL")."\"\n";
+
+$stmt="select count(*),queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL') group by queue_seconds;";
+if ($DID=='Y')
+ {
+ $stmt="select count(*),queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL') group by queue_seconds;";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$ASCII_text.="$stmt\n";}
+$reasons_to_print = mysqli_num_rows($rslt);
+$i=0;
+while ($i < $reasons_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+
+ $BDansweredCALLS = ($BDansweredCALLS + $row[0]);
+
+ ### Get interval totals
+ if ($row[1] == 0) {$ad_0 = ($ad_0 + $row[0]);}
+ if ( ($row[1] > 0) and ($row[1] <= 5) ) {$ad_5 = ($ad_5 + $row[0]);}
+ if ( ($row[1] > 5) and ($row[1] <= 10) ) {$ad10 = ($ad10 + $row[0]);}
+ if ( ($row[1] > 10) and ($row[1] <= 15) ) {$ad15 = ($ad15 + $row[0]);}
+ if ( ($row[1] > 15) and ($row[1] <= 20) ) {$ad20 = ($ad20 + $row[0]);}
+ if ( ($row[1] > 20) and ($row[1] <= 25) ) {$ad25 = ($ad25 + $row[0]);}
+ if ( ($row[1] > 25) and ($row[1] <= 30) ) {$ad30 = ($ad30 + $row[0]);}
+ if ( ($row[1] > 30) and ($row[1] <= 35) ) {$ad35 = ($ad35 + $row[0]);}
+ if ( ($row[1] > 35) and ($row[1] <= 40) ) {$ad40 = ($ad40 + $row[0]);}
+ if ( ($row[1] > 40) and ($row[1] <= 45) ) {$ad45 = ($ad45 + $row[0]);}
+ if ( ($row[1] > 45) and ($row[1] <= 50) ) {$ad50 = ($ad50 + $row[0]);}
+ if ( ($row[1] > 50) and ($row[1] <= 55) ) {$ad55 = ($ad55 + $row[0]);}
+ if ( ($row[1] > 55) and ($row[1] <= 60) ) {$ad60 = ($ad60 + $row[0]);}
+ if ( ($row[1] > 60) and ($row[1] <= 90) ) {$ad90 = ($ad90 + $row[0]);}
+ if ($row[1] > 90) {$ad99 = ($ad99 + $row[0]);}
+ $i++;
+ }
+
+### Calculate cumulative totals
+$Cad_0 =$ad_0;
+$Cad_5 =($Cad_0 + $ad_5);
+$Cad10 =($Cad_5 + $ad10);
+$Cad15 =($Cad10 + $ad15);
+$Cad20 =($Cad15 + $ad20);
+$Cad25 =($Cad20 + $ad25);
+$Cad30 =($Cad25 + $ad30);
+$Cad35 =($Cad30 + $ad35);
+$Cad40 =($Cad35 + $ad40);
+$Cad45 =($Cad40 + $ad45);
+$Cad50 =($Cad45 + $ad50);
+$Cad55 =($Cad50 + $ad55);
+$Cad60 =($Cad55 + $ad60);
+$Cad90 =($Cad60 + $ad90);
+$Cad99 =($Cad90 + $ad99);
+
+### Calculate interval percentages
+$pad_0=0; $pad_5=0; $pad10=0; $pad15=0; $pad20=0; $pad25=0; $pad30=0; $pad35=0; $pad40=0; $pad45=0; $pad50=0; $pad55=0; $pad60=0; $pad90=0; $pad99=0;
+$pCad_0=0; $pCad_5=0; $pCad10=0; $pCad15=0; $pCad20=0; $pCad25=0; $pCad30=0; $pCad35=0; $pCad40=0; $pCad45=0; $pCad50=0; $pCad55=0; $pCad60=0; $pCad90=0; $pCad99=0;
+if ( ($BDansweredCALLS > 0) and ($TOTALcalls > 0) )
+ {
+ $pad_0 = (MathZDC($ad_0, $TOTALcalls) * 100); $pad_0 = round($pad_0, 0);
+ $pad_5 = (MathZDC($ad_5, $TOTALcalls) * 100); $pad_5 = round($pad_5, 0);
+ $pad10 = (MathZDC($ad10, $TOTALcalls) * 100); $pad10 = round($pad10, 0);
+ $pad15 = (MathZDC($ad15, $TOTALcalls) * 100); $pad15 = round($pad15, 0);
+ $pad20 = (MathZDC($ad20, $TOTALcalls) * 100); $pad20 = round($pad20, 0);
+ $pad25 = (MathZDC($ad25, $TOTALcalls) * 100); $pad25 = round($pad25, 0);
+ $pad30 = (MathZDC($ad30, $TOTALcalls) * 100); $pad30 = round($pad30, 0);
+ $pad35 = (MathZDC($ad35, $TOTALcalls) * 100); $pad35 = round($pad35, 0);
+ $pad40 = (MathZDC($ad40, $TOTALcalls) * 100); $pad40 = round($pad40, 0);
+ $pad45 = (MathZDC($ad45, $TOTALcalls) * 100); $pad45 = round($pad45, 0);
+ $pad50 = (MathZDC($ad50, $TOTALcalls) * 100); $pad50 = round($pad50, 0);
+ $pad55 = (MathZDC($ad55, $TOTALcalls) * 100); $pad55 = round($pad55, 0);
+ $pad60 = (MathZDC($ad60, $TOTALcalls) * 100); $pad60 = round($pad60, 0);
+ $pad90 = (MathZDC($ad90, $TOTALcalls) * 100); $pad90 = round($pad90, 0);
+ $pad99 = (MathZDC($ad99, $TOTALcalls) * 100); $pad99 = round($pad99, 0);
+
+ $pCad_0 = (MathZDC($Cad_0, $TOTALcalls) * 100); $pCad_0 = round($pCad_0, 0);
+ $pCad_5 = (MathZDC($Cad_5, $TOTALcalls) * 100); $pCad_5 = round($pCad_5, 0);
+ $pCad10 = (MathZDC($Cad10, $TOTALcalls) * 100); $pCad10 = round($pCad10, 0);
+ $pCad15 = (MathZDC($Cad15, $TOTALcalls) * 100); $pCad15 = round($pCad15, 0);
+ $pCad20 = (MathZDC($Cad20, $TOTALcalls) * 100); $pCad20 = round($pCad20, 0);
+ $pCad25 = (MathZDC($Cad25, $TOTALcalls) * 100); $pCad25 = round($pCad25, 0);
+ $pCad30 = (MathZDC($Cad30, $TOTALcalls) * 100); $pCad30 = round($pCad30, 0);
+ $pCad35 = (MathZDC($Cad35, $TOTALcalls) * 100); $pCad35 = round($pCad35, 0);
+ $pCad40 = (MathZDC($Cad40, $TOTALcalls) * 100); $pCad40 = round($pCad40, 0);
+ $pCad45 = (MathZDC($Cad45, $TOTALcalls) * 100); $pCad45 = round($pCad45, 0);
+ $pCad50 = (MathZDC($Cad50, $TOTALcalls) * 100); $pCad50 = round($pCad50, 0);
+ $pCad55 = (MathZDC($Cad55, $TOTALcalls) * 100); $pCad55 = round($pCad55, 0);
+ $pCad60 = (MathZDC($Cad60, $TOTALcalls) * 100); $pCad60 = round($pCad60, 0);
+ $pCad90 = (MathZDC($Cad90, $TOTALcalls) * 100); $pCad90 = round($pCad90, 0);
+ $pCad99 = (MathZDC($Cad99, $TOTALcalls) * 100); $pCad99 = round($pCad99, 0);
+
+ $ApCad_0 = (MathZDC($Cad_0, $BDansweredCALLS) * 100); $ApCad_0 = round($ApCad_0, 0);
+ $ApCad_5 = (MathZDC($Cad_5, $BDansweredCALLS) * 100); $ApCad_5 = round($ApCad_5, 0);
+ $ApCad10 = (MathZDC($Cad10, $BDansweredCALLS) * 100); $ApCad10 = round($ApCad10, 0);
+ $ApCad15 = (MathZDC($Cad15, $BDansweredCALLS) * 100); $ApCad15 = round($ApCad15, 0);
+ $ApCad20 = (MathZDC($Cad20, $BDansweredCALLS) * 100); $ApCad20 = round($ApCad20, 0);
+ $ApCad25 = (MathZDC($Cad25, $BDansweredCALLS) * 100); $ApCad25 = round($ApCad25, 0);
+ $ApCad30 = (MathZDC($Cad30, $BDansweredCALLS) * 100); $ApCad30 = round($ApCad30, 0);
+ $ApCad35 = (MathZDC($Cad35, $BDansweredCALLS) * 100); $ApCad35 = round($ApCad35, 0);
+ $ApCad40 = (MathZDC($Cad40, $BDansweredCALLS) * 100); $ApCad40 = round($ApCad40, 0);
+ $ApCad45 = (MathZDC($Cad45, $BDansweredCALLS) * 100); $ApCad45 = round($ApCad45, 0);
+ $ApCad50 = (MathZDC($Cad50, $BDansweredCALLS) * 100); $ApCad50 = round($ApCad50, 0);
+ $ApCad55 = (MathZDC($Cad55, $BDansweredCALLS) * 100); $ApCad55 = round($ApCad55, 0);
+ $ApCad60 = (MathZDC($Cad60, $BDansweredCALLS) * 100); $ApCad60 = round($ApCad60, 0);
+ $ApCad90 = (MathZDC($Cad90, $BDansweredCALLS) * 100); $ApCad90 = round($ApCad90, 0);
+ $ApCad99 = (MathZDC($Cad99, $BDansweredCALLS) * 100); $ApCad99 = round($ApCad99, 0);
+ }
+
+### Format variables
+$ad_0 = sprintf("%5s", $ad_0);
+$ad_5 = sprintf("%5s", $ad_5);
+$ad10 = sprintf("%5s", $ad10);
+$ad15 = sprintf("%5s", $ad15);
+$ad20 = sprintf("%5s", $ad20);
+$ad25 = sprintf("%5s", $ad25);
+$ad30 = sprintf("%5s", $ad30);
+$ad35 = sprintf("%5s", $ad35);
+$ad40 = sprintf("%5s", $ad40);
+$ad45 = sprintf("%5s", $ad45);
+$ad50 = sprintf("%5s", $ad50);
+$ad55 = sprintf("%5s", $ad55);
+$ad60 = sprintf("%5s", $ad60);
+$ad90 = sprintf("%5s", $ad90);
+$ad99 = sprintf("%5s", $ad99);
+$Cad_0 = sprintf("%5s", $Cad_0);
+$Cad_5 = sprintf("%5s", $Cad_5);
+$Cad10 = sprintf("%5s", $Cad10);
+$Cad15 = sprintf("%5s", $Cad15);
+$Cad20 = sprintf("%5s", $Cad20);
+$Cad25 = sprintf("%5s", $Cad25);
+$Cad30 = sprintf("%5s", $Cad30);
+$Cad35 = sprintf("%5s", $Cad35);
+$Cad40 = sprintf("%5s", $Cad40);
+$Cad45 = sprintf("%5s", $Cad45);
+$Cad50 = sprintf("%5s", $Cad50);
+$Cad55 = sprintf("%5s", $Cad55);
+$Cad60 = sprintf("%5s", $Cad60);
+$Cad90 = sprintf("%5s", $Cad90);
+$Cad99 = sprintf("%5s", $Cad99);
+$pad_0 = sprintf("%4s", $pad_0) . '%';
+$pad_5 = sprintf("%4s", $pad_5) . '%';
+$pad10 = sprintf("%4s", $pad10) . '%';
+$pad15 = sprintf("%4s", $pad15) . '%';
+$pad20 = sprintf("%4s", $pad20) . '%';
+$pad25 = sprintf("%4s", $pad25) . '%';
+$pad30 = sprintf("%4s", $pad30) . '%';
+$pad35 = sprintf("%4s", $pad35) . '%';
+$pad40 = sprintf("%4s", $pad40) . '%';
+$pad45 = sprintf("%4s", $pad45) . '%';
+$pad50 = sprintf("%4s", $pad50) . '%';
+$pad55 = sprintf("%4s", $pad55) . '%';
+$pad60 = sprintf("%4s", $pad60) . '%';
+$pad90 = sprintf("%4s", $pad90) . '%';
+$pad99 = sprintf("%4s", $pad99) . '%';
+$pCad_0 = sprintf("%4s", $pCad_0) . '%';
+$pCad_5 = sprintf("%4s", $pCad_5) . '%';
+$pCad10 = sprintf("%4s", $pCad10) . '%';
+$pCad15 = sprintf("%4s", $pCad15) . '%';
+$pCad20 = sprintf("%4s", $pCad20) . '%';
+$pCad25 = sprintf("%4s", $pCad25) . '%';
+$pCad30 = sprintf("%4s", $pCad30) . '%';
+$pCad35 = sprintf("%4s", $pCad35) . '%';
+$pCad40 = sprintf("%4s", $pCad40) . '%';
+$pCad45 = sprintf("%4s", $pCad45) . '%';
+$pCad50 = sprintf("%4s", $pCad50) . '%';
+$pCad55 = sprintf("%4s", $pCad55) . '%';
+$pCad60 = sprintf("%4s", $pCad60) . '%';
+$pCad90 = sprintf("%4s", $pCad90) . '%';
+$pCad99 = sprintf("%4s", $pCad99) . '%';
+$ApCad_0 = sprintf("%4s", $ApCad_0) . '%';
+$ApCad_5 = sprintf("%4s", $ApCad_5) . '%';
+$ApCad10 = sprintf("%4s", $ApCad10) . '%';
+$ApCad15 = sprintf("%4s", $ApCad15) . '%';
+$ApCad20 = sprintf("%4s", $ApCad20) . '%';
+$ApCad25 = sprintf("%4s", $ApCad25) . '%';
+$ApCad30 = sprintf("%4s", $ApCad30) . '%';
+$ApCad35 = sprintf("%4s", $ApCad35) . '%';
+$ApCad40 = sprintf("%4s", $ApCad40) . '%';
+$ApCad45 = sprintf("%4s", $ApCad45) . '%';
+$ApCad50 = sprintf("%4s", $ApCad50) . '%';
+$ApCad55 = sprintf("%4s", $ApCad55) . '%';
+$ApCad60 = sprintf("%4s", $ApCad60) . '%';
+$ApCad90 = sprintf("%4s", $ApCad90) . '%';
+$ApCad99 = sprintf("%4s", $ApCad99) . '%';
+
+$BDansweredCALLS = sprintf("%10s", $BDansweredCALLS);
+
+### Format and output
+$answeredTOTALs = "$ad_0 $ad_5 $ad10 $ad15 $ad20 $ad25 $ad30 $ad35 $ad40 $ad45 $ad50 $ad55 $ad60 $ad90 $ad99 | $BDansweredCALLS |";
+$answeredCUMULATIVE = "$Cad_0 $Cad_5 $Cad10 $Cad15 $Cad20 $Cad25 $Cad30 $Cad35 $Cad40 $Cad45 $Cad50 $Cad55 $Cad60 $Cad90 $Cad99 | $BDansweredCALLS |";
+$answeredINT_PERCENT = "$pad_0 $pad_5 $pad10 $pad15 $pad20 $pad25 $pad30 $pad35 $pad40 $pad45 $pad50 $pad55 $pad60 $pad90 $pad99 | |";
+$answeredCUM_PERCENT = "$pCad_0 $pCad_5 $pCad10 $pCad15 $pCad20 $pCad25 $pCad30 $pCad35 $pCad40 $pCad45 $pCad50 $pCad55 $pCad60 $pCad90 $pCad99 | |";
+$answeredCUM_ANS_PERCENT = "$ApCad_0 $ApCad_5 $ApCad10 $ApCad15 $ApCad20 $ApCad25 $ApCad30 $ApCad35 $ApCad40 $ApCad45 $ApCad50 $ApCad55 $ApCad60 $ApCad90 $ApCad99 | |";
+$ASCII_text.=_QXZ("INTERVAL",10)."| $answeredTOTALs\n";
+$ASCII_text.=_QXZ("INT",8)." %| $answeredINT_PERCENT\n";
+$ASCII_text.=_QXZ("CUMULATIVE",10)."| $answeredCUMULATIVE\n";
+$ASCII_text.=_QXZ("CUM",8)." %| $answeredCUM_PERCENT\n";
+$ASCII_text.=_QXZ("CUM ANS",8)." %| $answeredCUM_ANS_PERCENT\n";
+$ASCII_text.="----------+-------------------------------------------------------------------------------------------+------------+\n";
+
+
+$CSV_text2.="\""._QXZ("INTERVAL")."\",\"$ad_0\",\"$ad_5\",\"$ad10\",\"$ad15\",\"$ad20\",\"$ad25\",\"$ad30\",\"$ad35\",\"$ad40\",\"$ad45\",\"$ad50\",\"$ad55\",\"$ad60\",\"$ad90\",\"$ad99\",\"$BDansweredCALLS\"\n";
+$CSV_text2.="\""._QXZ("INT")." %\",\"$pad_0\",\"$pad_5\",\"$pad10\",\"$pad15\",\"$pad20\",\"$pad25\",\"$pad30\",\"$pad35\",\"$pad40\",\"$pad45\",\"$pad50\",\"$pad55\",\"$pad60\",\"$pad90\",\"$pad99\"\n";
+$CSV_text2.="\""._QXZ("CUMULATIVE")."\",\"$Cad_0\",\"$Cad_5\",\"$Cad10\",\"$Cad15\",\"$Cad20\",\"$Cad25\",\"$Cad30\",\"$Cad35\",\"$Cad40\",\"$Cad45\",\"$Cad50\",\"$Cad55\",\"$Cad60\",\"$Cad90\",\"$Cad99\",\"$BDansweredCALLS\"\n";
+$CSV_text2.="\""._QXZ("CUM")." %\",\"$pCad_0\",\"$pCad_5\",\"$pCad10\",\"$pCad15\",\"$pCad20\",\"$pCad25\",\"$pCad30\",\"$pCad35\",\"$pCad40\",\"$pCad45\",\"$pCad50\",\"$pCad55\",\"$pCad60\",\"$pCad90\",\"$pCad99\"\n";
+$CSV_text2.="\""._QXZ("CUM ANS")." %\",\"$ApCad_0\",\"$ApCad_5\",\"$ApCad10\",\"$ApCad15\",\"$ApCad20\",\"$ApCad25\",\"$ApCad30\",\"$ApCad35\",\"$ApCad40\",\"$ApCad45\",\"$ApCad50\",\"$ApCad55\",\"$ApCad60\",\"$ApCad90\",\"$ApCad99\"\n";
+
+if ($report_display_type=="HTML") {
+ $stmt="select count(*),round(queue_seconds) as rd_sec from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL') group by rd_sec order by rd_sec asc;";
+ $ms_stmt="select queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL') order by queue_seconds desc limit 1;";
+ $mc_stmt="select count(*) as ct from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL') group by queue_seconds order by ct desc limit 1;";
+ if ($DID=='Y')
+ {
+ $stmt="select count(*),round(queue_seconds) as rd_sec from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL') group by rd_sec;";
+ $ms_stmt="select queue_seconds from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL') order by queue_seconds desc limit 1;";
+ $mc_stmt="select count(*) as ct from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) and status NOT IN('DROP','XDROP','HXFER','QVMAIL','HOLDTO','LIVE','QUEUE','TIMEOT','AFTHRS','NANQUE','INBND','MAXCAL') group by queue_seconds order by ct desc limit 1;";
+ }
+ if ($DB) {$GRAPH_text.=$stmt."\n";}
+ $ms_rslt=mysql_to_mysqli($ms_stmt, $link);
+ $ms_row=mysqli_fetch_row($ms_rslt);
+ $max_seconds=$ms_row[0];
+ if ($max_seconds>90) {$max_seconds=91;}
+ for ($i=0; $i<=$max_seconds; $i++) {
+ $sec_ary[$i]=0;
+ }
+
+ $mc_rslt=mysql_to_mysqli($mc_stmt, $link);
+ $mc_row=mysqli_fetch_row($mc_rslt);
+ $max_calls=$ms_row[0];
+ if ($max_calls<=10) {
+ while ($maxcalls%5!=0) {
+ $maxcalls++;
+ }
+ } else if ($max_calls<=100) {
+ while ($maxcalls%10!=0) {
+ $maxcalls++;
+ }
+ } else if ($max_calls<=1000) {
+ while ($maxcalls%50!=0) {
+ $maxcalls++;
+ }
+ } else {
+ while ($maxcalls%500!=0) {
+ $maxcalls++;
+ }
+ }
+ $rslt=mysql_to_mysqli($stmt, $link);
+
+ $GRAPH_text="\n";
+ $GRAPH_text.="";
+ $MAIN.=$GRAPH_text;
+ }
+else
+ {
+ $MAIN.=$ASCII_text;
+ }
+
+##############################
+######### CALL HANGUP REASON STATS
+
+$TOTALcalls = 0;
+
+$ASCII_text="\n";
+$ASCII_text.="---------- $rpt_type_verbiage "._QXZ("HANGUP REASON STATS",25)." "._QXZ("DOWNLOAD")."\n";
+$ASCII_text.="+----------------------+------------+\n";
+$ASCII_text.="| "._QXZ("HANGUP REASON",20)." | $rpt_type_verbiages |\n";
+$ASCII_text.="+----------------------+------------+\n";
+
+$CSV_text3.="\n\"$rpt_type_verbiage "._QXZ("HANGUP REASON STATS")."\"\n";
+$CSV_text3.="\""._QXZ("HANGUP REASON")."\",\"$rpt_type_verbiages\"\n";
+
+$stmt="select count(*),term_reason from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) group by term_reason order by term_reason;";
+if ($DID=='Y')
+ {
+ $stmt="select count(*),term_reason from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) group by term_reason order by term_reason;";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$ASCII_text.="$stmt\n";}
+$reasons_to_print = mysqli_num_rows($rslt);
+$i=0;
+while ($i < $reasons_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+
+ $TOTALcalls = ($TOTALcalls + $row[0]);
+
+ $REASONcount = sprintf("%10s", $row[0]);
+ while(strlen($REASONcount)>10) {$REASONcount = substr("$REASONcount", 0, -1);}
+ $reason = sprintf("%-20s", $row[1]);while(strlen($reason)>20) {$reason = substr("$reason", 0, -1);}
+# if (preg_match('/NONE/',$reason)) {$reason = 'NO ANSWER ';}
+
+ $ASCII_text.="| $reason | $REASONcount |\n";
+ $CSV_text3.="\"$reason\",\"$REASONcount\"\n";
+
+ $i++;
+ }
+
+$TOTALcalls = sprintf("%10s", $TOTALcalls);
+
+$ASCII_text.="+----------------------+------------+\n";
+$ASCII_text.="| "._QXZ("TOTAL:",20). " | $TOTALcalls |\n";
+$ASCII_text.="+----------------------+------------+\n";
+
+$CSV_text3.="\""._QXZ("TOTAL").":\",\"$TOTALcalls\"\n";
+
+if ($report_display_type=="HTML")
+ {
+ $ct_ary=array();
+ $rslt=mysql_to_mysqli($stmt, $link);
+ $high_ct=0; $i=0;
+ while ($row=mysqli_fetch_row($rslt)) {
+ if ($row[0]>$high_ct) {$high_ct=$row[0];}
+ $ct_ary[$i][0]=$row[0];
+ $ct_ary[$i][1]=$row[1];
+ $i++;
+ }
+ $GRAPH_text="\n";
+ $GRAPH_text.="\n";
+ $GRAPH_text.=" $rpt_type_verbiage "._QXZ("HANGUP REASON STATS")."\n";
+ $GRAPH_text.=" \n";
+ $GRAPH_text.=" | "._QXZ("REASON")." | \n";
+ $GRAPH_text.=" $rpt_type_verbiages | \n";
+ $GRAPH_text.=" \n";
+ for ($i=0; $i\n";
+ $GRAPH_text.=" ".$ct_ary[$i][1]." | \n";
+ $GRAPH_text.=" ".$ct_ary[$i][0]." | \n";
+ $GRAPH_text.=" \n";
+ }
+ $GRAPH_text.=" \n";
+ $GRAPH_text.=" | TOTAL ".$rpt_type_verbiage.": | \n";
+ $GRAPH_text.=" ".trim($TOTALcalls)." | \n";
+ $GRAPH_text.=" \n";
+ $GRAPH_text.=" \n";
+ $GRAPH_text.="\n";
+ $MAIN.=$GRAPH_text;
+ }
+else
+ {
+ $MAIN.=$ASCII_text;
+ }
+
+##############################
+######### CALL STATUS STATS
+
+$TOTALcalls = 0;
+
+$ASCII_text="\n";
+$ASCII_text.="---------- $rpt_type_verbiage "._QXZ("STATUS STATS",18)." "._QXZ("DOWNLOAD")."\n";
+$ASCII_text.="+--------+----------------------+----------------------+------------+------------+----------+-----------+\n";
+$ASCII_text.="| "._QXZ("STATUS",6)." | "._QXZ("DESCRIPTION",20)." | "._QXZ("CATEGORY",20)." | $rpt_type_verbiages | "._QXZ("TOTAL TIME",10)." | "._QXZ("AVG TIME",8)." |$rpt_type_verbiages/"._QXZ("HOUR",4)."|\n";
+$ASCII_text.="+--------+----------------------+----------------------+------------+------------+----------+-----------+\n";
+
+$GRAPH="
";
+
+$CSV_text4.="\n\"$rpt_type_verbiage "._QXZ("STATUS STATS")."\"\n";
+$CSV_text4.="\""._QXZ("STATUS")."\",\""._QXZ("DESCRIPTION")."\",\""._QXZ("CATEGORY")."\",\"$rpt_type_verbiages\",\""._QXZ("TOTAL TIME")."\",\""._QXZ("AVG TIME")."\",\"$rpt_type_verbiages/HOUR\"\n";
+
+
+
+## get counts and time totals for all statuses in this campaign
+$stmt="select count(*),status,sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and campaign_id IN($group_SQL) group by status;";
+if ($DID=='Y')
+ {
+ $stmt="select count(*),status,sum(length_in_sec) from ".$vicidial_closer_log_table." where call_date >= '$query_date_BEGIN' and call_date <= '$query_date_END' $calldate_call_time_clause and uniqueid IN($unid_SQL) group by status;";
+ }
+$rslt=mysql_to_mysqli($stmt, $link);
+if ($DB) {$ASCII_text.="$stmt\n";}
+$statuses_to_print = mysqli_num_rows($rslt);
+$i=0;
+
+######## GRAPHING #########
+$max_calls=1;
+$max_total_time=1;
+$max_avg_time=1;
+$max_callshr=1;
+$graph_header=""._QXZ("CALL STATUS STATS")."| "._QXZ("STATUS")." | ";
+$CALLS_graph=$graph_header.""._QXZ("CALLS")." | ";
+$TOTALTIME_graph=$graph_header.""._QXZ("TOTAL TIME")." | ";
+$AVGTIME_graph=$graph_header.""._QXZ("AVG TIME")." | ";
+$CALLSHOUR_graph=$graph_header.""._QXZ("CALLS/HR")." | ";
+###########################
+
+while ($i < $statuses_to_print)
+ {
+ $row=mysqli_fetch_row($rslt);
+
+ $STATUScount = $row[0];
+ $RAWstatus = $row[1];
+ $r=0; $foundstat=0;
+ while ($r < $statcats_to_print)
+ {
+ if ( ($statcat_list[$RAWstatus] == "$vsc_id[$r]") and ($foundstat < 1) )
+ {
+ $vsc_count[$r] = ($vsc_count[$r] + $STATUScount);
+ }
+ $r++;
+ }
+
+ $TOTALcalls = ($TOTALcalls + $row[0]);
+ $STATUSrate = (MathZDC($STATUScount, MathZDC($TOTALsec, 3600)) );
+ $STATUSrate = sprintf("%.2f", $STATUSrate);
+
+ $STATUShours = sec_convert($row[2],'H');
+ $STATUSavg_sec = MathZDC($row[2], $STATUScount);
+ $STATUSavg = sec_convert($STATUSavg_sec,'H');
+
+ if ($row[0]>$max_calls) {$max_calls=$row[0];}
+ if ($row[2]>$max_total_time) {$max_total_time=$row[2];}
+ if ($STATUSavg_sec>$max_avg_time) {$max_avg_time=$STATUSavg_sec;}
+ if ($STATUSrate>$max_callshr) {$max_callshr=$STATUSrate;}
+ $graph_stats[$i][1]=$row[0];
+ $graph_stats[$i][2]=$row[2];
+ $graph_stats[$i][3]=$STATUSavg_sec;
+ $graph_stats[$i][4]=$STATUSrate;
+
+
+ $STATUScount = sprintf("%10s", $row[0]);while(strlen($STATUScount)>10) {$STATUScount = substr("$STATUScount", 0, -1);}
+ $status = sprintf("%-6s", $row[1]);while(strlen($status)>6) {$status = substr("$status", 0, -1);}
+ $STATUShours = sprintf("%10s", $STATUShours);while(strlen($STATUShours)>10) {$STATUShours = substr("$STATUShours", 0, -1);}
+ $STATUSavg = sprintf("%8s", $STATUSavg);while(strlen($STATUSavg)>8) {$STATUSavg = substr("$STATUSavg", 0, -1);}
+ $STATUSrate = sprintf("%8s", $STATUSrate);while(strlen($STATUSrate)>8) {$STATUSrate = substr("$STATUSrate", 0, -1);}
+
+ if ($non_latin < 1)
+ {
+ $status_name = sprintf("%-20s", $statname_list[$RAWstatus]);
+ while(strlen($status_name)>20) {$status_name = substr("$status_name", 0, -1);}
+ $statcat = sprintf("%-20s", $statcat_list[$RAWstatus]);
+ while(strlen($statcat)>20) {$statcat = substr("$statcat", 0, -1);}
+ }
+ else
+ {
+ $status_name = sprintf("%-60s", $statname_list[$RAWstatus]);
+ while(mb_strlen($status_name,'utf-8')>20) {$status_name = mb_substr("$status_name", 0, -1,'utf-8');}
+ $statcat = sprintf("%-60s", $statcat_list[$RAWstatus]);
+ while(mb_strlen($statcat,'utf-8')>20) {$statcat = mb_substr("$statcat", 0, -1,'utf-8');}
+ }
+ $graph_stats[$i][0]="$status - $status_name - $statcat";
+
+
+ $ASCII_text.="| $status | $status_name | $statcat | $STATUScount | $STATUShours | $STATUSavg | $STATUSrate |\n";
+ $CSV_text4.="\"$status\",\"$status_name\",\"$statcat\",\"$STATUScount\",\"$STATUShours\",\"$STATUSavg\",\"$STATUSrate\"\n";
+
+ $i++;
+ }
+
+if ($TOTALcalls < 1)
+ {
+ $TOTALhours = '0:00:00';
+ $TOTALavg = '0:00:00';
+ $TOTALrate = '0.00';
+ }
+else
+ {
+ $TOTALrate = MathZDC($TOTALcalls, MathZDC($TOTALsec, 3600) );
+ $TOTALrate = sprintf("%.2f", $TOTALrate);
+
+ $TOTALhours = sec_convert($TOTALsec,'H');
+ $TOTALavg_sec = MathZDC($TOTALsec, $TOTALcalls);
+ $TOTALavg = sec_convert($TOTALavg_sec,'H');
+ }
+$TOTALcalls = sprintf("%10s", $TOTALcalls);
+$TOTALhours = sprintf("%10s", $TOTALhours);while(strlen($TOTALhours)>10) {$TOTALhours = substr("$TOTALhours", 0, -1);}
+$TOTALavg = sprintf("%8s", $TOTALavg);while(strlen($TOTALavg)>8) {$TOTALavg = substr("$TOTALavg", 0, -1);}
+$TOTALrate = sprintf("%9s", $TOTALrate);while(strlen($TOTALrate)>9) {$TOTALrate = substr("$TOTALrate", 0, -1);}
+
+$ASCII_text.="+--------+----------------------+----------------------+------------+------------+----------+-----------+\n";
+$ASCII_text.="| "._QXZ("TOTAL:",52)." | $TOTALcalls | $TOTALhours | $TOTALavg | $TOTALrate |\n";
+$ASCII_text.="+------------------------------------------------------+------------+------------+----------+-----------+\n";
+
+#######
+ $JS_onload="onload = function() {\n";
+ $JS_onload.="\tDrawCSSGraph('CALLS', '1');\n";
+ $JS_onload.="\tDrawGraph('CALLS', '1');\n";
+
+ for ($d=0; $d".$graph_stats[$d][0]." | ".$graph_stats[$d][1]." | ";
+ $TOTALTIME_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][2], 'H')." | ";
+ $AVGTIME_graph.=" | ".$graph_stats[$d][0]." | ".sec_convert($graph_stats[$d][3], 'H')." | ";
+ $CALLSHOUR_graph.=" | ".$graph_stats[$d][0]." | ".$graph_stats[$d][4]." | ";
+ }
+ $CALLS_graph.="| "._QXZ("TOTAL").": | ".trim($TOTALcalls)." |
|---|
";
+ $TOTALTIME_graph.=" |