示例#1
0
/** Lets Sloodle know we are in a linker script. */
define('SLOODLE_LINKER_SCRIPT', true);
/** Grab the Sloodle/Moodle configuration. */
require_once '../../sl_config.php';
/** Include the Sloodle PHP API. */
require_once SLOODLE_LIBROOT . '/sloodle_session.php';
// Authenticate the request, and load a chat module
$sloodle = new SloodleSession();
$sloodle->authenticate_request();
$sloodle->load_module('chat', true);
// Attempt to validate the user
// (this will auto-register/enrol users where necessary and allowed)
// If server access level is public, then validation is not essential... otherwise, it is
$sloodleserveraccesslevel = $sloodle->request->get_server_access_level(false);
if ($sloodleserveraccesslevel == 0) {
    $sloodle->validate_user(false);
} else {
    $sloodle->validate_user(true);
}
// Has an incoming message been provided?
$message = sloodle_clean_for_db($sloodle->request->optional_param('message', null));
if ($message != null) {
    // Add it to the chatroom.
    if (!$sloodle->module->add_message($message)) {
        add_to_log($sloodle->course->get_course_id(), 'sloodle', 'add message', '', 'Added chat message to chatroom', $sloodle->request->get_module_id());
    } else {
        add_to_log($sloodle->course->get_course_id(), 'sloodle', 'add message', '', 'Failed to add chat message to chatroom', $sloodle->request->get_module_id());
    }
}
// Start preparing the response
$sloodle->response->set_status_code(1);
 *  sloodleadd = if 'true', then the given entries are added to the layout instead of replacing them
 * 
 *
 * The format for the "sloodlelayoutentries" parameter should be the same as the response from the query mode.
 * Due to the potentially large quantity of information this type of query may generate, it is advisable to use POST instead of GET.
 */
/** Lets Sloodle know we are in a linker script. */
define('SLOODLE_LINKER_SCRIPT', true);
/** Grab the Sloodle/Moodle configuration. */
require_once '../../sl_config.php';
/** Include the Sloodle PHP API. */
require_once SLOODLE_LIBROOT . '/sloodle_session.php';
// Authenticate the request and user, but do not allow auto-registration and enrolment
$sloodle = new SloodleSession();
$sloodle->authenticate_request();
$sloodle->validate_user(true, true, true);
// We need to check certain capabilities
$can_use_layouts = false;
$can_edit_layouts = false;
///// MOODLE-SPECIFIC /////
$course_context = get_context_instance(CONTEXT_COURSE, $sloodle->course->get_course_id());
$can_use_layouts = has_capability('mod/sloodle:uselayouts', $course_context);
$can_edit_layouts = has_capability('mod/sloodle:editlayouts', $course_context);
///// END MOODLE-SPECIFIC /////
// If the user cannot use layouts at all, then we cannot do anything
if (!$can_use_layouts) {
    $sloodle->response->quick_output(-301, 'USER_AUTH', 'User does not have permission to use layout profiles.', false);
    exit;
}
// Get the optional parameters
$sloodlelayoutname = $sloodle->request->optional_param('sloodlelayoutname');
示例#3
0
// There are two types of authentication - prim password, and object-specific password.
// In both cases, a SLOODLE Controller must be identified in the "sloodlecontrollerid" HTTP parameter, and the password in the "sloodlepwd" HTTP parameter.
// A prim-password is just a 5 to 9 digit number, and it is the same for any object using the Controller.
// An object-specific password is a 9-digit number PLUS the object's UUID, and it is unique for every object.
// * See the SLOODLE PHP API documentation for more information about the "SloodleSession" class *
///// HANDLING THE USER /////
// Many requests either deal with or are originated by a particular avatar.
// For example, the WebIntercom needs to know who is chatting a message.
// This information is passed-in using two parameters: sloodleavname, sloodleuuid.
// It is good practice to provide both in your script, but just one will usually suffice (unless you want to auto-register a new avatar).
// You can use the following method to check that an avatar has been specified.
// This will also check to see if they are registered in Moodle, and enrolled on the course.
// If it fails, it will normally terminate the script with an error, but you can suppress that using optional parameters.
// Note that this function will auto-register and/or auto-enrol avatars if necessary and if the Moodle site/course allow it.
// An important side-effect of this function is that it forces Moodle to think the registered Moodle user is actually logged-in for the duration of this script.
$sloodle->validate_user();
// At this stage, you are guaranteed to have a valid avatar AND Moodle user.
// You can now access the user information like this: $sloodle->user->...
// For example, let's get the names of the avatar and Moodle user.
$avatarname = $sloodle->user->get_avatar_name();
$moodlename = $sloodle->user->get_user_firstname() . ' ' . $sloodle->user->get_user_lastname();
// * See the SLOODLE PHP API documentation for more information about the SloodleUser class. *
// SloodleUser is defined in: sloodle/lib/user.php
///// LOADING MODULES /////
// In order to improve portability and code-reusability, a modules system was created.
// It is not essential, but can help keep linker scripts clean and free of Moodle-specific database code.
// The SloodleModule base class provides a common base for any SLOODLE code which 'wraps' a Moodle module.
// For example, the SloodleModuleChat class provides simple functions to handle a Moodle chatroom.
// Similarly, the SloodleModuleBlog class provides simple functions to handle the Moodle blog.
// Note that these will NOT necessarily correspond to actual Moodle modules (although they usually do).
// The following method can be used to load a module wrapper for a chatroom.
 * If successful, the status code returned will be 1 and the data line will contain a URL to forward the user to.
 * If nothing needs done because the user is already registered, then status code 301 is returned.
 * If nothing needs done because the user is already enrolled, then status code 401 is returned.
 * If the user cannot be enrolled because they are not yet registered, then status code -321.
 */
/** Lets Sloodle know we are in a linker script. */
define('SLOODLE_LINKER_SCRIPT', true);
/** Grab the Sloodle/Moodle configuration. */
require_once '../sl_config.php';
/** Include the Sloodle PHP API. */
require_once SLOODLE_LIBROOT . '/sloodle_session.php';
// Authenticate the request
$sloodle = new SloodleSession();
$sloodle->authenticate_request();
// Attempt to authenticate the user, but do not allow auto-registration/enrolment
$sloodle->validate_user(false, true, true);
$is_registered = $sloodle->user->is_user_loaded();
$is_enrolled = false;
if ($is_registered) {
    $is_enrolled = $sloodle->user->is_enrolled($sloodle->course->get_course_id());
}
// Make sure UUID and avatar name were specified
$sloodleuuid = $sloodle->request->get_avatar_uuid(TRUE);
$sloodleavname = $sloodle->request->get_avatar_name(TRUE);
// Get the mode value
$sloodlemode = $sloodle->request->required_param('sloodlemode');
// If the mode is 'regenrol', but the user is already registered,
//  then just do enrolment
if ($sloodlemode == 'regenrol' && $is_registered) {
    $sloodlemode = 'enrol';
}