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