* saves them in the report's plugin config. 
     * 
     * @param $data
     */
    public function process($data)
    {
        $data->roles = serialize($data->roles);
        $data->categories = serialize($data->categories);
        foreach ($data as $field => $value) {
            set_config($field, $value, 'report_targetgrades');
        }
    }
}
list($in_sql, $params) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles));
$customdata = array('fields' => array('', 'shortname' => get_string('shortname'), 'fullname' => get_string('fullname'), 'idnumber' => get_string('idnumber')), 'roles' => $DB->get_records_select_menu('role', 'id ' . $in_sql, $params), 'categories' => $DB->get_records_menu('course_categories'), 'userfields' => $DB->get_records_menu('user_info_field', null, '', 'id, name'));
if (empty($customdata['userfields'])) {
    throw new moodle_exception('err_nouserfields', 'report_targetgrades', new moodle_url('/user/profile/index.php'));
}
$form = new report_targetgrades_settingsform(null, $customdata);
if ($config = tg\get_config()) {
    $form->set_data($config);
}
if ($data = $form->get_data()) {
    $form->process($data);
    redirect(new moodle_url('/admin/report/targetgrades'), get_string('settingssaved', 'report_targetgrades'), 3);
    exit;
}
echo $OUTPUT->header();
echo tg\print_tabs(3);
$form->display();
echo $OUTPUT->footer();
 * @author      Mark Johnson <*****@*****.**>
 * @copyright   2011 Tauntons College, UK
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../../config.php';
require_once $CFG->dirroot . '/' . $CFG->admin . '/report/targetgrades/alisdata_form.php';
require_once $CFG->dirroot . '/' . $CFG->admin . '/report/targetgrades/lib.php';
require_once $CFG->libdir . '/adminlib.php';
use report\targetgrades as tg;
require_login($SITE);
admin_externalpage_setup('reporttargetgrades', null, null, '/' . $CFG->admin . '/report/targetgrades/alisdata.php');
$PAGE->navbar->add(get_string('alisdata', 'report_targetgrades'));
$savepatterns = optional_param('savepatterns', false, PARAM_BOOL);
$alispatterns = optional_param('alispatterns', array(), PARAM_CLEAN);
$addpattern = optional_param('addpattern', array(), PARAM_CLEAN);
$config = tg\get_config('report_targetgrades');
$addfield = optional_param('addfield', null, PARAM_INT);
if ($savepatterns || !empty($addpattern)) {
    foreach ($alispatterns as $alisid => $patterns) {
        foreach ($patterns as $id => $pattern) {
            if ($alisdata = $DB->get_record('report_targetgrades_alisdata', array('id' => $alisid))) {
                if ($patternrecord = $DB->get_record('report_targetgrades_patterns', array('id' => $id))) {
                    if (empty($pattern)) {
                        $DB->delete_records('report_targetgrades_patterns', array('id' => $id));
                    } else {
                        $patternrecord->pattern = $pattern;
                        $DB->update_record('report_targetgrades_patterns', $patternrecord);
                    }
                } else {
                    if (!empty($pattern)) {
                        $patternrecord = new stdClass();
require_once $CFG->dirroot . '/user/selector/lib.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->dirroot . '/' . $CFG->admin . '/report/targetgrades/lib.php';
use report\targetgrades as tg;
require_login($SITE);
admin_externalpage_setup('reporttargetgrades', null, null, '/' . $CFG->admin . '/report/targetgrades/distribute.php');
$PAGE->navbar->add(get_string('mtgdistribute', 'report_targetgrades'));
$context = get_context_instance(CONTEXT_SYSTEM);
if (!has_capability('report/targetgrades:distribute', $context)) {
    print_error('noperms', 'report_targetgrades');
}
$defaultscale = optional_param('defaultscale', null, PARAM_INT);
if (!empty($defaultscale)) {
    set_config('defaultscale', $defaultscale, 'report_targetgrades');
}
$config = tg\get_config();
// Get the raw config data for the block
if (preg_match('/(.+?\\.?[*+].*?)[*+]/', $config->exclude_regex)) {
    print_error('unsaferegex', 'report_targetgrades');
}
$potential_selector = new tg\potential_course_selector('potentialcourses');
$distributed_selector = new tg\distributed_course_selector('distributedcourses');
$potential_selector->exclude(array_keys(current($distributed_selector->find_users())));
$courses = array();
if (optional_param('calculate', false, PARAM_TEXT)) {
    $courses = $potential_selector->get_selected_users();
} else {
    if (optional_param('recalculate', false, PARAM_TEXT)) {
        $courses = current($distributed_selector->find_users());
    }
}