function new_module($smarty, $module_name, $local_templates_dir, $arrLangModule, &$pDB_acl) { require_once 'libs/paloSantoACL.class.php'; global $arrConfig; $pACL = new paloACL($pDB_acl); $groups = $pACL->getGroups(); $ip = $_SERVER["SERVER_ADDR"]; foreach ($groups as $value) { $arrGroups[$value[0]] = $value[1]; } $arrFormElements = array("group_permissions" => array("LABEL" => $arrLangModule["Group Permission"], "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrGroups, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "", "EDITABLE" => "no", "SIZE" => "3", "MULTIPLE" => true)); $oForm = new paloForm($smarty, $arrFormElements); $smarty->assign("SAVE", $arrLangModule["Save"]); $smarty->assign("REQUIRED_FIELD", $arrLangModule["Required field"]); $smarty->assign("general_information", $arrLangModule["General Information"]); $smarty->assign("location", $arrLangModule["Location"]); $smarty->assign("module_description", $arrLangModule["Module Description"]); $smarty->assign("option_type", $arrConfig['arr_type']); $smarty->assign("email", $arrLangModule["Your e-mail"]); $smarty->assign("module_name_label", $arrLangModule["Module Name"]); $smarty->assign("id_module_label", $arrLangModule["Module Id"]); $smarty->assign("arrGroups", $arrGroups); $smarty->assign("your_name_label", $arrLangModule["Your Name"]); $smarty->assign("module_type", $arrLangModule["Module Type"]); $smarty->assign("type_grid", $arrLangModule["Grid"]); $smarty->assign("type_form", $arrLangModule["Form"]); $smarty->assign("type_framed", $arrLangModule["Framed"]); $smarty->assign("Field_Name", $arrLangModule["Field Name"]); $smarty->assign("Type_Field", $arrLangModule["Type Field"]); $smarty->assign("Url", $arrLangModule["Url"]); $smarty->assign("level_2", $arrLangModule["Level 2"]); $smarty->assign("level_3", $arrLangModule["Level 3"]); $smarty->assign("parent_1_exists", $arrLangModule["Level 1 Parent Exists"]); $smarty->assign("parent_2_exists", $arrLangModule["Level 2 Parent Exists"]); $smarty->assign("peYes", $arrLangModule["Yes"]); $smarty->assign("peNo", $arrLangModule["No"]); $smarty->assign("module_level", $arrLangModule["Module Level"]); $smarty->assign("level_1_parent_name", $arrLangModule["Level 1 Parent Name"]); $smarty->assign("level_1_parent_id", $arrLangModule["Level 1 Parent Id"]); $smarty->assign("icon", "modules/{$module_name}/images/developer.png"); $html = $oForm->fetchForm("{$local_templates_dir}/new_module.tpl", $arrLangModule["Build Module"], $_POST); //$contenidoModulo = "<form method='POST' style='margin-bottom:0;' action='?menu=$module_name'>".$html."</form>"; return $html; }
function deleteGroup($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $userLevel1, $userAccount, $idOrganization) { $pACL = new paloACL($pDB); $pORGZ = new paloSantoOrganization($pDB); $error = ""; $idGroup = getParameter("id"); if (isset($idGroup)) { // No se puede eliminar al grupo superadmin if ($idGroup == 0) { $error = _tr("This group can't be deleted because is used to admin elastix."); } elseif ($pACL->getGroupNameByid($idGroup) == "administrator") { $error = _tr("The administrator group cannot be deleted because is the default Elastix Group. You can delete any other group."); } else { if ($userLevel1 == "superadmin") { $arrGroup = $pACL->getGroups($idGroup); } else { $arrGroup = $pACL->getGroups($idGroup, $idOrganization); } if ($arrGroup == false) { $error = _tr("Group doesn't exist") . $pACL->errMsg; } } if ($error == "") { if ($pACL->deleteGroup($idGroup)) { $smarty->assign("mb_title", _tr("MESSAGE")); $error = _tr("Group was deleted successfully"); } else { $smarty->assign("mb_title", _tr("ERROR")); $error = _tr($pACL->errMsg); } } else { $smarty->assign("mb_title", _tr("ERROR")); } } else { $smarty->assign("mb_title", _tr("ERROR")); $error = _tr("Invalid Group"); } $smarty->assign("mb_message", $error); return reportGroup($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $userLevel1, $userAccount, $idOrganization); }
private function createAllGroupOrganization($idOrganization) { $gExito = false; $pACL = new paloACL($this->_DB); //creamos los grupos $query = "INSERT INTO acl_group (description,name,id_organization) " . "SELECT description,name,? FROM acl_group WHERE id_organization=1 AND name IN ('administrator', 'supervisor', 'end_user')"; $exito = $this->_DB->genQuery($query, array($idOrganization)); if ($exito == false) { $this->errMsg = _tr("An error has ocurred trying to create organizaion's group"); return false; } //obtenemos los grupos recien insertados a la organizacion $grpOrga = $pACL->getGroups(null, $idOrganization); if ($grpOrga == false) { $this->errMsg = _tr("An error has ocurred trying to create organizaion's group"); return false; } //asignamos los recursos a los grupos recien creados //la asignacion de recursos se obtiene de la asignacion que existe a los grupos // 'administrator', 'supervisor', 'end_user' de la organizacion por default // que tiene id 1. //Los grupos antes mencionados no deberian ser borrados del sistema $query = "INSERT INTO group_resource_action (id_group,id_resource_action) " . "SELECT ?,gract.id_resource_action FROM " . "(SELECT or1.id_resource FROM organization_resource or1 \n WHERE or1.id_organization=?) as or_re " . "JOIN " . "(SELECT gr.id_resource_action,ract.id_resource FROM resource_action ract \n JOIN group_resource_action gr ON ract.id=gr.id_resource_action \n JOIN acl_group g ON g.id=gr.id_group \n WHERE g.name=? AND g.id_organization=1) as gract " . "ON or_re.id_resource=gract.id_resource"; foreach ($grpOrga as $value) { //$value[0]=id //$value[1]=name $result = $this->_DB->genQuery($query, array($value[0], $idOrganization, $value[1])); if ($result == false) { $this->errMsg = _tr("An error has ocurred trying to assign group resources"); return false; } } return true; }
function reportGroupPermission($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials) { $pACL = new paloACL($pDB); $pORGZ = new paloSantoOrganization($pDB); $arrGroups = array(); $arrOrgz = array(); $idOrgFil = getParameter("idOrganization"); if ($credentials['userlevel'] == "superadmin") { $orgTmp = $pORGZ->getOrganization(array()); if ($orgTmp === false) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr($pORGZ->errMsg)); } elseif (count($orgTmp) == 0) { $smarty->assign("mb_title", _tr("MESSAGE")); $msg = _tr("You haven't created any organization"); $smarty->assign("mb_message", $msg); } else { //si el usuario a selecionado una organizacion comprobamos que esta exista //caso contrario procedemos a sellecionar la primera disponible $flag = false; foreach ($orgTmp as $value) { $arrOrgz[$value["id"]] = $value["name"]; if ($value["id"] == $idOrgFil) { $flag = true; } } if (!$flag) { $idOrgFil = $orgTmp[0]['id']; } } } else { $idOrgFil = $credentials['id_organization']; $orgTmp = $pORGZ->getOrganizationById($idOrgFil); if ($orgTmp == false) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr("An error has ocurred to retrieved organization data")); } else { $arrOrgz = $orgTmp; } } if (count($arrOrgz) > 0) { //que se un arreglo y que tenga al menos una organizacion $groupTmp = $pACL->getGroupsPaging(null, null, $idOrgFil); if ($groupTmp === false) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr($pACL->errMsg)); } else { foreach ($groupTmp as $value) { $arrGroups[$value[0]] = $value[1]; } } } $filter_group = getParameter("filter_group"); if (count($arrGroups) > 0) { if (empty($filter_group)) { //seleccionamos el primer grupo de la lista de grupos $filter_group = $groupTmp[0][0]; } //valido que el grupo pertenzca a la organizacion if ($pACL->getGroups($filter_group, $idOrgFil) == false) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr("Invalid Group")); $filter_group = $groupTmp[0][0]; } } $filter_resource = getParameter("filter_resource"); $lang = get_language(); if ($lang != "en") { if (isset($filter_resource)) { if (trim($filter_resource) != "") { global $arrLang; $filter_value = strtolower(trim($filter_resource)); $parameter_to_find[] = $filter_value; //parametro de busqueda sin traduccion foreach ($arrLang as $key => $value) { $langValue = strtolower(trim($value)); if (preg_match("/^[[:alnum:]| ]*\$/", $filter_value)) { if (strpos($langValue, $filter_value) !== FALSE) { $parameter_to_find[] = $key; } } } } } } if (isset($filter_resource)) { $parameter_to_find[] = $filter_resource; } else { $parameter_to_find = null; } $totalGroupPermission = 0; if (count($arrGroups) > 0) { $arrResourceOrg = $pACL->getResourcesByOrg($idOrgFil, $parameter_to_find); if ($arrResourceOrg === false) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr("An error has ocurred to retrieved Resources")); } else { $totalGroupPermission = count($arrResourceOrg); } } //begin grid parameters $oGrid = new paloSantoGrid($smarty); $limit = 25; $total = $totalGroupPermission; $oGrid->setLimit($limit); $oGrid->setTotal($total); $offset = $oGrid->calculateOffset(); $end = $offset + $limit <= $total ? $offset + $limit : $total; $url['menu'] = $module_name; $url['idOrganization'] = $idOrgFil; $url['filter_group'] = $filter_group; $url['filter_resource'] = $filter_resource; $arrData = $arrResourceActions = $arrPermisos = array(); $error = false; if (count($arrGroups) > 0 && $totalGroupPermission > 0) { $arrResource = array_slice($arrResourceOrg, $offset, $limit); $idGroup = $filter_group; foreach ($arrResource as $resource) { $listResource[] = $resource['id']; //lista de id de los recursos que queremos consulta $listResDes[$resource['id']] = $resource['description']; } //las acciones que tiene cada drecurso $arrResourceActions = $pACL->getResourcesActions($listResource); if ($arrResourceActions === false) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr("An error has ocurred to retrieved Resources Actions")); $error = true; } //los premisos que tiene el grupo $arrPermisos = $pACL->loadGroupPermissions($idGroup, $listResource); if ($arrPermisos === false) { $smarty->assign("mb_title", _tr("ERROR")); $smarty->assign("mb_message", _tr("An error has ocurred to retrieved Group Permissions")); $error = true; } } $max_actions = 0; $isAdministrator = $pACL->getGroupNameByid($idGroup) == _tr("administrator") ? true : false; if ($totalGroupPermission > 0 && !$error) { foreach ($arrResourceActions as $resource => $actions) { $arrTmp = array(); $arrTmp[] = _tr($listResDes[$resource]); $disabled = ""; if ($isAdministrator && ($resource == 'grouplist' || $resource == 'userlist' || $resource == 'group_permission')) { $disabled = "disabled='disabled'"; } //dentro del modulo organizacion ahi acciones que unicamente las puede realizar el superadmin //por lo tando no deben aparecer listadas if ($resource == "organization") { $actions = array_diff($actions, array('change_org_status', 'create_org', 'delete_org', 'edit_DID')); } elseif ($resource == "dashboard") { $actions = array('access'); } elseif ($resource == 'cdrreport') { $actions = array('access', 'export'); } if (count($actions) > $max_actions) { $max_actions = count($actions); } $desactivar = false; if (isset($arrPermisos[$resource])) { //grupo no tiene nigun permiso if (!in_array('access', $arrPermisos[$resource])) { $desactivar = true; } } else { $desactivar = true; $arrPermisos[$resource] = array(); } foreach ($actions as $action) { $class = 'other_act'; if ($action == 'access') { $class = 'access_act'; } elseif ($desactivar) { $disabled = "disabled='disabled'"; } $checked0 = ''; //chequeamos si la accion se encuentra en la lista de acciones permitidas en el recurso if (in_array($action, $arrPermisos[$resource])) { $checked0 = "checked"; } $arrTmp[] = "<input type='checkbox' class='{$class}' {$disabled} name='groupPermission[" . $resource . "][{$action}]' {$checked0}> {$action}"; } $arrData[] = $arrTmp; } } $oGrid->setTitle(_tr("Group Permission")); $oGrid->setURL($url); $oGrid->setWidth("99%"); $oGrid->setStart($total == 0 ? 0 : $offset + 1); $oGrid->setEnd($end); $oGrid->setTotal($total); $arrColumn[] = _tr("Resource"); for ($i = 1; $i <= $max_actions; $i++) { $act = _tr("Action"); $arrColumn[] = "{$act}" . " {$i}"; } $oGrid->setColumns($arrColumn); //begin section filter $arrFormFilter = createFieldFilter($arrGroups); $oFilterForm = new paloForm($smarty, $arrFormFilter); $smarty->assign("SHOW", _tr("Show")); $smarty->assign("limit_apply", htmlspecialchars($limit, ENT_COMPAT, 'UTF-8')); $smarty->assign("offset_apply", htmlspecialchars($offset, ENT_COMPAT, 'UTF-8')); $smarty->assign("resource_apply", htmlentities($filter_resource)); $_POST["filter_group"] = htmlspecialchars($filter_group, ENT_COMPAT, 'UTF-8'); $_POST["filter_resource"] = htmlspecialchars($filter_resource, ENT_COMPAT, 'UTF-8'); $_POST["idOrganization"] = $idOrgFil; if (count($arrOrgz) > 0) { global $arrPermission; if (in_array('edit_permission', $arrPermission)) { $oGrid->addSubmitAction("apply", _tr("Save")); } if ($credentials['userlevel'] == "superadmin") { $oGrid->addComboAction("idOrganization", _tr("Organization"), $arrOrgz, $idOrgFil, "report"); } $nameGroup = isset($arrGroups[$filter_group]) ? $arrGroups[$filter_group] : ""; $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Group") . " = {$nameGroup}", $_POST, array("filter_group" => $groupTmp[0][0]), true); $oGrid->addFilterControl(_tr("Filter applied ") . _tr("Resource") . " = {$filter_resource}", $_POST, array("filter_resource" => "")); $htmlFilter = $oFilterForm->fetchForm("{$local_templates_dir}/filter.tpl", "", $_POST); $oGrid->showFilter(trim($htmlFilter)); } else { $smarty->assign("mb_title", _tr("MESSAGE")); $smarty->assign("mb_message", _tr("You haven't created any organization")); } $contenidoModulo = $oGrid->fetchGrid(array(), $arrData); //end grid parameters return $contenidoModulo; }
function _moduleContent(&$smarty, $module_name) { include_once "libs/paloSantoDB.class.php"; include_once "libs/paloSantoGrid.class.php"; include_once "libs/paloSantoACL.class.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); /////conexion a php $pDB = new paloDB($arrConf['elastix_dsn']['acl']); //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']; if (!empty($pDB->errMsg)) { echo "ERROR DE DB: {$pDB->errMsg} <br>"; } $arrData = array(); $pACL = new paloACL($pDB); if (!empty($pACL->errMsg)) { echo "ERROR DE ACL: {$pACL->errMsg} <br>"; } $arrFormElements = array("description" => array("LABEL" => _tr("Description"), "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "group" => array("LABEL" => _tr("Group"), "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "")); //description id name $contenidoModulo = ""; $smarty->assign("REQUIRED_FIELD", _tr("Required field")); $smarty->assign("CANCEL", _tr("Cancel")); $smarty->assign("APPLY_CHANGES", _tr("Apply changes")); $smarty->assign("SAVE", _tr("Save")); $smarty->assign("EDIT", _tr("Edit")); $smarty->assign("DELETE", _tr("Delete")); $smarty->assign("icon", "modules/{$module_name}/images/system_groups.png"); $smarty->assign("CONFIRM_CONTINUE", _tr("Are you sure you wish to continue?")); if (isset($_POST['submit_create_group'])) { // Implementar include_once "libs/paloSantoForm.class.php"; $arrFillGroup['group'] = ''; $arrFillGroup['description'] = ''; $oForm = new paloForm($smarty, $arrFormElements); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/grouplist.tpl", _tr("New Group"), $arrFillGroup); } else { if (isset($_POST['edit'])) { // Tengo que recuperar la data del usuario $pACL = new paloACL($pDB); $arrGroup = $pACL->getGroups($_POST['id_group']); if (!is_array($arrGroup)) { $contenidoModulo = ''; Header("Location: ?menu={$module_name}"); } else { if ($arrGroup[0][1] == 'administrator') { $arrGroup[0][1] = _tr('administrator'); } else { if ($arrGroup[0][1] == 'operator') { $arrGroup[0][1] = _tr('operator'); } else { if ($arrGroup[0][1] == 'extension') { $arrGroup[0][1] = _tr('extension'); } } } if ($arrGroup[0][2] == 'total access') { $arrGroup[0][2] = _tr('total access'); } else { if ($arrGroup[0][2] == 'operator') { $arrGroup[0][2] = _tr('operator'); } else { if ($arrGroup[0][2] == 'extension user') { $arrGroup[0][2] = _tr('extension user'); } } } $arrFillGroup['group'] = $arrGroup[0][1]; $arrFillGroup['description'] = $arrGroup[0][2]; // Implementar include_once "libs/paloSantoForm.class.php"; $oForm = new paloForm($smarty, $arrFormElements); $oForm->setEditMode(); $smarty->assign("id_group", htmlspecialchars($_POST['id_group'], ENT_COMPAT, 'UTF-8')); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/grouplist.tpl", _tr('Edit Group') . " \"" . $arrFillGroup['group'] . "\"", $arrFillGroup); } } else { if (isset($_POST['submit_save_group'])) { include_once "libs/paloSantoForm.class.php"; $oForm = new paloForm($smarty, $arrFormElements); if ($oForm->validateForm($_POST)) { // Exito, puedo procesar los datos ahora. $pACL = new paloACL($pDB); // Creo el Grupo $pACL->createGroup($_POST['group'], $_POST['description']); if (!empty($pACL->errMsg)) { // Ocurrio algun error aqui $smarty->assign("mb_message", "ERROR: {$pACL->errMsg}"); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/grouplist.tpl", _tr("New Group"), $_POST); } else { header("Location: ?menu=grouplist"); } } else { // Error $smarty->assign("mb_title", _tr("Validation Error")); $arrErrores = $oForm->arrErroresValidacion; $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br>"; foreach ($arrErrores as $k => $v) { $strErrorMsg .= "{$k}, "; } $strErrorMsg .= ""; $smarty->assign("mb_message", $strErrorMsg); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/grouplist.tpl", _tr("New Group"), $_POST); } } else { if (isset($_POST['submit_apply_changes'])) { $arrGroup = $pACL->getGroups($_POST['id_group']); if (!is_array($arrGroup)) { $contenidoModulo = ''; Header("Location: ?menu={$module_name}"); } else { $group = $arrGroup[0][1]; $description = $arrGroup[0][2]; include_once "libs/paloSantoForm.class.php"; $oForm = new paloForm($smarty, $arrFormElements); $oForm->setEditMode(); if ($oForm->validateForm($_POST)) { // Exito, puedo procesar los datos ahora. $pACL = new paloACL($pDB); if (!$pACL->updateGroup($_POST['id_group'], $_POST['group'], $_POST['description'])) { // Ocurrio algun error aqui $smarty->assign("mb_message", "ERROR: {$pACL->errMsg}"); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/grouplist.tpl", _tr("Edit Group"), $_POST); } else { header("Location: ?menu=grouplist"); } } else { // Manejo de Error $smarty->assign("mb_title", _tr("Validation Error")); $arrErrores = $oForm->arrErroresValidacion; $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br>"; foreach ($arrErrores as $k => $v) { $strErrorMsg .= "{$k}, "; } $strErrorMsg .= ""; $smarty->assign("mb_message", $strErrorMsg); $arrFillGroup['group'] = $_POST['group']; $arrFillGroup['description'] = $_POST['description']; $smarty->assign("id_group", htmlspecialchars($_POST['id_group'], ENT_COMPAT, 'UTF-8')); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/grouplist.tpl", _tr("Edit Group"), $arrFillGroup); } } } else { if (isset($_GET['action']) && $_GET['action'] == "view") { include_once "libs/paloSantoForm.class.php"; $oForm = new paloForm($smarty, $arrFormElements); //- TODO: Tengo que validar que el id sea valido, si no es valido muestro un mensaje de error $oForm->setViewMode(); // Esto es para activar el modo "preview" $arrGroup = $pACL->getGroups($_GET['id']); if (!is_array($arrGroup)) { $contenidoModulo = ''; Header("Location: ?menu={$module_name}"); } else { // Conversion de formato if ($arrGroup[0][1] == 'administrator') { $arrGroup[0][1] = _tr('administrator'); } else { if ($arrGroup[0][1] == 'operator') { $arrGroup[0][1] = _tr('operator'); } else { if ($arrGroup[0][1] == 'extension') { $arrGroup[0][1] = _tr('extension'); } } } if ($arrGroup[0][2] == 'total access') { $arrGroup[0][2] = _tr('total access'); } else { if ($arrGroup[0][2] == 'operator') { $arrGroup[0][2] = _tr('operator'); } else { if ($arrGroup[0][2] == 'extension user') { $arrGroup[0][2] = _tr('extension user'); } } } $arrTmp['group'] = $arrGroup[0][1]; $arrTmp['description'] = $arrGroup[0][2]; $smarty->assign("id_group", htmlspecialchars($_GET['id'], ENT_COMPAT, 'UTF-8')); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/grouplist.tpl", _tr("View Group"), $arrTmp); // hay que pasar el arreglo } } else { if (isset($_POST['delete'])) { //- TODO: Validar el id de group if (isset($_POST['id_group']) && $_POST['id_group'] == '1') { // No se puede eliminar al grupo admin $smarty->assign("mb_message", _tr("The administrator group cannot be deleted because is the default Elastix Group. You can delete any other group.")); } else { if ($pACL->HaveUsersTheGroup($_POST['id_group']) == TRUE) { $smarty->assign("mb_message", _tr("The Group have users assigned. You can delete any group that does not have any users assigned in it.")); } else { $pACL->deleteGroup($_POST['id_group']); } } } $nav = getParameter("nav"); $start = getParameter("start"); $total = $pACL->getNumGroups(); $total = $total == NULL ? 0 : $total; $limit = 20; $oGrid = new paloSantoGrid($smarty); $oGrid->setLimit($limit); $oGrid->setTotal($total); $oGrid->pagingShow(true); $oGrid->setURL("?menu=grouplist"); $offset = $oGrid->calculateOffset(); $end = $oGrid->getEnd(); $arrGroups = $pACL->getGroupsPaging($limit, $offset); $end = count($arrGroups); $arrData = array(); foreach ($arrGroups as $group) { $arrTmp = array(); if ($group[1] == 'administrator') { $group[1] = _tr('administrator'); } else { if ($group[1] == 'operator') { $group[1] = _tr('operator'); } else { if ($group[1] == 'extension') { $group[1] = _tr('extension'); } } } if ($group[2] == 'total access') { $group[2] = _tr('total access'); } else { if ($group[2] == 'operator') { $group[2] = _tr('operator'); } else { if ($group[2] == 'extension user') { $group[2] = _tr('extension user'); } } } $arrTmp[0] = " <a href='?menu=grouplist&action=view&id=" . $group[0] . "'>" . $group[1] . "</a>"; //id_group name $arrTmp[1] = $group[2]; //description $arrData[] = $arrTmp; } $arrGrid = array("title" => _tr("Group List"), "icon" => "/modules/{$module_name}/images/system_groups.png", "columns" => array(0 => array("name" => _tr("Group"), "property1" => ""), 1 => array("name" => _tr("Description"), "property1" => ""))); $oGrid->addNew("submit_create_group", _tr("Create New Group")); $contenidoModulo = $oGrid->fetchGrid($arrGrid, $arrData); } } } } } return $contenidoModulo; }
function _moduleContent(&$smarty, $module_name) { include_once "libs/paloSantoDB.class.php"; include_once "libs/paloSantoConfig.class.php"; include_once "libs/paloSantoGrid.class.php"; include_once "libs/paloSantoACL.class.php"; 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); //conexion acl.db $pDB = new paloDB($arrConf['elastix_dsn']['acl']); //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']; $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"; $pDBa = new paloDB($dsn); //////////////////// if (!empty($pDB->errMsg)) { echo "ERROR DE DB: {$pDB->errMsg} <br>"; } $arrData = array(); $arrData[""] = $arrLang["no extension"]; $pACL = new paloACL($pDB); if (!empty($pACL->errMsg)) { echo "ERROR DE ACL: {$pACL->errMsg} <br>"; } /*******/ $typeUser = ""; $userLevel1 = ""; $extOther = ""; $userAccount = isset($_SESSION['elastix_user']) ? $_SESSION['elastix_user'] : ""; $idUserAccount = $pACL->isUserAdministratorGroup($userAccount); $idUserInt = $pACL->getIdUser($userAccount); if ($idUserAccount) { $userLevel1 = "admin"; } else { $userLevel1 = "other"; } $smarty->assign("userLevel1", $userLevel1); /*******/ $sQuery = "select extension from users order by extension;"; $arrayResult = $pDBa->fetchTable($sQuery, true); if (!$arrayResult) { $error = $pDBa->errMsg; } else { if (is_array($arrayResult) && count($arrayResult) > 0) { //$arrData[$item["null"]] = "No extension"; if ($idUserAccount) { foreach ($arrayResult as $item) { $arrData[$item["extension"]] = $item["extension"]; } } else { $idOther = $pACL->getIdUser($userAccount); $arrUserOther = $pACL->getUsers($idOther); $extOther = $arrUserOther[0][3]; $arrData[$extOther] = $extOther; } } } $arrGruposACL = $pACL->getGroups(); for ($i = 0; $i < count($arrGruposACL); $i++) { if ($arrGruposACL[$i][1] == 'administrator') { $arrGruposACL[$i][1] = $arrLang['administrator']; } else { if ($arrGruposACL[$i][1] == 'operator') { $arrGruposACL[$i][1] = $arrLang['operator']; } else { if ($arrGruposACL[$i][1] == 'extension') { $arrGruposACL[$i][1] = $arrLang['extension']; } } } if ($idUserAccount) { $arrGrupos[$arrGruposACL[$i][0]] = $arrGruposACL[$i][1]; } else { $arrUserPer = $pACL->getMembership($idUserInt); foreach ($arrUserPer as $key => $value) { if ($arrGruposACL[$i][1] == $key) { $arrGrupos[$arrGruposACL[$i][0]] = $arrGruposACL[$i][1]; } } } } $arrFormElements = array("description" => array("LABEL" => "{$arrLang['Name']} {$arrLang['(Ex. John Doe)']}", "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "name" => array("LABEL" => $arrLang["Login"], "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "", "EDITABLE" => "no"), "password1" => array("LABEL" => $arrLang["Password"], "REQUIRED" => "yes", "INPUT_TYPE" => "PASSWORD", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "password2" => array("LABEL" => $arrLang["Retype password"], "REQUIRED" => "yes", "INPUT_TYPE" => "PASSWORD", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "group" => array("LABEL" => $arrLang["Group"], "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrGrupos, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "extension" => array("LABEL" => $arrLang["Extension"], "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrData, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "webmailpassword1" => array("LABEL" => $arrLang["Webmail Password"], "REQUIRED" => "no", "INPUT_TYPE" => "PASSWORD", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "webmailuser" => array("LABEL" => $arrLang["Webmail User"], "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "webmaildomain" => array("LABEL" => $arrLang["Webmail Domain"], "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "")); $contenidoModulo = ""; $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]); $smarty->assign("CANCEL", $arrLang["Cancel"]); $smarty->assign("APPLY_CHANGES", $arrLang["Apply changes"]); $smarty->assign("SAVE", $arrLang["Save"]); $smarty->assign("EDIT", $arrLang["Edit"]); $smarty->assign("DELETE", $arrLang["Delete"]); $smarty->assign("CONFIRM_CONTINUE", $arrLang["Are you sure you wish to continue?"]); $smarty->assign("icon", "images/user.png"); $smarty->assign("title_webmail", $arrLang["Mail Profile"]); if (isset($_POST['submit_create_user'])) { // Implementar include_once "libs/paloSantoForm.class.php"; $arrFillUser['description'] = ''; $arrFillUser['name'] = ''; $arrFillUser['group'] = ''; $arrFillUser['extension'] = ''; $arrFillUser['password1'] = ''; $arrFillUser['password2'] = ''; $oForm = new paloForm($smarty, $arrFormElements); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["New User"], $arrFillUser); } else { if (!is_null(getParameter("edit"))) { $contenidoModulo = editUser($userAccount, $pACL, $pDB, $arrFormElements, $smarty, $local_templates_dir, $arrLang, $idUserAccount, $userLevel1); } else { if (isset($_POST['submit_save_user'])) { include_once "libs/paloSantoForm.class.php"; $oForm = new paloForm($smarty, $arrFormElements); if ($oForm->validateForm($_POST)) { // Exito, puedo procesar los datos ahora. $pACL = new paloACL($pDB); if (empty($_POST['password1']) or $_POST['password1'] != $_POST['password2']) { // Error claves $smarty->assign("mb_message", $arrLang["The passwords are empty or don't match"]); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["New User"], $_POST); } else { if ($userLevel1 == "admin") { // Creo al usuario $md5_password = md5($_POST['password1']); $pACL->createUser($_POST['name'], $_POST['description'], $md5_password, $_POST['extension']); $idUser = $pACL->getIdUser($_POST['name']); // Versiones viejas del archivo acl.db tienen una fila con una // tupla que asocia al usuario inexistente con ID 2, con el // grupo 2 (Operadores). Se limpia cualquier membresía extraña. $listaMembresia = $pACL->getMembership($idUser); if (is_array($listaMembresia) && count($listaMembresia) > 0) { foreach ($listaMembresia as $idGrupo) { $pACL->delFromGroup($idUser, $idGrupo); } } // Creo la membresia $pACL->addToGroup($idUser, $_POST['group']); $bExito = TRUE; if (empty($pACL->errMsg)) { $nuevasPropiedades = array(); if (!empty($_POST['webmailuser'])) { $nuevasPropiedades['login'] = $_POST['webmailuser']; } if (!empty($_POST['webmailpassword1'])) { $nuevasPropiedades['password'] = $_POST['webmailpassword1']; } if (!empty($_POST['webmaildomain'])) { $nuevasPropiedades['domain'] = $_POST['webmaildomain']; } $bExito = actualizarPropiedades($pDB, $smarty, $idUser, 'webmail', 'default', $nuevasPropiedades); } if (!empty($pACL->errMsg)) { // Ocurrio algun error aqui $smarty->assign("mb_message", "ERROR: {$pACL->errMsg}"); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["New User"], $_POST); } else { if ($bExito) { header("Location: ?menu=userlist"); } } } else { $smarty->assign("mb_message", $arrLang["userNoAllowed"]); } } } else { // Error $smarty->assign("mb_title", $arrLang["Validation Error"]); $arrErrores = $oForm->arrErroresValidacion; $strErrorMsg = "<b>{$arrLang['The following fields contain errors']}:</b><br>"; foreach ($arrErrores as $k => $v) { $strErrorMsg .= "{$k}, "; } $strErrorMsg .= ""; $smarty->assign("mb_message", $strErrorMsg); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["New User"], $_POST); } } else { if (isset($_POST['submit_apply_changes'])) { $arrayContent = applyChanges($userAccount, $pACL, $smarty, $arrLang, $idUserAccount, $userLevel1, $arrFormElements, $pDB, $local_templates_dir, $idUserInt, $extOther); if (isset($arrayContent["mb_title"]) && isset($arrayContent["mb_message"])) { $smarty->assign("mb_title", $arrayContent["mb_title"]); $smarty->assign("mb_message", $arrayContent["mb_message"]); } if ($arrayContent["success"]) { header("Location: ?menu=userlist"); } else { if (isset($arrayContent["id_user"])) { $smarty->assign("id_user", $_POST['id_user']); } if (isset($arrayContent["fill_user"])) { $contenidoModulo = $arrayContent["form"]->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["Edit User"], $arrayContent["fill_user"]); } else { $contenidoModulo = $arrayContent["content"]; } } } else { if (isset($_GET['action']) && $_GET['action'] == "view") { if (!$pACL->isUserAdministratorGroup($userAccount)) { if ($pACL->getIdUser($userAccount) != $_GET['id']) { $smarty->assign("mb_title", $arrLang["ERROR"]); $smarty->assign("mb_message", $arrLang["You are not authorized to access to information of that user"]); return reportUserList($arrLang, $pACL, $idUserAccount, $smarty, $userLevel1, $userAccount); } } include_once "libs/paloSantoForm.class.php"; $oForm = new paloForm($smarty, $arrFormElements); //- TODO: Tengo que validar que el id sea valido, si no es valido muestro un mensaje de error $oForm->setViewMode(); // Esto es para activar el modo "preview" $arrUser = $pACL->getUsers($_GET['id']); // Conversion de formato $arrTmp['name'] = $arrUser[0][1]; $arrTmp['description'] = $arrUser[0][2]; $arrTmp['password1'] = "****"; $arrTmp['password2'] = "****"; $arrTmp['extension'] = $arrUser[0][3]; //- TODO: Falta llenar el grupo $arrMembership = $pACL->getMembership($_GET['id']); $id_group = ""; if (is_array($arrMembership)) { foreach ($arrMembership as $groupName => $groupId) { $id_group = $groupId; // Asumo que cada usuario solo puede pertenecer a un grupo break; } } $arrTmp['group'] = $id_group; $listaPropiedades = leerPropiedadesWebmail($pDB, $smarty, $_GET['id']); if (isset($listaPropiedades['login'])) { $arrTmp['webmailuser'] = $listaPropiedades['login']; } if (isset($listaPropiedades['domain'])) { $arrTmp['webmaildomain'] = $listaPropiedades['domain']; } if (isset($listaPropiedades['password'])) { $arrTmp['webmailpassword1'] = '****'; } //if (isset($listaPropiedades['imapsvr'])) $arrTmp['webmailimapsvr'] = $listaPropiedades['imapsvr']; $smarty->assign("id_user", $_GET['id']); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", $arrLang["View User"], $arrTmp); // hay que pasar el arreglo } else { if (getParameter('action') == "edit_userExtension") { $smarty->assign("editUserExtension", "yes"); $html = editUser($userAccount, $pACL, $pDB, $arrFormElements, $smarty, $local_templates_dir, $arrLang, $idUserAccount, $userLevel1); $smarty->assign("CONTENT", $html); $smarty->assign("THEMENAME", $arrConf['mainTheme']); $smarty->assign("MODULE_NAME", $module_name); $smarty->assign("path", ""); $contenidoModulo = $smarty->display("{$local_templates_dir}/edit_userExtension.tpl"); } else { if (getParameter('action') == "apply_changes_UserExtension") { include_once "libs/paloSantoJSON.class.php"; $jsonObject = new PaloSantoJSON(); $result = applyChanges($userAccount, $pACL, $smarty, $arrLang, $idUserAccount, $userLevel1, $arrFormElements, $pDB, $local_templates_dir, $idUserInt, $extOther); $arrMessage["mb_title"] = isset($result["mb_title"]) ? $result["mb_title"] : null; $arrMessage["mb_message"] = isset($result["mb_message"]) ? $result["mb_message"] : null; $arrMessage["success"] = $result["success"]; $jsonObject->set_message($arrMessage); $contenidoModulo = $jsonObject->createJSON(); } else { $contenidoModulo = reportUserList($arrLang, $pACL, $idUserAccount, $smarty, $userLevel1, $userAccount); } } } } } } } return $contenidoModulo; }