[FEATURE] Reports interface standardize
[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 class tx_reports_Module extends t3lib_SCbase {
39
40 protected $pageinfo;
41
42 /**
43 * Initializes the Module
44 *
45 * @return void
46 */
47 public function __construct() {
48 parent::init();
49
50 // initialize document
51 $this->doc = t3lib_div::makeInstance('template');
52 $this->doc->setModuleTemplate(
53 t3lib_extMgm::extPath('reports') . 'mod/mod_template.html'
54 );
55 $this->doc->backPath = $GLOBALS['BACK_PATH'];
56 $this->doc->addStyleSheet(
57 'tx_reports',
58 '../' . t3lib_extMgm::siteRelPath('reports') . 'mod/mod_styles.css'
59 );
60 }
61
62 /**
63 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
64 *
65 * @return void
66 */
67 public function menuConfig() {
68 $reportsMenuItems = array();
69 $this->MOD_MENU = array('function' => array());
70
71 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
72 foreach ($reports as $reportName => $report) {
73 $reportsMenuItems[$extKey . '.' . $reportName] = $GLOBALS['LANG']->sL($report['title']);
74 }
75 }
76
77 asort($reportsMenuItems);
78 $reportsMenuItems = array_merge(
79 array('index' => $GLOBALS['LANG']->getLL('reports_overview')),
80 $reportsMenuItems
81 );
82
83 foreach ($reportsMenuItems as $key => $title) {
84 $this->MOD_MENU['function'][$key] = $title;
85 }
86
87 parent::menuConfig();
88 }
89
90 /**
91 * Creates the module's content. In this case it rather acts as a kind of #
92 * dispatcher redirecting requests to specific reports.
93 *
94 * @return void
95 */
96 public function main() {
97 $docHeaderButtons = $this->getButtons();
98
99 // Access check!
100 // The page will show only if user has admin rights
101 if ($GLOBALS['BE_USER']->user['admin']) {
102
103 // Draw the form
104 $this->doc->form = '<form action="" method="post" enctype="multipart/form-data">';
105 // JavaScript
106 $this->doc->JScodeArray[] = '
107 script_ended = 0;
108 function jumpToUrl(URL) {
109 document.location = URL;
110 }
111 ';
112 $this->doc->postCode='
113 <script language="javascript" type="text/javascript">
114 script_ended = 1;
115 if (top.fsMod) {
116 top.fsMod.recentIds["web"] = 0;
117 }
118 </script>
119 ';
120 // Render content:
121 $this->renderModuleContent();
122 } else {
123 // If no access or if ID == 0
124 $docHeaderButtons['save'] = '';
125 $this->content.=$this->doc->spacer(10);
126 }
127
128 // compile document
129 $markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu(
130 0,
131 'SET[function]',
132 $this->MOD_SETTINGS['function'],
133 $this->MOD_MENU['function']
134 );
135 $markers['CONTENT'] = $this->content;
136
137 // Build the <body> for the module
138
139 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
140
141 // Renders the module page
142 $this->content = $this->doc->render(
143 '',
144 $this->content
145 );
146 }
147
148 /**
149 * Prints out the module's HTML
150 *
151 * @return void
152 */
153 public function printContent() {
154 echo $this->content;
155 }
156
157 /**
158 * Generates the module content by calling the selected report
159 *
160 * @return void
161 */
162 protected function renderModuleContent() {
163 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
164
165 $action = (string) $this->MOD_SETTINGS['function'];
166 $title = '';
167 $content = '';
168
169 if ($action == 'index') {
170 $content .= $this->indexAction();
171 $title = $GLOBALS['LANG']->getLL('reports_overview');
172 } else {
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 ?>