1f8abbcf1fe963f935076d30350e5ceb3e4451c0
[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 $status[$statusProviderId] = $statusProvider->getStatus();
57 }
58
59 $content .= '<p class="help">'
60 . $GLOBALS['LANG']->getLL('status_report_explanation')
61 . '</p>';
62
63 return $content . $this->renderStatus($status);
64 }
65
66 /**
67 * Gets all registered status providers and creates instances of them.
68 *
69 * @return void
70 */
71 protected function getStatusProviders() {
72 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvider) {
73 $statusProviderInstance = t3lib_div::makeInstance($statusProvider);
74 if ($statusProviderInstance instanceof tx_reports_StatusProvider) {
75 $this->statusProviders[$key] = $statusProviderInstance;
76 }
77 }
78 }
79
80 /**
81 * Renders the system's status
82 *
83 * @param array An array of statuses as returned by the available status providers
84 * @return string The system status as an HTML table
85 */
86 protected function renderStatus(array $statusCollection) {
87 $content = '';
88 $template = '
89 <div class="typo3-message message-###CLASS###">
90 <div class="header-container">
91 <div class="message-header message-left">###HEADER###</div>
92 <div class="message-header message-right">###STATUS###</div>
93 </div>
94 <div class="message-body">###CONTENT###</div>
95 </div>';
96
97 $statuses = $this->sortStatusProviders($statusCollection);
98
99 foreach($statuses as $provider => $providerStatus) {
100 $providerState = $this->sortStatuses($providerStatus);
101
102 $id = str_replace(' ', '-', $provider);
103 if (isset($GLOBALS['BE_USER']->uc['reports']['states'][$id]) && $GLOBALS['BE_USER']->uc['reports']['states'][$id]) {
104 $collapsedStyle = 'style="display:none"';
105 $collapsedClass = 'collapsed';
106 } else {
107 $collapsedStyle = '';
108 $collapsedClass = 'expanded';
109 }
110
111
112 $classes = array(
113 tx_reports_reports_status_Status::NOTICE => 'notice',
114 tx_reports_reports_status_Status::INFO => 'information',
115 tx_reports_reports_status_Status::OK => 'ok',
116 tx_reports_reports_status_Status::WARNING => 'warning',
117 tx_reports_reports_status_Status::ERROR => 'error',
118 );
119
120 $icon[tx_reports_reports_status_Status::WARNING] = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/warning.png', 'width="16" height="16"') . ' />';
121 $icon[tx_reports_reports_status_Status::ERROR] = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/error.png', 'width="16" height="16"') . ' />';
122 $messages = '';
123 $headerIcon = '';
124 $sectionSeverity = 0;
125
126 foreach ($providerState as $status) {
127 $severity = $status->getSeverity();
128 $sectionSeverity = $severity > $sectionSeverity ? $severity : $sectionSeverity;
129 $messages .= strtr($template, array(
130 '###CLASS###' => $classes[$severity],
131 '###HEADER###' => $status->getTitle(),
132 '###STATUS###' => $status->getValue(),
133 '###CONTENT###' => $status->getMessage(),
134 ));
135 }
136 if ($sectionSeverity > 0) {
137 $headerIcon = $icon[$sectionSeverity];
138 }
139 $content .= '<h2 id="' . $id . '" class="section-header ' . $collapsedClass . '">' . $headerIcon . $provider . '</h2>
140 <div ' . $collapsedStyle . '>' . $messages . '</div>';
141 }
142 return $content;
143 }
144
145 /**
146 * Sorts the status providers (alphabetically and puts primary status providers at the beginning)
147 *
148 * @param array A collection of statuses (with providers)
149 * @return array The collection of statuses sorted by provider (beginning with provider "_install")
150 */
151 protected function sortStatusProviders(array $statusCollection) {
152 // Extract the primary status collections, i.e. the status groups
153 // that must appear on top of the status report
154 // Change their keys to localized collection titles
155 $primaryStatuses = array(
156 $GLOBALS['LANG']->getLL('status_typo3') => $statusCollection['typo3'],
157 $GLOBALS['LANG']->getLL('status_system') => $statusCollection['system'],
158 $GLOBALS['LANG']->getLL('status_security') => $statusCollection['security'],
159 $GLOBALS['LANG']->getLL('status_configuration') => $statusCollection['configuration']
160 );
161 unset(
162 $statusCollection['typo3'],
163 $statusCollection['system'],
164 $statusCollection['security'],
165 $statusCollection['configuration']
166 );
167 // Assemble list of secondary status collections with left-over collections
168 // Change their keys using localized labels if available
169 $secondaryStatuses = array();
170 foreach ($statusCollection as $statusProviderId => $collection) {
171 $label = '';
172 if (strpos($statusProviderId, 'LLL:') === 0) {
173 // Label provided by extension
174 $label = $GLOBALS['LANG']->sL($statusProviderId);
175 } else {
176 // Generic label
177 $label = $GLOBALS['LANG']->getLL('status_' . $statusProviderId);
178 }
179 $providerLabel = (empty($label)) ? $statusProviderId : $label;
180 $secondaryStatuses[$providerLabel] = $collection;
181 }
182 // Sort the secondary status collections alphabetically
183 ksort($secondaryStatuses);
184 $orderedStatusCollection = array_merge($primaryStatuses, $secondaryStatuses);
185
186 return $orderedStatusCollection;
187 }
188
189 /**
190 * Sorts the statuses by severity
191 *
192 * @param array A collection of statuses per provider
193 * @return array The collection of statuses sorted by severity
194 */
195 protected function sortStatuses(array $statusCollection) {
196 $statuses = array();
197 $sortTitle = array();
198
199 foreach ($statusCollection as $status) {
200 if ($status->getTitle() === 'TYPO3') {
201 $header = $status;
202 continue;
203 }
204
205 $statuses[] = $status;
206 $sortTitle[] = $status->getSeverity();
207 }
208 array_multisort($sortTitle, SORT_DESC, $statuses);
209
210 // making sure that the core version information is always on the top
211 if(is_object($header)) {
212 array_unshift($statuses, $header);
213 }
214 return $statuses;
215 }
216
217 /**
218 * saves the section toggle state in the backend user's uc
219 *
220 * @param array array of parameters from the AJAX interface, currently unused
221 * @param TYPO3AJAX object of type TYPO3AJAX
222 * @return void
223 */
224
225 public function saveCollapseState(array $params, TYPO3AJAX $ajaxObj) {
226 $item = t3lib_div::_POST('item');
227 $state = (bool)t3lib_div::_POST('state');
228
229 $GLOBALS['BE_USER']->uc['reports']['states'][$item] = $state;
230 $GLOBALS['BE_USER']->writeUC();
231 }
232 }
233
234
235 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']) {
236 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/reports/reports/class.tx_reports_reports_status.php']);
237 }
238
239 ?>