Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
freedom_modaccess.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Generated Header (not documented yet)
8  *
9  * @author Anakeen
10  * @version $Id: freedom_modaccess.php,v 1.15 2008/10/22 16:14:42 eric Exp $
11  * @package FDL
12  * @subpackage GED
13  */
14 /**
15  */
16 // ---------------------------------------------------------------
17 // $Id: freedom_modaccess.php,v 1.15 2008/10/22 16:14:42 eric Exp $
18 // $Source: /home/cvsroot/anakeen/freedom/freedom/Action/Freedom/freedom_modaccess.php,v $
19 // ---------------------------------------------------------------
20 include_once ("FDL/Class.Doc.php");
21 include_once ("FDL/Lib.Dir.php");
22 // -----------------------------------
24 {
25  // -----------------------------------
26  global $_SERVER;
27  // get all parameters
28 
29  /*
30  * @var array $acls
31  */
32  $acls = $action->getArgument("acls", array());
33  $docid = $action->getArgument("docid"); // id for controlled object
34  $dbaccess = $action->dbaccess;
35 
37  // test if current user can modify ACL
38  $err = $doc->Control("modifyacl");
39  if ($err != "") $action->exitError($err);
40 
41  $before = array();
42  $after = array();
43 
44  if (count($acls) > 0) {
45 
46  foreach ($acls as $userid => $aclon) {
47  // modif permission for a particular user
48  $perm = new DocPerm($dbaccess, array(
49  $docid,
50  $userid
51  ));
52 
53  $before[$userid] = getUserAclNames($doc, $userid);
54 
55  $doc->removeControl($userid);
56  foreach ($aclon as $k => $aclName) {
57 
58  $doc->addControl($userid, $aclName);
59  }
60 
61  $after[$userid] = getUserAclNames($doc, $userid);
62  }
63  if ($err != "") $action->exitError($err);
64 
65  $doc->setViewProfil();
66  // recompute all related profile
67  $doc->recomputeProfiledDocument();
68  //-------------------------------
69  // compose history
70  //** find username
71  $tuid = array();
72  foreach ($acls as $userid => $aclon) {
73  $tuid[] = $userid;
74  }
75  $q = new QueryDb("", "Account");
76  $q->AddQuery(getsqlcond($tuid, "id"));
77  $l = $q->Query(0, 0, "TABLE");
78 
79  $tuname = array();
80  if ($q->nb > 0) {
81  foreach ($l as $k => $v) {
82  $tuname[$v["id"]] = $v["firstname"] . ' ' . $v["lastname"];
83  }
84  }
85 
86  $q = new QueryDb("", "Vgroup");
87  $q->AddQuery(getsqlcond($tuid, "num"));
88  $l = $q->Query(0, 0, "TABLE");
89  if ($q->nb > 0) {
90  foreach ($l as $k => $v) {
91  $tuname[$v["num"]] = sprintf(_("attribute %s") , $v["id"]);
92  }
93  }
94  $tc = array();
95  $posacls = array();
96  foreach ($doc->dacls as $k => $v) {
97  $posacls[$k] = $v["pos"];
98  }
99 
100  foreach ($before as $uid => $acls) {
101 
102  $tadd = array();
103  $tdel = array();
104  foreach ($acls as $aclName => $granted) {
105  if (($before[$uid][$aclName] === true) && ($after[$uid][$aclName] === false)) {
106  $tdel[] = $aclName;
107  } elseif (($before[$uid][$aclName] === false) && ($after[$uid][$aclName] === true)) {
108  $tadd[] = $aclName;
109  }
110  }
111 
112  if (count($tadd) > 0) $tc[] = sprintf(_("Add acl %s for %s") , implode(", ", $tadd) , $tuname[$uid]);
113  if (count($tdel) > 0) $tc[] = sprintf(_("Delete acl %s for %s") , implode(", ", $tdel) , $tuname[$uid]);
114  }
115  if (count($tc) > 0) $doc->addHistoryEntry(sprintf(_("Change control :\n %s") , implode("\n", $tc)));
116  }
117  redirect($action, "FREEDOM", sprintf("FREEDOM_GACCESS&id=%s&allgreen=%s&group=%s", $docid, $action->getArgument("allgreen", "N") , $action->getArgument("group", "N")));
118 }
119 
120 function getUserAclNames(Doc & $doc, $userid)
121 {
122  $uperm = DocPerm::getUperm($doc->id, $userid, true);
123  $doc->userid = $userid;
124  $grant = array();
125  foreach ($doc->acls as $aclName) {
126  if ($doc->isExtendedAcl($aclName)) $grant[$aclName] = ($doc->controlExtId($doc->id, $aclName, true) == '');
127  else $grant[$aclName] = ($doc->controlUp($uperm, $aclName) == '');
128  }
129  return ($grant);
130 }
global $action
controlUp($uperm, $aclname)
exitError($texterr, $exit=true, $code="")
static getUperm($profid, $userid, $strict=false)
$docid
Definition: cleanFamily.php:13
getUserAclNames(Doc &$doc, $userid)
freedom_modaccess(Action &$action)
global $_SERVER
controlExtId($docid, $aclname, $strict=false)
new_Doc($dbaccess, $id= '', $latest=false)
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
isExtendedAcl($aclname)
← centre documentaire © anakeen