37 include_once (
"FDL/Class.DocTimer.php");
43 $dt->attachdate =
$doc->getTimeDate();
45 if ($origin)
$dt->originid = $origin->id;
51 if (((count($dates) == 0) || $dates[0] + $hours[0] == 0) && ($tododate == null)) {
52 $err = sprintf(_(
"no delay specified in timer %s [%d]") , $this->title, $this->
id);
56 if (count($acts) == 1) {
57 $act = current($acts);
58 $dt->actions = serialize($act[
"actions"]);
60 $day = doubleval($dates[0]);
61 $hour = doubleval($hours[0]);
62 if ($tododate)
$dt->tododate = $tododate;
65 }
else $err = sprintf(_(
"no level 0 specified in timer %s [%d]") , $this->title, $this->
id);
77 include_once (
"FDL/Class.DocTimer.php");
80 if ($origin)
$err =
$dt->unattachFromOrigin(
$doc->initid, $origin->initid,
$c);
93 include_once (
"FDL/Class.DocTimer.php");
96 $err =
$dt->unattachDocument(
$doc->initid, $this->id);
110 $this->linearizeActions();
113 $jdattach = StringDateToJD(
$adate);
114 $spentDelay = $jdnow - $jdattach;
118 $jdstart = $jdattach;
120 $max = min(($level + $maxOccur) , count($this->lineActions));
121 for ($clevel = 0; $clevel < $level; $clevel++) {
122 $prev[$clevel] = $this->lineActions[$clevel];
123 if ($first && $tododate) {
130 $ldelay = $prev[$clevel][
"delay"];
133 for ($clevel = $level; $clevel < $max; $clevel++) {
134 $tprev[$clevel] = $this->lineActions[$clevel];
135 if ($first && $tododate) {
136 $jdtodo = StringDateToJD($tododate);
137 $execdate = $jdstart + $tprev[$clevel][
"delay"];
138 $delta = $jdtodo - $execdate;
142 $ldelay = $tprev[$clevel][
"delay"];
144 $tprev[$clevel][
"execdate"] =
jd2cal($jdstart + $ldelay);
145 $tprev[$clevel][
"execdelay"] = ($jdstart + $ldelay) - $jdnow;
151 private function linearizeActions()
153 $this->lineActions = array();
154 $tactions = $this->getAvalues(
"tm_t_config");
156 foreach ($tactions as $k => $v) {
157 $repeat = intval($v[
"tm_iteration"]);
158 if ($repeat <= 0) $repeat = 1;
160 for ($i = 0; $i < $repeat; $i++) {
161 $this->lineActions[$level] = array(
163 "delay" => $v[
"tm_delay"] + ($v[
"tm_hdelay"] / 24) ,
165 "state" => $v[
"tm_state"],
166 "tmail" => $v[
"tm_tmail"],
167 "method" => $v[
"tm_method"]
173 ksort($this->lineActions);
185 $doc = new_doc($this->dbaccess,
$docid,
true);
186 if (!
$doc->isAlive())
return sprintf(_(
"cannot execute : document %s is not found") ,
$docid);
191 if (count($acts) > 0) {
192 foreach ($acts as $k => $v) {
193 foreach ($v[
"actions"] as $ka => $va) {
198 $tva = $this->
_val2array(str_replace(
'<BR>',
"\n", $va));
199 foreach ($tva as $idmail) {
200 $tm = new_doc($this->dbaccess, $idmail);
201 if ($tm->isAlive()) {
202 $msg = sprintf(_(
"send mail with template %s [%d]") , $tm->title, $tm->id);
203 $doc->addComment(sprintf(_(
"execute timer %s (level %d) : %s") , $this->title, $this->level, $msg));
211 $msg = sprintf(_(
"change state to %s") , _($va));
212 $doc->addComment(sprintf(_(
"execute timer %s (level %d) : %s") , $this->title, $this->level, $msg));
218 $msg = sprintf(_(
"apply method %s") , $va);
219 $doc->addComment(sprintf(_(
"execute timer %s (level %d) : %s") , $this->title, $this->level, $msg));
227 $doc->addComment(sprintf(_(
"execute timer %s (level %d) : %s") , $this->title, $this->level,
$err) ,
HISTO_ERROR);
237 $msg = implode(
".\n", $tmsg);