15 include_once (
"FDL/Class.Doc.php");
29 private $onlyAttributes = null;
38 if (isset($config->latest))
$latest = $config->latest;
41 if ($config === null) {
42 $config =
new stdClass();
43 $config->onlyValues = null;
45 if ($id || is_object(
$doc)) {
47 else $this->doc = new_doc($this->dbaccess, $id,
$latest);
48 if (!$this->doc->isAffected()) $this->error = sprintf(_(
"document %s not exist") , $id);
51 if ($this->doc->doctype !=
'C' || (!empty($config->onlyValues))) $this->error = $this->doc->control(
'view');
52 if ($this->error) $this->error = sprintf(_(
"no privilege view for %d") , $id);
53 elseif ($this->doc->isConfidential()) $this->error = sprintf(_(
"confidential document"));
55 if ($this->error) $this->doc = null;
57 $this->doc->refresh();
58 $mask = $this->doc->getDefaultView(
false,
"mask");
59 if ($mask) $this->doc->applyMask($mask);
71 if ($temporary) $cdoc =
createTmpDoc($this->dbaccess, $familyId);
72 else $cdoc =
createDoc($this->dbaccess, $familyId);
76 $this->
setError(sprintf(_(
"cannot create document for family [%s]") , $familyId));
82 return is_object($this->doc);
90 if ($this->doc)
return $this->doc->isAlive();
99 $this->_properties = null;
100 $this->error = $this->doc->control(
'view');
101 if ($this->error) unset($this->doc);
106 return $this->doc->getAttribute($aid);
113 $this->onlyAttributes = $attrids;
131 if ($this->doc->doctype ==
'C') {
132 if (isset($this->doc->addfields)) {
133 foreach ($this->doc->addfields as $aid) {
134 $lvalues[$aid] = $this->doc->$aid;
138 $nattr = $this->doc->getNormalAttributes();
139 if ($this->onlyAttributes === null) $this->doc->applyMask();
140 $isoDate = (
getParam(
"DATA_LCDATE") ==
'iso');
141 foreach ($nattr as $k => $v) {
142 if ($this->onlyAttributes !== null && (!in_array($v->id, $this->onlyAttributes)))
continue;
144 if ($v->mvisibility !=
"I" && (!empty($this->doc->$k)) && $v->getOption(
"autotitle") !=
"yes") {
145 if ($v->inArray() || ($v->getOption(
"multiple") ==
"yes")) $lvalues[$v->id] = $this->doc->getMultipleRawValues($v->id);
146 else $lvalues[$v->id] = $this->doc->getRawValue($v->id);
148 if (($v->type ==
"docid" || $v->type ==
"account") && ($v->visibility !=
'H')) {
149 $isLatest = $v->getOption(
"docrev",
"latest") ==
"latest";
150 if ($v->isMultiple()) {
151 $lv = $lvalues[$v->id];
153 foreach ($lv as $kv => $aDocid) {
154 if (strpos($aDocid,
'<BR>') !==
false) {
156 $tt = explode(
'<BR>', $aDocid);
157 $lvalues[$v->id][$kv] = $tt;
159 foreach ($tt as $vv) {
161 if ($rtitle ===
false) $rtitle = $v->getOption(
"noaccesstext", _(
"information access deny"));
162 $trtitle[] = $rtitle;
164 $ltitle[] = $trtitle;
168 if ($rtitle ===
false) $rtitle = $v->getOption(
"noaccesstext", _(
"information access deny"));
172 $lvalues[$v->id .
"_title"] = $ltitle;
175 if ($lvalues[$v->id .
"_title"] ===
false) $lvalues[$v->id .
"_title"] = $v->getOption(
"noaccesstext", _(
"information access deny"));
179 } elseif (($v->type ==
"thesaurus")) {
180 $lvalues[$v->id .
"_title"] = $this->doc->getTitle($this->doc->getRawValue($v->id));
181 if ($v->inArray() || ($v->getOption(
"multiple") ==
"yes")) $lvalues[$v->id .
"_title"] = $this->doc->rawValueToArray($lvalues[$v->id .
"_title"]);
182 } elseif ($isoDate && ($v->type ==
'date' || $v->type ==
'timestamp')) {
183 if (is_array($lvalues[$v->id])) {
184 foreach ($lvalues[$v->id] as $kd => $vd) {
185 $lvalues[$v->id][$kd] = StringDateToIso($vd,
false);
187 }
else $lvalues[$v->id] = StringDateToIso($lvalues[$v->id],
false);
202 $oa = $this->doc->getAttribute($aid);
203 if ($oa && ($oa->mvisibility !=
"I")) {
204 if ($oa->inArray())
return $this->doc->getMultipleRawValues($oa->id);
205 else return $this->doc->getRawValue($oa->id);
220 $oa = $this->doc->getAttribute($aid);
221 $oa->phpfile =
"fdl.php";
223 $oa->phpfunc =
"lfamily(D,'$famid,'$key):theid,thetitle";
224 include_once (
"FDL/enum_choice.php");
225 $res =
getResPhpFunc($this->doc, $oa, $rarg, $outselect, $outval);
227 foreach ($res as $v) {
246 $oa = $this->doc->getAttribute($aid);
247 if ($oa && ($oa->mvisibility !=
"I"))
$err = $this->doc->setValue($oa->id,
$nv);
248 if (
$err ==
"")
return true;
257 $this->doc->fields[] = $key;
258 $this->doc->$key =
$value;
259 if ($this->_properties) $this->_properties[$key] =
$value;
266 if (
$d === null)
$d =
new Doc();
282 foreach ($dFields as $k => $v) {
283 $props[$v] = $this->doc->$v;
285 if (isset($this->doc->addfields)) {
286 foreach ($this->doc->addfields as $k => $v) {
287 $props[$v] = $this->doc->$v;
290 $props[
"icon"] = $this->doc->getIcon();
291 $props[
"title"] = $this->doc->getTitle();
292 $props[
"labelstate"] = $this->doc->state ? _($this->doc->state) :
'';
293 $props[
"defdoctype"] = $this->doc->defDoctype;
295 if ($props[
'id'] > 0) {
296 $props[
"mdate"] = strftime(
"%Y-%m-%d %H:%M:%S", $this->doc->revdate);
297 $props[
"readonly"] = ($this->doc->canEdit() !=
"");
299 $props[
"lockdomainid"] = intval($this->doc->lockdomainid);
301 if ($props[
"postitid"]) $props[
"postitid"] = $this->doc->rawValueToArray($props[
"postitid"]);
302 else $props[
"postitid"] = array();
303 $props[
"id"] = intval($props[
"id"]);
304 $props[
"initid"] = intval($props[
"initid"]);
305 $props[
"locked"] = intval($props[
"locked"]);
306 $props[
"revision"] = intval($props[
"revision"]);
307 $props[
"wid"] = intval($props[
"wid"]);
308 $props[
"cvid"] = intval($props[
"cvid"]);
309 $props[
"prelid"] = intval($props[
"prelid"]);
310 $props[
"profid"] = intval($props[
"profid"]);
311 $props[
"dprofid"] = intval($props[
"dprofid"]);
312 $props[
"fromid"] = intval($props[
"fromid"]);
313 $props[
"allocated"] = intval($props[
"allocated"]);
314 $props[
"owner"] = intval($props[
"owner"]);
315 if ($props[
"domainid"]) $props[
"domainid"] = $this->doc->rawValueToArray($props[
"domainid"]);
316 else $props[
"domainid"] = array();
318 if ($props[
"allocated"] > 0) $props[
"allocatedname"] = USER::getDisplayName(abs($props[
"allocated"]));
319 $props[
"ownername"] = USER::getDisplayName(abs($props[
"owner"]));
321 if (($this->doc->locked > 0) || ($this->doc->locked < - 1)) $props[
"locker"] = USER::getDisplayName(abs($props[
"locked"]));
325 $props[
"fromname"] = $this->doc->fromname;
326 $props[
"fromtitle"] = $this->doc->fromtitle;
328 if ($this->doc->doctype ==
'C') {
329 $props[
"generateVersion"] = doubleval($this->doc->genversion);
330 if ($complete) $props[
"configuration"] = $this->doc->getConfiguration();
333 $fdoc = $this->doc->getFamilyDocument();
334 if ($fdoc->isAffected()) {
335 $props[
"fromname"] = $fdoc->name;
336 $props[
"fromtitle"] = $fdoc->getTitle();
337 $props[
"generateVersion"] = doubleval($fdoc->genversion);
338 $props[
"configuration"] = $fdoc->getConfiguration();
342 if ($this->doc && $this->doc->wid) {
346 $wd = new_doc($this->dbaccess, $this->doc->wid);
347 if ($wd->isAlive()) {
348 $props[
"colorstate"] = $wd->getColor($this->doc->state);
349 if ($this->doc->locked != - 1) $props[
"activitystate"] = $wd->getActivity($this->doc->state);
357 $this->_properties = $props;
369 $fdoc = $this->doc->getFamilyDocument();
370 if ($this->doc->doctype ==
'C') {
371 $conf = $this->doc->getConfiguration();
373 $conf = $fdoc->getConfiguration();
386 $acls = $this->doc->acls;
387 foreach ($acls as $acl) {
388 if (isset($this->doc->dacls[$acl])) {
391 "description" => $this->doc->dacls[$acl][
"description"],
392 "ldescription" => ($this->doc->dacls[$acl][
"description"]) ? _($this->doc->dacls[$acl][
"description"]) :
'',
393 "control" => $this->doc->control($acl) ==
""
403 $thm = $this->doc->getHisto(
false,
"MODIFY");
404 if (count($thm) > 0)
return $thm[0][
"uname"];
405 else return USER::getDisplayName(abs($this->doc->owner));
412 $idprop = strtolower($idprop);
414 if (isset($this->_properties[$idprop]))
return $this->_properties[$idprop];
428 $listattr = $this->doc->getAttributes();
430 foreach ($listattr as $k => $oa) {
431 if ($oa && ($oa->id != \Adoc::HIDDENFIELD) && ($oa->usefor !=
"Q")) {
432 foreach ($oa as $aid => $v) {
433 if ($aid ==
"options") {
436 foreach ($oa->_topt as $ko => $vo) {
437 if ($vo) $topt[$ko] = $oa->getOption($ko);
439 $attrs[$oa->id][
"options"] = $topt;
441 } elseif (!is_object($v)) $attrs[$oa->id][$aid] = $v;
442 else if ($aid ==
"fieldSet")
if ($v->id != \Adoc::HIDDENFIELD) $attrs[$oa->id][
"parentId"] = $v->id;
443 else $attrs[$oa->id][
"parentId"] = null;
445 $attrs[$oa->id][
'labelText'] = $oa->getLabel();
447 if ($oa->type ==
"enum") {
451 $attrs[$oa->id][
"enumerate"] = $oa->getEnum();
460 return ($this->doc->defDoctype ==
'D' || $this->doc->defDoctype ==
'S');
471 return ($this->doc->getAttribute($aid) !=
false);
478 function getDocument($onlyvalues =
false, $completeprop =
true, $infoprop =
false, $usertags =
false)
481 "error" => $this->error,
482 "properties" => $this->
getProperties($completeprop, $infoprop) ,
485 "requestDate" => date(
'Y-m-d H:i:s') ,
488 if ($this->onlyAttributes !== null) {
489 $out[
"partialDocument"] =
true;
512 $rev = $this->doc->getRevisions(
"TABLE");
514 foreach ($rev as $k => $zdoc) {
516 $tmpdoc->Affect($rdoc);
517 $out[] = $tmpdoc->getDocument($onlyvalues, $completeprop);
529 $clone = $this->doc->duplicate($temporary,
true, $linkfld, $copyfile);
531 if (is_object($clone)) {
534 $clone->disableEditControl();
536 if ($clone->title !=
$title) {
538 $clone->modify(
true, array(
542 $clone->enableEditControl();
560 $out = $this->doc->getHisto($allrevision, $code);
561 foreach (
$out as $k => $v) {
562 $out[$k][
"userName"] = $v[
"uname"];
563 $out[$k][
"userId"] = $v[
"uid"];
564 unset(
$out[$k][
"uname"]);
565 unset(
$out[$k][
"uid"]);
573 $err = $this->doc->canEdit();
577 $olds = $this->doc->getOldRawValues();
578 $needpostmodif = (is_array($olds));
580 $this->doc->refresh();
581 if ($needpostmodif) $this->doc->postStore();
582 $err = $this->doc->modify();
585 $olds = $this->doc->getOldRawValues();
587 if (is_array($olds)) {
588 foreach ($olds as $ka => $va) {
589 $oa = $this->doc->getAttribute($ka);
590 $keys[] = $oa->getLabel();
592 $skeys = implode(
",", $keys);
593 $this->doc->addHistoryEntry(sprintf(_(
"change %s") , $skeys) ,
HISTO_INFO,
"MODIFY");
601 include_once (
"FDL/mailcard.php");
602 $err =
sendCard(
$action, $this->doc->id,
$to,
$cc,
$subject,
"",
true,
$comment,
"",
$bcc,
"html",
true, array() ,
true, $savecopy);
618 $err = $this->doc->lock($auto);
627 $err = $this->doc->unlock($auto);
636 $err = $this->doc->addUtag($this->doc->userid, $tag,
$comment);
645 $err = $this->doc->delUtag($this->doc->userid, $tag);
654 $dbutags = $this->doc->searchUtags();
656 foreach ($dbutags as $k => $v) {
657 $utags[$v[
"tag"]] = $v[
"comment"];
704 $err = $this->doc->setState($state);
711 function delete($really =
false)
714 $err = $this->doc->delete($really);
723 $err = $this->doc->control(
"edit");
725 $err = $this->doc->undelete();
743 function moveTo($movetoid, $fromtoid = null)
747 if (!$fromtoid) $fromtoid = $this->doc->prelid;
749 $da = new_doc($this->dbaccess, $movetoid);
750 if ($da->isAlive()) {
751 if (method_exists($da,
"addFile")) {
755 $err = $da->insertDocument($this->doc->initid);
757 if (($fromtoid) && ($fromtoid != $movetoid)) {
758 $d = new_doc($this->dbaccess, $fromtoid);
760 if (method_exists(
$d,
"delFile")) {
764 $err =
$d->removeDocument($this->doc->initid);
766 $this->doc->prelid = $da->initid;
767 $this->doc->modify(
true, array(
771 }
else $err = sprintf(_(
"document %s is not a folder") ,
$d->getTitle());
775 $this->doc->prelid = $da->initid;
776 $this->doc->modify(
true, array(
782 }
else $err = sprintf(_(
"document %s is not a folder") , $da->getTitle());
792 include_once (
"FDL/modcard.php");
793 foreach ($_FILES as $k => $v) {
795 $oldname = $this->doc->vault_filename($k);
799 if ($this->doc->vault_filename($k) ==
"Unknown") $this->doc->renameFile($k, $oldname);
807 if (!$this->doc)
return false;
809 foreach ($as as $aid => $oa) {
812 if (
$nv ===
'')
$nv =
' ';
814 $oa = $this->doc->getAttribute($aid);
815 if ($oa->isMultiple())
$nv = json_decode(
$nv);
824 if ($this->doc && $this->doc->name ==
'') {
827 $err = $this->doc->setLogicalName($name);
841 return $this->doc->hasWaitingFiles();
847 $la = $this->doc->attributes->getNormalAttributes();
850 foreach (
$la as $at) {
851 if ($at->getOption(
"version") ==
"yes") {
852 $err = $this->doc->setValue($at->id, $version);
854 if ((!
$err) && $usecomment) $this->doc->addHistoryEntry(sprintf(_(
"change version to %s") , $version));
858 if ((
$err ==
"") && (!$hasversion)) {
859 $this->doc->version = trim($version);
861 if ($version ==
"") $this->doc->addHistoryEntry(sprintf(_(
"reset version")));
862 else $this->doc->addHistoryEntry(sprintf(_(
"change version to %s") , $version));
871 if ($this->doc && $this->doc->wid) {
875 $wd = new_doc($this->dbaccess, $this->doc->wid);
876 if (!$wd->isAlive())
return null;
877 $wd->set($this->doc);
878 $ns = $wd->getFollowingStates();
881 foreach ($ns as $state) {
884 foreach ($wd->cycle as $k => $t) {
885 if (($t[
"e1"] == $this->doc->state) && ($t[
"e2"] == $state)) {
892 "transition" => $tlabel,
893 "transitionLabel" => $tlabel ? _($tlabel) :
'',
894 "label" => _($state) ,
895 "color" => $wd->getColor($state)
903 function getAttachedTimers()
906 $timers = $this->doc->getAttachedTimers();
907 foreach ($timers as $k => $v) {
911 $timer = new_doc($this->dbaccess, $v[
"timerid"]);
912 if ($timer->isAlive()) {
913 $iprev = $timer->getPrevisions($v[
"attachdate"], $v[
"tododate"], $v[
"level"]);
914 foreach ($iprev as $pk => $pv) {
915 $iprev[$pk][
"timerid"] = $timer->id;
916 $iprev[$pk][
"timertitle"] = $timer->getTitle();
918 $prev = array_merge($prev, $iprev);
921 foreach ($prev as $k => $v) {
922 $prev[$k][
"local"][
"lstate"] =
"";
923 $prev[$k][
"local"][
"lmethod"] =
"";
924 $prev[$k][
"local"][
"tmailtitle"] =
"";
925 if ($v[
"actions"][
"state"]) $prev[$k][
"local"][
"lstate"] = _($v[
"actions"][
"state"]);
926 else $prev[$k][
"local"][
"lstate"] =
false;
927 if ($v[
"actions"][
"tmail"]) {
928 $prev[$k][
"local"][
"tmailtitle"] = $this->doc->getTitle($v[
"actions"][
"tmail"]);
930 if ($v[
"actions"][
"method"]) $prev[$k][
"local"][
"lmethod"] = _($v[
"actions"][
"method"]);
931 else $prev[$k][
"local"][
"lmethod"] =
false;
932 $prev[$k][
"local"][
"hdelay"] = $this->
humandelay($v[
"execdelay"]);
943 if (
$a[
"execdelay"] > $b[
"execdelay"])
return 1;
944 elseif (
$a[
"execdelay"] < $b[
"execdelay"])
return -1;
953 if ($j > 1)
$s.= sprintf(_(
"%d days") , $j);
954 else $s.= sprintf(_(
"%d day") , $j);
962 if ($j > 1)
$s.= sprintf(_(
"%d hours") , $j);
963 else $s.= sprintf(_(
"%d hour") , $j);
970 if ($j > 1)
$s.= sprintf(_(
"%d minutes") , $j);
971 else $s.= sprintf(_(
"%d minute") , $j);
getResPhpFunc(Doc &$doc, NormalAttribute &$oattr, &$rargids, &$tselect, &$tval, $whttpvars=true, $index="")
cloneDocument($temporary=false, $linkfld=true, $copyfile=false, $title="")
getRevisions($onlyvalues=true, $completeprop=false)
getHistory($allrevision=true, $code="")
addRevision($comment, $version="", $volatile=false)
createDocument($familyId, $temporary=false)
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
addUserTag($tag, $comment)
getDocument($onlyvalues=false, $completeprop=true, $infoprop=false, $usertags=false)
sendCard(Action &$action, $docid, $to, $cc, $subject, $zonebodycard="", $ulink=false, $comment="", $from="", $bcc="", $format="html", $sendercopy=true, $addfiles=array(), $userinfo=null, $savecopy=false)
setVersion($version, $usecomment=true)
getProperties($complete=true, $infoprop=false)
static getRelationTitle($docid, $latest=true, Doc $doc, $docrevOption="", array &$info=array())
setVolatileProperty($key, $value)
__construct($id=0, $config=null, Doc &$doc=null)
allocate($userid, $comment="", $revision=false, $autolock=true)
getParam($name, $def="")
must be in core or global type
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getHttpVars($name, $def="", $scope="all")
getProposalDocuments($aid, $key)
static sortprevision($a, $b)
unallocate($comment="", $revision=false)
setFileValueFromHttpVars()
usePartialDocument(array $attrids)
send($to="", $cc="", $bcc="", $subject="", $comment="", $savecopy=false)
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
insert_file(Doc &$doc, $attrid, $strict=false)
if($file) if($subject==""&&$file) if($subject=="") $err
moveTo($movetoid, $fromtoid=null)
getDocObject($dbaccess, $v, $k=0)