27 include_once DOL_DOCUMENT_ROOT .
'/core/boxes/modules_boxes.php';
35 public $boxcode =
"scheduledjobs";
36 public $boximg =
"object_cron";
37 public $boxlabel =
"BoxScheduledJobs";
38 public $depends = array(
"cron");
50 public $info_box_head = array();
51 public $info_box_contents = array();
66 $this->hidden = !($user->hasRight(
'service',
'lire') && $user->hasRight(
'contrat',
'lire'));
77 global $user, $langs, $conf,
$form;
80 $this->info_box_head = array(
'text' => $langs->trans(
"BoxScheduledJobs", $max));
82 if ($user->rights->cron->read) {
83 include_once DOL_DOCUMENT_ROOT .
'/cron/class/cronjob.class.php';
85 $resultarray = array();
88 $sql =
"SELECT t.rowid, t.datelastrun, t.datenextrun, t.datestart,";
89 $sql .=
" t.label, t.status, t.test, t.lastresult";
90 $sql .=
" FROM " . MAIN_DB_PREFIX .
"cronjob as t";
91 $sql .=
" WHERE status <> ".$cronstatic::STATUS_DISABLED;
92 $sql .=
" AND entity IN (0, ".$conf->entity.
")";
93 $sql .= $this->
db->order(
"t.datelastrun",
"DESC");
95 $result = $this->
db->query($sql);
99 $num = $this->
db->num_rows($result);
103 $objp = $this->
db->fetch_object($result);
105 if (
dol_eval($objp->test, 1, 1,
'')) {
106 $nextrun = $this->
db->jdate($objp->datenextrun);
107 if (empty($nextrun)) {
108 $nextrun = $this->
db->jdate($objp->datestart);
111 if ($line == 0 || ($nextrun < $cronstatic->datenextrun && (empty($objp->nbrun) || empty($objp->maxrun) || $objp->nbrun < $objp->maxrun))) {
112 $cronstatic->id = $objp->rowid;
113 $cronstatic->ref = $objp->rowid;
114 $cronstatic->label = $langs->trans($objp->label);
115 $cronstatic->status = $objp->status;
116 $cronstatic->datenextrun = $this->
db->jdate($objp->datenextrun);
117 $cronstatic->datelastrun = $this->
db->jdate($objp->datelastrun);
120 $resultarray[$line] = array(
121 $langs->trans(
"LastExecutedScheduledJob"),
122 $cronstatic->getNomUrl(1),
123 $cronstatic->datelastrun,
125 $cronstatic->getLibStatut(3)
130 if (!empty($objp->lastresult)) {
138 $resultarray[$line] = array(
139 $langs->trans(
"NextScheduledJobExecute"),
140 $cronstatic->getNomUrl(1),
141 $cronstatic->datenextrun,
143 $cronstatic->getLibStatut(3)
147 foreach ($resultarray as $line => $value) {
148 $this->info_box_contents[$line][] = array(
149 'td' =>
'class="tdoverflowmax200"',
150 'text' => $resultarray[$line][0]
153 $this->info_box_contents[$line][] = array(
154 'td' =>
'class="nowraponall"',
155 'textnoformat' => $resultarray[$line][1]
157 $this->info_box_contents[$line][] = array(
158 'td' =>
'class="right"',
159 'textnoformat' => (empty($resultarray[$line][2]) ?
'' :
$form->textwithpicto(
dol_print_date($resultarray[$line][2],
"dayhoursec",
'tzserver'), $langs->trans(
"CurrentTimeZone")))
161 $this->info_box_contents[$line][] = array(
162 'td' =>
'class="center" ',
163 'textnoformat' => $resultarray[$line][4]
167 $this->info_box_contents[$line][] = array(
168 'td' =>
'class="tdoverflowmax300" colspan="3"',
169 'text' => $langs->trans(
"NumberScheduledJobError")
171 $this->info_box_contents[$line][] = array(
172 'td' =>
'class="center"',
173 'textnoformat' => ($nbjobsinerror ?
'<a href="'.DOL_URL_ROOT.
'/cron/list.php?search_lastresult='.urlencode(
'<>0').
'"><div class="badge badge-danger"><i class="fa fa-exclamation-triangle"></i> '.$nbjobsinerror.
'</div></a>' :
'<a href="'.DOL_URL_ROOT.
'/cron/list.php"><div class="center badge-status4">0</div></a>')
176 $this->info_box_contents[0][0] = array(
179 'text' => ($this->
db->lasterror() .
' sql=' . $sql)
183 $this->info_box_contents[0][0] = array(
184 'td' =>
'class="nohover opacitymedium left"',
185 'text' => $langs->trans(
"ReadPermissionNotAllowed")
198 public function showBox($head =
null, $contents =
null, $nooutput = 0)
200 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);