function listarColas($pDB, $smarty, $module_name, $local_templates_dir) { require_once "libs/paloSantoGrid.class.php"; global $arrLang; $oColas = new paloSantoColaEntrante($pDB); // Verificar si alguna cola debe activarse o inactivarse if (!is_null($id = getParameter('id'))) { if (!is_null(getParameter('activate'))) { $bExito = $oColas->cambiarMonitoreoCola($id, 'A'); } elseif (!is_null(getParameter('deactivate'))) { $bExito = $oColas->cambiarMonitoreoCola($id, 'I'); } if (!$bExito) { $smarty->assign("mb_title", _tr('Unable to change activation')); $smarty->assign("mb_message", $oColas->errMsg); } } // Estado indicado por el filtro $sEstado = getParameter('estatus'); if (is_null($sEstado)) { $sEstado = 'A'; } if (!in_array($sEstado, array('', 'A', 'I'))) { $sEstado = 'A'; } if ($sEstado == '') { $sEstado = NULL; } // Consulta de las colas $arrDataQueues = $oColas->leerColas(NULL, $sEstado); if (!is_array($arrDataQueues)) { $smarty->assign("mb_title", _tr('Unable to read queues')); $smarty->assign("mb_message", _tr('Cannot read queues') . ' - ' . $oColas->errMsg); $arrDataQueues = array(); } // Construcción del reporte $end = count($arrDataQueues); $url = construirUrl(array('menu' => $module_name), array('nav', 'start')); $arrGrid = array("title" => _tr('Queue List'), 'url' => $url, "icon" => "images/list.png", "width" => "99%", "start" => $end == 0 ? 0 : 1, "end" => $end, "total" => $end, "columns" => array(array("name" => "<input class=\"button\" type=\"submit\" name=\"activate\" value=\"" . _tr('Activate') . "\" />" . "<input class=\"button\" type=\"submit\" name=\"deactivate\" value=\"" . _tr('Deactivate') . "\" />"), array("name" => _tr('Name Queue')), array("name" => _tr('Status')), array("name" => _tr('Options')))); $oGrid = new paloSantoGrid($smarty); $arrData = array(); foreach ($arrDataQueues as $tuplaQueue) { $arrData[] = array("<input type=\"radio\" name=\"id\" value=\"{$tuplaQueue['id']}\" />", $tuplaQueue['queue'], $tuplaQueue['estatus'] == 'A' ? _tr('Active') : _tr('Inactive'), "<a href=\"?menu={$module_name}&action=edit_queue&id_queue={$tuplaQueue['id']}\">[" . htmlentities(_tr('Edit'), ENT_COMPAT, 'UTF-8') . "]</a>"); } $oGrid->showFilter('<table width="100%" border="0"><tr>' . '<td align="right"><b>' . _tr('Status') . '</b></td>' . '<td align="left"><select name="estatus" onchange="submit();">' . combo(array('' => _tr('all'), 'A' => _tr('active'), 'I' => _tr('inactive')), $sEstado) . '</select></td>' . '<td align="right"><b><a href="?menu=' . $module_name . '&action=new_queue">' . _tr('Select Queue') . ' »</a></b></td>' . '</tr></table>'); $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; }
function listadoForm($pDB, $smarty, $module_name, $local_templates_dir) { global $arrLang; $oDataForm = new paloSantoDataForm($pDB); // preguntando por el estado del filtro if (!isset($_POST['cbo_estado']) || $_POST['cbo_estado'] == "") { $_POST['cbo_estado'] = "A"; } $arrDataForm = $oDataForm->getFormularios(NULL, $_POST['cbo_estado']); $end = count($arrDataForm); $arrData = array(); if (is_array($arrDataForm)) { foreach ($arrDataForm as $DataForm) { $arrTmp = array(); $arrTmp[0] = $DataForm['nombre']; if (!isset($DataForm['descripcion']) || $DataForm['descripcion'] == "") { $DataForm['descripcion'] = " "; } $arrTmp[1] = $DataForm['descripcion']; if ($DataForm['estatus'] == 'I') { $arrTmp[2] = _tr('Inactive'); $arrTmp[3] = " <a href='?menu={$module_name}&action=preview&id=" . $DataForm['id'] . "'>" . _tr('Preview') . "</a>"; } else { $arrTmp[2] = _tr('Active'); $arrTmp[3] = " <a href='?menu={$module_name}&action=preview&id=" . $DataForm['id'] . "'>" . _tr('Preview') . "</a>"; } $arrData[] = $arrTmp; } } $url = construirUrl(array('menu' => $module_name), array('nav', 'start')); $arrGrid = array("title" => _tr("Form List"), "url" => $url, "icon" => "images/list.png", "width" => "99%", "start" => $end == 0 ? 0 : 1, "end" => $end, "total" => $end, "columns" => array(0 => array("name" => _tr("Form Name"), "property1" => ""), 1 => array("name" => _tr("Form Description"), "property1" => ""), 2 => array("name" => _tr("Status"), "property1" => ""), 3 => array("name" => _tr("Options"), "property1" => ""))); $estados = array("all" => _tr("All"), "A" => _tr("Active"), "I" => _tr("Inactive")); $combo_estados = "<select name='cbo_estado' id='cbo_estado' onChange='submit();'>" . combo($estados, $_POST['cbo_estado']) . "</select>"; $oGrid = new paloSantoGrid($smarty); $oGrid->showFilter("<table width='100%' border='0'><tr>" . "<td>" . _tr("Forms") . "</td>" . "<td class='letra12' align='right'><b>" . _tr("Status") . ":</b> {$combo_estados}</td>" . "</tr></table>"); $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; }
function reportReportCall($smarty, $module_name, $local_templates_dir, &$pDB_cdr, &$pDB_billing, $arrConf, $arrLang) { $pReportCall = new paloSantoReportCall($pDB_cdr, $pDB_billing); //PARAMETERS $type = getParameter("option_fil"); $value_tmp = getParameter("value_fil"); $date_ini_tmp = getParameter("date_from"); $date_end_tmp = getParameter("date_to"); $order_by_tmp = getParameter("order_by"); $order_type_tmp = getParameter("order_type"); $action = getParameter("nav"); $start = getParameter("start"); $value = isset($value_tmp) ? $value_tmp : ""; $order_by = isset($order_by_tmp) ? $order_by_tmp : 1; $order_type = isset($order_type_tmp) ? $order_type_tmp : "asc"; $date_from = isset($date_ini_tmp) ? $date_ini_tmp : date("d M Y"); $date_to = isset($date_end_tmp) ? $date_end_tmp : date("d M Y"); $date_ini = translateDate($date_from) . " 00:00:00"; $date_end = translateDate($date_to) . " 23:59:59"; //********************************** //begin grid parameters $oGrid = new paloSantoGrid($smarty); $limit = 40; $total = $pReportCall->ObtainNumberDevices($type, $value); $oGrid->setLimit($limit); $oGrid->setTotal($total); $oGrid->calculatePagination($action, $start); $offset = $oGrid->getOffsetValue(); $end = $oGrid->getEnd(); $urlFields = array('menu' => $module_name, 'option_fil' => $type, 'value_fil' => $value, 'date_from' => $date_from, 'date_to' => $date_to); $url = construirUrl($urlFields, array('nav', 'start')); $urlFields['order_by'] = $order_by; $urlFields['order_type'] = $order_type; $smarty->assign("order_by", $order_by); $smarty->assign("order_type", $order_type); $arrData = null; $arrResult = $pReportCall->ObtainReportCall($limit, $offset, $date_ini, $date_end, $type, $value, $order_by, $order_type); $order_type = $order_type == "desc" ? "asc" : "desc"; if (is_array($arrResult) && $total > 0) { foreach ($arrResult as $key => $val) { $ext = $val['extension']; $arrTmp[0] = $ext; $arrTmp[1] = $val['user_name']; $arrTmp[2] = $val['num_incoming_call']; $arrTmp[3] = $val['num_outgoing_call']; $arrTmp[4] = "<label style='color: green;' title='{$val['duration_incoming_call']} {$arrLang['seconds']}'>" . $pReportCall->Sec2HHMMSS($val['duration_incoming_call']) . "</label>"; $arrTmp[5] = "<label style='color: green;' title='{$val['duration_outgoing_call']} {$arrLang['seconds']}'>" . $pReportCall->Sec2HHMMSS($val['duration_outgoing_call']) . "</label>"; $arrTmp[6] = "<a href='javascript: popup_ventana(\"?menu={$module_name}&action=graph&rawmode=yes&ext={$ext}&dini={$date_ini}&dfin={$date_end}\");'>" . "" . $arrLang['Call Details'] . "</a>"; $arrData[] = $arrTmp; } } $img = "<img src='images/flecha_{$order_type}.png' border='0' align='absmiddle'>"; $leyend_1 = "<a class='link_summary_off' href='{$url}&order_by=1&order_type=asc'>{$arrLang["Extension"]}</a>"; $leyend_2 = "<a class='link_summary_off' href='{$url}&order_by=2&order_type=asc'>{$arrLang["User name"]}</a>"; $leyend_3 = "<a class='link_summary_off' href='{$url}&order_by=3&order_type=asc'>{$arrLang["Num. Incoming Calls"]}</a>"; $leyend_4 = "<a class='link_summary_off' href='{$url}&order_by=4&order_type=asc'>{$arrLang["Num. Outgoing Calls"]}</a>"; $leyend_5 = "<a class='link_summary_off' href='{$url}&order_by=5&order_type=asc'>{$arrLang["Sec. Incoming Calls"]}</a>"; $leyend_6 = "<a class='link_summary_off' href='{$url}&order_by=6&order_type=asc'>{$arrLang["Sec. Outgoing Calls"]}</a>"; if ($order_by == 1) { $leyend_1 = "<a class='link_summary_on' href='{$url}&order_by=1&order_type={$order_type}'>{$arrLang["Extension"]} {$img}</a>"; } else { if ($order_by == 2) { $leyend_2 = "<a class='link_summary_on' href='{$url}&order_by=2&order_type={$order_type}'>{$arrLang["User name"]} {$img}</a>"; } else { if ($order_by == 3) { $leyend_3 = "<a class='link_summary_on' href='{$url}&order_by=3&order_type={$order_type}'>{$arrLang["Num. Incoming Calls"]} {$img}</a>"; } else { if ($order_by == 4) { $leyend_4 = "<a class='link_summary_on' href='{$url}&order_by=4&order_type={$order_type}'>{$arrLang["Num. Outgoing Calls"]} {$img}</a>"; } else { if ($order_by == 5) { $leyend_5 = "<a class='link_summary_on' href='{$url}&order_by=5&order_type={$order_type}'>{$arrLang["Sec. Incoming Calls"]} {$img}</a>"; } else { if ($order_by == 6) { $leyend_6 = "<a class='link_summary_on' href='{$url}&order_by=6&order_type={$order_type}'>{$arrLang["Sec. Outgoing Calls"]} {$img}</a>"; } } } } } } $arrGrid = array("title" => $arrLang["Summary by Extension"], "icon" => "images/list.png", "width" => "100%", "start" => $total == 0 ? 0 : $offset + 1, "end" => $end, "total" => $total, "url" => $urlFields, "columns" => array(0 => array("name" => $leyend_1, "property1" => ""), 1 => array("name" => $leyend_2, "property1" => ""), 2 => array("name" => $leyend_3, "property1" => ""), 3 => array("name" => $leyend_4, "property1" => ""), 4 => array("name" => $leyend_5, "property1" => ""), 5 => array("name" => $leyend_6, "property1" => ""), 6 => array("name" => $arrLang["Details"], "property1" => ""))); //begin section filter $arrFormFilterReportCall = createFieldForm($arrLang); $oFilterForm = new paloForm($smarty, $arrFormFilterReportCall); $_POST['option_fil'] = $type; $_POST['value_fil'] = $value; $_POST['date_from'] = $date_from; $_POST['date_to'] = $date_to; $smarty->assign("SHOW", $arrLang["Show"]); if ($_POST["date_from"] === "") { $_POST["date_from"] = " "; } if ($_POST['date_to'] === "") { $_POST['date_to'] = " "; } $oGrid->addFilterControl(_tr("Filter applied: ") . _tr("Start Date") . " = " . $date_from . ", " . _tr("End Date") . " = " . $date_to, $_POST, array("date_from" => date("d M Y"), "date_to" => date("d M Y")), true); $valueType = ""; if (!is_null($type)) { if ($type == "Ext") { $valueType = _tr("Extension"); } else { $valueType = _tr("User"); } } $oGrid->addFilterControl(_tr("Filter applied: ") . $valueType . " = " . $value, $_POST, array("option_fil" => "Ext", "value_fil" => "")); $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST); //end section filter $oGrid->showFilter(trim($htmlFilter)); $contenidoModulo = $oGrid->fetchGrid($arrGrid, $arrData, $arrLang); return $contenidoModulo; }
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&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; } }