source: moodle/trunk/fuentes/admin/tool/log/stores.php @ 1331

Last change on this file since 1331 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 3.0 KB
Line 
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Logging store management.
19 *
20 * @package    tool_log
21 * @copyright  2013 Petr Skoda {@link http://skodak.org}
22 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require_once('../../../config.php');
26require_once($CFG->libdir . '/adminlib.php');
27
28$action = required_param('action', PARAM_ALPHANUMEXT);
29$enrol = required_param('store', PARAM_PLUGIN);
30
31$PAGE->set_url('/admin/tool/log/stores.php');
32$PAGE->set_context(context_system::instance());
33
34require_login();
35require_capability('moodle/site:config', context_system::instance());
36require_sesskey();
37
38$all = \tool_log\log\manager::get_store_plugins();
39$enabled = get_config('tool_log', 'enabled_stores');
40if (!$enabled) {
41    $enabled = array();
42} else {
43    $enabled = array_flip(explode(',', $enabled));
44}
45
46$return = new moodle_url('/admin/settings.php', array('section' => 'managelogging'));
47
48$syscontext = context_system::instance();
49
50switch ($action) {
51    case 'disable':
52        unset($enabled[$enrol]);
53        set_config('enabled_stores', implode(',', array_keys($enabled)), 'tool_log');
54        break;
55
56    case 'enable':
57        if (!isset($all[$enrol])) {
58            break;
59        }
60        $enabled = array_keys($enabled);
61        $enabled[] = $enrol;
62        set_config('enabled_stores', implode(',', $enabled), 'tool_log');
63        break;
64
65    case 'up':
66        if (!isset($enabled[$enrol])) {
67            break;
68        }
69        $enabled = array_keys($enabled);
70        $enabled = array_flip($enabled);
71        $current = $enabled[$enrol];
72        if ($current == 0) {
73            break; // Already at the top.
74        }
75        $enabled = array_flip($enabled);
76        $enabled[$current] = $enabled[$current - 1];
77        $enabled[$current - 1] = $enrol;
78        set_config('enabled_stores', implode(',', $enabled), 'tool_log');
79        break;
80
81    case 'down':
82        if (!isset($enabled[$enrol])) {
83            break;
84        }
85        $enabled = array_keys($enabled);
86        $enabled = array_flip($enabled);
87        $current = $enabled[$enrol];
88        if ($current == count($enabled) - 1) {
89            break; // Already at the end.
90        }
91        $enabled = array_flip($enabled);
92        $enabled[$current] = $enabled[$current + 1];
93        $enabled[$current + 1] = $enrol;
94        set_config('enabled_stores', implode(',', $enabled), 'tool_log');
95        break;
96}
97
98redirect($return);
Note: See TracBrowser for help on using the repository browser.