$ASCII_text .= "|   " . _QXZ("Scheduled callbk:", 19) . " {$SC_count}    {$SC_percent}%                   |\n";
 $ASCII_text .= "|   " . _QXZ("Completed:", 19) . " {$COMP_count}    {$COMP_percent}%                   |\n";
 $ASCII_text .= "+--------------------------------------------------------------+\n";
 for ($d = 0; $d < count($graph_stats); $d++) {
     if ($d == 0) {
         $class = " first";
     } else {
         if ($d + 1 == count($graph_stats)) {
             $class = " last";
         } else {
             $class = "";
         }
     }
     $CALLS_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][1], $max_calls)) . "' height='16' />" . $graph_stats[$d][1] . "</td></tr>";
     $DURATION_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][2], $max_duration)) . "' height='16' />" . sec_convert($graph_stats[$d][2], 'H') . "</td></tr>";
     $HANDLETIME_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][3], $max_handletime)) . "' height='16' />" . sec_convert($graph_stats[$d][3], 'H') . "</td></tr>";
 }
 $CALLS_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($total_calls) . "</th></tr></table>";
 $DURATION_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . sec_convert($total_duration, 'H') . "</th></tr></table>";
 $HANDLETIME_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . sec_convert($total_handle_time, 'H') . "</th></tr></table>";
 $JS_onload .= "\tDraw" . $list_id . "Graph('CALLS', '1');\n";
 $JS_text .= "function Draw" . $list_id . "Graph(graph, th_id) {\n";
 $JS_text .= "\tvar CALLS_graph=\"{$CALLS_graph}\";\n";
 $JS_text .= "\tvar DURATION_graph=\"{$DURATION_graph}\";\n";
 $JS_text .= "\tvar HANDLETIME_graph=\"{$HANDLETIME_graph}\";\n";
 $JS_text .= "\n";
 $JS_text .= "\tfor (var i=1; i<=3; i++) {\n";
 $JS_text .= "\t\tvar cellID=\"list_" . $list_id . "_graph\"+i;\n";
 $JS_text .= "\t\tdocument.getElementById(cellID).style.backgroundColor='#DDDDDD';\n";
 $JS_text .= "\t}\n";
 $JS_text .= "\tvar cellID=\"list_" . $list_id . "_graph\"+th_id;\n";
     $login_sec = $login_start_end_check;
 }
 if ($ASsessions[$k] < 1) {
     $ASsessions[$k] = 1;
 }
 $avg_session_sec = MathZDC($login_sec, $ASsessions[$k]);
 $avg_pause_sec = MathZDC($ASpause_sec[$k], $ASpauses[$k]);
 $avg_pause_session = MathZDC($ASpauses[$k], $ASsessions[$k]);
 if ($ASpauses[$k] < 1 or $login_sec < 1) {
     $pct_pause = 100;
 } else {
     $pct_pause = MathZDC($ASpause_sec[$k], $login_sec) * 100;
 }
 $avg_cust_sec = MathZDC($cust_sec, $AScalls[$k]);
 $avg_wait_sec = MathZDC($ASwait_sec[$k], $AScalls[$k]);
 $pct_of_queue = MathZDC($AScalls[$k], $total_calls) * 100;
 if ($AScalls[$k] < 1) {
     $cust_sec = 0;
     $wait_sec = 0;
 } else {
     $cust_sec = $AStalk_sec[$k] - $ASdead_sec[$k];
     $wait_sec = $ASwait_sec[$k];
 }
 $avg_session_sec = round($avg_session_sec);
 $avg_pause_sec = round($avg_pause_sec);
 $avg_pause_session = round($avg_pause_session);
 $pct_pause = round($pct_pause, 1);
 $avg_cust_sec = round($avg_cust_sec);
 $avg_wait_sec = round($avg_wait_sec);
 $pct_of_queue = round($pct_of_queue, 1);
 $login_sec = sec_convert($login_sec, $time_format);
     $m++;
 }
 ##### END loop through each user formatting data for output
 for ($i = 0; $i < count($graph_stats); $i++) {
     if ($i == 0) {
         $class = " first";
     } else {
         if ($i + 1 == count($graph_stats)) {
             $class = " last";
         } else {
             $class = "";
         }
     }
     $GRAPH .= "  <tr>\n";
     $GRAPH .= "\t<th class=\"thgraph{$class}\" scope=\"col\">" . $graph_stats[$i][0] . "</th>\n";
     $GRAPH .= "\t<th class=\"thgraph value{$class}\" scope=\"col\" nowrap><img src=\"images/bar.png\" alt=\"\" width=\"" . round(MathZDC(200 * $graph_stats[$i][1], $max_time)) . "\" height=\"16\" />" . sec_convert($graph_stats[$i][1], 'H') . $graph_stats[$i][2] . "</th>\n";
     $GRAPH .= "\t<th class=\"thgraph{$class}\" scope=\"col\">" . $graph_stats[$i][3] . "</th>\n";
     $GRAPH .= "  </tr>\n";
 }
 $TOT_AGENTS = sprintf("%4s", $m);
 $k = $m;
 if ($DB) {
     $ASCII_text .= _QXZ("Done analyzing") . "...   {$TOTwait}|{$TOTtalk}|{$TOTdispo}|{$TOTpause}|{$TOTALtime}|{$TOTcalls}|{$uc}|<BR>\n";
 }
 ### BEGIN sort through output to display properly ###
 if (preg_match('/NAME|ID|TCLOCK|GROUP/', $stage) and $k > 0) {
     if (preg_match('/ID/', $stage)) {
         sort($TOPsort, SORT_NUMERIC);
     }
     if (preg_match('/TCLOCK/', $stage)) {
         rsort($TOPsort, SORT_NUMERIC);
     $Aavg_hold[$h] = sprintf("%4s", $Aavg_hold[$h]);
     while (strlen($Aavg_hold[$h]) > 4) {
         $Aavg_hold[$h] = preg_replace('/^./', '', $Aavg_hold[$h]);
     }
     $MAIN .= "|{$HMdisplay[$h]}| {$qrtCALLS[$h]} | {$Phd__0[$h]} {$Phd_20[$h]} {$Phd_40[$h]} {$Phd_60[$h]} {$Phd_80[$h]} {$Phd100[$h]} {$Phd120[$h]} {$Phd121[$h]} | | {$Aavg_hold[$h]} |{$qrtQUEUEavg_scale[$h]}|\n";
     $CSV_text .= "\"{$HMdisplay[$h]}\",\"{$qrtCALLS[$h]}\",\"{$Phd__0[$h]}\",\"{$Phd_20[$h]}\",\"{$Phd_40[$h]}\",\"{$Phd_60[$h]}\",\"{$Phd_80[$h]}\",\"{$Phd100[$h]}\",\"{$Phd120[$h]}\",\"{$Phd121[$h]}\",\"{$Aavg_hold[$h]}\"\n";
     $h++;
 }
 $APhd__0 = round(MathZDC($ALLhd__0, $ALLcalls) * 100);
 $APhd_20 = round(MathZDC($ALLhd_20, $ALLcalls) * 100);
 $APhd_40 = round(MathZDC($ALLhd_40, $ALLcalls) * 100);
 $APhd_60 = round(MathZDC($ALLhd_60, $ALLcalls) * 100);
 $APhd_80 = round(MathZDC($ALLhd_80, $ALLcalls) * 100);
 $APhd100 = round(MathZDC($ALLhd100, $ALLcalls) * 100);
 $APhd120 = round(MathZDC($ALLhd120, $ALLcalls) * 100);
 $APhd121 = round(MathZDC($ALLhd121, $ALLcalls) * 100);
 $ALLcalls = sprintf("%5s", $ALLcalls);
 $APhd__0 = sprintf("%4s", $APhd__0);
 $APhd_20 = sprintf("%4s", $APhd_20);
 $APhd_40 = sprintf("%4s", $APhd_40);
 $APhd_60 = sprintf("%4s", $APhd_60);
 $APhd_80 = sprintf("%4s", $APhd_80);
 $APhd100 = sprintf("%4s", $APhd100);
 $APhd120 = sprintf("%4s", $APhd120);
 $APhd121 = sprintf("%4s", $APhd121);
 while (strlen($totQUEUEavg) > 4) {
     $totQUEUEavg = preg_replace('/.$/', '', $totQUEUEavg);
 }
 $MAIN .= "+-------------+-------+-----------------------------------------+ +------+--------------------------------+\n";
 $MAIN .= "| " . _QXZ("TOTAL", 11) . " | {$ALLcalls} | {$APhd__0} {$APhd_20} {$APhd_40} {$APhd_60} {$APhd_80} {$APhd100} {$APhd120} {$APhd121} | | {$totQUEUEavg} |\n";
 $MAIN .= "+-------------+-------+-----------------------------------------+ +------+\n";
             $class = " last";
         } else {
             $class = "";
         }
     }
     $CALLS_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$q][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$q][1], $max_calls)) . "' height='16' />" . $graph_stats[$q][1] . "</td></tr>";
     $ANSWER_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$q][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$q][2], $max_answer)) . "' height='16' />" . $graph_stats[$q][2] . "</td></tr>";
     $TALK_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$q][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$q][3], $max_talk)) . "' height='16' />" . sec_convert($graph_stats[$q][3], 'H') . "</td></tr>";
     $AVGTALK_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$q][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$q][4], $max_avgtalk)) . "' height='16' />" . sec_convert($graph_stats[$q][4], 'H') . "</td></tr>";
     $QUEUE_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$q][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$q][5], $max_queue)) . "' height='16' />" . sec_convert($graph_stats[$q][5], 'H') . "</td></tr>";
     $AVGQUEUE_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$q][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$q][6], $max_avgqueue)) . "' height='16' />" . sec_convert($graph_stats[$q][6], 'H') . "</td></tr>";
     $MAXQUEUE_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$q][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$q][7], $max_maxqueue)) . "' height='16' />" . sec_convert($graph_stats[$q][7], 'H') . "</td></tr>";
     $TOTALABANDONS_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$q][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$q][8], $max_totalabandons)) . "' height='16' />" . $graph_stats[$q][8] . "</td></tr>";
 }
 $gTOTtalk_avg = round(MathZDC($gTOTtalk_sec, $gTOTanswer_count));
 $gTOTqueue_avg = round(MathZDC($gTOTqueue_seconds, $gTOTcalls_count));
 $gTOTtalk_sec = sec_convert($gTOTtalk_sec, 'H');
 $gTOTtalk_avg = sec_convert($gTOTtalk_avg, 'H');
 $gTOTqueue_seconds = sec_convert($gTOTqueue_seconds, 'H');
 $gTOTqueue_avg = sec_convert($gTOTqueue_avg, 'H');
 $gTOTmax_queue_seconds = sec_convert($gTOTmax_queue_seconds, 'H');
 $CALLS_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($gTOTcalls_count) . "</th></tr></table>";
 $ANSWER_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($gTOTanswer_count) . "</th></tr></table>";
 $TALK_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($gTOTtalk_sec) . "</th></tr></table>";
 $AVGTALK_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($gTOTtalk_avg) . "</th></tr></table>";
 $QUEUE_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($gTOTqueue_seconds) . "</th></tr></table>";
 $AVGQUEUE_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($gTOTqueue_avg) . "</th></tr></table>";
 $MAXQUEUE_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($gTOTmax_queue_seconds) . "</th></tr></table>";
 $TOTALABANDONS_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($gTOTdrop_count) . "</th></tr></table>";
 $JS_onload .= "\tDrawGraph('CALLS', '1');\n";
 $JS_text .= "function DrawGraph(graph, th_id) {\n";
 if ($DB) {
     echo "{$stmt}\n";
 }
 $talking_to_print = mysqli_num_rows($rslt);
 if ($talking_to_print > 0) {
     $i = 0;
     while ($i < $talking_to_print) {
         $row = mysqli_fetch_row($rslt);
         $user = sprintf("%-8s", $row[0]);
         $leadid = sprintf("%-10s", $row[1]);
         $group = sprintf("%-14s", $row[2]);
         $phone = sprintf("%-10s", $row[3]);
         $status = sprintf("%-6s", $row[4]);
         $start_time = sprintf("%-19s", $row[5]);
         $call_time_S = $row[6];
         $call_time_M = MathZDC($call_time_S, 60);
         $call_time_M = round($call_time_M, 2);
         $call_time_M_int = intval("{$call_time_M}");
         $call_time_SEC = $call_time_M - $call_time_M_int;
         $call_time_SEC = $call_time_SEC * 60;
         $call_time_SEC = round($call_time_SEC, 0);
         if ($call_time_SEC < 10) {
             $call_time_SEC = "0{$call_time_SEC}";
         }
         $call_time_MS = "{$call_time_M_int}:{$call_time_SEC}";
         $call_time_MS = sprintf("%7s", $call_time_MS);
         $G = '';
         $EG = '';
         #			if ($call_time_M_int >= 5) {$G='<SPAN class="yellow"><B>'; $EG='</B></SPAN>';}
         #			if ($call_time_M_int >= 10) {$G='<SPAN class="orange"><B>'; $EG='</B></SPAN>';}
         echo "| {$G}{$user}{$EG} | {$G}{$leadid}{$EG} | {$G}{$group}{$EG} | {$G}{$phone}{$EG} | {$G}{$status}{$EG} | {$G}{$start_time}{$EG} | {$G}{$call_time_MS}{$EG} |\n";
} else {
    $query_date_BEGIN = $begin_query_time;
    $query_date_END = $end_query_time;
    echo _QXZ("Server Performance Report", 53) . " {$NOW_TIME}\n";
    echo _QXZ("Time range") . ": {$query_date_BEGIN} " . _QXZ("to") . " {$query_date_END}\n\n";
    echo "---------- " . _QXZ("TOTALS, PEAKS and AVERAGES") . "\n";
    $stmt = "select AVG(sysload),AVG(channels_total),MAX(sysload),MAX(channels_total),MAX(processes) from server_performance where start_time <= '" . mysqli_real_escape_string($link, $query_date_END) . "' and start_time >= '" . mysqli_real_escape_string($link, $query_date_BEGIN) . "' and server_ip='" . mysqli_real_escape_string($link, $group) . "';";
    $rslt = mysql_to_mysqli($stmt, $link);
    if ($DB) {
        echo "{$stmt}\n";
    }
    $row = mysqli_fetch_row($rslt);
    $AVGload = sprintf("%10s", $row[0]);
    $AVGchannels = sprintf("%10s", $row[1]);
    $HIGHload = $row[2];
    $HIGHmulti = intval(MathZDC($HIGHload, 100));
    $HIGHchannels = $row[3];
    $HIGHprocesses = $row[4];
    if ($row[2] > $row[3]) {
        $HIGHlimit = $row[2];
    } else {
        $HIGHlimit = $row[3];
    }
    if ($HIGHlimit < $row[4]) {
        $HIGHlimit = $row[4];
    }
    $stmt = "select AVG(cpu_user_percent),AVG(cpu_system_percent),AVG(cpu_idle_percent) from server_performance where start_time <= '" . mysqli_real_escape_string($link, $query_date_END) . "' and start_time >= '" . mysqli_real_escape_string($link, $query_date_BEGIN) . "' and server_ip='" . mysqli_real_escape_string($link, $group) . "';";
    $rslt = mysql_to_mysqli($stmt, $link);
    if ($DB) {
        echo "{$stmt}\n";
    }
 while (strlen($total_CC_percent) > 6) {
     $total_CC_percent = substr("{$total_CC_percent}", 0, -1);
 }
 $total_NI_percent = sprintf("%6.2f", MathZDC($category_totals["NI"], $totalTOTALleads) * 100);
 while (strlen($total_NI_percent) > 6) {
     $total_NI_percent = substr("{$total_NI_percent}", 0, -1);
 }
 $total_UW_percent = sprintf("%6.2f", MathZDC($category_totals["UW"], $totalTOTALleads) * 100);
 while (strlen($total_UW_percent) > 6) {
     $total_UW_percent = substr("{$total_UW_percent}", 0, -1);
 }
 $total_SC_percent = sprintf("%6.2f", MathZDC($category_totals["SC"], $totalTOTALleads) * 100);
 while (strlen($total_SC_percent) > 6) {
     $total_SC_percent = substr("{$total_SC_percent}", 0, -1);
 }
 $total_COMP_percent = sprintf("%6.2f", MathZDC($category_totals["COMP"], $totalTOTALleads) * 100);
 while (strlen($total_COMP_percent) > 6) {
     $total_COMP_percent = substr("{$total_COMP_percent}", 0, -1);
 }
 $total_HA_count = sprintf("%10s", $category_totals["HA"]);
 while (strlen($total_HA_count) > 10) {
     $total_HA_count = substr("{$total_HA_count}", 0, -1);
 }
 $total_SALE_count = sprintf("%10s", $category_totals["SALE"]);
 while (strlen($total_SALE_count) > 10) {
     $total_SALE_count = substr("{$total_SALE_count}", 0, -1);
 }
 $total_DNC_count = sprintf("%10s", $category_totals["DNC"]);
 while (strlen($total_DNC_count) > 10) {
     $total_DNC_count = substr("{$total_DNC_count}", 0, -1);
 }
function horizontal_bar_chart($campaign_id, $days_graph, $title, $link, $metric, $metric_name, $more_link, $END_DATE, $download_link)
{
    $stats_start_time = time();
    if ($END_DATE) {
        $Bstats_date[0] = $END_DATE;
    } else {
        $Bstats_date[0] = date("Y-m-d");
    }
    $Btotal_calls[0] = 0;
    $link_text = '';
    $max_count = 0;
    $i = 0;
    $NWB = "{$download_link} &nbsp; <a href=\"javascript:openNewWindow('help.php?ADD=99999";
    $NWE = "')\"><IMG SRC=\"help.gif\" WIDTH=20 HEIGHT=20 BORDER=0 ALT=\"HELP\" ALIGN=TOP></A>";
    ### get stats for last X days
    $stmt = "SELECT stats_date,{$metric} from vicidial_daily_max_stats where campaign_id='{$campaign_id}' and stats_flag='OPEN' and stats_date<='{$Bstats_date['0']}';";
    if ($metric == 'total_calls_inbound_all') {
        $stmt = "SELECT stats_date,sum(total_calls) from vicidial_daily_max_stats where stats_type='INGROUP' and stats_flag='OPEN' and stats_date<='{$Bstats_date['0']}' group by stats_date;";
    }
    if ($metric == 'total_calls_outbound_all') {
        $stmt = "SELECT stats_date,sum(total_calls) from vicidial_daily_max_stats where stats_type='CAMPAIGN' and stats_flag='OPEN' and stats_date<='{$Bstats_date['0']}' group by stats_date;";
    }
    if ($metric == 'ra_total_calls') {
        $stmt = "SELECT stats_date,total_calls from vicidial_daily_ra_stats where stats_flag='OPEN' and stats_date<='{$Bstats_date['0']}' and user='******';";
    }
    if ($metric == 'ra_concurrent_calls') {
        $stmt = "SELECT stats_date,max_calls from vicidial_daily_ra_stats where stats_flag='OPEN' and stats_date<='{$Bstats_date['0']}' and user='******';";
    }
    $rslt = mysql_to_mysqli($stmt, $link);
    $Xstats_to_print = mysqli_num_rows($rslt);
    if ($Xstats_to_print > 0) {
        $rowx = mysqli_fetch_row($rslt);
        $Bstats_date[0] = $rowx[0];
        $Btotal_calls[0] = $rowx[1];
        if ($max_count < $Btotal_calls[0]) {
            $max_count = $Btotal_calls[0];
        }
    }
    $stats_date_ARRAY = explode("-", $Bstats_date[0]);
    $stats_start_time = mktime(10, 10, 10, $stats_date_ARRAY[1], $stats_date_ARRAY[2], $stats_date_ARRAY[0]);
    while ($i <= $days_graph) {
        $Bstats_date[$i] = date("Y-m-d", $stats_start_time);
        $Btotal_calls[$i] = 0;
        $stmt = "SELECT stats_date,{$metric} from vicidial_daily_max_stats where campaign_id='{$campaign_id}' and stats_date='{$Bstats_date[$i]}';";
        if ($metric == 'total_calls_inbound_all') {
            $stmt = "SELECT stats_date,sum(total_calls) from vicidial_daily_max_stats where stats_date='{$Bstats_date[$i]}' and stats_type='INGROUP' group by stats_date;";
        }
        if ($metric == 'total_calls_outbound_all') {
            $stmt = "SELECT stats_date,sum(total_calls) from vicidial_daily_max_stats where stats_date='{$Bstats_date[$i]}' and stats_type='CAMPAIGN' group by stats_date;";
        }
        if ($metric == 'ra_total_calls') {
            $stmt = "SELECT stats_date,total_calls from vicidial_daily_ra_stats where stats_date='{$Bstats_date[$i]}' and user='******';";
        }
        if ($metric == 'ra_concurrent_calls') {
            $stmt = "SELECT stats_date,max_calls from vicidial_daily_ra_stats where stats_date='{$Bstats_date[$i]}' and user='******';";
        }
        echo "<!-- {$i}) {$stmt} \\-->\n";
        $rslt = mysql_to_mysqli($stmt, $link);
        $Ystats_to_print = mysqli_num_rows($rslt);
        if ($Ystats_to_print > 0) {
            $rowx = mysqli_fetch_row($rslt);
            $Btotal_calls[$i] = $rowx[1];
            if ($max_count < $Btotal_calls[$i]) {
                $max_count = $Btotal_calls[$i];
            }
        }
        $i++;
        $stats_start_time = $stats_start_time - 86400;
    }
    if ($max_count < 1) {
        echo "<!-- no max stats cache summary information available -->";
    } else {
        if ($title == 'campaign') {
            $out_in_type = ' outbound';
        }
        if ($title == 'in-group') {
            $out_in_type = ' inbound';
        }
        if ($more_link > 0) {
            $link_text = "<a href=\"{$PHP_SELF}?ADD=999993&campaign_id={$campaign_id}&stage={$title}\"><font size=1>more summary stats...</font></a>";
        }
        echo "<table cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"white\" summary=\"Multiple day {$metric_name}.\" style=\"background-image:url(images/bg_fade.png); background-repeat:repeat-x; background-position:left top; width: 33em;\">\n";
        echo "<caption align=\"top\">{$days_graph} Day {$out_in_type} {$metric_name} for this {$title} &nbsp; {$link_text}  &nbsp; {$NWB}#max_stats{$NWE}<br /></caption>\n";
        echo "<tr>\n";
        echo "<th scope=\"col\" style=\"text-align: left; vertical-align:top;\"><span class=\"auraltext\">date</span> </th>\n";
        echo "<th scope=\"col\" style=\"text-align: left; vertical-align:top;\"><span class=\"auraltext\">{$metric_name}</span> </th>\n";
        echo "</tr>\n";
        $max_multi = MathZDC(400, $max_count);
        $i = 0;
        while ($i < $days_graph) {
            $bar_width = intval($max_multi * $Btotal_calls[$i]);
            if ($Btotal_calls[$i] < 1) {
                $Btotal_calls[$i] = "-none-";
            }
            echo "<tr>\n";
            echo "<td class=\"chart_td\"><font style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 60%;\">{$Bstats_date[$i]} </font></td>\n";
            echo "<td class=\"chart_td\"><img src=\"images/bar.png\" alt=\"\" width=\"{$bar_width}\" height=\"10\" style=\"vertical-align: middle; margin: 2px 2px 2px 0;\"/><font style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 60%;\"> {$Btotal_calls[$i]}</font></td>\n";
            echo "</tr>\n";
            $i++;
        }
        echo "</table>\n";
    }
}
 $JS_text .= "\tdocument.getElementById('call_stats_graph').innerHTML=graph_to_display;\n";
 $JS_text .= "}\n";
 $GRAPH3 = "<tr><td colspan='84' class='graph_span_cell'><span id='call_stats_graph'><BR>&nbsp;<BR></span></td></tr></table><BR><BR>";
 for ($d = 0; $d < count($graph_stats); $d++) {
     if ($d == 0) {
         $class = " first";
     } else {
         if ($d + 1 == count($graph_stats)) {
             $class = " last";
         } else {
             $class = "";
         }
     }
     $GRAPH .= "  <tr>\n";
     $GRAPH .= "\t<td class=\"chart_td{$class}\">" . $graph_stats[$d][1] . "</td>\n";
     $GRAPH .= "\t<td nowrap class=\"chart_td value{$class}\"><img src=\"images/bar.png\" alt=\"\" width=\"" . round(MathZDC(400 * $graph_stats[$d][0], $max_calls)) . "\" height=\"16\" />" . $graph_stats[$d][0] . "</td>\n";
     $GRAPH .= "  </tr>\n";
 }
 $GRAPH .= "  <tr>\n";
 $GRAPH .= "\t<th class=\"thgraph\" scope=\"col\">" . _QXZ("TOTAL") . ":</th>\n";
 $GRAPH .= "\t<th class=\"thgraph\" scope=\"col\">" . trim($TOTALleads) . "</th>\n";
 $GRAPH .= "  </tr>\n";
 $GRAPH .= "</table><PRE>\n";
 $GRAPH .= "<BR><BR><a name='callsgraph'/><table border='0' cellpadding='0' cellspacing='2' width='800'>";
 if ($report_display_type == "HTML") {
     $MAIN .= $GRAPH . $GRAPH2 . $GRAPH3;
 } else {
     $MAIN .= "{$OUToutput}";
 }
 $ENDtime = date("U");
 $RUNtime = $ENDtime - $STARTtime;
 if ($DB) {
     echo "{$stmt}\n";
 }
 $row = mysqli_fetch_row($rslt);
 echo _QXZ("FIRST LOGIN:"******" {$row['0']}\n";
 $start = $row[1];
 $stmt = "select event_time,UNIX_TIMESTAMP(event_time) from vicidial_agent_log_archive where event_time <= '" . mysqli_real_escape_string($link, $query_date_END) . "' and event_time >= '" . mysqli_real_escape_string($link, $query_date_BEGIN) . "' and user='******' order by event_time desc limit 1;";
 $rslt = mysql_to_mysqli($stmt, $link);
 if ($DB) {
     echo "{$stmt}\n";
 }
 $row = mysqli_fetch_row($rslt);
 echo _QXZ("LAST LOG ACTIVITY:", 21) . " {$row['0']}\n";
 $end = $row[1];
 $login_time = $end - $start;
 $LOGIN_TIME_H = MathZDC($login_time, 3600);
 $LOGIN_TIME_H = round($LOGIN_TIME_H, 2);
 $LOGIN_TIME_H_int = intval("{$LOGIN_TIME_H}");
 $LOGIN_TIME_M = $LOGIN_TIME_H - $LOGIN_TIME_H_int;
 $LOGIN_TIME_M = $LOGIN_TIME_M * 60;
 $LOGIN_TIME_M = round($LOGIN_TIME_M, 2);
 $LOGIN_TIME_M_int = intval("{$LOGIN_TIME_M}");
 $LOGIN_TIME_S = $LOGIN_TIME_M - $LOGIN_TIME_M_int;
 $LOGIN_TIME_S = $LOGIN_TIME_S * 60;
 $LOGIN_TIME_S = round($LOGIN_TIME_S, 0);
 if ($LOGIN_TIME_S < 10) {
     $LOGIN_TIME_S = "0{$LOGIN_TIME_S}";
 }
 if ($LOGIN_TIME_M_int < 10) {
     $LOGIN_TIME_M_int = "0{$LOGIN_TIME_M_int}";
 }
    if ($call_minutes_int < 10) {
        $call_minutes_int = "0{$call_minutes_int}";
    }
    echo "<tr {$bgcolor}><td><font size=2>{$row['1']}</td>";
    echo "<td align=right><font size=2> {$row['0']}</td>\n";
    echo "<td align=right><font size=2> {$call_hours_int}:{$call_minutes_int}</td></tr>\n";
    $total_calls = $total_calls + $row[0];
    $call_seconds = 0;
    $o++;
}
$stmt = "SELECT sum(length_in_sec) from call_log where extension='" . mysqli_real_escape_string($link, $extension) . "' and server_ip='" . mysqli_real_escape_string($link, $server_ip) . "' and start_time >= '" . mysqli_real_escape_string($link, $begin_date) . " 0:00:01'  and start_time <= '" . mysqli_real_escape_string($link, $end_date) . " 23:59:59'";
$rslt = mysql_to_mysqli($stmt, $link);
$counts_to_print = mysqli_num_rows($rslt);
$row = mysqli_fetch_row($rslt);
$call_seconds = $row[0];
$call_hours = MathZDC($call_seconds, 3600);
$call_hours = round($call_hours, 2);
$call_hours_int = intval("{$call_hours}");
$call_minutes = $call_hours - $call_hours_int;
$call_minutes = $call_minutes * 60;
$call_minutes_int = round($call_minutes, 0);
if ($call_minutes_int < 10) {
    $call_minutes_int = "0{$call_minutes_int}";
}
#	echo "|$stmt|\n";
echo "<tr><td><font size=2>" . _QXZ("TOTAL CALLS") . " </td><td align=right><font size=2> {$total_calls}</td><td align=right><font size=2> {$call_hours_int}:{$call_minutes_int}</td></tr>\n";
echo "</TABLE></center>\n";
echo "<br><br>\n";
echo "<center>\n";
echo "<B>" . _QXZ("LAST 1000 CALLS FOR DATE RANGE") . ":</B>\n";
echo "<TABLE width=400 cellspacing=0 cellpadding=1>\n";
$rslt = mysql_to_mysqli($stmt, $link);
$gmt_recs = mysqli_num_rows($rslt);
if ($gmt_recs > 0) {
    $row = mysqli_fetch_row($rslt);
    $DBSERVER_GMT = "{$row['0']}";
    if (strlen($DBSERVER_GMT) > 0) {
        $SERVER_GMT = $DBSERVER_GMT;
    }
    if ($isdst) {
        $SERVER_GMT++;
    }
} else {
    $SERVER_GMT = date("O");
    $SERVER_GMT = preg_replace('/\\+/i', '', $SERVER_GMT);
    $SERVER_GMT = $SERVER_GMT + 0;
    $SERVER_GMT = MathZDC($SERVER_GMT, 100);
}
$LOCAL_GMT_OFF = $SERVER_GMT;
$LOCAL_GMT_OFF_STD = $SERVER_GMT;
$dedupe_status_select = '';
$stmt = "SELECT status, status_name from vicidial_statuses order by status;";
$rslt = mysql_to_mysqli($stmt, $link);
$stat_num_rows = mysqli_num_rows($rslt);
$snr_count = 0;
while ($stat_num_rows > $snr_count) {
    $row = mysqli_fetch_row($rslt);
    $dedupe_status_select .= "\t\t\t<option value='{$row['0']}'>{$row['0']} - {$row['1']}</option>\n";
    $snr_count++;
}
#if ($DB) {print "SEED TIME  $secX      :   $year-$mon-$mday $hour:$min:$sec  LOCAL GMT OFFSET NOW: $LOCAL_GMT_OFF\n";}
header("Content-type: text/html; charset=utf-8");
$HTML_text .= $UnocidPERCENT . " | ";
$HTML_text .= sprintf("%6s", $totaldnc) . " | ";
$HTML_text .= sprintf("%6s", $Utotaldnc) . " |";
$UprdncPERCENT = MathZDC($Utotaldnc, $Utotal) * 100;
$UprdncPERCENT = round($UprdncPERCENT, 2);
$UprdncPERCENT = sprintf("%6s", $UprdncPERCENT);
$HTML_text .= $UprdncPERCENT . " | ";
$HTML_text .= sprintf("%6s", $totalsale) . " | ";
$HTML_text .= sprintf("%6s", $Utotalsale) . " |";
$UpsalePERCENT = MathZDC($Utotalsale, $Utotal) * 100;
$UpsalePERCENT = round($UpsalePERCENT, 2);
$UpsalePERCENT = sprintf("%6s", $UpsalePERCENT);
$HTML_text .= $UpsalePERCENT . " | ";
$HTML_text .= sprintf("%6s", $totalarch) . " | ";
$HTML_text .= sprintf("%6s", $Utotalarch) . " |";
$UarchPERCENT = MathZDC($Utotalarch, $Utotal) * 100;
$UarchPERCENT = round($UarchPERCENT, 2);
$UarchPERCENT = sprintf("%6s", $UarchPERCENT);
$HTML_text .= $UarchPERCENT . " |\n";
$HTML_text .= "+------------------------------+--------+--------+-------+----------------------+----------------------+-------+--------+--------+-------+--------+--------+-------+--------+--------+-------+--------+--------+-------+\n";
$CSV_text .= "\"" . _QXZ("TOTALS") . "\",\"{$total}\",\"{$Utotal}\",\"n/a\",\"{$queue_str}\",\"{$Uqueue_str}\",\"{$UtotalPERCENT}\",\"{$totalnocid}\",\"{$Utotalnocid}\",\"{$UnocidPERCENT}\",\"{$totaldnc}\",\"{$Utotaldnc}\",\"{$UprdncPERCENT}\",\"{$totalsale}\",\"{$Utotalsale}\",\"{$UpsalePERCENT}\",\"{$totalarch}\",\"{$Utotalarch}\",\"{$UarchPERCENT}\",\n";
$HTML_text .= "** - (x|y) " . _QXZ("values under") . " \"" . _QXZ("SENT TO QUEUE") . "\" - \"x\" " . _QXZ("is number of calls taken into queue") . ", \"y\" " . _QXZ("is number of calls sent to an agent") . "\n";
$CSV_text .= "\n\"** - (x|y) " . _QXZ("values under") . " '" . _QXZ("SENT TO QUEUE") . "'\",\n\" - 'x' " . _QXZ("is number of calls taken into queue") . "\",\n\" - 'y' " . _QXZ("is number of calls sent to an agent") . "\",\n";
$ENDtime = date("U");
$RUNtime = $ENDtime - $STARTtime;
$HTML_text .= "\n" . _QXZ("Run Time") . ": {$RUNtime} " . _QXZ("seconds") . "\n";
$HTML_text .= "</PRE>\n";
$HTML_text .= "</TD></TR></TABLE>\n";
$HTML_text .= "</BODY></HTML>\n";
$HTML_text .= "\n\n<BR>{$db_source}";
$HTML_text .= "</TD></TR></TABLE>";
 $TOTALleads = sprintf("%10s", $TOTALleads);
 $OUToutput .= "     +--------+-----------------------------------+------------+\n";
 $OUToutput .= "     | " . _QXZ("TOTAL", 41, "r") . ": | {$TOTALleads} |\n";
 $OUToutput .= "     +--------------------------------------------+------------+\n";
 $CSV_text4 .= "\"" . _QXZ("TOTAL") . ":\",\"\",\"{$TOTALleads}\"\n\n\n";
 for ($d = 0; $d < count($graph_stats); $d++) {
     if ($d == 0) {
         $class = " first";
     } else {
         if ($d + 1 == count($graph_stats)) {
             $class = " last";
         } else {
             $class = "";
         }
     }
     $STATUS_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][1], $max_status)) . "' height='16' />" . $graph_stats[$d][1] . "</td></tr>";
 }
 $STATUS_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($TOTALleads) . "</th></tr></table>";
 $JS_onload .= "\tDraw" . $LISTIDlists[$i] . "Graph('FLAGS', '1');\n";
 $JS_text .= "function Draw" . $LISTIDlists[$i] . "Graph(graph, th_id) {\n";
 $JS_text .= "\tvar FLAGS_graph=\"{$FLAGS_graph}\";\n";
 $JS_text .= "\tvar STATUS_graph=\"{$STATUS_graph}\";\n";
 $JS_text .= "\n";
 $JS_text .= "\tfor (var i=1; i<=2; i++) {\n";
 $JS_text .= "\t\tvar cellID=\"graph" . $LISTIDlists[$i] . "\"+i;\n";
 $JS_text .= "\t\tdocument.getElementById(cellID).style.backgroundColor='#DDDDDD';\n";
 $JS_text .= "\t}\n";
 $JS_text .= "\tvar cellID=\"graph" . $LISTIDlists[$i] . "\"+th_id;\n";
 $JS_text .= "\tdocument.getElementById(cellID).style.backgroundColor='#999999';\n";
 $JS_text .= "\tvar graph_to_display=eval(graph+\"_graph\");\n";
 $JS_text .= "\tdocument.getElementById('status_" . $LISTIDlists[$i] . "_graph').innerHTML=graph_to_display;\n";
         if ($DB) {
             echo "{$stmt}\n";
         }
         $rslt = mysql_to_mysqli($stmt, $link);
         $affected_rows = mysqli_affected_rows($link);
         print "<!-- NEW vicidial_admin_log record inserted for {$PHP_AUTH_USER}:   |{$affected_rows}| -->\n";
         echo _QXZ("The timeclock session has been updated") . ". <A HREF=\"{$PHP_SELF}?timeclock_id={$LOGINevent_id}\">" . _QXZ("Click here to view") . "</A>.<BR>\n";
         exit;
     }
 }
 ##### END TIMECLOCK RECORD MODIFY #####
 echo "\n<BR>";
 if ($modify_timeclock_log > 0) {
     #	$LOGINevent_id =	$timeclock_id;
     #	$LOGOUTevent_id =	$tcid_link;
     $event_hours = MathZDC($LOGINlogin_sec, 3600);
     $event_hours_int = round($event_hours, 2);
     $event_hours_int = intval("{$event_hours_int}");
     $event_minutes = $event_hours - $event_hours_int;
     $event_minutes = $event_minutes * 60;
     $event_minutes_int = round($event_minutes, 0);
     if ($event_minutes_int < 10) {
         $event_minutes_int = "0{$event_minutes_int}";
     }
     $stmt = "SELECT full_name from vicidial_users where user='******';";
     if ($DB) {
         echo "|{$stmt}|\n";
     }
     $rslt = mysql_to_mysqli($stmt, $link);
     $row = mysqli_fetch_row($rslt);
     $full_name = $row[0];
 $totQUEUEmax = sprintf("%5s", $totQUEUEmax);
 while (strlen($totQUEUEmax) > 5) {
     $totQUEUEmax = preg_replace('/.$/', '', $totQUEUEmax);
 }
 $totDROPS = sprintf("%5s", $totDROPS);
 $totCALLS = sprintf("%5s", $totCALLS);
 $ASCII_text .= "+-------------+-------------------------------------------------------------------------+-------+\n";
 $ASCII_text .= "| " . _QXZ("TOTAL", 11) . " |                                                                         | {$totCALLS} |\n";
 $ASCII_text .= "+-------------+-------------------------------------------------------------------------+-------+\n";
 for ($d = 0; $d < count($graph_stats); $d++) {
     $graph_stats[$d][0] = preg_replace('/\\s/', "", $graph_stats[$d][0]);
     $GRAPH_text .= "  <tr><td class='chart_td' width='50'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value' width='600' valign='bottom'>\n";
     if ($graph_stats[$d][1] > 0) {
         $GRAPH_text .= "<ul class='overlap_barGraph'><li class=\"p1\" style=\"height: 12px; left: 0px; width: " . round(MathZDC(600 * $graph_stats[$d][1], $max_calls)) . "px\">" . $graph_stats[$d][1] . "</li>";
         if ($graph_stats[$d][2] > 0) {
             $GRAPH_text .= "<li class=\"p2\" style=\"height: 12px; left: 0px; width: " . round(MathZDC(600 * $graph_stats[$d][2], $max_calls)) . "px\">" . $graph_stats[$d][2] . "</li>";
         }
         $GRAPH_text .= "</ul>\n";
     } else {
         $GRAPH_text .= "0";
     }
     $GRAPH_text .= "</td></tr>\n";
 }
 $GRAPH_text .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTALS") . ":</th><th class='thgraph' scope='col'>" . trim($totCALLS) . "</th></tr></table>";
 if ($report_display_type == "HTML") {
     $MAIN .= $GRAPH_text;
 } else {
     $MAIN .= $ASCII_text;
 }
 $CSV_text1 .= "\"" . _QXZ("TOTAL") . "\",\"{$totCALLS}\"\n";
 $ENDtime = date("U");
    $MAIN .= "\t<th class=\"thgraph\" scope=\"col\">" . _QXZ("USER") . "  </th>\n";
    $MAIN .= "\t<th class=\"thgraph\" scope=\"col\">" . _QXZ("HOURS") . " </th>\n";
    $MAIN .= "  </tr>\n";
    for ($i = 0; $i < count($ct_ary); $i++) {
        if ($i == 0) {
            $class = " first";
        } else {
            if ($i + 1 == count($ct_ary)) {
                $class = " last";
            } else {
                $class = "";
            }
        }
        $MAIN .= "  <tr>\n";
        $MAIN .= "\t<td class=\"chart_td{$class}\">" . $ct_ary[$i][0] . "</td>\n";
        $MAIN .= "\t<td class=\"chart_td value{$class}\"><img src=\"images/bar.png\" alt=\"\" width=\"" . round(MathZDC(400 * $ct_ary[$i][1], $high_ct)) . "\" height=\"16\" />" . $ct_ary[$i][1] . "</td>\n";
        $MAIN .= "  </tr>\n";
    }
    $MAIN .= "  <tr>\n";
    $MAIN .= "\t<th class=\"thgraph\" scope=\"col\">" . _QXZ("TOTAL HOURS") . ":</th>\n";
    $MAIN .= "\t<th class=\"thgraph\" scope=\"col\">" . trim($TOThours) . "</th>\n";
    $MAIN .= "  </tr>\n";
    $MAIN .= "</table>\n";
    $MAIN .= "<PRE>\n";
    ###########################
}
$MAIN .= "</CENTER>\n";
$MAIN .= "</BODY></HTML>\n";
if ($file_download > 0) {
    $FILE_TIME = date("Ymd-His");
    $CSVfilename = "timeclock_report_{$US}{$FILE_TIME}.csv";
         $x++;
         $CSV_text .= "\"{$val[$x]}\",";
         $ASCII_text .= " " . sprintf("%5s", $val[$x]) . " |";
         $TOTALS_array[$x] += $val[$x];
         $x++;
         $CSV_text .= "\"{$val[$x]} %\",";
         $ASCII_text .= " " . sprintf("%10s", $val[$x]) . "% |";
         $TOTALS_array[$x] = sprintf("%0.2f", MathZDC(100 * $TOTALS_array[$x - 1], $TOTALS_array[$x - 2]));
         $x++;
         $CSV_text .= "\"{$val[$x]}\",";
         $ASCII_text .= " " . sprintf("%12s", $val[$x]) . " |";
         $x++;
         $CSV_text .= "\"" . sec_convert($val[$x], 'H') . "\",";
         $ASCII_text .= " " . sprintf("%9s", sec_convert($val[$x], 'H')) . " ||";
         $TOTALS_array[$x] += $val[$x];
         $TOTALS_array[$x - 1] = sprintf("%0.2f", MathZDC($TOTALS_array[$x - 3], MathZDC($TOTALS_array[$x], 3600)));
         # Go back to get last result
     }
     $ASCII_text .= "\n";
     $CSV_text .= "\n";
 }
 $ASCII_text .= $ASCII_header2;
 $CSV_text .= '"","' . _QXZ("TOTALS") . '",';
 $ASCII_text .= "| " . sprintf("%26s", $TOTALS_array[0]) . " ||";
 $GRAPH_text .= $GRAPH . $GRAPH2 . $GRAPH3;
 for ($i = 1; $i < count($TOTALS_array); $i++) {
     $CSV_text .= "\"{$TOTALS_array[$i]}\",";
     switch ($i % 5) {
         case "1":
         case "2":
             $ASCII_text .= " " . sprintf("%5s", $TOTALS_array[$i]) . " |";
    echo $ASCII_text;
}
echo "</span>\n";
if ($report_display_type == "TEXT" || !$report_display_type) {
    echo "<span style=\"position:absolute;left:3px;top:3px;z-index:18;\"  id=agent_status_bars>\n";
    echo "<PRE><FONT SIZE=2>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    $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 "              <SPAN class=\"yellow\">";
            $TOPsortPLOT = MathZDC($TOPsortTALLY[$i], $TOPsortMAX) * 120;
            $h = 0;
            while ($h <= $TOPsortPLOT) {
                echo " ";
                $h++;
            }
            echo "</SPAN>\n";
        }
        $m++;
    }
    echo "</span>\n";
}
if ($db_source == 'S') {
    mysqli_close($link);
    $use_slave_server = 0;
    $db_source = 'M';
 for ($d = 0; $d < count($graph_stats); $d++) {
     if ($d == 0) {
         $class = " first";
     } else {
         if ($d + 1 == count($graph_stats)) {
             $class = " last";
         } else {
             $class = "";
         }
     }
     $CALLS_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][1], $max_calls)) . "' height='16' />" . $graph_stats[$d][1] . "</td></tr>";
     $SALES_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][2], $max_sales)) . "' height='16' />" . $graph_stats[$d][2] . "</td></tr>";
     $DROP_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][3], $max_drops)) . "' height='16' />" . $graph_stats[$d][3] . "</td></tr>";
     $OTHER_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][4], $max_other)) . "' height='16' />" . $graph_stats[$d][4] . "</td></tr>";
     $SALES2_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][5], $max_sales2)) . "' height='16' />" . $graph_stats[$d][5] . "</td></tr>";
     $CONVPCT_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][6], $max_conv_pct)) . "' height='16' />" . $graph_stats[$d][6] . "%</td></tr>";
 }
 $CALLS_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($TOTcalls) . "</th></tr></table>";
 $SALES_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($totA1) . "</th></tr></table>";
 $DROP_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($totDROP) . "</th></tr></table>";
 $OTHER_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($totOTHER) . "</th></tr></table>";
 $SALES2_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($TOTsales) . "</th></tr></table>";
 $CONVPCT_graph .= "<tr><th class='thgraph' scope='col'>TOTAL:</th><th class='thgraph' scope='col'>" . trim($totCpct) . "%</th></tr></table>";
 $JS_onload .= "\tDrawCloserGraph('CALLS', '1');\n";
 $JS_text .= "function DrawCloserGraph(graph, th_id) {\n";
 $JS_text .= "\tvar CALLS_graph=\"{$CALLS_graph}\";\n";
 $JS_text .= "\tvar SALES_graph=\"{$SALES_graph}\";\n";
 $JS_text .= "\tvar DROP_graph=\"{$DROP_graph}\";\n";
 $JS_text .= "\tvar OTHER_graph=\"{$OTHER_graph}\";\n";
 $JS_text .= "\tvar SALES2_graph=\"{$SALES2_graph}\";\n";
 $JS_text .= "\tvar CONVPCT_graph=\"{$CONVPCT_graph}\";\n";
         $class = " first";
     } else {
         if ($d + 1 == count($graph_stats)) {
             $class = " last";
         } else {
             $class = "";
         }
     }
     $TOTAL_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][1], $max_total)) . "' height='16' />" . sec_convert($graph_stats[$d][1], $TIME_H_agentperfdetail) . "</td></tr>";
     $NONPAUSE_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][2], $max_nonpause)) . "' height='16' />" . sec_convert($graph_stats[$d][2], $TIME_H_agentperfdetail) . "</td></tr>";
     $PAUSE_graph .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][3], $max_pause)) . "' height='16' />" . sec_convert($graph_stats[$d][3], $TIME_H_agentperfdetail) . "</td></tr>";
     for ($e = 0; $e < count($sub_statusesARY); $e++) {
         $Sstatus = $sub_statusesARY[$e];
         $varname = $Sstatus . "_graph";
         $max_varname = "max_" . $Sstatus;
         ${$varname} .= "  <tr><td class='chart_td{$class}'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $graph_stats[$d][$e + 4], ${$max_varname})) . "' height='16' />" . sec_convert($graph_stats[$d][$e + 4], $TIME_H_agentperfdetail) . "</td></tr>";
     }
 }
 $TOTAL_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("LOGIN TIME") . ":</th><th class='thgraph' scope='col'>" . trim($TOTtotTOTAL_MS) . "</th></tr></table>";
 $NONPAUSE_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("LOGIN TIME") . ":</th><th class='thgraph' scope='col'>" . trim($TOTtotNONPAUSE_MS) . "</th></tr></table>";
 $PAUSE_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("LOGIN TIME") . ":</th><th class='thgraph' scope='col'>" . trim($TOTtotPAUSE_MS) . "%</th></tr></table>";
 for ($e = 0; $e < count($sub_statusesARY); $e++) {
     $Sstatus = $sub_statusesARY[$e];
     $total_var = $Sstatus . "_total";
     $graph_var = $Sstatus . "_graph";
     ${$graph_var} .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim(sec_convert(${$total_var}, $TIME_H_agentperfdetail)) . "</th></tr></table>";
 }
 $JS_onload .= "\tDrawPauseGraph('TOTAL', '1');\n";
 $JS_text = "<script language='Javascript'>\n";
 $JS_text .= "function DrawPauseGraph(graph, th_id) {\n";
 $JS_text .= "\tvar graph_TOTAL=\"{$TOTAL_graph}\";\n";
     $graph_stats[$i][2] = trim($drop_count[$i]);
     if (trim($hour_count[$i]) > $max_calls) {
         $max_calls = trim($hour_count[$i]);
     }
     $i++;
     $h++;
 }
 $ASCII_text .= "+------+-------------------------------------------------------------------------------------------------------+-------+-------+\n\n";
 for ($d = 0; $d < count($graph_stats); $d++) {
     if (strlen(trim($graph_stats[$d][0]))) {
         $graph_stats[$d][0] = preg_replace('/\\s/', "", $graph_stats[$d][0]);
         $GRAPH_text .= "  <tr><td class='chart_td' width='50'>" . $graph_stats[$d][0] . "</td><td nowrap class='chart_td value' width='600' valign='bottom'>\n";
         if ($graph_stats[$d][1] > 0) {
             $GRAPH_text .= "<ul class='overlap_barGraph'><li class=\"p1\" style=\"height: 12px; left: 0px; width: " . round(MathZDC(600 * $graph_stats[$d][1], $max_calls)) . "px\"><font style='background-color: #900'>" . $graph_stats[$d][1] . "</font></li>";
             if ($graph_stats[$d][2] > 0) {
                 $GRAPH_text .= "<li class=\"p2\" style=\"height: 12px; left: 0px; width: " . round(MathZDC(600 * $graph_stats[$d][2], $max_calls)) . "px\"><font style='background-color: #009'>" . $graph_stats[$d][2] . "</font></li>";
             }
             $GRAPH_text .= "</ul>\n";
         } else {
             $GRAPH_text .= "0";
         }
         $GRAPH_text .= "</td></tr>\n";
     }
 }
 $GRAPH_text .= "</table><BR/><BR/>";
 if ($report_display_type == "HTML") {
     $MAIN .= $GRAPH_text;
 } else {
     $MAIN .= $ASCII_text;
 }
 ##### Answered wait time breakdown
                }
            }
        }
    }
    $rpt_header .= _QXZ("Date") . ": " . date("m/d/Y") . " -- " . _QXZ("Time") . ": " . date("H:i a") . "\n\n";
    $rpt_header .= "+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+{$rpt_header_BORDER}\n";
    $rpt_header .= "| " . _QXZ("Call list", 9) . " | " . _QXZ("List description", 30) . " | " . _QXZ("Campaign", 8) . " | " . _QXZ("Last call date", 19) . " | " . _QXZ("Start Inv", 9) . " | " . _QXZ("Call Inv", 8) . " | " . _QXZ("Call Inv", 8) . " | " . _QXZ("Call Inv", 8) . " | " . _QXZ("Call Inv", 8) . " | " . _QXZ("Dial Avg", 8) . " | " . _QXZ("Pen.", 5) . " % |{$rpt_header_SHIFTS}\n";
    $rpt_header .= "|           |                                |          |                     |           | " . _QXZ("Total", 8) . " | " . _QXZ("No filtr", 8) . " | " . _QXZ("One-off", 8) . " | " . _QXZ("Inactive", 8) . " |          |         |{$rpt_header_SHIFTS_lower}\n";
    $rpt_header .= "+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+{$rpt_header_BORDER}\n";
    $CSV_header = "\"" . _QXZ("{$report_name}") . "\"\n";
    $CSV_header .= "\"Date: " . date("m/d/Y") . "\",\"\",\"Time: " . date("H:i a") . "\"\n\n";
    $CSV_header .= "\"" . _QXZ("Call list") . "\",\"" . _QXZ("List description") . "\",\"" . _QXZ("Campaign") . "\",\"" . _QXZ("Last call date") . "\",\"" . _QXZ("Start Inv") . "\",\"" . _QXZ("Call Inv Total") . "\",\"" . _QXZ("Call Inv - No filter") . "\",\"" . _QXZ("Call Inv - One-offs") . "\",\"" . _QXZ("Call Inv - Inactive dialable statuses") . "\",\"" . _QXZ("Dial Avg") . "\",\"" . _QXZ("Pen.") . " %\"," . substr($CSV_header_SHIFTS, 0, -1) . "\n";
    $rpt_footer = "+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+{$rpt_header_BORDER}\n";
    #### PRINT TOTALS ####
    $total_average_call_count = sprintf("%.1f", MathZDC($total_total_calls, $total_list_start_inv));
    $total_penetration = sprintf("%.2f", MathZDC(100 * ($total_list_start_inv - $total_dialable_count), $total_list_start_inv));
    $rpt_footer .= "|" . _QXZ("TOTALS", 76) . " | " . sprintf("%9s", $total_list_start_inv) . " | " . sprintf("%8s", $total_dialable_count) . " | " . sprintf("%8s", $total_dialable_count_nofilter) . " | " . sprintf("%8s", $total_dialable_count_oneoff) . " | " . sprintf("%8s", $total_dialable_count_inactive) . " | " . sprintf("%8s", $total_average_call_count) . " | " . sprintf("%6s", $total_penetration) . "% |";
    $CSV_body .= "\"\",\"\",\"\",\"" . _QXZ("TOTALS") . "\",\"{$total_list_start_inv}\",\"{$total_dialable_count}\",\"{$total_dialable_count_nofilter}\",\"{$total_dialable_count_oneoff}\",\"{$total_dialable_count_inactive}\",\"{$total_average_call_count}\",\"{$total_penetration}\"";
    $b = 0;
    while ($b < count($shift_ary)) {
        $total_varname = "total_" . $shift_ary[$b];
        $rpt_footer .= " " . sprintf("%8s", ${$total_varname}) . " |";
        $CSV_body .= ",\"" . ${$total_varname} . "\"";
        $b++;
    }
    $CSV_body .= "\n";
    $rpt_footer .= "\n";
    ######################
    $rpt_footer .= "+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+{$rpt_header_BORDER}\n";
}
$HTML_header .= "</PRE>\n";
function RecalculateHPD($query_date_BEGIN, $query_date_END, $time_BEGIN, $time_END)
{
    global $hpd, $query_date_BEGIN, $query_date_END, $time_BEGIN, $time_END;
    global $DURATIONday, $SQepoch, $EQepoch, $SQepochDAY, $SQsec, $EQsec;
    $TB_array = explode(':', $time_BEGIN);
    $TE_array = explode(':', $time_END);
    $TBoffset = 0;
    $TEoffset = 0;
    if ($TB_array[0] > 24) {
        while ($TB_array[0] > 24) {
            $TB_array[0]--;
            $TBoffset += 3600;
        }
        $time_BEGIN = "{$TB_array['0']}:{$TB_array['1']}:{$TB_array['2']}";
    }
    if ($TE_array[0] > 24) {
        while ($TE_array[0] > 24) {
            $TE_array[0]--;
            $TEoffset += 3600;
        }
        $time_END = "{$TE_array['0']}:{$TE_array['1']}:{$TE_array['2']}";
    }
    $time1 = strtotime($time_BEGIN) + $TBoffset;
    $time2 = strtotime($time_END) + 1 + $TEoffset;
    $hpd = ceil(MathZDC($time2 - $time1, 3600));
    if ($hpd < 0) {
        $hpd += 24;
    }
    $SQdate_ARY = explode(' ', $query_date_BEGIN);
    $SQday_ARY = explode('-', $SQdate_ARY[0]);
    $SQtime_ARY = explode(':', $SQdate_ARY[1]);
    $EQdate_ARY = explode(' ', $query_date_END);
    $EQday_ARY = explode('-', $EQdate_ARY[0]);
    $EQtime_ARY = explode(':', $EQdate_ARY[1]);
    $SQepochDAY = mktime(0, 0, 0, $SQday_ARY[1], $SQday_ARY[2], $SQday_ARY[0]);
    $SQepoch = mktime($SQtime_ARY[0], $SQtime_ARY[1], $SQtime_ARY[2], $SQday_ARY[1], $SQday_ARY[2], $SQday_ARY[0]);
    $EQepoch = mktime($EQtime_ARY[0], $EQtime_ARY[1], $EQtime_ARY[2], $EQday_ARY[1], $EQday_ARY[2], $EQday_ARY[0]);
    $SQsec = $SQtime_ARY[0] * 3600 + $SQtime_ARY[1] * 60 + $SQtime_ARY[2] * 1;
    $EQsec = $EQtime_ARY[0] * 3600 + $EQtime_ARY[1] * 60 + $EQtime_ARY[2] * 1;
    if (!$DURATIONday) {
        $DURATIONsec = $EQepoch - $SQepoch;
        $DURATIONday = intval(MathZDC($DURATIONsec, 86400) + 1);
        if ($EQsec < $SQsec and $DURATIONday < 1) {
            $EQepoch = $SQepochDAY + ($EQsec + 86400);
            $query_date_END = date("Y-m-d H:i:s", $EQepoch);
            $DURATIONday++;
        }
    }
}
     $row = mysqli_fetch_row($rslt);
     $drop_count[$i] = $row[0];
     $i++;
     $h++;
 }
 $hour_multiplier = MathZDC(100, $hi_hour_count);
 #$hour_multiplier = round($hour_multiplier, 0);
 echo "<!-- HICOUNT: {$hi_hour_count}|{$hour_multiplier} -->\n";
 echo _QXZ("GRAPH IN 15 MINUTE INCREMENTS OF TOTAL INCOMING CALLS FOR THIS GROUP") . "\n";
 $k = 1;
 $Mk = 0;
 $call_scale = '0';
 while ($k <= 102) {
     if ($Mk >= 5) {
         $Mk = 0;
         $scale_num = MathZDC($k, $hour_multiplier);
         $scale_num = round($scale_num, 0);
         $LENscale_num = strlen($scale_num);
         $k = $k + $LENscale_num;
         $call_scale .= "{$scale_num}";
     } else {
         $call_scale .= " ";
         $k++;
         $Mk++;
     }
 }
 echo "+------+-------------------------------------------------------------------------------------------------------+-------+-------+\n";
 #echo "| HOUR | GRAPH IN 15 MINUTE INCREMENTS OF TOTAL INCOMING CALLS FOR THIS GROUP                                  | DROPS | TOTAL |\n";
 echo "| " . _QXZ("HOUR", 4) . " |{$call_scale}| " . _QXZ("DROPS", 5) . " | " . _QXZ("TOTAL", 5) . " |\n";
 echo "+------+-------------------------------------------------------------------------------------------------------+-------+-------+\n";
 $ZZ = '00';
