Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
CheckAccess.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Checking application accesses
8  * @class CheckAccess
9  * @brief Check application accesses when importing definition
10  * @see ErrorCodeACCS
11  */
12 class CheckAccess extends CheckData
13 {
14  /**
15  * application name
16  * @var string
17  */
18  private $appName = '';
19  /**
20  * application identifier
21  * @var int
22  */
23  private $appId = '';
24  /**
25  * user identifier
26  * @var string
27  */
28  private $userId = '';
29  /**
30  * current action
31  * @var Action
32  */
33  private $action = null;
34  /**
35  * acl list
36  * @var array
37  */
38  private $acls = array();
39  /**
40  * @param array $data
41  * @return CheckProfid
42  */
43  public function check(array $data, &$action = null)
44  {
45  $this->appName = $data[2];
46  $this->userId = $data[1];
47 
48  for ($i = 3; $i < count($data); $i++) {
49  if (!empty($data[$i])) {
50  if ($data[$i][0] == '-') $this->acls[] = substr($data[$i], 1);
51  else $this->acls[] = $data[$i];
52  }
53  }
54 
55  $this->action = $action;
56  $this->checkAppExists();
57  if (!$this->hasErrors()) {
58  $this->checkUserExists();
59  $this->checkAclsExists();
60  }
61 
62  return $this;
63  }
64 
65  private function checkAppExists()
66  {
67  if (!$this->appName) {
68  $this->addError(ErrorCode::getError('ACCS0006'));
69  } else {
70  if ($this->checkSyntax($this->appName)) {
71  $this->appId = $this->action->parent->GetIdFromName($this->appName);
72  if (!$this->appId) {
73  $this->addError(ErrorCode::getError('ACCS0001', $this->appName));
74  }
75  } else {
76  $this->addError(ErrorCode::getError('ACCS0005', $this->appName));
77  }
78  }
79  }
80 
81  private function checkUserExists()
82  {
83  if ($this->userId) {
84  $findUser = false;
85  if (ctype_digit($this->userId)) {
86  $findUser = User::getDisplayName($this->userId);
87  } else {
88  // search document
89  $tu = getTDoc(getDbAccess() , $this->userId);
90  if ($tu) {
91  $findUser = ($tu["us_whatid"] != '');
92  }
93  }
94  if ($findUser === false) {
95  $this->addError(ErrorCode::getError('ACCS0003', $this->userId));
96  }
97  } else {
98  $this->addError(ErrorCode::getError('ACCS0007'));
99  }
100  }
101  private function checkAclsExists()
102  {
103  $oAcl = new Acl(getDbAccess());
104  foreach ($this->acls as $acl) {
105  if ($this->checkSyntax($acl)) {
106  if (!$oAcl->Set($acl, $this->appId)) {
107  $this->addError(ErrorCode::getError('ACCS0002', $acl, $this->appName));
108  }
109  } else {
110  $this->addError(ErrorCode::getError('ACCS0004', $acl));
111  }
112  }
113  }
114  /**
115  * @param string $acl
116  * @return bool
117  */
118  private function checkSyntax($acl)
119  {
120  if (preg_match("/^-?[A-Z_0-9_-]{1,63}$/i", $acl)) {
121  return true;
122  }
123  return false;
124  }
125 }
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
check(array $data, &$action=null)
Definition: CheckAccess.php:43
static getError($code, $args=null)
Definition: ErrorCode.php:27
Check application accesses when importing definition.
Definition: CheckAccess.php:12
static getDisplayName($uid)
addError($msg)
Definition: CheckData.php:29
getDbAccess()
Definition: Lib.Common.php:368
$data
← centre documentaire © anakeen