Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.DocCtrl.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  * Control Access Document
9  *
10  * @author Anakeen 2002
11  * @version $Id: Class.DocCtrl.php,v 1.54 2008/08/05 15:16:58 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.DocLDAP.php");
19 include_once ("FDL/Class.DocPerm.php");
20 include_once ("FDL/Class.VGroup.php");
21 
22 define("POS_INIT", 0);
23 define("POS_VIEW", 1);
24 define("POS_EDIT", 2);
25 define("POS_DEL", 3);
26 define("POS_SEND", 4);
27 // common part are 0-4 and 7-8
28 define("POS_OPEN", 5);
29 define("POS_EXEC", 5); // idem OPEN : alias
30 define("POS_CONT", 6); // view containt
31 define("POS_VACL", 7);
32 define("POS_MACL", 8);
33 define("POS_ULCK", 9);
34 define("POS_CONF", 10); // confidential
35 define("POS_FORUM", 11); // edit forum
36 define("POS_WASK", 12); // view all askes
37 // family profil
38 define("POS_CREATE", 5);
39 define("POS_ICREATE", 6);
40 // 11 undefined for the moment
41 define("POS_WF", 12); // begin of workflow privilege definition
42 // end of privilege is 31 : (coded on 32bits)
43 
44 /**
45  * Control Access Document Class
46  * @package FDL
47  *
48  */
49 class DocCtrl extends DocLDAP
50 {
51  var $isCacheble = false;
52  // --------------------------------------------------------------------
53  //---------------------- OBJECT CONTROL PERMISSION --------------------
54  // access privilege definition
55  var $dacls = array(
56  "init" => array(
57  "pos" => POS_INIT,
58  "description" => "control initialized"
59  ) ,
60 
61  "view" => array(
62  "pos" => POS_VIEW, # N_("view document")
63  "description" => "view document"
64  ) , # N_("view")
65  "send" => array(
66  "pos" => POS_SEND, # N_("send document")
67  "description" => "send document"
68  ) , # N_("send")
69  "edit" => array(
70  "pos" => POS_EDIT, # N_("edit document")
71  "description" => "edit document"
72  ) , # N_("edit")
73  "delete" => array(
74  "pos" => POS_DEL, # N_("delete document")
75  "description" => "delete document"
76  ) , # N_("delete")
77  "open" => array(
78  "pos" => POS_OPEN, # N_("open folder")
79  "description" => "open folder"
80  ) , # N_("open")
81  "execute" => array(
82  "pos" => POS_EXEC, # N_("execute search")
83  "description" => "execute search"
84  ) , # N_("execute")
85  "modify" => array(
86  "pos" => POS_CONT, # N_("modify folder")
87  "description" => "modify folder"
88  ) , # N_("modify")
89  "viewacl" => array(
90  "pos" => POS_VACL, # N_("view acl")
91  "description" => "view acl"
92  ) , # N_("viewacl")
93  "modifyacl" => array(
94  "pos" => POS_MACL, # N_("modify acl")
95  "description" => "modify acl"
96  ) , # N_("modifyacl")
97  "create" => array(
98  "pos" => POS_CREATE, # N_("modify acl")
99  "description" => "create doc"
100  ) , # N_("create doc")
101  "unlock" => array(
102  "pos" => POS_ULCK, # N_("unlock")
103  "description" => "unlock unowner locked doc"
104  ) , # N_("unlock unowner locked doc")
105  "icreate" => array(
106  "pos" => POS_ICREATE, # N_("icreate")
107  "description" => "create doc manually"
108  ) , # N_("create doc manually")
109  "confidential" => array(
110  "pos" => POS_CONF, # N_("confidential")
111  "description" => "view confidential"
112  ) , # N_("view confidential")
113  "forum" => array(
114  "pos" => POS_FORUM, # N_("forum")
115  "description" => "edit forum"
116  ) , # N_("edit forum")
117  "wask" => array(
118  "pos" => POS_WASK, # N_("wask")
119  "description" => "view answers"
120  ) # N_("view answers")
121 
122  );
123  // --------------------------------------------------------------------
124  function __construct($dbaccess = '', $id = '', $res = '', $dbid = 0)
125  {
126  // --------------------------------------------------------------------
127  global $action; // necessary to see information about user privilege
128  if (isset($action)) {
129  $this->userid = $action->parent->user->id;
130  }
131  if (!isset($this->attributes->attr)) $this->attributes->attr = array();
132  parent::__construct($dbaccess, $id, $res, $dbid);
133  }
134 
135  function isControlled()
136  {
137  return ($this->profid != 0);
138  }
139 
140  function unsetControl()
141  {
142  if ($this->id == $this->profid) {
143  // inhibated all doc references this profil
144  if ($this->doctype == 'P') $this->exec_query("update doc set profid=-profid where profid=" . $this->id . " and locked != -1;");
145  }
146  $this->profid = "0";
147  $err = $this->modify(true, array(
148  "profid"
149  ));
150  }
151  /**
152  * Unset all Acl for document (for everybody)
153  *
154  */
155  function removeControl()
156  {
157  if ($this->id == $this->profid) {
158  // inhibated all doc references this profil
159  $this->exec_query("delete from docperm where docid=" . $this->id);
160  }
161  $this->modify();
162  }
163  /**
164  * activate access specific control
165  * @param bool $userctrl if true add all acls for current user
166  */
167  function setControl($userctrl = true)
168  {
169  if ($userctrl) {
170  $perm = new DocPerm($this->dbaccess, array(
171  $this->id,
172  $this->userid
173  ));
174  $perm->docid = $this->id;
175  $perm->userid = $this->userid;
176  $perm->upacl = - 2; // all privileges
177  $perm->unacl = 0;
178  $perm->cacl = 0;
179  if (!$perm->IsAffected()) {
180  // add all privileges to current user
181  $perm->Add();
182  } else {
183  $perm->Modify();
184  }
185  }
186  // reactivation of doc with its profil
187  if ($this->doctype == 'P') $this->exec_query("update doc set profid=-profid where profid=-" . $this->id . " and locked != -1;");
188 
189  $this->profid = $this->id;
190  $err = $this->modify(true, array(
191  "profid"
192  ) , true);
193  return $err;
194  }
195  /**
196  * set profil for document
197  *
198  * @param int profid identificator for profil document
199  */
200  function setProfil($profid, $fromdocidvalues = 0)
201  {
202 
203  if (!is_numeric($profid)) $profid = getIdFromName($this->dbaccess, $profid);
204  if (empty($profid)) {
205  $profid = 0;
206  }
207  $this->profid = $profid;
208  if (($profid > 0) && ($profid != $this->id)) {
209  // make sure that the profil is activated
210  $pdoc = new_Doc($this->dbaccess, $profid);
211  if ($pdoc->getValue("DPDOC_FAMID") > 0) {
212  // dynamic profil
213  $this->dprofid = $profid;
214  $this->computeDProfil($this->dprofid, $fromdocidvalues);
215  unset($this->uperm); // force recompute privileges
216 
217  } else {
218  $this->dprofid = 0;
219  }
220  if ($pdoc->profid == 0) $this->profid = - $profid; // inhibition
221 
222  } elseif (($profid > 0) && ($profid == $this->id)) {
223  $this->dprofid = 0;
224  }
225  if ($this->id > 0) {
226  $err = $this->modify(true, array(
227  "profid",
228  "dprofid"
229  ) , true);
230  }
231  }
232  /**
233  * reset right for dynamic profil
234  *
235  * @param int dprofid identificator for dynamic profil document
236  */
237  function computeDProfil($dprofid = 0, $fromdocidvalues = 0)
238  {
239  if ($this->id == 0) return;
240  if ($dprofid == 0) $dprofid = $this->dprofid;
241  if ($dprofid <= 0) return;
242 
243  $pdoc = new_Doc($this->dbaccess, $dprofid);
244  $pfamid = $pdoc->getValue("DPDOC_FAMID");
245  if ($pfamid > 0) {
246  if ($this->profid != $this->id) {
247  $this->profid = $this->id; //private profil
248  $this->modify(true, array(
249  "profid"
250  ));
251  }
252 
253  $query = new QueryDb($this->dbaccess, "DocPerm");
254  $query->AddQuery("docid=" . $pdoc->id);
255  $tacl = $query->Query(0, 0, "TABLE");
256  if (!is_array($tacl)) {
257  // print "err $tacl";
258  $tacl = array();
259  }
260  $tgnum = array(); // list of virtual user/group
261  foreach ($tacl as $v) {
262  if ($v["userid"] >= STARTIDVGROUP) {
263  $tgnum[] = $v["userid"];
264  }
265  }
266  if (count($tgnum) > 0) {
267  $query = new QueryDb($this->dbaccess, "VGroup");
268  $query->AddQuery(GetSqlCond($tgnum, "num", true));
269  $tg = $query->Query(0, 0, "TABLE");
270  if ($query->nb > 0) {
271  foreach ($tg as $vg) {
272  $tnum[$vg["num"]] = $vg["id"];
273  }
274  }
275  }
276  $this->exec_query("delete from docperm where docid=" . $this->id);
277  if ($fromdocidvalues == 0) $fromdocidvalues = & $this;
278  foreach ($tacl as $v) {
279 
280  if ($v["userid"] < STARTIDVGROUP) {
281  $tuid = array(
282  $v["userid"]
283  );
284  } else {
285  $tuid = array();
286  $aid = $tnum[$v["userid"]];
287  $duid = $fromdocidvalues->getValue($aid);
288  if ($duid == "") $duid = $fromdocidvalues->getParamValue($aid);
289  if ($duid != "") {
290  $duid = str_replace("<BR>", "\n", $duid); // docid multiple
291  $tduid = $this->_val2array($duid);
292  foreach ($tduid as $duid) {
293  if ($duid > 0) {
294  $docu = getTDoc($fromdocidvalues->dbaccess, intval($duid)); // not for idoc list for the moment
295  $tuid[] = $docu["us_whatid"];
296  //print "<br>$aid:$duid:".$docu["us_whatid"];
297 
298  }
299  }
300  }
301  }
302  foreach ($tuid as $ku => $uid) {
303  // add right in case of multiple use of the same user : possible in dynamic profile
304  $vupacl[$uid] = (intval($vupacl[$uid]) | intval($v["upacl"]));
305  $vunacl[$uid] = (intval($vunacl[$uid]) | intval($v["unacl"]));
306 
307  if ($uid > 0) {
308  $perm = new DocPerm($this->dbaccess, array(
309  $this->id,
310  $uid
311  ));
312  $perm->cacl = "0";
313  $perm->upacl = $vupacl[$uid];
314  $perm->unacl = $vunacl[$uid];
315  // print "<BR>set perm $uid : ".$this->id."/".$perm->upacl;
316  if ($perm->isAffected()) $err = $perm->modify();
317  else {
318  if ($perm->upacl || $perm->unacl) {
319  // add if necessary
320  $err = $perm->Add();
321  }
322  }
323  }
324  }
325  }
326  if ($perm) {
327  // reinit computed
328  $err = $perm->resetComputed();
329  }
330  }
331  unset($this->uperm); // force recompute privileges
332  return $err;
333  }
334  /**
335  * modify control for a specific user
336  *
337  * @param int uid user identificator
338  * @param string $aclname name of the acl (edit, view,...)
339  * @param bool $deletecontrol set true if want delete a control
340  * @param bool $negativecontrol set true if want add a negative control (explicit no permission)
341  * @return string error message (empty if no errors)
342  */
343  function modifyControl($uid, $aclname, $deletecontrol = false, $negativecontrol = false)
344  {
345 
346  if (!isset($this->dacls[$aclname])) {
347  return sprintf(_("unknow privilege %s") , $aclname);
348  }
349  $pos = $this->dacls[$aclname]["pos"];
350 
351  if (!is_numeric($uid)) {
352  $uiid = getIdFromName($this->dbaccess, $uid);
353  if ($uiid) {
354  $udoc = new_Doc($this->dbaccess, $uiid);
355  if ($udoc->isAlive()) $uid = $udoc->getValue("us_whatid");
356  }
357  }
358 
359  if (!is_numeric($uid)) {
360  // logical name
361  $vg = new VGroup($this->dbaccess, strtolower($uid));
362  if (!$vg->isAffected()) {
363  // try to add
364  $ddoc = new_Doc($this->dbaccess, $this->getValue("dpdoc_famid"));
365  $oa = $ddoc->getAttribute($uid);
366  if ($oa->type == "docid") {
367  $vg->id = $oa->id;
368  $vg->Add();
369  $uid = $vg->num;
370  } else $err = sprintf(_("unknow virtual user identificateur %s") , $uid);
371  } else {
372  $uid = $vg->num;
373  }
374  }
375 
376  if ($uid > 0) {
377  $perm = new DocPerm($this->dbaccess, array(
378  $this->id,
379  $uid
380  ));
381  if ($deletecontrol) {
382  if ($negativecontrol) $perm->UnsetControlN($pos);
383  else $perm->UnsetControlP($pos);
384  } else {
385  if ($negativecontrol) $perm->SetControlN($pos);
386  else $perm->SetControlP($pos);
387  }
388  if ($perm->isAffected()) $err = $perm->modify();
389  else {
390  $err = $perm->Add();
391  }
392  }
393  return $err;
394  }
395  /**
396  * add control for a specific user
397  *
398  * @param int uid user identificator
399  * @param string $aclname name of the acl (edit, view,...)
400  * @param bool $negativecontrol set true if want add a negative control (explicit no permission)
401  * @return string error message (empty if no errors)
402  */
403  function addControl($uid, $aclname, $negativecontrol = false)
404  {
405  return $this->ModifyControl($uid, $aclname, false, $negativecontrol);
406  }
407  /**
408  * suppress control for a specific user
409  *
410  * is not a negative control
411  * @param int uid user identificator
412  * @param string $aclname name of the acl (edit, view,...)
413  * @param bool $negativecontrol set true if want suppress a negative control
414  * @return string error message (empty if no errors)
415  */
416  function delControl($uid, $aclname, $negativecontrol = false)
417  {
418  return $this->ModifyControl($uid, $aclname, true, $negativecontrol);
419  }
420  /**
421  * set control view for document
422  *
423  * @param int cvid identificator for control view document
424  */
425  function setCvid($cvid)
426  {
427  if (!is_numeric($cvid)) $cvid = getIdFromName($this->dbaccess, $cvid);
428  $this->cvid = $cvid;
429  }
430  /**
431  * use to know if current user has access privilege
432  *
433  * @param int $docid profil identificator
434  * @param string $aclname name of the acl (edit, view,...)
435  * @return string if empty access granted else error message
436  */
437  function controlId($docid, $aclname)
438  {
439  if ($this->profid == $docid) {
440  if (!isset($this->uperm)) {
441  $perm = new DocPerm($this->dbaccess, array(
442  $docid,
443  $this->userid
444  ));
445  if ($perm->IsAffected()) $this->uperm = $perm->uperm;
446  else $this->uperm = $perm->getUperm($docid, $this->userid);
447  }
448  return $this->ControlUp($this->uperm, $aclname);
449  } else {
450  $perm = new DocPerm($this->dbaccess, array(
451  $docid,
452  $this->userid
453  ));
454  if ($perm->isAffected()) $uperm = $perm->uperm;
455  else $uperm = $perm->getUperm($docid, $this->userid);
456  return $this->ControlUp($uperm, $aclname);
457  }
458  }
459  /**
460  * use to know if current user has access privilege
461  *
462  * @param int $docid profil identificator
463  * @param int $uid user identificator
464  * @param string $aclname name of the acl (edit, view,...)
465  * @return string if empty access granted else error message
466  */
467  function controlUserId($docid, $uid, $aclname)
468  {
469  $perm = new DocPerm($this->dbaccess, array(
470  $docid,
471  $uid
472  ));
473 
474  if ($perm->isAffected()) $uperm = $perm->uperm;
475  else $uperm = $perm->getUperm($docid, $uid);
476 
477  return $this->controlUp($uperm, $aclname);
478  }
479  /**
480  * use to know if permission has access privilege
481  *
482  * @param int $uperm permission mask
483  * @param string $aclname name of the acl (edit, view,...)
484  * @return string if empty access granted else error message
485  */
486  function controlUp($uperm, $aclname)
487  {
488  if (isset($this->dacls[$aclname])) {
489  return (($uperm & (1 << ($this->dacls[$aclname]["pos"]))) != 0) ? "" : sprintf(_("no privilege %s for %s |%d]") , $aclname, $this->title, $this->id);
490  } else {
491  return sprintf(_("unknow privilege %s") , $aclname);
492  }
493  }
494  /**
495  * return all users which has a control for a document
496  * @param string $aclname the name of acl to search
497  * @return array of the system users informations
498  */
499  function getUsersForAcl($aclname)
500  {
501  if (isset($this->dacls[$aclname])) {
502  $pos = $this->dacls[$aclname]["pos"];
503 
504  if ($this->getValue("DPDOC_FAMID") > 0) {
505  if ($this->doc) {
506  if (!isset($this->pdoc)) {
507  $pdoc = createTmpDoc($this->dbaccess, $this->fromid);
508  $err = $pdoc->Add();
509  if ($err != "") return "getUsersForAcl:" . $err; // can't create profil
510  $pdoc->setProfil($this->profid, $this->doc);
511  $this->pdoc = & $pdoc;
512  } else {
513  $pdoc = $this->pdoc;
514  }
515  }
516  }
517  }
518  if ($pdoc) $pdocid = $pdoc->id;
519  else $pdocid = $this->profid;
520 
521  $query = new QueryDb($this->dbaccess, "DocPerm");
522  $query->AddQuery("docid=" . $pdocid);
523  $query->AddQuery(sprintf("(upacl & %d) != 0", 1 << $pos));
524  $tperm = $query->Query(0, 0, "TABLE");
525  $u = new User("");
526  $ru = array();
527  if ($query->nb > 0) {
528  foreach ($tperm as $perm) {
529  $u->select($perm["userid"]);
530  if ($u->login) {
531  if ($u->isgroup == 'Y') {
532  $ru+= $u->GetRUsersList($u->id);
533  } else {
534  $ru[$u->id] = $u->getValues();
535  }
536  }
537  }
538 
539  foreach ($ru as $k => $v) { // delete groups
540  if ($v["isgroup"] == "Y") unset($ru[$k]);
541  }
542  }
543  return $ru;
544  }
545  /**
546  * apply computeDProfil in all documents with this profile
547  * @return void
548  */
549  public function recomputeProfiledDocument()
550  {
551  if ($this->getAttribute("dpdoc_famid")) {
552 
553  include_once ("FDL/Class.SearchDoc.php");
554  if ($this->getValue("dpdoc_famid") > 0) {
555  // dynamic profil
556  // recompute associated documents
557  $s = new SearchDoc($this->dbaccess);
558  $s->addFilter("dprofid = %d", $this->id);
559  $s->setObjectReturn();
560  $s->search();
561  while ($doc = $s->nextDoc()) {
562  $doc->computeDProfil();
563  }
564  // in case of change profil status (static -> dynamic)
565  $s = new SearchDoc($this->dbaccess);
566  $s->addFilter("profid = %d", $this->id);
567  $s->setObjectReturn();
568  $s->search();
569  while ($doc = $s->nextDoc()) {
570  $doc->setProfil($this->id);
571  }
572  } else {
573  // static profil
574  // revert to static profiling
575  $s = new SearchDoc($this->dbaccess);
576  $s->addFilter("dprofid = %d", $this->id);
577  $s->setObjectReturn();
578  $s->search();
579  while ($doc = $s->nextDoc()) {
580  $doc->setProfil($this->id);
581  }
582  }
583  }
584  }
585  // // --------------------------------------------------------------------
586  // function ControlUserId ($userid,$aclname) {
587  // // --------------------------------------------------------------------
588  // if (isset($this->dacls[$aclname])) {
589  // $perm = new DocPerm($this->dbaccess, array($this->id,$userid));
590  // if ($perm -> IsAffected()) $uperm = $perm->uperm;
591  // else $uperm = $perm->getUperm($this->id,$userid);
592  // return (($uperm & (1 << ($this->dacls[$aclname]["pos"] ))) != 0)?"":sprintf(_("no privilege %s"),$aclname);
593  // } else {
594  // return sprintf(_("unknow privilege %s"),$aclname);
595  // }
596  // }
597  static public function parseMail($Email)
598  {
599  $sug = array(); // suggestions
600  $err = "";
601 
602  if ($Email != "") {
603  if ($Email[0] == "<") {
604  $sug[] = _("<it's a message>");
605  } else {
606  if (preg_match("/^[_\.0-9\/'?$&\+~`%|*a-z=^{}-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$/i", $Email)) {
607  return true;
608  }
609  $err = _("the email syntax is like : john.doe@anywhere.org");
610  if (!preg_match("/@/", $Email)) {
611  $err = _("the email must containt the @ character");
612  }
613  }
614  }
615  return array(
616  "err" => $err,
617  "sug" => $sug
618  );
619  }
620  /**
621  * return true if the date is in the future (one day after at less)
622  * @param string date date JJ/MM/AAAA
623  */
624  static public function isFutureDate($date)
625  {
626 
627  $err = "";
628  $sug = array(); // suggestions
629  if ($date != "") {
630  if (!preg_match("|^[0-9]{2}/[0-9]{2}/[0-9]{4}|", $date)) {
631  $err = _("the date syntax must be like : DD/MM/AAAA");
632  } else {
633 
634  list($dd, $mm, $yy) = explode("/", $date);
635  $yy = intval($yy);
636  $mm = intval($mm);
637  $dd = intval($dd);
638  $ti = mktime(0, 0, 0, $mm, $dd + 1, $yy);
639  if ($ti < time()) {
640  $err = sprintf(_("the date %s is in the past: today is %s") , date("d/m/Y", mktime(0, 0, 0, $mm, $dd, $yy)) , date("d/m/Y", time()));
641  $sug[] = date("d/m/Y", time());
642  }
643  }
644  }
645  return array(
646  "err" => $err,
647  "sug" => $sug
648  );
649  }
650  /**
651  * verify if a document title and its link are for the same document
652  * @param string document title use for verification
653  * @param string document identificator use for verification
654  */
655  public function isDocLinked($title, $docid)
656  {
657 
658  $err = "";
659  $sug = array(); // suggestions
660  if (trim($title) != "") {
661  if (trim($docid) == "") $err = _("need to select the document with the list");
662  else {
663  $d = new_doc($this->dbaccess, $docid);
664  if (!$d->isAlive()) $err = sprintf(_("the document id [%s] for this attribute is not valid") , $docid);
665  else if ($d->title != $title) $err = sprintf(_("the title of document [%s] is not conform to original [%s]") , $title, $d->title);
666  }
667  if ($err) {
668  $sug[] = _("clic to the ... button to link document correctly");
669  }
670  }
671  return array(
672  "err" => $err,
673  "sug" => $sug
674  );
675  }
676  /**
677  * verify if a link of document is alive
678  * @param string document title use for verification
679  * @param string document identificator use for verification
680  */
681  public function isValidLink($title, $docid)
682  {
683  $err = "";
684  $sug = array();
685  if (trim($title) != "") {
686  if (trim($docid) == "") {
687  $err = _("the document id is empty");
688  } else {
689  $d = new_doc($this->dbaccess, $docid);
690  if (!$d->isAlive()) $err = sprintf(_("the document id [%s] for this attribute is not valid") , $docid);
691  }
692  if ($err) {
693  $sug[] = _("clic to the [...] button to link document correctly");
694  }
695  } else {
696  if (trim($docid) != "") $err = _("the document title is empty");
697  }
698  return array(
699  "err" => $err,
700  "sug" => $sug
701  );
702  }
703  /**
704  * return true it is a number
705  * use for constraint
706  * @param float $x the number to test
707  * @param float $min the minimum of the number (null to indicate no limit)
708  * @param float $max the maximum of the number (null to indicate no limit)
709  * @return array err if cannot match range
710  */
711  static public function isFloat($x, $min = null, $max = null)
712  {
713  $err = "";
714  if ($x === "" || $x == '-') return "";
715  if (!is_numeric($x)) $err = sprintf(_("[%s] must be a number") , $x);
716  if (($min !== null) && ($x < $min)) $err = sprintf(_("[%s] must be greater than %s") , $x, $min);
717  if (($max !== null) && ($x > $max)) $err = sprintf(_("[%s] must be lower than %s") , $x, $max);
718  return $err;
719  }
720  /**
721  * return true it is a integer
722  * use for constraint
723  * @param float $x the number to test
724  * @param float $min the minimum of the number (null to indicate no limit)
725  * @param float $max the maximum of the number (null to indicate no limit)
726  * @return array err if cannot match range
727  */
728  static public function isInteger($x, $min = null, $max = null)
729  {
730  $err = "";
731  if ($x === "") return "";
732  $err = DocCtrl::isFloat($x, $min, $max);
733  if ($err == "") {
734  if (intval($x) != floatval($x)) $err = sprintf(_("[%s] must be a integer") , $x);
735  }
736 
737  return $err;
738  }
739  /**
740  * return true it is a number
741  * @param string date date JJ/MM/AAAA
742  */
743  static public function isString($x, $p)
744  {
745  $err = "";
746  if ($x === "") return "";
747  if (!preg_match("/^$p$/", $x)) $err = sprintf(_("[%s] must match /%s/") , $x, $p);
748  return array(
749  "err" => $err
750  );
751  }
752  /**
753  * return MENU_ACTIVE if user can execute the specified action
754  * @param string $appname application name
755  * @param string $actname action name
756  * @return int
757  */
758  static public function canExecute($appname, $actname)
759  {
760  global $action;
761 
762  $err = $action->canExecute($actname, $appname);
763 
764  if ($err == "") return MENU_ACTIVE;
765  return MENU_INVISIBLE;
766  }
767  /**
768  * return MENU_ACTIVE if user can edit document
769  * @param string $appname application name
770  * @param string $actname action name
771  * @return int
772  */
773  public function canEditMenu()
774  {
775 
776  $err = $this->canEdit();
777 
778  if ($err == "") return MENU_ACTIVE;
779  return MENU_INVISIBLE;
780  }
781  /**
782  * return MENU_ACTIVE if user can view or modify access in a profil document
783  * @param string $acl acl name
784  * @return int
785  */
786  public function controlAclAccess($acl)
787  {
788  // if ($this->profid != $this->id) return MENU_INVISIBLE;
789  $err = $this->control($acl);
790 
791  if ($err == "") return MENU_ACTIVE;
792  return MENU_INVISIBLE;
793  }
794  /**
795  * return MENU_ACTIVE if profil is actvate
796  * @return int
797  */
799  {
800  $m = $this->controlAclAccess('modifyacl');
801  if ($m == MENU_ACTIVE) $m = $this->profilIsActivate("true");
802  return $m;
803  }
804  /**
805  * return MENU_ACTIVE if user can view or modify access in a profil document
806  * @param string $acl acl name
807  * @return int
808  */
809  public function profilIsActivate($yes = true)
810  {
811  $err = $this->control('modifyacl');
812  if ($err != "") return MENU_INVISIBLE;
813  $err = $this->control('edit');
814  if ($err != "") return MENU_INVISIBLE;
815 
816  $r = ($this->profid == $this->id);
817  if ($yes == 'false') $r = !$r;
818 
819  if ($r) return MENU_ACTIVE;
820  return MENU_INVISIBLE;
821  }
822  /**
823  * Check if the document is a real profile.
824  *
825  * @return bool true if the document is a profile, false if not a profile
826  */
827  function isRealProfile()
828  {
829  return ($this->getAttribute('dpdoc_famid') != null);
830  }
831 }
832 ?>
← centre documentaire © anakeen - published under CC License - Dynacase