Core  3.2
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  * @package FDL
5 */
6 /**
7  * Document permissions
8  *
9  * @author Anakeen
10  * @version $Id: Class.DocPerm.php,v 1.15 2007/06/14 15:48:25 eric Exp $
11  * @package FDL
12  */
13 /**
14  */
15 
16 include_once ("Class.DbObj.php");
17 /**
18  * Managing permissions of documents
19  * @package FDL
20  *
21  */
22 class DocPerm extends DbObj
23 {
24  var $fields = array(
25  "docid",
26  "userid",
27  "upacl"
28  );
29 
30  var $id_fields = array(
31  "docid",
32  "userid"
33  );
34  public $docid;
35  public $userid;
36  public $upacl;
37  public $uperm;
38 
39  var $dbtable = "docperm";
40 
41  var $order_by = "docid";
42 
43  var $sqlcreate = "
44 create table docperm (
45  docid int check (docid > 0),
46  userid int check (userid > 1),
47  upacl int not null
48  );
49 create unique index idx_perm on docperm(docid, userid);";
50 
51  function preSelect($tid)
52  {
53  if (count($tid) == 2) {
54  $this->docid = $tid[0];
55  $this->userid = $tid[1];
56  }
57  }
58 
59  function preInsert()
60  {
61  if ($this->userid == 1) return _("not perm for admin");
62  return '';
63  }
64 
65  function preUpdate()
66  {
67  return $this->preInsert();
68  }
69  /**
70  * return account vector for current user
71  * to be use in getaperm sql function
72  * @static
73  * @param int $uid user identifier
74  * @param bool $strict set to true to not use substitute
75  * @return string
76  */
77  public static function getMemberOfVector($uid = 0, $strict = false)
78  {
79  if ($uid == 0) {
80  global $action;
81  if ($strict) $mof = $action->user->getStrictMemberOf();
82  else $mof = $action->user->getMemberOf();
83  $mof[] = $action->user->id;
84  } else {
85 
86  $mof = Account::getUserMemberOf($uid, $strict);
87  $mof[] = $uid;
88  }
89  return '{' . implode(',', $mof) . '}';
90  }
91  /**
92  * @static
93  * @param int $profid profil identifier
94  * @param int $userid user identifier
95  * @param bool $strict set to true to not use substitute
96  * @return int
97  */
98  public static function getUperm($profid, $userid, $strict = false)
99  {
100  if ($userid == 1) return -1;
102  $sql = sprintf("select getaperm('%s',%d) as uperm", $userMember, $profid);
103  simpleQuery(getDbAccess() , $sql, $uperm, true, true);
104  if ($uperm === false) return 0;
105 
106  return $uperm;
107  }
108 
109  public static function getStrictUperm($profid, $userid)
110  {
111  if ($userid == 1) return -1;
112  $userMember = DocPerm::getMemberOfVector($userid);
113  $sql = sprintf("select getaperm('%s',%d) as uperm", $userMember, $profid);
114  simpleQuery(getDbAccess() , $sql, $uperm, true, true);
115  if ($uperm === false) return 0;
116 
117  return $uperm;
118  }
119  /**
120  * control access at $pos position (direct or indirect) (green or grey)
121  * @param $pos
122  * @return bool
123  */
124  function ControlU($pos)
125  {
126  if ($this->uperm == 0) {
127  $this->uperm = $this->getUperm($this->docid, $this->userid);
128  }
129  return ($this->ControlMask($this->uperm, $pos));
130  }
131  // --------------------------------------------------------------------
132 
133  /**
134  * @param $pos
135  * @deprecated no need now. Control process has changed
136  * @return bool
137  */
138  function ControlG($pos)
139  {
140  return false;
141  }
142  /**
143  * control access at $pos position direct inly (green)
144  * @param $pos
145  * @return bool
146  */
147  function ControlUp($pos)
148  {
149  // --------------------------------------------------------------------
150  if ($this->isAffected()) {
151  return ($this->ControlMask($this->upacl, $pos));
152  }
153  return false;
154  }
155  // --------------------------------------------------------------------
156  function ControlMask($acl, $pos)
157  {
158  if ($pos < 0) {
159  return false;
160  }
161  return (($acl & (1 << ($pos))) != 0);
162  }
163  /**
164  * no control for anyone
165  */
166  function UnSetControl()
167  {
168  $this->upacl = 0;
169  }
170  /**
171  * set positive ACL in specified position
172  * @param int $pos column number (0 is the first right column)
173  */
174  function SetControlP($pos)
175  {
176  if ($pos >= 0) {
177  $this->upacl = intval($this->upacl) | (1 << $pos);
178  }
179  }
180  /**
181  * unset positive ACL in specified position
182  * @param int $pos column number (0 is the first right column)
183  */
184  function UnSetControlP($pos)
185  {
186  if ($pos >= 0) {
187  $this->upacl = $this->upacl & (~(1 << $pos));
188  }
189  }
190  public static function getPermsForDoc($docid)
191  {
192  $sql = sprintf("SELECT docid, userid, upacl FROM docperm WHERE docid = %d ORDER BY docid, userid, upacl", $docid);
193  $res = array();
194  simpleQuery('', $sql, $res, false, false, true);
195  return $res;
196  }
197 }
static getMemberOfVector($uid=0, $strict=false)
global $action
ControlG($pos)
ControlUp($pos)
static getUserMemberOf($uid, $strict=false)
static getPermsForDoc($docid)
ControlU($pos)
isAffected()
print docid
Definition: migrEnum.php:33
SetControlP($pos)
static getUperm($profid, $userid, $strict=false)
preSelect($tid)
getDbAccess()
Definition: Lib.Common.php:368
ControlMask($acl, $pos)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
static getStrictUperm($profid, $userid)
UnSetControlP($pos)
← centre documentaire © anakeen