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.
 
 
 
 
 
 

137 lines
4.8 KiB

<?php
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)
{
$org_id = GetOrganizacao();
$flagSystem = (IsAdmin() && IsLocalServer()) ? '1=1' : " gp_system = '0' ";
$query = "SELECT gp_id, gp_nome
FROM pbx_grupo g
WHERE $flagSystem and gp_status = 1
AND org_id = $org_id
ORDER BY gp_nome LIMIT 1";
//restricao se o usuario nao for admin
$result = pg_query($dbcon, $query);
$row = pg_fetch_array($result);
$codGp = $row["gp_id"];
$nomeGp = $row["gp_nome"];
}
function GetGrupo($dbcon, $codGp, $size = 1)
{
$org_id = GetOrganizacao();
$flagSystem = (IsAdmin() && IsLocalServer()) ? '1=1' : " gp_system = '0' ";
$idUser = GetIdUser();
$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 org_id = $org_id
AND gp_status = 1 ORDER BY 3,2";
$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)
{
$_SESSION["SStreRoot"] = GetLogin();
$_SESSION["SStreView"] = 1;
$_SESSION["SSperfilAcao"] = "add";
$idUser = GetIdUser();
$dadosMenu = MontaMenu(0, $idUser, 2, $notMenu, "add");
$dadosMenu = str_replace("MENU_ITEMS", "TREE_ITEMS", $dadosMenu);
$GLOBALS["jsBlok"][] = $dadosMenu;
$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 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 ";
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 ";
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;
}