<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Import / Export settings.
 *
 * @package    theme_oficial
 * @copyright  &copy; 2018 G J Barnard.
 * @author     G J Barnard - {@link http://moodle.org/user/profile.php?id=442195}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') || die;

$oficialsettingsprops = new admin_settingpage('theme_oficial_importexport', get_string('properties', 'theme_oficial'));
if ($ADMIN->fulltree) {
    if (file_exists("{$CFG->dirroot}/theme/oficial/settings/oficial_admin_setting_getprops.php")) {
        require_once($CFG->dirroot . '/theme/oficial/settings/oficial_admin_setting_getprops.php');
        require_once($CFG->dirroot . '/theme/oficial/settings/oficial_admin_setting_putprops.php');
    } else if (!empty($CFG->themedir) && file_exists("{$CFG->themedir}/oficial/settings/oficial_admin_setting_getprops.php")) {
        require_once($CFG->themedir . '/oficial/settings/oficial_admin_setting_getprops.php');
        require_once($CFG->themedir . '/oficial/settings/oficial_admin_setting_putprops.php');
    }

    $oficialsettingsprops->add(new admin_setting_heading('theme_oficial_importexport',
        get_string('propertiessub', 'theme_oficial'),
        format_text(get_string('propertiesdesc', 'theme_oficial'), FORMAT_MARKDOWN)));

    $oficialexportprops = optional_param('theme_oficial_getprops_saveprops', 0, PARAM_INT);
    $oficialprops = \theme_oficial\toolbox::compile_properties('oficial');
    $oficialsettingsprops->add(new oficial_admin_setting_getprops('theme_oficial_getprops',
        get_string('propertiesproperty', 'theme_oficial'),
        get_string('propertiesvalue', 'theme_oficial'),
        $oficialprops,
        'theme_oficial_importexport',
        get_string('propertiesreturn', 'theme_oficial'),
        get_string('propertiesexport', 'theme_oficial'),
        $oficialexportprops
    ));

    // Import theme settings section (put properties).
    $name = 'theme_oficial/theme_oficial_putprops_import_heading';
    $heading = get_string('putpropertiesheading', 'theme_oficial');
    $setting = new admin_setting_heading($name, $heading, '');
    $oficialsettingsprops->add($setting);

    $setting = new oficial_admin_setting_putprops('theme_oficial_putprops',
        get_string('putpropertiesname', 'theme_oficial'),
        get_string('putpropertiesdesc', 'theme_oficial'),
        'oficial',
        '\theme_oficial\toolbox::put_properties'
    );
    $setting->set_updatedcallback('purge_all_caches');
    $oficialsettingsprops->add($setting);
}
$ADMIN->add('theme_oficial', $oficialsettingsprops);
