Exemplo n.º 1
0
 function _calls_detail_map_recordset($cdr)
 {
     $mapaEstados = array('abandonada' => 'Bỏ nhỡ', 'Abandoned' => 'Bỏ nhỡ', 'terminada' => 'Đã nghe', 'Success' => 'Đã nghe', 'fin-monitoreo' => _tr('End Monitor'), 'Failure' => _tr('Failure'), 'NoAnswer' => _tr('NoAnswer'), 'OnQueue' => _tr('OnQueue'), 'Placing' => _tr('Placing'), 'Ringing' => _tr('Ringing'), 'ShortCall' => _tr('ShortCall'), 'activa' => 'Đang gọi');
     return array($cdr['stt'], $cdr[0], htmlentities($cdr[1], ENT_COMPAT, "UTF-8"), substr($cdr[2], 0, 10), substr($cdr[2], 11, 8), substr($cdr[3], 0, 10), substr($cdr[3], 11, 8), is_null($cdr[4]) ? '-' : formatoSegundos($cdr[4]), is_null($cdr[5]) ? '-' : formatoSegundos($cdr[5]), $cdr[6], $cdr[8], $cdr[9], isset($mapaEstados[$cdr[10]]) ? $mapaEstados[$cdr[10]] : _tr($cdr[10]), is_null($cdr[12]) || trim($cdr[12] == '') ? '' : '<a href="javascript:void(0)" onclick="view_note(\'' . $cdr[11] . '\')">Xem</a>');
 }
