Fixed bug #12675: Validation issues in sysext reports: Fix several errors
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / mod / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 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->getPageRenderer()->loadScriptaculous('effects');
59 $this->doc->addStyleSheet(
60 'tx_reports',
61 '../' . t3lib_extMgm::siteRelPath('reports') . 'mod/mod_styles.css'
62 );
63 }
64
65 /**
66 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
67 *
68 * @return void
69 */
70 public function menuConfig() {
71 $reportsMenuItems = array();
72 $this->MOD_MENU = array('function' => array());
73
74 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
75 foreach ($reports as $reportName => $report) {
76 $reportsMenuItems[$extKey . '.' . $reportName] = $GLOBALS['LANG']->sL($report['title']);
77 }
78 }
79
80 asort($reportsMenuItems);
81 $reportsMenuItems = array_merge(
82 array('index' => $GLOBALS['LANG']->getLL('reports_overview')),
83 $reportsMenuItems
84 );
85
86 foreach ($reportsMenuItems as $key => $title) {
87 $this->MOD_MENU['function'][$key] = $title;
88 }
89
90 parent::menuConfig();
91 }
92
93 /**
94 * Creates the module's content. In this case it rather acts as a kind of #
95 * dispatcher redirecting requests to specific reports.
96 *
97 * @return void
98 */
99 public function main() {
100 $docHeaderButtons = $this->getButtons();
101
102 // Access check!
103 // The page will show only if user has admin rights
104 if ($GLOBALS['BE_USER']->user['admin']) {
105
106 // Draw the form
107 $this->doc->form = '<form action="" method="post" enctype="multipart/form-data">';
108 // JavaScript
109 $this->doc->JScodeArray[] = '
110 script_ended = 0;
111 function jumpToUrl(URL) {
112 document.location = URL;
113 }
114 var state;
115 Event.observe(document, "dom:loaded", function(){
116 $$(".section-header").invoke("observe", "click", function(event){
117 var item = Event.element(event);
118 if (item.hasClassName("expanded")) {
119 item.removeClassName("expanded").addClassName("collapsed");
120 Effect.BlindUp(item.next("div"), {duration : 0.5});
121 state = 1;
122 } else {
123 item.removeClassName("collapsed").addClassName("expanded");
124 Effect.BlindDown(item.next("div"), {duration : 0.5});
125 state = 0;
126 }
127 new Ajax.Request("ajax.php", {
128 parameters : "ajaxID=Reports::saveCollapseState&item=" + item.id + "&state=" + state
129 });
130 });
131 });
132 ';
133 $this->doc->postCode='
134 <script language="javascript" type="text/javascript">
135 script_ended = 1;
136 if (top.fsMod) {
137 top.fsMod.recentIds["web"] = 0;
138 }
139 </script>
140 ';
141 // Render content:
142 $this->renderModuleContent();
143 } else {
144 // If no access or if ID == 0
145 $docHeaderButtons['save'] = '';
146 $this->content.=$this->doc->spacer(10);
147 }
148
149 // compile document
150 $markers['FUNC_MENU'] = $GLOBALS['LANG']->getLL('choose_report')
151 . t3lib_BEfunc::getFuncMenu(
152 0,
153 'SET[function]',
154 $this->MOD_SETTINGS['function'],
155 $this->MOD_MENU['function']
156 );
157 $markers['CONTENT'] = $this->content;
158
159 // Build the <body> for the module
160 $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
161 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
162 $this->content.= $this->doc->endPage();
163 $this->content = $this->doc->insertStylesAndJS($this->content);
164 }
165
166 /**
167 * Prints out the module's HTML
168 *
169 * @return void
170 */
171 public function printContent() {
172 echo $this->content;
173 }
174
175 /**
176 * Generates the module content by calling the selected report
177 *
178 * @return void
179 */
180 protected function renderModuleContent() {
181 $action = (string) $this->MOD_SETTINGS['function'];
182 $title = '';
183 $content = '';
184
185 if ($action == 'index') {
186 $content = $this->indexAction();
187 $title = $GLOBALS['LANG']->getLL('reports_overview');
188 } else {
189 $content = '';
190 list($extKey, $reportName) = explode('.', $action, 2);
191
192 $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extKey][$reportName]['report'];
193 $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extKey][$reportName]['title']);
194
195 $reportInstance = t3lib_div::makeInstance($reportClass, $this);
196
197 if ($reportInstance instanceof tx_reports_Report) {
198 $content = $reportInstance->getReport();
199 } else {
200 $content = $reportClass . ' does not implement the Report Interface which is necessary to be displayed here.';
201 }
202 }
203
204 $this->content .= $this->doc->section($title, $content, false, true);
205 }
206
207 /**
208 * Shows an overview list of available reports.
209 *
210 * @return string list of available reports
211 */
212 protected function indexAction() {
213 $defaultIcon = t3lib_extMgm::extRelPath('reports') . 'mod/moduleicon.gif';
214 $content = '<dl class="report-list">';
215 $reports = array();
216
217 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $extensionReports) {
218 foreach ($extensionReports as $reportName => $report) {
219 $action = $extKey . '.' . $reportName;
220 $link = 'mod.php?M=tools_txreportsM1' . htmlspecialchars('&SET[function]=') . $action;
221
222 $reportTitle = $GLOBALS['LANG']->sL($report['title']);
223
224 // Set default report icon
225 $icon = $defaultIcon;
226 // Check for custom icon
227 if (!empty($report['icon'])) {
228 $absIconPath = t3lib_div::getFileAbsFilename($report['icon']);
229 // If the file indeed exists, assemble relative path to it
230 if (file_exists($absIconPath)) {
231 $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
232 }
233 }
234 $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $reportTitle . '" alt="' . $reportTitle . '" />';
235 $reportContent = '<dt><a href="' . $link . '">' . $icon . $reportTitle . '</a></dt>';
236 $reportContent .= '<dd>' . $GLOBALS['LANG']->sL($report['description']) . '</dd>';
237
238 $reports[$reportTitle] = $reportContent;
239 }
240 }
241
242 ksort($reports);
243
244 foreach ($reports as $reportContent) {
245 $content .= $reportContent;
246 }
247
248 return $content . '</dl>';
249 }
250
251 /**
252 * Create the panel of buttons for submitting the form or otherwise
253 * perform operations.
254 *
255 * @return array all available buttons as an assoc. array
256 */
257 protected function getButtons() {
258 $buttons = array(
259 'csh' => '',
260 'shortcut' => '',
261 'save' => ''
262 );
263 // CSH
264 $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
265
266 // Shortcut
267 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
268 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
269 }
270
271 return $buttons;
272 }
273
274
275 }
276
277
278
279 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php']) {
280 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php']);
281 }
282
283
284
285
286 // Make instance:
287 $SOBE = t3lib_div::makeInstance('tx_reports_Module');
288
289 // Include files?
290 foreach($SOBE->include_once as $INC_FILE) {
291 include_once($INC_FILE);
292 }
293
294 $SOBE->main();
295 $SOBE->printContent();
296
297 ?>