Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.DocPerm.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  * Document permissions
9  *
10  * @author Anakeen 2000
11  * @version $Id: Class.DocPerm.php,v 1.15 2007/06/14 15:48:25 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  */
15 /**
16  */
17 
18 include_once ("Class.DbObj.php");
19 /**
20  * Managing permissions of documents
21  * @package FDL
22  *
23  */
24 class DocPerm extends DbObj
25 {
26  var $fields = array(
27  "docid",
28  "userid",
29  "upacl",
30  "unacl",
31  "cacl"
32  );
33 
34  var $sup_fields = array(
35  "getuperm(userid,docid) as uperm"
36  );
37  var $id_fields = array(
38  "docid",
39  "userid"
40  );
41 
42  var $dbtable = "docperm";
43 
44  var $order_by = "docid";
45 
46  var $isCacheble = false;
47  var $sqlcreate = "
48 create table docperm (
49  docid int check (docid > 0),
50  userid int check (userid > 1),
51  upacl int not null,
52  unacl int not null,
53  cacl int not null
54  );
55 create unique index idx_perm on docperm(docid, userid);
56 create trigger tinitacl AFTER INSERT OR UPDATE ON docperm FOR EACH ROW EXECUTE PROCEDURE initacl();";
57 
58  function preSelect($tid)
59  {
60  if (count($tid) == 2) {
61  $this->docid = $tid[0];
62  $this->userid = $tid[1];
63  }
64  }
65 
66  function preInsert()
67  {
68  if ($this->userid == 1) return _("not perm for admin");
69  if (($this->upacl == 0) && ($this->unacl == 0)) return "";
70  if ($this->unacl === "") $this->unacl = "0";
71  if ($this->cacl === "") $this->cacl = "0";
72  }
73 
74  function preUpdate()
75  {
76  return $this->preInsert();
77  }
78  /**
79  * reinitialize computed acl
80  * @param integer $docid docid acl to reset
81  */
82  function resetComputed($docid = "")
83  {
84  $err = "";
85  if (!$docid) $docid = $this->docid;
86  if ($docid > 0) {
87  $err = $this->exec_query(sprintf("update docperm set cacl=0 where docid=%d and cacl != 0;", $docid));
88  }
89  return $err;
90  }
91  function getUperm($docid, $userid)
92  {
93  $q = new QueryDb($this->dbaccess, "docperm");
94  $t = $q->Query(0, 1, "TABLE", "select getuperm($userid,$docid) as uperm");
95 
96  return (($q->nb > 0) ? $t[0]["uperm"] : 0);
97  }
98  function recomputeControl()
99  {
100  if ($this->docid > 0) $this->exec_query("select getuperm(userid,docid) as uperm from docperm where docid=" . $this->docid);
101  }
102  // --------------------------------------------------------------------
103  function ControlU($pos)
104  {
105  // --------------------------------------------------------------------
106  if ($this->cacl == 0) {
107  $this->cacl = $this->getUperm($this->docid, $this->userid);
108  }
109  return ($this->ControlMask($this->cacl, $pos));
110  }
111  // --------------------------------------------------------------------
112  function ControlG($pos)
113  {
114  // --------------------------------------------------------------------
115  if (!isset($this->gacl)) {
116  $q = new QueryDb($this->dbaccess, "docperm");
117  $t = $q->Query(0, 1, "TABLE", "select computegperm({$this->userid},{$this->docid}) as uperm");
118 
119  $this->gacl = $t[0]["uperm"];
120  }
121 
122  return ($this->ControlMask($this->gacl, $pos));
123  }
124  // --------------------------------------------------------------------
125  function ControlUp($pos)
126  {
127  // --------------------------------------------------------------------
128  if ($this->isAffected()) {
129  return ($this->ControlMask($this->upacl, $pos));
130  }
131  return false;
132  }
133  // --------------------------------------------------------------------
134  function ControlUn($pos)
135  {
136  // --------------------------------------------------------------------
137  if ($this->isAffected()) {
138  return ($this->ControlMask($this->unacl, $pos));
139  }
140  return false;
141  }
142  // --------------------------------------------------------------------
143  function ControlMask($acl, $pos)
144  {
145  // --------------------------------------------------------------------
146  return (($acl & (1 << ($pos))) != 0);
147  }
148  /**
149  * no control for anyone
150  */
151  function UnSetControl()
152  {
153  $this->upacl = 0;
154  $this->unacl = 0;
155  $this->cacl = 1;
156  }
157  /**
158  * set positive ACL in specified position
159  * @param int $pos column number (0 is the first right column)
160  */
161  function SetControlP($pos)
162  {
163  $this->upacl = $this->upacl | (1 << $pos);
164  $this->UnSetControlN($pos);
165  }
166  /**
167  * unset positive ACL in specified position
168  * @param int $pos column number (0 is the first right column)
169  */
170  function UnSetControlP($pos)
171  {
172  $this->upacl = $this->upacl & (~(1 << $pos));
173  }
174  /**
175  * set negative ACL in specified position
176  * @param int $pos column number (0 is the first right column)
177  */
178  function SetControlN($pos)
179  {
180  $this->unacl = $this->unacl | (1 << $pos);
181  $this->UnSetControlP($pos);
182  }
183  /**
184  * unset negative ACL in specified position
185  * @param int $pos column number (0 is the first right column)
186  */
187  function UnSetControlN($pos)
188  {
189  $this->unacl = $this->unacl & (~(1 << $pos));
190  }
191 }
192 ?>
← centre documentaire © anakeen - published under CC License - Dynacase