ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_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;
25  protected $tabs_gui;
26  protected $form;
27  protected $settings;
28 
29 
30  protected $log;
31 
32 
33 
39  public function __construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
40  {
41  global $lng,$tpl,$ilCtrl,$ilTabs;
42 
43  $this->type = 'logs';
44  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
45 
46  $this->lng = $lng;
47 
48  $this->tpl = $tpl;
49  $this->lng = $lng;
50  $this->ctrl = $ilCtrl;
51  $this->tabs_gui = $ilTabs;
52 
53  $this->initSettings();
54  $this->initErrorSettings();
55  $this->lng->loadLanguageModule('logging');
56  $this->lng->loadLanguageModule('log');
57 
58  include_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
59  $this->log = ilLoggerFactory::getLogger('log');
60  }
61 
66  public function getLogger()
67  {
68  return $this->log;
69  }
70 
77  public function executeCommand()
78  {
79  $next_class = $this->ctrl->getNextClass($this);
80  $cmd = $this->ctrl->getCmd();
81  $this->prepareOutput();
82 
83  switch ($next_class) {
84  case 'ilpermissiongui':
85  $this->tabs_gui->setTabActive('perm_settings');
86  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
87  $perm_gui = new ilPermissionGUI($this);
88  $ret =&$this->ctrl->forwardCommand($perm_gui);
89  break;
90 
91  default:
92  if ($cmd == "" || $cmd == "view") {
93  $cmd = "settings";
94  }
95  $this->$cmd();
96 
97  break;
98  }
99  return true;
100  }
101 
102 
109  public function getAdminTabs()
110  {
111  global $ilAccess;
112 
113  if ($ilAccess->checkAccess("read", '', $this->object->getRefId())) {
114  $this->tabs_gui->addTarget(
115  static::SECTION_SETTINGS,
116  $this->ctrl->getLinkTargetByClass('ilobjloggingsettingsgui', "settings")
117  );
118  }
119  if ($ilAccess->checkAccess('edit_permission', '', $this->object->getRefId())) {
120  $this->tabs_gui->addTarget(
121  "perm_settings",
122  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
123  );
124  }
125  }
126 
127  public function setSubTabs($a_section)
128  {
129  $this->tabs_gui->addSubTab(
130  static::SUB_SECTION_MAIN,
131  $this->lng->txt(static::SUB_SECTION_MAIN),
132  $this->ctrl->getLinkTarget($this, 'settings')
133  );
134  $this->tabs_gui->addSubTab(
135  static::SUB_SECTION_ERROR,
136  $this->lng->txt(static::SUB_SECTION_ERROR),
137  $this->ctrl->getLinkTarget($this, 'errorSettings')
138  );
139  $this->tabs_gui->addSubTab(
140  static::SUB_SECTION_COMPONENTS,
141  $this->lng->txt(static::SUB_SECTION_COMPONENTS),
142  $this->ctrl->getLinkTarget($this, 'components')
143  );
144 
145  $this->tabs_gui->activateSubTab($a_section);
146  }
147 
148  protected function initSettings()
149  {
150  include_once("Services/Logging/classes/class.ilLoggingDBSettings.php");
152  }
153 
158  public function getSettings()
159  {
160  return $this->settings;
161  }
162 
167  public function settings(ilPropertyFormGUI $form = null)
168  {
169  global $ilAccess,$ilErr;
170 
171  if (!$ilAccess->checkAccess('read', '', $this->object->getRefId())) {
172  $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
173  }
174 
175  $this->tabs_gui->setTabActive(static::SECTION_SETTINGS);
176  $this->setSubTabs(static::SUB_SECTION_MAIN);
177 
178  if (!$form instanceof ilPropertyFormGUI) {
179  $form = $this->initFormSettings();
180  }
181  $this->tpl->setContent($form->getHTML());
182 
183  $this->getLogger()->debug('Currrent level is ' . $this->getSettings()->getLevel());
184 
185  return true;
186  }
187 
192  public function updateSettings()
193  {
194  include_once 'Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
195 
196  global $rbacsystem;
197 
198  if (!$rbacsystem->checkAccess('write', $this->object->getRefId())) {
199  $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
200  }
201 
202 
203  $form = $this->initFormSettings();
204  if ($form->checkInput()) {
205  $this->getSettings()->setLevel($form->getInput('level'));
206  $this->getSettings()->enableCaching($form->getInput('cache'));
207  $this->getSettings()->setCacheLevel($form->getInput('cache_level'));
208  $this->getSettings()->enableMemoryUsage($form->getInput('memory'));
209  $this->getSettings()->enableBrowserLog($form->getInput('browser'));
210  $this->getSettings()->setBrowserUsers($form->getInput('browser_users'));
211 
212  $this->getLogger()->info(print_r($form->getInput('browser_users'), true));
213 
214  $this->getSettings()->update();
215 
216  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
217  $this->ctrl->redirect($this, 'settings');
218  return true;
219  }
220 
221  ilUtil::sendFailure($this->lng->txt('err_check_input'));
222  $form->setValuesByPost();
223  $this->settings($form);
224 
225  return true;
226  }
227 
232  protected function initFormSettings()
233  {
234  global $lng,$ilDB, $ilAccess;
235 
236  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
237  include_once './Services/Search/classes/class.ilSearchSettings.php';
238 
239  $form = new ilPropertyFormGUI();
240  $form->setTitle($this->lng->txt('logs_settings'));
241  $form->setFormAction($this->ctrl->getFormAction($this));
242 
243  if ($ilAccess->checkAccess('write', '', $this->object->getRefId())) {
244  $form->addCommandButton('updateSettings', $this->lng->txt('save'));
245  }
246 
247  $level = new ilSelectInputGUI($this->lng->txt('log_log_level'), 'level');
249  $level->setValue($this->getSettings()->getLevel());
250  $form->addItem($level);
251 
252  $cache = new ilCheckboxInputGUI($this->lng->txt('log_cache_'), 'cache');
253  $cache->setInfo($this->lng->txt('log_cache_info'));
254  $cache->setValue(1);
255  $cache->setChecked($this->getSettings()->isCacheEnabled());
256  $form->addItem($cache);
257 
258  $cache_level = new ilSelectInputGUI($this->lng->txt('log_cache_level'), 'cache_level');
259  $cache_level->setOptions(ilLogLevel::getLevelOptions());
260  $cache_level->setValue($this->getSettings()->getCacheLevel());
261  $cache->addSubItem($cache_level);
262 
263  $memory = new ilCheckboxInputGUI($this->lng->txt('log_memory'), 'memory');
264  $memory->setValue(1);
265  $memory->setChecked($this->getSettings()->isMemoryUsageEnabled());
266  $form->addItem($memory);
267 
268  // Browser handler
269  $browser = new ilCheckboxInputGUI($this->lng->txt('log_browser'), 'browser');
270  $browser->setValue(1);
271  $browser->setChecked($this->getSettings()->isBrowserLogEnabled());
272  $form->addItem($browser);
273 
274  // users
275  $users = new ilTextInputGUI($this->lng->txt('log_browser_users'), 'browser_users');
276  $users->setValue(current($this->getSettings()->getBrowserLogUsers()));
277  $users->setMulti(true);
278  $users->setMultiValues($this->getSettings()->getBrowserLogUsers());
279 
280  $this->getLogger()->debug(print_r($this->getSettings()->getBrowserLogUsers(), true));
281 
282  $browser->addSubItem($users);
283 
284 
285  return $form;
286  }
287 
288 
292  protected function components()
293  {
294  $this->tabs_gui->activateTab(static::SECTION_SETTINGS);
295  $this->setSubTabs(static::SUB_SECTION_COMPONENTS);
296 
297  include_once './Services/Logging/classes/class.ilLogComponentTableGUI.php';
298  $table = new ilLogComponentTableGUI($this, 'components');
299  $table->setEditable($this->checkPermissionBool('write'));
300  $table->init();
301  $table->parse();
302 
303  $GLOBALS['tpl']->setContent($table->getHTML());
304  }
305 
309  protected function saveComponentLevels()
310  {
311  $this->checkPermission('write');
312 
313  foreach ($_POST['level'] as $component_id => $value) {
314  ilLoggerFactory::getLogger('log')->debug($component_id);
315  ilLoggerFactory::getLogger('log')->debug($value);
316  include_once './Services/Logging/classes/class.ilLogComponentLevel.php';
317  $level = new ilLogComponentLevel($component_id, $value);
318  $level->update();
319  }
320 
321  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
322  $this->ctrl->redirect($this, 'components');
323  }
324 
325  protected function resetComponentLevels()
326  {
327  $this->checkPermission('write');
328 
329  foreach (ilLogComponentLevels::getInstance()->getLogComponents() as $component) {
330  $component->setLevel(null);
331  $component->update();
332  }
333  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
334  $this->ctrl->redirect($this, 'components');
335  }
336 
337  protected function errorSettings()
338  {
339  global $ilAccess,$ilErr;
340 
341  if (!$ilAccess->checkAccess('read', '', $this->object->getRefId())) {
342  $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
343  }
344 
345  $this->tabs_gui->setTabActive(static::SECTION_SETTINGS);
346  $this->setSubTabs(static::SUB_SECTION_ERROR);
347 
348  if (!$form instanceof ilPropertyFormGUI) {
349  $form = $this->initFormErrorSettings();
350  }
351  $this->tpl->setContent($form->getHTML());
352 
353  $this->getLogger()->debug('Currrent level is ' . $this->getSettings()->getLevel());
354  }
355 
356  protected function updateErrorSettings()
357  {
358  global $rbacsystem;
359 
360  if (!$rbacsystem->checkAccess('write', $this->object->getRefId())) {
361  $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
362  }
363 
364  $form = $this->initFormErrorSettings();
365  if ($form->checkInput()) {
366  $this->getErrorSettings()->setMail($form->getInput('error_mail'));
367  $this->getErrorSettings()->update();
368 
369  ilUtil::sendSuccess($this->lng->txt('error_settings_saved'), true);
370  $this->ctrl->redirect($this, 'errorSettings');
371  }
372 
373  ilUtil::sendFailure($this->lng->txt('err_check_input'));
374  $form->setValuesByPost();
375  $this->errorSettings($form);
376  }
377 
378  protected function initFormErrorSettings()
379  {
380  global $lng,$ilDB, $ilAccess;
381 
382  require_once './Services/Form/classes/class.ilPropertyFormGUI.php';
383  require_once './Services/Search/classes/class.ilSearchSettings.php';
384 
385  $form = new ilPropertyFormGUI();
386  $form->setTitle($this->lng->txt('logs_settings'));
387  $form->setFormAction($this->ctrl->getFormAction($this));
388 
389  if ($ilAccess->checkAccess('write', '', $this->object->getRefId())) {
390  $form->addCommandButton('updateErrorSettings', $this->lng->txt('save'));
391  }
392 
393  $folder = new ilNonEditableValueGUI($this->lng->txt('log_error_folder'), 'error_folder');
394  $folder->setValue($this->getErrorSettings()->folder());
395  $form->addItem($folder);
396 
397  $mail = new ilTextInputGUI($this->lng->txt('log_error_mail'), 'error_mail');
398  $mail->setValue($this->getErrorSettings()->mail());
399  $form->addItem($mail);
400 
401  return $form;
402  }
403 
404  protected function initErrorSettings()
405  {
406  require_once("Services/Logging/classes/error/class.ilLoggingErrorSettings.php");
407  $this->error_settings = ilLoggingErrorSettings::getInstance();
408  }
409 
410  protected function getErrorSettings()
411  {
412  return $this->error_settings;
413  }
414 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents a selection list property in a property form.
This class represents a property form user interface.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getLevelOptions()
Get log level options.
This class represents a checkbox property in a property form.
mail($to, $subject, $message, $additional_headers=null, $additional_parameters=null)
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
prepareOutput($a_show_subobjects=true)
prepare output
Class ilObjectGUI Basic methods of all Output classes.
setValue($a_value)
Set Value.
This class represents a text property in a property form.
redirection script todo: (a better solution should control the processing via a xml file) ...
settings(ilPropertyFormGUI $form=null)
Show settings public.
individual log levels for components
setOptions($a_options)
Set Options.
static getInstance()
Get instance.
$users
Definition: authpage.php:44
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
updateSettings()
Save settings public.
This class represents a non editable value in a property form.
global $ilDB
$ret
Definition: parser.php:6
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static getLogger($a_component_id)
Get component logger.
__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output=true)
Constructor.
if(empty($password)) $table
Definition: pwgen.php:24
setValue($a_value)
Set Value.
Component logger with individual log levels by component id.
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
$_POST["username"]