65dfbb9dd8b0271979f1e3f504ed1110bdad90f8
[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->JScode = '
110 <script language="javascript" type="text/javascript">
111 script_ended = 0;
112 function jumpToUrl(URL) {
113 document.location = URL;
114 }
115 var state;
116 Event.observe(document, "dom:loaded", function(){
117 $$(".section-header").invoke("observe", "click", function(event){
118 var item = Event.element(event);
119 if (item.hasClassName("expanded")) {
120 item.removeClassName("expanded").addClassName("collapsed");
121 Effect.BlindUp(item.next("div"), {duration : 0.5});
122 state = 1;
123 } else {
124 item.removeClassName("collapsed").addClassName("expanded");
125 Effect.BlindDown(item.next("div"), {duration : 0.5});
126 state = 0;
127 }
128 new Ajax.Request("ajax.php", {
129 parameters : "ajaxID=Reports::saveCollapseState&item=" + item.id + "&state=" + state
130 });
131 });
132 });
133 </script>
134 ';
135 $this->doc->postCode='
136 <script language="javascript" type="text/javascript">
137 script_ended = 1;
138 if (top.fsMod) {
139 top.fsMod.recentIds["web"] = 0;
140 }
141 </script>
142 ';
143 // Render content:
144 $this->renderModuleContent();
145 } else {
146 // If no access or if ID == 0
147 $docHeaderButtons['save'] = '';
148 $this->content.=$this->doc->spacer(10);
149 }
150
151 // compile document
152 $markers['FUNC_MENU'] = $GLOBALS['LANG']->getLL('choose_report')
153 . t3lib_BEfunc::getFuncMenu(
154 0,
155 'SET[function]',
156 $this->MOD_SETTINGS['function'],
157 $this->MOD_MENU['function']
158 );
159 $markers['CONTENT'] = $this->content;
160
161 // Build the <body> for the module
162 $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
163 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
164 $this->content.= $this->doc->endPage();
165 $this->content = $this->doc->insertStylesAndJS($this->content);
166 }
167
168 /**
169 * Prints out the module's HTML
170 *
171 * @return void
172 */
173 public function printContent() {
174 echo $this->content;
175 }
176
177 /**
178 * Generates the module content by calling the selected report
179 *
180 * @return void
181 */
182 protected function renderModuleContent() {
183 $action = (string) $this->MOD_SETTINGS['function'];
184 $title = '';
185 $content = '';
186
187 if ($action == 'index') {
188 $content = $this->indexAction();
189 $title = $GLOBALS['LANG']->getLL('reports_overview');
190 } else {
191 $content = '';
192 list($extKey, $reportName) = explode('.', $action, 2);
193
194 $reportClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extKey][$reportName]['report'];
195 $title = $GLOBALS['LANG']->sL($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'][$extKey][$reportName]['title']);
196
197 $reportInstance = t3lib_div::makeInstance($reportClass, $this);
198
199 if ($reportInstance instanceof tx_reports_Report) {
200 $content = $reportInstance->getReport();
201 } else {
202 $content = $reportClass . ' does not implement the Report Interface which is necessary to be displayed here.';
203 }
204 }
205
206 $this->content .= $this->doc->section($title, $content, false, true);
207 }
208
209 /**
210 * Shows an overview list of available reports.
211 *
212 * @return string list of available reports
213 */
214 protected function indexAction() {
215 $defaultIcon = t3lib_extMgm::extRelPath('reports') . 'mod/moduleicon.gif';
216 $content = '<dl class="report-list">';
217 $reports = array();
218
219 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $extensionReports) {
220 foreach ($extensionReports as $reportName => $report) {
221 $action = $extKey . '.' . $reportName;
222 $link = 'mod.php?M=tools_txreportsM1&SET[function]=' . $action;
223
224 $reportTitle = $GLOBALS['LANG']->sL($report['title']);
225
226 // Set default report icon
227 $icon = $defaultIcon;
228 // Check for custom icon
229 if (!empty($report['icon'])) {
230 $absIconPath = t3lib_div::getFileAbsFilename($report['icon']);
231 // If the file indeed exists, assemble relative path to it
232 if (file_exists($absIconPath)) {
233 $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
234 }
235 }
236 $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $reportTitle . '" />';
237 $reportContent = '<dt><a href="' . $link . '">' . $icon . $reportTitle . '</a></dt>';
238 $reportContent .= '<dd>' . $GLOBALS['LANG']->sL($report['description']) . '</dd>';
239
240 $reports[$reportTitle] = $reportContent;
241 }
242 }
243
244 ksort($reports);
245
246 foreach ($reports as $reportContent) {
247 $content .= $reportContent;
248 }
249
250 return $content . '</dl>';
251 }
252
253 /**
254 * Create the panel of buttons for submitting the form or otherwise
255 * perform operations.
256 *
257 * @return array all available buttons as an assoc. array
258 */
259 protected function getButtons() {
260 $buttons = array(
261 'csh' => '',
262 'shortcut' => '',
263 'save' => ''
264 );
265 // CSH
266 $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
267
268 // Shortcut
269 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
270 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
271 }
272
273 return $buttons;
274 }
275
276
277 }
278
279
280
281 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php']) {
282 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/mod/index.php']);
283 }
284
285
286
287
288 // Make instance:
289 $SOBE = t3lib_div::makeInstance('tx_reports_Module');
290
291 // Include files?
292 foreach($SOBE->include_once as $INC_FILE) {
293 include_once($INC_FILE);
294 }
295
296 $SOBE->main();
297 $SOBE->printContent();
298
299 ?>