index.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2010 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             Event.observe(document, "dom:loaded", function(){
00101                 var changeEffect;
00102                 Sortable.create("task-list", { handles:$$("#task-list .drag"), tag: "li", ghosting:false, overlap:"vertical", constraint:false,
00103                  onChange: function(item) {
00104                      var list = Sortable.options(item).element;
00105                      // deactivate link
00106                     $$("#task-list a").each(function(link) {
00107                         link.writeAttribute("onclick","return false;");
00108                     });
00109 
00110                  },
00111 
00112                  onUpdate: function(list) {
00113                      new Ajax.Request("ajax.php", {
00114                          method: "post",
00115                          parameters: { ajaxID :"Taskcenter::saveSortingState", data:  Sortable.serialize(list)}
00116                      });
00117                         // activate link
00118                      Event.observe(window,"mouseup",function(){
00119                         $$("#task-list a").each(function(link) {
00120                             link.writeAttribute("onclick","");
00121                         });
00122                     });
00123 
00124                  }
00125                 });
00126 
00127                 $$("#taskcenter-menu .down").invoke("observe", "click", function(event){
00128                     var item = Event.element(event);
00129                     var itemParent = item.up();
00130                     item = item.next("div").next("div").next("div").next("div");
00131 
00132                     if (itemParent.hasClassName("expanded")) {
00133                         itemParent.removeClassName("expanded").addClassName("collapsed");
00134                         Effect.BlindUp(item, {duration : 0.5});
00135                         state = 1;
00136                     } else {
00137                         itemParent.removeClassName("collapsed").addClassName("expanded");
00138                         Effect.BlindDown(item, {duration : 0.5});
00139                         state = 0;
00140                     }
00141                     new Ajax.Request("ajax.php", {
00142                         parameters : "ajaxID=Taskcenter::saveCollapseState&item=" + itemParent.id + "&state=" + state
00143                     });
00144                 });
00145             });
00146         ';
00147         $this->doc->postCode='
00148             <script language="javascript" type="text/javascript">
00149                 script_ended = 1;
00150                 if (top.fsMod) {
00151                     top.fsMod.recentIds["web"] = 0;
00152                 }
00153             </script>
00154         ';
00155 
00156             // Render content depending on the mode
00157         $mode = (string)$this->MOD_SETTINGS['mode'];
00158         if ($mode == 'information') {
00159             $this->renderInformationContent();
00160         } else {
00161             $this->renderModuleContent();
00162         }
00163 
00164             // compile document
00165         $markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu(
00166                 0,
00167                 'SET[mode]',
00168                 $this->MOD_SETTINGS['mode'],
00169                 $this->MOD_MENU['mode']
00170             );
00171         $markers['CONTENT'] = $this->content;
00172 
00173             // Build the <body> for the module
00174         $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
00175         $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
00176         $this->content .= $this->doc->endPage();
00177         $this->content = $this->doc->insertStylesAndJS($this->content);
00178     }
00179 
00180     /**
00181      * Prints out the module's HTML
00182      *
00183      * @return  void
00184      */
00185     public function printContent() {
00186         echo $this->content;
00187     }
00188 
00189     /**
00190      * Generates the module content by calling the selected task
00191      *
00192      * @return  void
00193      */
00194     protected function renderModuleContent() {
00195         $title = $content = $actionContent = '';
00196         $chosenTask = (string)$this->MOD_SETTINGS['function'];
00197 
00198             // render the taskcenter task as default
00199         if (empty($chosenTask) || $chosenTask == 'index') {
00200             $chosenTask = 'taskcenter.tasks';
00201         }
00202 
00203             // remder the task
00204         list($extKey, $taskClass) = explode('.', $chosenTask, 2);
00205         $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['title']);
00206 
00207         if (class_exists($taskClass)) {
00208             $taskInstance = t3lib_div::makeInstance($taskClass, $this);
00209 
00210             if ($taskInstance instanceof tx_taskcenter_Task) {
00211                     // check if the task is restricted to admins only
00212                 if ($this->checkAccess($extKey, $taskClass)) {
00213                     $actionContent .= $taskInstance->getTask();
00214                 } else {
00215                     $flashMessage = t3lib_div::makeInstance(
00216                         't3lib_FlashMessage',
00217                         $GLOBALS['LANG']->getLL('error-access', TRUE),
00218                         $GLOBALS['LANG']->getLL('error_header'),
00219                         t3lib_FlashMessage::ERROR
00220                     );
00221                     $actionContent .= $flashMessage->render();
00222                 }
00223             } else {
00224                     // error if the task is not an instance of tx_taskcenter_Task
00225                 $flashMessage = t3lib_div::makeInstance(
00226                     't3lib_FlashMessage',
00227                     sprintf($GLOBALS['LANG']->getLL('error_no-instance', TRUE), $taskClass, 'tx_taskcenter_Task'),
00228                     $GLOBALS['LANG']->getLL('error_header'),
00229                     t3lib_FlashMessage::ERROR
00230                 );
00231                 $actionContent .= $flashMessage->render();
00232             }
00233         } else {
00234             $flashMessage = t3lib_div::makeInstance(
00235                 't3lib_FlashMessage',
00236                 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr'),
00237                 $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_tabs_tab'),
00238                 t3lib_FlashMessage::INFO
00239             );
00240             $actionContent .= $flashMessage->render();
00241         }
00242 
00243         $content = '<div id="taskcenter-main">
00244                         <div id="taskcenter-menu">' . $this->indexAction() . '</div>
00245                         <div id="taskcenter-item" class="' . $extKey . '-' . $taskClass . '">' .
00246                             $actionContent . '
00247                         </div>
00248                     </div>';
00249 
00250         $this->content .= $content;
00251     }
00252 
00253     /**
00254      * Generates the information content
00255      *
00256      * @return  void
00257      */
00258     protected function renderInformationContent() {
00259         $content = $this->description (
00260             $GLOBALS['LANG']->getLL('mlang_tabs_tab'),
00261             $GLOBALS['LANG']->sL('LLL:EXT:taskcenter/task/locallang_mod.xml:mlang_labels_tabdescr')
00262         );
00263 
00264         $content .= $GLOBALS['LANG']->getLL('taskcenter-about');
00265 
00266         if ($GLOBALS['BE_USER']->isAdmin()) {
00267             $content .= '<br /><br />' . $this->description (
00268                 $GLOBALS['LANG']->getLL('taskcenter-adminheader'),
00269                 $GLOBALS['LANG']->getLL('taskcenter-admin')
00270             );
00271         }
00272 
00273         $this->content .= $content;
00274     }
00275 
00276     /**
00277      * Render the headline of a task including a title and an optional description.
00278      *
00279      * @param   string      $title: Title
00280      * @param   string      $description: Description
00281      * @return  string formatted title and description
00282      */
00283     public function description($title, $description='') {
00284         if (!empty($description)) {
00285             $description = '<p class="description">' .  nl2br(htmlspecialchars($description)) . '</p><br />';
00286         }
00287         $content = $this->doc->section($title, $description, FALSE, TRUE);
00288 
00289         return $content;
00290     }
00291 
00292     /**
00293      * Render a list of items as a nicely formated definition list including a
00294      * link, icon, title and description.
00295      * The keys of a single item are:
00296      *  - title:                Title of the item
00297      *  - link:                 Link to the task
00298      *  - icon:                 Path to the icon or Icon as HTML if it begins with <img
00299      *  - description:  Description of the task, using htmlspecialchars()
00300      *  - descriptionHtml:  Description allowing HTML tags which will override the
00301      *                                          description
00302      *
00303      * @param   array       $items: List of items to be displayed in the definition list.
00304      * @param   boolean     $mainMenu: Set it to TRUE to render the main menu
00305      * @return  string  definition list
00306      */
00307     public function renderListMenu($items, $mainMenu = FALSE) {
00308         $content = $section = '';
00309         $count = 0;
00310 
00311             // change the sorting of items to the user's one
00312         if ($mainMenu) {
00313             $userSorting = unserialize($GLOBALS['BE_USER']->uc['taskcenter']['sorting']);
00314             if (is_array($userSorting)) {
00315                 $newSorting = array();
00316                 foreach($userSorting as $item) {
00317                     if(isset($items[$item])) {
00318                         $newSorting[] = $items[$item];
00319                         unset($items[$item]);
00320                     }
00321                 }
00322                 $items = $newSorting + $items;
00323             }
00324         }
00325 
00326         if (is_array($items) && count($items) > 0) {
00327             foreach($items as $item) {
00328                 $title = htmlspecialchars($item['title']);
00329 
00330                 $icon = $additionalClass = $collapsedStyle = '';
00331                     // Check for custom icon
00332                 if (!empty($item['icon'])) {
00333                     if (strpos($item['icon'], '<img ') === FALSE) {
00334                         $absIconPath = t3lib_div::getFileAbsFilename($item['icon']);
00335                             // If the file indeed exists, assemble relative path to it
00336                         if (file_exists($absIconPath)) {
00337                             $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
00338                             $icon = '<img src="' . $icon . '" title="' . $title . '" alt="' . $title . '" />';
00339                         }
00340                         if (@is_file($icon)) {
00341                             $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $title . '" alt="' . $title . '" />';
00342                         }
00343                     } else {
00344                         $icon = $item['icon'];
00345                     }
00346                 }
00347 
00348 
00349                 $description = (!empty($item['descriptionHtml'])) ? $item['descriptionHtml'] : '<p>' . nl2br(htmlspecialchars($item['description'])) . '</p>';
00350 
00351                 $id = $this->getUniqueKey($item['uid']);
00352 
00353                     // collapsed & expanded menu items
00354                 if ($mainMenu && isset($GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) && $GLOBALS['BE_USER']->uc['taskcenter']['states'][$id]) {
00355                     $collapsedStyle = 'style="display:none"';
00356                     $additionalClass = 'collapsed';
00357                 } else {
00358                     $additionalClass = 'expanded';
00359                 }
00360 
00361                     // first & last menu item
00362                 if ($count == 0) {
00363                     $additionalClass .= ' first-item';
00364                 } elseif ($count + 1 === count($items)) {
00365                     $additionalClass .= ' last-item';
00366                 }
00367 
00368                     // active menu item
00369                 $active = ((string) $this->MOD_SETTINGS['function'] == $item['uid']) ? ' active-task' : '';
00370 
00371                     // Main menu: Render additional syntax to sort tasks
00372                 if ($mainMenu) {
00373                     $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="" />';
00374                     $section = '<div class="down">&nbsp;</div>
00375                                 <div class="drag">' . $dragIcon . '</div>';
00376                     $backgroundClass = 't3-row-header ';
00377                 }
00378 
00379                 $content .= '<li class="' . $additionalClass . $active . '" id="el_' .$id . '">
00380                                 ' . $section . '
00381                                 <div class="image">' . $icon . '</div>
00382                                 <div class="' . $backgroundClass . 'link"><a href="' . $item['link'] . '">' . $title . '</a></div>
00383                                 <div class="content " ' . $collapsedStyle . '>' . $description . '</div>
00384                             </li>';
00385 
00386                 $count++;
00387             }
00388 
00389             $navigationId = ($mainMenu) ? 'id="task-list"' : '';
00390 
00391             $content = '<ul ' . $navigationId . ' class="task-list">' . $content . '</ul>';
00392 
00393         }
00394 
00395         return $content;
00396     }
00397 
00398     /**
00399      * Shows an overview list of available reports.
00400      *
00401      * @return  string  list of available reports
00402      */
00403     protected function indexAction() {
00404         $content = '';
00405         $tasks = array();
00406         $icon = t3lib_extMgm::extRelPath('taskcenter') . 'task/task.gif';
00407 
00408             // render the tasks only if there are any available
00409         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) && count($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter']) > 0) {
00410             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'] as $extKey => $extensionReports) {
00411                 foreach ($extensionReports as $taskClass => $task) {
00412                     if (!$this->checkAccess($extKey, $taskClass)) {
00413                         continue;
00414                     }
00415                     $link = 'mod.php?M=user_task&SET[function]=' . $extKey . '.' . $taskClass;
00416                     $taskTitle = $GLOBALS['LANG']->sL($task['title']);
00417                     $taskDescriptionHtml = '';
00418 
00419                         // Check for custom icon
00420                     if (!empty($task['icon'])) {
00421                         $icon = t3lib_div::getFileAbsFilename($task['icon']);
00422                     }
00423 
00424                     if (class_exists($taskClass)) {
00425                         $taskInstance = t3lib_div::makeInstance($taskClass, $this);
00426                         if ($taskInstance instanceof tx_taskcenter_Task) {
00427                             $taskDescriptionHtml = $taskInstance->getOverview();
00428                         }
00429                     }
00430 
00431                         // generate an array of all tasks
00432                     $uniqueKey = $this->getUniqueKey($extKey . '.' . $taskClass);
00433                     $tasks[$uniqueKey] = array(
00434                         'title'             => $taskTitle,
00435                         'descriptionHtml'   => $taskDescriptionHtml,
00436                         'description'       => $GLOBALS['LANG']->sL($task['description']),
00437                         'icon'              => $icon,
00438                         'link'              => $link,
00439                         'uid'               => $extKey . '.' . $taskClass
00440                     );
00441                 }
00442             }
00443 
00444             $content .= $this->renderListMenu($tasks, TRUE);
00445         } else {
00446             $flashMessage = t3lib_div::makeInstance(
00447                 't3lib_FlashMessage',
00448                 $GLOBALS['LANG']->getLL('no-tasks', TRUE),
00449                 '',
00450                 t3lib_FlashMessage::INFO
00451             );
00452             $this->content .= $flashMessage->render();
00453         }
00454 
00455         return $content;
00456     }
00457 
00458     /**
00459      * Create the panel of buttons for submitting the form or otherwise
00460      * perform operations.
00461      *
00462      * @return  array   all available buttons as an assoc. array
00463      */
00464     protected function getButtons() {
00465         $buttons = array(
00466             'csh' => t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
00467             'shortcut' => '',
00468             'open_new_window' => $this->openInNewWindow()
00469         );
00470 
00471             // Shortcut
00472         if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
00473             $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
00474         }
00475 
00476         return $buttons;
00477     }
00478 
00479     /**
00480      * Check the access to a task. Considered are:
00481      *  - Admins are always allowed
00482      *  - Tasks can be restriced to admins only
00483      *  - Tasks can be blinded for Users with TsConfig taskcenter.<extensionkey>.<taskName> = 0
00484      *
00485      * @param   string      $extKey: Extension key
00486      * @param   string      $taskClass: Name of the task
00487      * @return boolean      Access to the task allowed or not
00488      */
00489     protected function checkAccess($extKey, $taskClass) {
00490             // check if task is blinded with TsConfig (taskcenter.<extkey>.<taskName>
00491         $tsConfig = $GLOBALS['BE_USER']->getTSConfig('taskcenter.' . $extKey . '.' . $taskClass);
00492         if (isset($tsConfig['value']) && intval($tsConfig['value']) == 0) {
00493             return FALSE;
00494         }
00495 
00496         // admins are always allowed
00497         if ($GLOBALS['BE_USER']->isAdmin()) {
00498             return TRUE;
00499         }
00500 
00501             // check if task is restricted to admins
00502         if (intval($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['taskcenter'][$extKey][$taskClass]['admin']) == 1) {
00503             return FALSE;
00504         }
00505 
00506         return TRUE;
00507     }
00508 
00509     /**
00510      * Returns HTML code to dislay an url in an iframe at the right side of the taskcenter
00511      *
00512      * @param   string      $url: url to display
00513      * @param   int     $max:
00514      * @return  string      code that inserts the iframe (HTML)
00515      */
00516     public function urlInIframe($url, $max=0) {
00517         $this->doc->JScodeArray[] =
00518         'function resizeIframe(frame,max) {
00519             var parent = $("typo3-docbody");
00520             var parentHeight = $(parent).getHeight() - 0;
00521             var parentWidth = $(parent).getWidth() - $("taskcenter-menu").getWidth() - 50;
00522             $("list_frame").setStyle({height: parentHeight+"px", width: parentWidth+"px"});
00523 
00524         }
00525         // event crashes IE6 so he is excluded first
00526         var version = parseFloat(navigator.appVersion.split(";")[1].strip().split(" ")[1]);
00527         if (!(Prototype.Browser.IE && version == 6)) {
00528             Event.observe(window, "resize", resizeIframe, false);
00529         }';
00530 
00531         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>';
00532     }
00533 
00534     /**
00535      * Create a unique key from a string which can be used in Prototype's Sortable
00536      * Therefore '_' are replaced
00537      *
00538      * @param   string      $string: string which is used to generate the identifier
00539      * @return  string      modified string
00540      */
00541     protected function getUniqueKey($string) {
00542         $search     = array('.', '_');
00543         $replace    = array('-', '');
00544 
00545         return str_replace($search, $replace, $string);
00546     }
00547 
00548     /**
00549      * This method prepares the link for opening the devlog in a new window
00550      *
00551      * @return  string  Hyperlink with icon and appropriate JavaScript
00552      */
00553     protected function openInNewWindow() {
00554         $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT');
00555         $onClick = "devlogWin=window.open('" . $url . "','taskcenter','width=790,status=0,menubar=1,resizable=1,location=0,scrollbars=1,toolbar=0');return false;";
00556         $content = '<a href="#" onclick="' . htmlspecialchars($onClick).'">' .
00557                     '<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="" />' .
00558                     '</a>';
00559         return $content;
00560     }
00561 
00562 
00563 }
00564 
00565 
00566 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/taskcenter/task/index.php']) {
00567     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/taskcenter/task/index.php']);
00568 }
00569 
00570 
00571 
00572     // Make instance:
00573 $SOBE = t3lib_div::makeInstance('SC_mod_user_task_index');
00574     // Include files?
00575 foreach($SOBE->include_once as $INC_FILE) {
00576     include_once($INC_FILE);
00577 }
00578 
00579 $SOBE->main();
00580 $SOBE->printContent();
00581 
00582 ?>

Generated on Sat Jul 24 04:17:16 2010 for TYPO3 API by  doxygen 1.4.7