user = $dummysession->user; } /** * Check the request parameters to see which course was specified. */ function process_request() { // Load the requested user $userid = required_param('user', PARAM_INT); if (!$this->user->load_user($userid)) error('User not found.'); // Look for any existing registered avatars $linked_avatar = $this->user->load_linked_avatar(); if ($linked_avatar === true) $this->has_avatar = 1; else if ($linked_avatar === 'multi') $this->has_avatar = 2; // Fetch the Moodle course data $courseid = optional_param('course', SITEID, PARAM_INT); if (!$this->course = sloodle_get_record('course', 'id', $courseid)) error('Could not find course.'); // Moodle 2 rendering functions like to know the course. // They get upset if you try to pass a course into sloodle_print_footer() that isn't what they were expecting. if ($this->course) { global $PAGE; if (isset($PAGE) && method_exists($PAGE, 'set_course')) { $PAGE->set_course($this->course); } } } /** * Check that the user is logged-in and has permission to alter course settings. */ function check_permission() { $system_context = get_context_instance(CONTEXT_SYSTEM); // Only allow admins to do this. if (!has_capability('moodle/user:editprofile', $system_context)) print_error('Only site administrators have access to this page.'); } /** * Process any form data which has been submitted. * This must be overridden to add functionality. */ function process_form() { // Was a form submitted? if (empty($_REQUEST['submit'])) return; // Make sure the correct session key was specified. $form_sesskey = required_param('sesskey', PARAM_RAW); if ($form_sesskey != sesskey()) { $this->msg_error[] = get_string('invalidsesskey', 'sloodle'); $this->add_status = -1; return; } // Grab the avatar data $form_uuid = required_param('sloodleuuid', PARAM_TEXT); $form_avname = required_param('sloodleavname', PARAM_TEXT); // Make sure the given UUID doesn't already exist in the database if (sloodle_count_records('sloodle_users', 'uuid', $form_uuid)) { $this->msg_error[] = get_string('avataruuidalreadyindb', 'sloodle'); $this->add_status = -1; return; } // Register the avatar to the user if ($this->user->add_linked_avatar($this->user->get_user_id(), $form_uuid, $form_avname)) { $this->msg_info[] = get_string('addavatar:success', 'sloodle'); $this->add_status = 1; } else { $this->msg_info[] = get_string('addavatar:fail', 'sloodle'); $this->add_status = -1; } } /** * Print the course settings page header. */ function sloodle_print_header() { global $CFG; // Construct the breadcrumb links $userid = $this->user->get_user_id(); $navigation = ""; if ($this->course->id != SITEID) $navigation .= "wwwroot}/course/view.php?_type=user&id={$this->course->id}\">{$this->course->shortname} -> "; $navigation .= "course->id}\">".get_string('sloodleuserprofiles', 'sloodle') . ' -> '; $navigation .= "course->id}\">".$this->user->get_user_firstname()." ".$this->user->get_user_lastname()." -> "; $navigation .= get_string('addavatar', 'sloodle'); // Display the header sloodle_print_header(get_string('addavatar', 'sloodle'), get_string('addavatar','sloodle'), $navigation, "", "", true); } /** * Render the view of the module or feature. * This MUST be overridden to provide functionality. */ function render() { global $CFG; // Fetch string table text $stravatarname = get_string('avatarname', 'sloodle'); $stravataruuid = get_string('avataruuid', 'sloodle'); $strsubmit = get_string('submit', 'sloodle'); $struser = get_string('user', 'sloodle'); //------------------------------------------------------ // Display any information messages if (count($this->msg_info) > 0) { sloodle_print_box_start('generalbox boxwidthwide boxaligncenter centerpara'); echo "\n"; sloodle_print_box_end(); } // Display any error messages if (count($this->msg_error) > 0) { sloodle_print_box_start('generalbox boxwidthwide boxaligncenter centerpara'); echo "\n"; sloodle_print_box_end(); } // Prepare the form default values $form_default_avname = ''; $form_default_uuid = ''; if ($this->add_status == -1) { $form_default_avname = optional_param('sloodleavname', '', PARAM_TEXT); $form_default_uuid = optional_param('sloodleuuid', '', PARAM_TEXT); } // Display the form $sk = sesskey(); $userid = $this->user->get_user_id(); $userfullname = $this->user->get_user_firstname().' '.$this->user->get_user_lastname(); sloodle_print_box_start('generalbox boxwidthwide boxaligncenter centerpara'); echo "

",get_string('addavatar', 'sloodle'),"

\n"; echo <<
{$struser}: {$userfullname}





ADD_AVATAR_FORM; sloodle_print_box_end(); echo "
\n"; echo "course->id}\"><<< ".get_string('backtoavatarpage','sloodle').""; echo "
\n"; } /** * Print the footer for this course. */ function sloodle_print_footer() { sloodle_print_footer($this->course); } } ?>