function getUserList($currentgroup = '', $courseId, $contextlevel, $context, $limitUsers = 15) { global $USER, $CFG, $DB, $OUTPUT; $groupmembers = ""; $groupselect = ""; $params = array(); //Add this to the SQL to show only group users if ($currentgroup !== NULL) { $groupmembers = ", {groups_members} gm"; $groupselect = "AND u.id = gm.userid AND gm.groupid = :currentgroup"; $params['currentgroup'] = $currentgroup; } $userfields = user_picture::fields('u', array('username')); if ($courseId == SITEID or $contextlevel < CONTEXT_COURSE) { // Site-level //Only show if is admin if (!checkIfUserIsAdmin()) { return ''; } $sql = "SELECT {$userfields}, ul.lastip, MAX(ul.timemodified) AS lastaccess\n FROM {user} u {$groupmembers} ,{sessions} ul\n WHERE u.id = ul.userid AND u.deleted = 0\n {$groupselect}\n GROUP BY {$userfields}\n ORDER BY ul.timemodified DESC "; } else { // Course level - show only enrolled users for now //Only show if is teacher or admin if (!checkIfUserIsTeacher($courseId)) { return ''; } list($esqljoin, $eparams) = get_enrolled_sql($context); $params = array_merge($params, $eparams); $sql = "SELECT {$userfields}, ul.lastip, MAX(ul.timemodified) AS lastaccess\n FROM {sessions} ul {$groupmembers}, {user} u\n JOIN ({$esqljoin}) euj ON euj.id = u.id\n WHERE u.id = ul.userid\n AND u.deleted = 0\n {$groupselect}\n GROUP BY {$userfields}\n ORDER BY lastaccess DESC"; $params['courseid'] = $courseId; } if ($users = $DB->get_records_sql($sql, $params, 0, $limitUsers)) { // We'll just take the most recent 50 maximum foreach ($users as $user) { $users[$user->id]->fullname = fullname($user); } } else { $users = array(); } return $users; }
require_once $CFG->libdir . '/tablelib.php'; require_login(); define('DEFAULT_PAGE_SIZE', 20); $courseid = required_param('courseid', PARAM_INT); $contextid = optional_param('contextid', 0, PARAM_INT); // one of this or $page = optional_param('page', 0, PARAM_INT); // which page to show $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // how many per page if ($courseid and !($course = $DB->get_record('course', array('id' => $courseid)))) { print_error('no_course', 'block_uniquelogin_list', '', $courseid); } $context = context_course::instance($courseid); $acess = false; if (checkIfUserIsAdmin()) { $acess = true; } else { if (checkIfUserIsTeacher($courseid)) { $acess = true; } } if (!$acess) { print_error('dennyacess', 'block_uniquelogin_list', '', $courseid); } $PAGE->set_context($context); $PAGE->set_course($course); $PAGE->set_url('/blocks/uniquelogin_list/list_users.php', array('courseid' => $courseid)); $PAGE->navbar->add(get_string("blocktitle", "block_uniquelogin_list")); $PAGE->set_title(get_string("blocktitle", "block_uniquelogin_list")); $PAGE->set_heading(get_string("blocktitle", "block_uniquelogin_list"));
function remote_login($user_login, $user) { $user_login = get_chatwee_user_login(); $chatId = get_option('chatwee-settings-group[clientid]'); $clientKey = get_option('chatwee-settings-group[keyapi]'); $isAdmin = 0; if (is_super_admin($user->ID) || checkIfUserIsAdmin($user->ID) || belong_to_moderator_group($user->ID)) { $isAdmin = 1; } $ismobile = check_user_agent('mobile') == true ? 1 : 0; $ip = get_the_user_ip(); $avatar = get_avatar_url_for_chatwee($user->ID); if (isset($_COOKIE["chch-SI"])) { remote_logout(); } if (isset($_SESSION['chatwee'][$user_login])) { $previousSessionId = $_SESSION['chatwee'][$user_login]; } else { if (isset($_COOKIE["chch-PSI"])) { $previousSessionId = $_COOKIE["chch-PSI"]; } else { $previousSessionId = null; } } $url = "http://chatwee-api.com/api/remotelogin?chatId=" . $chatId . "&clientKey=" . $clientKey . "&login="******"&isAdmin=" . $isAdmin . "&ipAddress=" . $ip . "&avatar=" . $avatar . "&isMobile=" . $ismobile . "&previousSessionId=" . $previousSessionId; $url = str_replace(' ', '%20', $url); $response = get_response($url); $sessionArray = json_decode($response); if ($sessionArray->errorCode) { update_option('chatwee-settings-group[ssoiserror]', $sessionArray->errorMessage); } else { update_option('chatwee-settings-group[ssoiserror]', ''); } $sessionId = $sessionArray->sessionId; $fullDomain = $_SERVER["HTTP_HOST"]; $isNumericDomain = preg_match('/\\d|"."/', $fullDomain); if ($isNumericDomain || !get_option('chatwee-settings-group[loginallsubdomains]')) { $CookieDomain = $fullDomain; } else { $hostChunks = explode(".", $fullDomain); $hostChunks = array_slice($hostChunks, -2); $CookieDomain = "." . implode(".", $hostChunks); } setcookie("chch-SI", $sessionId, time() + 2592000, "/", $CookieDomain); $_SESSION['chatwee'][$user_login] = $_SESSION['chatwee'][$user_login] == '' ? $sessionId : $_SESSION['chatwee'][$user_login]; }
function get_content() { global $USER, $CFG, $DB, $OUTPUT; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (empty($this->instance)) { return $this->content; } //Calculate if we are in separate groups $isseparategroups = $this->page->course->groupmode == SEPARATEGROUPS && $this->page->course->groupmodeforce && !has_capability('moodle/site:accessallgroups', $this->page->context); $currentgroup = $isseparategroups ? groups_get_course_group($this->page->course) : NULL; if ($this->page->course->id == SITEID or $this->page->context->contextlevel < CONTEXT_COURSE) { // Site-level //Only show if is admin if (!checkIfUserIsAdmin()) { return ''; } } else { //Only show if is teacher or admin if (!checkIfUserIsTeacher($this->page->course->id)) { return ''; } } //Get the user current group $users = getUserList($currentgroup, $this->page->course->id, $this->page->context->contextlevel, $this->page->context); //Now, we have in users, the list of users to show //Because they are online if (!empty($users)) { //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string). //Accessibility: Converted <div> to <ul>, inherit existing classes & styles. $this->content->text .= "<ul class='list'>\n"; if (isloggedin() && has_capability('moodle/site:sendmessage', $this->page->context) && !empty($CFG->messaging) && !isguestuser()) { $canshowicon = true; } else { $canshowicon = false; } foreach ($users as $user) { $this->content->text .= '<li class="listentry">'; if (isguestuser($user)) { $this->content->text .= '<div class="user">' . $OUTPUT->user_picture($user, array('size' => 16, 'alttext' => false)); $this->content->text .= get_string('guestuser') . '</div>'; } else { $this->content->text .= '<div class="user">'; $this->content->text .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $this->page->course->id . '">'; $this->content->text .= $OUTPUT->user_picture($user, array('size' => 16, 'alttext' => false, 'link' => false)) . $user->fullname . '</a></div>'; } if ($canshowicon and $USER->id != $user->id and !isguestuser($user)) { // Only when logged in and messaging active etc $anchortagcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/delete') . '" alt="' . get_string("deletesession", "block_uniquelogin_list") . '" />'; $anchortag = '<a href="' . $CFG->wwwroot . '/blocks/uniquelogin_list/processfile.php?id=' . $user->id . '&courseid=' . $this->page->course->id . '&sesskey=' . sesskey() . '" title="' . get_string("deletesession", "block_uniquelogin_list") . '">' . $anchortagcontents . '</a>'; $this->content->text .= '<div class="message">' . $anchortag . '</div>'; $anchortagcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/message') . '" alt="' . get_string('messageselectadd') . '" />'; $anchortag = '<a href="' . $CFG->wwwroot . '/message/index.php?id=' . $user->id . '" title="' . get_string('messageselectadd') . '">' . $anchortagcontents . '</a>'; $this->content->text .= '<div class="message">' . $anchortag . '</div>'; } $this->content->text .= "</li>\n"; } $this->content->text .= '</ul><div class="clearer"><!-- --></div>'; } else { $this->content->text .= "<div class=\"info\">" . get_string("none") . "</div>"; } $this->content->text .= '<div class=\\"info\\"><a href="' . $CFG->wwwroot . '/blocks/uniquelogin_list/list_users.php?courseid=' . $this->page->course->id . '">' . get_string("seeall", "block_uniquelogin_list") . '</a></div>'; return $this->content; }