3bdb4a85fff87d1537eeae9cd426d71f88b09338
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / reports / class.tx_reports_reports_status.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 /**
27 * The status report
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @package TYPO3
31 * @subpackage reports
32 */
33 class tx_reports_reports_Status implements tx_reports_Report {
34
35 protected $statusProviders = array();
36
37 /**
38 * constructor for class tx_reports_report_Status
39 */
40 public function __construct() {
41 $this->getStatusProviders();
42
43 $GLOBALS['LANG']->includeLLFile('EXT:reports/reports/locallang.xml');
44 }
45
46 /**
47 * Takes care of creating / rendering the status report
48 *
49 * @return string The status report as HTML
50 */
51 public function getReport() {
52 $status = array();
53 $content = '';
54
55 foreach ($this->statusProviders as $statusProviderId => $statusProvider) {
56 if (strcmp(substr($statusProviderId, 0, 4), 'LLL:')) {
57 $providerLabel = $GLOBALS['LANG']->getLL('status_' . $statusProviderId);
58 } else {
59 // label from extension
60 $providerLabel = $GLOBALS['LANG']->sL($statusProviderId);
61 }
62 $provider = $providerLabel ? $providerLabel : $statusProviderId;
63 $status[$provider] = $statusProvider->getStatus();
64 }
65
66 $content .= '<p class="help">'
67 . $GLOBALS['LANG']->getLL('status_report_explanation')
68 . '</p>';
69
70 return $content . $this->renderStatus($status);
71 }
72
73 /**
74 * Gets all registered status providers and creates instances of them.
75 *
76 * @return void
77 */
78 protected function getStatusProviders() {
79 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status'] as $key => $statusProvider) {
80 if (t3lib_div::inList('title,description,report', $key)) {
81 continue; // skip (for this report) unneccessary data
82 }
83
84 $statusProviderInstance = t3lib_div::makeInstance($statusProvider);
85 if ($statusProviderInstance instanceof tx_reports_StatusProvider) {
86 $this->statusProviders[$key] = $statusProviderInstance;
87 }
88 }
89 }
90
91 /**
92 * Renders the system's status
93 *
94 * @param array An array of statuses as returned by the available status providers
95 * @return string The system status as an HTML table
96 */
97 protected function renderStatus(array $statusCollection) {
98 $content = '';
99 $template = '
100 <div class="typo3-message message-###CLASS###">
101 <div class="header-container">
102 <div class="message-header message-left">###HEADER###</div>
103 <div class="message-header message-right">###STATUS###</div>
104 </div>
105 <div class="message-body">###CONTENT###</div>
106 </div>';
107
108 $statuses = $this->sortStatusProviders($statusCollection);
109
110 foreach($statuses as $provider => $providerStatus) {
111 $providerState = $this->sortStatuses($providerStatus);
112
113 $id = str_replace(' ', '-', $provider);
114 if (isset($GLOBALS['BE_USER']->uc['reports']['states'][$id]) && $GLOBALS['BE_USER']->uc['reports']['states'][$id]) {
115 $collapsedStyle = 'style="display:none"';
116 $collapsedClass = 'collapsed';
117 } else {
118 $collapsedStyle = '';
119 $collapsedClass = 'expanded';
120 }
121
122
123 $classes = array(
124 tx_reports_reports_status_Status::NOTICE => 'notice',
125 tx_reports_reports_status_Status::INFO => 'information',
126 tx_reports_reports_status_Status::OK => 'ok',
127 tx_reports_reports_status_Status::WARNING => 'warning',
128 tx_reports_reports_status_Status::ERROR => 'error',
129 );
130
131 $icon[tx_reports_reports_status_Status::WARNING] = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/warning.png', 'width="16" height="16"') . ' />';
132 $icon[tx_reports_reports_status_Status::ERROR] = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/error.png', 'width="16" height="16"') . ' />';
133 $messages = '';
134 $headerIcon = '';
135 $sectionSeverity = 0;
136
137 foreach ($providerState as $status) {
138 $severity = $status->getSeverity();
139 $sectionSeverity = $severity > $sectionSeverity ? $severity : $sectionSeverity;
140 $messages .= strtr($template, array(
141 '###CLASS###' => $classes[$severity],
142 '###HEADER###' => $status->getTitle(),
143 '###STATUS###' => $status->getValue(),
144 '###CONTENT###' => $status->getMessage(),
145 ));
146 }
147 if ($sectionSeverity > 0) {
148 $headerIcon = $icon[$sectionSeverity];
149 }
150 $content .= '<h2 id="' . $id . '" class="section-header ' . $collapsedClass . '">' . $headerIcon . $provider . '</h2>
151 <div ' . $collapsedStyle . '>' . $messages . '</div>';
152 }
153 return $content;
154 }
155
156 /**
157 * sorts the status providers (alphabetically and adds "_install" provider at the beginning)
158 *
159 * @param array A collection of statuses (with providers)
160 * @return array The collection of statuses sorted by provider (beginning with provider "_install")
161 */
162 protected function sortStatusProviders(array $statusCollection) {
163 $systemStatus = array(
164 'TYPO3 System' => $statusCollection['Installation'],
165 'System' => $statusCollection['System'],
166 'Security' => $statusCollection['security'],
167 'Configuration' => $statusCollection['configuration'],
168 );
169 unset(
170 $statusCollection['Installation'],
171 $statusCollection['System'],
172 $statusCollection['security'],
173 $statusCollection['configuration']
174 );
175 ksort($statusCollection);
176 $statusCollection = array_merge($systemStatus, $statusCollection);
177
178 return $statusCollection;
179 }
180
181 /**
182 * Sorts the statuses by severity
183 *
184 * @param array A collection of statuses per provider
185 * @return array The collection of statuses sorted by severity
186 */
187 protected function sortStatuses(array $statusCollection) {
188 $statuses = array();
189 $sortTitle = array();
190
191 foreach ($statusCollection as $status) {
192 if ($status->getTitle() === 'TYPO3') {
193 $header = $status;
194 continue;
195 }
196
197 $statuses[] = $status;
198 $sortTitle[] = $status->getSeverity();
199 }
200 array_multisort($sortTitle, SORT_DESC, $statuses);
201
202 // making sure that the core version information is always on the top
203 if(is_object($header)) {
204 array_unshift($statuses, $header);
205 }
206 return $statuses;
207 }
208
209 /**
210 * saves the section toggle state in the backend user's uc
211 *
212 * @param array array of parameters from the AJAX interface, currently unused
213 * @param TYPO3AJAX object of type TYPO3AJAX
214 * @return void
215 */
216
217 public function saveCollapseState(array $params, TYPO3AJAX $ajaxObj) {
218 $item = t3lib_div::_POST('item');
219 $state = (bool)t3lib_div::_POST('state');
220
221 $GLOBALS['BE_USER']->uc['reports']['states'][$item] = $state;
222 $GLOBALS['BE_USER']->writeUC();
223 }
224 }
225
226
227 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']) {
228 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
229 }
230
231 ?>