TYPO3 API  SVNRelease
index.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2011 Ingo Renner <ingo@typo3.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 $LANG->includeLLFile('EXT:reports/mod/locallang.xml');
00027     // This checks permissions and exits if the users has no permission for entry.
00028 $BE_USER->modAccess($MCONF, 1);
00029 
00030 
00031 /**
00032  * Module 'Reports' for the 'reports' extension.
00033  *
00034  * @author      Ingo Renner <ingo@typo3.org>
00035  * @package     TYPO3
00036  * @subpackage  tx_reports
00037  *
00038  * $Id: index.php 10120 2011-01-18 20:03:36Z ohader $
00039  */
00040 class tx_reports_Module extends t3lib_SCbase {
00041 
00042     protected $pageinfo;
00043 
00044     /**
00045      * Initializes the Module
00046      *
00047      * @return  void
00048      */
00049     public function __construct() {
00050         parent::init();
00051 
00052             // initialize document
00053         $this->doc = t3lib_div::makeInstance('template');
00054         $this->doc->setModuleTemplate(
00055             t3lib_extMgm::extPath('reports') . 'mod/mod_template.html'
00056         );
00057         $this->doc->backPath = $GLOBALS['BACK_PATH'];
00058         $this->doc->addStyleSheet(
00059             'tx_reports',
00060             '../' . t3lib_extMgm::siteRelPath('reports') . 'mod/mod_styles.css'
00061         );
00062     }
00063 
00064     /**
00065      * Adds items to the ->MOD_MENU array. Used for the function menu selector.
00066      *
00067      * @return  void
00068      */
00069     public function menuConfig() {
00070         $reportsMenuItems = array();
00071         $this->MOD_MENU   = array('function' => array());
00072 
00073         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
00074             foreach ($reports as $reportName => $report) {
00075                 $reportsMenuItems[$extKey . '.' . $reportName] = $GLOBALS['LANG']->sL($report['title']);
00076             }
00077         }
00078 
00079         asort($reportsMenuItems);
00080         $reportsMenuItems = array_merge(
00081             array('index' => $GLOBALS['LANG']->getLL('reports_overview')),
00082             $reportsMenuItems
00083         );
00084 
00085         foreach ($reportsMenuItems as $key => $title) {
00086             $this->MOD_MENU['function'][$key] = $title;
00087         }
00088 
00089         parent::menuConfig();
00090     }
00091 
00092     /**
00093      * Creates the module's content. In this case it rather acts as a kind of #
00094      * dispatcher redirecting requests to specific reports.
00095      *
00096      * @return  void
00097      */
00098     public function main() {
00099         $docHeaderButtons = $this->getButtons();
00100 
00101             // Access check!
00102             // The page will show only if user has admin rights
00103         if ($GLOBALS['BE_USER']->user['admin']) {
00104 
00105                 // Draw the form
00106             $this->doc->form = '<form action="" method="post" enctype="multipart/form-data">';
00107                 // JavaScript
00108             $this->doc->JScodeArray[] = '
00109                 script_ended = 0;
00110                 function jumpToUrl(URL) {
00111                     document.location = URL;
00112                 }
00113             ';
00114             $this->doc->postCode='
00115                 <script language="javascript" type="text/javascript">
00116                     script_ended = 1;
00117                     if (top.fsMod) {
00118                         top.fsMod.recentIds["web"] = 0;
00119                     }
00120                 </script>
00121             ';
00122                 // Render content:
00123             $this->renderModuleContent();
00124         } else {
00125                 // If no access or if ID == 0
00126             $docHeaderButtons['save'] = '';
00127             $this->content.=$this->doc->spacer(10);
00128         }
00129 
00130             // compile document
00131         $markers['FUNC_MENU'] = $GLOBALS['LANG']->getLL('choose_report')
00132             . t3lib_BEfunc::getFuncMenu(
00133                 0,
00134                 'SET[function]',
00135                 $this->MOD_SETTINGS['function'],
00136                 $this->MOD_MENU['function']
00137             );
00138         $markers['CONTENT'] = $this->content;
00139 
00140                 // Build the <body> for the module
00141         $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
00142             // Renders the module page
00143         $this->content = $this->doc->render(
00144             $GLOBALS['LANG']->getLL('title'),
00145             $this->content
00146         );
00147     }
00148 
00149     /**
00150      * Prints out the module's HTML
00151      *
00152      * @return  void
00153      */
00154     public function printContent() {
00155         echo $this->content;
00156     }
00157 
00158     /**
00159      * Generates the module content by calling the selected report
00160      *
00161      * @return  void
00162      */
00163     protected function renderModuleContent() {
00164         $action  = (string) $this->MOD_SETTINGS['function'];
00165         $title   = '';
00166         $content = '';
00167 
00168         if ($action == 'index') {
00169             $content = $this->indexAction();
00170             $title   = $GLOBALS['LANG']->getLL('reports_overview');
00171         } else {
00172             $content = '';
00173             list($extensionKey, $reportName) = explode('.', $action, 2);
00174 
00175             $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extensionKey][$reportName]['report'];
00176             $title       = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extensionKey][$reportName]['title']);
00177 
00178             $reportInstance = t3lib_div::makeInstance($reportClass, $this);
00179 
00180             if ($reportInstance instanceof tx_reports_Report) {
00181                 $content = $reportInstance->getReport();
00182             } else {
00183                 $content = $reportClass . ' does not implement the Report Interface which is necessary to be displayed here.';
00184             }
00185         }
00186 
00187         $this->content .= $this->doc->section($title, $content, false, true);
00188     }
00189 
00190     /**
00191      * Shows an overview list of available reports.
00192      *
00193      * @return  string  list of available reports
00194      */
00195     protected function indexAction() {
00196         $defaultIcon = t3lib_extMgm::extRelPath('reports') . 'mod/moduleicon.gif';
00197         $content = '<dl class="t3-overview-list">';
00198         $reports = array();
00199 
00200         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $extensionReports) {
00201             foreach ($extensionReports as $reportName => $report) {
00202                 $action = $extKey . '.' . $reportName;
00203                 $link = 'mod.php?M=tools_txreportsM1' . htmlspecialchars('&SET[function]=') . $action;
00204 
00205                 $reportTitle = $GLOBALS['LANG']->sL($report['title']);
00206 
00207                     // Set default report icon
00208                 $icon = $defaultIcon;
00209                     // Check for custom icon
00210                 if (!empty($report['icon'])) {
00211                     $absIconPath = t3lib_div::getFileAbsFilename($report['icon']);
00212                         // If the file indeed exists, assemble relative path to it
00213                     if (file_exists($absIconPath)) {
00214                         $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
00215                     }
00216                 }
00217                 $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $reportTitle . '" alt="' . $reportTitle . '" />';
00218                 $reportContent  = '<dt><a href="' . $link . '">' . $icon . $reportTitle . '</a></dt>';
00219                 $reportContent .= '<dd>' . $GLOBALS['LANG']->sL($report['description']) . '</dd>';
00220 
00221                 $reports[$reportTitle] = $reportContent;
00222             }
00223         }
00224 
00225         ksort($reports);
00226 
00227         foreach ($reports as $reportContent) {
00228             $content .= $reportContent;
00229         }
00230 
00231         return $content . '</dl>';
00232     }
00233 
00234     /**
00235      * Create the panel of buttons for submitting the form or otherwise
00236      * perform operations.
00237      *
00238      * @return  array   all available buttons as an assoc. array
00239      */
00240     protected function getButtons() {
00241         $buttons = array(
00242             'csh' => '',
00243             'shortcut' => '',
00244             'save' => ''
00245         );
00246             // CSH
00247         $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
00248 
00249             // Shortcut
00250         if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
00251             $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
00252         }
00253 
00254         return $buttons;
00255     }
00256 
00257 
00258 }
00259 
00260 
00261 
00262 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php'])) {
00263     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php']);
00264 }
00265 
00266 
00267 
00268 
00269 // Make instance:
00270 $SOBE = t3lib_div::makeInstance('tx_reports_Module');
00271 
00272 // Include files?
00273 foreach($SOBE->include_once as $INC_FILE) {
00274     include_once($INC_FILE);
00275 }
00276 
00277 $SOBE->main();
00278 $SOBE->printContent();
00279 
00280 ?>