if ($importform->save_file('importfile', $pathname)) {
        if (substr($filenameorig, -4) === '.php') {
            $name = mlang_component::name_from_filename($filenameorig);
            $version = mlang_version::by_code($data->version);
            $component = new mlang_component($name, $data->language, $version);
            $parser = mlang_parser_factory::get_parser('php');
            try {
                $parser->parse(file_get_contents($pathname), $component);
            } catch (mlang_parser_exception $e) {
                notice($e->getMessage(), new moodle_url('/local/amos/stage.php'));
            }
            $encomponent = mlang_component::from_snapshot($component->name, 'en', $version);
            $component->intersect($encomponent);
            if (!$component->has_string()) {
                notice(get_string('nostringtoimport', 'local_amos'), new moodle_url('/local/amos/stage.php'));
            }
            $stage = mlang_persistent_stage::instance_for_user($USER->id, sesskey());
            $stage->add($component, true);
            $stage->store();
            mlang_stash::autosave($stage);
        } else {
            notice(get_string('nostringtoimport', 'local_amos'), new moodle_url('/local/amos/stage.php'));
        }
    } else {
        notice(get_string('nofiletoimport', 'local_amos'), new moodle_url('/local/amos/stage.php'));
    }
}
if (!isset($stage) or !$stage->has_component()) {
    notice(get_string('nostringtoimport', 'local_amos'), new moodle_url('/local/amos/stage.php'));
}
redirect(new moodle_url('/local/amos/stage.php'));