コード例 #1
0
ファイル: index.php プロジェクト: hardikk/HNH
function _moduleContent(&$smarty, $module_name)
{
    require_once "modules/{$module_name}/libs/ringgroup.php";
    //include module files
    include_once "modules/{$module_name}/configs/default.conf.php";
    load_language_module($module_name);
    global $arrConf;
    global $arrConfModule;
    $arrConf = array_merge($arrConf, $arrConfModule);
    //folder path for custom templates
    $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'];
    // DSN para consulta de cdrs
    $dsn = generarDSNSistema('asteriskuser', 'asteriskcdrdb');
    $pDB = new paloDB($dsn);
    $oCDR = new paloSantoCDR($pDB);
    $pDBACL = new paloDB($arrConf['elastix_dsn']['acl']);
    if (!empty($pDBACL->errMsg)) {
        return "ERROR DE DB: {$pDBACL->errMsg}";
    }
    $pACL = new paloACL($pDBACL);
    if (!empty($pACL->errMsg)) {
        return "ERROR DE ACL: {$pACL->errMsg}";
    }
    $exten = '6868';
    //$pACL->getUserExtension($_SESSION['elastix_user']);
    $isAdministrator = true;
    //$pACL->isUserAdministratorGroup($_SESSION['elastix_user']);
    if (is_null($exten) || $exten == "") {
        if (!$isAdministrator) {
            $smarty->assign('mb_message', "<b>" . _tr("contact_admin") . "</b>");
            return "";
        } else {
            $smarty->assign('mb_message', "<b>" . _tr("no_extension") . "</b>");
        }
    }
    // Para usuarios que no son administradores, se restringe a los CDR de la
    // propia extensión
    $sExtension = $isAdministrator ? '' : $pACL->getUserExtension($_SESSION['elastix_user']);
    // DSN para consulta de ringgroups
    $dsn_asterisk = generarDSNSistema('asteriskuser', 'asterisk');
    $pDB_asterisk = new paloDB($dsn_asterisk);
    $oRG = new RingGroup($pDB_asterisk);
    $dataRG = $oRG->getRingGroup();
    $dataRG[''] = _tr('(Any ringgroup)');
    // Cadenas estáticas en la plantilla
    $smarty->assign(array("Filter" => _tr("Filter")));
    $arrFormElements = array("date_start" => array("LABEL" => _tr("Start Date"), "REQUIRED" => "yes", "INPUT_TYPE" => "DATE", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "ereg", "VALIDATION_EXTRA_PARAM" => "^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}\$"), "date_end" => array("LABEL" => _tr("End Date"), "REQUIRED" => "yes", "INPUT_TYPE" => "DATE", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "ereg", "VALIDATION_EXTRA_PARAM" => "^[[:digit:]]{1,2}[[:space:]]+[[:alnum:]]{3}[[:space:]]+[[:digit:]]{4}\$"), "field_name" => array("LABEL" => _tr("Field Name"), "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => array("dst" => _tr("Destination"), "src" => _tr("Source"), "channel" => _tr("Src. Channel"), "accountcode" => _tr("Account Code"), "dstchannel" => _tr("Dst. Channel")), "VALIDATION_TYPE" => "ereg", "VALIDATION_EXTRA_PARAM" => "^(dst|src|channel|dstchannel|accountcode)\$"), "field_pattern" => array("LABEL" => _tr("Field"), "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "ereg", "VALIDATION_EXTRA_PARAM" => "^[\\*|[:alnum:]@_\\.,/\\-]+\$"), "status" => array("LABEL" => _tr("Status"), "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => array("ALL" => _tr("ALL"), "ANSWERED" => _tr("ANSWERED"), "BUSY" => _tr("BUSY"), "FAILED" => _tr("FAILED"), "NO ANSWER " => _tr("NO ANSWER")), "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "ringgroup" => array("LABEL" => _tr("Ring Group"), "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $dataRG, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""));
    $oFilterForm = new paloForm($smarty, $arrFormElements);
    // Parámetros base y validación de parámetros
    $url = array('menu' => $module_name);
    $paramFiltroBase = $paramFiltro = array('date_start' => date("d M Y"), 'date_end' => date("d M Y"), 'field_name' => 'dst', 'field_pattern' => '', 'status' => 'ALL', 'ringgroup' => '');
    foreach (array_keys($paramFiltro) as $k) {
        if (!is_null(getParameter($k))) {
            $paramFiltro[$k] = getParameter($k);
        }
    }
    $oGrid = new paloSantoGrid($smarty);
    if ($paramFiltro['date_start'] === "") {
        $paramFiltro['date_start'] = " ";
    }
    if ($paramFiltro['date_end'] === "") {
        $paramFiltro['date_end'] = " ";
    }
    $valueFieldName = $arrFormElements['field_name']["INPUT_EXTRA_PARAM"][$paramFiltro['field_name']];
    $valueStatus = $arrFormElements['status']["INPUT_EXTRA_PARAM"][$paramFiltro['status']];
    $valueRingGRoup = $arrFormElements['ringgroup']["INPUT_EXTRA_PARAM"][$paramFiltro['ringgroup']];
    $oGrid->addFilterControl(_tr("Filter applied: ") . _tr("Start Date") . " = " . $paramFiltro['date_start'] . ", " . _tr("End Date") . " = " . $paramFiltro['date_end'], $paramFiltro, array('date_start' => date("d M Y"), 'date_end' => date("d M Y")), true);
    $oGrid->addFilterControl(_tr("Filter applied: ") . $valueFieldName . " = " . $paramFiltro['field_pattern'], $paramFiltro, array('field_name' => "dst", 'field_pattern' => ""));
    $oGrid->addFilterControl(_tr("Filter applied: ") . _tr("Status") . " = " . $valueStatus, $paramFiltro, array('status' => 'ALL'), true);
    $oGrid->addFilterControl(_tr("Filter applied: ") . _tr("Ring Group") . " = " . $valueRingGRoup, $paramFiltro, array('ringgroup' => ''));
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $paramFiltro);
    if (!$oFilterForm->validateForm($paramFiltro)) {
        $smarty->assign(array('mb_title' => _tr('Validation Error'), 'mb_message' => '<b>' . _tr('The following fields contain errors') . ':</b><br/>' . implode(', ', array_keys($oFilterForm->arrErroresValidacion))));
        $paramFiltro = $paramFiltroBase;
        unset($_POST['delete']);
        // Se aborta el intento de borrar CDRs, si había uno.
    }
    // Tradudir fechas a formato ISO para comparación y para API de CDRs.
    $url = array_merge($url, $paramFiltro);
    $paramFiltro['date_start'] = translateDate($paramFiltro['date_start']) . ' 00:00:00';
    $paramFiltro['date_end'] = translateDate($paramFiltro['date_end']) . ' 23:59:59';
    // Valores de filtrado que no se seleccionan mediante filtro
    if ($sExtension != '') {
        $paramFiltro['extension'] = $sExtension;
    }
    // Ejecutar el borrado, si se ha validado.
    if (isset($_POST['delete'])) {
        if ($isAdministrator) {
            if ($paramFiltro['date_start'] <= $paramFiltro['date_end']) {
                $r = $oCDR->borrarCDRs($paramFiltro);
                if (!$r) {
                    $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => $oCDR->errMsg));
                }
            } else {
                $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => _tr("Please End Date must be greater than Start Date")));
            }
        } else {
            $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => _tr("Only administrators can delete CDRs")));
        }
    }
    $oGrid->setTitle(_tr("CDR Report"));
    $oGrid->pagingShow(true);
    // show paging section.
    $oGrid->enableExport();
    // enable export.
    $oGrid->setNameFile_Export(_tr("CDRReport"));
    $oGrid->setURL($url);
    //if($isAdministrator)
    //$oGrid->deleteList("Are you sure you wish to delete CDR(s) Report(s)?","delete",_tr("Delete"));
    $arrData = null;
    if (!isset($sExtension) || $sExtension == "" && !$isAdministrator) {
        $total = 0;
    } else {
        $total = $oCDR->contarCDRs($paramFiltro);
    }
    if ($oGrid->isExportAction()) {
        $limit = $total;
        $offset = 0;
        $arrColumns = array(_tr("Date"), _tr("Source"), _tr("Ring Group"), _tr("Destination"), _tr("Src. Channel"), _tr("Account Code"), _tr("Dst. Channel"), _tr("Status"), _tr("Duration"));
        $oGrid->setColumns($arrColumns);
        $arrResult = $oCDR->listarCDRs($paramFiltro, $limit, $offset);
        if (is_array($arrResult['cdrs']) && $total > 0) {
            foreach ($arrResult['cdrs'] as $key => $value) {
                $arrTmp[0] = date("d-m-Y H:i:s", strtotime($value[0]));
                $arrTmp[1] = $value[1];
                $arrTmp[2] = $value[11];
                $arrTmp[3] = $value[3];
                $arrTmp[4] = $value[9];
                $arrTmp[5] = $value[5];
                $iDuracion = $value[8];
                $iSec = $iDuracion % 60;
                $iDuracion = (int) (($iDuracion - $iSec) / 60);
                $iMin = $iDuracion % 60;
                $iDuracion = (int) (($iDuracion - $iMin) / 60);
                $sTiempo = "{$value[6]}s";
                if ($value[6] >= 60) {
                    if ($iDuracion > 0) {
                        $sTiempo .= " ({$iDuracion}h {$iMin}m {$iSec}s)";
                    } elseif ($iMin > 0) {
                        $sTiempo .= " ({$iMin}m {$iSec}s)";
                    }
                }
                $arrTmp[7] = $sTiempo;
                $arrData[] = $arrTmp;
            }
        }
        if (!is_array($arrResult)) {
            $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => $oCDR->errMsg));
        }
    } else {
        $limit = 20;
        $oGrid->setLimit($limit);
        $oGrid->setTotal($total);
        $offset = $oGrid->calculateOffset();
        $arrResult = $oCDR->listarCDRs($paramFiltro, $limit, $offset);
        $arrColumns = array('STT', _tr("Date"), _tr("Source"), _tr("Destination"), _tr("Src. Channel"), _tr("Dst. Channel"), _tr("Status"), _tr("Duration"));
        $oGrid->setColumns($arrColumns);
        if (is_array($arrResult['cdrs']) && $total > 0) {
            $index = 0;
            foreach ($arrResult['cdrs'] as $key => $value) {
                $arrTmp[0] = $index;
                $arrTmp[1] = date("d-m-Y H:i:s", strtotime($value[0]));
                $arrTmp[2] = $value[1];
                $arrTmp[3] = $value[2];
                $arrTmp[4] = channel_lookup($pDB_asterisk, $value[3]);
                $arrTmp[5] = channel_lookup($pDB_asterisk, $value[4]);
                $arrTmp[6] = $value[5];
                $iDuracion = $value[8];
                $iSec = $iDuracion % 60;
                $iDuracion = (int) (($iDuracion - $iSec) / 60);
                $iMin = $iDuracion % 60;
                $iDuracion = (int) (($iDuracion - $iMin) / 60);
                $sTiempo = "{$value[8]}s";
                if ($value[7] >= 60) {
                    if ($iDuracion > 0) {
                        $sTiempo .= " ({$iDuracion}h {$iMin}m {$iSec}s)";
                    } elseif ($iMin > 0) {
                        $sTiempo .= " ({$iMin}m {$iSec}s)";
                    }
                }
                $arrTmp[7] = $sTiempo;
                $arrData[] = $arrTmp;
                $index++;
            }
        }
        if (!is_array($arrResult)) {
            $smarty->assign(array('mb_title' => _tr('ERROR'), 'mb_message' => $oCDR->errMsg));
        }
    }
    $oGrid->setData($arrData);
    $smarty->assign("SHOW", _tr("Show"));
    $oGrid->showFilter($htmlFilter);
    $content = $oGrid->fetchGrid();
    return $content;
}
コード例 #2
0
function reportCDR($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials)
{
    global $arrPermission;
    $error = '';
    $pCDR = new paloSantoCDR($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");
    }
    $src = getParameter("src");
    if (isset($src) && $src != '') {
        $expression = $pPBX->getRegexPatternFromAsteriskPattern($src);
        if ($expression === false) {
            $src = '';
        }
    }
    $dst = getParameter("dst");
    if (isset($dst) && $dst != '') {
        $expression = $pPBX->getRegexPatternFromAsteriskPattern($dst);
        if ($expression === false) {
            $dst = '';
        }
    }
    $src_channel = getParameter("src_channel");
    $dst_channel = getParameter("dst_channel");
    $calltype = getParameter("calltype");
    $arrCallType = array("all" => _tr("ALL"), 'incoming' => _tr('Incoming'), 'outgoing' => _tr("Outgoing"));
    $calltype = array_key_exists($calltype, $arrCallType) ? $calltype : "all";
    $status = getParameter("status");
    $arrStatus = array("all" => _tr("ALL"), 'ANSWERED' => _tr('ANSWERED'), 'BUSY' => _tr("BUSY"), 'FAILED' => _tr("FAILED"), "NO ANSWER " => _tr("NO ANSWER"));
    $status = array_key_exists($status, $arrStatus) ? $status : "all";
    $accountcode = getParameter('accountcode');
    $url['menu'] = $module_name;
    $url['organization'] = $paramFiltro['organization'] = $domain;
    $url['date_start'] = $paramFiltro['date_start'] = $date_start;
    $url['date_end'] = $paramFiltro['date_end'] = $date_end;
    $url['src'] = $paramFiltro['src'] = $src;
    $url['dst'] = $paramFiltro['dst'] = $dst;
    $url['src_channel'] = $paramFiltro['src_channel'] = $src_channel;
    $url['dst_channel'] = $paramFiltro['dst_channel'] = $dst_channel;
    $url['calltype'] = $paramFiltro['calltype'] = $calltype;
    $url['status'] = $paramFiltro['status'] = $status;
    $url['accountcode'] = $paramFiltro['accountcode'] = $accountcode;
    //permission
    $delete = in_array("delete", $arrPermission);
    $export = in_array("export", $arrPermission);
    //begin grid parameters
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->setTitle(_tr("CDR Report"));
    $oGrid->pagingShow(true);
    if ($export) {
        $oGrid->enableExport();
        // enable export.
        $oGrid->setNameFile_Export(_tr("CDRReport"));
    }
    $oGrid->setURL($url);
    if ($delete && !$oGrid->isExportAction()) {
        $arrColumns[] = "<input type='checkbox' name='cdrcheckall' class='cdrcheckall' id='cdrcheckall' onclick='jqCheckAll(this.id)';>";
    }
    if ($credentials['userlevel'] == 'superadmin') {
        $arrColumns[] = _tr("Organization");
    }
    $arrColumns[] = _tr("Date");
    $arrColumns[] = _tr("Source");
    if ($credentials['userlevel'] != 'superadmin') {
        $arrColumns[] = _tr("Ring Group");
    }
    $arrColumns[] = _tr("Destination");
    $arrColumns[] = _tr("Src. Channel");
    $arrColumns[] = _tr("Account Code");
    $arrColumns[] = _tr("Dst. Channel");
    $arrColumns[] = _tr("Call Direction");
    $arrColumns[] = _tr("Status");
    $arrColumns[] = _tr("Duration");
    $oGrid->setColumns($arrColumns);
    //get NumCDR
    $total = $pCDR->getNumCDR($paramFiltro);
    if ($total === false) {
        $total = 0;
        $error = _tr("An error has ocurred to retrieve CDR data") . " " . "DATABASE ERROR";
    }
    $arrData = array();
    $arrResult = array();
    if ($total != 0) {
        if ($oGrid->isExportAction()) {
            if (!$export) {
                $arrData = _tr('INVALID ACTION');
            } else {
                $arrResult = $pCDR->listarCDRs($paramFiltro);
            }
        } else {
            $limit = 20;
            $oGrid->setLimit($limit);
            $oGrid->setTotal($total);
            $offset = $oGrid->calculateOffset();
            $arrResult = $pCDR->listarCDRs($paramFiltro, $limit, $offset);
        }
    }
    if ($arrResult === false) {
        $error = _tr('CDR data could not be retrieved.') . " " . "DATABASE ERROR";
    } else {
        foreach ($arrResult as $value) {
            $arrTmp = array();
            if ($delete && !$oGrid->isExportAction()) {
                $arrTmp[] = "<input type='checkbox' name='crdDel[]' class='cdrdelete' value='{$value['6']}' />";
            }
            if ($credentials['userlevel'] == "superadmin") {
                $arrTmp[] = isset($arrOrgz[$value[11]]) ? $arrOrgz[$value[11]] : '';
            }
            $arrTmp[] = $value[0];
            //calldate
            $arrTmp[] = $value[1];
            //src
            if ($credentials['userlevel'] != "superadmin") {
                $arrTmp[] = $value[10];
            }
            //rg_name
            $arrTmp[] = $value[2];
            //dst
            $arrTmp[] = $value[3];
            //channel
            $arrTmp[] = $value[9];
            //accountcode
            $arrTmp[] = $value[4];
            //dst_channel
            if ($value[12] == "1" || $value[13] == "1") {
                //call_type
                $arrTmp[] = $value[12] == "1" ? "outgoing" : "incoming";
            } else {
                $arrTmp[] = "";
            }
            $arrTmp[] = $value[5];
            //disposition
            $iDuracion = $value[8];
            //billsec
            $iSec = $iDuracion % 60;
            $iDuracion = (int) (($iDuracion - $iSec) / 60);
            $iMin = $iDuracion % 60;
            $iDuracion = (int) (($iDuracion - $iMin) / 60);
            $sTiempo = "{$value[8]}s";
            if ($value[8] >= 60) {
                if ($iDuracion > 0) {
                    $sTiempo .= " ({$iDuracion}h {$iMin}m {$iSec}s)";
                } elseif ($iMin > 0) {
                    $sTiempo .= " ({$iMin}m {$iSec}s)";
                }
            }
            $arrTmp[] = $sTiempo;
            $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" => "all"), true);
    }
    $_POST['date_start'] = $paramFiltro['date_start'];
    $_POST['date_end'] = $paramFiltro['date_end'];
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Start Date") . " = " . $paramFiltro['date_start'] . ", " . _tr("End Date") . " = " . $paramFiltro['date_end'], $paramFiltro, array('date_start' => date("d M Y"), 'date_end' => date("d M Y")), true);
    //DATE START - DATE END
    $_POST["src"] = $src;
    // source
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Source") . " = " . $src, $_POST, array("src" => ""));
    $_POST["dst"] = $dst;
    // destination
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Destination") . " = " . $dst, $_POST, array("dst" => ""));
    $_POST["src_channel"] = $src_channel;
    // source channel
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Source Channel") . " = " . $src_channel, $_POST, array("src_channel" => ""));
    $_POST["dst_channel"] = $dst_channel;
    // destination channel
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Destination Channel") . " = " . $dst_channel, $_POST, array("dst_channel" => ""));
    $_POST["calltype"] = $calltype;
    // call type
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Call Destination") . " = " . $arrCallType[$calltype], $_POST, array("calltype" => "all"), true);
    $_POST["status"] = $status;
    // call status
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Call Status") . " = " . $arrStatus[$status], $_POST, array("status" => "all"), true);
    $_POST["accountcode"] = $accountcode;
    // destination channel
    $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Account Code") . " = " . $dst, $_POST, array("accountcode" => ""));
    $arrForm = createFieldFilter($arrOrgz, $arrCallType, $arrStatus);
    $oFilterForm = new paloForm($smarty, $arrForm);
    $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST);
    $oGrid->showFilter(trim($htmlFilter));
    $content = $oGrid->fetchGrid();
    return $content;
}