0f99079aa96997ddcaedfa446a989e6a3f93c235
[Packages/TYPO3.CMS.git] / typo3 / sysext / taskcenter / task / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 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 Event.observe(document, "dom:loaded", function(){
101 var changeEffect;
102 Sortable.create("task-list", { handles:$$("#task-list .drag"), tag: "li", ghosting:false, overlap:"vertical", constraint:false,
103 onChange: function(item) {
104 var list = Sortable.options(item).element;
105 // deactivate link
106 $$("#task-list a").each(function(link) {
107 link.writeAttribute("onclick","return false;");
108 });
109
110 },
111
112 onUpdate: function(list) {
113 new Ajax.Request("ajax.php", {
114 method: "post",
115 parameters: { ajaxID :"Taskcenter::saveSortingState", data: Sortable.serialize(list)}
116 });
117 // activate link
118 Event.observe(window,"mouseup",function(){
119 $$("#task-list a").each(function(link) {
120 link.writeAttribute("onclick","");
121 });
122 });
123
124 }
125 });
126
127 $$("#taskcenter-menu .down").invoke("observe", "click", function(event){
128 var item = Event.element(event);
129 var itemParent = item.up();
130 item = item.next("div").next("div").next("div").next("div");
131
132 if (itemParent.hasClassName("expanded")) {
133 itemParent.removeClassName("expanded").addClassName("collapsed");
134 Effect.BlindUp(item, {duration : 0.5});
135 state = 1;
136 } else {
137 itemParent.removeClassName("collapsed").addClassName("expanded");
138 Effect.BlindDown(item, {duration : 0.5});
139 state = 0;
140 }
141 new Ajax.Request("ajax.php", {
142 parameters : "ajaxID=Taskcenter::saveCollapseState&item=" + itemParent.id + "&state=" + state
143 });
144 });
145 });
146 ';
147 $this->doc->postCode='
148 <script language="javascript" type="text/javascript">
149 script_ended = 1;
150 if (top.fsMod) {
151 top.fsMod.recentIds["web"] = 0;
152 }
153 </script>
154 ';
155
156 // Render content depending on the mode
157 $mode = (string)$this->MOD_SETTINGS['mode'];
158 if ($mode == 'information') {
159 $this->renderInformationContent();
160 } else {
161 $this->renderModuleContent();
162 }
163
164 // compile document
165 $markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu(
166 0,
167 'SET[mode]',
168 $this->MOD_SETTINGS['mode'],
169 $this->MOD_MENU['mode']
170 );
171 $markers['CONTENT'] = $this->content;
172
173 // Build the <body> for the module
174 $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
175 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
176 $this->content .= $this->doc->endPage();
177 $this->content = $this->doc->insertStylesAndJS($this->content);
178 }
179
180 /**
181 * Prints out the module's HTML
182 *
183 * @return void
184 */
185 public function printContent() {
186 echo $this->content;
187 }
188
189 /**
190 * Generates the module content by calling the selected task
191 *
192 * @return void
193 */
194 protected function renderModuleContent() {
195 $title = $content = $actionContent = '';
196 $chosenTask = (string)$this->MOD_SETTINGS['function'];
197
198 // render the taskcenter task as default
199 if (empty($chosenTask) || $chosenTask == 'index') {
200 $chosenTask = 'taskcenter.tasks';
201 }
202
203 // remder the task
204 list($extKey, $taskClass) = explode('.', $chosenTask, 2);
205 $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['title']);
206
207 if (class_exists($taskClass)) {
208 $taskInstance = t3lib_div::makeInstance($taskClass, $this);
209
210 if ($taskInstance instanceof tx_taskcenter_Task) {
211 // check if the task is restricted to admins only
212 if ($this->checkAccess($extKey, $taskClass)) {
213 $actionContent .= $taskInstance->getTask();
214 } else {
215 $flashMessage = t3lib_div::makeInstance(
216 't3lib_FlashMessage',
217 $GLOBALS['LANG']->getLL('error-access', TRUE),
218 $GLOBALS['LANG']->getLL('error_header'),
219 t3lib_FlashMessage::ERROR
220 );
221 $actionContent .= $flashMessage->render();
222 }
223 } else {
224 // error if the task is not an instance of tx_taskcenter_Task
225 $flashMessage = t3lib_div::makeInstance(
226 't3lib_FlashMessage',
227 sprintf($GLOBALS['LANG']->getLL('error_no-instance', TRUE), $taskClass, 'tx_taskcenter_Task'),
228 $GLOBALS['LANG']->getLL('error_header'),
229 t3lib_FlashMessage::ERROR
230 );
231 $actionContent .= $flashMessage->render();
232 }
233 } else {
234 $flashMessage = t3lib_div::makeInstance(
235 't3lib_FlashMessage',
236 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr'),
237 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_tabs_tab'),
238 t3lib_FlashMessage::INFO
239 );
240 $actionContent .= $flashMessage->render();
241 }
242
243 $content = '<div id="taskcenter-main">
244 <div id="taskcenter-menu">' . $this->indexAction() . '</div>
245 <div id="taskcenter-item" class="' . htmlspecialchars($extKey . '-' . $taskClass) . '">' .
246 $actionContent . '
247 </div>
248 </div>';
249
250 $this->content .= $content;
251 }
252
253 /**
254 * Generates the information content
255 *
256 * @return void
257 */
258 protected function renderInformationContent() {
259 $content = $this->description (
260 $GLOBALS['LANG']->getLL('mlang_tabs_tab'),
261 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr')
262 );
263
264 $content .= $GLOBALS['LANG']->getLL('taskcenter-about');
265
266 if ($GLOBALS['BE_USER']->isAdmin()) {
267 $content .= '<br /><br />' . $this->description (
268 $GLOBALS['LANG']->getLL('taskcenter-adminheader'),
269 $GLOBALS['LANG']->getLL('taskcenter-admin')
270 );
271 }
272
273 $this->content .= $content;
274 }
275
276 /**
277 * Render the headline of a task including a title and an optional description.
278 *
279 * @param string $title: Title
280 * @param string $description: Description
281 * @return string formatted title and description
282 */
283 public function description($title, $description='') {
284 if (!empty($description)) {
285 $description = '<p class="description">' . nl2br(htmlspecialchars($description)) . '</p><br />';
286 }
287 $content = $this->doc->section($title, $description, FALSE, TRUE);
288
289 return $content;
290 }
291
292 /**
293 * Render a list of items as a nicely formated definition list including a
294 * link, icon, title and description.
295 * The keys of a single item are:
296 * - title: Title of the item
297 * - link: Link to the task
298 * - icon: Path to the icon or Icon as HTML if it begins with <img
299 * - description: Description of the task, using htmlspecialchars()
300 * - descriptionHtml: Description allowing HTML tags which will override the
301 * description
302 *
303 * @param array $items: List of items to be displayed in the definition list.
304 * @param boolean $mainMenu: Set it to TRUE to render the main menu
305 * @return string definition list
306 */
307 public function renderListMenu($items, $mainMenu = FALSE) {
308 $content = $section = '';
309 $count = 0;
310
311 // change the sorting of items to the user's one
312 if ($mainMenu) {
313 $userSorting = unserialize($GLOBALS['BE_USER']->uc['taskcenter']['sorting']);
314 if (is_array($userSorting)) {
315 $newSorting = array();
316 foreach($userSorting as $item) {
317 if(isset($items[$item])) {
318 $newSorting[] = $items[$item];
319 unset($items[$item]);
320 }
321 }
322 $items = $newSorting + $items;
323 }
324 }
325
326 if (is_array($items) && count($items) > 0) {
327 foreach($items as $item) {
328 $title = htmlspecialchars($item['title']);
329
330 $icon = $additionalClass = $collapsedStyle = '';
331 // Check for custom icon
332 if (!empty($item['icon'])) {
333 if (strpos($item['icon'], '<img ') === FALSE) {
334 $absIconPath = t3lib_div::getFileAbsFilename($item['icon']);
335 // If the file indeed exists, assemble relative path to it
336 if (file_exists($absIconPath)) {
337 $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
338 $icon = '<img src="' . $icon . '" title="' . $title . '" alt="' . $title . '" />';
339 }
340 if (@is_file($icon)) {
341 $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $title . '" alt="' . $title . '" />';
342 }
343 } else {
344 $icon = $item['icon'];
345 }
346 }
347
348
349 $description = (!empty($item['descriptionHtml'])) ? $item['descriptionHtml'] : '<p>' . nl2br(htmlspecialchars($item['description'])) . '</p>';
350
351 $id = $this->getUniqueKey($item['uid']);
352
353 // collapsed & expanded menu items
354 if ($mainMenu && isset($GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) && $GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) {
355 $collapsedStyle = 'style="display:none"';
356 $additionalClass = 'collapsed';
357 } else {
358 $additionalClass = 'expanded';
359 }
360
361 // first & last menu item
362 if ($count == 0) {
363 $additionalClass .= ' first-item';
364 } elseif ($count + 1 === count($items)) {
365 $additionalClass .= ' last-item';
366 }
367
368 // active menu item
369 $active = ((string) $this->MOD_SETTINGS['function'] == $item['uid']) ? ' active-task' : '';
370
371 // Main menu: Render additional syntax to sort tasks
372 if ($mainMenu) {
373 $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="" />';
374 $section = '<div class="down">&nbsp;</div>
375 <div class="drag">' . $dragIcon . '</div>';
376 $backgroundClass = 't3-row-header ';
377 }
378
379 $content .= '<li class="' . $additionalClass . $active . '" id="el_' .$id . '">
380 ' . $section . '
381 <div class="image">' . $icon . '</div>
382 <div class="' . $backgroundClass . 'link"><a href="' . $item['link'] . '">' . $title . '</a></div>
383 <div class="content " ' . $collapsedStyle . '>' . $description . '</div>
384 </li>';
385
386 $count++;
387 }
388
389 $navigationId = ($mainMenu) ? 'id="task-list"' : '';
390
391 $content = '<ul ' . $navigationId . ' class="task-list">' . $content . '</ul>';
392
393 }
394
395 return $content;
396 }
397
398 /**
399 * Shows an overview list of available reports.
400 *
401 * @return string list of available reports
402 */
403 protected function indexAction() {
404 $content = '';
405 $tasks = array();
406 $icon = t3lib_extMgm::extRelPath('taskcenter') . 'task/task.gif';
407
408 // render the tasks only if there are any available
409 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) && count($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) > 0) {
410 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'] as $extKey => $extensionReports) {
411 foreach ($extensionReports as $taskClass => $task) {
412 if (!$this->checkAccess($extKey, $taskClass)) {
413 continue;
414 }
415 $link = 'mod.php?M=user_task&SET[function]=' . $extKey . '.' . $taskClass;
416 $taskTitle = $GLOBALS['LANG']->sL($task['title']);
417 $taskDescriptionHtml = '';
418
419 // Check for custom icon
420 if (!empty($task['icon'])) {
421 $icon = t3lib_div::getFileAbsFilename($task['icon']);
422 }
423
424 if (class_exists($taskClass)) {
425 $taskInstance = t3lib_div::makeInstance($taskClass, $this);
426 if ($taskInstance instanceof tx_taskcenter_Task) {
427 $taskDescriptionHtml = $taskInstance->getOverview();
428 }
429 }
430
431 // generate an array of all tasks
432 $uniqueKey = $this->getUniqueKey($extKey . '.' . $taskClass);
433 $tasks[$uniqueKey] = array(
434 'title' => $taskTitle,
435 'descriptionHtml' => $taskDescriptionHtml,
436 'description' => $GLOBALS['LANG']->sL($task['description']),
437 'icon' => $icon,
438 'link' => $link,
439 'uid' => $extKey . '.' . $taskClass
440 );
441 }
442 }
443
444 $content .= $this->renderListMenu($tasks, TRUE);
445 } else {
446 $flashMessage = t3lib_div::makeInstance(
447 't3lib_FlashMessage',
448 $GLOBALS['LANG']->getLL('no-tasks', TRUE),
449 '',
450 t3lib_FlashMessage::INFO
451 );
452 $this->content .= $flashMessage->render();
453 }
454
455 return $content;
456 }
457
458 /**
459 * Create the panel of buttons for submitting the form or otherwise
460 * perform operations.
461 *
462 * @return array all available buttons as an assoc. array
463 */
464 protected function getButtons() {
465 $buttons = array(
466 'csh' => t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
467 'shortcut' => '',
468 'open_new_window' => $this->openInNewWindow()
469 );
470
471 // Shortcut
472 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
473 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
474 }
475
476 return $buttons;
477 }
478
479 /**
480 * Check the access to a task. Considered are:
481 * - Admins are always allowed
482 * - Tasks can be restriced to admins only
483 * - Tasks can be blinded for Users with TsConfig taskcenter.<extensionkey>.<taskName> = 0
484 *
485 * @param string $extKey: Extension key
486 * @param string $taskClass: Name of the task
487 * @return boolean Access to the task allowed or not
488 */
489 protected function checkAccess($extKey, $taskClass) {
490 // check if task is blinded with TsConfig (taskcenter.<extkey>.<taskName>
491 $tsConfig = $GLOBALS['BE_USER']->getTSConfig('taskcenter.' . $extKey . '.' . $taskClass);
492 if (isset($tsConfig['value']) && intval($tsConfig['value']) == 0) {
493 return FALSE;
494 }
495
496 // admins are always allowed
497 if ($GLOBALS['BE_USER']->isAdmin()) {
498 return TRUE;
499 }
500
501 // check if task is restricted to admins
502 if (intval($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['admin']) == 1) {
503 return FALSE;
504 }
505
506 return TRUE;
507 }
508
509 /**
510 * Returns HTML code to dislay an url in an iframe at the right side of the taskcenter
511 *
512 * @param string $url: url to display
513 * @param int $max:
514 * @return string code that inserts the iframe (HTML)
515 */
516 public function urlInIframe($url, $max=0) {
517 $this->doc->JScodeArray[] =
518 'function resizeIframe(frame,max) {
519 var parent = $("typo3-docbody");
520 var parentHeight = $(parent).getHeight() - 0;
521 var parentWidth = $(parent).getWidth() - $("taskcenter-menu").getWidth() - 50;
522 $("list_frame").setStyle({height: parentHeight+"px", width: parentWidth+"px"});
523
524 }
525 // event crashes IE6 so he is excluded first
526 var version = parseFloat(navigator.appVersion.split(";")[1].strip().split(" ")[1]);
527 if (!(Prototype.Browser.IE && version == 6)) {
528 Event.observe(window, "resize", resizeIframe, false);
529 }';
530
531 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>';
532 }
533
534 /**
535 * Create a unique key from a string which can be used in Prototype's Sortable
536 * Therefore '_' are replaced
537 *
538 * @param string $string: string which is used to generate the identifier
539 * @return string modified string
540 */
541 protected function getUniqueKey($string) {
542 $search = array('.', '_');
543 $replace = array('-', '');
544
545 return str_replace($search, $replace, $string);
546 }
547
548 /**
549 * This method prepares the link for opening the devlog in a new window
550 *
551 * @return string Hyperlink with icon and appropriate JavaScript
552 */
553 protected function openInNewWindow() {
554 $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT');
555 $onClick = "devlogWin=window.open('" . $url . "','taskcenter','width=790,status=0,menubar=1,resizable=1,location=0,scrollbars=1,toolbar=0');return false;";
556 $content = '<a href="#" onclick="' . htmlspecialchars($onClick).'">' .
557 '<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="" />' .
558 '</a>';
559 return $content;
560 }
561
562
563 }
564
565
566 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/taskcenter/task/index.php']) {
567 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/taskcenter/task/index.php']);
568 }
569
570
571
572 // Make instance:
573 $SOBE = t3lib_div::makeInstance('SC_mod_user_task_index');
574 // Include files?
575 foreach($SOBE->include_once as $INC_FILE) {
576 include_once($INC_FILE);
577 }
578
579 $SOBE->main();
580 $SOBE->printContent();
581
582 ?>