function get_server_load($windows = false)
{
    $os = strtolower(PHP_OS);
    if (strpos($os, "win") === false) {
        if (file_exists("/proc/loadavg")) {
            $load = file_get_contents("/proc/loadavg");
            $load = explode(' ', $load);
            return $load[0] . ' ' . $load[1] . ' ' . $load[2];
        } elseif (function_exists("shell_exec")) {
            $load = explode(' ', `uptime`);
            return $load[count($load) - 3] . ' ' . $load[count($load) - 2] . ' ' . $load[count($load) - 1];
        } else {
            return false;
        }
    } elseif ($windows) {
        if (class_exists("COM")) {
            $wmi = new COM("WinMgmts:\\\\.");
            $cpus = $wmi->InstancesOf("Win32_Processor");
            $cpuload = 0;
            $i = 0;
            while ($cpu = $cpus->Next()) {
                $cpuload += $cpu->LoadPercentage;
                $i++;
            }
            $cpuload = round(MathZDC($cpuload, $i), 2);
            return "{$cpuload}%";
        } else {
            return false;
        }
    }
}
     $TOTALSALES_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][7], $max_totalsales)) . "' height='16' />" . $total_graph_stats[$d][7] . "</td></tr>";
     $TOTALSALESLEADSRATIO_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][8], $max_totalsalesleadsratio)) . "' height='16' />" . $total_graph_stats[$d][8] . "%</td></tr>";
     $TOTALSALESCONTACTSRATIO_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][9], $max_totalsalescontactsratio)) . "' height='16' />" . $total_graph_stats[$d][9] . "%</td></tr>";
     $TOTALSALESPERHOUR_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][10], $max_totalsalesperhour)) . "' height='16' />" . $total_graph_stats[$d][10] . "</td></tr>";
     $TOTALINCSALES_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][11], $max_totalincsales)) . "' height='16' />" . $total_graph_stats[$d][11] . "</td></tr>";
     $TOTALCANCELLEDSALES_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][12], $max_totalcancelledsales)) . "' height='16' />" . $total_graph_stats[$d][12] . "</td></tr>";
     $TOTALCALLBACKS_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][13], $max_totalcallbacks)) . "' height='16' />" . $total_graph_stats[$d][13] . "</td></tr>";
     $TOTALFIRSTCALLS_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][14], $max_totalfirstcall)) . "' height='16' />" . $total_graph_stats[$d][14] . "</td></tr>";
     $TOTALAVGSALETIME_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][15], $max_totalavgsaletime)) . "' height='16' />" . sec_convert($total_graph_stats[$d][15], 'H') . "</td></tr>";
     $TOTALAVGCONTACTTIME_graph .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][16], $max_totalavgcontacttime)) . "' height='16' />" . sec_convert($total_graph_stats[$d][16], 'H') . "</td></tr>";
     for ($e = 0; $e < count($call_status); $e++) {
         $Sstatus = $call_status[$e];
         $varname = "TOTAL" . $Sstatus . "_graph";
         $max_varname = "max_total" . $Sstatus;
         # $max.= "<!-- $max_varname => ".$$max_varname." //-->\n";
         ${$varname} .= "  <tr><td class='chart_td{$class}'>" . $total_graph_stats[$d][0] . "</td><td nowrap class='chart_td value{$class}'><img src='images/bar.png' alt='' width='" . round(MathZDC(400 * $total_graph_stats[$d][$e + 17], ${$max_varname})) . "' height='16' />" . $total_graph_stats[$d][$e + 17] . "</td></tr>";
     }
 }
 $TOTALCALLS_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_calls) . "</th></tr></table>";
 $TOTALLEADS_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_leads) . "</th></tr></table>";
 $TOTALCONTACTS_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_contacts) . "</th></tr></table>";
 $TOTALCONTACTRATIO_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_contact_ratio) . "%</th></tr></table>";
 $TOTALSYSTEMTIME_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . sec_convert($total_system_time, 'H') . "</th></tr></table>";
 $TOTALTALKTIME_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . sec_convert($total_talk_time, 'H') . "</th></tr></table>";
 $TOTALSALES_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_sales) . "</th></tr></table>";
 $TOTALSALESLEADSRATIO_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_sales_ratio) . "%</th></tr></table>";
 $TOTALSALESCONTACTSRATIO_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_sale_contact_ratio) . "%</th></tr></table>";
 $TOTALSALESPERHOUR_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_sales_per_hour) . "</th></tr></table>";
 $TOTALINCSALES_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_inc_sales) . "</th></tr></table>";
 $TOTALCANCELLEDSALES_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_cnc_sales) . "</th></tr></table>";
 $TOTALCALLBACKS_graph .= "<tr><th class='thgraph' scope='col'>" . _QXZ("TOTAL") . ":</th><th class='thgraph' scope='col'>" . trim($total_callbacks) . "</th></tr></table>";