16 include_once (
"Class.DocLDAP.php");
17 include_once (
"FDL/Class.DocPerm.php");
18 include_once (
"FDL/Class.VGroup.php");
20 define(
"POS_INIT", 0);
21 define(
"POS_VIEW", 1);
22 define(
"POS_EDIT", 2);
24 define(
"POS_SEND", 4);
26 define(
"POS_OPEN", 5);
27 define(
"POS_EXEC", 5);
28 define(
"POS_CONT", 6);
29 define(
"POS_VACL", 7);
30 define(
"POS_MACL", 8);
31 define(
"POS_ULCK", 9);
32 define(
"POS_CONF", 10);
33 define(
"POS_WASK", 12);
35 define(
"POS_CREATE", 5);
36 define(
"POS_ICREATE", 6);
63 "description" =>
"control initialized"
68 "description" =>
"view document"
72 "description" =>
"send document"
76 "description" =>
"edit document"
80 "description" =>
"delete document"
84 "description" =>
"open folder"
88 "description" =>
"execute search"
92 "description" =>
"modify folder"
96 "description" =>
"view acl"
100 "description" =>
"modify acl"
101 ) , #
N_(
"modifyacl")
104 "description" =>
"create doc"
105 ) , #
N_(
"create doc")
108 "description" =>
"unlock unowner locked doc"
109 ) , #
N_(
"unlock unowner locked doc")
112 "description" =>
"create doc manually"
113 ) , #
N_(
"create doc manually")
114 "confidential" => array(
116 "description" =>
"view confidential"
117 ) , #
N_(
"view confidential")
120 "description" =>
"view answers"
121 ) #
N_(
"view answers")
172 static private $globalDocPermLock =
false;
178 if (isset($action)) {
179 $app = $action->parent;
180 $this->userid =
$app->user->id;
183 if (!isset($this->attributes->attr)) {
184 if (!isset($this->attributes)) $this->attributes =
new stdClass();
185 $this->attributes->attr = array();
192 return ($this->profid != 0);
197 if ($this->
id == $this->profid) {
199 if ($this->doctype ==
'P') $this->
exec_query(
"update doc set profid=-profid where profid=" . $this->
id .
" and locked != -1;");
202 $this->
modify(
true, array(
213 if ($this->
id == $this->profid) {
216 $this->
exec_query(sprintf(
"delete from docperm where docid=%d", $this->
id));
217 $this->
exec_query(sprintf(
"delete from docpermext where docid=%d", $this->
id));
219 $this->
exec_query(sprintf(
"delete from docperm where docid=%d and userid=%d", $this->
id,
$userid));
220 $this->
exec_query(sprintf(
"delete from docpermext where docid=%d and userid=%d", $this->
id,
$userid));
233 $perm =
new DocPerm($this->dbaccess, array(
240 if (!$perm->IsAffected()) {
248 if ($this->doctype ==
'P') $this->
exec_query(
"update doc set profid=-profid where profid=-" . $this->
id .
" and locked != -1;");
270 $this->views =
'{0}';
276 if ($pdoc->getRawValue(
"DPDOC_FAMID") > 0) {
286 if ($pdoc->profid == 0) $this->profid = -
$profid;
308 private function computeDProfilExt(
$dprofid, $fromdocidvalues = null)
311 if (count($this->extendedAcls) == 0)
return '';
313 $tVgroup2attrid = array();
316 $tacl =
$query->Query(0, 0,
"TABLE");
317 if (!is_array($tacl)) {
321 if (!$tacl)
return '';
323 foreach ($tacl as $v) {
325 $tgnum[] = $v[
"userid"];
328 if (count($tgnum) > 0) {
331 $tg =
$query->Query(0, 0,
"TABLE");
333 foreach ($tg as $vg) {
334 $tVgroup2attrid[$vg[
"num"]] = $vg[
"id"];
338 $this->
exec_query(sprintf(
"delete from docpermext where docid=%d", $this->
id));
339 if ($fromdocidvalues == null) $fromdocidvalues = & $this;
341 foreach ($tacl as $v) {
345 $aid = $tVgroup2attrid[$v[
"userid"]];
349 $duid = $fromdocidvalues->getRawValue($aid);
350 if ($duid ==
"") $duid = $fromdocidvalues->getFamilyParameterValue($aid);
352 $duid = str_replace(
"<BR>",
"\n", $duid);
354 foreach ($tduid as $duid) {
356 $docu =
getTDoc($fromdocidvalues->dbaccess, intval($duid));
357 $greenUid[$docu[
"us_whatid"] . $v[
"acl"]] = array(
358 "uid" => $docu[
"us_whatid"],
371 foreach ($greenUid as $ku => $uid) {
373 $pe->userid = $uid[
"uid"];
374 $pe->acl = $uid[
"acl"];
390 if ($this->
id == 0)
return '';
396 $tVgroup2attrid = array();
398 $pfamid = $pdoc->getRawValue(
"DPDOC_FAMID");
400 if ($this->profid != $this->
id) {
402 $this->
modify(
true, array(
408 $query->AddQuery(sprintf(
"docid=%d", $pdoc->id));
409 $tacl =
$query->Query(0, 0,
"TABLE");
410 if (!is_array($tacl)) {
415 foreach ($tacl as $v) {
417 $tgnum[] = $v[
"userid"];
420 if (count($tgnum) > 0) {
423 $tg =
$query->Query(0, 0,
"TABLE");
425 foreach ($tg as $vg) {
426 $tVgroup2attrid[$vg[
"num"]] = $vg[
"id"];
430 $point = uniqid(
"dcp:docperm");
432 if (!self::$globalDocPermLock) {
436 $this->
exec_query(sprintf(
"delete from docperm where docid=%d", $this->
id));
437 if ($fromdocidvalues == null) $fromdocidvalues = & $this;
439 foreach ($tacl as $v) {
447 $aid = $tVgroup2attrid[$v[
"userid"]];
451 $duid = $fromdocidvalues->getRawValue($aid);
452 if ($duid ==
"") $duid = $fromdocidvalues->getFamilyParameterValue($aid);
454 $duid = str_replace(
"<BR>",
"\n", $duid);
456 foreach ($tduid as $duid) {
458 $docu =
getTDoc($fromdocidvalues->dbaccess, intval($duid));
459 if (!is_array($docu)) {
461 $errorMessage =
ErrorCode::getError(
'DOC0127', var_export($duid,
true) , var_export($aid,
true));
462 $this->log->error($errorMessage);
464 } elseif (!array_key_exists(
'us_whatid', $docu)) {
465 $errorMessage =
ErrorCode::getError(
'DOC0128', var_export($duid,
true) , var_export($aid,
true));
466 $this->log->error($errorMessage);
468 } elseif (empty($docu[
'us_whatid'])) {
470 $errorMessage =
ErrorCode::getError(
'DOC0129', var_export($duid,
true) , var_export($aid,
true));
471 $this->log->error($errorMessage);
474 $tuid[] = $docu[
"us_whatid"];
480 foreach ($tuid as $ku => $uid) {
482 if (($v[
"upacl"] & 2) && $uid) $greenUid[$uid] = $uid;
483 if (!isset($vupacl[$uid])) $vupacl[$uid] = 0;
484 $vupacl[$uid] = (intval($vupacl[$uid]) | intval($v[
"upacl"]));
486 $perm =
new DocPerm($this->dbaccess, array(
490 $perm->upacl = $vupacl[$uid];
492 if ($perm->isAffected())
$err = $perm->modify();
504 $this->views =
'{' . implode(
',', $greenUid) .
'}';
505 $this->Modify(
true, array(
508 $err.= $this->computeDProfilExt($pdoc->id, $fromdocidvalues);
518 if ($this->dprofid) {
521 if ($this->profid == $this->
id) {
522 simpleQuery($this->dbaccess, sprintf(
"select userid from docperm where docid=%d and upacl & 2 != 0", $this->
id) , $uids,
true,
false);
523 $this->views =
'{' . implode(
',', $uids) .
'}';
524 $this->
modify(
true, array(
529 simpleQuery($this->dbaccess, sprintf(
"update doc set views='%s' where profid=%d and (dprofid is null or dprofid = 0)", $this->views, $this->
id));
533 if ($this->profid > 0) {
534 simpleQuery($this->dbaccess, sprintf(
"select views from docread where id=%d", $this->profid) , $view,
true,
true);
538 $this->views = $view;
540 $this->
modify(
true, array(
553 return ($this->getAttribute(
"dpdoc_famid") != null);
563 private function modifyExtendedControl($uName, $aclname, $deletecontrol =
false)
566 $uid = $this->getUid($uName);
567 $eacl =
new DocPermExt($this->dbaccess, array(
572 if ($deletecontrol) {
573 if ($eacl->isAffected())
$err = $eacl->Delete();
576 if (!$eacl->isAffected()) {
577 $eacl->userid = $uid;
578 $eacl->acl = $aclname;
591 private function getUid($accountReference)
600 $udoc =
new_Doc($this->dbaccess, $uiid);
601 if ($udoc->isAlive()) $accountReference = $udoc->getRawValue(
"us_whatid");
610 $vg =
new VGroup($this->dbaccess, strtolower($accountReference));
611 if (!$vg->isAffected()) {
613 $ddoc =
new_Doc($this->dbaccess, $this->getRawValue(
"dpdoc_famid"));
614 $oa = $ddoc->getAttribute($accountReference);
615 if (($oa->type ==
"docid") || ($oa->type ==
"account")) {
618 $accountReference = $vg->num;
624 $accountReference = $vg->num;
627 return $accountReference;
640 if (!isset($this->dacls[$aclname])) {
641 return sprintf(_(
"unknow privilege %s") , $aclname);
643 $pos = $this->dacls[$aclname][
"pos"];
644 $uid = $this->getUid($uid);
647 $perm =
new DocPerm($this->dbaccess, array(
651 if ($deletecontrol) {
652 $perm->UnsetControlP($pos);
654 $perm->SetControlP($pos);
656 if ($perm->isAffected())
$err = $perm->modify();
674 return $this->modifyExtendedControl($uid, $aclname,
false);
682 return (!empty($this->extendedAcls[$aclname]));
695 return $this->modifyExtendedControl($uid, $aclname,
true);
697 return $this->ModifyControl($uid, $aclname,
true);
725 return $this->ControlUp(
$uperm, $aclname);
727 if ($this->profid ==
$docid) {
728 if (!isset($this->uperm)) {
731 return $this->ControlUp($this->uperm, $aclname);
734 return $this->ControlUp(
$uperm, $aclname);
752 if (!$grant)
$err = sprintf(_(
"no privilege %s for %s [%d]") , $aclname, $this->title, $this->
id);
765 $perm =
new DocPerm($this->dbaccess, array(
770 if ($perm->isAffected())
$uperm = $perm->uperm;
784 if (isset($this->dacls[$aclname])) {
785 return ((
$uperm & (1 << ($this->dacls[$aclname][
"pos"]))) != 0) ?
"" : sprintf(_(
"no privilege %s for %s [%d]") , $aclname, $this->title, $this->
id);
787 return sprintf(_(
"unknow privilege %s") , $aclname);
799 if (isset($this->dacls[$aclname])) {
800 $pos = $this->dacls[$aclname][
"pos"];
802 if ($this->getRawValue(
"DPDOC_FAMID") > 0) {
804 if (!isset($this->pdoc)) {
807 if (
$err !=
"")
return "getUsersForAcl:" .
$err;
808 $pdoc->setProfil($this->profid, $this->doc);
809 $this->pdoc = & $pdoc;
816 if ($pdoc) $pdocid = $pdoc->id;
820 $query->AddQuery(
"docid=" . $pdocid);
821 $query->AddQuery(sprintf(
"(upacl & %d) != 0", 1 << $pos));
822 $tperm =
$query->Query(0, 0,
"TABLE");
826 foreach ($tperm as $perm) {
827 $u->select($perm[
"userid"]);
829 if ($u->accounttype !=
'U') {
830 $ru+= $u->GetRUsersList($u->id);
832 $ru[$u->id] = $u->getValues();
837 foreach ($ru as $k => $v) {
838 if ($v[
"accounttype"] ==
"G") unset($ru[$k]);
851 include_once (
"FDL/Class.SearchDoc.php");
852 if ($this->getRawValue(
"dpdoc_famid") > 0) {
857 if (!empty(self::$savepoint[intval($this->dbid) ])) {
859 simpleQuery($this->dbaccess,
"lock table docperm in exclusive mode");
860 self::$globalDocPermLock =
true;
863 $s->addFilter(
"dprofid = %d", $this->
id);
864 $s->setObjectReturn();
865 $s->overrideViewControl();
867 while (
$doc =
$s->getNextDoc()) {
868 $doc->computeDProfil();
872 $s->addFilter(
"profid = %d", $this->
id);
873 $s->setObjectReturn();
874 $s->overrideViewControl();
876 while (
$doc =
$s->getNextDoc()) {
877 $doc->setProfil($this->
id);
883 $s->addFilter(
"dprofid = %d", $this->
id);
884 $s->setObjectReturn();
885 $s->overrideViewControl();
887 while (
$doc =
$s->getNextDoc()) {
888 $doc->setProfil($this->
id);
911 if ($Email[0] ==
"<") {
912 $sug[] = _(
"<it's a message>");
914 if (preg_match(
"/^[_\.0-9\/'?$&\+~`%|*a-z=^{}-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$/i", $Email)) {
917 $err = _(
"the email syntax is like : john.doe@anywhere.org");
918 if (!preg_match(
"/@/", $Email)) {
919 $err = _(
"the email must containt the @ character");
940 if (!preg_match(
"|^[0-9]{4}-[0-9]{2}-[0-9]{2}|", $date)) {
941 $err = _(
"the date syntax must be like : AAAA-MM-DD");
944 list($yy, $mm, $dd) = explode(
"-", $date);
948 $ti = mktime(0, 0, 0, $mm, $dd + 1, $yy);
950 $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()));
951 $sug[] = date(
"d/m/Y", time());
972 if (trim(
$docid) ==
"")
$err = _(
"need to select the document with the list");
974 $d = new_doc($this->dbaccess,
$docid);
975 if (!
$d->isAlive())
$err = sprintf(_(
"the document id [%s] for this attribute is not valid") ,
$docid);
976 else if (
$d->title !=
$title)
$err = sprintf(_(
"the title of document [%s] is not conform to original [%s]") ,
$title,
$d->title);
979 $sug[] = _(
"clic to the ... button to link document correctly");
999 $err = _(
"the document id is empty");
1001 $d = new_doc($this->dbaccess,
$docid);
1002 if (!
$d->isAlive())
$err = sprintf(_(
"the document id [%s] for this attribute is not valid") ,
$docid);
1005 $sug[] = _(
"clic to the [...] button to link document correctly");
1008 if (trim(
$docid) !=
"")
$err = _(
"the document title is empty");
1023 static public function isFloat($x, $min = null, $max = null)
1026 if ($x ===
"" || $x ==
'-')
return "";
1027 if (!is_numeric($x))
$err = sprintf(_(
"[%s] must be a number") , $x);
1028 if (($min !== null) && ($x < $min))
$err = sprintf(_(
"[%s] must be greater than %s") , $x, $min);
1029 if (($max !== null) && ($x > $max))
$err = sprintf(_(
"[%s] must be lower than %s") , $x, $max);
1040 static public function isInteger($x, $min = null, $max = null)
1042 if ($x ===
"")
return "";
1046 if (floatval($x) < - floatval(pow(2, 31)) || floatval($x) > floatval(pow(2, 31) - 1)) {
1048 return sprintf(_(
"[%s] must be between %s and %s") , $x, -floatval(pow(2, 31)) , floatval(pow(2, 31) - 1));
1050 if (intval($x) != floatval($x)) {
1051 return sprintf(_(
"[%s] must be a integer") , $x);
1065 if ($x ===
"")
return "";
1066 if (!preg_match(
"/^$p$/", $x))
$err = sprintf(_(
"[%s] must match /%s/") , $x, $p);
1096 $err = $this->canEdit();
1109 $err = $this->control($acl);
1131 $err = $this->control(
'modifyacl');
1133 $err = $this->control(
'edit');
1137 if ($yes ==
'false')
$r = !
$r;
static isGranted($userid, $acl, $profid, $strict=false)
static isFutureDate($date)
delControl($uid, $aclname)
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
addControl($uid, $aclname)
stringDateToIso($date, $format=false, $withT=false)
modifyControl($uid, $aclname, $deletecontrol=false)
exec_query($sql, $lvl=0, $prepare=false)
static rawValueToArray($v)
static canExecute($appname, $actname)
static getError($code, $args=null)
controlUp($uperm, $aclname)
setControl($userctrl=true)
modify($nopost=false, $sfields="", $nopre=false)
static getUperm($profid, $userid, $strict=false)
isValidLink($title, $docid)
static isInteger($x, $min=null, $max=null)
__construct($dbaccess= '', $id= '', $res= '', $dbid=0)
lockPoint($exclusiveLock, $exclusiveLockPrefix= '')
recomputeProfiledDocument()
controlId($docid, $aclname, $strict=false)
setProfil($profid, $fromdocidvalues=null)
removeControl($userid=-1)
if($updateExistingTable) $point
controlExtId($docid, $aclname, $strict=false)
static isFloat($x, $min=null, $max=null)
new_Doc($dbaccess, $id= '', $latest=false)
GetSqlCond($Table, $column, $integer=false)
setMaxExecutionTimeTo($limit)
if(($docid!==0)&&(!is_numeric($docid))) $query
getIdFromName($dbaccess, $name)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
if($file) if($subject==""&&$file) if($subject=="") $err
profilIsActivate($yes=true)
computeDProfil($dprofid=0, $fromdocidvalues=null)
controlUserId($docid, $uid, $aclname)
isDocLinked($title, $docid)