$PAGE->set_context($systemcontext);
$PAGE->set_title($title);
$PAGE->set_pagelayout('standard');
$PAGE->set_heading($title);
$config = get_config('local_rtoactivitygradeexport');
if ($config->ismanual == 0) {
    redirect(new moodle_url("/admin/settings.php?section=local_rtoactivitygradeexport_settings"), get_string('isnotmanual', 'local_rtoactivitygradeexport'));
    exit;
}
$form = new local_rtoactivitygradeexport_manual_export_form();
if ($form->is_cancelled()) {
    // Form cancelled?
    redirect(new moodle_url($returnurl));
    exit;
}
if (empty($submitbutton)) {
    echo $OUTPUT->header();
    $form->display();
    echo $OUTPUT->footer();
} else {
    if ($data = $form->get_data()) {
        $config = get_config('local_rtoactivitygradeexport');
        if ($config->ismanual) {
            local_rtoactivitygradeexport_write_csv_to_file('manual', $data);
            redirect(new moodle_url($returnurl), get_string('exportsuccess', 'local_rtoactivitygradeexport'));
        }
    } else {
        redirect(new moodle_url($returnurl), get_string('exporterror', 'local_rtoactivitygradeexport'));
    }
}
exit;
 /**
  * Perform the task
  */
 public function execute()
 {
     local_rtoactivitygradeexport_write_csv_to_file('auto');
 }