[FEATURE] Intgrate CSS class "lead" for introductions
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Controller / SchedulerModuleController.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Fran├žois Suter <francois@typo3.org>
8 * (c) 2005-2013 Christian Jul Jensen <julle@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32
33 /**
34 * Module 'TYPO3 Scheduler administration module' for the 'scheduler' extension.
35 *
36 * @author Fran├žois Suter <francois@typo3.org>
37 * @author Christian Jul Jensen <julle@typo3.org>
38 * @author Ingo Renner <ingo@typo3.org>
39 */
40 class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
41
42 /**
43 * Back path to typo3 main dir
44 *
45 * @var string $backPath
46 */
47 public $backPath;
48
49 /**
50 * Array containing submitted data when editing or adding a task
51 *
52 * @var array $submittedData
53 */
54 protected $submittedData = array();
55
56 /**
57 * Array containing all messages issued by the application logic
58 * Contains the error's severity and the message itself
59 *
60 * @var array $messages
61 */
62 protected $messages = array();
63
64 /**
65 * @var string Key of the CSH file
66 */
67 protected $cshKey;
68
69 /**
70 * @var \TYPO3\CMS\Scheduler\Scheduler Local scheduler instance
71 */
72 protected $scheduler;
73
74 /**
75 * Constructor
76 *
77 * @return \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
78 */
79 public function __construct() {
80 $this->backPath = $GLOBALS['BACK_PATH'];
81 // Set key for CSH
82 $this->cshKey = '_MOD_' . $GLOBALS['MCONF']['name'];
83 }
84
85 /**
86 * Initializes the backend module
87 *
88 * @return void
89 */
90 public function init() {
91 parent::init();
92 // Initialize document
93 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
94 $this->doc->setModuleTemplate(ExtensionManagementUtility::extPath('scheduler') . 'mod1/mod_template.html');
95 $this->doc->getPageRenderer()->addCssFile(ExtensionManagementUtility::extRelPath('scheduler') . 'res/tx_scheduler_be.css');
96 $this->doc->backPath = $this->backPath;
97 $this->doc->bodyTagId = 'typo3-mod-php';
98 $this->doc->bodyTagAdditions = 'class="tx_scheduler_mod1"';
99 // Create scheduler instance
100 $this->scheduler = GeneralUtility::makeInstance('TYPO3\\CMS\\Scheduler\\Scheduler');
101 }
102
103 /**
104 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
105 *
106 * @return void
107 */
108 public function menuConfig() {
109 $this->MOD_MENU = array(
110 'function' => array(
111 'scheduler' => $GLOBALS['LANG']->getLL('function.scheduler'),
112 'check' => $GLOBALS['LANG']->getLL('function.check'),
113 'info' => $GLOBALS['LANG']->getLL('function.info')
114 )
115 );
116 parent::menuConfig();
117 }
118
119 /**
120 * Main function of the module. Write the content to $this->content
121 *
122 * @return void
123 */
124 public function main() {
125 // Access check!
126 // The page will show only if user has admin rights
127 if ($GLOBALS['BE_USER']->user['admin']) {
128 // Set the form
129 $this->doc->form = '<form name="tx_scheduler_form" id="tx_scheduler_form" method="post" action="">';
130 // JavaScript for main function menu
131 $this->doc->JScode = '
132 <script language="javascript" type="text/javascript">
133 script_ended = 0;
134 function jumpToUrl(URL) {
135 document.location = URL;
136 }
137 </script>
138 ';
139 $this->doc->getPageRenderer()->addInlineSetting('scheduler', 'runningIcon', ExtensionManagementUtility::extRelPath('scheduler') . 'res/gfx/status_running.png');
140 // Prepare main content
141 $this->content = $this->doc->header($GLOBALS['LANG']->getLL('function.' . $this->MOD_SETTINGS['function']));
142 $this->content .= $this->getModuleContent();
143 } else {
144 // If no access, only display the module's title
145 $this->content = $this->doc->header($GLOBALS['LANG']->getLL('title'));
146 $this->content .= $this->doc->spacer(5);
147 }
148 // Place content inside template
149 $content = $this->doc->moduleBody(array(), $this->getDocHeaderButtons(), $this->getTemplateMarkers());
150 // Renders the module page
151 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $content);
152 }
153
154 /**
155 * Generate the module's content
156 *
157 * @return string HTML of the module's main content
158 */
159 protected function getModuleContent() {
160 $content = '';
161 $sectionTitle = '';
162 // Get submitted data
163 $this->submittedData = GeneralUtility::_GPmerged('tx_scheduler');
164 $this->submittedData['uid'] = intval($this->submittedData['uid']);
165 // If a save command was submitted, handle saving now
166 if ($this->CMD == 'save' || $this->CMD == 'saveclose') {
167 $previousCMD = GeneralUtility::_GP('previousCMD');
168 // First check the submitted data
169 $result = $this->preprocessData();
170 // If result is ok, proceed with saving
171 if ($result) {
172 $this->saveTask();
173 if ($this->CMD == 'saveclose') {
174 // Unset command, so that default screen gets displayed
175 unset($this->CMD);
176 } elseif ($this->CMD == 'save') {
177 // After saving a "add form", return to edit
178 $this->CMD = 'edit';
179 } else {
180 // Return to edit form
181 $this->CMD = $previousCMD;
182 }
183 } else {
184 $this->CMD = $previousCMD;
185 }
186 }
187 // Handle chosen action
188 switch ((string) $this->MOD_SETTINGS['function']) {
189 case 'scheduler':
190 // Scheduler's main screen
191 $this->executeTasks();
192 // Execute chosen action
193 switch ($this->CMD) {
194 case 'add':
195
196 case 'edit':
197 try {
198 // Try adding or editing
199 $content .= $this->editTask();
200 $sectionTitle = $GLOBALS['LANG']->getLL('action.' . $this->CMD);
201 } catch (\Exception $e) {
202 // An exception may happen when the task to
203 // edit could not be found. In this case revert
204 // to displaying the list of tasks
205 // It can also happen when attempting to edit a running task
206 $content .= $this->listTasks();
207 }
208 break;
209 case 'delete':
210 $this->deleteTask();
211 $content .= $this->listTasks();
212 break;
213 case 'stop':
214 $this->stopTask();
215 $content .= $this->listTasks();
216 break;
217 case 'list':
218
219 default:
220 $content .= $this->listTasks();
221 }
222 break;
223 case 'check':
224 // Setup check screen
225 // TODO: move check to the report module
226 $content .= $this->displayCheckScreen();
227 break;
228 case 'info':
229 // Information screen
230 $content .= $this->displayInfoScreen();
231 break;
232 }
233 // Wrap the content in a section
234 return $this->doc->section($sectionTitle, '<div class="tx_scheduler_mod1">' . $content . '</div>', 0, 1);
235 }
236
237 /**
238 * This method actually prints out the module's HTML content
239 *
240 * @return void
241 */
242 public function render() {
243 echo $this->content;
244 }
245
246 /**
247 * This method checks the status of the '_cli_scheduler' user
248 * It will differentiate between a non-existing user and an existing,
249 * but disabled user (as per enable fields)
250 *
251 * @return integer -1 if user doesn't exist
252 */
253 protected function checkSchedulerUser() {
254 $schedulerUserStatus = -1;
255 // Assemble base WHERE clause
256 $where = 'username = \'_cli_scheduler\' AND admin = 0' . BackendUtility::deleteClause('be_users');
257 // Check if user exists at all
258 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('1', 'be_users', $where);
259 if ($GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
260 $schedulerUserStatus = 0;
261 // Check if user exists and is enabled
262 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('1', 'be_users', $where . BackendUtility::BEenableFields('be_users'));
263 if ($GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
264 $schedulerUserStatus = 1;
265 }
266 }
267 $GLOBALS['TYPO3_DB']->sql_free_result($res);
268 return $schedulerUserStatus;
269 }
270
271 /**
272 * This method creates the "cli_scheduler" BE user if it doesn't exist
273 *
274 * @return void
275 */
276 protected function createSchedulerUser() {
277 // Check _cli_scheduler user status
278 $checkUser = $this->checkSchedulerUser();
279 // Prepare default message
280 $message = $GLOBALS['LANG']->getLL('msg.userExists');
281 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING;
282 // If the user does not exist, try creating it
283 if ($checkUser == -1) {
284 // Prepare necessary data for _cli_scheduler user creation
285 $password = md5(uniqid('scheduler', TRUE));
286 $data = array('be_users' => array('NEW' => array('username' => '_cli_scheduler', 'password' => $password, 'pid' => 0)));
287 /** @var $tcemain \TYPO3\CMS\Core\DataHandling\DataHandler */
288 $tcemain = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
289 $tcemain->stripslashes_values = 0;
290 $tcemain->start($data, array());
291 $tcemain->process_datamap();
292 // Check if a new uid was indeed generated (i.e. a new record was created)
293 // (counting TCEmain errors doesn't work as some failures don't report errors)
294 $numberOfNewIDs = count($tcemain->substNEWwithIDs);
295 if ($numberOfNewIDs == 1) {
296 $message = $GLOBALS['LANG']->getLL('msg.userCreated');
297 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK;
298 } else {
299 $message = $GLOBALS['LANG']->getLL('msg.userNotCreated');
300 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR;
301 }
302 }
303 $this->addMessage($message, $severity);
304 }
305
306 /**
307 * This method displays the result of a number of checks
308 * on whether the Scheduler is ready to run or running properly
309 *
310 * @return string Further information
311 */
312 protected function displayCheckScreen() {
313 $message = '';
314 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK;
315 // First, check if _cli_scheduler user creation was requested
316 if ($this->CMD == 'user') {
317 $this->createSchedulerUser();
318 }
319
320 // Start generating the content
321 $content = '<p class="lead">' . $GLOBALS['LANG']->getLL('msg.schedulerSetupCheck') . '</p>';
322
323 // Display information about last automated run, as stored in the system registry
324 /** @var $registry \TYPO3\CMS\Core\Registry */
325 $registry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
326 $lastRun = $registry->get('tx_scheduler', 'lastRun');
327 if (!is_array($lastRun)) {
328 $message = $GLOBALS['LANG']->getLL('msg.noLastRun');
329 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING;
330 } else {
331 if (empty($lastRun['end']) || empty($lastRun['start']) || empty($lastRun['type'])) {
332 $message = $GLOBALS['LANG']->getLL('msg.incompleteLastRun');
333 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING;
334 } else {
335 $startDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $lastRun['start']);
336 $startTime = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $lastRun['start']);
337 $endDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $lastRun['end']);
338 $endTime = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $lastRun['end']);
339 $label = 'automatically';
340 if ($lastRun['type'] == 'manual') {
341 $label = 'manually';
342 }
343 $type = $GLOBALS['LANG']->getLL('label.' . $label);
344 $message = sprintf($GLOBALS['LANG']->getLL('msg.lastRun'), $type, $startDate, $startTime, $endDate, $endTime);
345 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::INFO;
346 }
347 }
348 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
349 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, '', $severity);
350
351 $content .= '<div class="info-block">';
352 $content .= '<h2>' . $GLOBALS['LANG']->getLL('hdg.lastRun') . '</h2>';
353 $content .= $flashMessage->render();
354 $content .= '</div>';
355
356 // Check CLI user
357 $content .= '<div class="info-block">';
358 $content .= '<h2>' . $GLOBALS['LANG']->getLL('hdg.schedulerUser') . '</h2>';
359 $content .= '<p>' . $GLOBALS['LANG']->getLL('msg.schedulerUser') . '</p>';
360 $checkUser = $this->checkSchedulerUser();
361 if ($checkUser == -1) {
362 $link = $GLOBALS['MCONF']['_'] . '&SET[function]=check&CMD=user';
363 $message = sprintf($GLOBALS['LANG']->getLL('msg.schedulerUserMissing'), htmlspecialchars($link));
364 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR;
365 } elseif ($checkUser == 0) {
366 $message = $GLOBALS['LANG']->getLL('msg.schedulerUserFoundButDisabled');
367 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING;
368 } else {
369 $message = $GLOBALS['LANG']->getLL('msg.schedulerUserFound');
370 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK;
371 }
372 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, '', $severity);
373 $content .= $flashMessage->render() . '</div>';
374
375 // Check if CLI script is executable or not
376 $script = PATH_typo3 . 'cli_dispatch.phpsh';
377 $isExecutable = FALSE;
378 // Skip this check if running Windows, as rights do not work the same way on this platform
379 // (i.e. the script will always appear as *not* executable)
380 if (TYPO3_OS === 'WIN') {
381 $isExecutable = TRUE;
382 } else {
383 $isExecutable = is_executable($script);
384 }
385 $content .= '<div class="info-block">';
386 $content .= '<h2>' . $GLOBALS['LANG']->getLL('hdg.cliScript') . '</h2>';
387 $content .= '<p>' . sprintf($GLOBALS['LANG']->getLL('msg.cliScript'), $script) . '</p>';
388 if ($isExecutable) {
389 $message = $GLOBALS['LANG']->getLL('msg.cliScriptExecutable');
390 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK;
391 } else {
392 $message = $GLOBALS['LANG']->getLL('msg.cliScriptNotExecutable');
393 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR;
394 }
395 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, '', $severity);
396 $content .= $flashMessage->render() . '</div>';
397 return $content;
398 }
399
400 /**
401 * This method gathers information about all available task classes and displays it
402 *
403 * @return string HTML content to display
404 */
405 protected function displayInfoScreen() {
406 $content = '';
407 $registeredClasses = self::getRegisteredClasses();
408 // No classes available, display information message
409 if (count($registeredClasses) == 0) {
410 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
411 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('msg.noTasksDefined'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
412 $content .= $flashMessage->render();
413 } else {
414 // Initialise table layout
415 $tableLayout = array(
416 'table' => array('<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist">', '</table>'),
417 '0' => array(
418 'tr' => array('<tr class="t3-row-header" valign="top">', '</tr>'),
419 'defCol' => array('<td>', '</td>')
420 ),
421 'defRow' => array(
422 'tr' => array('<tr class="db_list_normal">', '</tr>'),
423 'defCol' => array('<td>', '</td>')
424 )
425 );
426 $table = array();
427 $tr = 0;
428 // Header row
429 $table[$tr][] = $GLOBALS['LANG']->getLL('label.name');
430 $table[$tr][] = $GLOBALS['LANG']->getLL('label.extension');
431 $table[$tr][] = $GLOBALS['LANG']->getLL('label.description');
432 $table[$tr][] = '';
433 $tr++;
434 // Display information about each service
435 foreach ($registeredClasses as $class => $classInfo) {
436 $table[$tr][] = $classInfo['title'];
437 $table[$tr][] = $classInfo['extension'];
438 $table[$tr][] = $classInfo['description'];
439 $link = $GLOBALS['MCONF']['_'] . '&SET[function]=list&CMD=add&tx_scheduler[class]=' . $class;
440 $table[$tr][] = '<a href="' . htmlspecialchars($link) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:new', TRUE) . '" class="icon">' . IconUtility::getSpriteIcon('actions-document-new') . '</a>';
441 $tr++;
442 }
443 // Render the table and return it
444 $content = '<p class="lead">' . $GLOBALS['LANG']->getLL('msg.infoScreenIntro') . '</p>';
445 $content .= $this->doc->table($table, $tableLayout);
446 }
447 return $content;
448 }
449
450 /**
451 * Display the current server's time along with a help text about server time
452 * usage in the Scheduler
453 *
454 * @return string HTML to display
455 */
456 protected function displayServerTime() {
457 // Get the current time, formatted
458 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ' T (e';
459 $now = date($dateFormat) . ', GMT ' . date('P') . ')';
460 // Display the help text
461 $serverTime = '<h3>' . $GLOBALS['LANG']->getLL('label.serverTime') . '</h3>';
462 $serverTime .= '<p>' . $GLOBALS['LANG']->getLL('msg.serverTimeHelp') . '</p>';
463 $serverTime .= '<p>' . sprintf($GLOBALS['LANG']->getLL('msg.serverTime'), $now) . '</p>';
464 return $serverTime;
465 }
466
467 /**
468 * Renders the task progress bar.
469 *
470 * @param float $progress Task progress
471 * @return string Progress bar markup
472 */
473 protected function renderTaskProgressBar($progress) {
474 $progressText = $GLOBALS['LANG']->getLL('status.progress') . ':&nbsp;' . $progress . '%';
475 $progressBar = '<div class="progress"> <div class="bar" style="width: ' . $progress . '%;">' . $progressText . '</div> </div>';
476 return $progressBar;
477 }
478
479 /**
480 * Delete a task from the execution queue
481 *
482 * @return void
483 */
484 protected function deleteTask() {
485 try {
486 // Try to fetch the task and delete it
487 $task = $this->scheduler->fetchTask($this->submittedData['uid']);
488 // If the task is currently running, it may not be deleted
489 if ($task->isExecutionRunning()) {
490 $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotDeleteRunningTask'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
491 } else {
492 if ($this->scheduler->removeTask($task)) {
493 $GLOBALS['BE_USER']->writeLog(4, 0, 0, 0, 'Scheduler task "%s" (UID: %s, Class: "%s") was deleted', array($task->getTaskTitle(), $task->getTaskUid(), $task->getTaskClassName()));
494 $this->addMessage($GLOBALS['LANG']->getLL('msg.deleteSuccess'));
495 } else {
496 $this->addMessage($GLOBALS['LANG']->getLL('msg.deleteError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
497 }
498 }
499 } catch (\UnexpectedValueException $e) {
500 // The task could not be unserialized properly, simply delete the database record
501 $result = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_scheduler_task', 'uid = ' . intval($this->submittedData['uid']));
502 if ($result) {
503 $this->addMessage($GLOBALS['LANG']->getLL('msg.deleteSuccess'));
504 } else {
505 $this->addMessage($GLOBALS['LANG']->getLL('msg.deleteError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
506 }
507 } catch (\OutOfBoundsException $e) {
508 // The task was not found, for some reason
509 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
510 }
511 }
512
513 /**
514 * Clears the registered running executions from the task
515 * Note that this doesn't actually stop the running script. It just unmarks
516 * all executions.
517 * TODO: find a way to really kill the running task
518 *
519 * @return void
520 */
521 protected function stopTask() {
522 try {
523 // Try to fetch the task and stop it
524 $task = $this->scheduler->fetchTask($this->submittedData['uid']);
525 if ($task->isExecutionRunning()) {
526 // If the task is indeed currently running, clear marked executions
527 $result = $task->unmarkAllExecutions();
528 if ($result) {
529 $this->addMessage($GLOBALS['LANG']->getLL('msg.stopSuccess'));
530 } else {
531 $this->addMessage($GLOBALS['LANG']->getLL('msg.stopError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
532 }
533 } else {
534 // The task is not running, nothing to unmark
535 $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotStopNonRunningTask'), \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
536 }
537 } catch (\Exception $e) {
538 // The task was not found, for some reason
539 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
540 }
541 }
542
543 /**
544 * Return a form to add a new task or edit an existing one
545 *
546 * @return string HTML form to add or edit a task
547 */
548 protected function editTask() {
549 $registeredClasses = self::getRegisteredClasses();
550 $content = '';
551 $taskInfo = array();
552 $task = NULL;
553 $process = 'edit';
554 if ($this->submittedData['uid'] > 0) {
555 // If editing, retrieve data for existing task
556 try {
557 $taskRecord = $this->scheduler->fetchTaskRecord($this->submittedData['uid']);
558 // If there's a registered execution, the task should not be edited
559 if (!empty($taskRecord['serialized_executions'])) {
560 $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotEditRunningTask'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
561 throw new \LogicException('Runnings tasks cannot not be edited', 1251232849);
562 }
563 // Get the task object
564 /** @var $task \TYPO3\CMS\Scheduler\Task\AbstractTask */
565 $task = unserialize($taskRecord['serialized_task_object']);
566 // Set some task information
567 $taskInfo['disable'] = $taskRecord['disable'];
568 // Check that the task object is valid
569 if ($this->scheduler->isValidTaskObject($task)) {
570 // The task object is valid, process with fetching current data
571 $taskInfo['class'] = get_class($task);
572 // Get execution information
573 $taskInfo['start'] = $task->getExecution()->getStart();
574 $taskInfo['end'] = $task->getExecution()->getEnd();
575 $taskInfo['interval'] = $task->getExecution()->getInterval();
576 $taskInfo['croncmd'] = $task->getExecution()->getCronCmd();
577 $taskInfo['multiple'] = $task->getExecution()->getMultiple();
578 if (!empty($taskInfo['interval']) || !empty($taskInfo['croncmd'])) {
579 // Guess task type from the existing information
580 // If an interval or a cron command is defined, it's a recurring task
581 // FIXME: remove magic numbers for the type, use class constants instead
582 $taskInfo['type'] = 2;
583 $taskInfo['frequency'] = empty($taskInfo['interval']) ? $taskInfo['croncmd'] : $taskInfo['interval'];
584 } else {
585 // It's not a recurring task
586 // Make sure interval and cron command are both empty
587 $taskInfo['type'] = 1;
588 $taskInfo['frequency'] = '';
589 $taskInfo['end'] = 0;
590 }
591 } else {
592 // The task object is not valid
593 // Issue error message
594 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.invalidTaskClassEdit'), get_class($task)), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
595 // Initialize empty values
596 $taskInfo['start'] = 0;
597 $taskInfo['end'] = 0;
598 $taskInfo['frequency'] = '';
599 $taskInfo['multiple'] = FALSE;
600 $taskInfo['type'] = 1;
601 }
602 } catch (\OutOfBoundsException $e) {
603 // Add a message and continue throwing the exception
604 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
605 throw $e;
606 }
607 } else {
608 // If adding a new object, set some default values
609 $taskInfo['class'] = key($registeredClasses);
610 $taskInfo['type'] = 2;
611 $taskInfo['start'] = $GLOBALS['EXEC_TIME'];
612 $taskInfo['end'] = '';
613 $taskInfo['frequency'] = '';
614 $taskInfo['multiple'] = 0;
615 $process = 'add';
616 }
617 if (count($this->submittedData) > 0) {
618 // If some data was already submitted, use it to override
619 // existing data
620 $taskInfo = GeneralUtility::array_merge_recursive_overrule($taskInfo, $this->submittedData);
621 }
622 // Get the extra fields to display for each task that needs some
623 $allAdditionalFields = array();
624 if ($process == 'add') {
625 foreach ($registeredClasses as $class => $registrationInfo) {
626 if (!empty($registrationInfo['provider'])) {
627 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
628 $providerObject = GeneralUtility::getUserObj($registrationInfo['provider']);
629 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
630 $additionalFields = $providerObject->getAdditionalFields($taskInfo, NULL, $this);
631 $allAdditionalFields = array_merge($allAdditionalFields, array($class => $additionalFields));
632 }
633 }
634 }
635 } else {
636 if (!empty($registeredClasses[$taskInfo['class']]['provider'])) {
637 $providerObject = GeneralUtility::getUserObj($registeredClasses[$taskInfo['class']]['provider']);
638 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
639 $allAdditionalFields[$taskInfo['class']] = $providerObject->getAdditionalFields($taskInfo, $task, $this);
640 }
641 }
642 }
643 // Load necessary JavaScript
644 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
645 $pageRenderer = $this->doc->getPageRenderer();
646 $pageRenderer->loadExtJS();
647 $pageRenderer->addJsFile(ExtensionManagementUtility::extRelPath('scheduler') . 'res/tx_scheduler_be.js');
648 $pageRenderer->addJsFile($this->backPath . 'sysext/backend/Resources/Public/JavaScript/tceforms.js');
649 $pageRenderer->addJsFile($this->backPath . 'js/extjs/ux/Ext.ux.DateTimePicker.js');
650 // Define settings for Date Picker
651 $typo3Settings = array(
652 'datePickerUSmode' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? 1 : 0,
653 'dateFormat' => array('j-n-Y', 'G:i j-n-Y'),
654 'dateFormatUS' => array('n-j-Y', 'G:i n-j-Y')
655 );
656 $pageRenderer->addInlineSettingArray('', $typo3Settings);
657 // Define table layout for add/edit form
658 $tableLayout = array(
659 'table' => array('<table border="0" cellspacing="0" cellpadding="0" id="edit_form" class="typo3-usersettings">', '</table>')
660 );
661 // Define a style for hiding
662 // Some fields will be hidden when the task is not recurring
663 $style = '';
664 if ($taskInfo['type'] == 1) {
665 $style = ' style="display: none"';
666 }
667 // Start rendering the add/edit form
668 $content .= '<input type="hidden" name="tx_scheduler[uid]" value="' . $this->submittedData['uid'] . '" />';
669 $content .= '<input type="hidden" name="previousCMD" value="' . $this->CMD . '" />';
670 $table = array();
671 $tr = 0;
672 $defaultCell = array('<td class="td-input">', '</td>');
673 // Disable checkbox
674 $label = '<label for="task_disable">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:disable') . '</label>';
675 $table[$tr][] = BackendUtility::wrapInHelp($this->cshKey, 'task_disable', $label);
676 $table[$tr][] = '<input type="hidden" name="tx_scheduler[disable]" value="0" />
677 <input type="checkbox" name="tx_scheduler[disable]" value="1" id="task_disable"' . ($taskInfo['disable'] == 1 ? ' checked="checked"' : '') . ' />';
678 $tableLayout[$tr] = array(
679 'tr' => array('<tr id="task_disable_row">', '</tr>'),
680 'defCol' => $defaultCell,
681 '0' => array('<td class="td-label">', '</td>')
682 );
683 $tr++;
684 // Task class selector
685 $label = '<label for="task_class">' . $GLOBALS['LANG']->getLL('label.class') . '</label>';
686 $table[$tr][] = BackendUtility::wrapInHelp($this->cshKey, 'task_class', $label);
687 // On editing, don't allow changing of the task class, unless it was not valid
688 if ($this->submittedData['uid'] > 0 && !empty($taskInfo['class'])) {
689 $cell = $registeredClasses[$taskInfo['class']]['title'] . ' (' . $registeredClasses[$taskInfo['class']]['extension'] . ')';
690 $cell .= '<input type="hidden" name="tx_scheduler[class]" id="task_class" value="' . $taskInfo['class'] . '" />';
691 } else {
692 $cell = '<select name="tx_scheduler[class]" id="task_class" class="wide" onchange="actOnChangedTaskClass(this)">';
693 // Group registered classes by classname
694 $groupedClasses = array();
695 foreach ($registeredClasses as $class => $classInfo) {
696 $groupedClasses[$classInfo['extension']][$class] = $classInfo;
697 }
698 ksort($groupedClasses);
699 // Loop on all grouped classes to display a selector
700 foreach ($groupedClasses as $extension => $class) {
701 $cell .= '<optgroup label="' . $extension . '">';
702 foreach ($groupedClasses[$extension] as $class => $classInfo) {
703 $selected = $class == $taskInfo['class'] ? ' selected="selected"' : '';
704 $cell .= '<option value="' . $class . '"' . 'title="' . $classInfo['description'] . '"' . $selected . '>' . $classInfo['title'] . '</option>';
705 }
706 $cell .= '</optgroup>';
707 }
708 $cell .= '</select>';
709 }
710 $table[$tr][] = $cell;
711 // Make sure each row has a unique id, for manipulation with JS
712 $tableLayout[$tr] = array(
713 'tr' => array('<tr id="task_class_row">', '</tr>'),
714 'defCol' => $defaultCell,
715 '0' => array('<td class="td-label">', '</td>')
716 );
717 $tr++;
718 // Task type selector
719 $label = '<label for="task_type">' . $GLOBALS['LANG']->getLL('label.type') . '</label>';
720 $table[$tr][] = BackendUtility::wrapInHelp($this->cshKey, 'task_type', $label);
721 $table[$tr][] = '<select name="tx_scheduler[type]" id="task_type" onchange="actOnChangedTaskType(this)">' . '<option value="1"' . ($taskInfo['type'] == 1 ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->getLL('label.type.single') . '</option>' . '<option value="2"' . ($taskInfo['type'] == 2 ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->getLL('label.type.recurring') . '</option>' . '</select>';
722 $tableLayout[$tr] = array(
723 'tr' => array('<tr id="task_type_row">', '</tr>'),
724 'defCol' => $defaultCell,
725 '0' => array('<td class="td-label">', '</td>')
726 );
727 $tr++;
728 // Start date/time field
729 // NOTE: datetime fields need a special id naming scheme
730 $label = '<label for="tceforms-datetimefield-task_start">' . $GLOBALS['LANG']->getLL('label.start') . '</label>';
731 $table[$tr][] = BackendUtility::wrapInHelp($this->cshKey, 'task_start', $label);
732 $table[$tr][] = '<input name="tx_scheduler[start]" type="text" id="tceforms-datetimefield-task_start" value="' . (empty($taskInfo['start']) ? '' : strftime('%H:%M %d-%m-%Y', $taskInfo['start'])) . '" />' . IconUtility::getSpriteIcon('actions-edit-pick-date', array(
733 'style' => 'cursor:pointer;',
734 'id' => 'picker-tceforms-datetimefield-task_start'
735 ));
736 $tableLayout[$tr] = array(
737 'tr' => array('<tr id="task_start_row">', '</tr>'),
738 'defCol' => $defaultCell,
739 '0' => array('<td class="td-label">', '</td>')
740 );
741 $tr++;
742 // End date/time field
743 // NOTE: datetime fields need a special id naming scheme
744 $label = '<label for="tceforms-datetimefield-task_end">' . $GLOBALS['LANG']->getLL('label.end') . '</label>';
745 $table[$tr][] = BackendUtility::wrapInHelp($this->cshKey, 'task_end', $label);
746 $table[$tr][] = '<input name="tx_scheduler[end]" type="text" id="tceforms-datetimefield-task_end" value="' . (empty($taskInfo['end']) ? '' : strftime('%H:%M %d-%m-%Y', $taskInfo['end'])) . '" />' . IconUtility::getSpriteIcon('actions-edit-pick-date', array(
747 'style' => 'cursor:pointer;',
748 'id' => 'picker-tceforms-datetimefield-task_end'
749 ));
750 $tableLayout[$tr] = array(
751 'tr' => array('<tr id="task_end_row"' . $style . '>', '</tr>'),
752 'defCol' => $defaultCell,
753 '0' => array('<td class="td-label">', '</td>')
754 );
755 $tr++;
756 // Frequency input field
757 $label = '<label for="task_frequency">' . $GLOBALS['LANG']->getLL('label.frequency.long') . '</label>';
758 $table[$tr][] = BackendUtility::wrapInHelp($this->cshKey, 'task_frequency', $label);
759 $cell = '<input type="text" name="tx_scheduler[frequency]" id="task_frequency" value="' . htmlspecialchars($taskInfo['frequency']) . '" />';
760 $table[$tr][] = $cell;
761 $tableLayout[$tr] = array(
762 'tr' => array('<tr id="task_frequency_row"' . $style . '>', '</tr>'),
763 'defCol' => $defaultCell,
764 '0' => array('<td class="td-label">', '</td>')
765 );
766 $tr++;
767 // Multiple execution selector
768 $label = '<label for="task_multiple">' . $GLOBALS['LANG']->getLL('label.parallel.long') . '</label>';
769 $table[$tr][] = BackendUtility::wrapInHelp($this->cshKey, 'task_multiple', $label);
770 $table[$tr][] = '<input type="hidden" name="tx_scheduler[multiple]" value="0" />
771 <input type="checkbox" name="tx_scheduler[multiple]" value="1" id="task_multiple"' . ($taskInfo['multiple'] == 1 ? ' checked="checked"' : '') . ' />';
772 $tableLayout[$tr] = array(
773 'tr' => array('<tr id="task_multiple_row"' . $style . '>', '</tr>'),
774 'defCol' => $defaultCell,
775 '0' => array('<td class="td-label">', '</td>')
776 );
777 $tr++;
778 // Display additional fields
779 foreach ($allAdditionalFields as $class => $fields) {
780 if ($class == $taskInfo['class']) {
781 $additionalFieldsStyle = '';
782 } else {
783 $additionalFieldsStyle = ' style="display: none"';
784 }
785 // Add each field to the display, if there are indeed any
786 if (isset($fields) && is_array($fields)) {
787 foreach ($fields as $fieldID => $fieldInfo) {
788 $label = '<label for="' . $fieldID . '">' . $GLOBALS['LANG']->sL($fieldInfo['label']) . '</label>';
789 $table[$tr][] = BackendUtility::wrapInHelp($fieldInfo['cshKey'], $fieldInfo['cshLabel'], $label);
790 $table[$tr][] = $fieldInfo['code'];
791 $htmlClassName = strtolower(str_replace('\\', '-', $class));
792 $tableLayout[$tr] = array(
793 'tr' => array('<tr id="' . $fieldID . '_row"' . $additionalFieldsStyle . ' class="extraFields extra_fields_' . $htmlClassName . '">', '</tr>'),
794 'defCol' => $defaultCell,
795 '0' => array('<td class="td-label">', '</td>')
796 );
797 $tr++;
798 }
799 }
800 }
801 // Render the add/edit task form
802 $content .= '<div style="float: left;"><div class="typo3-dyntabmenu-divs">';
803 $content .= $this->doc->table($table, $tableLayout);
804 $content .= '</div></div>';
805 $content .= '<div style="padding-top: 20px; clear: both;"></div>';
806 // Display information about server time usage
807 $content .= $this->displayServerTime();
808 return $content;
809 }
810
811 /**
812 * Execute all selected tasks
813 *
814 * @return void
815 */
816 protected function executeTasks() {
817 // Make sure next automatic scheduler-run is scheduled
818 if (GeneralUtility::_POST('go') !== NULL) {
819 $this->scheduler->scheduleNextSchedulerRunUsingAtDaemon();
820 }
821 // Continue if some elements have been chosen for execution
822 if (isset($this->submittedData['execute']) && count($this->submittedData['execute']) > 0) {
823 // Get list of registered classes
824 $registeredClasses = self::getRegisteredClasses();
825 // Loop on all selected tasks
826 foreach ($this->submittedData['execute'] as $uid) {
827 try {
828 // Try fetching the task
829 $task = $this->scheduler->fetchTask($uid);
830 $class = get_class($task);
831 $name = $registeredClasses[$class]['title'] . ' (' . $registeredClasses[$class]['extension'] . ')';
832 // Now try to execute it and report on outcome
833 try {
834 $result = $this->scheduler->executeTask($task);
835 if ($result) {
836 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.executed'), $name));
837 } else {
838 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.notExecuted'), $name), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
839 }
840 } catch (\Exception $e) {
841 // An exception was thrown, display its message as an error
842 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.executionFailed'), $name, $e->getMessage()), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
843 }
844 } catch (\OutOfBoundsException $e) {
845 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $uid), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
846 } catch (\UnexpectedValueException $e) {
847 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.executionFailed'), $uid, $e->getMessage()), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
848 }
849 }
850 // Record the run in the system registry
851 $this->scheduler->recordLastRun('manual');
852 // Make sure to switch to list view after execution
853 $this->CMD = 'list';
854 }
855 }
856
857 /**
858 * Assemble display of list of scheduled tasks
859 *
860 * @return string Table of pending tasks
861 */
862 protected function listTasks() {
863 // Define display format for dates
864 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
865 $content = '';
866 // Get list of registered classes
867 $registeredClasses = self::getRegisteredClasses();
868 // Get all registered tasks
869 $query = array(
870 'SELECT' => '*',
871 'FROM' => 'tx_scheduler_task',
872 'WHERE' => '1=1',
873 'ORDERBY' => 'nextexecution'
874 );
875 $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($query);
876 $numRows = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
877 // No tasks defined, display information message
878 if ($numRows == 0) {
879 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
880 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('msg.noTasks'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
881 $content .= $flashMessage->render();
882 } else {
883 // Load ExtJS framework and specific JS library
884 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
885 $pageRenderer = $this->doc->getPageRenderer();
886 $pageRenderer->loadExtJS();
887 $pageRenderer->addJsFile(ExtensionManagementUtility::extRelPath('scheduler') . 'res/tx_scheduler_be.js');
888 // Initialise table layout
889 $tableLayout = array(
890 'table' => array(
891 '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist">',
892 '</table>'
893 ),
894 '0' => array(
895 'tr' => array('<tr class="t3-row-header">', '</tr>'),
896 'defCol' => array('<td>', '</td>'),
897 '1' => array('<td style="width: 56px;">', '</td>'),
898 '3' => array('<td colspan="2">', '</td>')
899 ),
900 'defRow' => array(
901 'tr' => array('<tr class="db_list_normal">', '</tr>'),
902 'defCol' => array('<td>', '</td>'),
903 '1' => array('<td class="right">', '</td>'),
904 '2' => array('<td class="right">', '</td>')
905 )
906 );
907 $disabledTaskRow = array(
908 'tr' => array('<tr class="db_list_normal disabled">', '</tr>'),
909 'defCol' => array('<td>', '</td>'),
910 '1' => array('<td class="right">', '</td>'),
911 '2' => array('<td class="right">', '</td>')
912 );
913 $rowWithSpan = array(
914 'tr' => array('<tr class="db_list_normal">', '</tr>'),
915 'defCol' => array('<td>', '</td>'),
916 '1' => array('<td class="right">', '</td>'),
917 '2' => array('<td class="right">', '</td>'),
918 '3' => array('<td colspan="6">', '</td>')
919 );
920 $table = array();
921 $tr = 0;
922 // Header row
923 $table[$tr][] = '<a href="#" onclick="toggleCheckboxes();" title="' . $GLOBALS['LANG']->getLL('label.checkAll', TRUE) . '" class="icon">' . IconUtility::getSpriteIcon('actions-document-select') . '</a>';
924 $table[$tr][] = '&nbsp;';
925 $table[$tr][] = $GLOBALS['LANG']->getLL('label.id');
926 $table[$tr][] = $GLOBALS['LANG']->getLL('task');
927 $table[$tr][] = $GLOBALS['LANG']->getLL('label.type');
928 $table[$tr][] = $GLOBALS['LANG']->getLL('label.frequency');
929 $table[$tr][] = $GLOBALS['LANG']->getLL('label.parallel');
930 $table[$tr][] = $GLOBALS['LANG']->getLL('label.lastExecution');
931 $table[$tr][] = $GLOBALS['LANG']->getLL('label.nextExecution');
932 $tr++;
933 // Loop on all tasks
934 while ($schedulerRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
935 // Define action icons
936 $editAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=edit&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:edit', TRUE) . '" class="icon">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
937 $deleteAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=delete&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" onclick="return confirm(\'' . $GLOBALS['LANG']->getLL('msg.delete') . '\');" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:delete', TRUE) . '" class="icon">' . IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
938 $stopAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=stop&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" onclick="return confirm(\'' . $GLOBALS['LANG']->getLL('msg.stop') . '\');" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:stop', TRUE) . '" class="icon"><img ' . IconUtility::skinImg($this->backPath, (ExtensionManagementUtility::extRelPath('scheduler') . '/res/gfx/stop.png')) . ' alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:stop') . '" /></a>';
939 $runAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&tx_scheduler[execute][]=' . $schedulerRecord['uid'] . '" title="' . $GLOBALS['LANG']->getLL('action.run_task') . '" class="icon">' . IconUtility::getSpriteIcon('extensions-scheduler-run-task') . '</a>';
940 // Define some default values
941 $lastExecution = '-';
942 $isRunning = FALSE;
943 $executionStatus = 'scheduled';
944 $executionStatusOutput = '';
945 $name = '';
946 $nextDate = '-';
947 $execType = '-';
948 $frequency = '-';
949 $multiple = '-';
950 $startExecutionElement = '&nbsp;';
951 // Restore the serialized task and pass it a reference to the scheduler object
952 /** @var $task \TYPO3\CMS\Scheduler\Task\AbstractTask|\TYPO3\CMS\Scheduler\ProgressProviderInterface */
953 $task = unserialize($schedulerRecord['serialized_task_object']);
954 $class = get_class($task);
955 if ($class === '__PHP_Incomplete_Class' && preg_match('/^O:[0-9]+:"(?P<classname>.+?)"/', $schedulerRecord['serialized_task_object'], $matches) === 1) {
956 $class = $matches['classname'];
957 }
958 // Assemble information about last execution
959 $context = '';
960 if (!empty($schedulerRecord['lastexecution_time'])) {
961 $lastExecution = date($dateFormat, $schedulerRecord['lastexecution_time']);
962 if ($schedulerRecord['lastexecution_context'] == 'CLI') {
963 $context = $GLOBALS['LANG']->getLL('label.cron');
964 } else {
965 $context = $GLOBALS['LANG']->getLL('label.manual');
966 }
967 $lastExecution .= ' (' . $context . ')';
968 }
969 if ($this->scheduler->isValidTaskObject($task)) {
970 // The task object is valid
971 $name = htmlspecialchars($registeredClasses[$class]['title'] . ' (' . $registeredClasses[$class]['extension'] . ')');
972 $name .= '<br /> ';
973 $additionalInformation = $task->getAdditionalInformation();
974 if ($task instanceof \TYPO3\CMS\Scheduler\ProgressProviderInterface) {
975 $progress = round(floatval($task->getProgress()), 2);
976 $name .= $this->renderTaskProgressBar($progress);
977 }
978 if (!empty($additionalInformation)) {
979 $name .= '[' . htmlspecialchars($additionalInformation) . ']';
980 }
981 // Check if task currently has a running execution
982 if (!empty($schedulerRecord['serialized_executions'])) {
983 $isRunning = TRUE;
984 $executionStatus = 'running';
985 }
986 // Prepare display of next execution date
987 // If task is currently running, date is not displayed (as next hasn't been calculated yet)
988 // Also hide the date if task is disabled (the information doesn't make sense, as it will not run anyway)
989 if ($isRunning || $schedulerRecord['disable'] == 1) {
990 $nextDate = '-';
991 } else {
992 $nextDate = date($dateFormat, $schedulerRecord['nextexecution']);
993 if (empty($schedulerRecord['nextexecution'])) {
994 $nextDate = $GLOBALS['LANG']->getLL('none');
995 } elseif ($schedulerRecord['nextexecution'] < $GLOBALS['EXEC_TIME']) {
996 // Next execution is overdue, highlight date
997 $nextDate = '<span class="late" title="' . $GLOBALS['LANG']->getLL('status.legend.scheduled') . '">' . $nextDate . '</span>';
998 $executionStatus = 'late';
999 }
1000 }
1001 // Get execution type
1002 if ($task->getExecution()->getInterval() == 0 && $task->getExecution()->getCronCmd() == '') {
1003 $execType = $GLOBALS['LANG']->getLL('label.type.single');
1004 $frequency = '-';
1005 } else {
1006 $execType = $GLOBALS['LANG']->getLL('label.type.recurring');
1007 if ($task->getExecution()->getCronCmd() == '') {
1008 $frequency = $task->getExecution()->getInterval();
1009 } else {
1010 $frequency = $task->getExecution()->getCronCmd();
1011 }
1012 }
1013 // Get multiple executions setting
1014 if ($task->getExecution()->getMultiple()) {
1015 $multiple = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:yes');
1016 } else {
1017 $multiple = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:no');
1018 }
1019 // Define checkbox
1020 $startExecutionElement = '<input type="checkbox" name="tx_scheduler[execute][]" value="' . $schedulerRecord['uid'] . '" id="task_' . $schedulerRecord['uid'] . '" class="checkboxes" />';
1021
1022 $actions = $editAction . $deleteAction;
1023
1024 // Check the disable status
1025 // Row is shown dimmed if task is disabled, unless it is still running
1026 if ($schedulerRecord['disable'] == 1 && !$isRunning) {
1027 $tableLayout[$tr] = $disabledTaskRow;
1028 $executionStatus = 'disabled';
1029 }
1030
1031 // Show no action links (edit, delete) if task is running
1032 if ($isRunning) {
1033 $actions = $stopAction;
1034 } else {
1035 $actions .= $runAction;
1036 }
1037
1038 // Check if the last run failed
1039 $failureOutput = '';
1040 if (!empty($schedulerRecord['lastexecution_failure'])) {
1041 // Try to get the stored exception object
1042 /** @var $exception \Exception */
1043 $exception = unserialize($schedulerRecord['lastexecution_failure']);
1044 // If the exception could not be unserialized, issue a default error message
1045 if ($exception === FALSE || $exception instanceof \__PHP_Incomplete_Class) {
1046 $failureDetail = $GLOBALS['LANG']->getLL('msg.executionFailureDefault');
1047 } else {
1048 $failureDetail = sprintf($GLOBALS['LANG']->getLL('msg.executionFailureReport'), $exception->getCode(), $exception->getMessage());
1049 }
1050 $failureOutput = ' <img ' . IconUtility::skinImg(ExtensionManagementUtility::extRelPath('scheduler'), 'res/gfx/status_failure.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.failure')) . '" title="' . htmlspecialchars($failureDetail) . '" />';
1051 }
1052 // Format the execution status,
1053 // including failure feedback, if any
1054 $executionStatusOutput = '<img ' . IconUtility::skinImg(ExtensionManagementUtility::extRelPath('scheduler'), ('res/gfx/status_' . $executionStatus . '.png')) . ' id="executionstatus_' . $schedulerRecord['uid'] . '" alt="' . htmlspecialchars($GLOBALS['LANG']->getLL(('status.' . $executionStatus))) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL(('status.legend.' . $executionStatus))) . '" />' . $failureOutput;
1055 $table[$tr][] = $startExecutionElement;
1056 $table[$tr][] = $actions;
1057 $table[$tr][] = $schedulerRecord['uid'];
1058 $table[$tr][] = $executionStatusOutput;
1059 $table[$tr][] = $name;
1060 $table[$tr][] = $execType;
1061 $table[$tr][] = $frequency;
1062 $table[$tr][] = $multiple;
1063 $table[$tr][] = $lastExecution;
1064 $table[$tr][] = $nextDate;
1065 } else {
1066 // The task object is not valid
1067 // Prepare to issue an error
1068 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
1069 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('msg.invalidTaskClass'), $class), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1070 $executionStatusOutput = $flashMessage->render();
1071 $tableLayout[$tr] = $rowWithSpan;
1072 $table[$tr][] = $startExecutionElement;
1073 $table[$tr][] = $deleteAction;
1074 $table[$tr][] = $schedulerRecord['uid'];
1075 $table[$tr][] = $executionStatusOutput;
1076 }
1077 $tr++;
1078 }
1079 // Render table
1080 $content .= $this->doc->table($table, $tableLayout);
1081 $content .= '<input type="submit" class="button" name="go" id="scheduler_executeselected" value="' . $GLOBALS['LANG']->getLL('label.executeSelected') . '" />';
1082 }
1083 if (!count($registeredClasses) > 0) {
1084 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
1085 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('msg.noTasksDefined'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
1086 $content .= $flashMessage->render();
1087 }
1088 // Display legend, if there's at least one registered task
1089 // Also display information about the usage of server time
1090 if ($numRows > 0) {
1091 $content .= $this->doc->spacer(20);
1092 $content .= '<h3>' . $GLOBALS['LANG']->getLL('status.legend') . '</h3>
1093 <ul>
1094 <li><img ' . IconUtility::skinImg(ExtensionManagementUtility::extRelPath('scheduler'), 'res/gfx/status_failure.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.failure')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.failure')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.failure') . '</li>
1095 <li><img ' . IconUtility::skinImg(ExtensionManagementUtility::extRelPath('scheduler'), 'res/gfx/status_late.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.late')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.late')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.late') . '</li>
1096 <li><img ' . IconUtility::skinImg(ExtensionManagementUtility::extRelPath('scheduler'), 'res/gfx/status_running.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.running')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.running')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.running') . '</li>
1097 <li><img ' . IconUtility::skinImg(ExtensionManagementUtility::extRelPath('scheduler'), 'res/gfx/status_scheduled.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.scheduled')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.scheduled')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.scheduled') . '</li>
1098 <li><img ' . IconUtility::skinImg(ExtensionManagementUtility::extRelPath('scheduler'), 'res/gfx/status_disabled.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.disabled')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.disabled')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.disabled') . '</li>
1099 </ul>';
1100 $content .= $this->displayServerTime();
1101 }
1102 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1103 return $content;
1104 }
1105
1106 /**
1107 * Saves a task specified in the backend form to the database
1108 *
1109 * @return void
1110 */
1111 protected function saveTask() {
1112 // If a task is being edited fetch old task data
1113 if (!empty($this->submittedData['uid'])) {
1114 try {
1115 $taskRecord = $this->scheduler->fetchTaskRecord($this->submittedData['uid']);
1116 /** @var $task \TYPO3\CMS\Scheduler\Task\AbstractTask */
1117 $task = unserialize($taskRecord['serialized_task_object']);
1118 } catch (\OutOfBoundsException $e) {
1119 // If the task could not be fetched, issue an error message
1120 // and exit early
1121 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1122 return;
1123 }
1124 // Register single execution
1125 if ($this->submittedData['type'] == 1) {
1126 $task->registerSingleExecution($this->submittedData['start']);
1127 } else {
1128 if (!empty($this->submittedData['croncmd'])) {
1129 // Definition by cron-like syntax
1130 $interval = 0;
1131 $cronCmd = $this->submittedData['croncmd'];
1132 } else {
1133 // Definition by interval
1134 $interval = $this->submittedData['interval'];
1135 $cronCmd = '';
1136 }
1137 // Register recurring execution
1138 $task->registerRecurringExecution($this->submittedData['start'], $interval, $this->submittedData['end'], $this->submittedData['multiple'], $cronCmd);
1139 }
1140 // Set disable flag
1141 $task->setDisabled($this->submittedData['disable']);
1142 // Save additional input values
1143 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields'])) {
1144 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
1145 $providerObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields']);
1146 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
1147 $providerObject->saveAdditionalFields($this->submittedData, $task);
1148 }
1149 }
1150 // Save to database
1151 $result = $this->scheduler->saveTask($task);
1152 if ($result) {
1153 $GLOBALS['BE_USER']->writeLog(4, 0, 0, 0, 'Scheduler task "%s" (UID: %s, Class: "%s") was updated', array($task->getTaskTitle(), $task->getTaskUid(), $task->getTaskClassName()));
1154 $this->addMessage($GLOBALS['LANG']->getLL('msg.updateSuccess'));
1155 } else {
1156 $this->addMessage($GLOBALS['LANG']->getLL('msg.updateError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1157 }
1158 } else {
1159 // A new task is being created
1160 // Create an instance of chosen class
1161 $task = GeneralUtility::makeInstance($this->submittedData['class']);
1162 if ($this->submittedData['type'] == 1) {
1163 // Set up single execution
1164 $task->registerSingleExecution($this->submittedData['start']);
1165 } else {
1166 // Set up recurring execution
1167 $task->registerRecurringExecution($this->submittedData['start'], $this->submittedData['interval'], $this->submittedData['end'], $this->submittedData['multiple'], $this->submittedData['croncmd']);
1168 }
1169 // Save additional input values
1170 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields'])) {
1171 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
1172 $providerObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields']);
1173 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
1174 $providerObject->saveAdditionalFields($this->submittedData, $task);
1175 }
1176 }
1177 // Set disable flag
1178 $task->setDisabled($this->submittedData['disable']);
1179 // Add to database
1180 $result = $this->scheduler->addTask($task);
1181 if ($result) {
1182 $GLOBALS['BE_USER']->writeLog(4, 0, 0, 0, 'Scheduler task "%s" (UID: %s, Class: "%s") was added', array($task->getTaskTitle(), $task->getTaskUid(), $task->getTaskClassName()));
1183 $this->addMessage($GLOBALS['LANG']->getLL('msg.addSuccess'));
1184
1185 // set the uid of the just created task so that we
1186 // can continue editing after initial saving
1187 $this->submittedData['uid'] = $task->getTaskUid();
1188 } else {
1189 $this->addMessage($GLOBALS['LANG']->getLL('msg.addError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1190 }
1191 }
1192 }
1193
1194 /*************************
1195 *
1196 * INPUT PROCESSING UTILITIES
1197 *
1198 *************************/
1199 /**
1200 * Checks the submitted data and performs some pre-processing on it
1201 *
1202 * @return boolean TRUE if everything was ok, FALSE otherwise
1203 */
1204 protected function preprocessData() {
1205 $result = TRUE;
1206 // Validate id
1207 $this->submittedData['uid'] = empty($this->submittedData['uid']) ? 0 : intval($this->submittedData['uid']);
1208 // Validate selected task class
1209 if (!class_exists($this->submittedData['class'])) {
1210 $this->addMessage($GLOBALS['LANG']->getLL('msg.noTaskClassFound'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1211 }
1212 // Check start date
1213 if (empty($this->submittedData['start'])) {
1214 $this->addMessage($GLOBALS['LANG']->getLL('msg.noStartDate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1215 $result = FALSE;
1216 } else {
1217 try {
1218 $timestamp = $this->checkDate($this->submittedData['start']);
1219 $this->submittedData['start'] = $timestamp;
1220 } catch (\Exception $e) {
1221 $this->addMessage($GLOBALS['LANG']->getLL('msg.invalidStartDate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1222 $result = FALSE;
1223 }
1224 }
1225 // Check end date, if recurring task
1226 if ($this->submittedData['type'] == 2 && !empty($this->submittedData['end'])) {
1227 try {
1228 $timestamp = $this->checkDate($this->submittedData['end']);
1229 $this->submittedData['end'] = $timestamp;
1230 if ($this->submittedData['end'] < $this->submittedData['start']) {
1231 $this->addMessage($GLOBALS['LANG']->getLL('msg.endDateSmallerThanStartDate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1232 $result = FALSE;
1233 }
1234 } catch (\Exception $e) {
1235 $this->addMessage($GLOBALS['LANG']->getLL('msg.invalidEndDate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1236 $result = FALSE;
1237 }
1238 }
1239 // Set default values for interval and cron command
1240 $this->submittedData['interval'] = 0;
1241 $this->submittedData['croncmd'] = '';
1242 // Check type and validity of frequency, if recurring
1243 if ($this->submittedData['type'] == 2) {
1244 $frequency = trim($this->submittedData['frequency']);
1245 if (empty($frequency)) {
1246 // Empty frequency, not valid
1247 $this->addMessage($GLOBALS['LANG']->getLL('msg.noFrequency'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1248 $result = FALSE;
1249 } else {
1250 $cronErrorCode = 0;
1251 $cronErrorMessage = '';
1252 // Try interpreting the cron command
1253 try {
1254 \TYPO3\CMS\Scheduler\CronCommand\NormalizeCommand::normalize($frequency);
1255 $this->submittedData['croncmd'] = $frequency;
1256 } catch (\Exception $e) {
1257 // Store the exception's result
1258 $cronErrorMessage = $e->getMessage();
1259 $cronErrorCode = $e->getCode();
1260 // Check if the frequency is a valid number
1261 // If yes, assume it is a frequency in seconds, and unset cron error code
1262 if (is_numeric($frequency)) {
1263 $this->submittedData['interval'] = intval($frequency);
1264 unset($cronErrorCode);
1265 }
1266 }
1267 // If there's a cron error code, issue validation error message
1268 if (!empty($cronErrorCode)) {
1269 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.frequencyError'), $cronErrorMessage, $cronErrorCode), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1270 $result = FALSE;
1271 }
1272 }
1273 }
1274 // Validate additional input fields
1275 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields'])) {
1276 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
1277 $providerObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields']);
1278 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
1279 // The validate method will return TRUE if all went well, but that must not
1280 // override previous FALSE values => AND the returned value with the existing one
1281 $result &= $providerObject->validateAdditionalFields($this->submittedData, $this);
1282 }
1283 }
1284 return $result;
1285 }
1286
1287 /**
1288 * This method checks whether the given string can be considered a valid date or not
1289 * Allowed values are anything that matches natural language (see PHP function strtotime())
1290 * or TYPO3's date syntax: HH:ii yyyy-mm-dd
1291 * If the string is a valid date, the corresponding timestamp is returned.
1292 * Otherwise an exception is thrown
1293 *
1294 * @param string $string String to check
1295 * @return integer Unix timestamp
1296 * @throws \InvalidArgumentException
1297 */
1298 public function checkDate($string) {
1299 // Try with strtotime
1300 $timestamp = strtotime($string);
1301 // That failed. Try TYPO3's standard date/time input format
1302 if ($timestamp === FALSE) {
1303 // Split time and date
1304 $dateParts = GeneralUtility::trimExplode(' ', $string, TRUE);
1305 // Proceed if there are indeed two parts
1306 // Extract each component of date and time
1307 if (count($dateParts) == 2) {
1308 list($time, $date) = $dateParts;
1309 list($hour, $minutes) = GeneralUtility::trimExplode(':', $time, TRUE);
1310 list($day, $month, $year) = GeneralUtility::trimExplode('-', $date, TRUE);
1311 // Get a timestamp from all these parts
1312 $timestamp = @mktime($hour, $minutes, 0, $month, $day, $year);
1313 }
1314 // If the timestamp is still FALSE, throw an exception
1315 if ($timestamp === FALSE) {
1316 throw new \InvalidArgumentException('"' . $string . '" seems not to be a correct date.', 1294587694);
1317 }
1318 }
1319 return $timestamp;
1320 }
1321
1322 /*************************
1323 *
1324 * APPLICATION LOGIC UTILITIES
1325 *
1326 *************************/
1327 /**
1328 * This method is used to add a message to the internal queue
1329 *
1330 * @param string $message The message itself
1331 * @param integer $severity Message level (according to \TYPO3\CMS\Core\Messaging\FlashMessage class constants)
1332 * @return void
1333 */
1334 public function addMessage($message, $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK) {
1335 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, '', $severity);
1336 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
1337 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
1338 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1339 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1340 $defaultFlashMessageQueue->enqueue($flashMessage);
1341 }
1342
1343 /**
1344 * This method a list of all classes that have been registered with the Scheduler
1345 * For each item the following information is provided, as an associative array:
1346 *
1347 * ['extension'] => Key of the extension which provides the class
1348 * ['filename'] => Path to the file containing the class
1349 * ['title'] => String (possibly localized) containing a human-readable name for the class
1350 * ['provider'] => Name of class that implements the interface for additional fields, if necessary
1351 *
1352 * The name of the class itself is used as the key of the list array
1353 *
1354 * @return array List of registered classes
1355 */
1356 static protected function getRegisteredClasses() {
1357 $list = array();
1358 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'])) {
1359 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'] as $class => $registrationInformation) {
1360 $title = isset($registrationInformation['title']) ? $GLOBALS['LANG']->sL($registrationInformation['title']) : '';
1361 $description = isset($registrationInformation['description']) ? $GLOBALS['LANG']->sL($registrationInformation['description']) : '';
1362 $list[$class] = array(
1363 'extension' => $registrationInformation['extension'],
1364 'title' => $title,
1365 'description' => $description,
1366 'provider' => isset($registrationInformation['additionalFields']) ? $registrationInformation['additionalFields'] : ''
1367 );
1368 }
1369 }
1370 return $list;
1371 }
1372
1373 /*************************
1374 *
1375 * RENDERING UTILITIES
1376 *
1377 *************************/
1378 /**
1379 * Gets the filled markers that are used in the HTML template.
1380 *
1381 * @return array The filled marker array
1382 */
1383 protected function getTemplateMarkers() {
1384 $markers = array(
1385 'CSH' => BackendUtility::wrapInHelp('_MOD_system_txschedulerM1', ''),
1386 'FUNC_MENU' => $this->getFunctionMenu(),
1387 'CONTENT' => $this->content,
1388 'TITLE' => $GLOBALS['LANG']->getLL('title')
1389 );
1390 return $markers;
1391 }
1392
1393 /**
1394 * Gets the function menu selector for this backend module.
1395 *
1396 * @return string The HTML representation of the function menu selector
1397 */
1398 protected function getFunctionMenu() {
1399 $functionMenu = BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
1400 return $functionMenu;
1401 }
1402
1403 /**
1404 * Gets the buttons that shall be rendered in the docHeader.
1405 *
1406 * @return array Available buttons for the docHeader
1407 */
1408 protected function getDocHeaderButtons() {
1409 $buttons = array(
1410 'addtask' => '',
1411 'close' => '',
1412 'save' => '',
1413 'saveclose' => '',
1414 'delete' => '',
1415 'reload' => '',
1416 'shortcut' => $this->getShortcutButton()
1417 );
1418 if (empty($this->CMD) || $this->CMD == 'list' || $this->CMD == 'delete') {
1419 $buttons['reload'] = '<a href="' . $GLOBALS['MCONF']['_'] . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', TRUE) . '">' . IconUtility::getSpriteIcon('actions-system-refresh') . '</a>';
1420 if ($this->MOD_SETTINGS['function'] === 'scheduler' && count(self::getRegisteredClasses())) {
1421 $link = $GLOBALS['MCONF']['_'] . '&CMD=add';
1422 $image = '<img ' . IconUtility::skinImg($this->backPath, 'gfx/new_el.gif') . ' alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:new', TRUE) . '" />';
1423 $buttons['addtask'] = '<a href="' . htmlspecialchars($link) . '" ' . 'title="' . $GLOBALS['LANG']->getLL('action.add') . '">' . $image . '</a>';
1424 }
1425 }
1426 if ($this->CMD === 'add' || $this->CMD === 'edit') {
1427 $buttons['close'] = '<a href="#" onclick="document.location=\'' . $GLOBALS['MCONF']['_'] . '\'" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:cancel', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-close') . '</a>';
1428 $buttons['save'] = '<button style="padding: 0; margin: 0; cursor: pointer;" type="submit" name="CMD" value="save" class="c-inputButton" src="clear.gif" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:save', TRUE) . '" />' . IconUtility::getSpriteIcon('actions-document-save') . '</button>';
1429 $buttons['saveclose'] = '<button style="padding: 0; margin: 0; cursor: pointer;" type="submit" name="CMD" value="saveclose" class="c-inputButton" src="clear.gif" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:saveAndClose', TRUE) . '" />' . IconUtility::getSpriteIcon('actions-document-save-close') . '</button>';
1430 }
1431 if ($this->CMD === 'edit') {
1432 $buttons['delete'] = '<button style="padding: 0; margin: 0; cursor: pointer;" type="submit" name="CMD" value="delete" class="c-inputButton" src="clear.gif" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:delete', TRUE) . '" />' . IconUtility::getSpriteIcon('actions-edit-delete') . '</button>';
1433 }
1434 return $buttons;
1435 }
1436
1437 /**
1438 * Gets the button to set a new shortcut in the backend (if current user is allowed to).
1439 *
1440 * @return string HTML representation of the shortcut button
1441 */
1442 protected function getShortcutButton() {
1443 $result = '';
1444 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
1445 $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
1446 }
1447 return $result;
1448 }
1449
1450 }
1451
1452
1453 ?>