. /** * Import attendance sessions. * * @package mod_attendance * @author Chris Wharton * @copyright 2017 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('NO_OUTPUT_BUFFERING', true); require_once(__DIR__ . '/../../../config.php'); require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->dirroot . '/mod/attendance/lib.php'); require_once($CFG->dirroot . '/mod/attendance/locallib.php'); admin_externalpage_setup('managemodules'); $pagetitle = get_string('importsessions', 'attendance'); $context = context_system::instance(); $url = new moodle_url('/mod/attendance/import/sessions.php'); $PAGE->set_context($context); $PAGE->set_url($url); $PAGE->set_title($pagetitle); $PAGE->set_pagelayout('admin'); $PAGE->set_heading($pagetitle); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('importsessions', 'attendance')); $tabmenu = attendance_print_settings_tabs('importsessions'); echo $tabmenu; $form = null; if (optional_param('needsconfirm', 0, PARAM_BOOL)) { $form = new \mod_attendance\form\import\sessions($url->out(false)); } else if (optional_param('confirm', 0, PARAM_BOOL)) { $importer = new \mod_attendance\import\sessions(); $form = new \mod_attendance\form\import\sessions_confirm(null, $importer); } else { $form = new \mod_attendance\form\import\sessions($url->out(false)); } if ($form->is_cancelled()) { $form = new \mod_attendance\form\import\sessions($url->out(false)); } else if ($data = $form->get_data()) { require_sesskey(); if ($data->confirm) { $importid = $data->importid; $importer = new \mod_attendance\import\sessions(null, null, null, $importid, $data, true); $error = $importer->get_error(); if ($error) { $form = new \mod_attendance\form\import\sessions($url->out(false)); $form->set_import_error($error); } else { $sessions = $importer->import(); mod_attendance_notifyqueue::show(); echo $OUTPUT->continue_button($url); die(); } } else { $text = $form->get_file_content('importfile'); $encoding = $data->encoding; $delimiter = $data->delimiter_name; $importer = new \mod_attendance\import\sessions($text, $encoding, $delimiter, 0, null, true); $confirmform = new \mod_attendance\form\import\sessions_confirm(null, $importer); $form = $confirmform; $pagetitle = get_string('confirmcolumnmappings', 'attendance'); } } echo $OUTPUT->heading($pagetitle); $form->display(); echo $OUTPUT->footer();