function get_sloodle_course() { $course = new SloodleCourse(); if ($course->load($this->courseid)) { return $course; } return null; }
/** * Checks for incoming request data identifying a particular module (parameter 'id'). * Loads the relevant course module and SLOODLE module instances. * This should be overridden to add functionality to load any module-specific data. * However, you can simply call the parent function (i.e. this one) first to load the basic data. */ function process_request() { // Note: some modules prefer 's' to indicate the instance number... may need to implement that as well. // Fetch the course module instance $id = required_param('id', PARAM_INT); if (!($this->cm = get_coursemodule_from_id('sloodle', $id))) { error('Course module ID was incorrect.'); } // Fetch the course data if (!($this->course = get_record('course', 'id', $this->cm->course))) { error('Failed to retrieve course.'); } $this->sloodle_course = new SloodleCourse(); if (!$this->sloodle_course->load($this->course)) { error(get_string('failedcourseload', 'sloodle')); } // Fetch the SLOODLE instance itself if (!($this->sloodle = get_record('sloodle', 'id', $this->cm->instance))) { error('Failed to find SLOODLE module instance'); } }
$stryes = get_string('yes'); $strno = get_string('no'); // Attempt to fetch the course module instance if (!($cm = get_coursemodule_from_id('sloodle', $sloodlecontrollerid))) { error("Failed to load course module"); } // Get the course data if (!($course = get_record("course", "id", $cm->course))) { error("Course is misconfigured"); } // Get the Sloodle instance if (!($sloodle = get_record('sloodle', 'id', $cm->instance))) { error('Failed to find Sloodle module instance.'); } // Get the Sloodle course data $sloodle_course = new SloodleCourse(); if (!$sloodle_course->load($course)) { error(get_string('failedcourseload', 'sloodle')); } if (!$sloodle_course->controller->load($sloodlecontrollerid)) { error('Failed to load Sloodle Controller.'); } // Ensure that the user is logged-in for this course require_course_login($course, true, $cm); // Is the user allowed to edit the module? $module_context = get_context_instance(CONTEXT_MODULE, $cm->id); $course_context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $module_context); // Display the page header //$navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/index.php?id=$course->id\">$strsloodles</a> ->"; $navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?id={$sloodlecontrollerid}\">" . format_string($sloodle->name) . "</a> ->";
/** * Defines *and* returns the content of this block. * @return object */ function get_content() { global $CFG, $COURSE, $USER; // Construct the content $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; // If no course has been specified, then we are using the site course if (!isset($COURSE)) { $COURSE = get_site(); } // If the user is not logged in or if they are using guest access, then we can't show anything if (!isloggedin() || isguest()) { return $this->content; } // Get the context instance for this course $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id); // This version of the menu isn't compatible with older version of the Sloodle module if (defined('SLOODLE_VERSION') && SLOODLE_VERSION < 0.4) { $this->content->text = get_string('oldmodule', 'block_sloodle_menu'); return $this->content; } // Has the Sloodle activity module been installed? if (!(function_exists("sloodle_is_installed") && sloodle_is_installed())) { $this->content->text = get_string('sloodlenotinstalled', 'block_sloodle_menu'); return $this->content; } // Get the Sloodle course data $sloodle_course = new SloodleCourse(); if (!$sloodle_course->load((int) $COURSE->id)) { $this->content->text = get_string('failedloadcourse', 'block_sloodle_menu'); return $this->content; } // Add the Sloodle and Sloodle Menu version info to the footer of the block $this->content->footer = '<span style="color:#565656;font-style:italic; font-size:10pt;">' . get_string('sloodlemenuversion', 'block_sloodle_menu') . ': ' . (string) SLOODLE_MENU_VERSION . '</span>'; $this->content->footer .= '<br/><span style="color:#888888;font-style:italic;font-size:8pt;">' . get_string('sloodleversion', 'block_sloodle_menu') . ': ' . (string) SLOODLE_VERSION . '</span>'; // Attempt to find a Sloodle user for the Moodle user $dbquery = " SELECT * FROM {$CFG->prefix}sloodle_users\n WHERE userid = {$USER->id} AND NOT (avname = '' AND uuid = '')\n "; $dbresult = get_records_sql($dbquery); $sl_avatar_name = ""; if (!is_array($dbresult) || count($dbresult) == 0) { $userresult = FALSE; } else { if (count($dbresult) > 1) { $userresult = "Multiple avatars associated with your Moodle account."; } else { $userresult = TRUE; reset($dbresult); $cur = current($dbresult); $sl_avatar_name = $cur->avname; } } if ($userresult === TRUE) { // Success // Make sure there was a name if (empty($sl_avatar_name)) { $sl_avatar_name = '(' . get_string('nameunknown', 'block_sloodle_menu') . ')'; } $this->content->text .= '<center><span style="font-size:10pt;font-style:italic;color:#777777;">' . get_string('youravatar', 'block_sloodle_menu') . ':</span><br/>'; // Make the avatar name a link if the user management page exists $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=user&id={$USER->id}&course={$COURSE->id}\">{$sl_avatar_name}</a>"; $this->content->text .= '<br/></center>'; } else { if (is_string($userresult)) { // An error occurred $this->content->text .= '<center><span style="font-size:10pt;font-style:italic;color:#777777;">' . get_string('youravatar', 'block_sloodle_menu') . ':</span><br/>ERROR (' . $userresult . ')</center>'; } else { // No avatar linked yet $this->content->text .= '<center><span style="font-style:italic;">(' . get_string('noavatar', 'block_sloodle_menu') . ')</span></center>'; } } // Add links to common Sloodle stuff $this->content->text .= '<div style="padding:1px; margin-top:4px; margin-bottom:4px; border-top:solid 1px #cccccc; border-bottom:solid 1px #cccccc;">'; // Add the Sloodle profile link $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/user.gif\" width=\"16\" height=\"16\"/> "; $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=user&id={$USER->id}&course={$COURSE->id}\">" . get_string('mysloodleprofile', 'block_sloodle_menu') . "</a><br/>"; // Show a link to all Sloodle activities on this course //TODO: possibly show number of visible Sloodle activities? $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/boxes.gif\" width=\"16\" height=\"16\"/> "; $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/index.php?id={$COURSE->id}\">" . get_string('sloodleactivities', 'block_sloodle_menu') . "</a><br/>"; // Do we have LoginZone data for this course? if ($sloodle_course->has_loginzone_data()) { // Show a link to the LoginZone for this course $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/loginzone.gif\" width=\"16\" height=\"16\"/> "; $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/classroom/loginzone.php?id={$COURSE->id}\">" . get_string('courseloginzone', 'block_sloodle_menu') . "</a><br/>"; } //$this->content->text .= '<hr>'; // Add a link for avatars list $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/user_mng.gif\" width=\"16\" height=\"16\"/> "; $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=users&course={$COURSE->id}\">" . get_string('avatars', 'block_sloodle_menu') . "</a><br/>"; // Add a link to Sloodle course settings, if the user can update the course if (has_capability('moodle/course:update', $course_context)) { $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/page.gif\" width=\"16\" height=\"16\"/> "; $this->content->text .= "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=course&id={$COURSE->id}\">" . get_string('editcourse', 'block_sloodle_menu') . "</a><br>\n"; } // Add a module configuration link if the user has authority to administer the module if (has_capability('moodle/site:config', $course_context)) { // The address of the configuration page depends on our version of Moodle if ($CFG->version < 2007101500) { // < 1.9 $address = "/admin/module.php?module=sloodle"; } else { // >= 1.9 $address = "/admin/settings.php?section=modsettingsloodle"; } $this->content->text .= "<img src=\"{$CFG->wwwroot}/blocks/sloodle_menu/img/configure.gif\" width=\"16\" height=\"16\"/> "; $this->content->text .= "<a href=\"{$CFG->wwwroot}{$address}\">" . get_string('sloodleconfig', 'block_sloodle_menu') . "</a><br/>"; } $this->content->text .= '</div>'; return $this->content; }
/** * Gets a numeric array of {@link SloodleCourse} objects for courses the user is Sloodle staff. * This relates to the "mod/sloodle:staff" capability. * WARNING: this function is not very efficient, and will likely be very slow on large sites. * @param mixed $category Unique identifier of a category to limit the query to. Ignored if null. (Type depends on VLE; integer for Moodle) * @return array A numeric array of {@link SloodleCourse} objects * @access public */ function get_staff_courses($category = null) { // Make sure we have user data if (empty($this->user_data)) { return array(); } // Convert the category ID as appropriate if ($category == null || $category < 0 || !is_int($category)) { $category = 0; } // Modified from "get_user_capability_course()" in Moodle's "lib/accesslib.php" // Get a list of all courses on the system $usercourses = array(); $courses = get_courses($category); // Go through each course foreach ($courses as $course) { // Check if the user can teach using Sloodle on this course if (has_capability('mod/sloodle:staff', get_context_instance(CONTEXT_COURSE, $course->id), $this->user_data->id)) { $sc = new SloodleCourse(); $sc->load($course); $usercourses[] = $sc; } } return $usercourses; }
* */ /** Sloodle/Moodle configuration script. */ require_once 'sl_config.php'; /** Sloodle core library functionality */ require_once SLOODLE_DIRROOT . '/lib.php'; /** General Sloodle functions. */ require_once SLOODLE_LIBROOT . '/general.php'; /** Sloodle course data. */ require_once SLOODLE_LIBROOT . '/course.php'; require_once SLOODLE_LIBROOT . '/layout_profile.php'; // Get the Sloodle course data $courseid = required_param('courseid', PARAM_INT); $layoutid = optional_param('layoutid', -1, PARAM_INT); // 0 to add a layout, -1 just to display $sloodle_course = new SloodleCourse(); if (!$sloodle_course->load($courseid)) { error(get_string('failedcourseload', 'sloodle')); } // Ensure that the user is logged-in to this course require_login($courseid); $course_context = get_context_instance(CONTEXT_COURSE, $courseid); // Do not allow guest access if (isguestuser()) { error(get_string('noguestaccess', 'sloodle')); exit; } // Make sure the user is logged-in and is not a guest if (isloggedin() == false || isguestuser() == true) { error(get_string('noguestaccess', 'sloodle')); exit;
/** * Validates the user account and enrolment (ensures there is an avatar linked to a VLE account, and that the VLE account is enrolled in the current course). * Attempts auto-registration/enrolment if that is allowed and required, and logs-in the user. * Server access level is checked if it is specified in the request parameters. * If the request indicates that it relates to an object, then the validation fails. * Note: if you only require to ensure that an avatar is registered, then use {@link validate_avatar()}. * @param bool $require If true, the script will be terminated with an error message if validation fails * @param bool $suppress_autoreg If true, auto-registration will be completely suppressed for this function call * @param bool $suppress_autoenrol If true, auto-enrolment will be completely suppressed for this function call * @return bool Returns true if validation and/or autoregistration were successful. Returns false on failure (unless $require was true). * @see SloodleSession::validate_avatar() */ function validate_user($require = true, $suppress_autoreg = false, $suppress_autoenrol = false) { // Is it an object request? if ($this->request->is_object_request()) { if ($require) { $this->response->quick_output(-301, 'USER_AUTH', 'Cannot validate object as user.', false); exit; } return false; } // Was a server access level specified in the request? $sal = $this->request->get_server_access_level(false); if ($sal != null) { // Check what level was specified $sal = (int) $sal; $allowed = false; $reason = 'Unknown.'; switch ($sal) { case SLOODLE_SERVER_ACCESS_LEVEL_PUBLIC: // Always allowed $allowed = true; break; case SLOODLE_SERVER_ACCESS_LEVEL_COURSE: // Is a course already loaded? if (!$this->course->is_loaded()) { $reason = 'No course loaded.'; break; } // Was a user account already fully loaded? if ($this->user->is_avatar_linked()) { // Is the user enrolled on the current course? if ($this->user->is_enrolled($this->course->get_course_id())) { $allowed = true; } else { $reason = 'User not enrolled in course.'; } } else { $reason = 'User not registered on site.'; } break; case SLOODLE_SERVER_ACCESS_LEVEL_SITE: // Was a user account already fully loaded? if ($this->user->is_avatar_linked()) { $allowed = true; } else { $reason = 'User not registered on site.'; } break; case SLOODLE_SERVER_ACCESS_LEVEL_STAFF: // Is a course already loaded? if (!$this->course->is_loaded()) { $reason = 'No course loaded.'; break; } // Was a user account already fully loaded? if ($this->user->is_avatar_linked()) { // Is the user staff on the current course? if ($this->user->is_staff($this->course->get_course_id())) { $allowed = true; } else { $reason = 'User not staff in course.'; } } else { $reason = 'User not registered on site.'; } break; default: // Unknown access level $reason = 'Access level not recognised'; break; } // Was the user blocked by access level? if (!$allowed) { if ($require) { $this->response->quick_output(-331, 'USER_AUTH', $reason, false); exit; } return false; } } // REGISTRATION // // Make sure a the course is loaded if (!$this->course->is_loaded()) { if ($require) { $this->response->quick_output(-511, 'COURSE', 'Cannot validate user - no course data loaded.', false); exit; } return false; } // Is the user already loaded? if (!$this->user->is_avatar_linked()) { // If an avatar is loaded, but the user isn't, then we probably have a deleted Moodle user if ($this->user->is_avatar_loaded() == true && $this->user->is_user_loaded() == false) { $this->response->quick_output(-301, 'USER_AUTH', 'Avatar linked to deleted user account', false); exit; } // Make sure avatar details were provided $uuid = $this->request->get_avatar_uuid(false); $avname = $this->request->get_avatar_name(false); // Is validation required? if ($require) { // Check the UUID if (empty($uuid)) { $this->response->quick_output(-311, 'USER_AUTH', 'User UUID required', false); exit; } // Check the name if (empty($avname)) { $this->response->quick_output(-311, 'USER_AUTH', 'Avatar name required', false); exit; } } else { if (empty($uuid) || empty($avname)) { // If there was a problem, just stop return false; } } // Ensure autoreg is not suppressed, and that it is permitted on that course and on the site if ($suppress_autoreg == true || $this->course->check_autoreg() == false) { if ($require) { $this->response->quick_output(-321, 'USER_AUTH', 'User not registered, and auto-registration of users was not permitted', false); exit; } return false; } // It is important that we also check auto-enrolment here. // If that is not enabled, but the call here requires it, then there is no point registering the user. if ($suppress_autoenrol == true || $this->course->check_autoenrol() == false) { if ($require) { $this->response->quick_output(-421, 'USER_ENROL', 'User not enrolled, and auto-enrolment of users was not permitted', false); exit; } return false; } // Is there an avatar loaded? if (!$this->user->is_avatar_loaded()) { // Add the avatar details, linked to imaginary user 0 if (!$this->user->add_linked_avatar(0, $uuid, $avname)) { if ($require) { $this->response->quick_output(-322, 'USER_AUTH', 'Failed to add new avatar', false); exit; } return false; } } // If we reached here then we definitely have an avatar // Create a matching Moodle user $password = $this->user->autoregister_avatar_user(); if ($password === FALSE) { if ($require) { $this->response->quick_output(-322, 'USER_AUTH', 'Failed to register new user account', false); exit; } return false; } // Add a side effect code to our response data $this->response->add_side_effect(322); // The user needs to be notified of their new username/password if (isset($_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY'])) { sloodle_login_notification($_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY'], $uuid, $this->user->get_username(), $password); } } // ENROLMENT // // Is the user already enrolled on the course? if (!$this->user->is_enrolled($this->course->get_course_id())) { // Ensure auto-enrolment is not suppressed, and that it is permitted on that course and on the site if ($suppress_autoenrol == true || $this->course->check_autoenrol() == false) { if ($require) { $this->response->quick_output(-421, 'USER_ENROL', 'Auto-enrolment of users was not permitted', false); exit; } return false; } // Attempt to enrol the user if (!$this->user->enrol()) { if ($require) { $this->response->quick_output(-422, 'USER_ENROL', 'Auto-enrolment failed', false); exit; } return false; } // Add a side effect code to our response data $this->response->add_side_effect(422); } // Make sure the user is logged-in return $this->user->login(); }
require_once '../sl_config.php'; /** Main Sloodle API. */ require_once SLOODLE_LIBROOT . '/sloodle_session.php'; // Fetch our request parameters $id = optional_param('id', 0, PARAM_INT); // Course Module instance ID // Attempt to fetch the course module instance if ($id) { if (!($course = get_record('course', 'id', $id))) { error('Could not find course'); } } else { error('Must specify a course ID'); } // Get the Sloodle course data $sloodle_course = new SloodleCourse(); if (!$sloodle_course->load($course)) { error(get_string('failedcourseload', 'sloodle')); } // Ensure that the user is logged-in to this course require_login($course->id); $course_context = get_context_instance(CONTEXT_COURSE, $course->id); // Do not allow guest access if (isguestuser()) { error(get_string('noguestaccess', 'sloodle')); exit; } // This is really a dummy Sloodle Session $sloodle = new SloodleSession(false); $sloodle->user->load_user($USER->id); $has_avatar = $sloodle->user->load_linked_avatar();
$stryes = get_string('yes'); $strno = get_string('no'); // Attempt to fetch the course module instance if (!($cm = get_coursemodule_from_id('sloodle', $sloodlecontrollerid))) { error("Failed to load course module"); } // Get the course data if (!($course = get_record("course", "id", $cm->course))) { error("Course is misconfigured"); } // Get the Sloodle instance if (!($sloodle = get_record('sloodle', 'id', $cm->instance))) { error('Failed to find Sloodle module instance.'); } // Get the Sloodle course data $sloodle_course = new SloodleCourse(); if (!$sloodle_course->load($course)) { error(get_string('failedcourseload', 'sloodle')); } if (!$sloodle_course->controller->load($sloodlecontrollerid)) { error('Failed to load Controller data'); } // Ensure that the user is logged-in for this course require_course_login($course, true, $cm); // Is the user allowed to edit the module? $module_context = get_context_instance(CONTEXT_MODULE, $cm->id); $course_context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $module_context); // Display the page header //$navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/index.php?id=$course->id\">$strsloodles</a> ->"; $navigation = "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?id={$sloodlecontrollerid}\">" . format_string($sloodle->name) . "</a> ->";