Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Document Object Definition
9  *
10  * @author Anakeen 2002
11  * @version $Id: Class.Doc.php,v 1.562 2009/01/14 09:18:05 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  */
15 /**
16  */
17 include_once ("FDL/Class.Doc.php");
18 /**
19  * Document Class
20  *
21  */
23 {
24 
25  protected $doc;
26  public $dbaccess;
27  function __construct($id = 0, $config = null, Doc & $doc = null)
28  {
29  $this->dbaccess = getParam("FREEDOM_DB");
30  if (isset($config->latest)) $latest = $config->latest;
31  else $latest = true;
32  if ($id || - $doc) {
33  if ($doc) $this->doc = $doc;
34  else $this->doc = new_doc($this->dbaccess, $id, $latest);
35  if (!$this->doc->isAffected()) $this->error = sprintf(_("document %s not exist") , $id);
36  if (!$this->error) {
37  // no control families if structure is required
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"));
41  }
42  if ($this->error) unset($this->doc);
43  else {
44  $this->doc->refresh();
45  $mask = $this->doc->getDefaultView(false, "mask");
46  if ($mask) $this->doc->applyMask($mask);
47  }
48  }
49  }
50  /**
51  * create document : not set in dataabse until it was saved
52  * @param string $familyId the family identificator
53  * @param boolean $temporary set to true if need only a temporary document
54  * @return void
55  */
56  function createDocument($familyId, $temporary = false)
57  {
58  if ($temporary) $cdoc = createTmpDoc($this->dbaccess, $familyId);
59  else $cdoc = createDoc($this->dbaccess, $familyId);
60  if ($cdoc) {
61  $this->doc = $cdoc;
62  } else {
63  $this->setError(sprintf(_("cannot create document for family [%s]") , $familyId));
64  }
65  }
66 
67  function docisset()
68  {
69  return is_object($this->doc);
70  }
71  function setError($err)
72  {
73  if ($err) $this->error = $err;
74  }
75  function isAlive()
76  {
77  if ($this->doc) return $this->doc->isAlive();
78  return null;
79  }
80  function affect(&$doc)
81  {
82  $this->doc = $doc;
83  $this->_properties = null;
84  $this->error = $this->doc->control('view');
85  if ($this->error) unset($this->doc);
86  }
87  function getAttribute($aid)
88  {
89  if ($this->doc) {
90  return $this->doc->getAttribute($aid);
91  }
92  return null;
93  }
94 
96  {
97  return $this->doc;
98  }
99  /**
100  * return all attribute values
101  * @return array
102  */
103  function getValues()
104  {
105  if ($this->doc) {
106  $lvalues = array();
107  if ($this->doc->doctype == 'C') {
108  foreach ($this->doc->addfields as $aid) {
109  $lvalues[$aid] = $this->doc->$aid;
110  }
111  } else {
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);
119 
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);
130  }
131  } else $lvalues[$v->id] = stringDateToIso($lvalues[$v->id], false);
132  }
133  }
134  }
135  }
136  }
137  return $lvalues;
138  }
139  /**
140  * return an attribute values
141  * @return array
142  */
143  function getValue($aid)
144  {
145  if ($this->doc) {
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);
150  }
151  }
152  return null;
153  }
154  /**
155  * return document list for relation attribute
156  * @return array
157  */
158  function getProposalDocuments($aid, $key)
159  {
160  if ($this->doc) {
161  $oa = $this->doc->getAttribute($aid);
162  $oa->phpfile = "fdl.php";
163  $famid = $oa->format;
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);
167  $out = array();
168  foreach ($res as $v) {
169  $out[] = array(
170  "display" => $v[0],
171  "id" => $v[1],
172  "title" => $v[2]
173  );
174  }
175  return $out;
176  }
177  return null;
178  }
179  /**
180  * return an attribute values
181  * @return array
182  */
183  function setValue($aid, $nv)
184  {
185  if ($this->doc) {
186  $oa = $this->doc->getAttribute($aid);
187  if ($oa && ($oa->mvisibility != "I")) $err = $this->doc->setValue($oa->id, $nv);
188  if ($err == "") return true;
189  else $this->setError($err);
190  }
191  return null;
192  }
193 
194  function setVolatileProperty($key, $value)
195  {
196  if ($this->doc) {
197  $this->doc->fields[] = $key;
198  $this->doc->$key = $value;
199  if ($this->_properties) $this->_properties[$key] = $value;
200  }
201  }
202  /**
203  * return all properties object like id, initid, revision, ...
204  * @param bool $complete if false not set fromname, fromtitle, lastmodifiername (it is set to false in collection to increase speed)
205  * @param bool $infoprop if true add informations about properties like labels
206  * @return array
207  */
208  function getProperties($complete = true, $infoprop = false)
209  {
210  if ($this->_properties) return $this->_properties;
211  $props = null;
212  if ($this->doc) {
213  $props = array();
214  foreach ($this->doc->fields as $k => $v) {
215  if (is_numeric($k)) $props[$v] = $this->doc->$v;
216  }
217  if ($this->doc->addfields) {
218  foreach ($this->doc->addfields as $k => $v) {
219  $props[$v] = $this->doc->$v;
220  }
221  }
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;
226 
227  if ($props['id'] > 0) {
228  $props["mdate"] = strftime("%d/%m/%Y %H:%M:%S", $this->doc->revdate);
229  $props["readonly"] = ($this->doc->canEdit() != "");
230 
231  $props["lockdomainid"] = intval($this->doc->lockdomainid);
232  // numeric values
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") {
251  $props["cdate"] = stringDateToIso($props["cdate"], false);
252  $props["mdate"] = stringDateToIso($props["mdate"], false);
253  $props["adate"] = stringDateToIso($props["adate"], false);
254  }
255 
256  if ($props["allocated"] > 0) $props["allocatedname"] = USER::getDisplayName(abs($props["allocated"]));
257  $props["ownername"] = USER::getDisplayName(abs($props["owner"]));
258  if ($complete) {
259  if (($this->doc->locked > 0) || ($this->doc->locked < - 1)) $props["locker"] = USER::getDisplayName(abs($props["locked"]));
260  $props["lastmodifiername"] = $this->getLastModifier();
261  }
262 
263  $props["fromname"] = $this->doc->fromname;
264  $props["fromtitle"] = $this->doc->fromtitle;
265  }
266  if ($this->doc->doctype == 'C') {
267  $props["generateVersion"] = doubleval($this->doc->genversion);
268  if ($complete) $props["configuration"] = $this->doc->getConfiguration();
269  } else {
270  if ($complete) {
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();
277  }
278  }
279  }
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);
285  }
286  }
287 
288  foreach ($this->doc->infofields as $k => $v) $this->doc->infofields[$k]["label"] = _($v["label"]);
289  if ($infoprop) $props["informations"] = $this->doc->infofields; // only when search folder family
290  $this->_properties = $props;
291  }
292  return $props;
293  }
294  /**
295  * return all configuration item from xml config file
296  * @return array
297  */
298  function getConfiguration()
299  {
300  $conf = null;
301  if ($this->doc) {
302  $fdoc = $this->doc->getFamDoc();
303  if ($this->doc->doctype == 'C') {
304  $conf = $this->doc->getConfiguration();
305  } else {
306  $conf = $fdoc->getConfiguration();
307  }
308  }
309  return $conf;
310  }
311  /**
312  * return all configuration item from xml config file
313  * @return array
314  */
315  function getSecurity()
316  {
317  $conf = null;
318  if ($this->doc) {
319  $acls = $this->doc->acls;
320  foreach ($acls as $acl) {
321  $conf[$acl] = array(
322  "acl" => $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) == ""
326  );
327  }
328  }
329  return $conf;
330  }
331  function getLastModifier()
332  {
333  if ($this->doc) {
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));
337  }
338  return null;
339  }
340 
341  function getProperty($idprop)
342  {
343  $idprop = strtolower($idprop);
344  if (!$this->_properties) $this->getProperties();
345  if (isset($this->_properties[$idprop])) return $this->_properties[$idprop];
346  return null;
347  }
348  /**
349  * return all attribute definition
350  * return parameters also only if it is a family
351  * @return array
352  */
353  function getAttributes()
354  {
355  $attrs = null;
356  if ($this->doc) {
357 
358  $props = array();
359  $listattr = $this->doc->getAttributes();
360 
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") {
365  $oa->getOption('');
366  $topt = array();
367  foreach ($oa->_topt as $ko => $vo) {
368  if ($vo) $topt[$ko] = $oa->getOption($ko);
369  }
370  $attrs[$oa->id]["options"] = $topt;
371  unset($oa->_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;
375  }
376  $attrs[$oa->id]['labelText'] = $oa->getLabel();
377  }
378  if ($oa->type == "enum") {
379  $attrs[$oa->id]["enumerate"] = $oa->getEnum();
380  }
381  }
382  }
383  return $attrs;
384  }
385  public function isCollection()
386  {
387  if ($this->doc) {
388  return ($this->doc->defDoctype == 'D' || $this->doc->defDoctype == 'S');
389  }
390  return null;
391  }
392  /**
393  * return all attribute definition
394  * @return
395  */
396  function hasAttribute($aid)
397  {
398  if ($this->doc) {
399  return ($this->doc->getAttribute($aid) != false);
400  }
401  return null;
402  }
403  /**
404  * return properties, values and attributes definition
405  */
406  function getDocument($onlyvalues = false, $completeprop = true, $infoprop = false, $usertags = false)
407  {
408  $out = array(
409  "error" => $this->error,
410  "properties" => $this->getProperties($completeprop, $infoprop) ,
411  "configuration" => $this->getConfiguration($completeprop) ,
412  "security" => $this->getSecurity() ,
413  "requestDate" => date('Y-m-d H:i:s') ,
414  "values" => $this->getValues()
415  );
416 
417  if ($completeprop) {
418  $out["followingStates"] = $this->getFollowingStates();
419  }
420  if ($usertags) {
421  $out["userTags"] = $this->getUserTags();
422  }
423 
424  if (!$onlyvalues) {
425  $out["attributes"] = $this->getAttributes();
426  }
427  return $out;
428  }
429  /**
430  * return properties, values and attributes definition
431  */
432  function getRevisions($onlyvalues = true, $completeprop = false)
433  {
434  $out = null;
435  if ($this->doc) {
436  $out = array();
437  $rev = $this->doc->getRevisions("TABLE");
438  $tmpdoc = new Fdl_Document();
439  foreach ($rev as $k => $zdoc) {
440  $rdoc = getDocObject($this->dbaccess, $zdoc);
441  $tmpdoc->Affect($rdoc);
442  $out[] = $tmpdoc->getDocument($onlyvalues, $completeprop);
443  }
444  }
445  return $out;
446  }
447  /**
448  * clone document
449  */
450  function cloneDocument($temporary = false, $linkfld = true, $copyfile = false, $title = "")
451  {
452  $out = null;
453  if ($this->doc) {
454  $clone = $this->doc->copy($temporary, true, $linkfld, $copyfile);
455 
456  if (is_object($clone)) {
457  if ($title) {
458  $clone->setTitle($title);
459  $clone->disableEditControl();
460  $clone->modify();
461  if ($clone->title != $title) {
462  $clone->title = $title;
463  $clone->modify(true, array(
464  "title"
465  ) , true);
466  }
467  $clone->enableEditControl();
468  }
469  $dc = new Fdl_Document();
470  $dc->doc = $clone;
471  return $dc;
472  } else {
473  $this->setError($clone);
474  return false;
475  }
476  }
477  return null;
478  }
479  /**
480  * return properties, values and attributes definition
481  */
482  function getHistory($allrevision = true, $code = "")
483  {
484  if ($this->doc) {
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"]);
491  }
492  return $out;
493  }
494  return null;
495  }
496  function save()
497  {
498  $err = $this->doc->canEdit();
499  if ($err) {
500  $this->setError($err);
501  } else {
502  $olds = $this->doc->getOldValues();
503  $needpostmodif = (is_array($olds));
504 
505  $this->doc->refresh();
506  if ($needpostmodif) $this->doc->postModify();
507  $err = $this->doc->modify();
508  $this->setError($err);
509  if ($err == "") {
510  $olds = $this->doc->getOldValues();
511  $keys = array();
512  if (is_array($olds)) {
513  foreach ($olds as $ka => $va) {
514  $oa = $this->doc->getAttribute($ka);
515  $keys[] = $oa->getLabel();
516  }
517  $skeys = implode(",", $keys);
518  $this->doc->Addcomment(sprintf(_("change %s") , $skeys) , HISTO_INFO, "MODIFY");
519  }
520  }
521  }
522  }
523 
524  function send($to = "", $cc = "", $bcc = "", $subject = "", $comment = "", $savecopy = false)
525  {
526  include_once ("FDL/mailcard.php");
527  $err = sendCard($action, $this->doc->id, $to, $cc, $subject, "", true, $comment, "", $bcc, "html", true, array() , true, $savecopy);
528  if ($err != "") {
529  $this->setError($err);
530  }
531  return $err == "";
532  }
533 
534  function create()
535  {
536  $this->doc->refresh();
537  $this->doc->postModify();
538  $err = $this->doc->add();
539  $this->setError($err);
540  }
541 
542  function lock($auto = false)
543  {
544  if ($this->doc) {
545  $err = $this->doc->lock($auto);
546  if ($err) $this->setError($err);
547  return ($err == "");
548  }
549  return null;
550  }
551  function unlock($auto = false)
552  {
553  if ($this->doc) {
554  $err = $this->doc->unlock($auto);
555  if ($err) $this->setError($err);
556  return ($err == "");
557  }
558  return null;
559  }
560  function addUserTag($tag, $comment)
561  {
562  if ($this->doc) {
563  $err = $this->doc->addUtag($this->doc->userid, $tag, $comment);
564  if ($err) $this->setError($err);
565  return ($err == "");
566  }
567  return null;
568  }
569  function deleteUserTag($tag)
570  {
571  if ($this->doc) {
572  $err = $this->doc->delUtag($this->doc->userid, $tag);
573  if ($err) $this->setError($err);
574  return ($err == "");
575  }
576  return null;
577  }
578  function getUserTags()
579  {
580  if ($this->doc) {
581  $dbutags = $this->doc->searchUtags();
582  $utags = array();
583  foreach ($dbutags as $k => $v) {
584  $utags[$v["tag"]] = $v["comment"];
585  }
586  return $utags;
587  }
588  return null;
589  }
590  /**
591  * allocate document
592  *
593  * affect a document to a user
594  * @param int $userid the system identificator of the user to affect
595  * @param bool $revision if false no revision are made
596  * @param bool $autolock if false no lock are made
597  *
598  * @return string error message, if no error empty string, if message
599  */
600  function allocate($userid, $comment = "", $revision = false, $autolock = true)
601  {
602  if ($this->doc) {
603  $err = $this->doc->allocate($userid, $comment, $revision, $autolock);
604  if ($err) $this->setError($err);
605  return ($err == "");
606  }
607  return null;
608  }
609  /**
610  * allocate document
611  *
612  * affect a document to a user
613  * @param int $userid the system identificator of the user to affect
614  * @param bool $revision if false no revision are made
615  * @param bool $autolock if false no lock are made
616  *
617  * @return string error message, if no error empty string, if message
618  */
619  function unallocate($comment = "", $revision = false)
620  {
621  if ($this->doc) {
622  $err = $this->doc->unallocate($comment, $revision);
623  if ($err) $this->setError($err);
624  return ($err == "");
625  }
626  return null;
627  }
628  function changeState($state)
629  {
630  if ($this->doc) {
631  $err = $this->doc->setState($state);
632  if ($err) $this->setError($err);
633  return ($err == "");
634  }
635  return null;
636  }
637 
638  function delete($really = false)
639  {
640  if ($this->doc) {
641  $err = $this->doc->delete($really);
642  if ($err) $this->setError($err);
643  return ($err == "");
644  }
645  return null;
646  }
647  function restore()
648  {
649  if ($this->doc) {
650  $err = $this->doc->control("edit");
651  if ($err == "") {
652  $err = $this->doc->revive();
653  }
654  if ($err) $this->setError($err);
655  return ($err == "");
656  }
657  return null;
658  }
659  function addRevision($comment, $version = "", $volatile = false)
660  {
661  if ($this->doc) {
662  if ($version) $this->setVersion($version);
663  if (!$comment) $comment = _("revision of document");
664  $err = $this->doc->addRevision($comment);
665  if ($err) $this->setError($err);
666  return ($err == "");
667  }
668  return null;
669  }
670  function moveTo($movetoid, $fromtoid = null)
671  {
672  if ($this->doc) {
673  if (!$fromtoid) $fromtoid = $this->doc->prelid;
674  // if ($fromtoid == $movetoid) return; // same destination
675  $da = new_doc($this->dbaccess, $movetoid);
676  if ($da->isAlive()) {
677  if (method_exists($da, "addFile")) {
678  $err = $da->addFile($this->doc->initid);
679  if ($err == "") {
680  if (($fromtoid) && ($fromtoid != $movetoid)) {
681  $d = new_doc($this->dbaccess, $fromtoid);
682  if ($d->isAlive()) {
683  if (method_exists($d, "delFile")) {
684  $err = $d->delFile($this->doc->initid);
685  if ($err == "") {
686  $this->doc->prelid = $da->initid;
687  $this->doc->modify(true, array(
688  "prelid"
689  ) , true);
690  }
691  } else $err = sprintf(_("document %s is not a folder") , $d->getTitle());
692  }
693  } else {
694  if ($err == "") {
695  $this->doc->prelid = $da->initid;
696  $this->doc->modify(true, array(
697  "prelid"
698  ) , true);
699  }
700  }
701  }
702  } else $err = sprintf(_("document %s is not a folder") , $da->getTitle());
703  }
704 
705  if ($err) $this->setError($err);
706  return ($err == "");
707  }
708  return null;
709  }
711  {
712  include_once ("FDL/modcard.php");
713  foreach ($_FILES as $k => $v) {
714  if ($this->hasAttribute($k)) {
715  $oldname = $this->doc->vault_filename($k);
716  $filename = insert_file($this->doc, $k, true);
717  if ($filename != "") {
718  $this->setValue($k, $filename);
719  if ($this->doc->vault_filename($k) == "Unknown") $this->doc->renameFile($k, $oldname);
720  }
721  }
722  }
723  }
724 
726  {
727  if (!$this->doc) return false;
728  $as = $this->getAttributes();
729  foreach ($as as $aid => $oa) {
730  $nv = getHttpVars($aid, null);
731  if ($nv !== null) {
732  if ($nv === '') $nv = ' ';
733  if ($nv[0] == '[') {
734  $oa = $this->doc->getAttribute($aid);
735  if ($oa->isMultiple()) $nv = json_decode($nv);
736  }
737  $this->setValue($aid, $nv);
738  }
739  }
740  return true;
741  }
743  {
744  if ($this->doc && $this->doc->name == '') {
745  $name = getHttpVars("name");
746  if ($name) {
747  $err = $this->doc->setLogicalIdentificator($name);
748  if ($err) {
749  $this->setError($err);
750  return false;
751  }
752  return true;
753  }
754  }
755  return null;
756  }
757 
758  function hasWaitingFiles()
759  {
760  if ($this->doc) {
761  return $this->doc->hasWaitingFiles();
762  }
763  return null;
764  }
765  function setVersion($version, $usecomment = true)
766  {
767  $la = $this->doc->GetNormalAttributes();
768  $hasversion = false;
769  $err = "";
770  foreach ($la as $at) {
771  if ($at->getOption("version") == "yes") {
772  $err = $this->doc->setValue($at->id, $version);
773  $hasversion = true;
774  if ((!$err) && $usecomment) $this->doc->addComment(sprintf(_("change version to %s") , $version));
775  break;
776  }
777  }
778  if (($err == "") && (!$hasversion)) {
779  $this->doc->version = trim($version);
780  if ($usecomment) {
781  if ($version == "") $this->doc->addComment(sprintf(_("reset version")));
782  else $this->doc->addComment(sprintf(_("change version to %s") , $version));
783  }
784  }
785 
786  $this->setError($err);
787  }
788 
790  {
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();
796  addLogMsg($ns);
797  $ts = array();
798  foreach ($ns as $state) {
799  if ($state) {
800  $tlabel = "";
801  foreach ($wd->cycle as $k => $t) {
802  if (($t["e1"] == $this->doc->state) && ($t["e2"] == $state)) {
803  $tlabel = $t["t"];
804  break;
805  }
806  }
807  $ts[] = array(
808  "state" => $state,
809  "transition" => $tlabel,
810  "transitionLabel" => $tlabel ? _($tlabel) : '',
811  "label" => _($state) ,
812  "color" => $wd->getColor($state)
813  );
814  }
815  }
816  return $ts;
817  } else return null;
818  }
819 
820  function getAttachedTimers()
821  {
822  $prev = array();
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();
831  }
832  $prev = array_merge($prev, $iprev);
833  }
834  }
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"]);
843  }
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"]);
847  }
848  usort($prev, array(
849  get_class($this) ,
850  "sortprevision"
851  ));
852 
853  return ($prev);
854  }
855  static function sortprevision($a, $b)
856  {
857  if ($a["execdelay"] > $b["execdelay"]) return 1;
858  elseif ($a["execdelay"] < $b["execdelay"]) return -1;
859  return 0;
860  }
861 
862  static function humandelay($dd)
863  {
864  $s = "";
865  if ($dd > 1) {
866  $j = intval($dd);
867  if ($j > 1) $s.= sprintf(_("%d days") , $j);
868  else $s.= sprintf(_("%d day") , $j);
869  $s.= " ";
870  $dd = $dd - $j;
871  }
872  $dd = $dd * 24;
873 
874  if ($dd > 1) {
875  $j = intval($dd);
876  if ($j > 1) $s.= sprintf(_("%d hours") , $j);
877  else $s.= sprintf(_("%d hour") , $j);
878  $s.= " ";
879  $dd = $dd - $j;
880  }
881  $dd = $dd * 60;
882  if ($dd > 1) {
883  $j = intval($dd);
884  if ($j > 1) $s.= sprintf(_("%d minutes") , $j);
885  else $s.= sprintf(_("%d minute") , $j);
886  $s.= " ";
887  $dd = $dd - $j;
888  }
889  return $s;
890  }
891 }
892 ?>
← centre documentaire © anakeen - published under CC License - Dynacase