TYPO3 API  SVNRelease
index.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2010-2011 Georg Ringer <typo3@ringerge.org>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 
00026 /**
00027  * This class provides a taskcenter for BE users
00028  *
00029  * @author      Georg Ringer <typo3@ringerge.org>
00030  * @package     TYPO3
00031  * @subpackage  taskcenter
00032  *
00033  */
00034 
00035 
00036 $LANG->includeLLFile('EXT:taskcenter/task/locallang.xml');
00037 
00038 
00039 $BE_USER->modAccess($MCONF, 1);
00040 
00041 
00042 // ***************************
00043 // Script Classes
00044 // ***************************
00045 class SC_mod_user_task_index extends t3lib_SCbase {
00046 
00047     protected $pageinfo;
00048 
00049     /**
00050      * Initializes the Module
00051      *
00052      * @return  void
00053      */
00054     public function __construct() {
00055         parent::init();
00056 
00057             // initialize document
00058         $this->doc = t3lib_div::makeInstance('template');
00059         $this->doc->setModuleTemplate(
00060             t3lib_extMgm::extPath('taskcenter') . 'res/mod_template.html'
00061         );
00062         $this->doc->backPath = $GLOBALS['BACK_PATH'];
00063         $this->doc->getPageRenderer()->loadScriptaculous('effects,dragdrop');
00064         $this->doc->addStyleSheet(
00065             'tx_taskcenter',
00066             '../' . t3lib_extMgm::siteRelPath('taskcenter') . 'res/mod_styles.css'
00067         );
00068     }
00069 
00070     /**
00071      * Adds items to the ->MOD_MENU array. Used for the function menu selector.
00072      *
00073      * @return  void
00074      */
00075     public function menuConfig() {
00076         $this->MOD_MENU  = array('mode' => array());
00077 
00078         $this->MOD_MENU['mode']['information'] = $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/locallang.xml:task_overview');
00079         $this->MOD_MENU['mode']['tasks'] = 'Tasks';
00080 
00081         parent::menuConfig();
00082     }
00083 
00084     /**
00085      * Creates the module's content. In this case it rather acts as a kind of #
00086      * dispatcher redirecting requests to specific tasks.
00087      *
00088      * @return  void
00089      */
00090     public function main() {
00091         $docHeaderButtons = $this->getButtons();
00092         $markers = array();
00093 
00094         $this->doc->JScodeArray[] = '
00095             script_ended = 0;
00096             function jumpToUrl(URL) {
00097                 document.location = URL;
00098             }
00099         ';
00100         $this->doc->postCode='
00101             <script language="javascript" type="text/javascript">
00102                 script_ended = 1;
00103                 if (top.fsMod) {
00104                     top.fsMod.recentIds["web"] = 0;
00105                 }
00106             </script>
00107         ';
00108 
00109             // Render content depending on the mode
00110         $mode = (string)$this->MOD_SETTINGS['mode'];
00111         if ($mode == 'information') {
00112             $this->renderInformationContent();
00113         } else {
00114             $this->renderModuleContent();
00115         }
00116 
00117             // compile document
00118         $markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu(
00119                 0,
00120                 'SET[mode]',
00121                 $this->MOD_SETTINGS['mode'],
00122                 $this->MOD_MENU['mode']
00123             );
00124         $markers['CONTENT'] = $this->content;
00125 
00126             // Build the <body> for the module
00127         $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
00128             // Renders the module page
00129         $this->content = $this->doc->render(
00130             $GLOBALS['LANG']->getLL('title'),
00131             $this->content
00132         );
00133     }
00134 
00135     /**
00136      * Prints out the module's HTML
00137      *
00138      * @return  void
00139      */
00140     public function printContent() {
00141         echo $this->content;
00142     }
00143 
00144     /**
00145      * Generates the module content by calling the selected task
00146      *
00147      * @return  void
00148      */
00149     protected function renderModuleContent() {
00150         $title = $content = $actionContent = '';
00151         $chosenTask = (string)$this->MOD_SETTINGS['function'];
00152 
00153             // render the taskcenter task as default
00154         if (empty($chosenTask) || $chosenTask == 'index') {
00155             $chosenTask = 'taskcenter.tasks';
00156         }
00157 
00158             // remder the task
00159         list($extKey, $taskClass) = explode('.', $chosenTask, 2);
00160         $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['title']);
00161 
00162         if (class_exists($taskClass)) {
00163             $taskInstance = t3lib_div::makeInstance($taskClass, $this);
00164 
00165             if ($taskInstance instanceof tx_taskcenter_Task) {
00166                     // check if the task is restricted to admins only
00167                 if ($this->checkAccess($extKey, $taskClass)) {
00168                     $actionContent .= $taskInstance->getTask();
00169                 } else {
00170                     $flashMessage = t3lib_div::makeInstance(
00171                         't3lib_FlashMessage',
00172                         $GLOBALS['LANG']->getLL('error-access', TRUE),
00173                         $GLOBALS['LANG']->getLL('error_header'),
00174                         t3lib_FlashMessage::ERROR
00175                     );
00176                     $actionContent .= $flashMessage->render();
00177                 }
00178             } else {
00179                     // error if the task is not an instance of tx_taskcenter_Task
00180                 $flashMessage = t3lib_div::makeInstance(
00181                     't3lib_FlashMessage',
00182                     sprintf($GLOBALS['LANG']->getLL('error_no-instance', TRUE), $taskClass, 'tx_taskcenter_Task'),
00183                     $GLOBALS['LANG']->getLL('error_header'),
00184                     t3lib_FlashMessage::ERROR
00185                 );
00186                 $actionContent .= $flashMessage->render();
00187             }
00188         } else {
00189             $flashMessage = t3lib_div::makeInstance(
00190                 't3lib_FlashMessage',
00191                 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr'),
00192                 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_tabs_tab'),
00193                 t3lib_FlashMessage::INFO
00194             );
00195             $actionContent .= $flashMessage->render();
00196         }
00197 
00198         $content = '<div id="taskcenter-main">
00199                         <div id="taskcenter-menu">' . $this->indexAction() . '</div>
00200                         <div id="taskcenter-item" class="' . htmlspecialchars($extKey . '-' . $taskClass) . '">' .
00201                             $actionContent . '
00202                         </div>
00203                     </div>';
00204 
00205         $this->content .= $content;
00206     }
00207 
00208     /**
00209      * Generates the information content
00210      *
00211      * @return  void
00212      */
00213     protected function renderInformationContent() {
00214         $content = $this->description (
00215             $GLOBALS['LANG']->getLL('mlang_tabs_tab'),
00216             $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr')
00217         );
00218 
00219         $content .= $GLOBALS['LANG']->getLL('taskcenter-about');
00220 
00221         if ($GLOBALS['BE_USER']->isAdmin()) {
00222             $content .= '<br /><br />' . $this->description (
00223                 $GLOBALS['LANG']->getLL('taskcenter-adminheader'),
00224                 $GLOBALS['LANG']->getLL('taskcenter-admin')
00225             );
00226         }
00227 
00228         $this->content .= $content;
00229     }
00230 
00231     /**
00232      * Render the headline of a task including a title and an optional description.
00233      *
00234      * @param   string      $title: Title
00235      * @param   string      $description: Description
00236      * @return  string formatted title and description
00237      */
00238     public function description($title, $description='') {
00239         if (!empty($description)) {
00240             $description = '<p class="description">' .  nl2br(htmlspecialchars($description)) . '</p><br />';
00241         }
00242         $content = $this->doc->section($title, $description, FALSE, TRUE);
00243 
00244         return $content;
00245     }
00246 
00247     /**
00248      * Render a list of items as a nicely formated definition list including a
00249      * link, icon, title and description.
00250      * The keys of a single item are:
00251      *  - title:                Title of the item
00252      *  - link:                 Link to the task
00253      *  - icon:                 Path to the icon or Icon as HTML if it begins with <img
00254      *  - description:  Description of the task, using htmlspecialchars()
00255      *  - descriptionHtml:  Description allowing HTML tags which will override the
00256      *                                          description
00257      *
00258      * @param   array       $items: List of items to be displayed in the definition list.
00259      * @param   boolean     $mainMenu: Set it to TRUE to render the main menu
00260      * @return  string  definition list
00261      */
00262     public function renderListMenu($items, $mainMenu = FALSE) {
00263         $content = $section = '';
00264         $count = 0;
00265 
00266             // change the sorting of items to the user's one
00267         if ($mainMenu) {
00268             $this->doc->getPageRenderer()->addJsFile(t3lib_extMgm::extRelPath('taskcenter') . 'res/tasklist.js');
00269             $userSorting = unserialize($GLOBALS['BE_USER']->uc['taskcenter']['sorting']);
00270             if (is_array($userSorting)) {
00271                 $newSorting = array();
00272                 foreach($userSorting as $item) {
00273                     if(isset($items[$item])) {
00274                         $newSorting[] = $items[$item];
00275                         unset($items[$item]);
00276                     }
00277                 }
00278                 $items = $newSorting + $items;
00279             }
00280         }
00281 
00282         if (is_array($items) && count($items) > 0) {
00283             foreach($items as $item) {
00284                 $title = htmlspecialchars($item['title']);
00285 
00286                 $icon = $additionalClass = $collapsedStyle = '';
00287                     // Check for custom icon
00288                 if (!empty($item['icon'])) {
00289                     if (strpos($item['icon'], '<img ') === FALSE) {
00290                         $absIconPath = t3lib_div::getFileAbsFilename($item['icon']);
00291                             // If the file indeed exists, assemble relative path to it
00292                         if (file_exists($absIconPath)) {
00293                             $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
00294                             $icon = '<img src="' . $icon . '" title="' . $title . '" alt="' . $title . '" />';
00295                         }
00296                         if (@is_file($icon)) {
00297                             $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $title . '" alt="' . $title . '" />';
00298                         }
00299                     } else {
00300                         $icon = $item['icon'];
00301                     }
00302                 }
00303 
00304 
00305                 $description = (!empty($item['descriptionHtml'])) ? $item['descriptionHtml'] : '<p>' . nl2br(htmlspecialchars($item['description'])) . '</p>';
00306 
00307                 $id = $this->getUniqueKey($item['uid']);
00308 
00309                     // collapsed & expanded menu items
00310                 if ($mainMenu && isset($GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) && $GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) {
00311                     $collapsedStyle = 'style="display:none"';
00312                     $additionalClass = 'collapsed';
00313                 } else {
00314                     $additionalClass = 'expanded';
00315                 }
00316 
00317                     // first & last menu item
00318                 if ($count == 0) {
00319                     $additionalClass .= ' first-item';
00320                 } elseif ($count + 1 === count($items)) {
00321                     $additionalClass .= ' last-item';
00322                 }
00323 
00324                     // active menu item
00325                 $active = ((string) $this->MOD_SETTINGS['function'] == $item['uid']) ? ' active-task' : '';
00326 
00327                     // Main menu: Render additional syntax to sort tasks
00328                 if ($mainMenu) {
00329                     $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="" />';
00330                     $section = '<div class="down">&nbsp;</div>
00331                                 <div class="drag">' . $dragIcon . '</div>';
00332                     $backgroundClass = 't3-row-header ';
00333                 }
00334 
00335                 $content .= '<li class="' . $additionalClass . $active . '" id="el_' .$id . '">
00336                                 ' . $section . '
00337                                 <div class="image">' . $icon . '</div>
00338                                 <div class="' . $backgroundClass . 'link"><a href="' . $item['link'] . '">' . $title . '</a></div>
00339                                 <div class="content " ' . $collapsedStyle . '>' . $description . '</div>
00340                             </li>';
00341 
00342                 $count++;
00343             }
00344 
00345             $navigationId = ($mainMenu) ? 'id="task-list"' : '';
00346 
00347             $content = '<ul ' . $navigationId . ' class="task-list">' . $content . '</ul>';
00348 
00349         }
00350 
00351         return $content;
00352     }
00353 
00354     /**
00355      * Shows an overview list of available reports.
00356      *
00357      * @return  string  list of available reports
00358      */
00359     protected function indexAction() {
00360         $content = '';
00361         $tasks = array();
00362         $icon = t3lib_extMgm::extRelPath('taskcenter') . 'task/task.gif';
00363 
00364             // render the tasks only if there are any available
00365         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) && count($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) > 0) {
00366             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'] as $extKey => $extensionReports) {
00367                 foreach ($extensionReports as $taskClass => $task) {
00368                     if (!$this->checkAccess($extKey, $taskClass)) {
00369                         continue;
00370                     }
00371                     $link = 'mod.php?M=user_task&SET[function]=' . $extKey . '.' . $taskClass;
00372                     $taskTitle = $GLOBALS['LANG']->sL($task['title']);
00373                     $taskDescriptionHtml = '';
00374 
00375                         // Check for custom icon
00376                     if (!empty($task['icon'])) {
00377                         $icon = t3lib_div::getFileAbsFilename($task['icon']);
00378                     }
00379 
00380                     if (class_exists($taskClass)) {
00381                         $taskInstance = t3lib_div::makeInstance($taskClass, $this);
00382                         if ($taskInstance instanceof tx_taskcenter_Task) {
00383                             $taskDescriptionHtml = $taskInstance->getOverview();
00384                         }
00385                     }
00386 
00387                         // generate an array of all tasks
00388                     $uniqueKey = $this->getUniqueKey($extKey . '.' . $taskClass);
00389                     $tasks[$uniqueKey] = array(
00390                         'title'             => $taskTitle,
00391                         'descriptionHtml'   => $taskDescriptionHtml,
00392                         'description'       => $GLOBALS['LANG']->sL($task['description']),
00393                         'icon'              => $icon,
00394                         'link'              => $link,
00395                         'uid'               => $extKey . '.' . $taskClass
00396                     );
00397                 }
00398             }
00399 
00400             $content .= $this->renderListMenu($tasks, TRUE);
00401         } else {
00402             $flashMessage = t3lib_div::makeInstance(
00403                 't3lib_FlashMessage',
00404                 $GLOBALS['LANG']->getLL('no-tasks', TRUE),
00405                 '',
00406                 t3lib_FlashMessage::INFO
00407             );
00408             $this->content .= $flashMessage->render();
00409         }
00410 
00411         return $content;
00412     }
00413 
00414     /**
00415      * Create the panel of buttons for submitting the form or otherwise
00416      * perform operations.
00417      *
00418      * @return  array   all available buttons as an assoc. array
00419      */
00420     protected function getButtons() {
00421         $buttons = array(
00422             'csh' => t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
00423             'shortcut' => '',
00424             'open_new_window' => $this->openInNewWindow()
00425         );
00426 
00427             // Shortcut
00428         if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
00429             $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
00430         }
00431 
00432         return $buttons;
00433     }
00434 
00435     /**
00436      * Check the access to a task. Considered are:
00437      *  - Admins are always allowed
00438      *  - Tasks can be restriced to admins only
00439      *  - Tasks can be blinded for Users with TsConfig taskcenter.<extensionkey>.<taskName> = 0
00440      *
00441      * @param   string      $extKey: Extension key
00442      * @param   string      $taskClass: Name of the task
00443      * @return boolean      Access to the task allowed or not
00444      */
00445     protected function checkAccess($extKey, $taskClass) {
00446             // check if task is blinded with TsConfig (taskcenter.<extkey>.<taskName>
00447         $tsConfig = $GLOBALS['BE_USER']->getTSConfig('taskcenter.' . $extKey . '.' . $taskClass);
00448         if (isset($tsConfig['value']) && intval($tsConfig['value']) == 0) {
00449             return FALSE;
00450         }
00451 
00452         // admins are always allowed
00453         if ($GLOBALS['BE_USER']->isAdmin()) {
00454             return TRUE;
00455         }
00456 
00457             // check if task is restricted to admins
00458         if (intval($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['admin']) == 1) {
00459             return FALSE;
00460         }
00461 
00462         return TRUE;
00463     }
00464 
00465     /**
00466      * Returns HTML code to dislay an url in an iframe at the right side of the taskcenter
00467      *
00468      * @param   string      $url: url to display
00469      * @param   int     $max:
00470      * @return  string      code that inserts the iframe (HTML)
00471      */
00472     public function urlInIframe($url, $max=0) {
00473         $this->doc->JScodeArray[] =
00474         'function resizeIframe(frame,max) {
00475             var parent = $("typo3-docbody");
00476             var parentHeight = $(parent).getHeight() - 0;
00477             var parentWidth = $(parent).getWidth() - $("taskcenter-menu").getWidth() - 50;
00478             $("list_frame").setStyle({height: parentHeight+"px", width: parentWidth+"px"});
00479 
00480         }
00481         // event crashes IE6 so he is excluded first
00482         var version = parseFloat(navigator.appVersion.split(";")[1].strip().split(" ")[1]);
00483         if (!(Prototype.Browser.IE && version == 6)) {
00484             Event.observe(window, "resize", resizeIframe, false);
00485         }';
00486 
00487         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>';
00488     }
00489 
00490     /**
00491      * Create a unique key from a string which can be used in Prototype's Sortable
00492      * Therefore '_' are replaced
00493      *
00494      * @param   string      $string: string which is used to generate the identifier
00495      * @return  string      modified string
00496      */
00497     protected function getUniqueKey($string) {
00498         $search     = array('.', '_');
00499         $replace    = array('-', '');
00500 
00501         return str_replace($search, $replace, $string);
00502     }
00503 
00504     /**
00505      * This method prepares the link for opening the devlog in a new window
00506      *
00507      * @return  string  Hyperlink with icon and appropriate JavaScript
00508      */
00509     protected function openInNewWindow() {
00510         $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT');
00511         $onClick = "devlogWin=window.open('" . $url . "','taskcenter','width=790,status=0,menubar=1,resizable=1,location=0,scrollbars=1,toolbar=0');return false;";
00512         $content = '<a href="#" onclick="' . htmlspecialchars($onClick).'">' .
00513                     '<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="" />' .
00514                     '</a>';
00515         return $content;
00516     }
00517 
00518 
00519 }
00520 
00521 
00522 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/taskcenter/task/index.php'])) {
00523     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/taskcenter/task/index.php']);
00524 }
00525 
00526 
00527 
00528     // Make instance:
00529 $SOBE = t3lib_div::makeInstance('SC_mod_user_task_index');
00530     // Include files?
00531 foreach($SOBE->include_once as $INC_FILE) {
00532     include_once($INC_FILE);
00533 }
00534 
00535 $SOBE->main();
00536 $SOBE->printContent();
00537 
00538 ?>