function reportDIDorganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials) { $pORGZ = new paloSantoOrganization($pDB); $pDID = new paloDidPBX($pDB); $domain = getParameter('domain'); if ($credentials['userlevel'] != "superadmin") { $domain = $credentials['domain']; } if (!preg_match("/^(([[:alnum:]-]+)\\.)+([[:alnum:]])+\$/", $domain)) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr("Invalid domain format")); return reportOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials); } $total = $pDID->getTotalDID($domain); if ($total === false) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr("An error has ocurred to retrieve DID data")); return reportOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials); } $limit = 20; $oGrid = new paloSantoGrid($smarty); $oGrid->setLimit($limit); $oGrid->setTotal($total); $offset = $oGrid->calculateOffset(); $end = $offset + $limit <= $total ? $offset + $limit : $total; $url['menu'] = $module_name; $url['domain'] = $domain; $oGrid->setTitle(_tr('DID Organization List')); $oGrid->setURL($url); $oGrid->setWidth("99%"); $oGrid->setStart($total == 0 ? 0 : $offset + 1); $oGrid->setEnd($end); $oGrid->setTotal($total); if ($credentials['userlevel'] == "superadmin") { $arrColumns[] = ''; $arrColumns[] = _tr("Organization Domain"); } $arrColumns[] = _tr("DID"); $arrColumns[] = _tr("Type"); $arrColumns[] = _tr("Country"); $arrColumns[] = _tr("City"); $arrColumns[] = _tr("Country Code / Area Code"); $oGrid->setColumns($arrColumns); $arrData = array(); $arrDID = $pDID->getDIDs($domain, null, null, null, $limit, $offset); if ($arrDID === false) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr("An error has ocurred to retrieve DID data")); return reportOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials); } else { //si es un usuario solo se ve su didsion //si es un administrador ve todas las didsiones foreach ($arrDID as $did) { $arrTmp = array(); if ($credentials["userlevel"] == "superadmin") { $arrTmp[] = "<input type='checkbox' name='dids[]' value='{$did['id']}' />"; $arrTmp[] = $did["organization_domain"]; } $arrTmp[] = $did['did']; $arrTmp[] = $did["type"]; $arrTmp[] = $did["country"]; $arrTmp[] = $did["city"]; $arrTmp[] = $did["country_code"] . " / " . $did["area_code"]; $arrData[] = $arrTmp; } } if ($credentials['userlevel'] == "superadmin") { $oGrid->addNew("assignDIDs", _tr("Add DID")); $oGrid->deleteList(_tr('Are you sure you wish REMOVE this DID from organization'), 'removeDID', "Remove DID"); } $content = $oGrid->fetchGrid(array(), $arrData); return $content; }
function reportDID($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials) { global $arrPermission; $pDID = new paloDidPBX($pDB); $pORGZ = new paloSantoOrganization($pDB); $error = ""; $did_number = getParameter("did_number"); // did number $status = getParameter("status"); // asignado o sin asignar $country = getParameter("country"); // pais al que pertence el did $domain = getParameter("organization"); // did que se encuentran asigandos a dicha organizacion $url['menu'] = $module_name; if (isset($did_number) && $did_number != '') { $expression = $pDID->getRegexPatternFromAsteriskPattern($did_number); if ($expression === false) { $did_number = ''; } } $status = empty($status) ? 'all' : $status; $domain = empty($domain) ? 'all' : $domain; $url['did_number'] = $did_number; $url['status'] = $status; $url['country'] = $country; $url['organization'] = $domain; $total = 0; $total = $pDID->getTotalDID($domain, $did_number, $country, $status); if ($total === false) { $error = $pDID->errMsg; $total = 0; } $limit = 20; $oGrid = new paloSantoGrid($smarty); $oGrid->setLimit($limit); $oGrid->setTotal($total); $offset = $oGrid->calculateOffset(); $end = $offset + $limit <= $total ? $offset + $limit : $total; $url = "?menu={$module_name}"; $arrGrid = array("title" => _tr('DID List'), "url" => $url, "width" => "99%", "start" => $total == 0 ? 0 : $offset + 1, "end" => $end, "total" => $total, 'columns' => array(array("name" => _tr("DID")), array("name" => _tr("Organization Domain")), array("name" => _tr("Type")), array("name" => _tr("Country")), array("name" => _tr("Country Code / Area Code")))); $arrData = array(); $arrDID = array(); if ($total != 0) { $arrDID = $pDID->getDIDs($domain, $did_number, $country, $status, $limit, $offset); } if ($arrDID === false) { $error = _tr("Error to obtain DID") . $pDID->errMsg; $arrData = array(); } else { //si es un usuario solo se ve su didsion //si es un administrador ve todas las didsiones foreach ($arrDID as $did) { $arrTmp[0] = " <a href='?menu=did&action=view&id_did=" . $did['id'] . "'>" . $did['did'] . "</a>"; $arrTmp[1] = $did["organization_domain"]; $arrTmp[2] = $did["type"]; $arrTmp[3] = $did["country"]; $arrTmp[4] = $did["country_code"] . " / " . $did["area_code"]; $arrData[] = $arrTmp; } } if (in_array('create', $arrPermission)) { $oGrid->addNew("create_did", _tr("New DID")); } $_POST["did_number"] = $did_number; $oGrid->addFilterControl(_tr("Filter applied ") . _tr("DID Number") . " = " . $did_number, $_POST, array("did_number" => "")); $arrStatus = array("all" => _tr('All'), "free" => _tr("No Assigned"), "busy" => _tr('Assigned')); $_POST["status"] = $status; $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Status") . " = " . $arrStatus[$status], $_POST, array("status" => _tr("all")), true); $_POST["country"] = $country; $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Country") . " = " . $country, $_POST, array("country" => "")); $arrOrgz = array("all" => _tr("all")); foreach ($pORGZ->getOrganization(array()) as $value) { $arrOrgz[$value["domain"]] = $value["name"]; } $_POST["organization"] = $domain; $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Organization") . " = " . $arrOrgz[$domain], $_POST, array("organization" => "all"), true); //organization $smarty->assign("SEARCH", "<input type='submit' class='button' value='" . _tr('Search') . "' name='search'>"); $arrFormElements = createFieldFilter($arrOrgz, $arrStatus); $oFilterForm = new paloForm($smarty, $arrFormElements); $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST); $oGrid->showFilter(trim($htmlFilter)); if ($error != "") { $smarty->assign("mb_title", _tr("MESSAGE")); $smarty->assign("mb_message", $error); } $content = $oGrid->fetchGrid($arrGrid, $arrData); return $content; }