Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
viewtimers.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  * View Attached timer
9  *
10  * @author Anakeen 2008
11  * @version $Id: viewtimers.php,v 1.4 2009/01/02 17:43:50 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 /**
21  * View timers attached to a document
22  * @param Action &$action current action
23  * @global id Http var : document identificator to see
24  */
25 function viewtimers(&$action)
26 {
27  $docid = getHttpVars("id");
28  $szone = (getHttpVars("szone") == "Y");
29  $dbaccess = $action->GetParam("FREEDOM_DB");
30  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/resizeimg.js");
31  $doc = new_Doc($dbaccess, $docid, true);
32  if (!$doc->isAlive()) {
33  $action->exitError(sprintf(_("document not alive %s") , $docid));
34  }
35  $err = $doc->control('view');
36  if ($err) $action->exitError($err);
37  $prev = array();
38  $timers = $doc->getAttachedTimers();
39  foreach ($timers as $k => $v) {
40  $timer = new_doc($dbaccess, $v["timerid"]);
41  if ($timer->isAlive()) {
42  $iprev = $timer->getPrevisions($v["attachdate"], $v["tododate"], $v["level"]);
43  foreach ($iprev as $pk => $pv) {
44  $iprev[$pk]["timerid"] = $timer->id;
45  $iprev[$pk]["timertitle"] = $timer->getTitle();
46  }
47  $prev = array_merge($prev, $iprev);
48  }
49  }
50 
51  foreach ($prev as $k => $v) {
52  $prev[$k]["tmaila"] = "";
53  $prev[$k]["state"] = "";
54  $prev[$k]["method"] = "";
55  if ($v["actions"]["state"]) $prev[$k]["state"] = _($v["actions"]["state"]);
56  else $prev[$k]["state"] = false;
57  if ($v["actions"]["tmail"]) {
58  $prev[$k]["tmail"] = true;
59  $prev[$k]["tmaila"] = $timer->getHtmlValue($timer->getAttribute("tm_tmail") , $v["actions"]["tmail"]);
60  } else $prev[$k]["tmail"] = false;
61  if ($v["actions"]["method"]) $prev[$k]["method"] = _($v["actions"]["method"]);
62  else $prev[$k]["method"] = false;
63  $prev[$k]["hdelay"] = humandelay($v["execdelay"]);
64  $prev[$k]["oddoreven"] = ($k % 2 == 0) ? "even" : "odd";
65  }
66 
67  usort($prev, "sortprevision");
68  $action->lay->setBlockData("PREV", $prev);
69  $action->lay->set("docid", $doc->id);
70  $action->lay->set("iconsrc", $doc->getIcon());
71  $action->lay->set("doctitle", $doc->getTitle());
72  $action->lay->set("szone", $szone);
73 }
74 
75 function sortprevision($a, $b)
76 {
77  if ($a["execdelay"] > $b["execdelay"]) return 1;
78  elseif ($a["execdelay"] < $b["execdelay"]) return -1;
79  return 0;
80 }
81 
82 function humandelay($dd)
83 {
84  $s = "";
85  if ($dd > 1) {
86  $j = intval($dd);
87  if ($j > 1) $s.= sprintf(_("%d days") , $j);
88  else $s.= sprintf(_("%d day") , $j);
89  $s.= " ";
90  $dd = $dd - $j;
91  }
92  $dd = $dd * 24;
93 
94  if ($dd > 1) {
95  $j = intval($dd);
96  if ($j > 1) $s.= sprintf(_("%d hours") , $j);
97  else $s.= sprintf(_("%d hour") , $j);
98  $s.= " ";
99  $dd = $dd - $j;
100  }
101  $dd = $dd * 60;
102  if ($dd > 1) {
103  $j = intval($dd);
104  if ($j > 1) $s.= sprintf(_("%d minutes") , $j);
105  else $s.= sprintf(_("%d minute") , $j);
106  $s.= " ";
107  $dd = $dd - $j;
108  }
109  return $s;
110 }
111 ?>
← centre documentaire © anakeen - published under CC License - Dynacase