Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Generated Header (not documented yet)
9  *
10  * @author Anakeen 2000
11  * @version $Id: freedom_modaccess.php,v 1.15 2008/10/22 16:14:42 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage GED
15  */
16 /**
17  */
18 // ---------------------------------------------------------------
19 // $Id: freedom_modaccess.php,v 1.15 2008/10/22 16:14:42 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/freedom/Action/Freedom/freedom_modaccess.php,v $
21 // ---------------------------------------------------------------
22 include_once ("FDL/Class.Doc.php");
23 include_once ("FDL/Lib.Dir.php");
24 // -----------------------------------
26 {
27  // -----------------------------------
28  global $_SERVER;
29  // get all parameters
30  $acls = GetHttpVars("acls", array());
31  $docid = GetHttpVars("docid"); // id for controlled object
32  $dbaccess = $action->GetParam("FREEDOM_DB");
33 
35  // test if current user can modify ACL
36  $err = $doc->Control("modifyacl");
37  if ($err != "") $action->exitError($err);
38 
39  $before = array();
40  $after = array();
41 
42  if (count($acls) > 0) {
43 
44  foreach ($acls as $userid => $aclon) {
45  // modif permission for a particular user
46  $perm = new DocPerm($dbaccess, array(
47  $docid,
48  $userid
49  ));
50 
51  $before[$userid] = array(
52  $perm->upacl,
53  $perm->unacl
54  );
55  $perm->UnsetControl();
56 
57  foreach ($aclon as $k => $pos) {
58  if (intval($pos) > 0) $perm->SetControlP($pos);
59  }
60  if ($perm->isAffected()) $err = $perm->modify();
61  else $err = $perm->Add();
62  if ($err != "") {
63  if ($perm->isAffected()) $err = $perm->delete();
64  }
65  $after[$userid] = array(
66  $perm->upacl,
67  $perm->unacl
68  );
69  }
70  if ($err != "") $action->exitError($err);
71  // recompute all related profile
72  $doc->recomputeProfiledDocument();
73  // find username
74  $tuid = array();
75  foreach ($acls as $userid => $aclon) {
76  $tuid[] = $userid;
77  }
78  $q = new QueryDb("", "User");
79  $q->AddQuery(getsqlcond($tuid, "id"));
80  $l = $q->Query(0, 0, "TABLE");
81 
82  $tuname = array();
83  if ($q->nb > 0) {
84  foreach ($l as $k => $v) {
85  $tuname[$v["id"]] = $v["firstname"] . ' ' . $v["lastname"];
86  }
87  }
88 
89  $q = new QueryDb("", "Vgroup");
90  $q->AddQuery(getsqlcond($tuid, "num"));
91  $l = $q->Query(0, 0, "TABLE");
92  if ($q->nb > 0) {
93  foreach ($l as $k => $v) {
94  $tuname[$v["num"]] = sprintf(_("attribute %s") , $v["id"]);
95  }
96  }
97  $tc = array();
98  $posacls = array();
99  foreach ($doc->dacls as $k => $v) {
100  $posacls[$k] = $v["pos"];
101  }
102 
103  foreach ($before as $k => $v) {
104  $a = $after[$k][0];
105  $b = $before[$k][0];
106  if ($b != $a) {
107  $tadd = array();
108  $tdel = array();
109  foreach ($doc->acls as $acl) {
110  $pos = $posacls[$acl];
111 
112  $a0 = ($a & (1 << $pos));
113  $b0 = ($b & (1 << $pos));
114  if ($a0 != $b0) {
115  if ($a0) $tadd[] = $acl;
116  else $tdel[] = $acl;
117  }
118  }
119 
120  if (count($tadd) > 0) $tc[] = sprintf(_("Add acl %s for %s") , implode(", ", $tadd) , $tuname[$k]);
121  if (count($tdel) > 0) $tc[] = sprintf(_("Delete acl %s for %s") , implode(", ", $tdel) , $tuname[$k]);
122  }
123  }
124  if (count($tc) > 0) $doc->addComment(sprintf(_("Change control :\n %s") , implode("\n", $tc)));
125  }
126  RedirectSender($action); // return to sender
127 
128 }
129 ?>
← centre documentaire © anakeen - published under CC License - Dynacase