18 include_once (
"Class.DocLDAP.php");
19 include_once (
"FDL/Class.DocPerm.php");
20 include_once (
"FDL/Class.VGroup.php");
22 define(
"POS_INIT", 0);
23 define(
"POS_VIEW", 1);
24 define(
"POS_EDIT", 2);
26 define(
"POS_SEND", 4);
28 define(
"POS_OPEN", 5);
29 define(
"POS_EXEC", 5);
30 define(
"POS_CONT", 6);
31 define(
"POS_VACL", 7);
32 define(
"POS_MACL", 8);
33 define(
"POS_ULCK", 9);
34 define(
"POS_CONF", 10);
35 define(
"POS_FORUM", 11);
36 define(
"POS_WASK", 12);
38 define(
"POS_CREATE", 5);
39 define(
"POS_ICREATE", 6);
58 "description" =>
"control initialized"
63 "description" =>
"view document"
67 "description" =>
"send document"
71 "description" =>
"edit document"
75 "description" =>
"delete document"
79 "description" =>
"open folder"
83 "description" =>
"execute search"
87 "description" =>
"modify folder"
91 "description" =>
"view acl"
95 "description" =>
"modify acl"
99 "description" =>
"create doc"
100 ) , #
N_(
"create doc")
103 "description" =>
"unlock unowner locked doc"
104 ) , #
N_(
"unlock unowner locked doc")
107 "description" =>
"create doc manually"
108 ) , #
N_(
"create doc manually")
109 "confidential" => array(
111 "description" =>
"view confidential"
112 ) , #
N_(
"view confidential")
115 "description" =>
"edit forum"
116 ) , #
N_(
"edit forum")
119 "description" =>
"view answers"
120 ) #
N_(
"view answers")
128 if (isset($action)) {
129 $this->userid = $action->parent->user->id;
131 if (!isset($this->attributes->attr)) $this->attributes->attr = array();
137 return ($this->profid != 0);
142 if ($this->
id == $this->profid) {
144 if ($this->doctype ==
'P') $this->
exec_query(
"update doc set profid=-profid where profid=" . $this->
id .
" and locked != -1;");
157 if ($this->
id == $this->profid) {
159 $this->
exec_query(
"delete from docperm where docid=" . $this->
id);
175 $perm->userid = $this->userid;
179 if (!
$perm->IsAffected()) {
187 if ($this->doctype ==
'P') $this->
exec_query(
"update doc set profid=-profid where profid=-" . $this->
id .
" and locked != -1;");
203 if (!is_numeric($profid)) $profid =
getIdFromName($this->dbaccess, $profid);
204 if (empty($profid)) {
207 $this->profid = $profid;
208 if (($profid > 0) && ($profid != $this->
id)) {
210 $pdoc =
new_Doc($this->dbaccess, $profid);
211 if ($pdoc->getValue(
"DPDOC_FAMID") > 0) {
213 $this->dprofid = $profid;
220 if ($pdoc->profid == 0) $this->profid = - $profid;
222 } elseif (($profid > 0) && ($profid == $this->
id)) {
239 if ($this->
id == 0)
return;
240 if ($dprofid == 0) $dprofid = $this->dprofid;
241 if ($dprofid <= 0)
return;
243 $pdoc =
new_Doc($this->dbaccess, $dprofid);
244 $pfamid = $pdoc->getValue(
"DPDOC_FAMID");
246 if ($this->profid != $this->
id) {
248 $this->
modify(
true, array(
254 $query->AddQuery(
"docid=" . $pdoc->id);
255 $tacl =
$query->Query(0, 0,
"TABLE");
256 if (!is_array($tacl)) {
261 foreach ($tacl as $v) {
263 $tgnum[] = $v[
"userid"];
266 if (count($tgnum) > 0) {
269 $tg =
$query->Query(0, 0,
"TABLE");
271 foreach ($tg as $vg) {
272 $tnum[$vg[
"num"]] = $vg[
"id"];
276 $this->
exec_query(
"delete from docperm where docid=" . $this->
id);
277 if ($fromdocidvalues == 0) $fromdocidvalues = & $this;
278 foreach ($tacl as $v) {
286 $aid = $tnum[$v[
"userid"]];
287 $duid = $fromdocidvalues->getValue($aid);
288 if ($duid ==
"") $duid = $fromdocidvalues->getParamValue($aid);
290 $duid = str_replace(
"<BR>",
"\n", $duid);
291 $tduid = $this->_val2array($duid);
292 foreach ($tduid as $duid) {
294 $docu =
getTDoc($fromdocidvalues->dbaccess, intval($duid));
295 $tuid[] = $docu[
"us_whatid"];
302 foreach ($tuid as $ku =>
$uid) {
304 $vupacl[
$uid] = (intval($vupacl[
$uid]) | intval($v[
"upacl"]));
305 $vunacl[
$uid] = (intval($vunacl[$uid]) | intval($v[
"unacl"]));
346 if (!isset($this->dacls[$aclname])) {
347 return sprintf(_(
"unknow privilege %s") , $aclname);
349 $pos = $this->dacls[$aclname][
"pos"];
351 if (!is_numeric(
$uid)) {
354 $udoc =
new_Doc($this->dbaccess, $uiid);
355 if ($udoc->isAlive())
$uid = $udoc->getValue(
"us_whatid");
359 if (!is_numeric(
$uid)) {
361 $vg =
new VGroup($this->dbaccess, strtolower(
$uid));
362 if (!$vg->isAffected()) {
364 $ddoc =
new_Doc($this->dbaccess, $this->getValue(
"dpdoc_famid"));
365 $oa = $ddoc->getAttribute(
$uid);
366 if ($oa->type ==
"docid") {
370 }
else $err = sprintf(_(
"unknow virtual user identificateur %s") ,
$uid);
381 if ($deletecontrol) {
382 if ($negativecontrol)
$perm->UnsetControlN($pos);
383 else $perm->UnsetControlP($pos);
385 if ($negativecontrol)
$perm->SetControlN($pos);
386 else $perm->SetControlP($pos);
405 return $this->ModifyControl(
$uid, $aclname,
false, $negativecontrol);
418 return $this->ModifyControl(
$uid, $aclname,
true, $negativecontrol);
427 if (!is_numeric($cvid)) $cvid =
getIdFromName($this->dbaccess, $cvid);
439 if ($this->profid ==
$docid) {
440 if (!isset($this->uperm)) {
445 if (
$perm->IsAffected()) $this->uperm =
$perm->uperm;
446 else $this->uperm =
$perm->getUperm(
$docid, $this->userid);
448 return $this->ControlUp($this->uperm, $aclname);
454 if (
$perm->isAffected()) $uperm =
$perm->uperm;
455 else $uperm =
$perm->getUperm(
$docid, $this->userid);
456 return $this->ControlUp($uperm, $aclname);
474 if (
$perm->isAffected()) $uperm =
$perm->uperm;
477 return $this->
controlUp($uperm, $aclname);
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);
491 return sprintf(_(
"unknow privilege %s") , $aclname);
501 if (isset($this->dacls[$aclname])) {
502 $pos = $this->dacls[$aclname][
"pos"];
504 if ($this->getValue(
"DPDOC_FAMID") > 0) {
506 if (!isset($this->pdoc)) {
509 if (
$err !=
"")
return "getUsersForAcl:" .
$err;
510 $pdoc->setProfil($this->profid, $this->doc);
511 $this->pdoc = & $pdoc;
518 if ($pdoc) $pdocid = $pdoc->id;
519 else $pdocid = $this->profid;
522 $query->AddQuery(
"docid=" . $pdocid);
523 $query->AddQuery(sprintf(
"(upacl & %d) != 0", 1 << $pos));
524 $tperm =
$query->Query(0, 0,
"TABLE");
528 foreach ($tperm as
$perm) {
529 $u->select($perm[
"userid"]);
531 if (
$u->isgroup ==
'Y') {
532 $ru+=
$u->GetRUsersList(
$u->id);
534 $ru[
$u->id] =
$u->getValues();
539 foreach ($ru as $k => $v) {
540 if ($v[
"isgroup"] ==
"Y") unset($ru[$k]);
551 if ($this->getAttribute(
"dpdoc_famid")) {
553 include_once (
"FDL/Class.SearchDoc.php");
554 if ($this->getValue(
"dpdoc_famid") > 0) {
558 $s->addFilter(
"dprofid = %d", $this->
id);
559 $s->setObjectReturn();
561 while (
$doc =
$s->nextDoc()) {
562 $doc->computeDProfil();
566 $s->addFilter(
"profid = %d", $this->
id);
567 $s->setObjectReturn();
569 while (
$doc =
$s->nextDoc()) {
570 $doc->setProfil($this->
id);
576 $s->addFilter(
"dprofid = %d", $this->
id);
577 $s->setObjectReturn();
579 while (
$doc =
$s->nextDoc()) {
580 $doc->setProfil($this->
id);
603 if ($Email[0] ==
"<") {
604 $sug[] = _(
"<it's a message>");
606 if (preg_match(
"/^[_\.0-9\/'?$&\+~`%|*a-z=^{}-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$/i", $Email)) {
609 $err = _(
"the email syntax is like : john.doe@anywhere.org");
610 if (!preg_match(
"/@/", $Email)) {
611 $err = _(
"the email must containt the @ character");
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");
634 list($dd, $mm, $yy) = explode(
"/", $date);
638 $ti = mktime(0, 0, 0, $mm, $dd + 1, $yy);
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());
661 if (trim(
$docid) ==
"")
$err = _(
"need to select the document with the list");
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);
668 $sug[] = _(
"clic to the ... button to link document correctly");
687 $err = _(
"the document id is empty");
689 $d = new_doc($this->dbaccess,
$docid);
690 if (!
$d->isAlive())
$err = sprintf(_(
"the document id [%s] for this attribute is not valid") ,
$docid);
693 $sug[] = _(
"clic to the [...] button to link document correctly");
696 if (trim(
$docid) !=
"")
$err = _(
"the document title is empty");
711 static public function isFloat($x, $min = null, $max = null)
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);
728 static public function isInteger($x, $min = null, $max = null)
731 if ($x ===
"")
return "";
734 if (intval($x) != floatval($x))
$err = sprintf(_(
"[%s] must be a integer") , $x);
746 if ($x ===
"")
return "";
747 if (!preg_match(
"/^$p$/", $x))
$err = sprintf(_(
"[%s] must match /%s/") , $x, $p);
776 $err = $this->canEdit();
789 $err = $this->control($acl);
811 $err = $this->control(
'modifyacl');
813 $err = $this->control(
'edit');
817 if ($yes ==
'false')
$r = !
$r;
829 return ($this->getAttribute(
'dpdoc_famid') != null);