4c6ca10ef501a99e218703ca6d369a68d8f99ec4
[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'] = $GLOBALS['LANG']->getLL('choose_report')
130 . t3lib_BEfunc::getFuncMenu(
131 0,
132 'SET[function]',
133 $this->MOD_SETTINGS['function'],
134 $this->MOD_MENU['function']
135 );
136 $markers['CONTENT'] = $this->content;
137
138 // Build the <body> for the module
139 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
140 // Renders the module page
141 $this->content = $this->doc->render(
142 $GLOBALS['LANG']->getLL('title'),
143 $this->content
144 );
145 }
146
147 /**
148 * Prints out the module's HTML
149 *
150 * @return void
151 */
152 public function printContent() {
153 echo $this->content;
154 }
155
156 /**
157 * Generates the module content by calling the selected report
158 *
159 * @return void
160 */
161 protected function renderModuleContent() {
162 $action = (string) $this->MOD_SETTINGS['function'];
163 $title = '';
164 $content = '';
165
166 if ($action == 'index') {
167 $content = $this->indexAction();
168 $title = $GLOBALS['LANG']->getLL('reports_overview');
169 } else {
170 $content = '';
171 list($extensionKey, $reportName) = explode('.', $action, 2);
172
173 $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extensionKey][$reportName]['report'];
174 $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extensionKey][$reportName]['title']);
175
176 $reportInstance = t3lib_div::makeInstance($reportClass, $this);
177
178 if ($reportInstance instanceof tx_reports_Report) {
179 $content = $reportInstance->getReport();
180 } else {
181 $content = $reportClass . ' does not implement the Report Interface which is necessary to be displayed here.';
182 }
183 }
184
185 $this->content .= $this->doc->header($title);
186 $this->content .= $this->doc->section('', $content, FALSE, TRUE);
187 }
188
189 /**
190 * Shows an overview list of available reports.
191 *
192 * @return string list of available reports
193 */
194 protected function indexAction() {
195 $defaultIcon = t3lib_extMgm::extRelPath('reports') . 'mod/moduleicon.gif';
196 $content = '<dl class="t3-overview-list">';
197 $reports = array();
198
199 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $extensionReports) {
200 foreach ($extensionReports as $reportName => $report) {
201 $action = $extKey . '.' . $reportName;
202 $link = 'mod.php?M=tools_txreportsM1' . htmlspecialchars('&SET[function]=') . $action;
203
204 $reportTitle = $GLOBALS['LANG']->sL($report['title']);
205
206 // Set default report icon
207 $icon = $defaultIcon;
208 // Check for custom icon
209 if (!empty($report['icon'])) {
210 $absIconPath = t3lib_div::getFileAbsFilename($report['icon']);
211 // If the file indeed exists, assemble relative path to it
212 if (file_exists($absIconPath)) {
213 $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
214 }
215 }
216 $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $reportTitle . '" alt="' . $reportTitle . '" />';
217 $reportContent = '<dt><a href="' . $link . '">' . $icon . $reportTitle . '</a></dt>';
218 $reportContent .= '<dd>' . $GLOBALS['LANG']->sL($report['description']) . '</dd>';
219
220 $reports[$reportTitle] = $reportContent;
221 }
222 }
223
224 ksort($reports);
225
226 foreach ($reports as $reportContent) {
227 $content .= $reportContent;
228 }
229
230 return $content . '</dl>';
231 }
232
233 /**
234 * Create the panel of buttons for submitting the form or otherwise
235 * perform operations.
236 *
237 * @return array all available buttons as an assoc. array
238 */
239 protected function getButtons() {
240 $buttons = array(
241 'csh' => '',
242 'shortcut' => '',
243 'save' => ''
244 );
245 // CSH
246 $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
247
248 // Shortcut
249 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
250 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
251 }
252
253 return $buttons;
254 }
255
256
257 }
258
259
260
261 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php'])) {
262 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php']);
263 }
264
265
266
267
268 // Make instance:
269 $SOBE = t3lib_div::makeInstance('tx_reports_Module');
270
271 // Include files?
272 foreach($SOBE->include_once as $INC_FILE) {
273 include_once($INC_FILE);
274 }
275
276 $SOBE->main();
277 $SOBE->printContent();
278
279 ?>