Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
timers_admin_result.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  * Timer management
9  *
10  * @author Anakeen 2008
11  * @version $Id: timers_admin_result.php,v 1.4 2009/01/07 18:04:19 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.Doc.php");
20 include_once ("FDL/Class.DocTimer.php");
21 include_once ("FDL/viewtimers.php");
22 /**
23  * Timers management
24  * @param Action &$action current action
25  * @global type Http var : request type
26  */
28 {
29 
30  $type = GetHttpVars("type", "next");
31  $offset = GetHttpVars("offset", 0);
32  $limit = GetHttpVars("limit", 100);
33  $filter = GetHttpVars("filter");
34  $purgeday = intval(GetHttpVars("purgeday", 7));
35  $dbaccess = $action->GetParam("FREEDOM_DB");
36 
37  if ($type == "purge") {
38  $type = "previous";
39 
40  $q = new QueryDb($dbaccess, "DocTimer");
41 
42  if ($filter) $delfilter = sprintf("and title ~* '%s'", pg_escape_string($filter));
43  $sqlpurge = "delete from doctimer where donedate is not null and donedate < now() - interval '$purgeday day' $delfilter;";
44  print $sqlpurge;
45  $timerhourlimit = max($purgeday, $action->getParam("FDL_TIMERHOURLIMIT", 2));
46  $q->Query(0, 0, 'TABLE', $sqlpurge);
47  $sqlpurge = "delete from doctimer where tododate is not null and tododate < now() - interval '$timerhourlimit day' $delfilter;";
48  print $sqlpurge;
49  $q->Query(0, 0, 'TABLE', $sqlpurge);
50  }
51  if ($type == "detach") {
52  $type = "next";
53 
54  $q = new QueryDb($dbaccess, "DocTimer");
55 
56  if ($filter) $delfilter = sprintf("and title ~* '%s'", pg_escape_string($filter));
57  $sqlpurge = "delete from doctimer where donedate is null $delfilter;";
58  print $sqlpurge;
59  $q->Query(0, 0, 'TABLE', $sqlpurge);
60  }
61 
62  $q = new QueryDb($dbaccess, "DocTimer");
63  if ($type == "next") {
64  $q->addQuery("tododate is not null");
65  $timerhourlimit = getParam("FDL_TIMERHOURLIMIT", 2);
66  $q->addQuery("tododate > now() - interval '$timerhourlimit hour'");
67  $q->order_by = 'tododate';
68  }
69  if ($type == "skip") {
70  $q->addQuery("tododate is not null");
71  $timerhourlimit = getParam("FDL_TIMERHOURLIMIT", 2);
72  $q->addQuery("tododate < now() - interval '$timerhourlimit hour'");
73  $q->order_by = 'tododate';
74  }
75  if ($type == "previous") {
76  $q->addQuery("donedate is not null");
77  $q->order_by = 'donedate desc';
78  }
79  if ($filter) $q->addQuery(sprintf("title ~* '%s'", pg_escape_string($filter)));
80  $t = $q->Query($offset, $limit, "TABLE");
81  if (is_array($t)) {
82  foreach ($t as $k => $v) {
83  $t[$k]["hact"] = humanactions($v["actions"], $dbaccess);
84  $t[$k]["hdelay"] = computehumandelay($v["tododate"]);
85  }
86  }
87  $action->lay->setBlockData("TIMERS", $t);
88  $action->lay->set("isprev", ($type == "previous"));
89  $action->lay->set("isnext", ($type == "next") || ($type == "skip"));
90 }
91 function computehumandelay($tdate)
92 {
93  if (!$tdate) return '';
94  $jdnow = StringDateToJD(Doc::getTimeDate());
95  $jdtdate = StringDateToJD($tdate);
96  if (($jdtdate - $jdnow) < 0) $hd = "- ";
97  else $hd = "";
98  return $hd . humandelay(abs($jdtdate - $jdnow));
99 }
100 
101 function humanactions($act, $dbaccess)
102 {
103  $oact = unserialize($act);
104  if (!$oact) return "-";
105  foreach ($oact as $k => $v) {
106  if ($v) {
107  switch ($k) {
108  case "tmail":
109  $tva = Doc::_val2array(str_replace('<BR>', "\n", $v));
110  foreach ($tva as $idmail) {
111  $tm = new_doc($dbaccess, $idmail);
112  if ($tm->isAlive()) {
113  $msg = sprintf(_("send mail with template %s [%d]") , $tm->title, $tm->id);
114  $tmsg[] = $msg;
115  }
116  }
117  break;
118 
119  case "state":
120  $msg = sprintf(_("change state to %s") , _($v));
121  $tmsg[] = $msg;
122  break;
123 
124  case "method":
125  $msg = sprintf(_("apply method %s") , $v);
126  $tmsg[] = $msg;
127  break;
128  }
129  }
130  }
131  return implode($tmsg, ".\n");
132 }
133 ?>
← centre documentaire © anakeen - published under CC License - Dynacase