You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

146 lines
6.0 KiB

<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
if (IsPostBack()) {
$dadosGrupo = Explode('|', $_POST["lstGrupo"]);
$codGp = $dadosGrupo[0];
$nomeGp = $dadosGrupo[1];
$_SESSION["lstGrupo"] = $codGp;
$_SESSION["nameGrupo"] = $nomeGp;
} else {
GetGrupoDef($dbcon, $codGp, $nomeGp, GetIdUser());
$_SESSION["lstGrupo"] = $codGp;
$_SESSION["nameGrupo"] = $nomeGp;
}
$codUser = 0;
$sizeUser = 12;
$sizeGpUser = 10;
$grupouser = "";
$cssBlock = "<style>
a, A:link, a:visited, a:active
{color: #0000aa; text-decoration: none; font-family: Tahoma, Verdana; font-size: 11px}
A:hover
{color: #ff0000; text-decoration: none; font-family: Tahoma, Verdana; font-size: 11px}
</style>";
$jsPage[] = "scriptApl/tree.js";
$jsPage[] = "scriptApl/tree_tpl_func.js";
$grupos = GetGrupo($dbcon, $codGp, 1);
$funcs = GetFunc($dbcon, $codGp, 1);
$smarty->assign("grupos", $grupos);
$smarty->assign("funcs", $funcs);
$smarty->assign("lstGrupo", $codGp);
$smarty->assign("nameGrupo", $nomeGp);
GetTemplate($smarty, 'seguranca/perfilGrupos.tpl');
function GetGrupoDef($dbcon, &$codGp, &$nomeGp, $idUser) {
$flagSystem = (IsAdmin() && IsLocalServer()) ? '1=1' : " gp_system = '0' ";
$query = "select gp_id, gp_nome from pbx_grupo g where $flagSystem and gp_status = 1 {REST} order by gp_nome limit 1";
//restricao se o usuario nao for admin
$query = strtoupper(GetLogin()) == "ADMIN" ? str_replace("{REST}", "", $query) : str_replace("{REST}", " and exists(select '' from pbx_grupo_usuario where gp_id = g.gp_id and user_id = $idUser)", $query);
$result = pg_query($dbcon, $query);
$row = pg_fetch_array($result);
$codGp = $row["gp_id"];
$nomeGp = $row["gp_nome"];
}
function GetGrupo($dbcon, $codGp, $size = 1) {
$flagSystem = (IsAdmin() && IsLocalServer()) ? '1=1' : " gp_system = '0' ";
$idUser = GetIdUser();
//$query = "select gp_id, gp_nome from pbx_grupo g where $flagSystem and gp_status = 1 {REST} order by 2";
$query = "select gp_id, case when(gp_system = 1)then (gp_nome || '#') else case when(user_id = 0)then gp_nome else (gp_nome || '**') end end gp_nome, case when(user_id = 0)then 0 else 1 end as ord from pbx_grupo g where $flagSystem and gp_status = 1 {REST} order by 3,2";
//restricao se o usuario nao for admin
$query = strtoupper(GetLogin()) == "ADMIN" ? str_replace("{REST}", "", $query) : str_replace("{REST}", " and exists(select '' from pbx_grupo_usuario where gp_id = g.gp_id and user_id = $idUser)", $query);
$result = @pg_query($dbcon, $query);
$sel = "";
$cont = 0;
$lista = "<select name=\"lstGrupo\" id=\"lstGrupo\" size=\"$size\" style=\"width:410px\" onchange=\"submit()\">\n";
while (($row = @pg_fetch_array($result))) {
$cod = $row["gp_id"];
$sel = ($codGp == $cod) ? "selected" : "";
$desc = $row["gp_nome"];
$lista .= "<option value=\"$cod|$desc\" $sel>$desc</option>\n";
$cont++;
}
$lista .= $cont ? "</select>" : "<option value=\"0\" selected>-</option>\n</select>\n";
return $lista;
}
function GetFunc($dbcon, $idGrupo, $notMenu = 0) {
//$dadosMenu = Menu($dbcon, QueryPerfilHead($idGrupo), QueryPerfilItens($idGrupo));
$_SESSION["SStreRoot"] = GetLogin();
$_SESSION["SStreView"] = 1;
$_SESSION["SSperfilAcao"] = "add";
$idUser = GetIdUser();
//$dadosMenu = Menu($dbcon, QueryMenuHead($idUser), QueryMenuItens($idUser, true));
$dadosMenu = MontaMenu(0, $idUser, 2, $notMenu, "add");
$dadosMenu = str_replace("MENU_ITEMS", "TREE_ITEMS", $dadosMenu);
$GLOBALS["jsBlok"][] = $dadosMenu;
/*
$menu = "<div class=\"menuGeral\" style=\"position:relative\">\n";
$menu .= "<script language=\"JavaScript\">\n";
$menu .= "<!--//\n";
$menu .= " new menu (TREE_ITEMS, MENU_TPL);\n";
$menu .= "//-->\n";
$menu .= "</script>\n";
$menu .= "</div>\n";
*/
$menu = "<div style=\"width:300px;height:800px;position:relative;\">\n";
$menu .= "<script language=\"JavaScript\">\n";
$menu .= "<!--//\n";
$menu .= " new tree (TREE_ITEMS, tree_tpl);\n";
$menu .= "//-->\n";
$menu .= "</script>\n";
$menu .= "</div>\n";
return $menu;
}
function GetGrupoFunc($dbcon, $idGrupo) {
return $lista;
}
function QueryPerfilHead($idGrupo) {
$idUser = GetIdUser();
$query = "select b.fun_id, b.fun_nome, b.fun_menu, b.fun_menu_text, b.fun_menu_url, b.fun_menu_img, b.fun_id_pai
from pbx_funcoes b
where coalesce(b.fun_id_pai, 0) = 0 ";
// and b.fun_id not in(select b.fun_id from pbx_grupo_funcoes a, pbx_funcoes b where b.fun_id = a.fun_id and a.gp_id = '$idGrupo') ";
if (!IsAdmin())
$query .= " and b.fun_id in(select gf.fun_id from pbx_grupo_funcoes gf, pbx_grupo_usuario gu where gf.gp_id = gu.gp_id and gu.user_id = '$idUser' order by 1) ";
$query .= "Union select b.fun_id, b.fun_nome, b.fun_menu, b.fun_menu_text, b.fun_menu_url, b.fun_menu_img, b.fun_id_pai
from pbx_funcoes b where coalesce(b.fun_id_pai, 0) = 0 and fun_public = 1";
$query .= " order by 1 ";
return $query;
}
function QueryPerfilItens($idGrupo) {
$idUser = GetIdUser();
$query = "select b.fun_id, b.fun_nome, b.fun_menu, b.fun_menu_text, b.fun_menu_url, b.fun_menu_img, b.fun_id_pai
from pbx_funcoes b
where coalesce(b.fun_id_pai, 0) > 0 ";
// and b.fun_id not in(select b.fun_id from pbx_grupo_funcoes a, pbx_funcoes b where b.fun_id = a.fun_id and a.gp_id = '$idGrupo') ";
if (!IsAdmin())
$query .= " and b.fun_id in(select gf.fun_id from pbx_grupo_funcoes gf, pbx_grupo_usuario gu where gf.gp_id = gu.gp_id and gu.user_id = '$idUser' order by 1) ";
$query .= " order by b.fun_id ";
return $query;
}
?>