Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / mod / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Ingo Renner <ingo@typo3.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 $LANG->includeLLFile('EXT:reports/mod/locallang.xml');
27 // This checks permissions and exits if the users has no permission for entry.
28 $BE_USER->modAccess($MCONF, 1);
29
30
31 /**
32 * Module 'Reports' for the 'reports' extension.
33 *
34 * @author Ingo Renner <ingo@typo3.org>
35 * @package TYPO3
36 * @subpackage tx_reports
37 *
38 * $Id$
39 */
40 class tx_reports_Module extends t3lib_SCbase {
41
42 protected $pageinfo;
43
44 /**
45 * Initializes the Module
46 *
47 * @return void
48 */
49 public function __construct() {
50 parent::init();
51
52 // initialize document
53 $this->doc = t3lib_div::makeInstance('template');
54 $this->doc->setModuleTemplate(
55 t3lib_extMgm::extPath('reports') . 'mod/mod_template.html'
56 );
57 $this->doc->backPath = $GLOBALS['BACK_PATH'];
58 $this->doc->addStyleSheet(
59 'tx_reports',
60 '../' . t3lib_extMgm::siteRelPath('reports') . 'mod/mod_styles.css'
61 );
62 }
63
64 /**
65 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
66 *
67 * @return void
68 */
69 public function menuConfig() {
70 $reportsMenuItems = array();
71 $this->MOD_MENU = array('function' => array());
72
73 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
74 foreach ($reports as $reportName => $report) {
75 $reportsMenuItems[$extKey . '.' . $reportName] = $GLOBALS['LANG']->sL($report['title']);
76 }
77 }
78
79 asort($reportsMenuItems);
80 $reportsMenuItems = array_merge(
81 array('index' => $GLOBALS['LANG']->getLL('reports_overview')),
82 $reportsMenuItems
83 );
84
85 foreach ($reportsMenuItems as $key => $title) {
86 $this->MOD_MENU['function'][$key] = $title;
87 }
88
89 parent::menuConfig();
90 }
91
92 /**
93 * Creates the module's content. In this case it rather acts as a kind of #
94 * dispatcher redirecting requests to specific reports.
95 *
96 * @return void
97 */
98 public function main() {
99 $docHeaderButtons = $this->getButtons();
100
101 // Access check!
102 // The page will show only if user has admin rights
103 if ($GLOBALS['BE_USER']->user['admin']) {
104
105 // Draw the form
106 $this->doc->form = '<form action="" method="post" enctype="multipart/form-data">';
107 // JavaScript
108 $this->doc->JScodeArray[] = '
109 script_ended = 0;
110 function jumpToUrl(URL) {
111 document.location = URL;
112 }
113 ';
114 $this->doc->postCode='
115 <script language="javascript" type="text/javascript">
116 script_ended = 1;
117 if (top.fsMod) {
118 top.fsMod.recentIds["web"] = 0;
119 }
120 </script>
121 ';
122 // Render content:
123 $this->renderModuleContent();
124 } else {
125 // If no access or if ID == 0
126 $docHeaderButtons['save'] = '';
127 $this->content.=$this->doc->spacer(10);
128 }
129
130 // compile document
131 $markers['FUNC_MENU'] = $GLOBALS['LANG']->getLL('choose_report')
132 . t3lib_BEfunc::getFuncMenu(
133 0,
134 'SET[function]',
135 $this->MOD_SETTINGS['function'],
136 $this->MOD_MENU['function']
137 );
138 $markers['CONTENT'] = $this->content;
139
140 // Build the <body> for the module
141 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
142 // Renders the module page
143 $this->content = $this->doc->render(
144 $GLOBALS['LANG']->getLL('title'),
145 $this->content
146 );
147 }
148
149 /**
150 * Prints out the module's HTML
151 *
152 * @return void
153 */
154 public function printContent() {
155 echo $this->content;
156 }
157
158 /**
159 * Generates the module content by calling the selected report
160 *
161 * @return void
162 */
163 protected function renderModuleContent() {
164 $action = (string) $this->MOD_SETTINGS['function'];
165 $title = '';
166 $content = '';
167
168 if ($action == 'index') {
169 $content = $this->indexAction();
170 $title = $GLOBALS['LANG']->getLL('reports_overview');
171 } else {
172 $content = '';
173 list($extensionKey, $reportName) = explode('.', $action, 2);
174
175 $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extensionKey][$reportName]['report'];
176 $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extensionKey][$reportName]['title']);
177
178 $reportInstance = t3lib_div::makeInstance($reportClass, $this);
179
180 if ($reportInstance instanceof tx_reports_Report) {
181 $content = $reportInstance->getReport();
182 } else {
183 $content = $reportClass . ' does not implement the Report Interface which is necessary to be displayed here.';
184 }
185 }
186
187 $this->content .= $this->doc->section($title, $content, false, true);
188 }
189
190 /**
191 * Shows an overview list of available reports.
192 *
193 * @return string list of available reports
194 */
195 protected function indexAction() {
196 $defaultIcon = t3lib_extMgm::extRelPath('reports') . 'mod/moduleicon.gif';
197 $content = '<dl class="t3-overview-list">';
198 $reports = array();
199
200 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $extensionReports) {
201 foreach ($extensionReports as $reportName => $report) {
202 $action = $extKey . '.' . $reportName;
203 $link = 'mod.php?M=tools_txreportsM1' . htmlspecialchars('&SET[function]=') . $action;
204
205 $reportTitle = $GLOBALS['LANG']->sL($report['title']);
206
207 // Set default report icon
208 $icon = $defaultIcon;
209 // Check for custom icon
210 if (!empty($report['icon'])) {
211 $absIconPath = t3lib_div::getFileAbsFilename($report['icon']);
212 // If the file indeed exists, assemble relative path to it
213 if (file_exists($absIconPath)) {
214 $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
215 }
216 }
217 $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $reportTitle . '" alt="' . $reportTitle . '" />';
218 $reportContent = '<dt><a href="' . $link . '">' . $icon . $reportTitle . '</a></dt>';
219 $reportContent .= '<dd>' . $GLOBALS['LANG']->sL($report['description']) . '</dd>';
220
221 $reports[$reportTitle] = $reportContent;
222 }
223 }
224
225 ksort($reports);
226
227 foreach ($reports as $reportContent) {
228 $content .= $reportContent;
229 }
230
231 return $content . '</dl>';
232 }
233
234 /**
235 * Create the panel of buttons for submitting the form or otherwise
236 * perform operations.
237 *
238 * @return array all available buttons as an assoc. array
239 */
240 protected function getButtons() {
241 $buttons = array(
242 'csh' => '',
243 'shortcut' => '',
244 'save' => ''
245 );
246 // CSH
247 $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
248
249 // Shortcut
250 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
251 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
252 }
253
254 return $buttons;
255 }
256
257
258 }
259
260
261
262 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php'])) {
263 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php']);
264 }
265
266
267
268
269 // Make instance:
270 $SOBE = t3lib_div::makeInstance('tx_reports_Module');
271
272 // Include files?
273 foreach($SOBE->include_once as $INC_FILE) {
274 include_once($INC_FILE);
275 }
276
277 $SOBE->main();
278 $SOBE->printContent();
279
280 ?>