private function _getFastGraphics() { $uelastix = FALSE; if (isset($_SESSION)) { $pDB = new paloDB($this->arrConf['elastix_dsn']['settings']); if (empty($pDB->errMsg)) { $uelastix = get_key_settings($pDB, 'uelastix'); $uelastix = (int) $uelastix != 0; } unset($pDB); } return $uelastix; }
function _moduleContent(&$smarty, $module_name) { include_once "libs/paloSantoGrid.class.php"; include_once "libs/paloSantoDB.class.php"; include_once "libs/paloSantoForm.class.php"; include_once "libs/paloSantoConfig.class.php"; include_once "libs/paloSantoTrunk.class.php"; require_once "libs/misc.lib.php"; //include module files include_once "modules/{$module_name}/configs/default.conf.php"; $lang = get_language(); $base_dir = dirname($_SERVER['SCRIPT_FILENAME']); $lang_file = "modules/{$module_name}/lang/{$lang}.lang"; if (file_exists("{$base_dir}/{$lang_file}")) { include_once "{$lang_file}"; } else { include_once "modules/{$module_name}/lang/en.lang"; } //global variables global $arrConf; global $arrConfModule; global $arrLang; global $arrLangModule; $arrConf = array_merge($arrConf, $arrConfModule); $arrLang = array_merge($arrLang, $arrLangModule); //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']; $contenido = ''; $msgError = ''; $pConfig = new paloConfig("/etc", "amportal.conf", "=", "[[:space:]]*=[[:space:]]*"); $arrConfig = $pConfig->leer_configuracion(false); $dsn = $arrConfig['AMPDBENGINE']['valor'] . "://" . $arrConfig['AMPDBUSER']['valor'] . ":" . $arrConfig['AMPDBPASS']['valor'] . "@" . $arrConfig['AMPDBHOST']['valor'] . "/asterisk"; $pDB = new paloDB($dsn); $pDBSetting = new paloDB($arrConf['elastix_dsn']['settings']); $pDBTrunk = new paloDB($arrConfModule['dsn_conn_database_1']); $arrForm = array("default_rate" => array("LABEL" => $arrLang["Default Rate"], "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "float", "VALIDATION_EXTRA_PARAM" => ""), "default_rate_offset" => array("LABEL" => $arrLang["Default Rate Offset"], "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "float", "VALIDATION_EXTRA_PARAM" => "")); $oForm = new paloForm($smarty, $arrForm); $oForm->setViewMode(); //obtener el valor de la tarifa por defecto $arrDefaultRate['default_rate'] = get_key_settings($pDBSetting, "default_rate"); $arrDefaultRate['default_rate_offset'] = get_key_settings($pDBSetting, "default_rate_offset"); $smarty->assign("EDIT", $arrLang["Edit"]); $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]); $strReturn = $oForm->fetchForm("{$local_templates_dir}/default_rate.tpl", $arrLang["Default Rate Configuration"], $arrDefaultRate); if (isset($_POST['edit_default'])) { $arrDefaultRate['default_rate'] = get_key_settings($pDBSetting, "default_rate"); $arrDefaultRate['default_rate_offset'] = get_key_settings($pDBSetting, "default_rate_offset"); $oForm = new paloForm($smarty, $arrForm); $smarty->assign("CANCEL", $arrLang["Cancel"]); $smarty->assign("SAVE", $arrLang["Save"]); $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]); $strReturn = $oForm->fetchForm("{$local_templates_dir}/default_rate.tpl", $arrLang["Default Rate Configuration"], $arrDefaultRate); } else { if (isset($_POST['save_default'])) { $oForm = new paloForm($smarty, $arrForm); $arrDefaultRate['default_rate'] = $_POST['default_rate']; $arrDefaultRate['default_rate_offset'] = $_POST['default_rate_offset']; if ($oForm->validateForm($_POST)) { $bValido = set_key_settings($pDBSetting, 'default_rate', $arrDefaultRate['default_rate']); $bValido = set_key_settings($pDBSetting, 'default_rate_offset', $arrDefaultRate['default_rate_offset']); if (!$bValido) { echo $arrLang["Error when saving default rate"]; } else { header("Location: index.php?menu=billing_setup"); } } else { // Error $smarty->assign("mb_title", $arrLang["Validation Error"]); $smarty->assign("mb_message", $arrLang["Value for rate is not valid"]); $smarty->assign("CANCEL", $arrLang["Cancel"]); $smarty->assign("SAVE", $arrLang["Save"]); $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]); $strReturn = $oForm->fetchForm("{$local_templates_dir}/default_rate.tpl", $arrLang["Default Rate Configuration"], $arrDefaultRate); } } } $arrTrunks = array(); $arrData = array(); $arrTrunksBill = array(); //obtener todos los trunks $oTrunk = new paloTrunk($pDBTrunk); //obtener todos los trunks que son para billing //$arrTrunksBill=array("DAHDI/g0","DAHDI/g1"); getTrunksBillFiltrado($pDB, $oTrunk, $arrConfig, $arrTrunks, $arrTrunksBill); if (isset($_POST['submit_bill_trunks'])) { //obtengo las que estan guardadas y las que ahora no estan $selectedTrunks = isset($_POST['trunksBills']) ? array_keys($_POST['trunksBills']) : array(); if (count($selectedTrunks) > 0) { foreach ($selectedTrunks as $selectedTrunk) { $nuevaListaTrunks[] = base64_decode($selectedTrunk); } } else { $nuevaListaTrunks = array(); } $listaTrunksNuevos = array_diff($nuevaListaTrunks, $arrTrunksBill); $listaTrunksAusentes = array_diff($arrTrunksBill, $nuevaListaTrunks); //tengo que borrar los trunks ausentes //tengo que agregar los trunks nuevos // print_r($listaTrunksNuevos); //print_r($listaTrunksAusentes); if (count($listaTrunksAusentes) > 0) { $bExito = $oTrunk->deleteTrunksBill($listaTrunksAusentes); if (!$bExito) { $msgError = $oTrunk->errMsg; } } if (count($listaTrunksNuevos) > 0) { $bExito = $oTrunk->saveTrunksBill($listaTrunksNuevos); if (!$bExito) { $msgError .= $oTrunk->errMsg; } } if (!empty($msgError)) { $smarty->assign("mb_message", $msgError); } } getTrunksBillFiltrado($pDB, $oTrunk, $arrConfig, $arrTrunks, $arrTrunksBill); $end = count($arrTrunks); if (is_array($arrTrunks)) { foreach ($arrTrunks as $trunk) { $arrTmp = array(); $checked = in_array($trunk[1], $arrTrunksBill) ? "checked" : ""; $arrTmp[0] = "<input type='checkbox' name='trunksBills[" . base64_encode($trunk[1]) . "]' {$checked}>"; $arrTmp[1] = $trunk[1]; $arrData[] = $arrTmp; } } $arrGrid = array("title" => $arrLang["Trunk Bill Configuration"], "icon" => "/modules/{$module_name}/images/reports_billing_setup.png", "width" => "99%", "start" => $end == 0 ? 0 : 1, "end" => $end, "total" => $end, "columns" => array(0 => array("name" => "", "property1" => ""), 1 => array("name" => $arrLang["Trunk"], "property1" => ""))); $oGrid = new paloSantoGrid($smarty); $oGrid->pagingShow(false); $oGrid->customAction('submit_bill_trunks', _tr('Billing Capable')); $trunk_config = $oGrid->fetchGrid($arrGrid, $arrData, $arrLang); if (strpos($trunk_config, '<form') === FALSE) { $trunk_config = "<form style='margin-bottom:0;' method='POST' action='?menu=billing_setup'>{$trunk_config}</form>"; } //mostrar los dos formularios $contenido .= $strReturn . $trunk_config; return $contenido; }
function loadShortcut($pdbACL, $uid, &$smarty) { global $arrConf; $pDB = new paloDB($arrConf['elastix_dsn']['settings']); if (empty($pDB->errMsg)) { $uelastix = get_key_settings($pDB, 'uelastix'); if ((int) $uelastix != 0) { return ''; } } if ($uid === FALSE) { return ''; } $sql = <<<SQL_BOOKMARKS_HISTORY SELECT aus.id AS id, ar.description AS name, ar.id AS id_menu, ar.name AS namemenu FROM acl_user_shortcut aus, acl_resource ar WHERE id_user = ? AND type = ? AND ar.id = aus.id_resource ORDER BY aus.id DESC SQL_BOOKMARKS_HISTORY; $bookmarks = $pdbACL->fetchTable($sql, TRUE, array($uid, 'bookmark')); if (is_array($bookmarks) && count($bookmarks) >= 0) { foreach (array_keys($bookmarks) as $i) { $bookmarks[$i]['name'] = _tr($bookmarks[$i]['name']); } } else { $bookmarks = NULL; } $smarty->assign(array('SHORTCUT_BOOKMARKS' => $bookmarks, 'SHORTCUT_BOOKMARKS_LABEL' => _tr('Bookmarks'))); $history = $pdbACL->fetchTable($sql, TRUE, array($uid, 'history')); if (is_array($history) && count($history) >= 0) { foreach (array_keys($history) as $i) { $history[$i]['name'] = _tr($history[$i]['name']); } } else { $history = NULL; } $smarty->assign(array('SHORTCUT_HISTORY' => $history, 'SHORTCUT_HISTORY_LABEL' => _tr('History'))); return $smarty->fetch('_common/_shortcut.tpl'); }
function filterAuthorizedMenus($idUser, $administrative = 'no') { global $arrConf; require_once "libs/paloSantoACL.class.php"; $pACL = new paloACL($this->_DB); $org_access = ''; $uelastix = FALSE; if (isset($_SESSION)) { $pDB = new paloDB($arrConf['elastix_dsn']['elastix']); if (empty($pDB->errMsg)) { $uelastix = get_key_settings($pDB, 'uelastix'); $uelastix = (int) $uelastix != 0; } unset($pDB); } if ($uelastix && isset($_SESSION['elastix_user_permission'])) { return $_SESSION['elastix_user_permission']; } $superAdmin = $pACL->isUserSuperAdmin($_SESSION['elastix_user']); //el usuario superadmin solo tiene acceso a los modulos administrativos if ($superAdmin && $administrative == 'no') { return NULL; } if (!$superAdmin) { //comprobamos que el modulo puede ser accesado por la organizacion $org_access = "AND ar.organization_access='yes'"; } //obtenemos el id del grupo al que pertecene el usuario $idGroup = $pACL->getUserGroup($idUser); if ($idGroup == false) { return NULL; } //seleccionamos los recuersos a los cuales la organizacion a la que pertenece el usuario tiene acceso //y de eso hacemos uns interseccion con la //union de las acciones permitidas por el grupo al que pertenece el usuario //y las acciones permitidas a el usuario $query = "SELECT ar.id, ar.IdParent, ar.Link, ar.description, ar.Type, ar.order_no \n FROM acl_resource ar JOIN organization_resource ore ON ar.id=ore.id_resource \n JOIN acl_group g ON g.id_organization=ore.id_organization \n WHERE g.id=? AND ar.administrative=? {$org_access} AND ar.id IN \n (SELECT ract.id_resource FROM resource_action ract \n JOIN group_resource_action as gr ON ract.id=gr.id_resource_action \n WHERE gr.id_group=? AND ract.action='access' \n UNION \n SELECT ract.id_resource FROM user_resource_action as ur \n JOIN resource_action ract ON ract.id=ur.id_resource_action \n WHERE ur.id_user=? AND ract.action='access') ORDER BY ar.order_no"; $arrModulesFiltered = array(); $r = $this->_DB->fetchTable($query, TRUE, array($idGroup, $administrative, $idGroup, $idUser)); if (!is_array($r)) { $this->errMsg = $this->_DB->errMsg; return NULL; } foreach ($r as $tupla) { $tupla['HasChild'] = FALSE; $arrModulesFiltered[$tupla['id']] = $tupla; } //Leer el nombre de todos los menus dentro de acl_resource $r = $this->_DB->fetchTable('SELECT ar.id, ar.IdParent, ar.Link, ar.description, ar.Type, ar.order_no, 1 AS HasChild ' . "FROM acl_resource ar WHERE ar.administrative=? {$org_access} ORDER BY ar.order_no", TRUE, array($administrative)); if (!is_array($r)) { $this->errMsg = $this->_DB->errMsg; return NULL; } $allMenus = array(); foreach ($r as $tupla) { $tupla['HasChild'] = FALSE; $allMenus[$tupla['id']] = $tupla; } //resolveoms referencia a los niveles superiores $menuMenus = array(); foreach (array_keys($arrModulesFiltered) as $k) { if ($arrModulesFiltered[$k]['Type'] == 'module') { $menuMenus[$k] = $k; } $kp = $arrModulesFiltered[$k]['IdParent']; if (isset($allMenus[$kp])) { //menu de segundo o tercer nivel $menuMenus[$kp] = $kp; //se hace esta verificacion para que loe menus de primer nivel sean incluidos if (isset($allMenus[$kp]['IdParent'])) { $menuMenus[$allMenus[$kp]['IdParent']] = $allMenus[$kp]['IdParent']; } } } // Copiar al arreglo filtrado los menús de primer nivel y segundo nivel EN EL ORDEN LEÍDO $arrMenuFiltered = array_intersect_key($allMenus, $menuMenus); if ($uelastix) { $_SESSION['elastix_user_permission'] = $arrMenuFiltered; } return $arrMenuFiltered; }
function isActivatedFreePBXFrontend() { $pDBSettings = new paloDB($this->arrConf['elastix_dsn']["settings"]); return get_key_settings($pDBSettings, "activatedFreePBX"); }
function leerDatosGrafico($type_graph, $date_start, $date_end) { global $arrConf; global $arrConfModule; global $arrLang; $MAX_SLICES = 10; $pConfig = new paloConfig("/etc", "amportal.conf", "=", "[[:space:]]*=[[:space:]]*"); $arrConfig = $pConfig->leer_configuracion(false); $pDBSQLite = new paloDB($arrConfModule['dsn_conn_database_2']); if (!empty($pDBSQLite->errMsg)) { echo "{$arrLang['ERROR']}: {$pDBSQLite->errMsg} <br>"; } $pRate = new paloRate($pDBSQLite); if (!empty($pRate->errMsg)) { echo "{$arrLang['ERROR']}: {$pRate->errMsg} <br>"; } $pDBSet = new paloDB($arrConf['elastix_dsn']['settings']); $pDBTrunk = new paloDB($arrConfModule['dsn_conn_database_1']); $oTrunk = new paloTrunk($pDBTrunk); $grupos = NULL; $troncales = $oTrunk->getExtendedTrunksBill($grupos, $arrConfig['ASTETCDIR']['valor'] . '/chan_dahdi.conf'); //ej array("DAHDI/1","DAHDI/2"); $dsn = $arrConfig['AMPDBENGINE']['valor'] . "://" . $arrConfig['AMPDBUSER']['valor'] . ":" . $arrConfig['AMPDBPASS']['valor'] . "@" . $arrConfig['AMPDBHOST']['valor'] . "/asteriskcdrdb"; $pDB = new paloDB($dsn); $oCDR = new paloSantoCDR($pDB); $arrCDR = $oCDR->obtenerCDRs("", 0, $date_start, $date_end, "", "", "ANSWERED", "outgoing", $troncales); $total = $arrCDR['NumRecords'][0]; $num_calls = array(); $minutos = array(); $val_charge = array(); $nombre_rate = array(); $title_sumary = NULL; if ($total > 0) { foreach ($arrCDR['Data'] as $cdr) { if (eregi("^DAHDI/([[:digit:]]+)", $cdr[4], $regs3)) { $trunk = 'DAHDI/g' . $grupos[$regs3[1]]; } else { $trunk = str_replace(strstr($cdr[4], '-'), '', $cdr[4]); } //tengo que buscar la tarifa para el numero de telefono $numero = $cdr[2]; $tarifa = array(); $rate_name = ""; $charge = 0; $bExito = $pRate->buscarTarifa($numero, $tarifa, $trunk); if (!count($tarifa) > 0 && $bExito) { $bExito = $pRate->buscarTarifa($numero, $tarifa, 'None'); } if (!$bExito) { echo "{$arrLang['ERROR']}: {$pRate->errMsg} <br>"; } else { //verificar si tiene tarifa if (count($tarifa) > 0) { foreach ($tarifa as $id_tarifa => $datos_tarifa) { $rate_name = $datos_tarifa['name']; $id_rate = $datos_tarifa['id']; $charge = $cdr[8] / 60 * $datos_tarifa['rate'] + $datos_tarifa['offset']; } } else { $rate_name = $arrLang["default"]; $id_rate = 0; //no tiene tarifa buscar tarifa por omision //por ahora para probar $1 el minuto $rate = get_key_settings($pDBSet, "default_rate"); $rate_offset = get_key_settings($pDBSet, "default_rate_offset"); $charge = $cdr[8] / 60 * $rate + $rate_offset; } $nombre_rate[$id_rate] = $rate_name; if (!isset($minutos[$id_rate])) { $minutos[$id_rate] = 0; } if (!isset($num_calls[$id_rate])) { $num_calls[$id_rate] = 0; } if (!isset($val_charge[$id_rate])) { $val_charge[$id_rate] = 0; } $minutos[$id_rate] += $cdr[8] / 60; $num_calls[$id_rate]++; $val_charge[$id_rate] += $charge; } } //ordenar los valores a mostrar arsort($num_calls); arsort($minutos); arsort($val_charge); //verificar que los valores no excedan el numero de slices del pie //numero de llamadas if (count($num_calls) > $MAX_SLICES) { $i = 1; foreach ($num_calls as $id_rate => $valor) { if ($i > $MAX_SLICES - 1) { if (!isset($valores_num_calls['otros'])) { $valores_num_calls['otros'] = 0; } $valores_num_calls['otros'] += $valor; } else { $valores_num_calls[$id_rate] = $valor; } $i++; } } else { $valores_num_calls = $num_calls; } //minutos if (count($minutos) > $MAX_SLICES) { $i = 1; foreach ($minutos as $id_rate => $valor) { if ($i > $MAX_SLICES - 1) { if (!isset($valores_minutos['otros'])) { $valores_minutos['otros'] = 0; } $valores_minutos['otros'] += $valor; } else { $valores_minutos[$id_rate] = $valor; } $i++; } } else { $valores_minutos = $minutos; } //charge if (count($val_charge) > $MAX_SLICES) { $i = 1; foreach ($val_charge as $id_rate => $valor) { if ($i > $MAX_SLICES - 1) { if (!isset($valores_charge['otros'])) { $valores_charge['otros'] = 0; } $valores_charge['otros'] += $valor; } else { $valores_charge[$id_rate] = $valor; } $i++; } } else { $valores_charge = $val_charge; } if ($type_graph == "minutes") { $titulo = $arrLang["Distribution by Time"]; $valores_grafico = $valores_minutos; $title_sumary = $arrLang["Minutes"]; } elseif ($type_graph == "charge") { $titulo = $arrLang["Distribution by Cost"]; $valores_grafico = $valores_charge; $title_sumary = $arrLang["Cost"]; } else { $titulo = $arrLang["Distribution by Number of Calls"]; $valores_grafico = $valores_num_calls; $title_sumary = $arrLang["Number of Calls"]; } //nombres de tarifas para leyenda foreach ($valores_grafico as $id => $valor) { $nombres_tarifas[] = isset($nombre_rate[$id]) ? $nombre_rate[$id] : $arrLang["others"]; } $data = array_values($valores_grafico); } else { if ($type_graph == "minutes") { $titulo = $arrLang["Distribution by Time"]; } elseif ($type_graph == "charge") { $titulo = $arrLang["Distribution by Cost"]; } else { $titulo = $arrLang["Distribution by Number of Calls"]; } $nombres_tarifas = $data = array(); } //formar la estructura a pasar al pie $data_graph = array("values" => $data, "legend" => $nombres_tarifas, "title" => $titulo, "title_sumary" => $title_sumary); return $data_graph; }
function _moduleContent(&$smarty, $module_name) { include_once "libs/paloSantoDB.class.php"; include_once "libs/paloSantoForm.class.php"; //include module files include_once "modules/{$module_name}/configs/default.conf.php"; //include file language agree to elastix configuration //if file language not exists, then include language by default (en) $lang = get_language(); $base_dir = dirname($_SERVER['SCRIPT_FILENAME']); $lang_file = "modules/{$module_name}/lang/{$lang}.lang"; if (file_exists("{$base_dir}/{$lang_file}")) { include_once "{$lang_file}"; } else { include_once "modules/{$module_name}/lang/en.lang"; } //global variables global $arrConf; global $arrConfModule; global $arrLang; global $arrLangModule; $arrConf = array_merge($arrConf, $arrConfModule); $arrLang = array_merge($arrLang, $arrLangModule); //folder path for custom templates $templates_dir = isset($arrConf['templates_dir']) ? $arrConf['templates_dir'] : 'themes'; $local_templates_dir = "{$base_dir}/modules/{$module_name}/" . $templates_dir . '/' . $arrConf['theme']; $contenido = ''; $msgError = ''; $pDBSetting = new paloDB($arrConf['dsn_conn_database']); $arrForm = array("fax_master" => array("LABEL" => $arrLang["Fax Master Email"], "REQUIRED" => "yes", "EDITABLE" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "ereg", "VALIDATION_EXTRA_PARAM" => "^[a-zA-Z0-9_.\\-]+@[a-zA-Z0-9_.\\-]+\\.[a-zA-Z0-9_.\\-]+\$")); $oForm = new paloForm($smarty, $arrForm); $oForm->setEditMode(); //obtener el valor de la tarifa por defecto $arrDefault['fax_master'] = get_key_settings($pDBSetting, "fax_master"); $smarty->assign("FAXMASTER_MSG", $arrLang["Write the email address which will receive the notifications of received messages, errors and activity summary of the Fax Server"]); $smarty->assign("icon", "/modules/{$module_name}/images/fax_fax_master.png"); $smarty->assign("APPLY_CHANGES", $arrLang["Save"]); $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]); $strReturn = $oForm->fetchForm("{$local_templates_dir}/fax_master.tpl", $arrLang["Fax Master Configuration"], $arrDefault); if (isset($_POST['save_default'])) { $oForm = new paloForm($smarty, $arrForm); $arrDefault['fax_master'] = $_POST['fax_master']; $bMostrarError = TRUE; if ($oForm->validateForm($_POST)) { $bMostrarError = FALSE; $bValido = set_key_settings($pDBSetting, 'fax_master', $arrDefault['fax_master']); if (!$bValido) { echo $arrLang["Error when saving Fax Master"]; } else { //guardar en /etc/postfix/virtual $bExito = modificar_archivos_mail($arrDefault['fax_master'], $error); if ($bExito) { header("Location: index.php?menu=faxmaster"); } else { $mensaje = $error; $bMostrarError = TRUE; } } } else { $mensaje = $arrLang["Value for Fax Master is not valid"]; } if ($bMostrarError) { // Error $smarty->assign("mb_title", $arrLang["Validation Error"]); $smarty->assign("mb_message", $mensaje); $smarty->assign("APPLY_CHANGES", $arrLang["Save"]); $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]); $strReturn = $oForm->fetchForm("{$local_templates_dir}/fax_master.tpl", $arrLang["Fax Master Configuration"], $arrDefault); } } return $strReturn; }
/** * Procedimiento para obtener de la base settings el tema actual de elastix * * @return string nombre del tema actual si lo encontro, vacio si no */ function getThemeActual() { $resultado = get_key_settings($this->_DB, 'theme'); return $resultado; }
function filterAuthorizedMenus($idUser) { global $arrConf; $uelastix = FALSE; if (isset($_SESSION)) { $pDB = new paloDB($arrConf['elastix_dsn']['settings']); if (empty($pDB->errMsg)) { $uelastix = get_key_settings($pDB, 'uelastix'); $uelastix = (int) $uelastix != 0; } unset($pDB); } if ($uelastix && isset($_SESSION['elastix_user_permission'])) { return $_SESSION['elastix_user_permission']; } // Adjuntar base de datos de ACL para acelerar búsqueda $bExito = $this->_DB->genQuery('ATTACH DATABASE ? AS acl', array(str_replace('sqlite3:////', '/', $arrConf['elastix_dsn']['acl']))); if (!$bExito) { $this->errMsg = $this->_DB->errMsg; return NULL; } // Obtener todos los módulos autorizados $sPeticionSQL = <<<INFO_AUTH_MODULO SELECT id, IdParent, Link, Name, Type, order_no FROM menu, ( SELECT acl_resource.name AS acl_resource_name, acl_group.name AS acl_name FROM acl_membership, acl_group, acl_group_permission, acl_resource WHERE acl_membership.id_user = ? AND acl_membership.id_group = acl_group.id AND acl_group.id = acl_group_permission.id_group AND acl_group_permission.id_resource = acl_resource.id UNION SELECT acl_resource.name AS acl_resource_name, acl_user.name AS acl_name FROM acl_user, acl_user_permission, acl_resource WHERE acl_user_permission.id_user = ? AND acl_user_permission.id_resource = acl_resource.id ) WHERE acl_resource_name = id ORDER BY order_no; INFO_AUTH_MODULO; $arrMenuFiltered = array(); $r = $this->_DB->fetchTable($sPeticionSQL, TRUE, array($idUser, $idUser)); if (!is_array($r)) { $this->errMsg = $this->_DB->errMsg; return NULL; } $this->_DB->genQuery('DETACH DATABASE acl'); foreach ($r as $tupla) { $tupla['HasChild'] = FALSE; $arrMenuFiltered[$tupla['id']] = $tupla; } // Leer los menús de primer nivel $r = $this->_DB->fetchTable('SELECT id, IdParent, Link, Name, Type, order_no, 1 AS HasChild ' . 'FROM menu WHERE IdParent = "" ORDER BY order_no', TRUE); if (!is_array($r)) { $this->errMsg = $this->_DB->errMsg; return NULL; } $menuPrimerNivel = array(); foreach ($r as $tupla) { $tupla['HasChild'] = (bool) $tupla['HasChild']; $menuPrimerNivel[$tupla['id']] = $tupla; } // Resolver internamente las referencias de menú superior $menuSuperior = array(); foreach (array_keys($arrMenuFiltered) as $k) { $kp = $arrMenuFiltered[$k]['IdParent']; if (isset($arrMenuFiltered[$kp])) { $arrMenuFiltered[$kp]['HasChild'] = TRUE; } elseif (isset($menuPrimerNivel[$kp])) { $menuSuperior[$kp] = $kp; } else { // Menú es de segundo nivel y no estaba autorizado unset($arrMenuFiltered[$k]); } } // Copiar al arreglo filtrado los menús de primer nivel EN EL ORDEN LEÍDO $arrMenuFiltered = array_merge($arrMenuFiltered, array_intersect_key($menuPrimerNivel, $menuSuperior)); if ($uelastix) { $_SESSION['elastix_user_permission'] = $arrMenuFiltered; } return $arrMenuFiltered; }
function _moduleContent(&$smarty, $module_name) { //include module files include_once "libs/paloSantoDB.class.php"; include_once "libs/paloSantoForm.class.php"; include "configs/languages.conf.php"; include_once "modules/{$module_name}/configs/default.conf.php"; load_language_module($module_name); //global variables 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']; $error_msg = ''; $msgError = ''; $contenido = ''; $archivos = array(); $langElastix = array(); $arrDefaultRate = array(); $conexionDB = FALSE; //leer los archivos disponibles /* $languages=array( "en"=>"English", "es"=>"Español", "fr"=>"Français", );*/ leer_directorio("lang", $error_msg, $archivos); if (count($archivos) > 0) { foreach ($languages as $lang => $lang_name) { if (in_array("{$lang}.lang", $archivos)) { $langElastix[$lang] = $lang_name; } } } if (count($langElastix) > 0) { //si no me puedo conectar a la base de datos // debo presentar un mensaje en vez del boton cambiar // un $arrForm = array("language" => array("LABEL" => _tr("Select language"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $langElastix, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "")); $oForm = new paloForm($smarty, $arrForm); $pDB = new paloDB($arrConf['elastix_dsn']['settings']); if (empty($pDB->errMsg)) { $conexionDB = TRUE; if (isset($_POST['save_language'])) { //guardar el nuevo valor $lang = $_POST['language']; $bExito = set_key_settings($pDB, 'language', $lang); //redirigir a la pagina nuevamente if ($bExito) { header("Location: index.php?menu=language"); } else { $smarty->assign("mb_message", "Error"); } } //obtener el valor de la tarifa por defecto $defLang = get_key_settings($pDB, 'language'); if (empty($defLang)) { $defLang = "en"; } $arrDefaultRate['language'] = $defLang; } else { $msgError = _tr("You can't change language") . '.-' . _tr("ERROR") . ":" . $pDB->errMsg; } // $arrDefaultRate['language']="es"; $smarty->assign("CAMBIAR", _tr("Save")); $smarty->assign("MSG_ERROR", $msgError); $smarty->assign("conectiondb", $conexionDB); $smarty->assign("icon", "modules/{$module_name}/images/system_preferencies_language.png"); $contenido = $oForm->fetchForm("{$local_templates_dir}/language.tpl", _tr("Language"), $arrDefaultRate); } return $contenido; }