function getMonitoring($limit, $offset, $filter_field, $filter_value, $extension, $date_initial, $date_final) { $where = ""; $arrParam = array(); if (isset($filter_field) & $filter_field != "") { if ($filter_field == "ext") { $where = " AND (channel like 'SIP/{$filter_value}%' OR dstchannel like 'SIP/{$filter_value}%') "; } elseif ($filter_field == "userfield") { $in_val = strtolower($filter_value); switch ($in_val) { case "outgoing": $where = " AND (userfield like 'audio:O%' OR userfield like 'audio:/var/spool/asterisk/monitor/O%') "; break; case "group": $where = " AND (userfield like 'audio:g%' OR userfield like 'audio:/var/spool/asterisk/monitor/g%') "; break; case "queue": $where = " AND (userfield like 'audio:q%' OR userfield like 'audio:/var/spool/asterisk/monitor/q%') "; break; default: $where = " AND userfield REGEXP '[[:<:]]audio:[0-9]' "; break; } } else { $arrParam[] = "{$filter_value}%"; $where = " AND {$filter_field} like ? AND userfield LIKE 'audio:%' "; } } if (isset($date_initial) & $date_initial != "" && isset($date_final) & $date_final != "") { $arrParam[] = $date_initial; $arrParam[] = $date_final; $where .= " AND (calldate >= ? AND calldate <= ?) "; } else { $date_initial = date('Y-m-d') . " 00:00:00"; $date_final = date('Y-m-d') . " 23:59:59"; $arrParam[] = $date_initial; $arrParam[] = $date_final; $where .= " AND (calldate >= ? AND calldate <= ?) "; } if (isset($extension) & $extension != "") { $arrParam[] = $extension; $arrParam[] = $extension; $where .= " AND (src=? OR dst=?)"; } $arrParam[] = $limit; $arrParam[] = $offset; $query = "SELECT * FROM cdr WHERE userfield <> '' {$where} ORDER BY uniqueid DESC LIMIT ? OFFSET ?"; $result = $this->_DB->fetchTable($query, true, $arrParam); if ($result == FALSE) { $this->errMsg = $this->_DB->errMsg; return false; } //tri require_once "modules/agent_console/getinfo.php"; $oMainConsole = new getInfoMainConsole(); $oMainConsole->callcenter_db_connect($this->getConfig()); $index = 0; foreach ($result as $row) { // get note $arr_note = $oMainConsole->getNoteCdr($row['uniqueid']); // get delivery info $arrDelivery = $oMainConsole->getDeliveryCdr($row['uniqueid']); $result[$index]['note_id'] = $arr_note['call_entry_id']; $result[$index]['note'] = $arr_note['note']; $result[$index]['delivery_id'] = count($arrDelivery) > 0 ? $arrDelivery['id'] : null; $index++; } $oMainConsole->callcenter_db_disconnect(); return $result; }
function view_delivery() { $response = array('action' => 'viewDelivery', 'message' => '(no message)'); $ticket_id = getParameter('view_delivery_id'); global $arrConf; $oMainConsole = new getInfoMainConsole(); $oMainConsole->callcenter_db_connect($arrConf['cadena_dsn']); $delivery = $oMainConsole->getDeliveryById($ticket_id); if (!$delivery) { $response['action'] = 'error'; $response['message'] = 'Lỗi kết nối dữ liệu'; } $oMainConsole->callcenter_db_disconnect(); // get history log include_once "modules/ticket_delivery/libs/Ticket_Delivery.class.php"; $pDB = new paloDB($arrConf['cadena_dsn']); $pTicketExpand = new Ticket_Delivery($pDB); $arrLog = $pTicketExpand->getTicketLog($ticket_id); //return json $response['message'] = $delivery; $response['log'] = $arrLog; $json = new Services_JSON(); Header('Content-Type: application/json'); return $json->encode($response); }
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; }
function addCustomer() { $response = array('action' => 'addCustomer', 'message' => 'Lưu khách hàng thành công'); $sNumber = trim(getParameter('phone')); $arrNumber = explode("\n", $sNumber); foreach ($arrNumber as $row) { if ($row == '' || is_null($row) || !is_numeric($row)) { $response['action'] = 'error'; $response['message'] = 'Thêm khách hàng: Số điện thoại không được rỗng và chỉ ký tự số!'; $json = new Services_JSON(); Header('Content-Type: application/json'); return $json->encode($response); } } global $arrConf; $oCustomer = new getInfoMainConsole(); $oCustomer->callcenter_db_connect($arrConf['cadena_dsn']); // collect parameters $sFirstname = isset($_POST['firstname']) ? trim(getParameter('firstname')) : ''; $sLastname = isset($_POST['lastname']) ? trim(getParameter('lastname')) : ''; $sBirthday = isset($_POST['birthday']) ? date("Y-m-d", strtotime(trim(getParameter('birthday')))) : ''; $sBirthplace = isset($_POST['birthplace']) ? trim(getParameter('birthplace')) : ''; $sAddress = isset($_POST['address']) ? trim(getParameter('address')) : ''; $sCmnd = isset($_POST['cmnd']) ? trim(getParameter('cmnd')) : ''; $sPassport = isset($_POST['passport']) ? trim(getParameter('passport')) : ''; $sId = isset($_POST['id']) ? trim(getParameter('id')) : ''; $sMembership = isset($_POST['membership']) ? trim(getParameter('membership')) : ''; $agentid = $oCustomer->getAgentId($_SESSION['callcenter']['extension']); $sEmail = isset($_POST['email']) ? trim(getParameter('email')) : ''; $params = array($arrNumber, $sFirstname, $sLastname, $sBirthday, $sBirthplace, $sAddress, $sCmnd, $sPassport, $sMembership, $sEmail, $agentid); //tri working $result = $oCustomer->addCustomer($params, $sId); $oCustomer->callcenter_db_disconnect(); // return json if (!$result) { $response['action'] = 'error'; $response['message'] = 'Lỗi: ' . $oCustomer->errMsg; } $json = new Services_JSON(); Header('Content-Type: application/json'); return $json->encode($response); }
function getMonitoring($limit, $offset, $filter_field, $filter_value, $extension, $date_initial, $date_final) { $where = ""; $arrParam = array(); if (isset($filter_field) & $filter_field != "") { if ($filter_field == "ext") { $where = " AND (channel like 'SIP/{$filter_value}%' OR dstchannel like 'SIP/{$filter_value}%') "; } elseif ($filter_field == "userfield") { $in_val = strtolower($filter_value); switch ($in_val) { case "outgoing": $where = " AND (userfield like 'audio:O%' OR userfield like 'audio:/var/spool/asterisk/monitor/O%') "; break; case "group": $where = " AND (userfield like 'audio:g%' OR userfield like 'audio:/var/spool/asterisk/monitor/g%') "; break; case "queue": $where = " AND (userfield like 'audio:q%' OR userfield like 'audio:/var/spool/asterisk/monitor/q%') "; break; default: $where = " AND userfield REGEXP '[[:<:]]audio:[0-9]' "; break; } } else { $arrParam[] = "{$filter_value}%"; $where = " AND {$filter_field} like ? "; } } if (isset($date_initial) & $date_initial != "" && isset($date_final) & $date_final != "") { $arrParam[] = $date_initial; $arrParam[] = $date_final; $where .= " AND (calldate >= ? AND calldate <= ?) "; } else { $date_initial = date('Y-m-d') . " 00:00:00"; $date_final = date('Y-m-d') . " 23:59:59"; $arrParam[] = $date_initial; $arrParam[] = $date_final; $where .= " AND (calldate >= ? AND calldate <= ?) "; } if (isset($extension) & $extension != "") { $arrParam[] = $extension; $arrParam[] = $extension; $where .= " AND (src=? OR dst=?)"; } $arrParam[] = $limit; $arrParam[] = $offset; $query = "SELECT * FROM cdr WHERE 1 = 1 {$where} ORDER BY uniqueid DESC LIMIT ? OFFSET ?"; $result = $this->_DB->fetchTable($query, true, $arrParam); if ($result == FALSE) { $this->errMsg = $this->_DB->errMsg; return false; } //tri require_once "modules/agent_console/getinfo.php"; $oMainConsole = new getInfoMainConsole(); $oMainConsole->callcenter_db_connect($this->getConfig()); $index = 0; foreach ($result as $row) { // get note $arr_note = $oMainConsole->getNoteCdr($row['uniqueid']); // get delivery info //$arrDelivery = $oMainConsole->getDeliveryCdr($row['uniqueid']); $result[$index]['note_id'] = $arr_note['call_entry_id']; $result[$index]['note'] = $arr_note['note']; $namefile = basename($result[$index]['userfield']); $namefile = str_replace("audio:", "", $namefile); // handle all situations switch ($result[$index]['dcontext']) { case 'from-internal-xfer': break; case 'from-did-direct': if ($result[$index]['userfield'] == '') { $filename = $this->checkFile(date('Ymd-His', strtotime($result[$index]['calldate'])) . '-' . $result[$index]['uniqueid'] . 'gsm'); if (is_null($filename)) { $result[$index]['userfield'] = ''; } $result[$index]['userfield'] = "audio:" . $filename; break; } break; case 'from-internal': // in case no audio file if ($result[$index]['userfield'] == '') { $filename = $this->checkFile(date('Ymd-His', strtotime($result[$index]['calldate'])) . '-' . $result[$index]['uniqueid'] . 'gsm'); if (is_null($filename)) { $result[$index]['userfield'] = ''; } $result[$index]['userfield'] = "audio:" . $filename; break; } if (substr($namefile, 0, 1) == 'q') { $result[$index]['userfield2'] = $result[$index]['userfield']; $filename = $this->checkFile(date('Ymd-His', strtotime($result[$index]['calldate'])) . '-' . $result[$index]['uniqueid'] . '.gsm'); if (is_null($filename)) { $result[$index]['userfield'] = ''; } else { $result[$index]['userfield'] = "audio:" . $filename; } $result[$index]['dcontext'] = 'from-internal-xfer'; break; } if (!strpos($result[$index]['userfield'], $result[$index]['uniqueid'])) { $filename = $this->checkFile(date('Ymd-His', strtotime($result[$index]['calldate'])) . '-' . $result[$index]['uniqueid'] . '.gsm'); if (is_null($filename)) { $result[$index]['userfield'] = ''; } $result[$index]['userfield'] = "audio:" . $filename; break; } break; case 'ext-queues': if (!strpos($result[$index]['userfield'], $result[$index]['uniqueid'])) { $filename = $this->checkFile("q" . $result[$index]['dst'] . "-" . date('Ymd-His', strtotime($result[$index]['calldate'])) . '-' . $result[$index]['uniqueid'] . '.gsm'); $result[$index]['userfield'] = "audio:/var/spool/asterisk/monitor/" . $filename; break; } break; default: break; } $index++; } $oMainConsole->callcenter_db_disconnect(); return $result; }
function viewDelivery() { $response = array('action' => 'viewDelivery', 'message' => '(no message)'); $ticket_id = getParameter('view_delivery_id'); global $arrConf; $oMainConsole = new getInfoMainConsole(); $oMainConsole->callcenter_db_connect($arrConf['cadena_dsn']); $delivery = $oMainConsole->getDeliveryById($ticket_id); $oMainConsole->callcenter_db_disconnect(); if (!$result) { $response['action'] = 'error'; $response['message'] = 'Lỗi: ' . $oMainConsole->errMsg; } //return json $response['message'] = $delivery; $json = new Services_JSON(); Header('Content-Type: application/json'); return $json->encode($response); }