function game_showusers($game) { global $CFG, $USER, $DB; $users = array(); $context = get_context_instance(CONTEXT_COURSE, $game->course); $groupid = optional_param('groupid', 0, PARAM_INT); $sql = "SELECT DISTINCT ra.userid,u.lastname,u.firstname FROM {role_assignments} ra, {user} u " . " WHERE ra.contextid={$context->id} AND ra.userid=u.id"; if ($groupid != 0) { $sql .= " AND ra.userid IN (SELECT gm.userid FROM {groups_members} gm WHERE gm.groupid={$groupid})"; } if ($recs = $DB->get_records_sql($sql)) { foreach ($recs as $rec) { $users[$rec->userid] = $rec->lastname . ' ' . $rec->firstname; } } if ($guest = guest_user()) { $users[$guest->id] = fullname($guest); } ?> <script type="text/javascript"> function onselectuser() { window.location.href = "<?php echo $CFG->wwwroot . '/mod/game/showattempts.php?q=' . $game->id . '&userid='; ?> " + document.getElementById('menuuser').value + '&groupid=' + document.getElementById('menugroup').value; } </script> <?php $attributes = 'onchange="javascript:onselectuser();"'; $name = 'user'; $id = 'menu' . $name; $class = 'menu' . $name; $class = 'select ' . $class; /// Add 'select' selector always $nothing = get_string("allparticipants"); $nothingvalue = '0'; $options = $users; $selected = optional_param('userid', 0, PARAM_INT); $output = '<select id="' . $id . '" class="' . $class . '" name="' . $name . '" ' . $attributes . '>' . "\n"; $output .= ' <option value="' . s($nothingvalue) . '"' . "\n"; if ($nothingvalue === $selected) { $output .= ' selected="selected"'; } $output .= '>' . $nothing . '</option>' . "\n"; if (!empty($options)) { foreach ($options as $value => $label) { $output .= ' <option value="' . s($value) . '"'; if ((string) $value == (string) $selected || is_array($selected) && in_array($value, $selected)) { $output .= ' selected="selected"'; } if ($label === '') { $output .= '>' . $value . '</option>' . "\n"; } else { $output .= '>' . $label . '</option>' . "\n"; } } } echo $output . '</select>' . "\n"; }
function game_showusers($game) { global $CFG, $USER; $users = array(); $context = get_context_instance(CONTEXT_COURSE, $game->course); if ($courseusers = get_enrolled_users($context)) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } if ($guest = guest_user()) { $users[$guest->id] = fullname($guest); } ?> <script type="text/javascript"> function onselectuser() { window.location.href = "<?php echo $CFG->wwwroot . '/mod/game/showanswers.php?q=' . $game->id . '&userid='; ?> " + document.getElementById('menuuser').value; } </script> <?php //choose_from_menu($users, 'user', $USER->id, get_string("allparticipants"), 'javascript:onselectuser();'); //function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', // $nothingvalue='0', $return=false, $disabled=false, $tabindex=0, // $id='', $listbox=false, $multiple=false, $class='') $attributes = 'onchange="javascript:onselectuser();"'; $name = 'user'; $id = 'menu' . $name; $class = 'menu' . $name; $class = 'select ' . $class; /// Add 'select' selector always $nothing = get_string("allparticipants"); $nothingvalue = '0'; $options = $users; $selected = optional_param('userid', $USER->id, PARAM_INT); $output = '<select id="' . $id . '" class="' . $class . '" name="' . $name . '" ' . $attributes . '>' . "\n"; $output .= ' <option value="' . s($nothingvalue) . '"' . "\n"; if ($nothingvalue === $selected) { $output .= ' selected="selected"'; } $output .= '>' . $nothing . '</option>' . "\n"; if (!empty($options)) { foreach ($options as $value => $label) { $output .= ' <option value="' . s($value) . '"'; if ((string) $value == (string) $selected || is_array($selected) && in_array($value, $selected)) { $output .= ' selected="selected"'; } if ($label === '') { $output .= '>' . $value . '</option>' . "\n"; } else { $output .= '>' . $label . '</option>' . "\n"; } } } echo $output . '</select>' . "\n"; }
/** * This function returns the URL for the RSS XML file. * * @param int $contextid the course id * @param int $userid the current user id * @param string $componentname the name of the current component. For example "forum" * @param string $additionalargs For modules, module instance id * @return string the url of the RSS feed */ function rss_get_url($contextid, $userid, $componentname, $additionalargs) { global $CFG; if (empty($userid)) { $userid = guest_user()->id; } $usertoken = rss_get_token($userid); $url = '/rss/file.php'; return moodle_url::make_file_url($url, '/' . $contextid . '/' . $usertoken . '/' . $componentname . '/' . $additionalargs . '/rss.xml'); }
/** * This function returns the URL for the RSS XML file. * * @param int $contextid the course id * @param int $userid the current user id * @param string $componentname the name of the current component. For example "forum" * @param string $additionalargs For modules, module instance id * @return string the url of the RSS feed */ function rss_get_url($contextid, $userid, $componentname, $additionalargs) { global $CFG; require_once $CFG->libdir . '/filelib.php'; if (empty($userid)) { $userid = guest_user()->id; } $usertoken = rss_get_token($userid); return get_file_url($contextid . '/' . $usertoken . '/' . $componentname . '/' . $additionalargs . '/rss.xml', null, 'rssfile'); }
/** * Callback called by comment::get_comments() and comment::add(). Gives an opportunity to enforce blind-marking. * * @param array $comments * @param stdClass $options * @return array * @throws comment_exception */ function assignsubmission_comments_comment_display($comments, $options) { global $CFG, $DB, $USER; if ($options->commentarea != 'submission_comments' && $options->commentarea != 'submission_comments_upgrade') { throw new comment_exception('invalidcommentarea'); } if (!($submission = $DB->get_record('assign_submission', array('id' => $options->itemid)))) { throw new comment_exception('invalidcommentitemid'); } $context = $options->context; $cm = $options->cm; $course = $options->courseid; require_once $CFG->dirroot . '/mod/assign/locallib.php'; $assignment = new assign($context, $cm, $course); if ($assignment->get_instance()->id != $submission->assignment) { throw new comment_exception('invalidcontext'); } if ($assignment->is_blind_marking() && !empty($comments)) { // Blind marking is being used, may need to map unique anonymous ids to the comments. $usermappings = array(); $hiddenuserstr = trim(get_string('hiddenuser', 'assign')); $guestuser = guest_user(); foreach ($comments as $comment) { // Anonymize the comments. if (empty($usermappings[$comment->userid])) { // The blind-marking information for this commenter has not been generated; do so now. $anonid = $assignment->get_uniqueid_for_user($comment->userid); $commenter = new stdClass(); $commenter->firstname = $hiddenuserstr; $commenter->lastname = $anonid; $commenter->picture = 0; $commenter->id = $guestuser->id; $commenter->email = $guestuser->email; $commenter->imagealt = $guestuser->imagealt; // Temporarily store blind-marking information for use in later comments if necessary. $usermappings[$comment->userid]->fullname = fullname($commenter); $usermappings[$comment->userid]->avatar = $assignment->get_renderer()->user_picture($commenter, array('size' => 18, 'link' => false)); } // Set blind-marking information for this comment. $comment->fullname = $usermappings[$comment->userid]->fullname; $comment->avatar = $usermappings[$comment->userid]->avatar; $comment->profileurl = null; } } return $comments; }
/** * Initialise $_SESSION, handles google access * and sets up not-logged-in user properly. * * WARNING: $USER and $SESSION are set up later, do not use them yet! * * @param bool $newsid is this a new session in first http request? */ protected static function initialise_user_session($newsid) { global $CFG, $DB; $sid = session_id(); if (!$sid) { // No session, very weird. error_log('Missing session ID, session not started!'); self::init_empty_session(); return; } if (!($record = $DB->get_record('sessions', array('sid' => $sid), 'id, sid, state, userid, lastip, timecreated, timemodified'))) { if (!$newsid) { if (!empty($_SESSION['USER']->id)) { // This should not happen, just log it, we MUST not produce any output here! error_log("Cannot find session record {$sid} for user " . $_SESSION['USER']->id . ", creating new session."); } // Prevent session fixation attacks. session_regenerate_id(true); } $_SESSION = array(); } unset($sid); if (isset($_SESSION['USER']->id)) { if (!empty($_SESSION['USER']->realuser)) { $userid = $_SESSION['USER']->realuser; } else { $userid = $_SESSION['USER']->id; } // Verify timeout first. $maxlifetime = $CFG->sessiontimeout; $timeout = false; if (isguestuser($userid) or empty($userid)) { // Ignore guest and not-logged in timeouts, there is very little risk here. $timeout = false; } else { if ($record->timemodified < time() - $maxlifetime) { $timeout = true; $authsequence = get_enabled_auth_plugins(); // Auths, in sequence. foreach ($authsequence as $authname) { $authplugin = get_auth_plugin($authname); if ($authplugin->ignore_timeout_hook($_SESSION['USER'], $record->sid, $record->timecreated, $record->timemodified)) { $timeout = false; break; } } } } if ($timeout) { session_regenerate_id(true); $_SESSION = array(); $DB->delete_records('sessions', array('id' => $record->id)); } else { // Update session tracking record. $update = new \stdClass(); $updated = false; if ($record->userid != $userid) { $update->userid = $record->userid = $userid; $updated = true; } $ip = getremoteaddr(); if ($record->lastip != $ip) { $update->lastip = $record->lastip = $ip; $updated = true; } $updatefreq = empty($CFG->session_update_timemodified_frequency) ? 20 : $CFG->session_update_timemodified_frequency; if ($record->timemodified == $record->timecreated) { // Always do first update of existing record. $update->timemodified = $record->timemodified = time(); $updated = true; } else { if ($record->timemodified < time() - $updatefreq) { // Update the session modified flag only once every 20 seconds. $update->timemodified = $record->timemodified = time(); $updated = true; } } if ($updated) { $update->id = $record->id; $DB->update_record('sessions', $update); } return; } } else { if ($record) { // This happens when people switch session handlers... session_regenerate_id(true); $_SESSION = array(); $DB->delete_records('sessions', array('id' => $record->id)); } } unset($record); $timedout = false; if (!isset($_SESSION['SESSION'])) { $_SESSION['SESSION'] = new \stdClass(); if (!$newsid) { $timedout = true; } } $user = null; if (!empty($CFG->opentogoogle)) { if (\core_useragent::is_web_crawler()) { $user = guest_user(); } $referer = get_local_referer(false); if (!empty($CFG->guestloginbutton) and !$user and !empty($referer)) { // Automatically log in users coming from search engine results. if (strpos($referer, 'google') !== false) { $user = guest_user(); } else { if (strpos($referer, 'altavista') !== false) { $user = guest_user(); } } } } // Setup $USER and insert the session tracking record. if ($user) { self::set_user($user); self::add_session_record($user->id); } else { self::init_empty_session(); self::add_session_record(0); } if ($timedout) { $_SESSION['SESSION']->has_timed_out = true; } }
/** * Returns list of user objects that are subscribed to this forum */ function forum_subscribed_users($course, $forum, $groupid = 0) { global $CFG; if ($groupid) { $grouptables = ", {$CFG->prefix}groups_members gm "; $groupselect = "AND gm.groupid = {$groupid} AND u.id = gm.userid"; } else { $grouptables = ''; $groupselect = ''; } if (forum_is_forcesubscribed($forum)) { $context = get_context_instance(CONTEXT_COURSE, $course->id); $sort = "u.email ASC"; $fields = "u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest, u.emailstop, u.imagealt,\n u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.timezone, u.theme, u.lang, u.trackforums, u.mnethostid"; $results = get_users_by_capability($context, 'mod/forum:initialsubscriptions', $fields, $sort, '', '', '', '', false, true); } else { $results = get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest, u.emailstop, u.imagealt,\n u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.timezone, u.theme, u.lang, u.trackforums, u.mnethostid\n FROM {$CFG->prefix}user u,\n {$CFG->prefix}forum_subscriptions s {$grouptables}\n WHERE s.forum = '{$forum->id}'\n AND s.userid = u.id\n AND u.deleted = 0 {$groupselect}\n ORDER BY u.email ASC"); } static $guestid = null; if (is_null($guestid)) { if ($guest = guest_user()) { $guestid = $guest->id; } else { $guestid = 0; } } // Guest user should never be subscribed to a forum. unset($results[$guestid]); return $results; }
/** * Adds a new chat message. * <b>Note:</b> if the $author parameter is omitted or invalid, then the function will attempt to use the {@link SloodleUser} member * of the current {@link SloodleSession} object; * If that is unavailable, then it will try to use the user currently 'logged-in' to the VLE (i.e. the $USER variable in Moodle). * If all else fails, it will attempt to attribute the message to the guest user. * @param string $message The text of the message. * @param mixed $user The user who wrote the message -- either a VLE user ID or (preferably) a {@link SloodleUser} object. If null, then the user in the current SloodleSession object will be used. If that fails, then the guest user is used if possible. * @param int $timestamp Timestamp of the message. If omitted or <= 0 then the current timestamp is used * @return bool True if successful, or false otherwise */ function add_message($message, $user = null, $timestamp = null) { // Ignore empty messages if (empty($message)) { return false; } // Make sure the message is safe $message = addslashes(clean_text(stripslashes($message))); // We need to get the user ID for the message $userid = 0; // Has a user object been provided? if (is_object($user)) { // Yes - grab the user ID $userid = $user->get_user_id(); } else { if ($user != null) { // May be an ID $userid = (int) $user; } } // Did we end up with a valid user ID? if ((int) $userid <= 0) { // No - do we have a user in the session parameter? if (isset($this->_session->user)) { // Store the user ID $userid = $this->_session->user->get_user_id(); } } // Are we still lacking a valid user? if ((int) $userid <= 0) { // Yes - user the guest user $guest = guest_user(); if ($guest) { $userid = $guest->id; } } // Prepare the timestamp variable if necessary if (is_null($timestamp)) { $timestamp = time(); } // Create a chat message record object $rec = new stdClass(); $rec->chatid = $this->moodle_chat_instance->id; $rec->userid = $userid; $rec->message = $message; $rec->timestamp = $timestamp; // Attempt to insert the chat message $result = insert_record('chat_messages', $rec); if (!$result) { // Insertion failed. // If possible, add an appropriate side effect code to our response if (isset($this->_session->response)) { $this->_session->response->add_side_effect(-10101); } } // We successfully added a chat message // If possible, add an appropriate side effect code to our response if (isset($this->_session->response)) { $this->_session->response->add_side_effect(10101); } return true; }
function Synch_restoreMergedBackupFromRemoteHost($id, $hostUrl, $sessionId, $fileName) { global $SynchManager, $USER; $USER = guest_user(); return $SynchManager->restoreMergedBackupFromRemoteHost($id, $hostUrl, $sessionId, $fileName); }
/** * Adds module specific settings to the settings block * * @param settings_navigation $settings The settings navigation object * @param navigation_node $forumnode The node to add module settings to */ function forum_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $forumnode) { global $USER, $PAGE, $CFG, $DB, $OUTPUT; $forumobject = $DB->get_record("forum", array("id" => $PAGE->cm->instance)); if (empty($PAGE->cm->context)) { $PAGE->cm->context = context_module::instance($PAGE->cm->instance); } $params = $PAGE->url->params(); if (!empty($params['d'])) { $discussionid = $params['d']; } // for some actions you need to be enrolled, beiing admin is not enough sometimes here $enrolled = is_enrolled($PAGE->cm->context, $USER, '', false); $activeenrolled = is_enrolled($PAGE->cm->context, $USER, '', true); $canmanage = has_capability('mod/forum:managesubscriptions', $PAGE->cm->context); $subscriptionmode = \mod_forum\subscriptions::get_subscription_mode($forumobject); $cansubscribe = $activeenrolled && !\mod_forum\subscriptions::is_forcesubscribed($forumobject) && (!\mod_forum\subscriptions::subscription_disabled($forumobject) || $canmanage); if ($canmanage) { $mode = $forumnode->add(get_string('subscriptionmode', 'forum'), null, navigation_node::TYPE_CONTAINER); $mode->add_class('subscriptionmode'); $allowchoice = $mode->add(get_string('subscriptionoptional', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => FORUM_CHOOSESUBSCRIBE, 'sesskey' => sesskey())), navigation_node::TYPE_SETTING); $forceforever = $mode->add(get_string("subscriptionforced", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => FORUM_FORCESUBSCRIBE, 'sesskey' => sesskey())), navigation_node::TYPE_SETTING); $forceinitially = $mode->add(get_string("subscriptionauto", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => FORUM_INITIALSUBSCRIBE, 'sesskey' => sesskey())), navigation_node::TYPE_SETTING); $disallowchoice = $mode->add(get_string('subscriptiondisabled', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'mode' => FORUM_DISALLOWSUBSCRIBE, 'sesskey' => sesskey())), navigation_node::TYPE_SETTING); switch ($subscriptionmode) { case FORUM_CHOOSESUBSCRIBE: // 0 $allowchoice->action = null; $allowchoice->add_class('activesetting'); $allowchoice->icon = new pix_icon('t/selected', '', 'mod_forum'); break; case FORUM_FORCESUBSCRIBE: // 1 $forceforever->action = null; $forceforever->add_class('activesetting'); $forceforever->icon = new pix_icon('t/selected', '', 'mod_forum'); break; case FORUM_INITIALSUBSCRIBE: // 2 $forceinitially->action = null; $forceinitially->add_class('activesetting'); $forceinitially->icon = new pix_icon('t/selected', '', 'mod_forum'); break; case FORUM_DISALLOWSUBSCRIBE: // 3 $disallowchoice->action = null; $disallowchoice->add_class('activesetting'); $disallowchoice->icon = new pix_icon('t/selected', '', 'mod_forum'); break; } } else { if ($activeenrolled) { switch ($subscriptionmode) { case FORUM_CHOOSESUBSCRIBE: // 0 $notenode = $forumnode->add(get_string('subscriptionoptional', 'forum')); break; case FORUM_FORCESUBSCRIBE: // 1 $notenode = $forumnode->add(get_string('subscriptionforced', 'forum')); break; case FORUM_INITIALSUBSCRIBE: // 2 $notenode = $forumnode->add(get_string('subscriptionauto', 'forum')); break; case FORUM_DISALLOWSUBSCRIBE: // 3 $notenode = $forumnode->add(get_string('subscriptiondisabled', 'forum')); break; } } } if ($cansubscribe) { if (\mod_forum\subscriptions::is_subscribed($USER->id, $forumobject, null, $PAGE->cm)) { $linktext = get_string('unsubscribe', 'forum'); } else { $linktext = get_string('subscribe', 'forum'); } $url = new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'sesskey' => sesskey())); $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING); if (isset($discussionid)) { if (\mod_forum\subscriptions::is_subscribed($USER->id, $forumobject, $discussionid, $PAGE->cm)) { $linktext = get_string('unsubscribediscussion', 'forum'); } else { $linktext = get_string('subscribediscussion', 'forum'); } $url = new moodle_url('/mod/forum/subscribe.php', array('id' => $forumobject->id, 'sesskey' => sesskey(), 'd' => $discussionid, 'returnurl' => $PAGE->url->out())); $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING); } } if (has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)) { $url = new moodle_url('/mod/forum/subscribers.php', array('id' => $forumobject->id)); $forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING); } if ($enrolled && forum_tp_can_track_forums($forumobject)) { // keep tracking info for users with suspended enrolments if ($forumobject->trackingtype == FORUM_TRACKING_OPTIONAL || !$CFG->forum_allowforcedreadtracking && $forumobject->trackingtype == FORUM_TRACKING_FORCED) { if (forum_tp_is_tracked($forumobject)) { $linktext = get_string('notrackforum', 'forum'); } else { $linktext = get_string('trackforum', 'forum'); } $url = new moodle_url('/mod/forum/settracking.php', array('id' => $forumobject->id, 'sesskey' => sesskey())); $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING); } } if (!isloggedin() && $PAGE->course->id == SITEID) { $userid = guest_user()->id; } else { $userid = $USER->id; } $hascourseaccess = $PAGE->course->id == SITEID || can_access_course($PAGE->course, $userid); $enablerssfeeds = !empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds); if ($enablerssfeeds && $forumobject->rsstype && $forumobject->rssarticles && $hascourseaccess) { if (!function_exists('rss_get_url')) { require_once "{$CFG->libdir}/rsslib.php"; } if ($forumobject->rsstype == 1) { $string = get_string('rsssubscriberssdiscussions', 'forum'); } else { $string = get_string('rsssubscriberssposts', 'forum'); } $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $userid, "mod_forum", $forumobject->id)); $forumnode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', '')); } }
/** * Initialise $USER object, handles google access * and sets up not logged in user properly. * * @return void */ protected function check_user_initialised() { global $CFG; if (isset($_SESSION['USER']->id)) { // already set up $USER return; } $user = null; if (!empty($CFG->opentogoogle) and !NO_MOODLE_COOKIES) { if (is_web_crawler()) { $user = guest_user(); } if (!empty($CFG->guestloginbutton) and !$user and !empty($_SERVER['HTTP_REFERER'])) { // automaticaly log in users coming from search engine results if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false) { $user = guest_user(); } else { if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false) { $user = guest_user(); } } } } if (!$user) { $user = new stdClass(); $user->id = 0; // to enable proper function of $CFG->notloggedinroleid hack if (isset($CFG->mnet_localhost_id)) { $user->mnethostid = $CFG->mnet_localhost_id; } else { $user->mnethostid = 1; } } session_set_user($user); }
/** * Returns list of user objects that are subscribed to this forum */ function forum_subscribed_users($course, $forum, $groupid = 0, $cache = false) { global $CFG; static $resultscache = array(); if ($cache && isset($resultscache[$forum->id][$groupid])) { return $resultscache[$forum->id][$groupid]; } if ($groupid) { $grouptables = ", {$CFG->prefix}groups_members gm "; $groupselect = "AND gm.groupid = '{$groupid}' AND u.id = gm.userid"; } else { $grouptables = ''; $groupselect = ''; } if (forum_is_forcesubscribed($forum)) { $results = get_course_users($course->id); // Otherwise get everyone in the course } else { $results = get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest, u.emailstop, u.imagealt,\n u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.timezone, u.theme, u.lang, u.trackforums, u.mnethostid\n FROM {$CFG->prefix}user u,\n {$CFG->prefix}forum_subscriptions s {$grouptables}\n WHERE s.forum = '{$forum->id}'\n AND s.userid = u.id\n AND u.deleted <> 1 {$groupselect}\n ORDER BY u.email ASC"); } // Guest user should never be subscribed to a forum. if ($guest = guest_user()) { unset($results[$guest->id]); } if ($cache) { $resultscache[$forum->id][$groupid] = $results; } return $results; }
public function test_apply_concurrent_login_limit() { global $DB; $this->resetAfterTest(); $user1 = $this->getDataGenerator()->create_user(); $user2 = $this->getDataGenerator()->create_user(); $guest = guest_user(); $record = new \stdClass(); $record->state = 0; $record->sessdata = null; $record->userid = $user1->id; $record->timemodified = time(); $record->firstip = $record->lastip = '10.0.0.1'; $record->sid = md5('hokus1'); $record->timecreated = 20; $DB->insert_record('sessions', $record); $record->sid = md5('hokus2'); $record->timecreated = 10; $DB->insert_record('sessions', $record); $record->sid = md5('hokus3'); $record->timecreated = 30; $DB->insert_record('sessions', $record); $record->userid = $user2->id; $record->sid = md5('pokus1'); $record->timecreated = 20; $DB->insert_record('sessions', $record); $record->sid = md5('pokus2'); $record->timecreated = 10; $DB->insert_record('sessions', $record); $record->sid = md5('pokus3'); $record->timecreated = 30; $DB->insert_record('sessions', $record); $record->timecreated = 10; $record->userid = $guest->id; $record->sid = md5('g1'); $DB->insert_record('sessions', $record); $record->sid = md5('g2'); $DB->insert_record('sessions', $record); $record->sid = md5('g3'); $DB->insert_record('sessions', $record); $record->userid = 0; $record->sid = md5('nl1'); $DB->insert_record('sessions', $record); $record->sid = md5('nl2'); $DB->insert_record('sessions', $record); $record->sid = md5('nl3'); $DB->insert_record('sessions', $record); set_config('limitconcurrentlogins', 0); $this->assertCount(12, $DB->get_records('sessions')); \core\session\manager::apply_concurrent_login_limit($user1->id); \core\session\manager::apply_concurrent_login_limit($user2->id); \core\session\manager::apply_concurrent_login_limit($guest->id); \core\session\manager::apply_concurrent_login_limit(0); $this->assertCount(12, $DB->get_records('sessions')); set_config('limitconcurrentlogins', -1); \core\session\manager::apply_concurrent_login_limit($user1->id); \core\session\manager::apply_concurrent_login_limit($user2->id); \core\session\manager::apply_concurrent_login_limit($guest->id); \core\session\manager::apply_concurrent_login_limit(0); $this->assertCount(12, $DB->get_records('sessions')); set_config('limitconcurrentlogins', 2); \core\session\manager::apply_concurrent_login_limit($user1->id); $this->assertCount(11, $DB->get_records('sessions')); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 20))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 30))); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 10))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 20))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 30))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 10))); set_config('limitconcurrentlogins', 2); \core\session\manager::apply_concurrent_login_limit($user2->id, md5('pokus2')); $this->assertCount(10, $DB->get_records('sessions')); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 20))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 30))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 10))); \core\session\manager::apply_concurrent_login_limit($guest->id); \core\session\manager::apply_concurrent_login_limit(0); $this->assertCount(10, $DB->get_records('sessions')); set_config('limitconcurrentlogins', 1); \core\session\manager::apply_concurrent_login_limit($user1->id, md5('grrr')); $this->assertCount(9, $DB->get_records('sessions')); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 20))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 30))); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 10))); \core\session\manager::apply_concurrent_login_limit($user1->id); $this->assertCount(9, $DB->get_records('sessions')); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 20))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 30))); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user1->id, 'timecreated' => 10))); \core\session\manager::apply_concurrent_login_limit($user2->id, md5('pokus2')); $this->assertCount(8, $DB->get_records('sessions')); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 20))); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 30))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 10))); \core\session\manager::apply_concurrent_login_limit($user2->id); $this->assertCount(8, $DB->get_records('sessions')); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 20))); $this->assertFalse($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 30))); $this->assertTrue($DB->record_exists('sessions', array('userid' => $user2->id, 'timecreated' => 10))); \core\session\manager::apply_concurrent_login_limit($guest->id); \core\session\manager::apply_concurrent_login_limit(0); $this->assertCount(8, $DB->get_records('sessions')); }
/** * Check user can save a new group tag instance as these have a unique key * If not, will use - admin user (0), guest user (1), other admin user (2+) * @param int $groupid * @param int $tagid * @param int $start default -1 for current user. * @return int user id * @throws moodle_exception If out of users */ private static function get_group_taginstance_userid($groupid, $tagid, $start = -1) { global $DB, $USER; $userid = $USER->id; $nexttry = 0; if ($start == 0) { $userid = get_admin()->id; $nexttry = 1; } else { if ($start == 1) { $userid = guest_user()->id; $nexttry = 2; } else { if ($start >= 2) { $admins = get_admins(); if (count($admins) < $start) { throw new moodle_exception('Cannot add tag instance - duplicate value, max possible reached.'); } $keys = array_keys($admins); // Get keys (user id's). $userid = $keys[$start - 1]; $nexttry = $start; $nexttry++; } } } if (!$DB->record_exists('tag_instance', array('itemtype' => 'groups', 'itemid' => $groupid, 'tiuserid' => $userid, 'tagid' => $tagid))) { // No existing record, safe to proceed. return $userid; } // Try and find another userid. return self::get_group_taginstance_userid($groupid, $tagid, $nexttry); }
/** * Returns list of user objects that are subscribed to this forum * * @global object * @global object * @param object $course the course * @param forum $forum the forum * @param integer $groupid group id, or 0 for all. * @param object $context the forum context, to save re-fetching it where possible. * @param string $fields requested user fields (with "u." table prefix) * @return array list of users. */ function forum_subscribed_users($course, $forum, $groupid = 0, $context = null, $fields = null) { global $CFG, $DB; $params = array($forum->id); if ($groupid) { $grouptables = ", {groups_members} gm "; $groupselect = "AND gm.groupid = ? AND u.id = gm.userid"; $params[] = $groupid; } else { $grouptables = ''; $groupselect = ''; } if (empty($fields)) { $fields = "u.id,\n u.username,\n u.firstname,\n u.lastname,\n u.maildisplay,\n u.mailformat,\n u.maildigest,\n u.imagealt,\n u.email,\n u.city,\n u.country,\n u.lastaccess,\n u.lastlogin,\n u.picture,\n u.timezone,\n u.theme,\n u.lang,\n u.trackforums,\n u.mnethostid"; } if (forum_is_forcesubscribed($forum)) { if (empty($context)) { $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); } $sort = "u.email ASC"; $results = forum_get_potential_subscribers($context, $groupid, $fields, $sort); } else { $results = $DB->get_records_sql("SELECT {$fields}\n FROM {user} u,\n {forum_subscriptions} s {$grouptables}\n WHERE s.forum = ?\n AND s.userid = u.id\n AND u.deleted = 0 {$groupselect}\n ORDER BY u.email ASC", $params); } static $guestid = null; if (is_null($guestid)) { if ($guest = guest_user()) { $guestid = $guest->id; } else { $guestid = 0; } } // Guest user should never be subscribed to a forum. unset($results[$guestid]); return $results; }
/** * @param $user * @return bool * @author Mark Nielsen */ function hsuforum_is_anonymous_user($user) { static $guest = null; if (is_null($guest)) { $guest = guest_user(); } return $user->id == $guest->id; }
} } if (empty($_SESSION['USER']) and !empty($_SERVER['HTTP_REFERER'])) { if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false) { $USER = guest_user(); } else { if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false) { $USER = guest_user(); } } } } } /// Populates an empty $USER if is empty if (empty($USER) || !isset($USER->ident)) { $USER = guest_user(); } /// backwards compatibility fill_legacy_user_session($USER); ////// ////// Load some core libraries ////// require_once $CFG->dirroot . "lib/templates.php"; require_once $CFG->dirroot . "lib/displaylib.php"; ////// ////// Init templating basics ////// if (!isset($CFG->templatestore)) { $CFG->templatestore = 'db'; } if (!isset($CFG->templatesroot)) {
$userid = $this->customdata['current_user']; $formdata['hidden']['userid'] = $userid; } // Generate search SQL $keywords = search_parse_keywords($query); $fields = array('firstname', 'lastname', 'email'); list($searchsql, $params) = search_get_keyword_where_clause($keywords, $fields); $search_info->fullname = $DB->sql_fullname('firstname', 'lastname'); if ($canviewemail) { $search_info->email = 'email'; } // exclude deleted, guest users and self $guest = guest_user(); $search_info->sql = " FROM {user} WHERE {$searchsql} AND deleted = 0 AND suspended = 0 AND id != ? "; $params[] = $guest->id; if (isset($this->customdata['current_user'])) { $search_info->sql .= " AND id <> ?"; $params[] = $userid;
/** * Initialise $USER object, handles google access * and sets up not logged in user properly. * * @return void */ protected function check_user_initialised() { if (isset($_SESSION['USER']->id)) { // already set up $USER return; } $user = null; if (!empty($CFG->opentogoogle) and !NO_MOODLE_COOKIES) { if (!empty($_SERVER['HTTP_USER_AGENT'])) { // allow web spiders in as guest users if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false) { $user = guest_user(); } else { if (strpos($_SERVER['HTTP_USER_AGENT'], 'google.com') !== false) { // Google $user = guest_user(); } else { if (strpos($_SERVER['HTTP_USER_AGENT'], 'Yahoo! Slurp') !== false) { // Yahoo $user = guest_user(); } else { if (strpos($_SERVER['HTTP_USER_AGENT'], '[ZSEBOT]') !== false) { // Zoomspider $user = guest_user(); } else { if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSNBOT') !== false) { // MSN Search $user = guest_user(); } } } } } } if (!empty($CFG->guestloginbutton) and !$user and !empty($_SERVER['HTTP_REFERER'])) { // automaticaly log in users coming from search engine results if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false) { $user = guest_user(); } else { if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false) { $user = guest_user(); } } } } if (!$user) { $user = new object(); $user->id = 0; // to enable proper function of $CFG->notloggedinroleid hack if (isset($CFG->mnet_localhost_id)) { $user->mnethostid = $CFG->mnet_localhost_id; } else { $user->mnethostid = 1; } } session_set_user($user); }
/** * Processes pending login notifications, up to a certain limit. * Retrieves the requests one-at-a-time for processing. * This is slower, but ensures minimal damage if the process is terminated, e.g. due to server timeout. * @param int $limit The maximum number of pending requests to process. * @return void */ function sloodle_process_login_notifications($limit = 25) { global $CFG; // Validate the limit $limit = (int) $limit; if ($limit < 1) { return; } // Go through each one for ($i = 0; $i < $limit; $i++) { // Obtain the first record $recs = get_records('sloodle_login_notifications', '', '', 'id', '*', 0, $limit); if (!$recs) { return false; } reset($recs); $rec = current($recs); // Determine the user ID of the person who requested this $userid = 0; if (!($sloodleuser = get_record('sloodle_users', 'uuid', $rec->avatar))) { // Failed to the user - get the guest user instead $guestdata = guest_user(); $userid = $guestdata->id; } else { // Got the data - store the user ID $userid = $sloodleuser->userid; } // Send the notification if (sloodle_send_login_notification($rec->destination, $rec->avatar, $rec->username, $rec->password)) { // Log the notification add_to_log(SITEID, 'sloodle', 'view', '', 'Sent login details by email to avatar in-world', 0, $userid); } else { // Log the failed notification (but don't keep trying the same one) add_to_log(SITEID, 'sloodle', 'view failed', '', 'Failed to send login details by email to avatar in-world', 0, $userid); } // Delete the record from the data delete_records('sloodle_login_notifications', 'id', $rec->id); } }
/** * Formats the column userpic. * * @param stdClass $row Table row. * @return string Output produced. */ protected function col_userpic($row) { global $CFG, $OUTPUT; if ($this->identitymode == block_xp_manager::IDENTITY_OFF && $this->userid != $row->userid) { static $guestuser = null; if ($guestuser === null) { $guestuser = guest_user(); } return $OUTPUT->user_picture($guestuser, array('link' => false, 'alttext' => false)); } return $OUTPUT->user_picture(user_picture::unalias($row, null, 'userid')); }
} else { $digestoptions_selector->selected = $forum->maildigest; } $row[] = $OUTPUT->render($digestoptions_selector); } //If this forum has RSS activated, calculate it if ($show_rss) { if ($forum->rsstype and $forum->rssarticles) { //Calculate the tooltip text if ($forum->rsstype == 1) { $tooltiptext = get_string('rsssubscriberssdiscussions', 'forum'); } else { $tooltiptext = get_string('rsssubscriberssposts', 'forum'); } if (!isloggedin() && $course->id == SITEID) { $userid = guest_user()->id; } else { $userid = $USER->id; } //Get html code for RSS link $row[] = rss_get_link($context->id, $userid, 'mod_forum', $forum->id, $tooltiptext); } else { $row[] = ' '; } } $generaltable->data[] = $row; } } // Start of the table for Learning Forums $learningtable = new html_table(); $learningtable->head = array($strforum, $strdescription, $strdiscussions);
public function test_session_exists() { global $CFG, $DB; $this->resetAfterTest(); $this->assertFalse(\core\session\manager::session_exists('abc')); $user = $this->getDataGenerator()->create_user(); $guest = guest_user(); // The file handler is used by default, so let's fake the data somehow. $sid = md5('hokus'); mkdir("{$CFG->dataroot}/sessions/", $CFG->directorypermissions, true); touch("{$CFG->dataroot}/sessions/sess_{$sid}"); $this->assertFalse(\core\session\manager::session_exists($sid)); $record = new stdClass(); $record->userid = 0; $record->sid = $sid; $record->timecreated = time(); $record->timemodified = $record->timecreated; $record->id = $DB->insert_record('sessions', $record); $this->assertTrue(\core\session\manager::session_exists($sid)); $record->timecreated = time() - $CFG->sessiontimeout - 100; $record->timemodified = $record->timecreated + 10; $DB->update_record('sessions', $record); $this->assertTrue(\core\session\manager::session_exists($sid)); $record->userid = $guest->id; $DB->update_record('sessions', $record); $this->assertTrue(\core\session\manager::session_exists($sid)); $record->userid = $user->id; $DB->update_record('sessions', $record); $this->assertFalse(\core\session\manager::session_exists($sid)); $CFG->sessiontimeout = $CFG->sessiontimeout + 3000; $this->assertTrue(\core\session\manager::session_exists($sid)); }
$CFG->lang = $SESSION->lang; } } // Set the default site locale, a lot of the stuff may depend on this // it is definitely too late to call this first in require_login()! moodle_setlocale(); if (!empty($CFG->debugvalidators) and !empty($CFG->guestloginbutton)) { if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation if (isset($_SERVER['HTTP_USER_AGENT']) and empty($USER->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest) if (strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false or strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false) { if ($user = get_complete_user_data("username", "w3cvalidator")) { $user->ignoresesskey = true; } else { $user = guest_user(); } session_set_user($user); } } } } // Apache log integration. In apache conf file one can use ${MOODULEUSER}n in // LogFormat to get the current logged in username in moodle. if ($USER && function_exists('apache_note') && !empty($CFG->apacheloguser) && isset($USER->username)) { $apachelog_userid = $USER->id; $apachelog_username = clean_filename($USER->username); $apachelog_name = ''; if (isset($USER->firstname)) { // We can assume both will be set // - even if to empty.
function fill_legacy_user_session($user = NULL) { if (!$user || $user == NULL) { $user = guest_user(); } /// Fills up all legacy user session data /// This function provides backward compatibility $_SESSION['userid'] = (int) $user->ident; $_SESSION['username'] = $user->username; $_SESSION['name'] = stripslashes($user->name); $_SESSION['email'] = stripslashes($user->email); $iconid = (int) $user->icon; if ($iconid == -1) { $_SESSION['icon'] = "default.png"; } else { if ($icon = get_record('icons', 'ident', $iconid)) { $_SESSION['icon'] = $icon->filename; } else { $_SESSION['icon'] = "default.png"; } } $_SESSION['icon_quota'] = (int) $user->icon_quota; }
/** * Adds module specific settings to the settings block * * @param settings_navigation $settings The settings navigation object * @param navigation_node $forumnode The node to add module settings to */ function forum_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $forumnode) { global $USER, $PAGE, $CFG, $DB, $OUTPUT; $forumobject = $DB->get_record("forum", array("id" => $PAGE->cm->instance)); if (empty($PAGE->cm->context)) { $PAGE->cm->context = context_module::instance($PAGE->cm->instance); } // for some actions you need to be enrolled, beiing admin is not enough sometimes here $enrolled = is_enrolled($PAGE->cm->context, $USER, '', false); $activeenrolled = is_enrolled($PAGE->cm->context, $USER, '', true); $canmanage = has_capability('mod/forum:managesubscriptions', $PAGE->cm->context); $subscriptionmode = forum_get_forcesubscribed($forumobject); $cansubscribe = ($activeenrolled && $subscriptionmode != FORUM_FORCESUBSCRIBE && ($subscriptionmode != FORUM_DISALLOWSUBSCRIBE || $canmanage)); if ($canmanage) { $mode = $forumnode->add(get_string('subscriptionmode', 'forum'), null, navigation_node::TYPE_CONTAINER); $allowchoice = $mode->add(get_string('subscriptionoptional', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_CHOOSESUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING); $forceforever = $mode->add(get_string("subscriptionforced", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_FORCESUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING); $forceinitially = $mode->add(get_string("subscriptionauto", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_INITIALSUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING); $disallowchoice = $mode->add(get_string('subscriptiondisabled', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_DISALLOWSUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING); switch ($subscriptionmode) { case FORUM_CHOOSESUBSCRIBE : // 0 $allowchoice->action = null; $allowchoice->add_class('activesetting'); break; case FORUM_FORCESUBSCRIBE : // 1 $forceforever->action = null; $forceforever->add_class('activesetting'); break; case FORUM_INITIALSUBSCRIBE : // 2 $forceinitially->action = null; $forceinitially->add_class('activesetting'); break; case FORUM_DISALLOWSUBSCRIBE : // 3 $disallowchoice->action = null; $disallowchoice->add_class('activesetting'); break; } } else if ($activeenrolled) { switch ($subscriptionmode) { case FORUM_CHOOSESUBSCRIBE : // 0 $notenode = $forumnode->add(get_string('subscriptionoptional', 'forum')); break; case FORUM_FORCESUBSCRIBE : // 1 $notenode = $forumnode->add(get_string('subscriptionforced', 'forum')); break; case FORUM_INITIALSUBSCRIBE : // 2 $notenode = $forumnode->add(get_string('subscriptionauto', 'forum')); break; case FORUM_DISALLOWSUBSCRIBE : // 3 $notenode = $forumnode->add(get_string('subscriptiondisabled', 'forum')); break; } } if ($cansubscribe) { if (forum_is_subscribed($USER->id, $forumobject)) { $linktext = get_string('unsubscribe', 'forum'); } else { $linktext = get_string('subscribe', 'forum'); } $url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'sesskey'=>sesskey())); $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING); } if (has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)){ $url = new moodle_url('/mod/forum/subscribers.php', array('id'=>$forumobject->id)); $forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING); } if ($enrolled && forum_tp_can_track_forums($forumobject)) { // keep tracking info for users with suspended enrolments if ($forumobject->trackingtype != FORUM_TRACKING_OPTIONAL) { //tracking forced on or off in forum settings so dont provide a link here to change it //could add unclickable text like for forced subscription but not sure this justifies adding another menu item } else { if (forum_tp_is_tracked($forumobject)) { $linktext = get_string('notrackforum', 'forum'); } else { $linktext = get_string('trackforum', 'forum'); } $url = new moodle_url('/mod/forum/settracking.php', array('id'=>$forumobject->id)); $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING); } } if (!isloggedin() && $PAGE->course->id == SITEID) { $userid = guest_user()->id; } else { $userid = $USER->id; } $hascourseaccess = ($PAGE->course->id == SITEID) || can_access_course($PAGE->course, $userid); $enablerssfeeds = !empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds); if ($enablerssfeeds && $forumobject->rsstype && $forumobject->rssarticles && $hascourseaccess) { if (!function_exists('rss_get_url')) { require_once("$CFG->libdir/rsslib.php"); } if ($forumobject->rsstype == 1) { $string = get_string('rsssubscriberssdiscussions','forum'); } else { $string = get_string('rsssubscriberssposts','forum'); } $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $userid, "mod_forum", $forumobject->id)); $forumnode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', '')); } }
/** * This function will get sermon html then let the parent class output the file * */ function display() { global $CFG, $COURSE; require_once $CFG->libdir . '/biblelib.php'; require_once $CFG->libdir . '/filelib.php'; $resource = $this->resource; resource_sermon_accessed($resource->id); $extrahtml = array(); /// build the sermon header $extrahtml[] = '<div class="sermon-header ui-corner-all">'; $extrahtml[] = '<span class="series-name nowrap">' . $resource->seriesname . '</span>'; $extrahtml[] = '</div>'; /// sermon information $extrahtml[] = '<div class="sermon-info">'; // get the correct user information $speakername = $userpicture = false; if (!empty($resource->speakerid)) { $user = get_record('user', 'id', $resource->speakerid); $userpicture = print_user_picture($user, SITEID, $user->picture, true, true); $speakername = fullname($user); } else { $guestuser = guest_user(); $userpicture = print_user_picture($guestuser, SITEID, $guestuser->picture, true, true, false); $speakername = $resource->guestspeakername; } //we need the book name $biblebooks = biblebooks_array(); $resource->bookname = $biblebooks[$resource->book]; // build speaker information $extrahtml[] = '<div class="speaker">'; $extrahtml[] = '<span class="speaker-pic nowrap">' . $userpicture . '</span>'; $extrahtml[] = '<span class="speaker-name nowrap">' . $speakername . '</span>'; $extrahtml[] = '</div>'; // build sermon information $extrahtml[] = '<div class="sermon-text">'; $extrahtml[] = '<span class="sermon-title">' . $resource->name . '</span>'; $extrahtml[] = '<span class="sermon-place nowrap">' . get_string('sermonplace', 'resource', $resource) . '</span>'; $extrahtml[] = '<span class="sermon-download-links nowrap">' . get_string('downloadlinks', 'resource') . '</span>'; $extrahtml[] = '<span class="links">'; $extrahtml[] = '<span class="link nowrap"> <span class="picture">' . print_file_picture($CFG->pixpath . '/cust/doc.png', 0, $height = '22px', $width = '22px', $CFG->wwwroot . '/file.php/' . $resource->course . '/' . $resource->reference, true) . '</span> <span class="link-name"><a href="' . $CFG->wwwroot . '/file.php/' . $resource->course . '/' . $resource->reference . '">' . get_string('sermonmp3link', 'resource', $resource) . '</a></span> </span>'; if (!empty($resource->referencesermontext)) { $extrahtml[] = '<span class="link nowrap"> <span class="picture">' . print_file_picture($CFG->pixpath . '/cust/mp3.png', 0, $height = '22px', $width = '22px', $CFG->wwwroot . '/file.php/' . $resource->course . '/' . $resource->referencesermontext, true) . '</span> <span class="link-name"><a href="' . $CFG->wwwroot . '/file.php/' . $resource->course . '/' . $resource->referencesermontext . '">' . get_string('sermontextlink', 'resource', $resource) . '</a></span> </span>'; } if (!empty($resource->referencelesson)) { $extrahtml[] = '<span class="link nowrap"> <span class="picture">' . print_file_picture($CFG->pixpath . '/cust/doc.png', 0, $height = '22', $width = '22', $CFG->wwwroot . '/file.php/' . $resource->course . '/' . $resource->referencesermonlesson, true) . '</span> <span class="link-name"><a href="' . $CFG->wwwroot . '/file.php/' . $resource->course . '/' . $resource->referencesermonlesson . '">' . get_string('sermonlessonlink', 'resource', $resource) . '</a></span> </span>'; } $extrahtml[] = '</span>'; $extrahtml[] = '</div>'; $extrahtml[] = '<div id="datedelivered-picker"></div>'; $extrahtml[] = '<script type="text/javascript">jQuery("#datedelivered-picker").datepicker({dateFormat: "@", onSelect : function (dateText, inst) {jQuery("#datedelivered-picker").datepicker("setDate", 0)}})</script>'; echo '<div id="extra-html" class="ui-corner-all">'; echo implode(' ', $extrahtml); $fullurl = get_file_url($COURSE->id . '/' . $resource->reference); $cleanurl = addslashes_js($fullurl); $artist = ''; if (!empty($resource->guestspeakername)) { $artist = "artists: \"{$resource->guestspeakername}\""; } else { if (!empty($resource->speakerid)) { $user = get_record('user', 'id', $resource->speakerid); if (!empty($user)) { $artist = "artists: \"{$user->firstname} {$user->lastname}\""; } } } $titles = ''; if (!empty($resource->seriesname)) { $titles = $resource->seriesname . ': '; } $titles .= $resource->name; echo '<div class="newresourcecontent">'; echo '<script type="text/javascript" src="' . $CFG->httpswwwroot . '/lib/audio-player.js"></script>'; echo '<script type="text/javascript"> AudioPlayer.setup("' . $CFG->httpswwwroot . '/lib/player.swf", { width: 600 }); </script>'; echo '<p id="audioplayer_1">Alternative content</p> <script type="text/javascript"> AudioPlayer.embed("audioplayer_1", { soundFile: "' . $fullurl . '", transparentpagebg: "yes", titles: "' . $titles . '", ' . $artist . ' }); </script>'; echo '</div>'; }