Beispiel #1
0
function agent_monitoring_HTML($module_name, $smarty, $sDirLocalPlantillas, $oPaloConsola)
{
    global $arrLang;
    $smarty->assign(array('FRAMEWORK_TIENE_TITULO_MODULO' => existeSoporteTituloFramework(), 'icon' => 'modules/' . $module_name . '/images/realtime.png', 'title' => 'Giám Sát & Quản Lý Tổng Đài Viên'));
    /* check if user login via agent console
    	 if (!isset($_SESSION['callcenter']['agente'])) {
            $smarty->assign(array(
                'mb_title'  =>  'ERROR',
                'mb_message'    =>  'Đăng nhập tại <a href="index.php?menu=agent_console">Agent Console</a> trước khi sử dụng tính năng này',
            ));
    		  return '';
        } */
    $estadoMonitor = $oPaloConsola->listarEstadoMonitoreoAgentes();
    //echo '<pre>' . print_r($estadoMonitor,1) . '</pre>';die;
    if (!is_array($estadoMonitor)) {
        $smarty->assign(array('mb_title' => 'ERROR', 'mb_message' => $oPaloConsola->errMsg));
        return '';
    }
    ksort($estadoMonitor);
    //echo '<pre>' . print_r($estadoMonitor,1) . '</pre>';die;
    $jsonData = contructDataJSON(mergeQueueAgent($estadoMonitor));
    // convert to Smarty data
    $sThemeDir = "modules/{$module_name}/themes/default";
    $arrSmartyData = array();
    foreach ($jsonData as $jsonKey => $jsonRow) {
        $arrSmartyData[$jsonKey] = $jsonRow;
        // show time format hh:mm:ss base on last-status
        $arrSmartyData[$jsonKey]['status_time'] = timestamp_format($jsonRow['sec_laststatus']);
        // show time format hh:mm:ss base on last-status
        $arrSmartyData[$jsonKey]['sec_calls_time'] = timestamp_format($jsonRow['sec_calls']);
        switch ($jsonRow['agentstatus']) {
            case 'offline':
                // image status with title information
                $arrSmartyData[$jsonKey]['img_status'] = "{$sThemeDir}/images/status_offline-ic.png";
                $arrSmartyData[$jsonKey]['img_status_title'] = "{$jsonKey}: Chưa sẵn sàng";
                // status time (count from sec_laststatus)
                $arrSmartyData[$jsonKey]['status_time_label'] = 'Offline:';
                break;
            case 'online':
                // image status with title information
                $arrSmartyData[$jsonKey]['img_status'] = "{$sThemeDir}/images/status_free-ic.png";
                $arrSmartyData[$jsonKey]['img_status_title'] = "{$jsonKey}: Đang sẵn sàng";
                // status time (count from sec_laststatus)
                $arrSmartyData[$jsonKey]['status_time_label'] = 'Online:';
                break;
            case 'oncall':
                // image status with title information
                $arrSmartyData[$jsonKey]['img_status'] = "{$sThemeDir}/images/status_on_call-ic.png";
                $arrSmartyData[$jsonKey]['img_status_title'] = "{$jsonKey}: Đang gọi - Tại kênh: " . $jsonRow['linkqueue'];
                // status time (count from sec_laststatus)
                $arrSmartyData[$jsonKey]['status_time_label'] = 'Đang gọi: ';
                // get customer information
                $agentState = getAgentState($jsonRow['agent_number']);
                $arrSmartyData[$jsonKey]['callnumber'] = $agentState['callnumber'];
                $arrSmartyData[$jsonKey]['callid'] = $agentState['callid'];
                $customer = getCustomer($arrSmartyData[$jsonKey]['callnumber']);
                $arrSmartyData[$jsonKey]['customer'] = $customer ? $customer : $arrSmartyData[$jsonKey]['callnumber'];
                break;
            case 'paused':
                // image status with title information
                $arrSmartyData[$jsonKey]['img_status'] = "{$sThemeDir}/images/status_away-ic.png";
                $arrSmartyData[$jsonKey]['img_status_title'] = "{$jsonKey}: Đang tạm nghỉ";
                // status time (count from sec_laststatus)
                $arrSmartyData[$jsonKey]['status_time_label'] = 'Tạm nghỉ:';
                break;
            default:
        }
    }
    // history call
    global $arrConf;
    $oCallHistory = new getInfoMainConsole();
    $oCallHistory->callcenter_db_connect($arrConf['cadena_dsn']);
    $arrHistory = $oCallHistory->getCallHistoryArray();
    $oCallHistory->callcenter_db_disconnect();
    //$oQueueStatus = new queue_waiting();
    //$arrQueue = $oQueueStatus->showQueue();
    //echo '<pre>' . print_r($res,1) . '</pre>';die;
    //smarty template assign
    $smarty->assign(array('AGENT_STATUS' => $arrSmartyData, 'SUPERVISOR_NUMBER' => $_SESSION['callcenter']['extension'], 'THEME_PATH' => $sThemeDir, 'CALL_HISTORY' => $arrHistory, 'ITEM_LIMIT' => 6));
    //echo '<pre>' . print_r($arrTicket,1) . '</pre>';die;
    $sContent = $smarty->fetch("{$sDirLocalPlantillas}/realtime_monitor.tpl");
    //initilize with jsonData
    foreach (array_keys($jsonData) as $k) {
        unset($jsonData[$k]['agentname']);
    }
    // Extraer la información que el navegador va a usar para actualizar
    $estadoCliente = array();
    foreach (array_keys($jsonData) as $k) {
        $estadoCliente[$k] = array('agentstatus' => $jsonData[$k]['agentstatus'], 'oncallupdate' => $jsonData[$k]['oncallupdate'], 'linkqueue' => $jsonData[$k]['linkqueue']);
    }
    $estadoHash = generarEstadoHash($module_name, $estadoCliente);
    $json = new Services_JSON();
    $INITIAL_CLIENT_STATE = $json->encode($jsonData);
    $sJsonInitialize = <<<JSON_INITIALIZE
<script type="text/javascript">
\$(function() {
    initialize_client_state({$INITIAL_CLIENT_STATE}, '{$estadoHash}');\t
});
</script>
JSON_INITIALIZE;
    return $sContent . $sJsonInitialize;
}
Beispiel #2
0
function manejarMonitoreo_HTML($module_name, $smarty, $sDirLocalPlantillas, $oPaloConsola)
{
    global $arrLang;
    $smarty->assign(array('FRAMEWORK_TIENE_TITULO_MODULO' => existeSoporteTituloFramework(), 'icon' => 'modules/' . $module_name . '/images/call.png', 'title' => _tr('Agent Monitoring')));
    /*
     * Un agente puede pertenecer a múltiples colas, y puede o no estar 
     * atendiendo una llamada, la cual puede haber llegado de como máximo una
     * cola. Hay 3 cronómetros que se pueden actualizar:
     * 
     * último estado:   el tiempo transcurrido desde el último cambio de estado
     * total de login:  el tiempo durante el cual el agente ha estado logoneado
     * total de llamadas: el tiempo que el agente pasa atendiendo llamadas
     * 
     * Para el monitoreo de este módulo, los estados en que puede estar
     * una fila (que muestra un agente en una cola) pueden ser los siguientes:
     * 
     * offline: el tiempo total de login y el tiempo de llamadas no se 
     *  actualizan. Si el cliente estuvo en otro estado previamente 
     *  (lastsessionend) entonces se actualiza regularmente el cronómetro de
     *  último estado. De otro modo el cronómetro de último estado está vacío.
     * online: se actualiza el tiempo total de login y el tiempo de último 
     *  estado, y el tiempo total de llamadas no se actualiza. El cronómetro de
     *  último estado cuenta desde el inicio de sesión.
     * paused: igual que online, pero el cronómentro de último estado cuenta
     *  desde el inicio de la pausa.
     * oncall: se actualiza el tiempo total de login. El cronómetro de último 
     *  estado cuenta desde el inicio de la llamada únicamente para la cola que 
     *  proporcionó la llamada que atiende el agente actualmente. De otro modo 
     *  el cronómetro no se actualiza. De manera similar, el total de tiempo de
     *  llamadas se actualiza únicamente para la cola que haya proporcionado la
     *  llamada que atiende el agente.
     * 
     * El estado del cliente consiste en un arreglo de tantos elementos como
     * agentes haya pertenecientes a cada cola. Si un agente pertenece a más de
     * una cola, hay un elemento por cada pertenencia del mismo agente a cada
     * cola. Cada elemento es una estructura que contiene los siguientes 
     * valores:
     * 
     * status:          {offline|online|oncall|paused}
     * sec_laststatus:  integer|null
     * sec_calls:       integer
     * logintime:       integer
     * num_calls:       integer
     * oncallupdate:    boolean
     * 
     * Cada elemento del arreglo se posiciona por 'queue-{NUM_COLA}-member-{NUM_AGENTE}'
     * 
     * El estado enviado por el cliente para detectar cambios es también un 
     * arreglo con el mismo número de elementos que el arreglo anterior, 
     * posicionado de la misma manera. Cada elemento es una estructura que 
     * contiene los siguientes valores:
     * 
     * status:          {offline|online|oncall|paused}
     * oncallupdate:    boolean
     */
    $estadoMonitor = $oPaloConsola->listarEstadoMonitoreoAgentes();
    if (!is_array($estadoMonitor)) {
        $smarty->assign(array('mb_title' => 'ERROR', 'mb_message' => $oPaloConsola->errMsg));
        return '';
    }
    ksort($estadoMonitor);
    $jsonData = construirDatosJSON($estadoMonitor);
    $arrData = array();
    $tuplaTotal = NULL;
    $sPrevQueue = NULL;
    foreach ($jsonData as $jsonKey => $jsonRow) {
        list($d1, $sQueue, $d2, $sTipoAgente, $sNumeroAgente) = explode('-', $jsonKey);
        $sEstadoTag = '(unimplemented)';
        switch ($jsonRow['status']) {
            case 'offline':
                $sEstadoTag = _tr('LOGOUT');
                break;
            case 'online':
                $sEstadoTag = '<img src="modules/' . $module_name . '/images/ready.png" border="0" alt="' . _tr('READY') . '"/>';
                break;
            case 'oncall':
                $sEstadoTag = '<img src="modules/' . $module_name . '/images/call.png" border="0" alt="' . _tr('CALL') . '"/>';
                break;
            case 'paused':
                $sEstadoTag = '<img src="modules/' . $module_name . '/images/break.png" border="0" alt="' . _tr('BREAK') . '"/>';
                break;
        }
        $sEstadoTag = '<span id="' . $jsonKey . '-statuslabel">' . $sEstadoTag . '</span>';
        $sEstadoTag .= '&nbsp;<span id="' . $jsonKey . '-sec_laststatus">';
        if (!is_null($jsonRow['sec_laststatus'])) {
            $sEstadoTag .= timestamp_format($jsonRow['sec_laststatus']);
        }
        $sEstadoTag .= '</span>';
        // Estado a mostrar en HTML se deriva del estado JSON
        if ($sPrevQueue != $sQueue) {
            if (!is_null($tuplaTotal)) {
                // Emitir fila de totales para la cola ANTERIOR
                $jsTotalKey = 'queue-' . $sPrevQueue;
                $arrData[] = array('<b>' . _tr('TOTAL') . '</b>', '&nbsp;', '<b>' . _tr('Agents') . ': ' . $tuplaTotal['num_agents'] . '</b>', '&nbsp;', '<b><span id="' . $jsTotalKey . '-num_calls">' . $tuplaTotal['num_calls'] . '</span></b>', '<b><span id="' . $jsTotalKey . '-logintime">' . timestamp_format($tuplaTotal['logintime']) . '</span></b>', '<b><span id="' . $jsTotalKey . '-sec_calls">' . timestamp_format($tuplaTotal['sec_calls']) . '</span></b>');
            }
            // Reiniciar totales aquí
            $tuplaTotal = array('num_agents' => 0, 'logintime' => 0, 'num_calls' => 0, 'sec_calls' => 0);
        }
        $tuplaTotal['num_agents']++;
        $tuplaTotal['logintime'] += $jsonRow['logintime'];
        $tuplaTotal['num_calls'] += $jsonRow['num_calls'];
        $tuplaTotal['sec_calls'] += $jsonRow['sec_calls'];
        $tupla = array($sPrevQueue == $sQueue ? '' : $sQueue, $jsonRow['agentchannel'], htmlentities($jsonRow['agentname'], ENT_COMPAT, 'UTF-8'), $sEstadoTag, '<span id="' . $jsonKey . '-num_calls">' . $jsonRow['num_calls'] . '</span>', '<span id="' . $jsonKey . '-logintime">' . timestamp_format($jsonRow['logintime']) . '</span>', '<span id="' . $jsonKey . '-sec_calls">' . timestamp_format($jsonRow['sec_calls']) . '</span>');
        $arrData[] = $tupla;
        $sPrevQueue = $sQueue;
    }
    // Emitir fila de totales para la cola ÚLTIMA
    $jsTotalKey = 'queue-' . $sPrevQueue;
    $arrData[] = array('<b>' . _tr('TOTAL') . '</b>', '&nbsp;', '<b>' . _tr('Agents') . ': ' . $tuplaTotal['num_agents'] . '</b>', '&nbsp;', '<b><span id="' . $jsTotalKey . '-num_calls">' . $tuplaTotal['num_calls'] . '</span></b>', '<b><span id="' . $jsTotalKey . '-logintime">' . timestamp_format($tuplaTotal['logintime']) . '</span></b>', '<b><span id="' . $jsTotalKey . '-sec_calls">' . timestamp_format($tuplaTotal['sec_calls']) . '</span></b>');
    // No es necesario emitir el nombre del agente la inicialización JSON
    foreach (array_keys($jsonData) as $k) {
        unset($jsonData[$k]['agentname']);
    }
    // Extraer la información que el navegador va a usar para actualizar
    $estadoCliente = array();
    foreach (array_keys($jsonData) as $k) {
        $estadoCliente[$k] = array('status' => $jsonData[$k]['status'], 'oncallupdate' => $jsonData[$k]['oncallupdate']);
    }
    $estadoHash = generarEstadoHash($module_name, $estadoCliente);
    $oGrid = new paloSantoGrid($smarty);
    $json = new Services_JSON();
    $INITIAL_CLIENT_STATE = $json->encode($jsonData);
    $sJsonInitialize = <<<JSON_INITIALIZE
<script type="text/javascript">
\$(function() {
    initialize_client_state({$INITIAL_CLIENT_STATE}, '{$estadoHash}');
});
</script>
JSON_INITIALIZE;
    return $oGrid->fetchGrid(array('title' => _tr('Agents Monitoring'), 'icon' => _tr('images/list.png'), 'width' => '99%', 'start' => 1, 'end' => 1, 'total' => 1, 'url' => array('menu' => $module_name), 'columns' => array(array('name' => _tr('Queue')), array('name' => _tr('Number')), array('name' => _tr('Agent')), array('name' => _tr('Current status')), array('name' => _tr('Total calls')), array('name' => _tr('Total login time')), array('name' => _tr('Total talk time')))), $arrData, $arrLang) . $sJsonInitialize;
}