| 1 | efrain | 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 |   | 
        
           |  |  | 25 | require_once('../../../config.php');
 | 
        
           |  |  | 26 | require_once($CFG->libdir . '/adminlib.php');
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 | $action = required_param('action', PARAM_ALPHANUMEXT);
 | 
        
           |  |  | 29 | $store = required_param('store', PARAM_PLUGIN);
 | 
        
           |  |  | 30 |   | 
        
           |  |  | 31 | $PAGE->set_url('/admin/tool/log/stores.php');
 | 
        
           |  |  | 32 | $PAGE->set_context(context_system::instance());
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | require_admin();
 | 
        
           |  |  | 35 | require_sesskey();
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 | $all = \tool_log\log\manager::get_store_plugins();
 | 
        
           |  |  | 38 | $enabled = get_config('tool_log', 'enabled_stores');
 | 
        
           |  |  | 39 | if (!$enabled) {
 | 
        
           |  |  | 40 |     $enabled = array();
 | 
        
           |  |  | 41 | } else {
 | 
        
           |  |  | 42 |     $enabled = array_flip(explode(',', $enabled));
 | 
        
           |  |  | 43 | }
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 | $return = new moodle_url('/admin/settings.php', array('section' => 'managelogging'));
 | 
        
           |  |  | 46 |   | 
        
           |  |  | 47 | $syscontext = context_system::instance();
 | 
        
           |  |  | 48 |   | 
        
           |  |  | 49 | switch ($action) {
 | 
        
           |  |  | 50 |     case 'disable':
 | 
        
           |  |  | 51 |         $class = \core_plugin_manager::resolve_plugininfo_class('logstore');
 | 
        
           |  |  | 52 |         $class::enable_plugin($store, false);
 | 
        
           |  |  | 53 |         break;
 | 
        
           |  |  | 54 |   | 
        
           |  |  | 55 |     case 'enable':
 | 
        
           |  |  | 56 |         $class = \core_plugin_manager::resolve_plugininfo_class('logstore');
 | 
        
           |  |  | 57 |         $class::enable_plugin($store, true);
 | 
        
           |  |  | 58 |         break;
 | 
        
           |  |  | 59 |   | 
        
           |  |  | 60 |     case 'up':
 | 
        
           |  |  | 61 |         if (!isset($enabled[$store])) {
 | 
        
           |  |  | 62 |             break;
 | 
        
           |  |  | 63 |         }
 | 
        
           |  |  | 64 |         $enabled = array_keys($enabled);
 | 
        
           |  |  | 65 |         $enabled = array_flip($enabled);
 | 
        
           |  |  | 66 |         $current = $enabled[$store];
 | 
        
           |  |  | 67 |         if ($current == 0) {
 | 
        
           |  |  | 68 |             break; // Already at the top.
 | 
        
           |  |  | 69 |         }
 | 
        
           |  |  | 70 |         $enabled = array_flip($enabled);
 | 
        
           |  |  | 71 |         $enabled[$current] = $enabled[$current - 1];
 | 
        
           |  |  | 72 |         $enabled[$current - 1] = $store;
 | 
        
           |  |  | 73 |         set_config('enabled_stores', implode(',', $enabled), 'tool_log');
 | 
        
           |  |  | 74 |         break;
 | 
        
           |  |  | 75 |   | 
        
           |  |  | 76 |     case 'down':
 | 
        
           |  |  | 77 |         if (!isset($enabled[$store])) {
 | 
        
           |  |  | 78 |             break;
 | 
        
           |  |  | 79 |         }
 | 
        
           |  |  | 80 |         $enabled = array_keys($enabled);
 | 
        
           |  |  | 81 |         $enabled = array_flip($enabled);
 | 
        
           |  |  | 82 |         $current = $enabled[$store];
 | 
        
           |  |  | 83 |         if ($current == count($enabled) - 1) {
 | 
        
           |  |  | 84 |             break; // Already at the end.
 | 
        
           |  |  | 85 |         }
 | 
        
           |  |  | 86 |         $enabled = array_flip($enabled);
 | 
        
           |  |  | 87 |         $enabled[$current] = $enabled[$current + 1];
 | 
        
           |  |  | 88 |         $enabled[$current + 1] = $store;
 | 
        
           |  |  | 89 |         set_config('enabled_stores', implode(',', $enabled), 'tool_log');
 | 
        
           |  |  | 90 |         break;
 | 
        
           |  |  | 91 | }
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 | redirect($return);
 |