Beispiel #1
0
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;
}
Beispiel #2
0
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);
}
Beispiel #3
0
function viewFormUser($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials)
{
    $pACL = new paloACL($pDB);
    $pORGZ = new paloSantoOrganization($pDB);
    $arrFill = array();
    $action = getParameter("action");
    $arrOrgz = array(0 => "Select one Organization");
    if ($credentials["userlevel"] == "superadmin") {
        $orgTmp = $pORGZ->getOrganization(array());
    } else {
        $orgTmp = $pORGZ->getOrganization(array("id" => $credentials["id_organization"]));
    }
    if ($orgTmp === false) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr($pORGZ->errMsg));
        return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } elseif (count($orgTmp) == 0) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("You need yo have at least one organization created before you can create a user"));
        return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } else {
        if (($action == "new_user" || $action == "save_new") && count($orgTmp) <= 1) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("It's necesary you create a new organization so you can create new user"));
            return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        }
        foreach ($orgTmp as $value) {
            $arrOrgz[$value["id"]] = $value["name"];
            $arrDomains[$value["id"]] = $value["domain"];
        }
        $smarty->assign("ORGANIZATION", htmlentities($orgTmp[0]["name"], ENT_COMPAT, 'UTF-8'));
    }
    $idUser = getParameter("id");
    $arrFill = $_POST;
    if ($action == "view" || getParameter("edit") || getParameter("save_edit")) {
        if (!isset($idUser)) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("Invalid User"));
            return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        } else {
            if ($credentials["userlevel"] == "superadmin") {
                $arrUsers = $pACL->getUsers($idUser);
            } else {
                $arrUsers = $pACL->getUsers($idUser, $credentials["id_organization"], null, null);
            }
        }
        if ($arrUsers === false) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr($pACL->errMsg));
            return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        } else {
            if (count($arrUsers) == 0) {
                $smarty->assign("mb_title", _tr("ERROR"));
                $smarty->assign("mb_message", _tr("User doesn't exist"));
                return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
            } else {
                $picture = $pACL->getUserPicture($idUser);
                if ($picture !== false) {
                    $smarty->assign("ShowImg", 1);
                }
                foreach ($arrUsers as $value) {
                    $arrFill["username"] = $value[1];
                    $arrFill["name"] = $value[2];
                    $arrFill["password1"] = "";
                    $arrFill["password2"] = "";
                    $arrFill["organization"] = $value[4];
                    $arrFill["group"] = $value[7];
                    $extu = isset($value[5]) ? $value[5] : _tr("Not assigned yet");
                    $extf = isset($value[6]) ? $value[6] : _tr("Not assigned yet");
                    $arrFill["extension"] = $extu;
                    $arrFill["fax_extension"] = $extf;
                }
                if ($arrFill["organization"] != 1) {
                    $smarty->assign("ORGANIZATION", htmlentities($arrOrgz[$arrFill["organization"]], ENT_COMPAT, 'UTF-8'));
                }
                $smarty->assign("USERNAME", $arrFill["username"]);
                $nGroup = $pACL->getGroupNameByid($arrFill["group"]);
                if ($nGroup == "superadmin") {
                }
                $nGroup = _tr("NONE");
                $smarty->assign("GROUP", $nGroup);
                $_POST["organization"] = $arrFill["organization"];
                //ahora obtenemos las configuraciones de fax dle usuario
                $pFax = new paloFax($pACL->_DB);
                $listFaxs = $pFax->getFaxList(array("exten" => $extf, "organization_domain" => $arrDomains[$arrFill["organization"]]));
                if ($listFaxs != false) {
                    $faxUser = $listFaxs[0];
                    $arrFill["country_code"] = $faxUser["country_code"];
                    $arrFill["area_code"] = $faxUser["area_code"];
                    $arrFill["clid_number"] = $faxUser["clid_number"];
                    $arrFill["clid_name"] = $faxUser["clid_name"];
                }
                //ahora obtenemos la cuenta del email
                $arrFill["email_quota"] = $pACL->getUserProp($idUser, "email_quota");
                if ($idUser == "1") {
                    $arrFill["email_contact"] = $pACL->getUserProp($idUser, "email_contact");
                }
                $smarty->assign("EMAILQOUTA", $arrFill["email_quota"]);
                $smarty->assign("EXTENSION", $extu);
                $smarty->assign("FAX_EXTENSION", $extf);
                if (getParameter("save_edit")) {
                    $arrFill = $_POST;
                }
            }
        }
    }
    if ($credentials["userlevel"] != "superadmin") {
        $idOrgSel = $credentials["id_organization"];
    } else {
        $idOrgSel = getParameter("organization");
    }
    if (!isset($idOrgSel)) {
        $idOrgSel = 0;
    }
    if ($idOrgSel == 0) {
        $arrGrupos = array();
    } else {
        $temp = $pACL->getGroupsPaging(null, null, $idOrgSel);
        if ($temp === false) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr($pACL->errMsg));
            return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
        }
        foreach ($temp as $value) {
            $arrGrupos[$value[0]] = $value[1];
        }
    }
    if (getParameter("create_user")) {
        $arrFill["country_code"] = $pORGZ->getOrganizationProp($idOrgSel, "country_code");
        $arrFill["area_code"] = $pORGZ->getOrganizationProp($idOrgSel, "area_code");
        $arrFill["email_quota"] = $pORGZ->getOrganizationProp($idOrgSel, "email_quota");
    }
    $arrFormOrgz = createFieldForm($arrGrupos, $arrOrgz);
    $oForm = new paloForm($smarty, $arrFormOrgz);
    $smarty->assign("HEIGHT", "310px");
    $smarty->assign("MARGIN_PIC", 'style="margin-top: 40px;"');
    $smarty->assign("MARGIN_TAB", "");
    if ($action == "view") {
        $smarty->assign("HEIGHT", "220px");
        $smarty->assign("MARGIN_PIC", "");
        $smarty->assign("MARGIN_TAB", "margin-top: 10px;");
        $oForm->setViewMode();
        $arrFill["password1"] = "*****";
        $arrFill["password2"] = "*****";
        $smarty->assign("HEIGHT", "220px");
    } else {
        if (getParameter("edit") || getParameter("save_edit")) {
            $oForm->setEditMode();
        }
    }
    global $arrPermission;
    if (in_array('create_user', $arrPermission)) {
        $smarty->assign("CREATE_USER", true);
    }
    if (in_array('edit_user', $arrPermission)) {
        $smarty->assign("EDIT_USER", true);
    }
    if (in_array('delete_user', $arrPermission)) {
        $smarty->assign("DEL_USER", true);
    }
    $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("CONFIRM_CONTINUE", _tr("Are you sure you wish to continue?"));
    $smarty->assign("icon", "../web/_common/images/user_info.png");
    $smarty->assign("FAX_SETTINGS", _tr("Fax Settings"));
    $smarty->assign("EMAIL_SETTINGS", _tr("Email Settings"));
    $smarty->assign("MODULE_NAME", $module_name);
    $smarty->assign("userLevel", $credentials["userlevel"]);
    $smarty->assign("id_user", $idUser);
    if (isset($arrUsers[0][1])) {
        $smarty->assign("isSuperAdmin", $pACL->isUserSuperAdmin($arrUsers[0][1]));
    } else {
        $smarty->assign("isSuperAdmin", FALSE);
    }
    $htmlForm = $oForm->fetchForm("{$local_templates_dir}/new.tpl", _tr("User"), $arrFill);
    $content = "<form  method='POST' enctype='multipart/form-data' style='margin-bottom:0;' action='?menu={$module_name}'>" . $htmlForm . "</form>";
    return $content;
}