17 include_once (
"FDL/Class.Doc.php");
29 $this->dbaccess =
getParam(
"FREEDOM_DB");
30 if (isset($config->latest))
$latest = $config->latest;
34 else $this->doc = new_doc($this->dbaccess,
$id,
$latest);
35 if (!$this->doc->isAffected()) $this->error = sprintf(_(
"document %s not exist") ,
$id);
38 if ($this->doc->doctype !=
'C' || ($config->onlyValues)) $this->error = $this->doc->control(
'view');
39 if ($this->error) $this->error = sprintf(_(
"no privilege view for %d") ,
$id);
40 elseif ($this->doc->isConfidential()) $this->error = sprintf(_(
"confidential document"));
42 if ($this->error) unset($this->doc);
44 $this->doc->refresh();
45 $mask = $this->doc->getDefaultView(
false,
"mask");
46 if ($mask) $this->doc->applyMask($mask);
58 if ($temporary) $cdoc =
createTmpDoc($this->dbaccess, $familyId);
59 else $cdoc =
createDoc($this->dbaccess, $familyId);
63 $this->
setError(sprintf(_(
"cannot create document for family [%s]") , $familyId));
69 return is_object($this->doc);
77 if ($this->doc)
return $this->doc->isAlive();
83 $this->_properties = null;
84 $this->error = $this->doc->control(
'view');
85 if ($this->error) unset($this->doc);
90 return $this->doc->getAttribute($aid);
107 if ($this->doc->doctype ==
'C') {
108 foreach ($this->doc->addfields as $aid) {
109 $lvalues[$aid] = $this->doc->$aid;
112 $nattr = $this->doc->getNormalAttributes();
113 $this->doc->applyMask();
114 $isoDate = (
getParam(
"DATA_LCDATE") ==
'iso');
115 foreach ($nattr as $k => $v) {
116 if ($v->mvisibility !=
"I" && $this->doc->$k) {
117 if ($v->inArray() || ($v->getOption(
"multiple") ==
"yes")) $lvalues[$v->id] = $this->doc->GetTValue($v->id);
118 else $lvalues[$v->id] = $this->doc->getValue($v->id);
120 if (($v->type ==
"docid") && ($v->visibility !=
'H') && ($v->getOption(
"doctitle") !=
"auto")) {
121 $lvalues[$v->id .
"_title"] = $this->doc->getTitle($this->doc->getValue($v->id));
122 if ($v->inArray() || ($v->getOption(
"multiple") ==
"yes")) $lvalues[$v->id .
"_title"] = $this->doc->_val2array($lvalues[$v->id .
"_title"]);
123 } elseif (($v->type ==
"thesaurus")) {
124 $lvalues[$v->id .
"_title"] = $this->doc->getTitle($this->doc->getValue($v->id));
125 if ($v->inArray() || ($v->getOption(
"multiple") ==
"yes")) $lvalues[$v->id .
"_title"] = $this->doc->_val2array($lvalues[$v->id .
"_title"]);
126 } elseif ($isoDate && ($v->type ==
'date' || $v->type ==
'timestamp')) {
127 if (is_array($lvalues[$v->id])) {
128 foreach ($lvalues[$v->id] as $kd => $vd) {
129 $lvalues[$v->id][$kd] = StringDateToIso($vd,
false);
146 $oa = $this->doc->getAttribute($aid);
147 if ($oa && ($oa->mvisibility !=
"I")) {
148 if ($oa->inArray())
return $this->doc->GetTValue($oa->id);
149 else return $this->doc->GetValue($oa->id);
161 $oa = $this->doc->getAttribute($aid);
162 $oa->phpfile =
"fdl.php";
164 $oa->phpfunc =
"lfamily(D,'$famid,'$key):theid,thetitle";
165 include_once (
"FDL/enum_choice.php");
166 $res =
getResPhpFunc($this->doc, $oa, $rarg, $outselect, $outval);
168 foreach ($res as $v) {
186 $oa = $this->doc->getAttribute($aid);
187 if ($oa && ($oa->mvisibility !=
"I"))
$err = $this->doc->setValue($oa->id,
$nv);
188 if (
$err ==
"")
return true;
197 $this->doc->fields[] = $key;
198 $this->doc->$key =
$value;
199 if ($this->_properties) $this->_properties[$key] =
$value;
210 if ($this->_properties)
return $this->_properties;
214 foreach ($this->doc->fields as $k => $v) {
215 if (is_numeric($k)) $props[$v] = $this->doc->$v;
217 if ($this->doc->addfields) {
218 foreach ($this->doc->addfields as $k => $v) {
219 $props[$v] = $this->doc->$v;
222 $props[
"icon"] = $this->doc->getIcon();
223 $props[
"title"] = $this->doc->getTitle();
224 $props[
"labelstate"] = $this->doc->state ? _($this->doc->state) :
'';
225 $props[
"defdoctype"] = $this->doc->defDoctype;
227 if ($props[
'id'] > 0) {
228 $props[
"mdate"] = strftime(
"%d/%m/%Y %H:%M:%S", $this->doc->revdate);
229 $props[
"readonly"] = ($this->doc->canEdit() !=
"");
231 $props[
"lockdomainid"] = intval($this->doc->lockdomainid);
233 if ($props[
"postitid"]) $props[
"postitid"] = $this->doc->_val2array($props[
"postitid"]);
234 else $props[
"postitid"] = array();
235 $props[
"id"] = intval($props[
"id"]);
236 $props[
"initid"] = intval($props[
"initid"]);
237 $props[
"locked"] = intval($props[
"locked"]);
238 $props[
"revision"] = intval($props[
"revision"]);
239 $props[
"wid"] = intval($props[
"wid"]);
240 $props[
"cvid"] = intval($props[
"cvid"]);
241 $props[
"prelid"] = intval($props[
"prelid"]);
242 $props[
"forumid"] = intval($props[
"forumid"]);
243 $props[
"profid"] = intval($props[
"profid"]);
244 $props[
"dprofid"] = intval($props[
"dprofid"]);
245 $props[
"fromid"] = intval($props[
"fromid"]);
246 $props[
"allocated"] = intval($props[
"allocated"]);
247 $props[
"owner"] = intval($props[
"owner"]);
248 if ($props[
"domainid"]) $props[
"domainid"] = $this->doc->_val2array($props[
"domainid"]);
249 else $props[
"domainid"] = array();
250 if (
getParam(
"DATA_LCDATE") ==
"iso") {
256 if ($props[
"allocated"] > 0) $props[
"allocatedname"] = USER::getDisplayName(abs($props[
"allocated"]));
257 $props[
"ownername"] = USER::getDisplayName(abs($props[
"owner"]));
259 if (($this->doc->locked > 0) || ($this->doc->locked < - 1)) $props[
"locker"] = USER::getDisplayName(abs($props[
"locked"]));
263 $props[
"fromname"] = $this->doc->fromname;
264 $props[
"fromtitle"] = $this->doc->fromtitle;
266 if ($this->doc->doctype ==
'C') {
267 $props[
"generateVersion"] = doubleval($this->doc->genversion);
268 if ($complete) $props[
"configuration"] = $this->doc->getConfiguration();
271 $fdoc = $this->doc->getFamDoc();
272 if (
$fdoc->isAffected()) {
273 $props[
"fromname"] =
$fdoc->name;
274 $props[
"fromtitle"] =
$fdoc->getTitle();
275 $props[
"generateVersion"] = doubleval(
$fdoc->genversion);
276 $props[
"configuration"] =
$fdoc->getConfiguration();
280 if ($this->doc && $this->doc->wid) {
281 $wd = new_doc($this->dbaccess, $this->doc->wid);
282 if ($wd->isAlive()) {
283 $props[
"colorstate"] = $wd->getColor($this->doc->state);
284 if ($this->doc->locked != - 1) $props[
"activitystate"] = $wd->getActivity($this->doc->state);
288 foreach ($this->doc->infofields as $k => $v) $this->doc->infofields[$k][
"label"] = _($v[
"label"]);
289 if ($infoprop) $props[
"informations"] = $this->doc->infofields;
290 $this->_properties = $props;
302 $fdoc = $this->doc->getFamDoc();
303 if ($this->doc->doctype ==
'C') {
304 $conf = $this->doc->getConfiguration();
306 $conf =
$fdoc->getConfiguration();
319 $acls = $this->doc->acls;
320 foreach ($acls as $acl) {
323 "description" => $this->doc->dacls[$acl][
"description"],
324 "ldescription" => ($this->doc->dacls[$acl][
"description"]) ? _($this->doc->dacls[$acl][
"description"]) :
'',
325 "control" => $this->doc->control($acl) ==
""
334 $thm = $this->doc->getHisto(
false,
"MODIFY");
335 if (count($thm) > 0)
return $thm[0][
"uname"];
336 else return USER::getDisplayName(abs($this->doc->owner));
343 $idprop = strtolower($idprop);
345 if (isset($this->_properties[$idprop]))
return $this->_properties[$idprop];
359 $listattr = $this->doc->getAttributes();
361 foreach ($listattr as $k => $oa) {
362 if ($oa && ($oa->id !=
'FIELD_HIDDENS') && ($oa->usefor !=
"Q")) {
363 foreach ($oa as $aid => $v) {
364 if ($aid ==
"options") {
367 foreach ($oa->_topt as $ko => $vo) {
368 if ($vo) $topt[$ko] = $oa->getOption($ko);
370 $attrs[$oa->id][
"options"] = $topt;
372 } elseif (!is_object($v)) $attrs[$oa->id][$aid] = $v;
373 else if ($aid ==
"fieldSet")
if ($v->id !=
'FIELD_HIDDENS') $attrs[$oa->id][
"parentId"] = $v->id;
374 else $attrs[$oa->id][
"parentId"] = null;
376 $attrs[$oa->id][
'labelText'] = $oa->getLabel();
378 if ($oa->type ==
"enum") {
379 $attrs[$oa->id][
"enumerate"] = $oa->getEnum();
388 return ($this->doc->defDoctype ==
'D' || $this->doc->defDoctype ==
'S');
399 return ($this->doc->getAttribute($aid) !=
false);
406 function getDocument($onlyvalues =
false, $completeprop =
true, $infoprop =
false, $usertags =
false)
409 "error" => $this->error,
410 "properties" => $this->
getProperties($completeprop, $infoprop) ,
413 "requestDate" => date(
'Y-m-d H:i:s') ,
437 $rev = $this->doc->getRevisions(
"TABLE");
439 foreach ($rev as $k => $zdoc) {
441 $tmpdoc->Affect($rdoc);
442 $out[] = $tmpdoc->getDocument($onlyvalues, $completeprop);
454 $clone = $this->doc->copy($temporary,
true, $linkfld, $copyfile);
456 if (is_object($clone)) {
459 $clone->disableEditControl();
461 if ($clone->title !=
$title) {
463 $clone->modify(
true, array(
467 $clone->enableEditControl();
485 $out = $this->doc->getHisto($allrevision, $code);
486 foreach (
$out as $k => $v) {
487 $out[$k][
"userName"] = $v[
"uname"];
488 $out[$k][
"userId"] = $v[
"uid"];
489 unset(
$out[$k][
"uname"]);
490 unset(
$out[$k][
"uid"]);
498 $err = $this->doc->canEdit();
502 $olds = $this->doc->getOldValues();
503 $needpostmodif = (is_array($olds));
505 $this->doc->refresh();
506 if ($needpostmodif) $this->doc->postModify();
507 $err = $this->doc->modify();
510 $olds = $this->doc->getOldValues();
512 if (is_array($olds)) {
513 foreach ($olds as $ka => $va) {
514 $oa = $this->doc->getAttribute($ka);
515 $keys[] = $oa->getLabel();
517 $skeys = implode(
",", $keys);
518 $this->doc->Addcomment(sprintf(_(
"change %s") , $skeys) ,
HISTO_INFO,
"MODIFY");
526 include_once (
"FDL/mailcard.php");
527 $err =
sendCard(
$action, $this->doc->id,
$to,
$cc,
$subject,
"",
true,
$comment,
"",
$bcc,
"html",
true, array() ,
true, $savecopy);
536 $this->doc->refresh();
537 $this->doc->postModify();
538 $err = $this->doc->add();
545 $err = $this->doc->lock($auto);
554 $err = $this->doc->unlock($auto);
563 $err = $this->doc->addUtag($this->doc->userid, $tag,
$comment);
572 $err = $this->doc->delUtag($this->doc->userid, $tag);
581 $dbutags = $this->doc->searchUtags();
583 foreach ($dbutags as $k => $v) {
584 $utags[$v[
"tag"]] = $v[
"comment"];
631 $err = $this->doc->setState($state);
638 function delete($really =
false)
641 $err = $this->doc->delete($really);
650 $err = $this->doc->control(
"edit");
652 $err = $this->doc->revive();
670 function moveTo($movetoid, $fromtoid = null)
673 if (!$fromtoid) $fromtoid = $this->doc->prelid;
675 $da = new_doc($this->dbaccess, $movetoid);
676 if ($da->isAlive()) {
677 if (method_exists($da,
"addFile")) {
678 $err = $da->addFile($this->doc->initid);
680 if (($fromtoid) && ($fromtoid != $movetoid)) {
681 $d = new_doc($this->dbaccess, $fromtoid);
683 if (method_exists(
$d,
"delFile")) {
684 $err =
$d->delFile($this->doc->initid);
686 $this->doc->prelid = $da->initid;
687 $this->doc->modify(
true, array(
691 }
else $err = sprintf(_(
"document %s is not a folder") ,
$d->getTitle());
695 $this->doc->prelid = $da->initid;
696 $this->doc->modify(
true, array(
702 }
else $err = sprintf(_(
"document %s is not a folder") , $da->getTitle());
712 include_once (
"FDL/modcard.php");
713 foreach ($_FILES as $k => $v) {
715 $oldname = $this->doc->vault_filename($k);
719 if ($this->doc->vault_filename($k) ==
"Unknown") $this->doc->renameFile($k, $oldname);
727 if (!$this->doc)
return false;
729 foreach ($as as $aid => $oa) {
730 $nv = getHttpVars($aid, null);
732 if (
$nv ===
'')
$nv =
' ';
734 $oa = $this->doc->getAttribute($aid);
735 if ($oa->isMultiple())
$nv = json_decode(
$nv);
744 if ($this->doc && $this->doc->name ==
'') {
745 $name = getHttpVars(
"name");
747 $err = $this->doc->setLogicalIdentificator(
$name);
761 return $this->doc->hasWaitingFiles();
767 $la = $this->doc->GetNormalAttributes();
770 foreach (
$la as $at) {
771 if ($at->getOption(
"version") ==
"yes") {
772 $err = $this->doc->setValue($at->id, $version);
774 if ((!
$err) && $usecomment) $this->doc->addComment(sprintf(_(
"change version to %s") , $version));
778 if ((
$err ==
"") && (!$hasversion)) {
779 $this->doc->version = trim($version);
781 if ($version ==
"") $this->doc->addComment(sprintf(_(
"reset version")));
782 else $this->doc->addComment(sprintf(_(
"change version to %s") , $version));
791 if ($this->doc && $this->doc->wid) {
792 $wd = new_doc($this->dbaccess, $this->doc->wid);
793 if (!$wd->isAlive())
return null;
794 $wd->set($this->doc);
795 $ns = $wd->getFollowingStates();
798 foreach ($ns as $state) {
801 foreach ($wd->cycle as $k =>
$t) {
802 if ((
$t[
"e1"] == $this->doc->state) && (
$t[
"e2"] == $state)) {
809 "transition" => $tlabel,
810 "transitionLabel" => $tlabel ? _($tlabel) :
'',
811 "label" => _($state) ,
812 "color" => $wd->getColor($state)
823 $timers = $this->doc->getAttachedTimers();
824 foreach ($timers as $k => $v) {
825 $timer = new_doc($this->dbaccess, $v[
"timerid"]);
826 if ($timer->isAlive()) {
827 $iprev = $timer->getPrevisions($v[
"attachdate"], $v[
"tododate"], $v[
"level"]);
828 foreach ($iprev as $pk => $pv) {
829 $iprev[$pk][
"timerid"] = $timer->id;
830 $iprev[$pk][
"timertitle"] = $timer->getTitle();
832 $prev = array_merge($prev, $iprev);
835 foreach ($prev as $k => $v) {
836 $prev[$k][
"local"][
"lstate"] =
"";
837 $prev[$k][
"local"][
"lmethod"] =
"";
838 $prev[$k][
"local"][
"tmailtitle"] =
"";
839 if ($v[
"actions"][
"state"]) $prev[$k][
"local"][
"lstate"] = _($v[
"actions"][
"state"]);
840 else $prev[$k][
"local"][
"lstate"] =
false;
841 if ($v[
"actions"][
"tmail"]) {
842 $prev[$k][
"local"][
"tmailtitle"] = $this->doc->getTitle($v[
"actions"][
"tmail"]);
844 if ($v[
"actions"][
"method"]) $prev[$k][
"local"][
"lmethod"] = _($v[
"actions"][
"method"]);
845 else $prev[$k][
"local"][
"lmethod"] =
false;
846 $prev[$k][
"local"][
"hdelay"] = $this->
humandelay($v[
"execdelay"]);
857 if (
$a[
"execdelay"] > $b[
"execdelay"])
return 1;
858 elseif (
$a[
"execdelay"] < $b[
"execdelay"])
return -1;
867 if ($j > 1)
$s.= sprintf(_(
"%d days") , $j);
868 else $s.= sprintf(_(
"%d day") , $j);
876 if ($j > 1)
$s.= sprintf(_(
"%d hours") , $j);
877 else $s.= sprintf(_(
"%d hour") , $j);
884 if ($j > 1)
$s.= sprintf(_(
"%d minutes") , $j);
885 else $s.= sprintf(_(
"%d minute") , $j);