aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/event_log.php
blob: f1d19c60da3ffeb5f03faea5e0a37ea02e649d8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
 * event_log.php - event logging admin controller
 *
 * @author    Elmar Ludwig <ludwig@uos.de>
 * @author    Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @copyright 2009 Authors
 * @license   GPL2 or any later version
 */

class EventLogController extends AuthenticatedController
{
    protected $_autobind = true;

    private $event_log;
    /**
     * common tasks for all actions
     */
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        // user must have root permission
        $GLOBALS['perm']->check('root');

        $this->event_log = new EventLog();
    }

    /**
     * show and search log events
     */
    public function show_action()
    {
        PageLayout::setTitle(_('Anzeige der Log-Events'));
        Navigation::activateItem('/admin/log/show');

        $this->page = Request::int('page', 0);

        $this->action_id   = Request::option('action_id');
        $this->object_id   = Request::option('object_id');
        $this->format      = Request::option('format');
        $this->search      = trim(Request::get('search'));
        $this->log_actions = LogAction::getUsed(true);
        $this->types       = $this->event_log->get_object_types();
        $this->type        = Request::option('type');

        // restrict log events to object scope
        if ($this->search) {
            $objects = $this->event_log->find_objects(
                $this->type,
                $this->search,
                $this->action_id
            );

            if (count($objects) > 0) {
                $this->objects = $objects;
            } else {
                PageLayout::postError(_('Kein passendes Objekt gefunden.'));
            }
        }

        // find all matching log events
        if (!$this->search || isset($this->object_id)) {
            $this->num_entries =$this->event_log->count_log_events(
                $this->action_id,
                $this->object_id
            );

            $this->log_events = $this->event_log->get_log_events(
                $this->action_id,
                $this->object_id,
                $this->page * 50
            );
        }
    }

    /**
     * configure log action
     */
    public function admin_action()
    {
        PageLayout::setTitle(_('Konfiguration der Logging-Funktionen'));
        Navigation::activateItem('/admin/log/admin');

        $this->log_actions = $this->event_log->get_log_actions();
    }

    /**
     * edit an existing log action
     */
    public function edit_action(LogAction $action)
    {
        PageLayout::setTitle(sprintf(
            _('Log-Aktion %s bearbeiten'),
            $action->name
        ));
    }

    /**
     * save changes to a log action
     */
    public function save_action(LogAction $action)
    {
        $action->description   = Request::get('description');
        $action->info_template = Request::get('info_template');
        $action->active        = (bool) Request::int('active', 0);
        $action->expires       = Request::int('expires', 0) * 86400;

        // Validate
        $errors = [];
        if (!$action->description) {
            $errors[] = _('Keine Beschreibung angegeben.');
        }
        if (!$action->info_template) {
            $errors[] = _('Kein Info-Template angegeben.');
        }
        if ($action->expires < 0) {
            $errors[] = _('Ablaufzeit darf nicht negativ sein.');
        }

        if (count($errors) > 0) {
            PageLayout::postError(_('Es sind Fehler aufgetreten.'), $errors);
            $this->render_action('edit');
            return;
        }

        $action->store();
        if (Request::isXhr()) {
            $this->response->add_header('X-Dialog-Close', 1);
            $this->render_nothing();
        } else {
            $this->redirect($this->admin());
        }
    }
}