<?php

// $Id: enrol.php,v 1.50.2.1 2008/03/03 05:27:36 moodler Exp $
// Depending on the current enrolment method, this page
// presents the user with whatever they need to know when
// they try to enrol in a course.
require_once "../config.php";
require_once "lib.php";
require_once "{$CFG->dirroot}/enrol/enrol.class.php";
if (isloggedin() and !isguest()) {
    if (!iscreator() and !isteacherinanycourse()) {
        redirect($CFG->wwwroot . '/index.php');
    }
} else {
    redirect($CFG->wwwroot . '/index.php');
}
$id = required_param('id', PARAM_INT);
// Masoud Sadjadi: PARAM_ALPHANUM changed to PARAM_RAW to support emails being passed as user names.
// $username     = required_param('username', PARAM_ALPHANUM);
$username = required_param('username', PARAM_RAW);
$loginasguest = optional_param('loginasguest', 0, PARAM_BOOL);
// hmm, is this still needed?
if (!isloggedin()) {
    // do not use require_login here because we are usually comming from it
    redirect(get_login_url());
}
if (!($course = get_record('course', 'id', $id))) {
    print_error("That's an invalid course id");
}
if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) {
    print_error("That's an invalid course id");
function getRoleForWimbaTools($courseId, $userId)
{
    global $CFG;
    global $USER;
    $role = "";
    if (strstr($CFG->release, "1.7")) {
        $context = get_context_instance(CONTEXT_COURSE, $courseId);
    }
    // the role of the current user is switched
    if (isset($USER->studentview) && $USER->studentview == 1 || isset($context) && isset($USER->switchrole) && !empty($USER->switchrole) && $USER->switchrole[$context->id] > 3) {
        $role = 'StudentBis';
    } else {
        if (isstudent($courseId)) {
            // Student
            $role = 'Student';
        } else {
            if (isadmin() || isteacher($courseId, $USER->id)) {
                // Admin, Teacher
                $role = 'Instructor';
            }
        }
        if (strstr($CFG->release, "1.7")) {
            // 1.7.* version
            if (iscreator()) {
                // Course Creator
                $role = 'Instructor';
            } else {
                if (!isteacheredit($courseId)) {
                    // Non-editing Teacher
                    $role = 'Student';
                }
            }
        }
    }
    return $role;
}