[FEATURE][DB] Change tinyint to int in standard tables
[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 $LANG->includeLLFile('EXT:reports/mod/locallang.xml');
26 // This checks permissions and exits if the users has no permission for entry.
27 $BE_USER->modAccess($MCONF, 1);
28
29 /**
30 * Module 'Reports' for the 'reports' extension.
31 *
32 * @author Ingo Renner <ingo@typo3.org>
33 * @package TYPO3
34 * @subpackage tx_reports
35 */
36 class tx_reports_Module extends t3lib_SCbase {
37
38 protected $pageinfo;
39
40 /**
41 * Initializes the Module
42 *
43 * @return void
44 */
45 public function __construct() {
46 parent::init();
47
48 // Initialize document
49 $this->doc = t3lib_div::makeInstance('template');
50 $this->doc->setModuleTemplate(
51 t3lib_extMgm::extPath('reports') . 'mod/mod_template.html'
52 );
53 $this->doc->backPath = $GLOBALS['BACK_PATH'];
54 $this->doc->addStyleSheet(
55 'tx_reports',
56 '../' . t3lib_extMgm::siteRelPath('reports') . 'mod/mod_styles.css'
57 );
58 }
59
60 /**
61 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
62 *
63 * @return void
64 */
65 public function menuConfig() {
66 $reportsMenuItems = array();
67 $this->MOD_MENU = array('function' => array());
68
69 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $reports) {
70 foreach ($reports as $reportName => $report) {
71 $reportsMenuItems[$extKey . '.' . $reportName] = $GLOBALS['LANG']->sL($report['title']);
72 }
73 }
74
75 asort($reportsMenuItems);
76 $reportsMenuItems = array_merge(
77 array('index' => $GLOBALS['LANG']->getLL('reports_overview')),
78 $reportsMenuItems
79 );
80
81 foreach ($reportsMenuItems as $key => $title) {
82 $this->MOD_MENU['function'][$key] = $title;
83 }
84
85 parent::menuConfig();
86 }
87
88 /**
89 * Creates the module's content. In this case it rather acts as a kind of #
90 * dispatcher redirecting requests to specific reports.
91 *
92 * @return void
93 */
94 public function main() {
95 $docHeaderButtons = $this->getButtons();
96
97 // Access check!
98 // The page will show only if user has admin rights
99 if ($GLOBALS['BE_USER']->user['admin']) {
100
101 // Draw the form
102 $this->doc->form = '<form action="" method="post" enctype="multipart/form-data">';
103 // JavaScript
104 $this->doc->JScodeArray[] = '
105 script_ended = 0;
106 function jumpToUrl(URL) {
107 document.location = URL;
108 }
109 ';
110 $this->doc->postCode='
111 <script language="javascript" type="text/javascript">
112 script_ended = 1;
113 if (top.fsMod) {
114 top.fsMod.recentIds["web"] = 0;
115 }
116 </script>
117 ';
118 // Render content:
119 $this->renderModuleContent();
120 } else {
121 // If no access or if ID == 0
122 $docHeaderButtons['save'] = '';
123 $this->content .= $this->doc->spacer(10);
124 }
125
126 // compile document
127 $markers['FUNC_MENU'] = t3lib_BEfunc::getFuncMenu(
128 0,
129 'SET[function]',
130 $this->MOD_SETTINGS['function'],
131 $this->MOD_MENU['function']
132 );
133 $markers['CONTENT'] = $this->content;
134
135 // Build the <body> for the module
136
137 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
138
139 // Renders the module page
140 $this->content = $this->doc->render(
141 '',
142 $this->content
143 );
144 }
145
146 /**
147 * Prints out the module's HTML
148 *
149 * @return void
150 */
151 public function printContent() {
152 echo $this->content;
153 }
154
155 /**
156 * Generates the module content by calling the selected report
157 *
158 * @return void
159 */
160 protected function renderModuleContent() {
161 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
162
163 $action = (string) $this->MOD_SETTINGS['function'];
164 $title = '';
165 $content = '';
166
167 if ($action == 'index') {
168 $content .= $this->indexAction();
169 $title = $GLOBALS['LANG']->getLL('reports_overview');
170 } else {
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->section($title, $content, FALSE, TRUE);
186 }
187
188 /**
189 * Shows an overview list of available reports.
190 *
191 * @return string List of available reports
192 */
193 protected function indexAction() {
194 $defaultIcon = t3lib_extMgm::extRelPath('reports') . 'mod/moduleicon.gif';
195 $content = '<dl class="t3-overview-list">';
196 $reports = array();
197
198 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports'] as $extKey => $extensionReports) {
199 foreach ($extensionReports as $reportName => $report) {
200 $action = $extKey . '.' . $reportName;
201 $link = 'mod.php?M=tools_txreportsM1' . htmlspecialchars('&SET[function]=') . $action;
202
203 $reportTitle = $GLOBALS['LANG']->sL($report['title']);
204
205 // Set default report icon
206 $icon = $defaultIcon;
207 // Check for custom icon
208 if (!empty($report['icon'])) {
209 $absIconPath = t3lib_div::getFileAbsFilename($report['icon']);
210 // If the file indeed exists, assemble relative path to it
211 if (file_exists($absIconPath)) {
212 $icon = $GLOBALS['BACK_PATH'] . '../' . str_replace(PATH_site, '', $absIconPath);
213 }
214 }
215 $icon = '<img' . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], $icon, 'width="16" height="16"') . ' title="' . $reportTitle . '" alt="' . $reportTitle . '" />';
216 $reportContent = '<dt><a href="' . $link . '">' . $icon . $reportTitle . '</a></dt>';
217 $reportContent .= '<dd>' . $GLOBALS['LANG']->sL($report['description']) . '</dd>';
218
219 $reports[$reportTitle] = $reportContent;
220 }
221 }
222
223 ksort($reports);
224
225 foreach ($reports as $reportContent) {
226 $content .= $reportContent;
227 }
228
229 return $content . '</dl>';
230 }
231
232 /**
233 * Create the panel of buttons for submitting the form or otherwise
234 * perform operations.
235 *
236 * @return array All available buttons as an assoc. array
237 */
238 protected function getButtons() {
239 $buttons = array(
240 'csh' => '',
241 'shortcut' => '',
242 'save' => ''
243 );
244 // CSH
245 $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
246
247 // Shortcut
248 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
249 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
250 }
251
252 return $buttons;
253 }
254 }
255
256 // Make instance:
257 $SOBE = t3lib_div::makeInstance('tx_reports_Module');
258
259 // Include files?
260 foreach($SOBE->include_once as $INC_FILE) {
261 include_once($INC_FILE);
262 }
263
264 $SOBE->main();
265 $SOBE->printContent();
266
267 ?>