Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / taskcenter / task / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Georg Ringer <typo3@ringerge.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * This class provides a taskcenter for BE users
28 *
29 * @author Georg Ringer <typo3@ringerge.org>
30 * @package TYPO3
31 * @subpackage taskcenter
32 *
33 */
34
35
36 $LANG->includeLLFile('EXT:taskcenter/task/locallang.xml');
37
38
39 $BE_USER->modAccess($MCONF, 1);
40
41
42 // ***************************
43 // Script Classes
44 // ***************************
45 class SC_mod_user_task_index extends t3lib_SCbase {
46
47 protected $pageinfo;
48
49 /**
50 * Initializes the Module
51 *
52 * @return void
53 */
54 public function __construct() {
55 parent::init();
56
57 // initialize document
58 $this->doc = t3lib_div::makeInstance('template');
59 $this->doc->setModuleTemplate(
60 t3lib_extMgm::extPath('taskcenter') . 'res/mod_template.html'
61 );
62 $this->doc->backPath = $GLOBALS['BACK_PATH'];
63 $this->doc->getPageRenderer()->loadScriptaculous('effects,dragdrop');
64 $this->doc->addStyleSheet(
65 'tx_taskcenter',
66 '../' . t3lib_extMgm::siteRelPath('taskcenter') . 'res/mod_styles.css'
67 );
68 }
69
70 /**
71 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
72 *
73 * @return void
74 */
75 public function menuConfig() {
76 $this->MOD_MENU = array('mode' => array());
77
78 $this->MOD_MENU['mode']['information'] = $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/locallang.xml:task_overview');
79 $this->MOD_MENU['mode']['tasks'] = 'Tasks';
80
81 parent::menuConfig();
82 }
83
84 /**
85 * Creates the module's content. In this case it rather acts as a kind of #
86 * dispatcher redirecting requests to specific tasks.
87 *
88 * @return void
89 */
90 public function main() {
91 $docHeaderButtons = $this->getButtons();
92 $markers = array();
93
94 $this->doc->JScodeArray[] = '
95 script_ended = 0;
96 function jumpToUrl(URL) {
97 document.location = URL;
98 }
99 ';
100 $this->doc->postCode='
101 <script language="javascript" type="text/javascript">
102 script_ended = 1;
103 if (top.fsMod) {
104 top.fsMod.recentIds["web"] = 0;
105 }
106 </script>
107 ';
108
109 // Render content depending on the mode
110 $mode = (string)$this->MOD_SETTINGS['mode'];
111 if ($mode == 'information') {
112 $this->renderInformationContent();
113 } else {
114 $this->renderModuleContent();
115 }
116
117 // compile document
118 $markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu(
119 0,
120 'SET[mode]',
121 $this->MOD_SETTINGS['mode'],
122 $this->MOD_MENU['mode']
123 );
124 $markers['CONTENT'] = $this->content;
125
126 // Build the <body> for the module
127 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
128 // Renders the module page
129 $this->content = $this->doc->render(
130 $GLOBALS['LANG']->getLL('title'),
131 $this->content
132 );
133 }
134
135 /**
136 * Prints out the module's HTML
137 *
138 * @return void
139 */
140 public function printContent() {
141 echo $this->content;
142 }
143
144 /**
145 * Generates the module content by calling the selected task
146 *
147 * @return void
148 */
149 protected function renderModuleContent() {
150 $title = $content = $actionContent = '';
151 $chosenTask = (string)$this->MOD_SETTINGS['function'];
152
153 // render the taskcenter task as default
154 if (empty($chosenTask) || $chosenTask == 'index') {
155 $chosenTask = 'taskcenter.tasks';
156 }
157
158 // remder the task
159 list($extKey, $taskClass) = explode('.', $chosenTask, 2);
160 $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['title']);
161
162 if (class_exists($taskClass)) {
163 $taskInstance = t3lib_div::makeInstance($taskClass, $this);
164
165 if ($taskInstance instanceof tx_taskcenter_Task) {
166 // check if the task is restricted to admins only
167 if ($this->checkAccess($extKey, $taskClass)) {
168 $actionContent .= $taskInstance->getTask();
169 } else {
170 $flashMessage = t3lib_div::makeInstance(
171 't3lib_FlashMessage',
172 $GLOBALS['LANG']->getLL('error-access', TRUE),
173 $GLOBALS['LANG']->getLL('error_header'),
174 t3lib_FlashMessage::ERROR
175 );
176 $actionContent .= $flashMessage->render();
177 }
178 } else {
179 // error if the task is not an instance of tx_taskcenter_Task
180 $flashMessage = t3lib_div::makeInstance(
181 't3lib_FlashMessage',
182 sprintf($GLOBALS['LANG']->getLL('error_no-instance', TRUE), $taskClass, 'tx_taskcenter_Task'),
183 $GLOBALS['LANG']->getLL('error_header'),
184 t3lib_FlashMessage::ERROR
185 );
186 $actionContent .= $flashMessage->render();
187 }
188 } else {
189 $flashMessage = t3lib_div::makeInstance(
190 't3lib_FlashMessage',
191 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr'),
192 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_tabs_tab'),
193 t3lib_FlashMessage::INFO
194 );
195 $actionContent .= $flashMessage->render();
196 }
197
198 $content = '<div id="taskcenter-main">
199 <div id="taskcenter-menu">' . $this->indexAction() . '</div>
200 <div id="taskcenter-item" class="' . htmlspecialchars($extKey . '-' . $taskClass) . '">' .
201 $actionContent . '
202 </div>
203 </div>';
204
205 $this->content .= $content;
206 }
207
208 /**
209 * Generates the information content
210 *
211 * @return void
212 */
213 protected function renderInformationContent() {
214 $content = $this->description (
215 $GLOBALS['LANG']->getLL('mlang_tabs_tab'),
216 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr')
217 );
218
219 $content .= $GLOBALS['LANG']->getLL('taskcenter-about');
220
221 if ($GLOBALS['BE_USER']->isAdmin()) {
222 $content .= '<br /><br />' . $this->description (
223 $GLOBALS['LANG']->getLL('taskcenter-adminheader'),
224 $GLOBALS['LANG']->getLL('taskcenter-admin')
225 );
226 }
227
228 $this->content .= $content;
229 }
230
231 /**
232 * Render the headline of a task including a title and an optional description.
233 *
234 * @param string $title: Title
235 * @param string $description: Description
236 * @return string formatted title and description
237 */
238 public function description($title, $description='') {
239 if (!empty($description)) {
240 $description = '<p class="description">' . nl2br(htmlspecialchars($description)) . '</p><br />';
241 }
242 $content = $this->doc->section($title, $description, FALSE, TRUE);
243
244 return $content;
245 }
246
247 /**
248 * Render a list of items as a nicely formated definition list including a
249 * link, icon, title and description.
250 * The keys of a single item are:
251 * - title: Title of the item
252 * - link: Link to the task
253 * - icon: Path to the icon or Icon as HTML if it begins with <img
254 * - description: Description of the task, using htmlspecialchars()
255 * - descriptionHtml: Description allowing HTML tags which will override the
256 * description
257 *
258 * @param array $items: List of items to be displayed in the definition list.
259 * @param boolean $mainMenu: Set it to TRUE to render the main menu
260 * @return string definition list
261 */
262 public function renderListMenu($items, $mainMenu = FALSE) {
263 $content = $section = '';
264 $count = 0;
265
266 // change the sorting of items to the user's one
267 if ($mainMenu) {
268 $this->doc->getPageRenderer()->addJsFile(t3lib_extMgm::extRelPath('taskcenter') . 'res/tasklist.js');
269 $userSorting = unserialize($GLOBALS['BE_USER']->uc['taskcenter']['sorting']);
270 if (is_array($userSorting)) {
271 $newSorting = array();
272 foreach($userSorting as $item) {
273 if(isset($items[$item])) {
274 $newSorting[] = $items[$item];
275 unset($items[$item]);
276 }
277 }
278 $items = $newSorting + $items;
279 }
280 }
281
282 if (is_array($items) && count($items) > 0) {
283 foreach($items as $item) {
284 $title = htmlspecialchars($item['title']);
285
286 $icon = $additionalClass = $collapsedStyle = '';
287 // Check for custom icon
288 if (!empty($item['icon'])) {
289 if (strpos($item['icon'], '<img ') === FALSE) {
290 $absIconPath = t3lib_div::getFileAbsFilename($item['icon']);
291 // If the file indeed exists, assemble relative path to it
292 if (file_exists($absIconPath)) {
293 $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
294 $icon = '<img src="' . $icon . '" title="' . $title . '" alt="' . $title . '" />';
295 }
296 if (@is_file($icon)) {
297 $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $title . '" alt="' . $title . '" />';
298 }
299 } else {
300 $icon = $item['icon'];
301 }
302 }
303
304
305 $description = (!empty($item['descriptionHtml'])) ? $item['descriptionHtml'] : '<p>' . nl2br(htmlspecialchars($item['description'])) . '</p>';
306
307 $id = $this->getUniqueKey($item['uid']);
308
309 // collapsed & expanded menu items
310 if ($mainMenu && isset($GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) && $GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) {
311 $collapsedStyle = 'style="display:none"';
312 $additionalClass = 'collapsed';
313 } else {
314 $additionalClass = 'expanded';
315 }
316
317 // first & last menu item
318 if ($count == 0) {
319 $additionalClass .= ' first-item';
320 } elseif ($count + 1 === count($items)) {
321 $additionalClass .= ' last-item';
322 }
323
324 // active menu item
325 $active = ((string) $this->MOD_SETTINGS['function'] == $item['uid']) ? ' active-task' : '';
326
327 // Main menu: Render additional syntax to sort tasks
328 if ($mainMenu) {
329 $dragIcon = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/move.gif', 'width="16" height="16" hspace="2"') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.move', 1) . '" alt="" />';
330 $section = '<div class="down">&nbsp;</div>
331 <div class="drag">' . $dragIcon . '</div>';
332 $backgroundClass = 't3-row-header ';
333 }
334
335 $content .= '<li class="' . $additionalClass . $active . '" id="el_' .$id . '">
336 ' . $section . '
337 <div class="image">' . $icon . '</div>
338 <div class="' . $backgroundClass . 'link"><a href="' . $item['link'] . '">' . $title . '</a></div>
339 <div class="content " ' . $collapsedStyle . '>' . $description . '</div>
340 </li>';
341
342 $count++;
343 }
344
345 $navigationId = ($mainMenu) ? 'id="task-list"' : '';
346
347 $content = '<ul ' . $navigationId . ' class="task-list">' . $content . '</ul>';
348
349 }
350
351 return $content;
352 }
353
354 /**
355 * Shows an overview list of available reports.
356 *
357 * @return string list of available reports
358 */
359 protected function indexAction() {
360 $content = '';
361 $tasks = array();
362 $icon = t3lib_extMgm::extRelPath('taskcenter') . 'task/task.gif';
363
364 // render the tasks only if there are any available
365 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) && count($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) > 0) {
366 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'] as $extKey => $extensionReports) {
367 foreach ($extensionReports as $taskClass => $task) {
368 if (!$this->checkAccess($extKey, $taskClass)) {
369 continue;
370 }
371 $link = 'mod.php?M=user_task&SET[function]=' . $extKey . '.' . $taskClass;
372 $taskTitle = $GLOBALS['LANG']->sL($task['title']);
373 $taskDescriptionHtml = '';
374
375 // Check for custom icon
376 if (!empty($task['icon'])) {
377 $icon = t3lib_div::getFileAbsFilename($task['icon']);
378 }
379
380 if (class_exists($taskClass)) {
381 $taskInstance = t3lib_div::makeInstance($taskClass, $this);
382 if ($taskInstance instanceof tx_taskcenter_Task) {
383 $taskDescriptionHtml = $taskInstance->getOverview();
384 }
385 }
386
387 // generate an array of all tasks
388 $uniqueKey = $this->getUniqueKey($extKey . '.' . $taskClass);
389 $tasks[$uniqueKey] = array(
390 'title' => $taskTitle,
391 'descriptionHtml' => $taskDescriptionHtml,
392 'description' => $GLOBALS['LANG']->sL($task['description']),
393 'icon' => $icon,
394 'link' => $link,
395 'uid' => $extKey . '.' . $taskClass
396 );
397 }
398 }
399
400 $content .= $this->renderListMenu($tasks, TRUE);
401 } else {
402 $flashMessage = t3lib_div::makeInstance(
403 't3lib_FlashMessage',
404 $GLOBALS['LANG']->getLL('no-tasks', TRUE),
405 '',
406 t3lib_FlashMessage::INFO
407 );
408 $this->content .= $flashMessage->render();
409 }
410
411 return $content;
412 }
413
414 /**
415 * Create the panel of buttons for submitting the form or otherwise
416 * perform operations.
417 *
418 * @return array all available buttons as an assoc. array
419 */
420 protected function getButtons() {
421 $buttons = array(
422 'csh' => t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
423 'shortcut' => '',
424 'open_new_window' => $this->openInNewWindow()
425 );
426
427 // Shortcut
428 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
429 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
430 }
431
432 return $buttons;
433 }
434
435 /**
436 * Check the access to a task. Considered are:
437 * - Admins are always allowed
438 * - Tasks can be restriced to admins only
439 * - Tasks can be blinded for Users with TsConfig taskcenter.<extensionkey>.<taskName> = 0
440 *
441 * @param string $extKey: Extension key
442 * @param string $taskClass: Name of the task
443 * @return boolean Access to the task allowed or not
444 */
445 protected function checkAccess($extKey, $taskClass) {
446 // check if task is blinded with TsConfig (taskcenter.<extkey>.<taskName>
447 $tsConfig = $GLOBALS['BE_USER']->getTSConfig('taskcenter.' . $extKey . '.' . $taskClass);
448 if (isset($tsConfig['value']) && intval($tsConfig['value']) == 0) {
449 return FALSE;
450 }
451
452 // admins are always allowed
453 if ($GLOBALS['BE_USER']->isAdmin()) {
454 return TRUE;
455 }
456
457 // check if task is restricted to admins
458 if (intval($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['admin']) == 1) {
459 return FALSE;
460 }
461
462 return TRUE;
463 }
464
465 /**
466 * Returns HTML code to dislay an url in an iframe at the right side of the taskcenter
467 *
468 * @param string $url: url to display
469 * @param int $max:
470 * @return string code that inserts the iframe (HTML)
471 */
472 public function urlInIframe($url, $max=0) {
473 $this->doc->JScodeArray[] =
474 'function resizeIframe(frame,max) {
475 var parent = $("typo3-docbody");
476 var parentHeight = $(parent).getHeight() - 0;
477 var parentWidth = $(parent).getWidth() - $("taskcenter-menu").getWidth() - 50;
478 $("list_frame").setStyle({height: parentHeight+"px", width: parentWidth+"px"});
479
480 }
481 // event crashes IE6 so he is excluded first
482 var version = parseFloat(navigator.appVersion.split(";")[1].strip().split(" ")[1]);
483 if (!(Prototype.Browser.IE && version == 6)) {
484 Event.observe(window, "resize", resizeIframe, false);
485 }';
486
487 return '<iframe onload="resizeIframe(this,' . $max . ');" scrolling="auto" width="100%" src="' . $url . '" name="list_frame" id="list_frame" frameborder="no" style="margin-top:-51px;border: none;"></iframe>';
488 }
489
490 /**
491 * Create a unique key from a string which can be used in Prototype's Sortable
492 * Therefore '_' are replaced
493 *
494 * @param string $string: string which is used to generate the identifier
495 * @return string modified string
496 */
497 protected function getUniqueKey($string) {
498 $search = array('.', '_');
499 $replace = array('-', '');
500
501 return str_replace($search, $replace, $string);
502 }
503
504 /**
505 * This method prepares the link for opening the devlog in a new window
506 *
507 * @return string Hyperlink with icon and appropriate JavaScript
508 */
509 protected function openInNewWindow() {
510 $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT');
511 $onClick = "devlogWin=window.open('" . $url . "','taskcenter','width=790,status=0,menubar=1,resizable=1,location=0,scrollbars=1,toolbar=0');return false;";
512 $content = '<a href="#" onclick="' . htmlspecialchars($onClick).'">' .
513 '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/open_in_new_window.gif', 'width="19" height="14"') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.openInNewWindow', 1) . '" class="absmiddle" alt="" />' .
514 '</a>';
515 return $content;
516 }
517
518
519 }
520
521
522 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/taskcenter/task/index.php'])) {
523 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/taskcenter/task/index.php']);
524 }
525
526
527
528 // Make instance:
529 $SOBE = t3lib_div::makeInstance('SC_mod_user_task_index');
530 // Include files?
531 foreach($SOBE->include_once as $INC_FILE) {
532 include_once($INC_FILE);
533 }
534
535 $SOBE->main();
536 $SOBE->printContent();
537
538 ?>