| 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 |  * TinyMCE Premium plugins configuration page.
 | 
        
           |  |  | 19 |  *
 | 
        
           |  |  | 20 |  * @package    tiny_premium
 | 
        
           |  |  | 21 |  * @copyright  2024 David Woloszyn <david.woloszyn@moodle.com>
 | 
        
           |  |  | 22 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 23 |  */
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | require_once(__DIR__ . '/../../../../../config.php');
 | 
        
           |  |  | 26 | require_once($CFG->libdir.'/adminlib.php');
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 | $action = required_param('action', PARAM_ALPHANUMEXT);
 | 
        
           |  |  | 29 | $plugin = required_param('plugin', PARAM_ALPHANUMEXT);
 | 
        
           |  |  | 30 |   | 
        
           |  |  | 31 | $syscontext = context_system::instance();
 | 
        
           |  |  | 32 | $PAGE->set_url('/lib/editor/tiny/plugins/premium/pluginsettings.php');
 | 
        
           |  |  | 33 | $PAGE->set_context($syscontext);
 | 
        
           |  |  | 34 |   | 
        
           |  |  | 35 | require_admin();
 | 
        
           |  |  | 36 | require_sesskey();
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 | $return = new moodle_url('/admin/settings.php', ['section' => 'tiny_premium_settings']);
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 | // Get all Tiny Premium plugins.
 | 
        
           |  |  | 41 | $premiumplugins = \tiny_premium\manager::get_plugins();
 | 
        
           |  |  | 42 | if (!in_array($plugin, $premiumplugins)) {
 | 
        
           |  |  | 43 |     throw new moodle_exception('pluginnotfound', 'tiny_premium', $return, $plugin);
 | 
        
           |  |  | 44 | }
 | 
        
           |  |  | 45 |   | 
        
           |  |  | 46 | // Get enabled Tiny Premium plugins.
 | 
        
           |  |  | 47 | $enabledplugins = \tiny_premium\manager::get_enabled_plugins();
 | 
        
           |  |  | 48 | $pluginname = get_string('premiumplugin:' . $plugin, 'tiny_premium');
 | 
        
           |  |  | 49 |   | 
        
           |  |  | 50 | switch ($action) {
 | 
        
           |  |  | 51 |     case 'disable':
 | 
        
           |  |  | 52 |         if (in_array($plugin, $enabledplugins)) {
 | 
        
           |  |  | 53 |             \tiny_premium\manager::set_plugin_config(['enabled' => 0], $plugin);
 | 
        
           |  |  | 54 |   | 
        
           |  |  | 55 |             \core\notification::add(
 | 
        
           |  |  | 56 |                 get_string('plugin_disabled', 'core_admin', $pluginname),
 | 
        
           |  |  | 57 |                 \core\notification::SUCCESS
 | 
        
           |  |  | 58 |             );
 | 
        
           |  |  | 59 |         }
 | 
        
           |  |  | 60 |         break;
 | 
        
           |  |  | 61 |   | 
        
           |  |  | 62 |     case 'enable':
 | 
        
           |  |  | 63 |         if (!in_array($plugin, $enabledplugins)) {
 | 
        
           |  |  | 64 |             \tiny_premium\manager::set_plugin_config(['enabled' => 1], $plugin);
 | 
        
           |  |  | 65 |   | 
        
           |  |  | 66 |             \core\notification::add(
 | 
        
           |  |  | 67 |                 get_string('plugin_enabled', 'core_admin', $pluginname),
 | 
        
           |  |  | 68 |                 \core\notification::SUCCESS
 | 
        
           |  |  | 69 |             );
 | 
        
           |  |  | 70 |         }
 | 
        
           |  |  | 71 |         break;
 | 
        
           |  |  | 72 | }
 | 
        
           |  |  | 73 |   | 
        
           |  |  | 74 | redirect($return);
 |