18 private $prfName =
'';
23 private $docName =
'';
33 private $dynDoc = null;
38 private $acls = array();
43 private $modifier =
'';
45 private $defaultAccountType =
'';
49 private $availablesModifier = array(
56 private $availablesDefaultType = array(
61 private $userIds = [];
69 if (!empty($data[2]) && !in_array($data[2], $this->availablesDefaultType)) {
70 $this->prfName = $data[2];
71 $this->docName = $data[1];
73 $this->defaultAccountType = isset($data[2]) ? trim($data[2]) : null;
74 $this->prfName = isset($data[1]) ? $data[1] : null;
75 for ($i = 4; $i < count($data); $i++) {
76 $this->acls[] = $data[$i];
79 if (isset($data[3])) $this->modifier = strtolower($data[3]);
82 $this->checkModifier();
83 $this->checkIsACompatibleProfil();
90 private function checkUnknow()
94 $this->profil = new_doc(
getDbAccess() , $this->prfName);
95 if (!$this->profil->isAlive()) {
103 private function checkIsACompatibleProfil()
105 if ($this->docName) {
107 if (!
$doc->isAlive()) {
110 if (
$doc->acls != $this->profil->acls) {
117 private function checkModifier()
119 if ($this->modifier) {
120 if (!in_array($this->modifier, $this->availablesModifier)) {
126 private function checkAcls()
128 if (!$this->docName) {
129 $profAcls = $this->profil->acls;
130 $profAcls[
"viewacl"] =
"viewacl";
131 $profAcls[
"modifyacl"] =
"modifyacl";
132 foreach ($this->acls as $acl) {
134 if (preg_match(
"/([^=]+)=(.+)/", $acl, $reg)) {
137 if (!in_array($aclId, $profAcls)) {
141 $this->checkUsers(explode(
',', $userId));
150 private function checkUsers(array $uids)
152 foreach ($uids as $uid) {
155 if ($this->profil->getRawValue(
"dpdoc_famid")) {
156 if (!$this->checkAccount($uid)) {
157 $this->checkAttribute($uid);
160 if (!$this->checkAccount($uid)) {
170 private function checkAccount($reference)
176 $findUser = $this->getUserIdFromLogin(
$value);
185 $findUser = ($tu[
"us_whatid"] !=
'');
189 case ':useAttribute':
190 $this->checkAttribute(
$value);
195 if (ctype_digit($reference)) {
201 $findUser = ($tu[
"us_whatid"] !=
'');
209 private function extractAccount($reference, &
$type, &
$value)
211 if (preg_match(
'/^attribute\((.*)\)$/', $reference, $reg)) {
212 $type =
":useAttribute";
213 $value = strtolower(trim($reg[1]));
214 } elseif (preg_match(
'/^account\((.*)\)$/', $reference, $reg)) {
215 $type =
":useAccount";
216 $value = mb_strtolower(trim($reg[1]));
217 } elseif (preg_match(
'/^document\((.*)\)$/', $reference, $reg)) {
218 $type =
":useDocument";
222 $type = $this->defaultAccountType;
226 private function getUserIdFromLogin(
$login)
229 if (!isset($this->userIds[
$login])) {
230 simpleQuery(
"", sprintf(
"select login from users where login='%s'", pg_escape_string($login)) , $uid,
true,
true);
231 $this->userIds[$uid] = $uid;
233 return $this->userIds[
$login];
235 private function checkAttribute($aid)
237 $dynName = $this->profil->getRawValue(
"dpdoc_famid");
238 if (!$this->dynDoc) {
241 if (!$this->dynDoc->isAlive()) {
244 $aids = array_keys($this->dynDoc->getNormalAttributes());
246 foreach ($aids as $naid) {
247 $aType = $this->dynDoc->getAttribute($naid)->type;
248 $isuserOption = $this->dynDoc->getAttribute($naid)->getOption(
"isuser");
249 if (($aType ==
"docid" && $isuserOption ==
"yes") || ($aType ==
"account")) {
253 if (!in_array(strtolower($aid) , $aids)) {
256 if (!in_array(strtolower($aid) , $adocids)) {
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
Check profil when importing definition.
check(array $data, &$extra=null)
static getError($code, $args=null)
static getDisplayName($uid)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)