19 include_once (
'Class.DbObj.php');
20 include_once (
'Class.QueryDb.php');
21 include_once (
'Class.Application.php');
22 include_once (
'Class.Action.php');
23 include_once (
'Class.Acl.php');
24 include_once (
'Class.User.php');
25 include_once (
'Class.Group.php');
43 private $upprivileges =
false;
44 private $unprivileges =
false;
45 private $gprivileges =
false;
47 create table permission (id_user int not null,
48 id_application int not null,
50 computed boolean default false);
51 create index permission_idx1 on permission(id_user);
52 create index permission_idx2 on permission(id_application);
53 create index permission_idx3 on permission(id_acl);
54 create index permission_idx4 on permission(computed);
66 "id_application" =>
$id[1],
93 if ($this->
Exists($this->id_user, $this->id_application, $this->id_acl))
return "Permission ({$this->id_user},{$this->id_application},{$this->id_acl}) already exists...";
99 if (!$this->computed) {
100 $this->
exec_query(sprintf(
"delete from permission where id_application=%d and abs(id_acl)=%d and computed", $this->id_application, $this->id_acl));
109 $query->basic_elem->sup_where = array(
110 "id_user='{$user->id}'",
111 "id_application='{app->id}'"
116 while ($i < $query->nb) {
126 $query->basic_elem->sup_where = array(
127 "id_user='{$user->id}'"
133 while ($i < $query->nb) {
134 $this->log->debug(
"ListUserApplicaion");
144 $query->basic_elem->sup_where = array(
145 "id_application='{$app->id}'"
151 while ($i < $query->nb) {
158 function Exists($userid, $applicationid, $aclid = 0)
161 $query->basic_elem->sup_where = array(
162 "id_application='$applicationid'",
163 "id_user='{$userid}'",
164 "( computed = FALSE OR computed IS NULL )"
168 $query->AddQuery(
"(id_acl={$aclid}) OR (id_acl= {$naclid}) ");
178 $query->basic_elem->sup_where = array(
179 "id_application='{$application->id}'",
180 "id_user='{$user->id}'"
183 if (
$query->nb == 0)
return FALSE;
184 $aclu =
new Acl($this->dbaccess,
$list[0]->id_acl);
185 return ($aclu->grant_level >= $acl->grant_level);
191 $query->basic_elem->sup_where = array(
192 "id_application='{$application->id}'",
193 "id_user='{$user->id}'"
196 if (
$query->nb == 0)
return (0);
197 $acl =
new Acl($this->dbaccess,
$list[0]->id_acl);
198 return ($acl->grant_level);
204 $query->basic_elem->sup_where = array(
208 $this->log->debug(
"DEL APP PERM");
210 while (list($k, $v) = each(
$list)) {
214 $this->log->debug(
"NO PERM");
222 if ($this->upprivileges ===
false) {
225 return $this->upprivileges;
232 if ($this->unprivileges ===
false) {
235 return $this->unprivileges;
242 if ($this->gprivileges ===
false) {
245 return $this->gprivileges;
253 $query->basic_elem->sup_where = array(
254 "id_application = '" . $appid .
"'"
258 foreach (
$res as $k => $v) {
270 $query->basic_elem->sup_where = array(
271 "id_application = '" . $appid .
"'",
272 "id_user = '" .
$uid .
"'",
275 $computedAcl = array();
279 while (list($k, $v) = each(
$list)) {
280 $computedAcl[abs($v->id_acl) ] = $v->id_acl;
284 foreach ($allAclList as $acl) {
285 if (!array_key_exists($acl, $computedAcl)) {
286 $computedAcl[abs($acl) ] = $this->
computePerm(
$uid, $appid, abs($acl));
289 return array_values($computedAcl);
298 $res =
$db->exec_query(sprintf(
"SELECT computePerm(%d, %d, %d)",
$uid, $appid, abs($acl)));
300 return $perm[
'computeperm'];
322 $this->privileges = array();
323 $this->upprivileges = array();
324 $this->unprivileges = array();
325 $this->gprivileges = array();
327 $ugroup =
new Group($this->dbaccess, $this->id_user);
329 while (list($k, $gid) = each($ugroup->groups)) {
331 $gperm =
new permission($this->dbaccess, array(
333 $this->id_application,
335 ) ,
'', 0, $computed);
337 while (list($k2, $gacl) = each($gperm->privileges)) {
338 if (!in_array($gacl, $this->privileges)) {
339 $this->gprivileges[] = $gacl;
340 $this->privileges[] = $gacl;
346 $query->basic_elem->sup_where = array(
347 "id_application='{$this->id_application}'",
348 "id_user='{$this->id_user}'",
349 (!$computed) ?
"( computed = FALSE OR computed IS NULL )" :
""
353 while (list($k, $v) = each(
$list)) {
354 if ($v->id_acl > 0) {
356 $this->upprivileges[] = $v->id_acl;
357 if (!in_array($v->id_acl, $this->privileges)) {
358 $this->privileges[] = $v->id_acl;
362 $this->unprivileges[] = - ($v->id_acl);
364 $nk = array_search(-($v->id_acl) , $this->privileges,
false);
365 if (is_integer($nk)) {
366 unset($this->privileges[$nk]);
372 return ($this->privileges);
377 return (($this->id_user == 1) ||
378 (in_array($idacl, $this->privileges)));
387 $this->id_application = $appid;
389 $acl =
new Acl($this->dbaccess);
390 if ($acl->Set($aclname, $this->id_application)) {
391 $this->id_acl = $acl->id;
405 $this->actions = array();
409 if (!count($acls))
return array();
411 $sSql =
" select distinct action.name from action inner join acl on
412 action.acl = acl.name where ";
413 $sSql.=
" action.id_application = '" . $this->id_application .
"' AND ";
414 $sSql.=
" acl.id in ('" . implode(
"','", $acls) .
"')";
416 $res = pg_exec($this->dbid, $sSql);
419 while ($arr = pg_fetch_array(
$res, $i)) {
420 $this->actions[] = $arr[0];
428 public function deletePermission($id_user = null, $id_application = null, $id_acl = null, $computed = null)
431 if ($id_user != null) {
432 $sqlCond[] = sprintf(
"( id_user = %d )", pg_escape_string($id_user));
434 if ($id_application != null) {
435 $sqlCond[] = sprintf(
"( id_application = %d )", pg_escape_string($id_application));
437 if ($id_acl != null) {
438 $sqlCond[] = sprintf(
"( abs(id_acl) = abs(%d) )", pg_escape_string($id_acl));
440 if ($computed != null) {
441 if ($computed =
true) {
442 $sqlCond[] =
"( computed = TRUE )";
444 $sqlCond[] =
"( computed = FALSE OR computed IS NULL )";
448 if (count($sqlCond) > 0) {
449 return $this->
exec_query(sprintf(
"DELETE FROM permission WHERE ( %s )", join(
" AND ", $sqlCond)));