Exemplo n.º 2
0
function _moduleContent(&$smarty, $module_name)
{
    include_once "libs/paloSantoGrid.class.php";
    include_once "libs/paloSantoDB.class.php";
    include_once "libs/paloSantoForm.class.php";
    include_once "libs/paloSantoConfig.class.php";
    require_once "libs/misc.lib.php";
    //Incluir librería de lenguaje
    load_language_module($module_name);
    //include module files
    include_once "modules/{$module_name}/configs/default.conf.php";
    include_once "modules/{$module_name}/libs/paloSantoCallPerAgent.class.php";
    global $arrConf;
    global $arrLang;
    $arrCallsAgentTmp = 0;
    //folder path for custom templates
    $base_dir = dirname($_SERVER['SCRIPT_FILENAME']);
    $templates_dir = isset($arrConfig['templates_dir']) ? $arrConfig['templates_dir'] : 'themes';
    $local_templates_dir = "{$base_dir}/modules/{$module_name}/" . $templates_dir . '/' . $arrConf['theme'];
    $pConfig = new paloConfig("/etc", "amportal.conf", "=", "[[:space:]]*=[[:space:]]*");
    $arrConfig = $pConfig->leer_configuracion(false);
    $pDB = new paloDB($cadena_dsn);
    $arrData = array();
    $oCallsAgent = new paloSantoCallsAgent($pDB);
    $urlVars = array('menu' => $module_name);
    $smarty->assign("menu", "calls_per_agent");
    $smarty->assign("Filter", _tr('Query'));
    $arrFormElements = createFieldFilter();
    $oFilterForm = new paloForm($smarty, $arrFormElements);
    // Por omision las fechas toman el sgte. valor (la fecha de hoy)
    $date_start = date("Y-m-d") . " 00:00:00";
    $date_end = date("Y-m-d") . " 23:59:59";
    $arrFilterExtraVars = null;
    $fieldPat = array();
    if (isset($_POST['filter'])) {
        if ($oFilterForm->validateForm($_POST)) {
            // Exito, puedo procesar los datos ahora.
            $date_start = translateDate($_POST['date_start']) . " 00:00:00";
            $date_end = translateDate($_POST['date_end']) . " 23:59:59";
            if (!empty($_POST['field_pattern'])) {
                $fieldPat[$_POST['field_name']][] = $_POST['field_pattern'];
            }
            if (!empty($_POST['field_pattern_1'])) {
                $fieldPat[$_POST['field_name_1']][] = $_POST['field_pattern_1'];
            }
            $arrFilterExtraVars = array("date_start" => $_POST['date_start'], "date_end" => $_POST['date_end'], "field_name" => $_POST['field_name'], "field_pattern" => $_POST['field_pattern'], "field_name_1" => $_POST['field_name_1'], "field_pattern_1" => $_POST['field_pattern_1']);
        } else {
            // Error
            $smarty->assign("mb_title", _tr("Validation Error"));
            $arrErrores = $oFilterForm->arrErroresValidacion;
            $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br>";
            foreach ($arrErrores as $k => $v) {
                $strErrorMsg .= "{$k}, ";
            }
            $strErrorMsg .= "";
            $smarty->assign("mb_message", $strErrorMsg);
        }
        $htmlFilter = $contenidoModulo = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST);
    } else {
        if (isset($_GET['date_start']) and isset($_GET['date_end'])) {
            $date_start = translateDate($_GET['date_start']) . " 00:00:00";
            $date_end = translateDate($_GET['date_end']) . " 23:59:59";
            if (!empty($_GET['field_pattern'])) {
                $fieldPat[$_GET['field_name']][] = $_GET['field_pattern'];
            }
            if (!empty($_GET['field_pattern_1'])) {
                $fieldPat[$_GET['field_name_1']][] = $_GET['field_pattern_1'];
            }
            $arrFilterExtraVars = array("date_start" => $_GET['date_start'], "date_end" => $_GET['date_end']);
            $htmlFilter = $contenidoModulo = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_GET);
        } else {
            $htmlFilter = $contenidoModulo = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", array('date_start' => date("d M Y"), 'date_end' => date("d M Y"), 'field_name' => 'agent', 'field_pattern' => '', 'field_name_1' => 'agent', 'field_pattern_1' => ''));
        }
    }
    $bElastixNuevo = method_exists('paloSantoGrid', 'setURL');
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->enableExport();
    // enable export.
    $oGrid->showFilter($htmlFilter);
    $bExportando = $bElastixNuevo ? $oGrid->isExportAction() : isset($_GET['exportcsv']) && $_GET['exportcsv'] == 'yes' || isset($_GET['exportspreadsheet']) && $_GET['exportspreadsheet'] == 'yes' || isset($_GET['exportpdf']) && $_GET['exportpdf'] == 'yes';
    $offset = 0;
    $limit = 20;
    if (isset($fieldPat['type'])) {
        $fieldPat['type'] = array_map('strtoupper', $fieldPat['type']);
    }
    $arrCallsAgentTmp = $oCallsAgent->obtenerCallsAgent($date_start, $date_end, $fieldPat);
    if (!is_array($arrCallsAgentTmp)) {
        $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => $oCallsAgent->errMsg));
        $arrCallsAgentTmp = array();
    }
    $totalCallsAgents = count($arrCallsAgentTmp);
    // Si se quiere avanzar a la sgte. pagina
    if ($bElastixNuevo) {
        $oGrid->setLimit($limit);
        $oGrid->setTotal($totalCallsAgents + 1);
        $offset = $oGrid->calculateOffset();
    } else {
        if (isset($_GET['nav']) && $_GET['nav'] == "end") {
            // Mejorar el sgte. bloque.
            if ($totalCallsAgents % $limit == 0) {
                $offset = $totalCallsAgents - $limit;
            } else {
                $offset = $totalCallsAgents - $totalCallsAgents % $limit;
            }
        }
        // Si se quiere avanzar a la sgte. pagina
        if (isset($_GET['nav']) && $_GET['nav'] == "next") {
            $offset = $_GET['start'] + $limit - 1;
        }
        // Si se quiere retroceder
        if (isset($_GET['nav']) && $_GET['nav'] == "previous") {
            $offset = $_GET['start'] - $limit - 1;
        }
    }
    // Bloque comun
    $arrCallsAgent = array_slice($arrCallsAgentTmp, $offset, $limit);
    $arrData = array();
    $sumCallAnswered = $sumDuration = $timeMayor = 0;
    foreach ($arrCallsAgent as $cdr) {
        $arrData[] = array($cdr['agent_number'], htmlentities($cdr['agent_name'], ENT_COMPAT, 'UTF-8'), $cdr['type'], $cdr['queue'], $cdr['num_answered'], formatoSegundos($cdr['sum_duration']), formatoSegundos($cdr['avg_duration']), formatoSegundos($cdr['max_duration']));
        $sumCallAnswered += $cdr['num_answered'];
        // Total de llamadas contestadas
        $sumDuration += $cdr['sum_duration'];
        // Total de segundos en llamadas
        $timeMayor = $timeMayor < $cdr['max_duration'] ? $cdr['max_duration'] : $timeMayor;
    }
    $sTagInicio = !$bExportando ? '<b>' : '';
    $sTagFinal = $sTagInicio != '' ? '</b>' : '';
    $arrData[] = array($sTagInicio . _tr('Total') . $sTagFinal, '', '', '', $sTagInicio . $sumCallAnswered . $sTagFinal, $sTagInicio . formatoSegundos($sumDuration) . $sTagFinal, $sTagInicio . formatoSegundos($sumCallAnswered > 0 ? $sumDuration / $sumCallAnswered : 0) . $sTagFinal, $sTagInicio . formatoSegundos($timeMayor) . $sTagFinal);
    // Construyo el URL base
    if (isset($arrFilterExtraVars) && is_array($arrFilterExtraVars) && count($arrFilterExtraVars) > 0) {
        $urlVars = array_merge($urlVars, $arrFilterExtraVars);
    }
    if ($bElastixNuevo) {
        $oGrid->setURL(construirURL($urlVars, array("nav", "start")));
        $oGrid->setData($arrData);
        $arrColumnas = array(_tr("No.Agent"), _tr("Agent"), _tr("Type"), _tr("Queue"), _tr("Calls answered"), _tr("Duration"), _tr("Average"), _tr("Call longest"));
        $oGrid->setColumns($arrColumnas);
        $oGrid->setTitle(_tr("Calls per Agent"));
        $oGrid->pagingShow(true);
        $oGrid->setNameFile_Export(_tr("Calls per Agent"));
        $smarty->assign("SHOW", _tr("Show"));
        return $oGrid->fetchGrid();
    } else {
        $url = construirURL($urlVars, array("nav", "start"));
        $offset = 0;
        $total = count($arrData);
        $limit = $total;
        $arrGrid = array("title" => _tr("Calls per Agent"), "url" => $url, "icon" => "images/user.png", "width" => "99%", "start" => $total == 0 ? 0 : $offset + 1, "end" => $offset + $limit <= $total ? $offset + $limit : $total, "total" => $total, "columns" => array(0 => array("name" => _tr("No.Agent"), "property" => ""), 1 => array("name" => _tr("Agent"), "property" => ""), 2 => array("name" => _tr("Type"), "property" => ""), 3 => array("name" => _tr("Queue"), "property" => ""), 4 => array("name" => _tr("Calls answered"), "property" => ""), 5 => array("name" => _tr("Duration"), "property" => ""), 6 => array("name" => _tr("Average"), "property" => ""), 7 => array("name" => _tr("Call longest"), "property" => "")));
        if (isset($_GET['exportpdf']) && $_GET['exportpdf'] == 'yes' && method_exists($oGrid, 'fetchGridPDF')) {
            return $oGrid->fetchGridPDF($arrGrid, $arrData);
        }
        if (isset($_GET['exportspreadsheet']) && $_GET['exportspreadsheet'] == 'yes' && method_exists($oGrid, 'fetchGridXLS')) {
            return $oGrid->fetchGridXLS($arrGrid, $arrData);
        }
        if ($bExportando) {
            header("Cache-Control: private");
            header("Pragma: cache");
            header('Content-Type: application/octet-stream');
            header('Content-disposition: inline; filename="calls_per_agent.csv"');
            header('Content-Type: application/force-download');
        }
        if ($bExportando) {
            return $oGrid->fetchGridCSV($arrGrid, $arrData);
        }
        $sContenido = $oGrid->fetchGrid($arrGrid, $arrData, $arrLang);
        if (strpos($sContenido, '<form') === FALSE) {
            $sContenido = "<form  method=\"POST\" style=\"margin-bottom:0;\" action=\"{$url}\">{$sContenido}</form>";
        }
        return $sContenido;
    }
}
Exemplo n.º 3
0
function reportReportsBreak($smarty, $module_name, $local_templates_dir, &$pDB)
{
    // Obtener rango de fechas de consulta. Si no existe, se asume día de hoy
    $sFechaInicio = date('d M Y');
    if (isset($_GET['txt_fecha_init'])) {
        $sFechaInicio = $_GET['txt_fecha_init'];
    }
    if (isset($_POST['txt_fecha_init'])) {
        $sFechaInicio = $_POST['txt_fecha_init'];
    }
    $sFechaFinal = date('d M Y');
    if (isset($_GET['txt_fecha_end'])) {
        $sFechaFinal = $_GET['txt_fecha_end'];
    }
    if (isset($_POST['txt_fecha_end'])) {
        $sFechaFinal = $_POST['txt_fecha_end'];
    }
    $arrFilterExtraVars = array("txt_fecha_init" => $sFechaInicio, "txt_fecha_end" => $sFechaFinal);
    $arrFormElements = createFieldFilter();
    $oFilterForm = new paloForm($smarty, $arrFormElements);
    // Validación de las fechas recogidas
    if (!$oFilterForm->validateForm($arrFilterExtraVars)) {
        $smarty->assign("mb_title", _tr("Validation Error"));
        $arrErrores = $oFilterForm->arrErroresValidacion;
        $strErrorMsg = '<b>' . _tr('The following fields contain errors') . '</b><br/>';
        foreach ($arrErrores as $k => $v) {
            $strErrorMsg .= "{$k}, ";
        }
        $smarty->assign("mb_message", $strErrorMsg);
        $arrFilterExtraVars = array("txt_fecha_init" => date('d M Y'), "txt_fecha_end" => date('d M Y'));
    }
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $arrFilterExtraVars);
    // Obtener fechas en formato yyyy-mm-dd
    $sFechaInicio = translateDate($arrFilterExtraVars['txt_fecha_init']);
    $sFechaFinal = translateDate($arrFilterExtraVars['txt_fecha_end']);
    $oReportsBreak = new paloSantoReportsBreak($pDB);
    //begin grid parameters
    $bElastixNuevo = method_exists('paloSantoGrid', 'setURL');
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->enableExport();
    // enable export.
    $oGrid->showFilter($htmlFilter);
    $arrColumnas = array(_tr('Agent Number'), _tr('Agent Name'));
    $bExportando = $bElastixNuevo ? $oGrid->isExportAction() : isset($_GET['exportcsv']) && $_GET['exportcsv'] == 'yes' || isset($_GET['exportspreadsheet']) && $_GET['exportspreadsheet'] == 'yes' || isset($_GET['exportpdf']) && $_GET['exportpdf'] == 'yes';
    $datosBreaks = $oReportsBreak->getReportesBreak($sFechaInicio, $sFechaFinal);
    $mapa = array();
    // Columna del break dado su ID
    $sTagInicio = !$bExportando ? '<b>' : '';
    $sTagFinal = $sTagInicio != '' ? '</b>' : '';
    $filaTotales = array($sTagInicio . _tr('Total') . $sTagFinal, '');
    foreach ($datosBreaks['breaks'] as $idBreak => $sNombreBreak) {
        $mapa[$idBreak] = count($arrColumnas);
        $arrColumnas[] = $sNombreBreak;
        $filaTotales[] = 0;
        // Total de segundos usado por todos los agentes en este break
    }
    $mapa['TOTAL'] = count($arrColumnas);
    $filaTotales[] = 0;
    // Total de segundos usado por todos los agentes en todos los breaks
    $arrColumnas[] = _tr('Total');
    $arrData = array();
    foreach ($datosBreaks['reporte'] as $infoAgente) {
        $filaAgente = array($infoAgente['numero_agente'], $infoAgente['nombre_agente']);
        $iTotalAgente = 0;
        // Total de segundos usados por agente en breaks
        // Valor inicial de todos los breaks es 0 segundos
        foreach (array_keys($datosBreaks['breaks']) as $idBreak) {
            $filaAgente[$mapa[$idBreak]] = '00:00:00';
        }
        // Asignar duración del break para este agente y break
        foreach ($infoAgente['breaks'] as $tuplaBreak) {
            $sTagInicio = !$bExportando && $tuplaBreak['duracion'] > 0 ? '<font color="green">' : '';
            $sTagFinal = $sTagInicio != '' ? '</font>' : '';
            $filaAgente[$mapa[$tuplaBreak['id_break']]] = $sTagInicio . formatoSegundos($tuplaBreak['duracion']) . $sTagFinal;
            $iTotalAgente += $tuplaBreak['duracion'];
            $filaTotales[$mapa[$tuplaBreak['id_break']]] += $tuplaBreak['duracion'];
            $filaTotales[$mapa['TOTAL']] += $tuplaBreak['duracion'];
        }
        // Total para todos los breaks de este agente
        $filaAgente[$mapa['TOTAL']] = formatoSegundos($iTotalAgente);
        $arrData[] = $filaAgente;
    }
    $sTagInicio = !$bExportando ? '<b>' : '';
    $sTagFinal = $sTagInicio != '' ? '</b>' : '';
    foreach ($mapa as $iPos) {
        $filaTotales[$iPos] = $sTagInicio . formatoSegundos($filaTotales[$iPos]) . $sTagFinal;
    }
    $arrData[] = $filaTotales;
    if ($bElastixNuevo) {
        $oGrid->setURL(construirURL($arrFilterExtraVars));
        $oGrid->setData($arrData);
        $oGrid->setColumns($arrColumnas);
        $oGrid->setTitle(_tr("Reports Break"));
        $oGrid->pagingShow(false);
        $oGrid->setNameFile_Export(_tr("Reports Break"));
        $smarty->assign("SHOW", _tr("Show"));
        return $oGrid->fetchGrid();
    } else {
        $url = construirURL($arrFilterExtraVars);
        $offset = 0;
        $total = count($datosBreaks['reporte']) + 1;
        $limit = $total;
        function _map_name($s)
        {
            return array('name' => $s);
        }
        $arrGrid = array("title" => _tr('Reports Break'), "url" => $url, "icon" => "images/list.png", "width" => "99%", "start" => $total == 0 ? 0 : $offset + 1, "end" => $offset + $limit <= $total ? $offset + $limit : $total, "total" => $total, "columns" => array_map('_map_name', $arrColumnas));
        if (isset($_GET['exportpdf']) && $_GET['exportpdf'] == 'yes' && method_exists($oGrid, 'fetchGridPDF')) {
            return $oGrid->fetchGridPDF($arrGrid, $arrData);
        }
        if (isset($_GET['exportspreadsheet']) && $_GET['exportspreadsheet'] == 'yes' && method_exists($oGrid, 'fetchGridXLS')) {
            return $oGrid->fetchGridXLS($arrGrid, $arrData);
        }
        if ($bExportando) {
            $title = $sFechaInicio . "-" . $sFechaFinal;
            header("Cache-Control: private");
            header("Pragma: cache");
            header('Content-Type: text/csv; charset=utf-8; header=present');
            header("Content-disposition: attachment; filename=\"" . $title . ".csv\"");
        }
        if ($bExportando) {
            return $oGrid->fetchGridCSV($arrGrid, $arrData);
        }
        $sContenido = $oGrid->fetchGrid($arrGrid, $arrData);
        if (strpos($sContenido, '<form') === FALSE) {
            $sContenido = "<form  method=\"POST\" style=\"margin-bottom:0;\" action=\"{$url}\">{$sContenido}</form>";
        }
        return $sContenido;
    }
}
Exemplo n.º 4
0
function _moduleContent(&$smarty, $module_name)
{
    global $arrConf;
    global $arrConfModule;
    //include module files
    include_once "modules/{$module_name}/configs/default.conf.php";
    include_once "modules/{$module_name}/libs/paloSantoTiempoConexiondeAgentes.class.php";
    include_once "libs/paloSantoConfig.class.php";
    $arrConf = array_merge($arrConf, $arrConfModule);
    // Obtengo la ruta del template a utilizar para generar el filtro.
    $base_dir = dirname($_SERVER['SCRIPT_FILENAME']);
    $templates_dir = isset($arrConf['templates_dir']) ? $arrConf['templates_dir'] : 'themes';
    $local_templates_dir = "{$base_dir}/modules/{$module_name}/" . $templates_dir . '/' . $arrConf['theme'];
    load_language_module($module_name);
    //conexion resource
    $pConfig = new paloConfig("/etc", "amportal.conf", "=", "[[:space:]]*=[[:space:]]*");
    $arrConfig = $pConfig->leer_configuracion(false);
    $dsnAsteriskCdr = $arrConfig['AMPDBENGINE']['valor'] . "://" . $arrConfig['AMPDBUSER']['valor'] . ":" . $arrConfig['AMPDBPASS']['valor'] . "@" . $arrConfig['AMPDBHOST']['valor'] . "/asterisk";
    $pDB = new paloDB($arrConf['dsn_conn_database']);
    $pDB_asterisk = new paloDB($dsnAsteriskCdr);
    $oCallsAgent = new paloSantoTiempoConexiondeAgentes($pDB);
    // Variables estáticas asignadas vía Smarty
    $smarty->assign(array("Filter" => _tr('Show')));
    $bElastixNuevo = method_exists('paloSantoGrid', 'setURL');
    $oGrid = new paloSantoGrid($smarty);
    $bExportando = $bElastixNuevo ? $oGrid->isExportAction() : isset($_GET['exportcsv']) && $_GET['exportcsv'] == 'yes';
    // Estas son las colas entrantes disponibles en el sistema
    $arrQueue = leerColasEntrantes($pDB, $pDB_asterisk);
    $t = array_keys($arrQueue);
    if (count($t) <= 0) {
        // TODO: internacionalizar y poner en plantilla
        return <<<NO_QUEUE_END
<p><b>No queues have been defined for incoming calls.</b></p>
<p>For proper operation and reporting, it is necessary to configure at least one queue. You can add queues <a href="?menu=pbxconfig&amp;display=queues">here</a>. 
In addition, the queue must be registered for use by incoming calls by clicking <a href="?menu=queues">here</a>.</p>
NO_QUEUE_END;
    }
    $sColaOmision = $t[0];
    //Esto es para validar cuando recien se entra al modulo, para q aparezca seteado un numero de agente en el textbox
    // TODO: reemplazar con lista desplegable de agentes en cola elegida
    $sAgenteOmision = $oCallsAgent->obtener_agente();
    $arrFormElements = createFieldFilter($arrQueue);
    $oFilterForm = new paloForm($smarty, $arrFormElements);
    // Valores iniciales de las variables
    $paramConsulta = array('date_start' => date('d M Y'), 'date_end' => date('d M Y'), 'queue' => $sColaOmision, 'agent' => $sAgenteOmision);
    foreach (array_keys($paramConsulta) as $k) {
        if (isset($_GET[$k])) {
            $paramConsulta[$k] = $_GET[$k];
        }
        if (isset($_POST[$k])) {
            $paramConsulta[$k] = $_POST[$k];
        }
    }
    if ($oFilterForm->validateForm($paramConsulta)) {
        // Exito, puedo procesar los datos ahora.
    } else {
        // Error
        $smarty->assign("mb_title", _tr("Validation Error"));
        $arrErrores = $oFilterForm->arrErroresValidacion;
        $strErrorMsg = "<b>" . _tr('Required field') . ":</b><br/>";
        foreach ($arrErrores as $k => $v) {
            $strErrorMsg .= "{$k}, ";
        }
        $strErrorMsg .= "";
        $smarty->assign("mb_message", $strErrorMsg);
        $paramConsulta = array('date_start' => date('d M Y'), 'date_end' => date('d M Y'), 'queue' => $sColaOmision, 'agent' => $sAgenteOmision);
    }
    // Se genera el filtro con las variables ya validadas
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $paramConsulta);
    // Consultar los datos y generar la matriz del reporte
    $sFechaInicial = translateDate($paramConsulta['date_start']);
    $sFechaFinal = translateDate($paramConsulta['date_end']);
    $r = $oCallsAgent->reportarBreaksAgente($paramConsulta['agent'], $paramConsulta['queue'], $sFechaInicial, $sFechaFinal);
    $b = $bExportando ? array('', '') : array('<b>', '</b>');
    $ub = $bExportando ? array('', '') : array('<u><b>', '</b></u>');
    $arrData = array();
    if (is_array($r) && count($r) > 0) {
        $tempTiempos = array('monitoreadas' => 0, 'llamadas_por_hora' => 0, 'duracion_llamadas' => 0, 'promedio_duracion' => 0, 'total_llamadas' => 0);
        foreach ($r['tiempos_llamadas'] as $tupla) {
            $tempTiempos['llamadas_por_hora'] = $tempTiempos['total_llamadas'] += $tupla['N'];
            $tempTiempos['duracion_llamadas'] += $tupla['tiempo_llamadas_entrantes'];
            if ($tupla['status'] == 'terminada') {
                $tempTiempos['monitoreadas'] = $tupla['N'];
                $tempTiempos['promedio_duracion'] = $tupla['promedio_sobre_monitoreadas'];
            }
        }
        if ($r['tiempo_conexion'] > 0) {
            $tempTiempos['llamadas_por_hora'] /= $r['tiempo_conexion'] / 3600;
        }
        $sFormatoMonitoreadas = sprintf('%d %s(s) (%d %s, %d %s)', $tempTiempos['total_llamadas'], _tr('Call'), $tempTiempos['monitoreadas'], _tr('Monitored'), $tempTiempos['total_llamadas'] - $tempTiempos['monitoreadas'], _tr('Unmonitored'));
        $arrData = array(array($b[0] . strtoupper(_tr('Agent name')) . $b[1], $r['name'], "", ""), array($b[0] . strtoupper(_tr('Conecction Data')) . $b[1], "", "", ""), array(_tr('First Conecction'), $r['primera_conexion'], "", ""), array(_tr('Last Conecction'), $r['ultima_conexion'], "", ""), array(_tr('Time Conecction'), formatoSegundos($r['tiempo_conexion']), "", ""), array(_tr('Count Conecction'), $r['conteo_conexion'], "", ""), array($b[0] . strtoupper(_tr('Calls Entry')) . $b[1], "", "", ""), array(_tr('Count Calls Entry'), $sFormatoMonitoreadas, "", ""), array(_tr('Calls/h'), number_format($tempTiempos['llamadas_por_hora'], 2), "", ""), array(_tr('Time Call Entry'), formatoSegundos($tempTiempos['duracion_llamadas']), "", ""), array(_tr('Average Calls Entry'), $tempTiempos['promedio_duracion'] . "    (" . _tr('Monitored only') . ')', "", ""), array($b[0] . strtoupper(_tr('Reason No Ready')) . $b[1], "", "", ""), array($ub[0] . _tr('Break') . $ub[1], $ub[0] . _tr('Count') . $ub[1], $ub[0] . _tr('Hour') . $ub[1], $ub[0] . _tr('Porcent compare whit time not ready') . $ub[1]));
        $tempBreaks = array();
        $iTotalSeg = 0;
        foreach ($r['tiempos_breaks'] as $tupla) {
            $tempBreaks[] = array($tupla['name'], $tupla['N'], formatoSegundos($tupla['total_break']), $tupla['total_break']);
            $iTotalSeg += $tupla['total_break'];
        }
        for ($i = 0; $i < count($tempBreaks); $i++) {
            $tempBreaks[$i][3] = number_format(100.0 * ($tempBreaks[$i][3] / $iTotalSeg), 2) . ' %';
            $arrData[] = $tempBreaks[$i];
        }
    } else {
        if (!is_array($r)) {
            $smarty->assign("mb_title", _tr("Database Error"));
            $smarty->assign("mb_message", $oCallsAgent->errMsg);
        }
        $arrData[] = array($b[0] . _tr("There aren't records to show") . $b[1], '', '', '');
    }
    // Creo objeto de grid
    $oGrid->enableExport();
    $oGrid->showFilter($htmlFilter);
    // La definición del grid
    $paramConsulta['menu'] = $module_name;
    if ($bElastixNuevo) {
        $oGrid->setURL(construirURL($paramConsulta));
        $oGrid->setData($arrData);
        $arrColumnas = array("", "", "", "");
        $oGrid->setColumns($arrColumnas);
        $oGrid->setTitle(_tr("Agent Information"));
        $oGrid->pagingShow(false);
        $oGrid->setNameFile_Export(_tr("Agent Information"));
        $smarty->assign("SHOW", _tr("Show"));
        return $oGrid->fetchGrid();
    } else {
        global $arrLang;
        $total = $end = count($arrData);
        $offset = 0;
        $url = construirUrl($paramConsulta);
        $arrGrid = array("title" => _tr("Time conecction of agents"), "icon" => "images/list.png", "width" => "99%", "start" => $total == 0 ? 0 : $offset + 1, "end" => $end, "total" => $total, "url" => $url, "columns" => array(0 => array("name" => "", "property" => ""), 1 => array("name" => "", "property" => ""), 2 => array("name" => "", "property" => ""), 3 => array("name" => "", "property" => "")));
        if ($bExportando) {
            $fechaActual = date("d M Y");
            header("Cache-Control: private");
            header("Pragma: cache");
            $title = $fechaActual;
            header('Content-Type: text/csv; charset=utf-8; header=present');
            header("Content-disposition: attachment; filename=\"" . $title . ".csv\"");
        }
        if ($bExportando) {
            return $oGrid->fetchGridCSV($arrGrid, $arrData);
        }
        $sContenido = $oGrid->fetchGrid($arrGrid, $arrData, $arrLang);
        if (strpos($sContenido, '<form') === FALSE) {
            $sContenido = "<form  method=\"POST\" style=\"margin-bottom:0;\" action=\"{$url}\">{$sContenido}</form>";
        }
        return $sContenido;
    }
}