Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Document.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Document Object Definition
8  *
9  * @author Anakeen
10  * @version $Id: Class.Doc.php,v 1.562 2009/01/14 09:18:05 eric Exp $
11  * @package FDL
12  */
13 /**
14  */
15 include_once ("FDL/Class.Doc.php");
16 /**
17  * Document Class
18  *
19  */
21 {
22  /**
23  * @var Doc|DocFam
24  */
25  protected $doc;
26  protected $_properties;
27  public $error = '';
28  public $dbaccess;
29  private $onlyAttributes = null;
30  /**
31  * @param int $id
32  * @param stdClass $config
33  * @param Doc $doc
34  */
35  function __construct($id = 0, $config = null, Doc & $doc = null)
36  {
37  $this->dbaccess = isset($doc) ? $doc->dbaccess : getDbAccess();
38  if (isset($config->latest)) $latest = $config->latest;
39  else $latest = true;
40 
41  if ($config === null) {
42  $config = new stdClass();
43  $config->onlyValues = null;
44  }
45  if ($id || is_object($doc)) {
46  if ($doc) $this->doc = $doc;
47  else $this->doc = new_doc($this->dbaccess, $id, $latest);
48  if (!$this->doc->isAffected()) $this->error = sprintf(_("document %s not exist") , $id);
49  if (!$this->error) {
50  // no control families if structure is required
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"));
54  }
55  if ($this->error) $this->doc = null;
56  else {
57  $this->doc->refresh();
58  $mask = $this->doc->getDefaultView(false, "mask");
59  if ($mask) $this->doc->applyMask($mask);
60  }
61  }
62  }
63  /**
64  * create document : not set in dataabse until it was saved
65  * @param string $familyId the family identifier
66  * @param boolean $temporary set to true if need only a temporary document
67  * @return void
68  */
69  function createDocument($familyId, $temporary = false)
70  {
71  if ($temporary) $cdoc = createTmpDoc($this->dbaccess, $familyId);
72  else $cdoc = createDoc($this->dbaccess, $familyId);
73  if ($cdoc) {
74  $this->doc = $cdoc;
75  } else {
76  $this->setError(sprintf(_("cannot create document for family [%s]") , $familyId));
77  }
78  }
79 
80  function docisset()
81  {
82  return is_object($this->doc);
83  }
84  function setError($err)
85  {
86  if ($err) $this->error = $err;
87  }
88  function isAlive()
89  {
90  if ($this->doc) return $this->doc->isAlive();
91  return null;
92  }
93  /**
94  * @param Doc $doc
95  */
96  function affect(&$doc)
97  {
98  $this->doc = $doc;
99  $this->_properties = null;
100  $this->error = $this->doc->control('view');
101  if ($this->error) unset($this->doc);
102  }
103  function getAttribute($aid)
104  {
105  if ($this->doc) {
106  return $this->doc->getAttribute($aid);
107  }
108  return null;
109  }
110 
111  public function usePartialDocument(array $attrids)
112  {
113  $this->onlyAttributes = $attrids;
114  }
115  /**
116  * @return Doc|null
117  */
119  {
120  return $this->doc;
121  }
122  /**
123  * return all attribute values
124  * @return array|null
125  */
126  function getValues()
127  {
128  $lvalues = null;
129  if ($this->doc) {
130  $lvalues = array();
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;
135  }
136  }
137  } else {
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;
143 
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);
147 
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];
152  $ltitle = array();
153  foreach ($lv as $kv => $aDocid) {
154  if (strpos($aDocid, '<BR>') !== false) {
155 
156  $tt = explode('<BR>', $aDocid);
157  $lvalues[$v->id][$kv] = $tt;
158  $trtitle = array();
159  foreach ($tt as $vv) {
160  $rtitle = DocTitle::getRelationTitle($vv, $isLatest, $this->doc);
161  if ($rtitle === false) $rtitle = $v->getOption("noaccesstext", _("information access deny"));
162  $trtitle[] = $rtitle;
163  }
164  $ltitle[] = $trtitle; //implode('<BR>',$trtitle);
165 
166  } else {
167  $rtitle = DocTitle::getRelationTitle($aDocid, $isLatest, $this->doc);
168  if ($rtitle === false) $rtitle = $v->getOption("noaccesstext", _("information access deny"));
169  $ltitle[] = $rtitle;
170  }
171  }
172  $lvalues[$v->id . "_title"] = $ltitle;
173  } else {
174  $lvalues[$v->id . "_title"] = DocTitle::getRelationTitle($this->doc->getRawValue($v->id) , $isLatest, $this->doc);
175  if ($lvalues[$v->id . "_title"] === false) $lvalues[$v->id . "_title"] = $v->getOption("noaccesstext", _("information access deny"));
176  }
177  //if ($v->inArray() || ($v->getOption("multiple") == "yes")) $lvalues[$v->id . "_title"] = $this->doc->rawValueToArray($lvalues[$v->id . "_title"]);
178 
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);
186  }
187  } else $lvalues[$v->id] = StringDateToIso($lvalues[$v->id], false);
188  }
189  }
190  }
191  }
192  }
193  return $lvalues;
194  }
195  /**
196  * return an attribute values
197  * @return array
198  */
199  function getValue($aid)
200  {
201  if ($this->doc) {
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);
206  }
207  }
208  return null;
209  }
210  /**
211  * return document list for relation attribute
212  * @return array
213  */
214  function getProposalDocuments($aid, $key)
215  {
216  if ($this->doc) {
217  /*
218  * @var NormalAttribute $oa
219  */
220  $oa = $this->doc->getAttribute($aid);
221  $oa->phpfile = "fdl.php";
222  $famid = $oa->format;
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);
226  $out = array();
227  foreach ($res as $v) {
228  $out[] = array(
229  "display" => $v[0],
230  "id" => $v[1],
231  "title" => $v[2]
232  );
233  }
234  return $out;
235  }
236  return null;
237  }
238  /**
239  * return an attribute values
240  * @return array
241  */
242  function setValue($aid, $nv)
243  {
244  if ($this->doc) {
245  $err = '';
246  $oa = $this->doc->getAttribute($aid);
247  if ($oa && ($oa->mvisibility != "I")) $err = $this->doc->setValue($oa->id, $nv);
248  if ($err == "") return true;
249  else $this->setError($err);
250  }
251  return null;
252  }
253 
254  function setVolatileProperty($key, $value)
255  {
256  if ($this->doc) {
257  $this->doc->fields[] = $key;
258  $this->doc->$key = $value;
259  if ($this->_properties) $this->_properties[$key] = $value;
260  }
261  }
262 
263  protected function getDocPropertiesFields()
264  {
265  static $d = null;
266  if ($d === null) $d = new Doc();
267  return $d->fields;
268  }
269  /**
270  * return all properties object like id, initid, revision, ...
271  * @param bool $complete if false not set fromname, fromtitle, lastmodifiername (it is set to false in collection to increase speed)
272  * @param bool $infoprop if true add informations about properties like labels
273  * @return array
274  */
275  function getProperties($complete = true, $infoprop = false)
276  {
277  if ($this->_properties) return $this->_properties;
278  $props = null;
279  if ($this->doc) {
280  $props = array();
281  $dFields = $this->getDocPropertiesFields();
282  foreach ($dFields as $k => $v) {
283  $props[$v] = $this->doc->$v;
284  }
285  if (isset($this->doc->addfields)) {
286  foreach ($this->doc->addfields as $k => $v) {
287  $props[$v] = $this->doc->$v;
288  }
289  }
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;
294 
295  if ($props['id'] > 0) {
296  $props["mdate"] = strftime("%Y-%m-%d %H:%M:%S", $this->doc->revdate);
297  $props["readonly"] = ($this->doc->canEdit() != "");
298 
299  $props["lockdomainid"] = intval($this->doc->lockdomainid);
300  // numeric values
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();
317 
318  if ($props["allocated"] > 0) $props["allocatedname"] = USER::getDisplayName(abs($props["allocated"]));
319  $props["ownername"] = USER::getDisplayName(abs($props["owner"]));
320  if ($complete) {
321  if (($this->doc->locked > 0) || ($this->doc->locked < - 1)) $props["locker"] = USER::getDisplayName(abs($props["locked"]));
322  $props["lastmodifiername"] = $this->getLastModifier();
323  }
324 
325  $props["fromname"] = $this->doc->fromname;
326  $props["fromtitle"] = $this->doc->fromtitle;
327  }
328  if ($this->doc->doctype == 'C') {
329  $props["generateVersion"] = doubleval($this->doc->genversion);
330  if ($complete) $props["configuration"] = $this->doc->getConfiguration();
331  } else {
332  if ($complete) {
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();
339  }
340  }
341  }
342  if ($this->doc && $this->doc->wid) {
343  /*
344  * @var WDoc $wd
345  */
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);
350  }
351  }
352  if ($infoprop) {
353  foreach (Doc::$infofields as $k => $v) Doc::$infofields[$k]["label"] = _($v["label"]);
354  $props["informations"] = Doc::$infofields; // only when search folder family
355 
356  }
357  $this->_properties = $props;
358  }
359  return $props;
360  }
361  /**
362  * return all configuration item from xml config file
363  * @return array
364  */
365  function getConfiguration()
366  {
367  $conf = null;
368  if ($this->doc) {
369  $fdoc = $this->doc->getFamilyDocument();
370  if ($this->doc->doctype == 'C') {
371  $conf = $this->doc->getConfiguration();
372  } else {
373  $conf = $fdoc->getConfiguration();
374  }
375  }
376  return $conf;
377  }
378  /**
379  * return all configuration item from xml config file
380  * @return array
381  */
382  function getSecurity()
383  {
384  $conf = null;
385  if ($this->doc) {
386  $acls = $this->doc->acls;
387  foreach ($acls as $acl) {
388  if (isset($this->doc->dacls[$acl])) {
389  $conf[$acl] = array(
390  "acl" => $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) == ""
394  );
395  }
396  }
397  }
398  return $conf;
399  }
400  function getLastModifier()
401  {
402  if ($this->doc) {
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));
406  }
407  return null;
408  }
409 
410  function getProperty($idprop)
411  {
412  $idprop = strtolower($idprop);
413  if (!$this->_properties) $this->getProperties();
414  if (isset($this->_properties[$idprop])) return $this->_properties[$idprop];
415  return null;
416  }
417  /**
418  * return all attribute definition
419  * return parameters also only if it is a family
420  * @return array
421  */
422  function getAttributes()
423  {
424  $attrs = null;
425  if ($this->doc) {
426 
427  $props = array();
428  $listattr = $this->doc->getAttributes();
429 
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") {
434  $oa->getOption('');
435  $topt = array();
436  foreach ($oa->_topt as $ko => $vo) {
437  if ($vo) $topt[$ko] = $oa->getOption($ko);
438  }
439  $attrs[$oa->id]["options"] = $topt;
440  unset($oa->_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;
444  }
445  $attrs[$oa->id]['labelText'] = $oa->getLabel();
446  }
447  if ($oa->type == "enum") {
448  /*
449  * @var NormalAttribute $oa
450  */
451  $attrs[$oa->id]["enumerate"] = $oa->getEnum();
452  }
453  }
454  }
455  return $attrs;
456  }
457  public function isCollection()
458  {
459  if ($this->doc) {
460  return ($this->doc->defDoctype == 'D' || $this->doc->defDoctype == 'S');
461  }
462  return null;
463  }
464  /**
465  * return all attribute definition
466  * @return
467  */
468  function hasAttribute($aid)
469  {
470  if ($this->doc) {
471  return ($this->doc->getAttribute($aid) != false);
472  }
473  return null;
474  }
475  /**
476  * return properties, values and attributes definition
477  */
478  function getDocument($onlyvalues = false, $completeprop = true, $infoprop = false, $usertags = false)
479  {
480  $out = array(
481  "error" => $this->error,
482  "properties" => $this->getProperties($completeprop, $infoprop) ,
483  "configuration" => $this->getConfiguration($completeprop) ,
484  "security" => $this->getSecurity() ,
485  "requestDate" => date('Y-m-d H:i:s') ,
486  "values" => $this->getValues()
487  );
488  if ($this->onlyAttributes !== null) {
489  $out["partialDocument"] = true;
490  }
491 
492  if ($completeprop) {
493  $out["followingStates"] = $this->getFollowingStates();
494  }
495  if ($usertags) {
496  $out["userTags"] = $this->getUserTags();
497  }
498 
499  if (!$onlyvalues) {
500  $out["attributes"] = $this->getAttributes();
501  }
502  return $out;
503  }
504  /**
505  * return properties, values and attributes definition
506  */
507  function getRevisions($onlyvalues = true, $completeprop = false)
508  {
509  $out = null;
510  if ($this->doc) {
511  $out = array();
512  $rev = $this->doc->getRevisions("TABLE");
513  $tmpdoc = new Fdl_Document();
514  foreach ($rev as $k => $zdoc) {
515  $rdoc = getDocObject($this->dbaccess, $zdoc);
516  $tmpdoc->Affect($rdoc);
517  $out[] = $tmpdoc->getDocument($onlyvalues, $completeprop);
518  }
519  }
520  return $out;
521  }
522  /**
523  * clone document
524  */
525  function cloneDocument($temporary = false, $linkfld = true, $copyfile = false, $title = "")
526  {
527  $out = null;
528  if ($this->doc) {
529  $clone = $this->doc->duplicate($temporary, true, $linkfld, $copyfile);
530 
531  if (is_object($clone)) {
532  if ($title) {
533  $clone->setTitle($title);
534  $clone->disableEditControl();
535  $clone->modify();
536  if ($clone->title != $title) {
537  $clone->title = $title;
538  $clone->modify(true, array(
539  "title"
540  ) , true);
541  }
542  $clone->enableEditControl();
543  }
544  $dc = new Fdl_Document();
545  $dc->doc = $clone;
546  return $dc;
547  } else {
548  $this->setError($clone);
549  return false;
550  }
551  }
552  return null;
553  }
554  /**
555  * return properties, values and attributes definition
556  */
557  function getHistory($allrevision = true, $code = "")
558  {
559  if ($this->doc) {
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"]);
566  }
567  return $out;
568  }
569  return null;
570  }
571  function save()
572  {
573  $err = $this->doc->canEdit();
574  if ($err) {
575  $this->setError($err);
576  } else {
577  $olds = $this->doc->getOldRawValues();
578  $needpostmodif = (is_array($olds));
579 
580  $this->doc->refresh();
581  if ($needpostmodif) $this->doc->postStore();
582  $err = $this->doc->modify();
583  $this->setError($err);
584  if ($err == "") {
585  $olds = $this->doc->getOldRawValues();
586  $keys = array();
587  if (is_array($olds)) {
588  foreach ($olds as $ka => $va) {
589  $oa = $this->doc->getAttribute($ka);
590  $keys[] = $oa->getLabel();
591  }
592  $skeys = implode(",", $keys);
593  $this->doc->addHistoryEntry(sprintf(_("change %s") , $skeys) , HISTO_INFO, "MODIFY");
594  }
595  }
596  }
597  }
598 
599  function send($to = "", $cc = "", $bcc = "", $subject = "", $comment = "", $savecopy = false)
600  {
601  include_once ("FDL/mailcard.php");
602  $err = sendCard($action, $this->doc->id, $to, $cc, $subject, "", true, $comment, "", $bcc, "html", true, array() , true, $savecopy);
603  if ($err != "") {
604  $this->setError($err);
605  }
606  return $err == "";
607  }
608 
609  function create()
610  {
611  $err = $this->doc->store($info, true);
612  $this->setError($err);
613  }
614 
615  function lock($auto = false)
616  {
617  if ($this->doc) {
618  $err = $this->doc->lock($auto);
619  if ($err) $this->setError($err);
620  return ($err == "");
621  }
622  return null;
623  }
624  function unlock($auto = false)
625  {
626  if ($this->doc) {
627  $err = $this->doc->unlock($auto);
628  if ($err) $this->setError($err);
629  return ($err == "");
630  }
631  return null;
632  }
633  function addUserTag($tag, $comment)
634  {
635  if ($this->doc) {
636  $err = $this->doc->addUtag($this->doc->userid, $tag, $comment);
637  if ($err) $this->setError($err);
638  return ($err == "");
639  }
640  return null;
641  }
642  function deleteUserTag($tag)
643  {
644  if ($this->doc) {
645  $err = $this->doc->delUtag($this->doc->userid, $tag);
646  if ($err) $this->setError($err);
647  return ($err == "");
648  }
649  return null;
650  }
651  function getUserTags()
652  {
653  if ($this->doc) {
654  $dbutags = $this->doc->searchUtags();
655  $utags = array();
656  foreach ($dbutags as $k => $v) {
657  $utags[$v["tag"]] = $v["comment"];
658  }
659  return $utags;
660  }
661  return null;
662  }
663  /**
664  * allocate document
665  *
666  * affect a document to a user
667  * @param int $userid the system identifier of the user to affect
668  * @param bool $revision if false no revision are made
669  * @param bool $autolock if false no lock are made
670  *
671  * @return string error message, if no error empty string, if message
672  */
673  function allocate($userid, $comment = "", $revision = false, $autolock = true)
674  {
675  if ($this->doc) {
676  $err = $this->doc->allocate($userid, $comment, $revision, $autolock);
677  if ($err) $this->setError($err);
678  return ($err == "");
679  }
680  return null;
681  }
682  /**
683  * allocate document
684  *
685  * affect a document to a user
686  * @param int $userid the system identifier of the user to affect
687  * @param bool $revision if false no revision are made
688  * @param bool $autolock if false no lock are made
689  *
690  * @return string error message, if no error empty string, if message
691  */
692  function unallocate($comment = "", $revision = false)
693  {
694  if ($this->doc) {
695  $err = $this->doc->unallocate($comment, $revision);
696  if ($err) $this->setError($err);
697  return ($err == "");
698  }
699  return null;
700  }
701  function changeState($state)
702  {
703  if ($this->doc) {
704  $err = $this->doc->setState($state);
705  if ($err) $this->setError($err);
706  return ($err == "");
707  }
708  return null;
709  }
710 
711  function delete($really = false)
712  {
713  if ($this->doc) {
714  $err = $this->doc->delete($really);
715  if ($err) $this->setError($err);
716  return ($err == "");
717  }
718  return null;
719  }
720  function restore()
721  {
722  if ($this->doc) {
723  $err = $this->doc->control("edit");
724  if ($err == "") {
725  $err = $this->doc->undelete();
726  }
727  if ($err) $this->setError($err);
728  return ($err == "");
729  }
730  return null;
731  }
732  function addRevision($comment, $version = "", $volatile = false)
733  {
734  if ($this->doc) {
735  if ($version) $this->setVersion($version);
736  if (!$comment) $comment = _("revision of document");
737  $err = $this->doc->revise($comment);
738  if ($err) $this->setError($err);
739  return ($err == "");
740  }
741  return null;
742  }
743  function moveTo($movetoid, $fromtoid = null)
744  {
745  if ($this->doc) {
746  $err = '';
747  if (!$fromtoid) $fromtoid = $this->doc->prelid;
748  // if ($fromtoid == $movetoid) return; // same destination
749  $da = new_doc($this->dbaccess, $movetoid);
750  if ($da->isAlive()) {
751  if (method_exists($da, "addFile")) {
752  /*
753  * @var Dir $da
754  */
755  $err = $da->insertDocument($this->doc->initid);
756  if ($err == "") {
757  if (($fromtoid) && ($fromtoid != $movetoid)) {
758  $d = new_doc($this->dbaccess, $fromtoid);
759  if ($d->isAlive()) {
760  if (method_exists($d, "delFile")) {
761  /*
762  * @var Dir $d
763  */
764  $err = $d->removeDocument($this->doc->initid);
765  if ($err == "") {
766  $this->doc->prelid = $da->initid;
767  $this->doc->modify(true, array(
768  "prelid"
769  ) , true);
770  }
771  } else $err = sprintf(_("document %s is not a folder") , $d->getTitle());
772  }
773  } else {
774  if ($err == "") {
775  $this->doc->prelid = $da->initid;
776  $this->doc->modify(true, array(
777  "prelid"
778  ) , true);
779  }
780  }
781  }
782  } else $err = sprintf(_("document %s is not a folder") , $da->getTitle());
783  }
784 
785  if ($err) $this->setError($err);
786  return ($err == "");
787  }
788  return null;
789  }
791  {
792  include_once ("FDL/modcard.php");
793  foreach ($_FILES as $k => $v) {
794  if ($this->hasAttribute($k)) {
795  $oldname = $this->doc->vault_filename($k);
796  $filename = insert_file($this->doc, $k, true);
797  if ($filename != "") {
798  $this->setValue($k, $filename);
799  if ($this->doc->vault_filename($k) == "Unknown") $this->doc->renameFile($k, $oldname);
800  }
801  }
802  }
803  }
804 
806  {
807  if (!$this->doc) return false;
808  $as = $this->getAttributes();
809  foreach ($as as $aid => $oa) {
810  $nv = getHttpVars($aid, null);
811  if ($nv !== null) {
812  if ($nv === '') $nv = ' ';
813  if ($nv[0] == '[') {
814  $oa = $this->doc->getAttribute($aid);
815  if ($oa->isMultiple()) $nv = json_decode($nv);
816  }
817  $this->setValue($aid, $nv);
818  }
819  }
820  return true;
821  }
822  function setLogicalName()
823  {
824  if ($this->doc && $this->doc->name == '') {
825  $name = getHttpVars("name");
826  if ($name) {
827  $err = $this->doc->setLogicalName($name);
828  if ($err) {
829  $this->setError($err);
830  return false;
831  }
832  return true;
833  }
834  }
835  return null;
836  }
837 
838  function hasWaitingFiles()
839  {
840  if ($this->doc) {
841  return $this->doc->hasWaitingFiles();
842  }
843  return null;
844  }
845  function setVersion($version, $usecomment = true)
846  {
847  $la = $this->doc->attributes->getNormalAttributes();
848  $hasversion = false;
849  $err = "";
850  foreach ($la as $at) {
851  if ($at->getOption("version") == "yes") {
852  $err = $this->doc->setValue($at->id, $version);
853  $hasversion = true;
854  if ((!$err) && $usecomment) $this->doc->addHistoryEntry(sprintf(_("change version to %s") , $version));
855  break;
856  }
857  }
858  if (($err == "") && (!$hasversion)) {
859  $this->doc->version = trim($version);
860  if ($usecomment) {
861  if ($version == "") $this->doc->addHistoryEntry(sprintf(_("reset version")));
862  else $this->doc->addHistoryEntry(sprintf(_("change version to %s") , $version));
863  }
864  }
865 
866  $this->setError($err);
867  }
868 
870  {
871  if ($this->doc && $this->doc->wid) {
872  /*
873  * @var WDoc $wd
874  */
875  $wd = new_doc($this->dbaccess, $this->doc->wid);
876  if (!$wd->isAlive()) return null;
877  $wd->set($this->doc);
878  $ns = $wd->getFollowingStates();
879  addLogMsg($ns);
880  $ts = array();
881  foreach ($ns as $state) {
882  if ($state) {
883  $tlabel = "";
884  foreach ($wd->cycle as $k => $t) {
885  if (($t["e1"] == $this->doc->state) && ($t["e2"] == $state)) {
886  $tlabel = $t["t"];
887  break;
888  }
889  }
890  $ts[] = array(
891  "state" => $state,
892  "transition" => $tlabel,
893  "transitionLabel" => $tlabel ? _($tlabel) : '',
894  "label" => _($state) ,
895  "color" => $wd->getColor($state)
896  );
897  }
898  }
899  return $ts;
900  } else return null;
901  }
902 
903  function getAttachedTimers()
904  {
905  $prev = array();
906  $timers = $this->doc->getAttachedTimers();
907  foreach ($timers as $k => $v) {
908  /**
909  * @var \Dcp\Family\TIMER $timer
910  */
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();
917  }
918  $prev = array_merge($prev, $iprev);
919  }
920  }
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"]);
929  }
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"]);
933  }
934  usort($prev, array(
935  get_class($this) ,
936  "sortprevision"
937  ));
938 
939  return ($prev);
940  }
941  static function sortprevision($a, $b)
942  {
943  if ($a["execdelay"] > $b["execdelay"]) return 1;
944  elseif ($a["execdelay"] < $b["execdelay"]) return -1;
945  return 0;
946  }
947 
948  static function humandelay($dd)
949  {
950  $s = "";
951  if ($dd > 1) {
952  $j = intval($dd);
953  if ($j > 1) $s.= sprintf(_("%d days") , $j);
954  else $s.= sprintf(_("%d day") , $j);
955  $s.= " ";
956  $dd = $dd - $j;
957  }
958  $dd = $dd * 24;
959 
960  if ($dd > 1) {
961  $j = intval($dd);
962  if ($j > 1) $s.= sprintf(_("%d hours") , $j);
963  else $s.= sprintf(_("%d hour") , $j);
964  $s.= " ";
965  $dd = $dd - $j;
966  }
967  $dd = $dd * 60;
968  if ($dd > 1) {
969  $j = intval($dd);
970  if ($j > 1) $s.= sprintf(_("%d minutes") , $j);
971  else $s.= sprintf(_("%d minute") , $j);
972  $s.= " ";
973  $dd = $dd - $j;
974  }
975  return $s;
976  }
977 }
getResPhpFunc(Doc &$doc, NormalAttribute &$oattr, &$rargids, &$tselect, &$tval, $whttpvars=true, $index="")
Definition: enum_choice.php:62
setValue($aid, $nv)
static $infofields
Definition: Class.Doc.php:105
cloneDocument($temporary=false, $linkfld=true, $copyfile=false, $title="")
getRevisions($onlyvalues=true, $completeprop=false)
getHistory($allrevision=true, $code="")
$comment
Definition: fdl_execute.php:35
static humandelay($dd)
global $action
addRevision($comment, $version="", $volatile=false)
createDocument($familyId, $temporary=false)
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
addUserTag($tag, $comment)
getDocument($onlyvalues=false, $completeprop=true, $infoprop=false, $usertags=false)
const HISTO_INFO
sendCard(Action &$action, $docid, $to, $cc, $subject, $zonebodycard="", $ulink=false, $comment="", $from="", $bcc="", $format="html", $sendercopy=true, $addfiles=array(), $userinfo=null, $savecopy=false)
Definition: mailcard.php:156
$filename
setVersion($version, $usecomment=true)
getProperties($complete=true, $infoprop=false)
if($famId) $s
$d
Definition: dav.php:77
$to
static getRelationTitle($docid, $latest=true, Doc $doc, $docrevOption="", array &$info=array())
setVolatileProperty($key, $value)
__construct($id=0, $config=null, Doc &$doc=null)
$subject
allocate($userid, $comment="", $revision=false, $autolock=true)
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
unlock($auto=false)
getHttpVars($name, $def="", $scope="all")
Definition: Lib.Http.php:124
changeState($state)
$bcc
getProposalDocuments($aid, $key)
getDbAccess()
Definition: Lib.Common.php:368
$cc
static sortprevision($a, $b)
unallocate($comment="", $revision=false)
$info
Definition: geticon.php:30
usePartialDocument(array $attrids)
lock($auto=false)
send($to="", $cc="", $bcc="", $subject="", $comment="", $savecopy=false)
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
insert_file(Doc &$doc, $attrid, $strict=false)
Definition: modcard.php:365
if($file) if($subject==""&&$file) if($subject=="") $err
$latest
$value
getProperty($idprop)
moveTo($movetoid, $fromtoid=null)
getDocObject($dbaccess, $v, $k=0)
← centre documentaire © anakeen