ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjLoggingSettingsGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Object/classes/class.ilObjectGUI.php';
5
15{
16 const SECTION_SETTINGS = 'settings';
17 const SUB_SECTION_MAIN = 'log_general_settings';
18 const SUB_SECTION_COMPONENTS = 'log_components';
19 const SUB_SECTION_ERROR = 'log_error_settings';
20
21
22 public $tpl;
23 public $lng;
24 public $ctrl;
28 protected $dic;
29 protected $tabs_gui;
30 protected $form;
31 protected $settings;
32
33
34 protected $log;
35
36
37
43 public function __construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
44 {
45 global $DIC;
46
47 $this->type = 'logs';
48 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
49
50 $this->dic = $DIC;
51 $this->lng = $this->dic->language();
52
53 $this->tpl = $this->dic['tpl'];
54 $this->lng = $this->dic->language();
55 $this->ctrl = $this->dic->ctrl();
56 $this->tabs_gui = $this->dic->tabs();
57
58 $this->initSettings();
59 $this->initErrorSettings();
60 $this->lng->loadLanguageModule('logging');
61 $this->lng->loadLanguageModule('log');
62
63 include_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
64 $this->log = ilLoggerFactory::getLogger('log');
65 }
66
71 public function getLogger()
72 {
73 return $this->log;
74 }
75
82 public function executeCommand()
83 {
84 $next_class = $this->ctrl->getNextClass($this);
85 $cmd = $this->ctrl->getCmd();
86 $this->prepareOutput();
87
88 switch ($next_class) {
89 case 'ilpermissiongui':
90 $this->tabs_gui->setTabActive('perm_settings');
91 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
92 $perm_gui = new ilPermissionGUI($this);
93 $ret = &$this->ctrl->forwardCommand($perm_gui);
94 break;
95
96 default:
97 if ($cmd == "" || $cmd == "view") {
98 $cmd = "settings";
99 }
100 $this->$cmd();
101
102 break;
103 }
104 return true;
105 }
106
107
114 public function getAdminTabs()
115 {
116 global $DIC;
117
118 $ilAccess = $DIC['ilAccess'];
119
120 if ($ilAccess->checkAccess("read", '', $this->object->getRefId())) {
121 $this->tabs_gui->addTarget(
122 static::SECTION_SETTINGS,
123 $this->ctrl->getLinkTargetByClass('ilobjloggingsettingsgui', "settings")
124 );
125 }
126 if ($ilAccess->checkAccess('edit_permission', '', $this->object->getRefId())) {
127 $this->tabs_gui->addTarget(
128 "perm_settings",
129 $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
130 );
131 }
132 }
133
134 public function setSubTabs($a_section)
135 {
136 $this->tabs_gui->addSubTab(
137 static::SUB_SECTION_MAIN,
138 $this->lng->txt(static::SUB_SECTION_MAIN),
139 $this->ctrl->getLinkTarget($this, 'settings')
140 );
141 $this->tabs_gui->addSubTab(
142 static::SUB_SECTION_ERROR,
143 $this->lng->txt(static::SUB_SECTION_ERROR),
144 $this->ctrl->getLinkTarget($this, 'errorSettings')
145 );
146 $this->tabs_gui->addSubTab(
147 static::SUB_SECTION_COMPONENTS,
148 $this->lng->txt(static::SUB_SECTION_COMPONENTS),
149 $this->ctrl->getLinkTarget($this, 'components')
150 );
151
152 $this->tabs_gui->activateSubTab($a_section);
153 }
154
155 protected function initSettings()
156 {
157 include_once("Services/Logging/classes/class.ilLoggingDBSettings.php");
159 }
160
165 public function getSettings()
166 {
167 return $this->settings;
168 }
169
174 public function settings(ilPropertyFormGUI $form = null)
175 {
176 global $DIC;
177
178 if (!$this->rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
179 $DIC['ilErr']->raiseError($this->lng->txt('permission_denied'), $DIC['ilErr']->MESSAGE);
180 }
181
182 $this->tabs_gui->setTabActive(static::SECTION_SETTINGS);
183 $this->setSubTabs(static::SUB_SECTION_MAIN);
184
185 if (!$form instanceof ilPropertyFormGUI) {
186 $form = $this->initFormSettings();
187 }
188 $this->tpl->setContent($form->getHTML());
189
190 $this->getLogger()->debug('Currrent level is ' . $this->getSettings()->getLevel());
191
192 return true;
193 }
194
199 public function updateSettings()
200 {
201 include_once 'Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
202
203 global $DIC;
204
205 $rbacsystem = $DIC['rbacsystem'];
206
207 if (!$rbacsystem->checkAccess('write', $this->object->getRefId())) {
208 $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
209 }
210
211
212 $form = $this->initFormSettings();
213 if ($form->checkInput()) {
214 $this->getSettings()->setLevel($form->getInput('level'));
215 $this->getSettings()->enableCaching($form->getInput('cache'));
216 $this->getSettings()->setCacheLevel($form->getInput('cache_level'));
217 $this->getSettings()->enableMemoryUsage($form->getInput('memory'));
218 $this->getSettings()->enableBrowserLog($form->getInput('browser'));
219 $this->getSettings()->setBrowserUsers($form->getInput('browser_users'));
220
221 $this->getLogger()->info(print_r($form->getInput('browser_users'), true));
222
223 $this->getSettings()->update();
224
225 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
226 $this->ctrl->redirect($this, 'settings');
227 return true;
228 }
229
230 ilUtil::sendFailure($this->lng->txt('err_check_input'));
231 $form->setValuesByPost();
232 $this->settings($form);
233
234 return true;
235 }
236
241 protected function initFormSettings()
242 {
243 global $DIC;
244
245 $lng = $DIC['lng'];
246 $ilDB = $DIC['ilDB'];
247 $ilAccess = $DIC['ilAccess'];
248
249 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
250 include_once './Services/Search/classes/class.ilSearchSettings.php';
251
252 $form = new ilPropertyFormGUI();
253 $form->setTitle($this->lng->txt('logs_settings'));
254 $form->setFormAction($this->ctrl->getFormAction($this));
255
256 if ($ilAccess->checkAccess('write', '', $this->object->getRefId())) {
257 $form->addCommandButton('updateSettings', $this->lng->txt('save'));
258 }
259
260 $level = new ilSelectInputGUI($this->lng->txt('log_log_level'), 'level');
261 $level->setOptions(ilLogLevel::getLevelOptions());
262 $level->setValue($this->getSettings()->getLevel());
263 $form->addItem($level);
264
265 $cache = new ilCheckboxInputGUI($this->lng->txt('log_cache_'), 'cache');
266 $cache->setInfo($this->lng->txt('log_cache_info'));
267 $cache->setValue(1);
268 $cache->setChecked($this->getSettings()->isCacheEnabled());
269 $form->addItem($cache);
270
271 $cache_level = new ilSelectInputGUI($this->lng->txt('log_cache_level'), 'cache_level');
272 $cache_level->setOptions(ilLogLevel::getLevelOptions());
273 $cache_level->setValue($this->getSettings()->getCacheLevel());
274 $cache->addSubItem($cache_level);
275
276 $memory = new ilCheckboxInputGUI($this->lng->txt('log_memory'), 'memory');
277 $memory->setValue(1);
278 $memory->setChecked($this->getSettings()->isMemoryUsageEnabled());
279 $form->addItem($memory);
280
281 // Browser handler
282 $browser = new ilCheckboxInputGUI($this->lng->txt('log_browser'), 'browser');
283 $browser->setValue(1);
284 $browser->setChecked($this->getSettings()->isBrowserLogEnabled());
285 $form->addItem($browser);
286
287 // users
288 $users = new ilTextInputGUI($this->lng->txt('log_browser_users'), 'browser_users');
289 $users->setValue(current($this->getSettings()->getBrowserLogUsers()));
290 $users->setMulti(true);
291 $users->setMultiValues($this->getSettings()->getBrowserLogUsers());
292
293 $this->getLogger()->debug(print_r($this->getSettings()->getBrowserLogUsers(), true));
294
295 $browser->addSubItem($users);
296
297
298 return $form;
299 }
300
301
305 protected function components()
306 {
307 $this->tabs_gui->activateTab(static::SECTION_SETTINGS);
308 $this->setSubTabs(static::SUB_SECTION_COMPONENTS);
309
310 include_once './Services/Logging/classes/class.ilLogComponentTableGUI.php';
311 $table = new ilLogComponentTableGUI($this, 'components');
312 $table->setEditable($this->checkPermissionBool('write'));
313 $table->init();
314 $table->parse();
315
316 $GLOBALS['DIC']['tpl']->setContent($table->getHTML());
317 }
318
322 protected function saveComponentLevels()
323 {
324 $this->checkPermission('write');
325
326 foreach ($_POST['level'] as $component_id => $value) {
327 ilLoggerFactory::getLogger('log')->debug($component_id);
328 ilLoggerFactory::getLogger('log')->debug($value);
329 include_once './Services/Logging/classes/class.ilLogComponentLevel.php';
330 $level = new ilLogComponentLevel($component_id, $value);
331 $level->update();
332 }
333
334 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
335 $this->ctrl->redirect($this, 'components');
336 }
337
338 protected function resetComponentLevels()
339 {
340 $this->checkPermission('write');
341
342 foreach (ilLogComponentLevels::getInstance()->getLogComponents() as $component) {
343 $component->setLevel(null);
344 $component->update();
345 }
346 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
347 $this->ctrl->redirect($this, 'components');
348 }
349
350 protected function errorSettings()
351 {
352 global $DIC;
353
354 if (!$this->rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
355 $DIC['ilErr']->raiseError($this->lng->txt('permission_denied'), $DIC['ilErr']->MESSAGE);
356 }
357
358 $this->tabs_gui->setTabActive(static::SECTION_SETTINGS);
359 $this->setSubTabs(static::SUB_SECTION_ERROR);
360
361 if (!$form instanceof ilPropertyFormGUI) {
362 $form = $this->initFormErrorSettings();
363 }
364 $this->tpl->setContent($form->getHTML());
365
366 $this->getLogger()->debug('Currrent level is ' . $this->getSettings()->getLevel());
367 }
368
369 protected function updateErrorSettings()
370 {
371 global $DIC;
372
373 $rbacsystem = $DIC['rbacsystem'];
374
375 if (!$rbacsystem->checkAccess('write', $this->object->getRefId())) {
376 $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
377 }
378
379 $form = $this->initFormErrorSettings();
380 if ($form->checkInput()) {
381 $this->getErrorSettings()->setMail($form->getInput('error_mail'));
382 $this->getErrorSettings()->update();
383
384 ilUtil::sendSuccess($this->lng->txt('error_settings_saved'), true);
385 $this->ctrl->redirect($this, 'errorSettings');
386 }
387
388 ilUtil::sendFailure($this->lng->txt('err_check_input'));
389 $form->setValuesByPost();
390 $this->errorSettings($form);
391 }
392
393 protected function initFormErrorSettings()
394 {
395 global $DIC;
396
397 $lng = $DIC['lng'];
398 $ilDB = $DIC['ilDB'];
399 $ilAccess = $DIC['ilAccess'];
400
401 require_once './Services/Form/classes/class.ilPropertyFormGUI.php';
402 require_once './Services/Search/classes/class.ilSearchSettings.php';
403
404 $form = new ilPropertyFormGUI();
405 $form->setTitle($this->lng->txt('logs_settings'));
406 $form->setFormAction($this->ctrl->getFormAction($this));
407
408 if ($ilAccess->checkAccess('write', '', $this->object->getRefId())) {
409 $form->addCommandButton('updateErrorSettings', $this->lng->txt('save'));
410 }
411
412 $folder = new ilNonEditableValueGUI($this->lng->txt('log_error_folder'), 'error_folder');
413 $folder->setValue($this->getErrorSettings()->folder());
414 $form->addItem($folder);
415
416 $mail = new ilTextInputGUI($this->lng->txt('log_error_mail'), 'error_mail');
417 $mail->setValue($this->getErrorSettings()->mail());
418 $form->addItem($mail);
419
420 return $form;
421 }
422
423 protected function initErrorSettings()
424 {
425 require_once("Services/Logging/classes/error/class.ilLoggingErrorSettings.php");
426 $this->error_settings = ilLoggingErrorSettings::getInstance();
427 }
428
429 protected function getErrorSettings()
430 {
431 return $this->error_settings;
432 }
433}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
individual log levels for components
Component logger with individual log levels by component id.
static getLevelOptions()
Get log level options.
static getLogger($a_component_id)
Get component logger.
static getInstance()
Get instance.
This class represents a non editable value in a property form.
settings(ilPropertyFormGUI $form=null)
Show settings @access public.
__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output=true)
Constructor.
updateSettings()
Save settings @access public.
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
prepareOutput($a_show_subobjects=true)
prepare output
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)
$ret
Definition: parser.php:6
global $ilDB