[TASK] Comment legacy files to be removed with 6.2
[Packages/TYPO3.CMS.git] / typo3 / sysext / taskcenter / Classes / Controller / TaskModuleController.php
1 <?php
2 namespace TYPO3\CMS\Taskcenter\Controller;
3
4 /**
5 * This class provides a taskcenter for BE users
6 *
7 * @author Georg Ringer <typo3@ringerge.org>
8 */
9 class TaskModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
10
11 protected $pageinfo;
12
13 /**
14 * Initializes the Module
15 *
16 * @return void
17 */
18 public function __construct() {
19 parent::init();
20 // Initialize document
21 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
22 $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('taskcenter') . 'res/mod_template.html');
23 $this->doc->backPath = $GLOBALS['BACK_PATH'];
24 $this->doc->getPageRenderer()->loadScriptaculous('effects,dragdrop');
25 $this->doc->addStyleSheet('tx_taskcenter', '../' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('taskcenter') . 'res/mod_styles.css');
26 }
27
28 /**
29 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
30 *
31 * @return void
32 */
33 public function menuConfig() {
34 $this->MOD_MENU = array('mode' => array());
35 $this->MOD_MENU['mode']['information'] = $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/locallang.xml:task_overview');
36 $this->MOD_MENU['mode']['tasks'] = 'Tasks';
37 parent::menuConfig();
38 }
39
40 /**
41 * Creates the module's content. In this case it rather acts as a kind of #
42 * dispatcher redirecting requests to specific tasks.
43 *
44 * @return void
45 */
46 public function main() {
47 $docHeaderButtons = $this->getButtons();
48 $markers = array();
49 $this->doc->JScodeArray[] = '
50 script_ended = 0;
51 function jumpToUrl(URL) {
52 document.location = URL;
53 }
54 ';
55 $this->doc->postCode = '
56 <script language="javascript" type="text/javascript">
57 script_ended = 1;
58 if (top.fsMod) {
59 top.fsMod.recentIds["web"] = 0;
60 }
61 </script>
62 ';
63 // Render content depending on the mode
64 $mode = (string) $this->MOD_SETTINGS['mode'];
65 if ($mode == 'information') {
66 $this->renderInformationContent();
67 } else {
68 $this->renderModuleContent();
69 }
70 // Compile document
71 $markers['FUNC_MENU'] = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu(0, 'SET[mode]', $this->MOD_SETTINGS['mode'], $this->MOD_MENU['mode']);
72 $markers['CONTENT'] = $this->content;
73 // Build the <body> for the module
74 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
75 // Renders the module page
76 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
77 }
78
79 /**
80 * Prints out the module's HTML
81 *
82 * @return void
83 */
84 public function printContent() {
85 echo $this->content;
86 }
87
88 /**
89 * Generates the module content by calling the selected task
90 *
91 * @return void
92 */
93 protected function renderModuleContent() {
94 $title = ($content = ($actionContent = ''));
95 $chosenTask = (string) $this->MOD_SETTINGS['function'];
96 // Render the taskcenter task as default
97 if (empty($chosenTask) || $chosenTask == 'index') {
98 $chosenTask = 'taskcenter.tasks';
99 }
100 // Render the task
101 list($extKey, $taskClass) = explode('.', $chosenTask, 2);
102 $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['title']);
103 if (class_exists($taskClass)) {
104 $taskInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($taskClass, $this);
105 if ($taskInstance instanceof \TYPO3\CMS\Taskcenter\TaskInterface) {
106 // Check if the task is restricted to admins only
107 if ($this->checkAccess($extKey, $taskClass)) {
108 $actionContent .= $taskInstance->getTask();
109 } else {
110 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('error-access', TRUE), $GLOBALS['LANG']->getLL('error_header'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
111 $actionContent .= $flashMessage->render();
112 }
113 } else {
114 // Error if the task is not an instance of tx_taskcenter_Task
115 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('error_no-instance', TRUE), $taskClass, 'TYPO3\\CMS\\Taskcenter\\TaskInterface'), $GLOBALS['LANG']->getLL('error_header'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
116 $actionContent .= $flashMessage->render();
117 }
118 } else {
119 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr'), $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_tabs_tab'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
120 $actionContent .= $flashMessage->render();
121 }
122 $content = '<div id="taskcenter-main">
123 <div id="taskcenter-menu">' . $this->indexAction() . '</div>
124 <div id="taskcenter-item" class="' . htmlspecialchars(($extKey . '-' . $taskClass)) . '">' . $actionContent . '
125 </div>
126 </div>';
127 $this->content .= $content;
128 }
129
130 /**
131 * Generates the information content
132 *
133 * @return void
134 */
135 protected function renderInformationContent() {
136 $content = $this->description($GLOBALS['LANG']->getLL('mlang_tabs_tab'), $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr'));
137 $content .= $GLOBALS['LANG']->getLL('taskcenter-about');
138 if ($GLOBALS['BE_USER']->isAdmin()) {
139 $content .= '<br /><br />' . $this->description($GLOBALS['LANG']->getLL('taskcenter-adminheader'), $GLOBALS['LANG']->getLL('taskcenter-admin'));
140 }
141 $this->content .= $content;
142 }
143
144 /**
145 * Render the headline of a task including a title and an optional description.
146 *
147 * @param string $title Title
148 * @param string $description Description
149 * @return string formatted title and description
150 */
151 public function description($title, $description = '') {
152 if (!empty($description)) {
153 $description = '<p class="description">' . nl2br(htmlspecialchars($description)) . '</p><br />';
154 }
155 $content = $this->doc->section($title, $description, FALSE, TRUE);
156 return $content;
157 }
158
159 /**
160 * Render a list of items as a nicely formated definition list including a
161 * link, icon, title and description.
162 * The keys of a single item are:
163 * - title: Title of the item
164 * - link: Link to the task
165 * - icon: Path to the icon or Icon as HTML if it begins with <img
166 * - description: Description of the task, using htmlspecialchars()
167 * - descriptionHtml: Description allowing HTML tags which will override the
168 * description
169 *
170 * @param array $items List of items to be displayed in the definition list.
171 * @param boolean $mainMenu Set it to TRUE to render the main menu
172 * @return string Fefinition list
173 */
174 public function renderListMenu($items, $mainMenu = FALSE) {
175 $content = ($section = '');
176 $count = 0;
177 // Change the sorting of items to the user's one
178 if ($mainMenu) {
179 $this->doc->getPageRenderer()->addJsFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('taskcenter') . 'res/tasklist.js');
180 $userSorting = unserialize($GLOBALS['BE_USER']->uc['taskcenter']['sorting']);
181 if (is_array($userSorting)) {
182 $newSorting = array();
183 foreach ($userSorting as $item) {
184 if (isset($items[$item])) {
185 $newSorting[] = $items[$item];
186 unset($items[$item]);
187 }
188 }
189 $items = $newSorting + $items;
190 }
191 }
192 if (is_array($items) && count($items) > 0) {
193 foreach ($items as $item) {
194 $title = htmlspecialchars($item['title']);
195 $icon = ($additionalClass = ($collapsedStyle = ''));
196 // Check for custom icon
197 if (!empty($item['icon'])) {
198 if (strpos($item['icon'], '<img ') === FALSE) {
199 $absIconPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFilename($item['icon']);
200 // If the file indeed exists, assemble relative path to it
201 if (file_exists($absIconPath)) {
202 $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
203 $icon = '<img src="' . $icon . '" title="' . $title . '" alt="' . $title . '" />';
204 }
205 if (@is_file($icon)) {
206 $icon = '<img' . \t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $title . '" alt="' . $title . '" />';
207 }
208 } else {
209 $icon = $item['icon'];
210 }
211 }
212 $description = !empty($item['descriptionHtml']) ? $item['descriptionHtml'] : '<p>' . nl2br(htmlspecialchars($item['description'])) . '</p>';
213 $id = $this->getUniqueKey($item['uid']);
214 // Collapsed & expanded menu items
215 if ($mainMenu && isset($GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) && $GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) {
216 $collapsedStyle = 'style="display:none"';
217 $additionalClass = 'collapsed';
218 } else {
219 $additionalClass = 'expanded';
220 }
221 // First & last menu item
222 if ($count == 0) {
223 $additionalClass .= ' first-item';
224 } elseif ($count + 1 === count($items)) {
225 $additionalClass .= ' last-item';
226 }
227 // Active menu item
228 $active = (string) $this->MOD_SETTINGS['function'] == $item['uid'] ? ' active-task' : '';
229 // Main menu: Render additional syntax to sort tasks
230 if ($mainMenu) {
231 $dragIcon = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::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="" />';
232 $section = '<div class="down">&nbsp;</div>
233 <div class="drag">' . $dragIcon . '</div>';
234 $backgroundClass = 't3-row-header ';
235 }
236 $content .= '<li class="' . $additionalClass . $active . '" id="el_' . $id . '">
237 ' . $section . '
238 <div class="image">' . $icon . '</div>
239 <div class="' . $backgroundClass . 'link"><a href="' . $item['link'] . '">' . $title . '</a></div>
240 <div class="content " ' . $collapsedStyle . '>' . $description . '</div>
241 </li>';
242 $count++;
243 }
244 $navigationId = $mainMenu ? 'id="task-list"' : '';
245 $content = '<ul ' . $navigationId . ' class="task-list">' . $content . '</ul>';
246 }
247 return $content;
248 }
249
250 /**
251 * Shows an overview list of available reports.
252 *
253 * @return string List of available reports
254 */
255 protected function indexAction() {
256 $content = '';
257 $tasks = array();
258 $icon = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('taskcenter') . 'task/task.gif';
259 // Render the tasks only if there are any available
260 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) && count($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) > 0) {
261 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'] as $extKey => $extensionReports) {
262 foreach ($extensionReports as $taskClass => $task) {
263 if (!$this->checkAccess($extKey, $taskClass)) {
264 continue;
265 }
266 $link = 'mod.php?M=user_task&SET[function]=' . $extKey . '.' . $taskClass;
267 $taskTitle = $GLOBALS['LANG']->sL($task['title']);
268 $taskDescriptionHtml = '';
269 // Check for custom icon
270 if (!empty($task['icon'])) {
271 $icon = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFilename($task['icon']);
272 }
273 if (class_exists($taskClass)) {
274 $taskInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($taskClass, $this);
275 if ($taskInstance instanceof \TYPO3\CMS\Taskcenter\TaskInterface) {
276 $taskDescriptionHtml = $taskInstance->getOverview();
277 }
278 }
279 // Generate an array of all tasks
280 $uniqueKey = $this->getUniqueKey($extKey . '.' . $taskClass);
281 $tasks[$uniqueKey] = array(
282 'title' => $taskTitle,
283 'descriptionHtml' => $taskDescriptionHtml,
284 'description' => $GLOBALS['LANG']->sL($task['description']),
285 'icon' => $icon,
286 'link' => $link,
287 'uid' => $extKey . '.' . $taskClass
288 );
289 }
290 }
291 $content .= $this->renderListMenu($tasks, TRUE);
292 } else {
293 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('no-tasks', TRUE), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
294 $this->content .= $flashMessage->render();
295 }
296 return $content;
297 }
298
299 /**
300 * Create the panel of buttons for submitting the form or otherwise
301 * perform operations.
302 *
303 * @return array All available buttons as an assoc. array
304 */
305 protected function getButtons() {
306 $buttons = array(
307 'csh' => \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
308 'shortcut' => '',
309 'open_new_window' => $this->openInNewWindow()
310 );
311 // Shortcut
312 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
313 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
314 }
315 return $buttons;
316 }
317
318 /**
319 * Check the access to a task. Considered are:
320 * - Admins are always allowed
321 * - Tasks can be restriced to admins only
322 * - Tasks can be blinded for Users with TsConfig taskcenter.<extensionkey>.<taskName> = 0
323 *
324 * @param string $extKey Extension key
325 * @param string $taskClass Name of the task
326 * @return boolean Access to the task allowed or not
327 */
328 protected function checkAccess($extKey, $taskClass) {
329 // Check if task is blinded with TsConfig (taskcenter.<extkey>.<taskName>
330 $tsConfig = $GLOBALS['BE_USER']->getTSConfig('taskcenter.' . $extKey . '.' . $taskClass);
331 if (isset($tsConfig['value']) && intval($tsConfig['value']) == 0) {
332 return FALSE;
333 }
334 // Admins are always allowed
335 if ($GLOBALS['BE_USER']->isAdmin()) {
336 return TRUE;
337 }
338 // Check if task is restricted to admins
339 if (intval($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['admin']) == 1) {
340 return FALSE;
341 }
342 return TRUE;
343 }
344
345 /**
346 * Returns HTML code to dislay an url in an iframe at the right side of the taskcenter
347 *
348 * @param string $url Url to display
349 * @param integer $max
350 * @return string Code that inserts the iframe (HTML)
351 */
352 public function urlInIframe($url, $max = 0) {
353 $this->doc->JScodeArray[] = 'function resizeIframe(frame,max) {
354 var parent = $("typo3-docbody");
355 var parentHeight = $(parent).getHeight() - 0;
356 var parentWidth = $(parent).getWidth() - $("taskcenter-menu").getWidth() - 50;
357 $("list_frame").setStyle({height: parentHeight+"px", width: parentWidth+"px"});
358
359 }
360 Event.observe(window, "resize", resizeIframe, false);';
361 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>';
362 }
363
364 /**
365 * Create a unique key from a string which can be used in Prototype's Sortable
366 * Therefore '_' are replaced
367 *
368 * @param string $string string which is used to generate the identifier
369 * @return string Modified string
370 */
371 protected function getUniqueKey($string) {
372 $search = array('.', '_');
373 $replace = array('-', '');
374 return str_replace($search, $replace, $string);
375 }
376
377 /**
378 * This method prepares the link for opening the devlog in a new window
379 *
380 * @return string Hyperlink with icon and appropriate JavaScript
381 */
382 protected function openInNewWindow() {
383 $url = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
384 $onClick = 'devlogWin=window.open(\'' . $url . '\',\'taskcenter\',\'width=790,status=0,menubar=1,resizable=1,location=0,scrollbars=1,toolbar=0\');return false;';
385 $content = '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::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="" />' . '</a>';
386 return $content;
387 }
388
389 }
390
391
392 ?>