23 include_once (
"FDL/Class.DocTimer.php");
25 $dt = new \DocTimer($this->dbaccess);
29 $dt->attachdate =
$doc->getTimeDate();
30 if ($referenceDate === null) $referenceDate =
$dt->attachdate;
32 if ($origin)
$dt->originid = $origin->id;
38 if ((count($dates) == 0)) {
39 $err = sprintf(_(
"no processes specified in timer %s [%d]") , $this->title, $this->
id);
43 if (count($acts) == 1) {
44 $act = current($acts);
45 $dt->actions = serialize($act[
"actions"]);
47 if ($referenceDate ===
'') {
48 $dt->tododate =
'infinity';
52 $jdRef+= doubleval($this->
getRawValue(
"tm_refdaydelta"));
53 $jdRef+= doubleval($this->
getRawValue(
"tm_refhourdelta")) / 24;
54 $deltaReferenceDate =
jd2cal($jdRef);
55 $dt->referencedate = $deltaReferenceDate;
57 $day = doubleval($dates[0]);
58 $hour = doubleval($hours[0]);
60 $jdTodo+= $day + ($hour / 24);
64 }
else $err = sprintf(_(
"no level 0 specified in timer %s [%d]") , $this->title, $this->
id);
76 include_once (
"FDL/Class.DocTimer.php");
78 $dt = new \DocTimer($this->dbaccess);
79 if ($origin)
$err =
$dt->unattachFromOrigin(
$doc->initid, $origin->initid,
$c);
92 include_once (
"FDL/Class.DocTimer.php");
94 $dt = new \DocTimer($this->dbaccess);
95 $err =
$dt->unattachDocument(
$doc->initid, $this->id);
109 $this->linearizeActions();
113 $spentDelay = $jdnow - $jdattach;
117 $jdstart = $jdattach;
119 $max = min(($level + $maxOccur) , count($this->lineActions));
120 for ($clevel = 0; $clevel < $level; $clevel++) {
121 $prev[$clevel] = $this->lineActions[$clevel];
122 if ($first && $tododate) {
129 $ldelay = $prev[$clevel][
"delay"];
132 for ($clevel = $level; $clevel < $max; $clevel++) {
133 $tprev[$clevel] = $this->lineActions[$clevel];
134 if ($tododate ===
"infinity") {
135 $tprev[$clevel][
"execdate"] = _(
"Timer infinity date");
136 $tprev[$clevel][
"execdelay"] =
"";
138 if ($first && $tododate) {
140 $execdate = $jdstart + $tprev[$clevel][
"delay"];
141 $delta = $jdtodo - $execdate;
145 $ldelay = $tprev[$clevel][
"delay"];
147 $tprev[$clevel][
"execdate"] =
jd2cal($jdstart + $ldelay);
148 $tprev[$clevel][
"execdelay"] = ($jdstart + $ldelay) - $jdnow;
155 private function linearizeActions()
157 $this->lineActions = array();
160 foreach ($tactions as $k => $v) {
161 $repeat = intval($v[
"tm_iteration"]);
162 if ($repeat <= 0) $repeat = 1;
164 for ($i = 0; $i < $repeat; $i++) {
165 $this->lineActions[$level] = array(
167 "delay" => doubleval($v[
"tm_delay"]) + (doubleval($v[
"tm_hdelay"]) / 24) ,
169 "state" => $v[
"tm_state"],
170 "tmail" => $v[
"tm_tmail"],
171 "method" => $v[
"tm_method"]
177 ksort($this->lineActions);
185 function executeLevel($level,
$docid, &$msg = null, &$nextlevel =
true)
189 $doc = new_doc($this->dbaccess,
$docid,
true);
190 if (!
$doc->isAlive())
return sprintf(_(
"cannot execute : document %s is not found") ,
$docid);
195 if (count($acts) > 0) {
196 foreach ($acts as $k => $v) {
197 foreach ($v[
"actions"] as $ka => $va) {
203 foreach ($tva as $idmail) {
207 $tm = new_doc($this->dbaccess, $idmail);
208 if ($tm->isAlive()) {
209 $msg = sprintf(_(
"send mail with template %s [%d]") , $tm->title, $tm->id);
210 $doc->addHistoryEntry(sprintf(_(
"execute timer %s (level %d) : %s") , $this->title, $level, $msg));
218 $msg = sprintf(_(
"change state to %s") , _($va));
219 $doc->addHistoryEntry(sprintf(_(
"execute timer %s (level %d) : %s") , $this->title, $level, $msg));
225 $msg = sprintf(_(
"apply method %s") , $va);
226 $doc->addHistoryEntry(sprintf(_(
"execute timer %s (level %d) : %s") , $this->title, $level, $msg));
234 $doc->addHistoryEntry(sprintf(_(
"execute timer %s (level %d) : %s") , $this->title, $level,
$err) ,
HISTO_ERROR);
244 $msg = implode(
".\n", $tmsg);
getPrevisions($adate, $tododate=false, $level=0, $maxOccur=10)
static rawValueToArray($v)
jd2cal($jd, $dformat= '')
getArrayRawValues($idAttr, $index=-1)
getMultipleRawValues($idAttr, $def="", $index=-1)
attachDocument(&$doc, $origin, $referenceDate=null)
static getTimeDate($hourdelta=0, $second=false)
if($file) if($subject==""&&$file) if($subject=="") $err
unattachAllDocument(&$doc, &$origin=null, &$c=0)
getRawValue($idAttr, $def="")