function reportMonitoring($smarty, $module_name, $local_templates_dir, &$pDB, $pACL, $arrConf, $user, $extension, $esAdministrador) { $pMonitoring = new paloSantoMonitoring($pDB); //var_dump($arrConfg); $pMonitoring->setConfig($arrConf); $filter_field = getParameter("filter_field"); switch ($filter_field) { case "dst": $filter_field = "dst"; $nameFilterField = _tr("Destination"); break; case "userfield": $filter_field = "userfield"; $nameFilterField = _tr("Type"); break; default: $filter_field = "src"; $nameFilterField = _tr("Source"); break; } if ($filter_field == "userfield") { $filter_value = getParameter("filter_value_userfield"); $filter = ""; $filter_userfield = $filter_value; } else { $filter_value = getParameter("filter_value"); $filter = $filter_value; $filter_userfield = ""; } switch ($filter_value) { case "outgoing": $smarty->assign("SELECTED_2", "Selected"); $nameFilterUserfield = _tr("Outgoing"); break; case "queue": $smarty->assign("SELECTED_3", "Selected"); $nameFilterUserfield = _tr("Queue"); break; case "group": $smarty->assign("SELECTED_4", "Selected"); $nameFilterUserfield = _tr("Group"); break; default: $smarty->assign("SELECTED_1", "Selected"); $nameFilterUserfield = _tr("Incoming"); break; } $date_ini = getParameter("date_start"); $date_end = getParameter("date_end"); $path_record = $arrConf['records_dir']; $_POST['date_start'] = isset($date_ini) ? $date_ini : date("d M Y"); $_POST['date_end'] = isset($date_end) ? $date_end : date("d M Y"); if ($date_ini === "") { $_POST['date_start'] = " "; } if ($date_end === "") { $_POST['date_end'] = " "; } if (!empty($pACL->errMsg)) { echo "ERROR DE ACL: {$pACL->errMsg} <br>"; } $date_initial = date('Y-m-d', strtotime($_POST['date_start'])) . " 00:00:00"; $date_final = date('Y-m-d', strtotime($_POST['date_end'])) . " 23:59:59"; $_DATA = $_POST; //begin grid parameters $oGrid = new paloSantoGrid($smarty); $oGrid->setTitle(_tr("Monitoring")); $oGrid->setIcon("modules/{$module_name}/images/pbx_monitoring.png"); $oGrid->pagingShow(true); // show paging section. $oGrid->enableExport(); // enable export. $oGrid->setNameFile_Export(_tr("Monitoring")); if ($esAdministrador) { $totalMonitoring = $pMonitoring->getNumMonitoring($filter_field, $filter_value, null, $date_initial, $date_final); } elseif (!($extension == "" || is_null($extension))) { $totalMonitoring = $pMonitoring->getNumMonitoring($filter_field, $filter_value, $extension, $date_initial, $date_final); } else { $totalMonitoring = 0; } $url = array('menu' => $module_name); $paramFilter = array('filter_field' => $filter_field, 'filter_value' => $filter, 'filter_value_userfield' => $filter_userfield, 'date_start' => $_POST['date_start'], 'date_end' => $_POST['date_end']); $url = array_merge($url, $paramFilter); $oGrid->setURL($url); $arrData = null; if ($oGrid->isExportAction()) { $limit = $totalMonitoring; $offset = 0; $arrColumns = array(_tr("Date"), _tr("Time"), _tr("Source"), _tr("Destination"), _tr("Duration"), _tr("Type"), _tr("File")); $oGrid->setColumns($arrColumns); if ($esAdministrador) { $arrResult = $pMonitoring->getMonitoring($limit, $offset, $filter_field, $filter_value, null, $date_initial, $date_final); } elseif (!($extension == "" || is_null($extension))) { $arrResult = $pMonitoring->getMonitoring($limit, $offset, $filter_field, $filter_value, $extension, $date_initial, $date_final); } else { $arrResult = array(); } if (is_array($arrResult) && $totalMonitoring > 0) { foreach ($arrResult as $key => $value) { $arrTmp[0] = date('d M Y', strtotime($value['calldate'])); $arrTmp[1] = date('H:i:s', strtotime($value['calldate'])); $arrTmp[2] = $value['src']; $arrTmp[3] = $value['dst']; $arrTmp[4] = $value['dstchannel']; $arrTmp[5] = SecToHHMMSS($value['duration']); $file = $value['uniqueid']; $namefile = basename($value['userfield']); $namefile = str_replace("audio:", "", $namefile); if ($namefile == 'deleted') { $arrTmp[6] = _tr('Deleted'); } else { switch ($namefile[0]) { case "O": $arrTmp[6] = _tr("Outgoing"); break; case "g": $arrTmp[6] = _tr("Group"); break; case "q": $arrTmp[6] = _tr("Queue"); break; default: $arrTmp[6] = _tr("Incoming"); break; } } $arrTmp[7] = $namefile; $arrTmp[8] = $value['note']; $arrTmp[9] = $value['delivery_id']; $arrData[] = $arrTmp; } } } else { $limit = 20; $total = $totalMonitoring; $oGrid->setLimit($limit); $oGrid->setTotal($total); $offset = $oGrid->calculateOffset(); if ($esAdministrador) { $oGrid->deleteList(_tr("message_alert"), 'submit_eliminar', _tr("Delete")); $buttonDelete = ""; } else { $buttonDelete = ""; } $arrColumns = array($buttonDelete, "Ngày", "Giờ", "Gọi từ", "Gọi đến", "Nhân viên/PSTN", "Thời gian gọi", "Loại", "Ghi âm", "Nội dung", "Giao vé"); $oGrid->setColumns($arrColumns); if ($esAdministrador) { $arrResult = $pMonitoring->getMonitoring($limit, $offset, $filter_field, $filter_value, null, $date_initial, $date_final); } elseif (!($extension == "" || is_null($extension))) { $arrResult = $pMonitoring->getMonitoring($limit, $offset, $filter_field, $filter_value, $extension, $date_initial, $date_final); } else { $arrResult = array(); } if (is_array($arrResult) && $total > 0) { $src = ""; $dst = ""; foreach ($arrResult as $key => $value) { if ($esAdministrador) { $arrTmp[0] = "<input type='checkbox' name='id_" . $value['uniqueid'] . "' />"; } else { $arrTmp[0] = ""; } $arrTmp[1] = date('d M Y', strtotime($value['calldate'])); $arrTmp[2] = date('H:i:s', strtotime($value['calldate'])); if (!isset($value['src']) || $value['src'] == "") { $src = "<font color='gray'>" . _tr("unknown") . "</font>"; } else { $src = $value['src']; } if (!isset($value['dst']) || $value['dst'] == "") { $dst = "<font color='gray'>" . _tr("unknown") . "</font>"; } else { $dst = $value['dst']; } $arrTmp[3] = $src; $arrTmp[4] = $dst; $arrTmp[5] = channel_lookup($pDB, $value['dstchannel']); $arrTmp[6] = "<label title='" . $value['duration'] . " seconds' style='color:green'>" . SecToHHMMSS($value['duration']) . "</label>"; //$file = base64_encode($value['userfield']); $file = $value['uniqueid']; $namefile = basename($value['userfield']); $namefile = str_replace("audio:", "", $namefile); if ($namefile == 'deleted') { $arrTmp[7] = _tr('Deleted'); } else { switch ($namefile[0]) { case "O": $arrTmp[7] = _tr("Outgoing"); break; case "g": $arrTmp[7] = _tr("Group"); break; case "q": $arrTmp[7] = _tr("Queue"); break; default: $arrTmp[7] = _tr("Incoming"); break; } } if ($namefile != 'deleted') { $recordingLink = "<a href=\"javascript:popUp('index.php?menu={$module_name}&action=display_record&id={$file}&namefile={$namefile}&rawmode=yes',350,100);\">" . _tr("Listen") . "</a> "; $recordingLink .= "<a href='?menu={$module_name}&action=download&id={$file}&namefile={$namefile}&rawmode=yes' >" . _tr("Download") . "</a>"; } else { $recordingLink = ''; } $arrTmp[8] = $recordingLink; $arrTmp[9] = is_null($value['note_id']) ? '-' : '<a href="javascript:void(0)" onclick="view_note(\'' . $value['note_id'] . '\')">Xem</a>'; $arrTmp[10] = is_null($value['delivery_id']) ? '-' : '<a href="javascript:void(0)" onclick="view_delivery(\'' . $value['delivery_id'] . '\')">Xem</a>'; $arrData[] = $arrTmp; } } } $oGrid->setData($arrData); //begin section filter $arrFormFilterMonitoring = createFieldFilter(); $oFilterForm = new paloForm($smarty, $arrFormFilterMonitoring); $smarty->assign("INCOMING", _tr("Incoming")); $smarty->assign("OUTGOING", _tr("Outgoing")); $smarty->assign("QUEUE", _tr("Queue")); $smarty->assign("GROUP", _tr("Group")); $smarty->assign("SHOW", _tr("Show")); $_POST["filter_field"] = $filter_field; $_POST["filter_value"] = $filter; $_POST["filter_value_userfield"] = $filter_userfield; $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Start Date") . " = " . $paramFilter['date_start'] . ", " . _tr("End Date") . " = " . $paramFilter['date_end'], $paramFilter, array('date_start' => date("d M Y"), 'date_end' => date("d M Y")), true); if ($filter_field == "userfield") { $oGrid->addFilterControl(_tr("Filter applied ") . " {$nameFilterField} = {$nameFilterUserfield}", $_POST, array('filter_field' => "src", 'filter_value_userfield' => "incoming")); } else { $oGrid->addFilterControl(_tr("Filter applied ") . " {$nameFilterField} = {$filter}", $_POST, array('filter_field' => "src", "filter_value" => "")); } $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST); //end section filter $oGrid->showFilter(trim($htmlFilter)); $content = $oGrid->fetchGrid(); //end grid parameters return $content; }
function reportMonitoring($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials) { global $arrPermission; $error = ''; $pMonitoring = new paloSantoMonitoring($pDB); $pORGZ = new paloSantoOrganization($arrConf['elastix_dsn']["elastix"]); $pPBX = new paloAsteriskDB($arrConf['elastix_dsn']["elastix"]); if ($credentials['userlevel'] == 'superadmin') { $domain = getParameter('organization'); $domain = empty($domain) ? 'all' : $domain; $arrOrgz = array("all" => _tr("all")); foreach ($pORGZ->getOrganization(array()) as $value) { $arrOrgz[$value["domain"]] = $value["name"]; } } else { $arrOrgz = array(); $domain = $credentials['domain']; } $date_start = getParameter('date_start'); if (!preg_match("/^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}\$/", $date_start)) { $date_start = date("d M Y"); } $date_end = getParameter('date_end'); if (!preg_match("/^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}\$/", $date_end)) { $date_end = date("d M Y"); } $arrType = array("" => "", "conference" => _tr("Conference"), "group" => _tr("Group"), "queue" => _tr("Queue"), 'incoming' => _tr('Incoming'), 'outgoing' => _tr("Outgoing")); $type = getParameter("type"); $type = array_key_exists($type, $arrType) ? $type : ""; $source = getParameter("source"); if (isset($source) && $source != '') { $expression = $pPBX->getRegexPatternFromAsteriskPattern($source); if ($expression === false) { $source = ''; } } $destination = getParameter("destination"); if (isset($destination) && $destination != '') { $expression = $pPBX->getRegexPatternFromAsteriskPattern($destination); if ($expression === false) { $destination = ''; } } $url['menu'] = $module_name; $url['organization'] = $arrProp['organization'] = $domain; $url['date_start'] = $arrProp['date_start'] = $date_start; $url['date_end'] = $arrProp['date_end'] = $date_end; $url['source'] = $arrProp['source'] = $source; $url['destination'] = $arrProp['destination'] = $destination; $url['type'] = $arrProp['type'] = $type; //permission $delete = in_array("delete", $arrPermission); $export = in_array("export", $arrPermission); //begin grid parameters $oGrid = new paloSantoGrid($smarty); $oGrid->setTitle(_tr("Monitoring")); $oGrid->setIcon("web/apps/{$module_name}/images/pbx_monitoring.png"); $oGrid->pagingShow(true); // show paging section. if ($export) { $oGrid->enableExport(); } // enable export. $oGrid->setNameFile_Export(_tr("Monitoring")); $oGrid->setURL($url); if ($delete && !$oGrid->isExportAction()) { $arrColumns[] = ""; } if ($credentials['userlevel'] == 'superadmin') { $arrColumns[] = _tr('organization'); } $arrColumns[] = _tr("Date"); $arrColumns[] = _tr("Time"); $arrColumns[] = _tr("Source"); $arrColumns[] = _tr("Destination"); $arrColumns[] = _tr("Duration"); $arrColumns[] = _tr("Type"); $arrColumns[] = _tr("File"); if (!$oGrid->isExportAction()) { $arrColumns[] = ""; //to display audio } $oGrid->setColumns($arrColumns); $totalMonitoring = $pMonitoring->getNumMonitoring($arrProp); if ($totalMonitoring === false) { $error = _tr('Recordings could not be retrieved.') . " " . "DATABASE ERROR"; $totalMonitoring = 0; } $arrData = array(); $arrResult = array(); if ($totalMonitoring != 0) { if ($oGrid->isExportAction()) { $arrResult = $pMonitoring->getMonitoring($arrProp); } else { $limit = 20; $total = $totalMonitoring; $oGrid->setLimit($limit); $oGrid->setTotal($total); $offset = $oGrid->calculateOffset(); $arrProp['limit'] = $limit; $arrProp['offset'] = $offset; $arrResult = $pMonitoring->getMonitoring($arrProp); } } if ($arrResult === false) { $error = _tr('Recordings could not be retrieved.') . " " . "DATABASE ERROR"; } else { if ($oGrid->isExportAction()) { if (!$export) { $arrData = _tr('INVALID ACTION'); } foreach ($arrResult as $monitoring) { $arrTmp = array(); if ($credentials['userlevel'] == 'superadmin') { $arrTmp[] = isset($arrOrgz[$monitoring['organization_domain']]) ? $arrOrgz[$monitoring['organization_domain']] : ''; } $arrTmp[] = date('d M Y', strtotime($monitoring['calldate'])); //date $arrTmp[] = date('H:i:s', strtotime($monitoring['calldate'])); //time $arrTmp[] = $monitoring['src']; //source $arrTmp[] = $monitoring['dst']; //destination $arrTmp[] = SecToHHMMSS($monitoring['duration']); //duration $namefile = basename($monitoring['userfield']); $namefile = str_replace("audio:", "", $namefile); if ($monitoring['toout'] == '1') { $arrTmp[] = $arrType['outgoing']; } elseif ($monitoring['fromout'] == '1') { $arrTmp[] = $arrType['incoming']; } else { if ($namefile[0] == 'g') { $arrTmp[] = $arrType['group']; } elseif ($namefile[0] == 'q') { $arrTmp[] = $arrType['queue']; } elseif (strpos($namefile, "meetme-conf") !== false) { $arrTmp[] = $arrType['conference']; } else { $arrTmp[] = ""; } } $arrTmp[] = $namefile; $arrData[] = $arrTmp; } } else { $i = 0; foreach ($arrResult as $monitoring) { $arrTmp = array(); if ($delete) { $arrTmp[] = "<input type='checkbox' name='recordDel[]' value='{$monitoring['uniqueid']}' />"; } if ($credentials['userlevel'] == 'superadmin') { $arrTmp[] = isset($arrOrgz[$monitoring['organization_domain']]) ? $arrOrgz[$monitoring['organization_domain']] : ''; } $arrTmp[] = date('d M Y', strtotime($monitoring['calldate'])); //date $arrTmp[] = date('H:i:s', strtotime($monitoring['calldate'])); //time $arrTmp[] = $monitoring['src']; //source $arrTmp[] = $monitoring['dst']; //destination $arrTmp[] = SecToHHMMSS($monitoring['duration']); //duration $namefile = basename($monitoring['userfield']); $namefile = str_replace("audio:", "", $namefile); if ($monitoring['toout'] == '1') { $arrTmp[] = $arrType['outgoing']; } elseif ($monitoring['fromout'] == '1') { $arrTmp[] = $arrType['incoming']; } else { if ($namefile[0] == 'g') { $arrTmp[] = $arrType['group']; } elseif ($namefile[0] == 'q') { $arrTmp[] = $arrType['queue']; } elseif (strpos($namefile, "meetme-conf") !== false) { $arrTmp[] = $arrType['conference']; } else { $arrTmp[] = ""; } } if ($namefile == 'deleted') { $arrTmp[] = $namefile; $arrTmp[] = ""; } else { $explod_name = explode(".", $namefile); $ext = array_pop($explod_name); if ($ext == 'gsm' || $ext == 'WAV') { $div_display = "<a href=\"javascript:popUp('index.php?menu={$module_name}&action=display_record&id={$monitoring['uniqueid']}&rawmode=yes',350,100)\"><img style='cursor:pointer;' width='13px' src='web/apps/recordings/images/sound.png'/></a> "; } else { $div_display = "<div class='single' id='{$i}' style='display:inline;'><span data-src='index.php?menu={$module_name}&action=download&id={$monitoring['uniqueid']}&rawmode=yes'><img style='cursor:pointer;' width='13px' src='web/apps/recordings/images/sound.png'/> </span></div>"; } $download = "<a href='index.php?menu={$module_name}&action=download&id={$monitoring['uniqueid']}&rawmode=yes'>" . $namefile . "</a>"; $arrTmp[] = $div_display . $download; $arrTmp[] = "<audio></audio>"; } $i++; $arrData[] = $arrTmp; } } } $oGrid->setData($arrData); if ($error != "") { $smarty->assign("mb_title", _tr("MESSAGE")); $smarty->assign("mb_message", $error); } //begin section filter $smarty->assign("USERLEVEL", $credentials['userlevel']); $smarty->assign("SEARCH", "<input type='submit' class='button' value='" . _tr('Search') . "' name='report'>"); if ($delete) { $oGrid->deleteList(_tr("Are you sure you want to delete?"), "delete", _tr("Delete Selected"), false); } if ($credentials['userlevel'] == 'superadmin') { $_POST["organization"] = $domain; $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Organization") . " = " . $arrOrgz[$domain], $_POST, array("organization" => _tr("all")), true); } $_POST['date_start'] = $arrProp['date_start']; $_POST['date_end'] = $arrProp['date_end']; $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Start Date") . " = " . $arrProp['date_start'] . ", " . _tr("End Date") . " = " . $arrProp['date_end'], $arrProp, array('date_start' => date("d M Y"), 'date_end' => date("d M Y")), true); //DATE START - DATE END $_POST["type"] = $type; // type $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Type") . " = " . $arrType[$type], $_POST, array("type" => "")); $_POST["source"] = $source; // source $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Source") . " = " . $source, $_POST, array("source" => "")); $_POST["destination"] = $destination; // destination $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Destination") . " = " . $source, $_POST, array("destination" => "")); $arrForm = createFieldFilter($arrOrgz, $arrType); $oFilterForm = new paloForm($smarty, $arrForm); $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST); $oGrid->showFilter(trim($htmlFilter)); //end section filter $content = $oGrid->fetchGrid(); return $content; }