Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.DocPermExt.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 DocPermExt extends DbObj
23 {
24  var $fields = array(
25  "docid",
26  "userid",
27  "acl"
28  );
29 
30  var $id_fields = array(
31  "docid",
32  "userid",
33  "acl"
34  );
35  public $docid;
36  public $userid;
37  public $acl;
38 
39  var $dbtable = "docpermext";
40 
41  var $order_by = "docid";
42 
43  var $sqlcreate = "
44 create table docpermext (
45  docid int check (docid > 0),
46  userid int check (userid > 1),
47  acl text not null
48  );
49 create unique index idx_permext on docpermext(docid, userid,acl);";
50 
51  public function preInsert()
52  {
53  if ($this->userid == 1) return _("not perm for admin");
54  return '';
55  }
56 
57  public function preUpdate()
58  {
59  return $this->preInsert();
60  }
61  /**
62  * @static
63  * @param int $userid user identifier
64  * @param string $acl acl name to control
65  * @param int $profid profil identifier
66  * @param bool $strict set to true to not use substitute
67  * @return int
68  */
69  public static function isGranted($userid, $acl, $profid, $strict = false)
70  {
71  if ($userid == 1) return true;
73  $gids[] = $userid;
74  $sql = sprintf("select * from docpermext where docid=%d and acl='%s' and userid in (%s)", $profid, pg_escape_string($acl) , implode(',', $gids));
75  simpleQuery('', $sql, $result);
76  //print_r($sql);
77  return (count($result) > 0);
78  }
79  public static function hasExtAclGrant($docid, $accountId, $aclName)
80  {
81  static $grants = null;
82  if ($grants === null && $grants[$docid] === null) {
83  simpleQuery('', sprintf("select * from docpermext where docid=%d", $docid) , $qgrants);
84  $grants[$docid] = $qgrants;
85  }
86  foreach ($grants[$docid] as $aGrant) {
87  if ($aGrant["acl"] == $aclName && $aGrant["userid"] == $accountId) return 'green';
88  }
89  $mof = Account::getUserMemberOf($accountId);
90  if ($mof) {
91  foreach ($grants[$docid] as $aGrant) {
92  if ($aGrant["acl"] == $aclName && in_array($aGrant["userid"], $mof)) return 'grey';
93  }
94  }
95  return '';
96  }
97  public static function getPermsForDoc($docid)
98  {
99  $sql = sprintf("SELECT docid, userid, acl FROM docpermext WHERE docid = %d ORDER BY docid, userid, acl", $docid);
100  $res = array();
101  simpleQuery('', $sql, $res, false, false, true);
102  return $res;
103  }
104 }
static isGranted($userid, $acl, $profid, $strict=false)
static getUserMemberOf($uid, $strict=false)
static getPermsForDoc($docid)
static hasExtAclGrant($docid, $accountId, $aclName)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
← centre documentaire © anakeen