-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.backend.php
707 lines (652 loc) · 24.3 KB
/
class.backend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
<?php
/**
* kitCronjob
*
* @author Ralf Hertsch <[email protected]>
* @link https://addons.phpmanufaktur.de/kitCronjob
* @copyright 2012 phpManufaktur by Ralf Hertsch
* @license MIT License (MIT) http://www.opensource.org/licenses/MIT
*/
// include class.secure.php to protect this file and the whole CMS!
if (defined('WB_PATH')) {
if (defined('LEPTON_VERSION'))
include(WB_PATH . '/framework/class.secure.php');
} else {
$oneback = "../";
$root = $oneback;
$level = 1;
while (($level < 10) && (!file_exists($root . '/framework/class.secure.php'))) {
$root .= $oneback;
$level += 1;
}
if (file_exists($root . '/framework/class.secure.php')) {
include($root . '/framework/class.secure.php');
} else {
trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
}
// end include class.secure.php
// wb2lepton compatibility
if (!defined('LEPTON_PATH'))
require_once WB_PATH . '/modules/' . basename(dirname(__FILE__)) . '/wb2lepton.php';
require_once(LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/class.interface.php');
if (!class_exists('Dwoo'))
require_once LEPTON_PATH.'/modules/dwoo/include.php';
// initialize the template engine
global $parser;
if (!is_object($parser)) {
$cache_path = LEPTON_PATH.'/temp/cache';
if (!file_exists($cache_path)) mkdir($cache_path, 0755, true);
$compiled_path = LEPTON_PATH.'/temp/compiled';
if (!file_exists($compiled_path)) mkdir($compiled_path, 0755, true);
$parser = new Dwoo($compiled_path, $cache_path);
}
// load extensions for the template engine
$loader = $parser->getLoader();
$loader->addDirectory(LEPTON_PATH.'/modules/'.basename(dirname(__FILE__)).'/templates/plugins/');
require_once LEPTON_PATH.'/modules/manufaktur_config/class.dialog.php';
// load the standard functions of LEPTON framework
require_once LEPTON_PATH . '/framework/functions.php';
class cronjobBackend {
const REQUEST_ACTION = 'act';
const REQUEST_ITEMS = 'its';
const ACTION_ABOUT = 'abt';
const ACTION_CONFIG = 'cfg';
const ACTION_DEFAULT = 'def';
const ACTION_CRONJOBS = 'cron';
const ACTION_EDIT = 'edt';
const ACTION_EDIT_CHECK = 'edtc';
const ACTION_PROTOCOL = 'prt';
private static $page_link = '';
private static $img_url = '';
private static $error = '';
private static $message = '';
protected $lang = NULL;
protected static $tab_navigation_array = null;
public function __construct() {
global $I18n;
self::$page_link = ADMIN_URL . '/admintools/tool.php?tool=kit_cronjob';
self::$img_url = LEPTON_URL . '/modules/' . basename(dirname(__FILE__)) . '/images/';
date_default_timezone_set(CFG_TIME_ZONE);
$this->lang = $I18n;
// don't translate the Tab Strings here - this will be done in the template!
self::$tab_navigation_array = array(
self::ACTION_CRONJOBS => 'Cronjob list',
self::ACTION_EDIT => 'Cronjob edit',
self::ACTION_PROTOCOL => 'Protocol',
self::ACTION_CONFIG => 'Settings',
self::ACTION_ABOUT => 'About');
} // __construct()
/**
* Set self::$error to $error
*
* @param $error string
*/
protected function setError($error) {
self::$error = $error;
} // setError()
/**
* Get Error from self::$error;
*
* @return string self::$error
*/
public function getError() {
return self::$error;
} // getError()
/**
* Check if self::$error is empty
*
* @return boolean
*/
public function isError() {
return (bool) !empty(self::$error);
} // isError
/**
* Set self::$message to $message
*
* @param $message string
*/
protected function setMessage($message) {
self::$message = $message;
} // setMessage()
/**
* Get Message from self::$message;
*
* @return string self::$message
*/
public function getMessage() {
return self::$message;
} // getMessage()
/**
* Check if self::$message is empty
*
* @return boolean
*/
public function isMessage() {
return (bool) !empty(self::$message);
} // isMessage
/**
* Return Version of Module
*
* @return float
*/
public function getVersion() {
// read info.php into array
$info_text = file(LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/info.php');
if ($info_text == false) {
return -1;
}
// walk through array
foreach ($info_text as $item) {
if (strpos($item, '$module_version') !== false) {
// split string $module_version
$value = explode('=', $item);
// return floatval
return floatval(preg_replace('([\'";,\(\)[:space:][:alpha:]])', '', $value[1]));
}
}
return -1;
} // getVersion()
/**
* Return the needed template
*
* @param $template string
* @param $template_data array
*/
protected function getTemplate($template, $template_data) {
global $parser;
$template_path = LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/templates/backend/';
// check if a custom template exists ...
$load_template = (file_exists($template_path . 'custom.' . $template)) ? $template_path . 'custom.' . $template
: $template_path . $template;
try {
$result = $parser->get($load_template, $template_data);
} catch (Exception $e) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__,
$this->lang->translate('Error executing the template <b>{{ template }}</b>: {{ error }}',
array(
'template' => basename($load_template),
'error' => $e->getMessage())
)));
return false;
}
return $result;
} // getTemplate()
/**
* Verhindert XSS Cross Site Scripting
*
* @param $_REQUEST reference array
* @return $request
*/
protected function xssPrevent(&$request) {
if (is_string($request)) {
$request = html_entity_decode($request);
$request = strip_tags($request);
$request = trim($request);
$request = stripslashes($request);
}
return $request;
} // xssPrevent()
/**
* Action handler of the class
*
* @return string result dialog or message
*/
public function action() {
$html_allowed = array();
foreach ($_REQUEST as $key => $value) {
// ignore config values!
if (!in_array($key, $html_allowed)) {
$_REQUEST[$key] = $this->xssPrevent($value);
}
}
$action = isset($_REQUEST[self::REQUEST_ACTION]) ? $_REQUEST[self::REQUEST_ACTION] : self::ACTION_DEFAULT;
switch ($action) :
case self::ACTION_CONFIG:
$this->show(self::ACTION_CONFIG, $this->dlgConfig());
break;
case self::ACTION_ABOUT:
$this->show(self::ACTION_ABOUT, $this->dlgAbout());
break;
case self::ACTION_EDIT:
$this->show(self::ACTION_EDIT, $this->dlgEdit());
break;
case self::ACTION_EDIT_CHECK:
$this->show(self::ACTION_EDIT, $this->checkEdit());
break;
case self::ACTION_PROTOCOL:
$this->show(self::ACTION_PROTOCOL, $this->dlgProtocol());
break;
case self::ACTION_CRONJOBS:
$this->show(self::ACTION_CRONJOBS, $this->dlgCronjobs());
break;
default:
$this->show(self::ACTION_ABOUT, $this->dlgAbout());
break;
endswitch;
} // action
/**
* Ausgabe des formatierten Ergebnis mit Navigationsleiste
*
* @param string $action aktives Navigationselement
* @param string $content Inhalt
*
* @return echo result
*/
protected function show($action, $content) {
$navigation = array();
foreach (self::$tab_navigation_array as $key => $value) {
$navigation[] = array(
'active' => ($key == $action) ? 1 : 0,
'url' => sprintf('%s&%s', self::$page_link, http_build_query(array(
self::REQUEST_ACTION => $key))),
'text' => $value);
}
$data = array(
'LEPTON_URL' => LEPTON_URL,
'IMG_URL' => self::$img_url,
'navigation' => $navigation,
'error' => ($this->isError()) ? 1 : 0,
'content' => ($this->isError()) ? $this->getError() : $content);
echo $this->getTemplate('body.lte', $data);
} // show()
/**
* Information about kitIdea
*
* @return string dialog
*/
protected function dlgAbout() {
$notes = file_get_contents(LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/CHANGELOG');
$use_markdown = 0;
if (file_exists(LEPTON_PATH.'/modules/lib_markdown/standard/markdown.php')) {
require_once LEPTON_PATH.'/modules/lib_markdown/standard/markdown.php';
$notes = Markdown($notes);
$use_markdown = 1;
}
$data = array(
'img_url' => self::$img_url,
'release' => array(
'number' => sprintf('%01.2f', $this->getVersion()),
'notes' => $notes,
'use_markdown' => $use_markdown
)
);
//_notes' => file_get_contents(LEPTON_PATH . '/modules/' . basename(dirname(__FILE__)) . '/info.txt'),);
return $this->getTemplate('about.lte', $data);
} // dlgAbout()
/**
* kitCronjob settings
*
* @return string dialog
*/
protected function dlgConfig() {
// set the link to call the dlgConfig()
$link = sprintf('%s&%s',
self::$page_link,
http_build_query(array(
self::REQUEST_ACTION => self::ACTION_CONFIG
)));
// set the abort link
$abort = sprintf('%s&%s',
self::$page_link,
http_build_query(array(
self::REQUEST_ACTION => self::ACTION_DEFAULT
)));
// exec manufakturConfig
$dialog = new manufakturConfigDialog('kit_cronjob', 'kitCronjob', $link, $abort);
return $dialog->action();
} // dlgConfig()
/**
* Dialog for create or edit a Cronjob
*
* @return boolean|Ambigous <boolean, string, mixed>
*/
protected function dlgEdit() {
global $cronjobInterface;
$id = isset($_REQUEST[cronjobInterface::CRONJOB_ID]) ? (int) $_REQUEST[cronjobInterface::CRONJOB_ID]
: -1;
if ($id < 1) {
// create a new cronjob
$fields = $cronjobInterface->getCronjobFieldArray();
$fields[cronjobInterface::CRONJOB_ID] = -1;
} else {
$fields = array();
if (!$cronjobInterface->getCronjob($id, $fields)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
if (count($fields) < 1) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $this->lang->translate('The cronjob with the ID {{ id }} does not exists!', array(
'id' => $id))));
return false;
}
}
// walk through the fields and check for $_REQUESTs
$cronjobInterface->checkCronjobRequests($fields);
$items = array();
// walk through the fields and build the $items array for the template
foreach ($fields as $key => $value) {
if (isset($_REQUEST[$key]))
$value = $_REQUEST[$key];
$items[$key] = array('name' => $key, 'value' => $value);
switch ($key) {
case cronjobInterface::CRONJOB_STATUS:
// ENUM() fields
$entries = array('ACTIVE','LOCKED','DELETED');
$items[$key]['options'] = $entries;
break;
case cronjobinterface::CRONJOB_MINUTE:
case cronjobInterface::CRONJOB_HOUR:
case cronjobInterface::CRONJOB_DAY_OF_MONTH:
case cronjobInterface::CRONJOB_DAY_OF_WEEK:
case cronjobInterface::CRONJOB_MONTH:
$entries = array();
if (!$cronjobInterface->fieldDefaults2array($key, $entries)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
$items[$key]['options'] = $entries;
break;
case cronjobInterface::CRONJOB_LAST_RUN:
case cronjobInterface::CRONJOB_NEXT_RUN:
case cronjobInterface::CRONJOB_TIMESTAMP:
if ($value == '0000-00-00 00:00:00') {
$items[$key]['formatted'] = '';
} else {
$items[$key]['formatted'] = date(CFG_DATETIME_STR, strtotime($value));
}
default:
break;
}
}
$data = array(
'form' => array('name' => 'cronjob_edit', 'action' => self::$page_link),
'action' => array(
'name' => self::REQUEST_ACTION,
'value' => self::ACTION_EDIT_CHECK),
'message' => array(
'active' => (int) $this->isMessage(),
'text' => $this->isMessage() ? $this->getMessage() : ''),
'fields' => $items,
'img_url' => self::$img_url,);
return $this->getTemplate('cronjob.lte', $data);
} // dlgEdit()
/**
* Check the user input of the dlgEdit() and create or update a cronjob record
*
* @return boolean|string
*/
protected function checkEdit() {
global $cronjobInterface;
$checked = true;
// check if each cronjob value isset
if (!isset($_REQUEST[cronjobInterface::CRONJOB_HOUR]) || !isset($_REQUEST[cronjobInterface::CRONJOB_MINUTE]) || !isset($_REQUEST[cronjobInterface::CRONJOB_DAY_OF_MONTH]) || !isset($_REQUEST[cronjobInterface::CRONJOB_DAY_OF_WEEK]) || !isset($_REQUEST[cronjobInterface::CRONJOB_MONTH]))
$checked = false;
if (!$checked) {
$this->setMessage($this->lang->translate('At minimum please set a value for hour, minute, day, weekday and month for definition of the cronjob!'));
return $this->dlgEdit();
}
// check the cronjob name
if (empty($_REQUEST[cronjobInterface::CRONJOB_NAME])) {
$this->setMessage($this->lang->translate('Please define a unique name for the cronjob!'));
return $this->dlgEdit();
}
$minimum_name_length = $cronjobInterface->getCronjobConfigValue(cronjobInterface::CFG_CRONJOB_NAME_MINIMUM_LENGTH);
if (strlen(trim($_REQUEST[cronjobInterface::CRONJOB_NAME])) < $minimum_name_length) {
$this->setMessage($this->lang->translate('The cronjob name must be at minimum {{ length }} characters long.', array(
'length' => $minimum_name_length)));
return $this->dlgEdit();
}
// check the cronjob command
if (empty($_REQUEST[cronjobInterface::CRONJOB_COMMAND])) {
$this->setMessage($this->lang->translate('Please define the command to execute by the cronjob!'));
return $this->dlgEdit();
}
if ($_REQUEST[cronjobInterface::CRONJOB_ID] > 0) {
// already existing cronjob
$cronjob = array();
if (false === ($cronjobInterface->getCronjob($_REQUEST[cronjobInterface::CRONJOB_ID], $cronjob))) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
// read the $_REQUEST's into an array
$new_cronjob = array();
$cronjobInterface->checkCronjobRequests($new_cronjob);
if ($cronjob[cronjobInterface::CRONJOB_NAME] != $new_cronjob[cronjobInterface::CRONJOB_NAME]) {
// cronjob name changed - check if the name is unique!
if (!$cronjobInterface->checkCronjobNameIsUnique($new_cronjob[cronjobInterface::CRONJOB_NAME], $cronjob[cronjobInterface::CRONJOB_ID])) {
if ($cronjobInterface->isError()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
$this->setMessage($this->lang->translate('The cronjob name {{ name }} is not unique, please select another name!', array(
'name' => $cronjob[cronjobInterface::CRONJOB_NAME])));
return $this->dlgEdit();
}
}
} else {
// create a new cronjob
$conjob = array();
$cronjobInterface->checkCronjobRequests($cronjob);
// check the cronjob name - must be unique!
if (!$cronjobInterface->checkCronjobNameIsUnique($cronjob[cronjobInterface::CRONJOB_NAME])) {
if ($cronjobInterface->isError()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
$this->setMessage($this->lang->translate('The cronjob name {{ name }} is not unique, please select another name!', array(
'name' => $cronjob[cronjobInterface::CRONJOB_NAME])));
return $this->dlgEdit();
}
}
// ok - save the cronjob
$data = array();
foreach ($cronjobInterface->getCronjobFieldArray() as $key => $value) {
if (isset($_REQUEST[$key])) {
switch ($key) {
case cronjobinterface::CRONJOB_MINUTE:
case cronjobInterface::CRONJOB_HOUR:
case cronjobInterface::CRONJOB_DAY_OF_MONTH:
case cronjobInterface::CRONJOB_DAY_OF_WEEK:
case cronjobInterface::CRONJOB_MONTH:
// implode array values
if (is_array($_REQUEST[$key])) {
$data[$key] = implode(',', $_REQUEST[$key]);
} else {
$data[$key] = '';
}
break;
case cronjobInterface::CRONJOB_LAST_RUN:
case cronjobInterface::CRONJOB_NEXT_RUN:
case cronjobInterface::CRONJOB_TIMESTAMP:
// nothing to do ...
break;
case cronjobInterface::CRONJOB_NAME:
// convert to a save name
$name = trim($_REQUEST[$key]);
$name = page_filename($name);
$data[$key] = $name;
$_REQUEST[$key] = $name;
break;
default:
// simply save the value
$data[$key] = $_REQUEST[$key];
break;
}
}
}
if ($_REQUEST[cronjobInterface::CRONJOB_ID] > 0) {
// update existing cronjob
$id = $_REQUEST[cronjobInterface::CRONJOB_ID];
if (!$cronjobInterface->updateCronjob($id, $data)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
$this->setMessage($this->lang->translate('The cronjob with the ID {{ id }} was successfull updated.', array(
'id' => $id)));
} else {
// insert a new cronjob
$id = -1;
if (!$cronjobInterface->insertCronjob($data, $id)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
$this->setMessage($this->lang->translate('The cronjob with the ID {{ id }} was successfull inserted', array(
'id' => $id)));
}
foreach ($cronjobInterface->getCronjobFieldArray() as $key => $value) {
if (isset($_REQUEST[$key]))
unset($_REQUEST[$key]);
}
$_REQUEST[cronjobInterface::CRONJOB_ID] = $id;
return $this->dlgEdit();
} // checkEdit()
protected function dlgCronjobs() {
global $cronjobInterface;
$cronjobs = array();
if (!$cronjobInterface->getCronjobsByStatus($cronjobs)) {
$this->setError(sprintf('[%s .- %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
$items = array();
$options_minute = array();
$options_hour = array();
$options_day_of_month = array();
$options_day_of_week = array();
$options_month = array();
$cronjobInterface->fieldDefaults2array(cronjobInterface::CRONJOB_MINUTE, $options_minute);
$cronjobInterface->fieldDefaults2array(cronjobInterface::CRONJOB_HOUR, $options_hour);
$cronjobInterface->fieldDefaults2array(cronjobInterface::CRONJOB_DAY_OF_MONTH, $options_day_of_month);
$cronjobInterface->fieldDefaults2array(cronjobInterface::CRONJOB_DAY_OF_WEEK, $options_day_of_week);
$cronjobInterface->fieldDefaults2array(cronjobInterface::CRONJOB_MONTH, $options_month);
foreach ($cronjobs as $cronjob) {
$items[$cronjob[cronjobInterface::CRONJOB_ID]] = array(
'id' => array(
'name' => cronjobInterface::CRONJOB_ID,
'value' => $cronjob[cronjobInterface::CRONJOB_ID]
),
'name' => array(
'name' => cronjobInterface::CRONJOB_NAME,
'value' => $cronjob[cronjobInterface::CRONJOB_NAME]
),
'description' => array(
'name' => cronjobInterface::CRONJOB_DESCRIPTION,
'value' => $cronjob[cronjobInterface::CRONJOB_DESCRIPTION]
),
'minutes' => array(
'name' => cronjobInterface::CRONJOB_MINUTE,
'values' => $cronjob[cronjobInterface::CRONJOB_MINUTE],
'options' => $options_minute
),
'hours' => array(
'name' => cronjobInterface::CRONJOB_HOUR,
'values' => $cronjob[cronjobInterface::CRONJOB_HOUR],
'options' => $options_hour
),
'days_of_month' => array(
'name' => cronjobInterface::CRONJOB_DAY_OF_MONTH,
'values' => $cronjob[cronjobInterface::CRONJOB_DAY_OF_MONTH],
'options' => $options_day_of_month
),
'days_of_week' => array(
'name' => cronjobInterface::CRONJOB_DAY_OF_WEEK,
'values' => $cronjob[cronjobInterface::CRONJOB_DAY_OF_WEEK],
'options' => $options_day_of_week
),
'months' => array(
'name' => cronjobInterface::CRONJOB_MONTH,
'values' => $cronjob[cronjobInterface::CRONJOB_MONTH],
'options' => $options_month
),
'command' => array(
'name' => cronjobInterface::CRONJOB_COMMAND,
'value' => $cronjob[cronjobInterface::CRONJOB_COMMAND],
),
'last_run' => array(
'name' => cronjobInterface::CRONJOB_LAST_RUN,
'value' => $cronjob[cronjobInterface::CRONJOB_LAST_RUN],
'formatted' => ($cronjob[cronjobInterface::CRONJOB_LAST_RUN] != '0000-00-00 00:00:00') ? date(CFG_DATETIME_STR, strtotime($cronjob[cronjobInterface::CRONJOB_LAST_RUN])) : ''
),
'next_run' => array(
'name' => cronjobInterface::CRONJOB_NEXT_RUN,
'value' => $cronjob[cronjobInterface::CRONJOB_NEXT_RUN],
'formatted' => ($cronjob[cronjobInterface::CRONJOB_NEXT_RUN] != '0000-00-00 00:00:00') ? date(CFG_DATETIME_STR, strtotime($cronjob[cronjobInterface::CRONJOB_NEXT_RUN])) : ''
),
'last_status' => array(
'name' => cronjobInterface::CRONJOB_LAST_STATUS,
'value' => $cronjob[cronjobInterface::CRONJOB_LAST_STATUS]
),
'status' => array(
'name' => cronjobInterface::CRONJOB_STATUS,
'value' => $cronjob[cronjobInterface::CRONJOB_STATUS],
'options' => array('ACTIVE','LOCKED','DELETED') //$cronjobInterface->enumColumn2array(cronjobInterface::CRONJOB_STATUS)
),
'timestamp' => array(
'name' => cronjobInterface::CRONJOB_TIMESTAMP,
'value' => $cronjob[cronjobInterface::CRONJOB_TIMESTAMP],
'formatted' => date(CFG_DATETIME_STR, strtotime($cronjob[cronjobInterface::CRONJOB_TIMESTAMP]))
),
'action' => array(
'edit' => sprintf('%s&%s', self::$page_link, http_build_query(array(
self::REQUEST_ACTION => self::ACTION_EDIT,
cronjobInterface::CRONJOB_ID => $cronjob[cronjobInterface::CRONJOB_ID]
))),
)
);
}
$data = array(
'message' => array(
'active' => (int) $this->isMessage(),
'text' => $this->getMessage()
),
'cronjob' => array(
'items' => $items,
'count' => count($items)
)
);
return $this->getTemplate('list.lte', $data);
} // dlgCronjob()
/**
* Show the kitCronjob protocol
*
* @return string dialog
*/
protected function dlgProtocol() {
global $cronjobInterface;
if (!$cronjobInterface->shrinkProtocol()) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
// limit the entries of the protocol
$limit = $cronjobInterface->getCronjobConfigValue(cronjobInterface::CFG_LOG_LIST_LIMIT);
// suppress no-load entries in the protocol
$show_no_load = $cronjobInterface->getCronjobConfigValue(cronjobInterface::CFG_LOG_SHOW_NO_LOAD);
$protocol = array();
if (!$cronjobInterface->getCronjobProtocol($protocol, $limit, $show_no_load)) {
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $cronjobInterface->getError()));
return false;
}
if (count($protocol) > 0) {
$last_call = $protocol[0]['log_timestamp'];
}
else {
$last_call = 0;
}
$key = $cronjobInterface->getCronjobConfigValue(cronjobInterface::CFG_CRONJOB_KEY);
$data = array(
'cronjob' => array(
'url' => sprintf('%s/modules/kit_cronjob/cronjob.php?key=%s', LEPTON_URL, $key)
),
'protocol' => array(
'last_call' => $last_call,
'count' => count($protocol),
'entries' => $protocol,
),
'message' => array(
'active' => (int) $this->isMessage(),
'text' => $this->getMessage()
),
);
return $this->getTemplate('protocol.lte', $data);
} // dlgProtocol()
} // class cronjobBackend