/** * Test the event. */ public function test_event() { global $CFG; require_once "{$CFG->libdir}/gradelib.php"; $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); $user = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($user->id, $course->id); $grade_category = grade_category::fetch_course_category($course->id); $grade_category->load_grade_item(); $grade_item = $grade_category->grade_item; $grade_item->update_final_grade($user->id, 10, 'gradebook'); $grade_grade = new grade_grade(array('userid' => $user->id, 'itemid' => $grade_item->id), true); $grade_grade->grade_item = $grade_item; $event = \core\event\user_graded::create_from_grade($grade_grade); $this->assertEventLegacyLogData(array($course->id, 'grade', 'update', '/report/grader/index.php?id=' . $course->id, $grade_item->itemname . ': ' . fullname($user)), $event); $this->assertEquals(context_course::instance($course->id), $event->get_context()); $this->assertSame($event->objecttable, 'grade_grades'); $this->assertEquals($event->objectid, $grade_grade->id); $this->assertEquals($event->other['itemid'], $grade_item->id); $this->assertTrue($event->other['overridden']); $this->assertEquals(10, $event->other['finalgrade']); // Trigger the events. $sink = $this->redirectEvents(); $event->trigger(); $result = $sink->get_events(); $sink->close(); $this->assertCount(1, $result); $event = reset($result); $this->assertEventContextNotUsed($event); $grade = $event->get_grade(); $this->assertInstanceOf('grade_grade', $grade); $this->assertEquals($grade_grade->id, $grade->id); }
/** * Return comments by pages * @param int $page * @return mixed */ function get_comments($page) { global $DB, $CFG, $USER; $params = array(); if ($page == 0) { $start = 0; } else { $start = $page * $this->perpage; } $sql = "SELECT c.id, c.contextid, c.itemid, c.commentarea, c.userid, c.content, u.firstname, u.lastname, c.timecreated\n FROM {comments} c, {user} u\n WHERE u.id=c.userid ORDER BY c.timecreated ASC"; $comments = array(); $formatoptions = array('overflowdiv' => true); if ($records = $DB->get_records_sql($sql, array(), $start, $this->perpage)) { foreach ($records as $item) { $item->fullname = fullname($item); $item->time = userdate($item->timecreated); $item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions); $comments[] = $item; unset($item->firstname); unset($item->lastname); unset($item->timecreated); } } return $comments; }
/** * @dataProvider chat_format_message_manually_provider */ public function test_chat_format_message_manually($messagetext, $system, $willreturn, $expecttext, $refreshusers, $expectbeep) { $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); $currentuser = $this->getDataGenerator()->create_user(); $this->setUser($currentuser); $otheruser = $this->getDataGenerator()->create_user(); // Replace the message texts. // These can't be done in the provider because it runs before the // test starts. $messagetext = str_replace('__CURRENTUSER__', $currentuser->id, $messagetext); $messagetext = str_replace('__OTHERUSER__', $otheruser->id, $messagetext); $message = (object) ['message' => $messagetext, 'timestamp' => time(), 'system' => $system]; $result = chat_format_message_manually($message, $course->id, $currentuser, $currentuser); if (!$willreturn) { $this->assertFalse($result); } else { $this->assertNotFalse($result); if (!empty($expecttext)) { $expecttext = str_replace('__CURRENTUSER__', fullname($currentuser), $expecttext); $expecttext = str_replace('__CURRENTUSER_FIRST__', $currentuser->firstname, $expecttext); $this->assertRegexp($expecttext, $result->text); } $this->assertEquals($refreshusers, $result->refreshusers); $this->assertEquals($expectbeep, $result->beep); } }
function get_content() { global $USER, $CFG; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (empty($this->instance) or empty($USER->id) or isguest() or empty($CFG->messaging)) { return $this->content; } $this->content->footer = '<a href="' . $CFG->wwwroot . '/message/index.php" onclick="this.target=\'message\'; return openpopup(\'/message/index.php\', \'message\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">' . get_string('messages', 'message') . '</a>...'; $users = get_records_sql("SELECT m.useridfrom as id, COUNT(m.useridfrom) as count,\n u.firstname, u.lastname, u.picture, u.lastaccess\n FROM {$CFG->prefix}user u, \n {$CFG->prefix}message m \n WHERE m.useridto = '{$USER->id}' \n AND u.id = m.useridfrom\n GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess"); //Now, we have in users, the list of users to show //Because they are online if (!empty($users)) { $this->content->text .= '<ul class="list">'; foreach ($users as $user) { $timeago = format_time(time() - $user->lastaccess); $this->content->text .= '<li class="listentry"><div class="user"><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $this->instance->pageid . '" title="' . $timeago . '">'; $this->content->text .= print_user_picture($user->id, $this->instance->pageid, $user->picture, 0, true, false, '', false); $this->content->text .= fullname($user) . '</a></div>'; $this->content->text .= '<div class="message"><a href="' . $CFG->wwwroot . '/message/discussion.php?id=' . $user->id . '" onclick="this.target=\'message_' . $user->id . '\'; return openpopup(\'/message/discussion.php?id=' . $user->id . '\', \'message_' . $user->id . '\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);"><img class="iconsmall" src="' . $CFG->pixpath . '/t/message.gif" alt="" /> ' . $user->count . '</a>'; $this->content->text .= '</div></li>'; } $this->content->text .= '</ul>'; } else { $this->content->text .= '<div class="info">'; $this->content->text .= get_string('nomessages', 'message'); $this->content->text .= '</div>'; } return $this->content; }
function block_exabis_eportfolio_print_extcomments($itemid) { $stredit = get_string('edit'); $strdelete = get_string('delete'); $comments = get_records("block_exabeporitemcomm", "itemid", $itemid, 'timemodified DESC'); if (!$comments) { return; } foreach ($comments as $comment) { $user = get_record('user', 'id', $comment->userid); echo '<table cellspacing="0" class="forumpost blogpost blog" width="100%">'; echo '<tr class="header"><td class="picture left">'; print_user_picture($comment->userid, SITEID, $user->picture); echo '</td>'; echo '<td class="topic starter"><div class="author">'; $fullname = fullname($user, $comment->userid); $by = new object(); $by->name = $fullname; $by->date = userdate($comment->timemodified); print_string('bynameondate', 'forum', $by); echo '</div></td></tr>'; echo '<tr><td class="left side">'; echo '</td><td class="content">' . "\n"; echo format_text($comment->entry); echo '</td></tr></table>' . "\n\n"; } }
function get_course_students($courseID = '') { global $CFG, $DB; $users = array(); $course = $DB->get_record('course', array('id' => $courseID)); if ($course->id != SITEID) { //$courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname, u.idnumber'); $context = get_context_instance(CONTEXT_COURSE, $courseID); $query = 'select u.id as id, firstname, lastname, idnumber, imagealt, email from ' . $CFG->prefix . 'role_assignments as a, ' . $CFG->prefix . 'user as u where contextid=' . $context->id . ' and roleid=5 and a.userid=u.id;'; $courseusers = $DB->get_recordset_sql($query); } else { $courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname, u.idnumber"); } //if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) { $showusers = 1; //} if ($showusers) { if ($courseusers) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } //if ($guest = get_guest()) { // $users[$guest->id] = fullname($guest); //} } return $users; }
/** * Renders course info box. * * @param stdClass $course * @return string */ public function course_info_box(stdClass $course) { global $CFG; $context = context_course::instance($course->id); $content = ''; $content .= $this->output->box_start('generalbox info'); $summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null); $content .= format_text($summary, $course->summaryformat, array('overflowdiv' => true), $course->id); if (!empty($CFG->coursecontact)) { $coursecontactroles = explode(',', $CFG->coursecontact); foreach ($coursecontactroles as $roleid) { if ($users = get_role_users($roleid, $context, true)) { foreach ($users as $teacher) { $role = new stdClass(); $role->id = $teacher->roleid; $role->name = $teacher->rolename; $role->shortname = $teacher->roleshortname; $role->coursealias = $teacher->rolecoursealias; $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context)); $namesarray[] = role_get_name($role, $context) . ': <a href="' . $CFG->wwwroot . '/user/view.php?id=' . $teacher->id . '&course=' . SITEID . '">' . $fullname . '</a>'; } } } if (!empty($namesarray)) { $content .= "<ul class=\"teachers\">\n<li>"; $content .= implode('</li><li>', $namesarray); $content .= "</li></ul>"; } } $content .= $this->output->box_end(); return $content; }
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 definition() { global $USER, $CFG; $mform =& $this->_form; $mform->addElement('header', '', get_string('createuserandpass'), ''); $mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"'); $mform->setType('username', PARAM_NOTAGS); $mform->addRule('username', get_string('missingusername'), 'required', null, 'server'); $mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"'); $mform->setType('password', PARAM_RAW); $mform->addRule('password', get_string('missingpassword'), 'required', null, 'server'); $mform->addElement('header', '', get_string('supplyinfo'), ''); $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25"'); $mform->setType('email', PARAM_NOTAGS); $mform->addRule('email', get_string('missingemail'), 'required', null, 'server'); $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"'); $mform->setType('email2', PARAM_NOTAGS); $mform->addRule('email2', get_string('missingemail'), 'required', null, 'server'); $nameordercheck = new object(); $nameordercheck->firstname = 'a'; $nameordercheck->lastname = 'b'; if (fullname($nameordercheck) == 'b a') { // See MDL-4325 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"'); $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"'); } else { $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"'); $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"'); } $mform->setType('firstname', PARAM_TEXT); $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'server'); $mform->setType('lastname', PARAM_TEXT); $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'server'); $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="20"'); $mform->setType('city', PARAM_TEXT); $mform->addRule('city', get_string('missingcity'), 'required', null, 'server'); $country = get_list_of_countries(); $default_country[''] = get_string('selectacountry'); $country = array_merge($default_country, $country); $mform->addElement('select', 'country', get_string('country'), $country); $mform->addRule('country', get_string('missingcountry'), 'required', null, 'server'); if (!empty($CFG->country)) { $mform->setDefault('country', $CFG->country); } else { $mform->setDefault('country', ''); } if (signup_captcha_enabled()) { $mform->addElement('recaptcha', 'recaptcha_element', get_string('recaptcha', 'auth'), array('https' => $CFG->loginhttps)); $mform->setHelpButton('recaptcha_element', array('recaptcha', get_string('recaptcha', 'auth'))); } profile_signup_fields($mform); if (!empty($CFG->sitepolicy)) { $mform->addElement('header', '', get_string('policyagreement'), ''); $mform->addElement('static', 'policylink', '', '<a href="' . $CFG->sitepolicy . '" onclick="this.target=\'_blank\'">' . get_String('policyagreementclick') . '</a>'); $mform->addElement('checkbox', 'policyagreed', get_string('policyaccept')); $mform->addRule('policyagreed', get_string('policyagree'), 'required', null, 'server'); } // buttons $this->add_action_buttons(true, get_string('createaccount')); }
/** * Sends a message to the specified user from the logged user. * * @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" message to "(?P<username_string>(?:[^"]|\\")*)"$/ * @throws ElementNotFoundException * @param string $messagecontent * @param string $tousername */ public function i_send_message_to_user($messagecontent, $tousername) { global $DB; // Runs by CLI, same PHP process that created the user. $touser = $DB->get_record('user', array('username' => $tousername)); if (!$touser) { throw new ElementNotFoundException($this->getSession(), '"' . $tousername . '" '); } $tofullname = fullname($touser); $steps = array(); $steps[] = new Given('I am on homepage'); if ($this->running_javascript()) { $steps[] = new Given('I expand "My profile" node'); } $steps[] = new Given('I follow "Messages"'); $steps[] = new Given('I fill in "' . get_string('searchcombined', 'message') . '" with "' . $tofullname . '"'); $steps[] = new Given('I press "' . get_string('searchcombined', 'message') . '"'); $steps[] = new Given('I follow "' . get_string('sendmessageto', 'message', $tofullname) . '"'); $steps[] = new Given('I fill in "id_message" with "' . $messagecontent . '"'); $steps[] = new Given('I press "' . get_string('sendmessage', 'message') . '"'); return $steps; }
/** * course_report * * @param mixed $indicators * @param mixed $data * @access public * @return void */ public function course_report($indicators, $data) { global $DB, $COURSE; if (empty($data)) { return ''; } $table = new flexible_table('engagement-course-report'); $table->define_baseurl(new moodle_url('/report/engagement/index.php', array('id' => $COURSE->id))); $headers = array(); $columns = array(); $headers[] = get_string('username'); $columns[] = 'username'; foreach ($indicators as $indicator) { $headers[] = get_string('pluginname', "engagementindicator_{$indicator}"); $columns[] = "indicator_{$indicator}"; } $headers[] = get_string('total'); $columns[] = 'total'; $table->define_headers($headers); $table->define_columns($columns); $table->sortable(true, 'total', SORT_DESC); $table->no_sorting('username'); $table->column_class('username', 'student'); foreach ($indicators as $indicator) { $table->column_class("indicator_{$indicator}", 'indicator'); } $table->column_class('total', 'total'); $table->set_attribute('id', 'engagement-course-report'); $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); $table->setup(); foreach ($data as $user => $ind_data) { $row = array(); $displayname = fullname($DB->get_record('user', array('id' => $user))); $url = new moodle_url('/course/report/engagement/index.php', array('id' => $COURSE->id, 'userid' => $user)); $row[] = html_writer::link($url, $displayname); $total = 0; $total_raw = 0; foreach ($indicators as $indicator) { if (isset($ind_data["indicator_{$indicator}"]['raw'])) { $ind_value = $ind_data["indicator_{$indicator}"]['raw']; $weight = $ind_data["indicator_{$indicator}"]['weight']; } else { $ind_value = 0; $weight = 0; } $weighted_value = sprintf("%.0f%%", $ind_value * $weight * 100); $raw_value = sprintf("%.0f%%", 100 * $ind_value); $row[] = $weighted_value . " ({$raw_value})"; $total += $ind_value * $weight; $total_raw += $ind_value; } $row[] = sprintf("%.0f%%", $total * 100); $table->add_data($row); } $html = $this->output->notification(get_string('reportdescription', 'coursereport_engagement')); ob_start(); $table->finish_output(); $html .= ob_get_clean(); return $html; }
/** * Add the specified user to the group. You should be in the groups page when running this step. * * @Given /^I add "(?P<username_string>(?:[^"]|\\")*)" user to "(?P<group_name_string>(?:[^"]|\\")*)" group$/ * @throws ElementNotFoundException Thrown by behat_base::find * @param string $username * @param string $groupname */ public function i_add_user_to_group($username, $groupname) { global $DB; $user = $DB->get_record('user', array('username' => $username)); $userfullname = fullname($user); // We don't know the option text as it contains the number of users in the group. $select = $this->find_field('groups'); $xpath = "//select[@id='groups']/descendant::option[contains(., '" . $groupname . "')]"; $groupoption = $this->find('xpath', $xpath); $fulloption = $groupoption->getText(); $select->selectOption($fulloption); // Here we don't need to wait for the AJAX response. $this->find_button('Add/remove users')->click(); // Wait for add/remove members page to be loaded. $this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")'); // Getting the option and selecting it. $select = $this->find_field('addselect'); $xpath = "//select[@id='addselect']/descendant::option[contains(., '" . $userfullname . "')]"; $memberoption = $this->find('xpath', $xpath); $fulloption = $memberoption->getText(); $select->selectOption($fulloption); // Click add button. $this->find_button('Add')->click(); // Wait for the page to load. $this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")'); // Returning to the main groups page. $this->find_button('Back to groups')->click(); }
public function export_for_template(\renderer_base $output) { global $USER; $data = new \stdClass(); $data->iscurrentuser = $USER->id == $this->currentuserid; $data->currentuserid = $this->currentuserid; if ($this->otheruserid) { $data->otheruserid = $this->otheruserid; $data->otheruserfullname = fullname($this->otheruser); } $data->isonline = null; if ($this->otheruserid) { if (\core_message\helper::show_online_status($this->otheruser)) { $data->isonline = \core_message\helper::is_online($this->otheruser->lastaccess); } } $data->showonlinestatus = is_null($data->isonline) ? false : true; $data->messages = array(); foreach ($this->messages as $message) { $message = new message($message); $data->messages[] = $message->export_for_template($output); } $data->isblocked = api::is_user_blocked($this->currentuserid, $this->otheruserid); return $data; }
/** * Creates a new Hawthorn object. * @param object $course Moodle course object. If not supplied, uses $COURSE. * Only required field is ->id. */ function get_hawthorn($course = null) { global $USER, $COURSE, $CFG; if ($course == null) { $course = $COURSE; } $context = get_context_instance(CONTEXT_COURSE, $course->id); // Work out user permissions $permissions = ''; if (has_capability('block/hawthorn:chat', $context)) { $permissions .= 'rw'; } if (has_capability('block/hawthorn:moderate', $context)) { $permissions .= 'm'; } if (has_capability('block/hawthorn:admin', $context)) { $permissions .= 'a'; } // Get user picture URL $userpic = print_user_picture($USER, $COURSE->id, NULL, 0, true, false); $userpic = preg_replace('~^.*src="([^"]*)".*$~', '$1', $userpic); // Decide key expiry (ms). Usually 1 hour, unless session timeout is lower. $keyExpiry = 3600000; if ($CFG->sessiontimeout * 1000 < $keyExpiry) { // Set expiry to session timeout (note that the JS will make a re-acquire // request 5 minutes before this) $keyExpiry = $CFG->sessiontimeout * 1000; } // Get server list $servers = empty($CFG->block_hawthorn_servers) ? array() : explode(',', $CFG->block_hawthorn_servers); $magicnumber = empty($CFG->block_hawthorn_magicnumber) ? 'xxx' : $CFG->block_hawthorn_magicnumber; // Construct Hawthorn object return new hawthorn($magicnumber, $servers, hawthorn::escapeId($USER->username), fullname($USER), $userpic, $permissions, $CFG->wwwroot . '/blocks/hawthorn/hawthorn.js', $CFG->wwwroot . '/blocks/hawthorn/popup.php', $CFG->wwwroot . '/blocks/hawthorn/reacquire.php', false, $keyExpiry); }
public function definition() { global $OUTPUT; $mform = $this->_form; $user = $this->_customdata['user']; $lastupdate = $this->_customdata['lastupdate']; $dategraded = $this->_customdata['dategraded']; // Hidden params. $mform->addElement('hidden', 'userid', 0); $mform->setType('userid', PARAM_INT); $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); $mform->addElement('static', 'picture', $OUTPUT->user_picture($user), fullname($user, true) . '<br/>' . get_string('lastupdated', 'mod_giportfolio') . date('l jS \\of F Y ', $lastupdate)); $this->add_grades_section(); $mform->addElement('header', 'Feed Back', get_string('feedback', 'grades')); $mform->addElement('textarea', 'feedback', get_string('feedback', 'grades'), 'wrap="virtual" rows="10" cols="50"'); if ($dategraded) { $datestring = userdate($dategraded) . " (" . format_time(time() - $dategraded) . ")"; $mform->addElement('header', 'Last Grade', get_string('lastgrade', 'assignment')); $mform->addElement('static', 'lastgrade', get_string('lastgrade', 'mod_giportfolio') . ':', $datestring); } // Buttons. $this->add_action_buttons(); $mform->setDisableShortforms(true); }
/** * Processes the message (sends using jabber). * @param object $message the message to be sent * @return true if ok, false if error */ function send_message($message) { global $DB; if (!($userfrom = $DB->get_record('user', array('id' => $message->useridfrom)))) { return false; } if (!($userto = $DB->get_record('user', array('id' => $this->message->useridto)))) { return false; } if (!($jabberaddress = get_user_preferences('message_processor_jabber_jabberid', $userto->email, $userto->id))) { $jabberaddress = $userto->email; } $jabbermessage = fullname($userfrom) . ': ' . $message->fullmessage; $conection = new XMPPHP_XMPP(JABBER_SERVER, 5222, JABBER_USERNAME, JABBER_PASSWORD, 'moodle', JABBER_SERVER); try { $conn->connect(); $conn->processUntil('session_start'); $conn->presence(); $conn->message($jabberaddress, $jabbermessage); $conn->disconnect(); } catch (XMPPHP_Exception $e) { return false; } return true; }
function print_entry($course) { global $CFG, $USER; $strloginto = get_string("loginto", "", $course->shortname); $strcourses = get_string("courses"); $teacher = get_teacher($course->id); if ((double) $course->cost < 0) { $cost = (double) $CFG->enrol_cost; } else { $cost = (double) $course->cost; } if (abs($cost) < 0.01) { // no cost, default to base class entry to course $manual = enrolment_factory::factory('manual'); $manual->print_entry($course); } else { $navlinks = array(); $navlinks[] = array('name' => $strcourses, 'link' => "{$CFG->wwwroot}/course", 'type' => 'misc'); $navlinks[] = array('name' => $strloginto, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header($strloginto, $course->fullname, $navigation); print_course($course, "80%"); if ($course->password) { // Presenting two options print_heading(get_string('costorkey', 'enrol_paypal'), 'center'); } print_simple_box_start("center"); if ($USER->username == 'guest') { // force login only for guest user, not real users with guest role if (empty($CFG->loginhttps)) { $wwwroot = $CFG->wwwroot; } else { // This actually is not so secure ;-), 'cause we're // in unencrypted connection... $wwwroot = str_replace("http://", "https://", $CFG->wwwroot); } echo '<div align="center"><p>' . get_string('paymentrequired') . '</p>'; echo '<p><b>' . get_string('cost') . ": {$CFG->enrol_currency} {$cost}" . '</b></p>'; echo '<p><a href="' . $wwwroot . '/login/">' . get_string('loginsite') . '</a></p>'; echo '</div>'; } else { //Sanitise some fields before building the PayPal form $coursefullname = $course->fullname; $courseshortname = $course->shortname; $userfullname = fullname($USER); $userfirstname = $USER->firstname; $userlastname = $USER->lastname; $useraddress = $USER->address; $usercity = $USER->city; include $CFG->dirroot . '/enrol/paypal/enrol.html'; } print_simple_box_end(); if ($course->password) { // Second option $password = ''; include $CFG->dirroot . '/enrol/manual/enrol.html'; } print_footer(); } }
/** * Return comments by pages * * @global moodle_database $DB * @param int $page * @return array An array of comments */ function get_comments($page) { global $DB; if ($page == 0) { $start = 0; } else { $start = $page * $this->perpage; } $comments = array(); $sql = "SELECT c.id, c.contextid, c.itemid, c.commentarea, c.userid, c.content, u.firstname, u.lastname, c.timecreated\n FROM {comments} c\n JOIN {user} u\n ON u.id=c.userid\n ORDER BY c.timecreated ASC"; $rs = $DB->get_recordset_sql($sql, null, $start, $this->perpage); $formatoptions = array('overflowdiv' => true); foreach ($rs as $item) { // Set calculated fields $item->fullname = fullname($item); $item->time = userdate($item->timecreated); $item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions); // Unset fields not related to the comment unset($item->firstname); unset($item->lastname); unset($item->timecreated); // Record the comment $comments[] = $item; } $rs->close(); return $comments; }
public function earlier_user_menu() { global $USER, $CFG, $OUTPUT; if ($CFG->branch > "27") { return ''; } $uname = fullname($USER, true); $dlink = new moodle_url("/my"); $plink = new moodle_url("/user/profile.php", array("id" => $USER->id)); $lo = new moodle_url('/login/logout.php', array('sesskey' => sesskey())); $content = '<li class="dropdown no-divider"> <a class="dropdown-toggle" data-toggle="dropdown" href="#"> ' . $uname . ' <i class="fa fa-chevron-down"></i><span class="caretup"></span> </a> <ul class="dropdown-menu"> <li><a href="' . $dlink . '">Dashboard</a></li> <li><a href="' . $plink . '">Profile</a></li> <li><a href="' . $lo . '">Logout</a></li> </ul> </li>'; return $content; }
/** * Add the specified user to the group. You should be in the groups page when running this step. * * @Given /^I add "(?P<username_string>(?:[^"]|\\")*)" user to "(?P<group_name_string>(?:[^"]|\\")*)" group$/ * @throws ElementNotFoundException Thrown by behat_base::find * @param string $username * @param string $groupname */ public function i_add_user_to_group($username, $groupname) { global $DB; $user = $DB->get_record('user', array('username' => $username)); $userfullname = $this->getSession()->getSelectorsHandler()->xpathLiteral(fullname($user)); // Using a xpath liternal to avoid problems with quotes and double quotes. $groupname = $this->getSession()->getSelectorsHandler()->xpathLiteral($groupname); // We don't know the option text as it contains the number of users in the group. $select = $this->find_field('groups'); $xpath = "//select[@id='groups']/descendant::option[contains(., {$groupname})]"; $groupoption = $this->find('xpath', $xpath); $fulloption = $groupoption->getText(); $select->selectOption($fulloption); // Here we don't need to wait for the AJAX response. $this->find_button(get_string('adduserstogroup', 'group'))->click(); // Wait for add/remove members page to be loaded. $this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")'); // Getting the option and selecting it. $select = $this->find_field('addselect'); $xpath = "//select[@id='addselect']/descendant::option[contains(., {$userfullname})]"; $memberoption = $this->find('xpath', $xpath); $fulloption = $memberoption->getText(); $select->selectOption($fulloption); // Click add button. $this->find_button(get_string('add'))->click(); // Wait for the page to load. $this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")'); // Returning to the main groups page. $this->find_button(get_string('backtogroups', 'group'))->click(); }
/** * Render a single contact. * * @param \stdClass $contact * * @return string */ public function contact(stdClass $contact) { $url = new moodle_url('/user/profile.php', array('id' => $contact->id)); $userpic = $this->output->user_picture($contact, array('size' => '100', 'class' => 'profilepicture')); $description = format_text($contact->description, $contact->descriptionformat); return html_writer::start_tag('li', array('class' => 'contact')) . html_writer::start_tag('div', array('class' => 'contactpic')) . $userpic . html_writer::end_tag('div') . html_writer::start_tag('a', array('href' => $url)) . fullname($contact) . html_writer::end_tag('a') . html_writer::start_tag('div', array('class' => 'contactdetails')) . $description . html_writer::end_tag('div') . html_writer::end_tag('li'); }
public function definition() { $mform = $this->_form; $mform->addElement('header', 'formheader', get_string('question', 'lesson')); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'attemptid'); $mform->setType('attemptid', PARAM_INT); $mform->addElement('hidden', 'mode', 'update'); $mform->setType('mode', PARAM_ALPHA); $mform->addElement('static', 'studentanswer', get_string('studentresponse', 'lesson', fullname($this->_customdata['user'], true))); $mform->addElement('textarea', 'response', get_string('comments', 'lesson'), array('rows'=>'15', 'cols'=>'60')); $mform->setType('response', PARAM_TEXT); $mform->addElement('select', 'score', get_string('essayscore', 'lesson'), $this->_customdata['scoreoptions']); $mform->setType('score', PARAM_INT); $this->add_action_buttons(get_string('cancel'), get_string('savechanges')); }
/** * Defines the elements of the form used to mark a quiz submission. */ public function definition() { global $OUTPUT; $mform =& $this->_form; $mform->addElement('hidden', 'attemptid'); $mform->setType('attemptid', PARAM_INT); $mform->addElement('hidden', 'questionid'); $mform->setType('questionid', PARAM_INT); $mform->addElement('hidden', 'sesskey', sesskey()); $mform->setType('sesskey', PARAM_ALPHANUM); $mform->addElement('static', 'picture', $OUTPUT->user_picture($this->_customdata->user), fullname($this->_customdata->user, true) . '<br/>' . userdate($this->_customdata->submission->timemodified) . $this->_customdata->lateness); // Now come multiple (possibly) question comment fields. // Use $attemptobj->get_questions($arrayofquestionis) for this. foreach ($this->_customdata->questions as $questionid => $question) { $mform->addElement('header', 'question' . $questionid, get_string('question', 'modulename')); // Display question text. // Display user's answer. // Display comment form. $mform->addElement('editor', 'comment[' . $questionid . ']', get_string('comment', 'quiz') . ':', null, $this->get_editor_options()); // Display grade selector. $grademenu = make_grades_menu($question->grade); $grademenu['-1'] = get_string('nograde'); // TODO broken! $attributes = array(); $mform->addElement('select', 'grade[' . $questionid . ']', get_string('grade') . ':', $grademenu, $attributes); // TODO set default to existing grade? $mform->setDefault('grade[' . $questionid . ']', -1); } }
/** * Processes the message (sends using jabber). * @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid * @return true if ok, false if error */ function send_message($eventdata) { global $CFG; if (message_output_jabber::_jabber_configured()) { //hold onto jabber id preference because /admin/cron.php sends a lot of messages at once static $jabberaddresses = array(); if (!array_key_exists($eventdata->userto->id, $jabberaddresses)) { $jabberaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_jabber_jabberid', $eventdata->userto->email, $eventdata->userto->id); } $jabberaddress = $jabberaddresses[$eventdata->userto->id]; $jabbermessage = fullname($eventdata->userfrom) . ': ' . $eventdata->smallmessage; if (!empty($eventdata->contexturl)) { $jabbermessage .= "\n" . get_string('view') . ': ' . $eventdata->contexturl; } $jabbermessage .= "\n(" . get_string('noreply', 'message') . ')'; $conn = new XMPPHP_XMPP($CFG->jabberhost, $CFG->jabberport, $CFG->jabberusername, $CFG->jabberpassword, 'moodle', $CFG->jabberserver); try { //$conn->useEncryption(false); $conn->connect(); $conn->processUntil('session_start'); $conn->presence(); $conn->message($jabberaddress, $jabbermessage); $conn->disconnect(); } catch (XMPPHP_Exception $e) { debugging($e->getMessage()); return false; } } //note that we're reporting success if message was sent or if Jabber simply isnt configured return true; }
/** * Processes the message (sends using jabber). * @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid * @return true if ok, false if error */ function send_message($eventdata) { global $CFG; if (!empty($CFG->noemailever)) { // hidden setting for development sites, set in config.php if needed debugging('$CFG->noemailever active, no jabber message sent.', DEBUG_MINIMAL); return true; } //hold onto jabber id preference because /admin/cron.php sends a lot of messages at once static $jabberaddresses = array(); if (!array_key_exists($eventdata->userto->id, $jabberaddresses)) { $jabberaddresses[$eventdata->userto->id] = get_user_preferences('message_processor_jabber_jabberid', null, $eventdata->userto->id); } $jabberaddress = $jabberaddresses[$eventdata->userto->id]; //calling s() on smallmessage causes Jabber to display things like < Jabber != a browser $jabbermessage = fullname($eventdata->userfrom) . ': ' . $eventdata->smallmessage; if (!empty($eventdata->contexturl)) { $jabbermessage .= "\n" . get_string('view') . ': ' . $eventdata->contexturl; } $jabbermessage .= "\n(" . get_string('noreply', 'message') . ')'; $conn = new XMPPHP_XMPP($CFG->jabberhost, $CFG->jabberport, $CFG->jabberusername, $CFG->jabberpassword, 'moodle', $CFG->jabberserver); try { //$conn->useEncryption(false); $conn->connect(); $conn->processUntil('session_start'); $conn->presence(); $conn->message($jabberaddress, $jabbermessage); $conn->disconnect(); } catch (XMPPHP_Exception $e) { debugging($e->getMessage()); return false; } return true; }
public function get_content() { global $CFG, $USER, $DB, $OUTPUT; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; if (isloggedin() && !isguestuser()) { $userid = $USER->id; $mentees = $DB->get_records_sql('SELECT c.instanceid, ra.userid, ra.contextid, c.id AS cid, u.id AS id, u.firstname, u.lastname, u.lastaccess, u.picture, u.imagealt, u.email FROM {role_assignments} ra, {context} c, {user} u WHERE ra.userid = ? AND ra.contextid = c.id AND c.instanceid = u.id AND c.contextlevel = ' . CONTEXT_USER, array($userid)); $timetoshowusers = 300; $timefrom = 100 * floor((time() - $timetoshowusers) / 100); $canshowmsgicon = false; $canshowblog = false; if (has_capability('moodle/site:sendmessage', $this->page->context) && !empty($CFG->messaging)) { $canshowmsgicon = true; } if ($CFG->bloglevel > 0) { $canshowblog = true; } foreach ($mentees as $record) { $this->content->text .= '<div class="mymentees_mentee">'; $this->content->text .= '<div class="mymentees_pic">' . $OUTPUT->user_picture($record, array('size' => 30)) . '</div>'; $this->content->text .= '<div class="mymentees_name"><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $record->instanceid . '&course=' . SITEID . '">' . fullname($record) . '</a></div>'; $this->content->text .= '<div>'; $gradelinkcontents = '<input type="hidden" name="studentid" value="' . $record->id . '">' . '<input type="submit" class="mymentees_grades" value="" style="background-image:url(' . $OUTPUT->pix_url('t/grades') . ');" title="' . get_string('grades') . '">'; $gradelink = '<form action="' . $CFG->wwwroot . '/blocks/mymentees/grades.php" method="post" style="display:inline">' . $gradelinkcontents . '</form>'; $this->content->text .= $gradelink . ' | '; $postlinkcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('icon', 'forum') . '" alt="' . get_string('forumposts', 'forum') . '" />'; $postlink = '<a href="' . $CFG->wwwroot . '/mod/forum/user.php?id=' . $record->id . '" title="' . get_string('forumposts', 'forum') . '">' . $postlinkcontents . '</a>'; $this->content->text .= $postlink . ' | '; if ($canshowblog) { $bloglinkcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('i/feedback') . '" alt="' . get_string('blogentries', 'blog') . '" />'; $bloglink = '<a class="mymentees_msg" href="' . $CFG->wwwroot . '/blog/index.php?userid=' . $record->id . '" title="' . get_string('blogentries', 'blog') . '">' . $bloglinkcontents . '</a>'; $this->content->text .= $bloglink . ' | '; } if ($canshowmsgicon) { $msglinkcontents = '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/message') . '" alt="' . get_string('messageselectadd') . '" />'; $msglink = '<a class="mymentees_msg" href="' . $CFG->wwwroot . '/message/index.php?id=' . $record->id . '" title="' . get_string('messageselectadd') . '">' . $msglinkcontents . '</a>'; $this->content->text .= $msglink . ' | '; } if ($record->lastaccess > $timefrom) { $this->content->text .= '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/go') . '" alt="' . get_string('online', 'block_mymentees') . '" title="' . get_string('online', 'block_mymentees') . '" />'; } else { $this->content->text .= '<img class="iconsmall" src="' . $OUTPUT->pix_url('t/stop') . '" alt="' . get_string('offline', 'block_mymentees') . '" title="' . get_string('offline', 'block_mymentees') . '" />'; } $this->content->text .= '</div></div>'; } } $this->content->footer = ''; return $this->content; }
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"; }
protected function display_content($question, $rowclasses) { if (!empty($question->modifierfirstname) && !empty($question->modifierlastname)) { $u = new \stdClass(); $u = username_load_fields_from_object($u, $question, 'modifier'); echo fullname($u); } }
/** * Returns a pretty print of the user's name. */ public function get_username() { if (method_exists($this, 'is_anonymous') && $this->is_anonymous()) { return 'Anonymous'; } $user = $this->get_user(); return fullname($user); }
/** * Process a message received and validated by the Inbound Message processor. * * @throws \core\message\inbound\processing_failed_exception * @param \stdClass $record The Inbound Message record * @param \stdClass $data The message data packet * @return bool Whether the message was successfully processed. */ public function process_message(\stdClass $record, \stdClass $data) { global $USER, $CFG; $context = \context_user::instance($USER->id); if (!has_capability('moodle/user:manageownfiles', $context)) { throw new \core\message\inbound\processing_failed_exception('emailtoprivatefilesdenied', 'moodle', $data); } // Initial setup. $component = 'user'; $filearea = 'private'; $itemid = 0; $license = $CFG->sitedefaultlicense; $author = fullname($USER); // Determine the quota space for this user. $maxbytes = $CFG->userquota; if (has_capability('moodle/user:ignoreuserquota', $context)) { $maxbytes = USER_CAN_IGNORE_FILE_SIZE_LIMITS; } // Keep track of files which were uploaded, and which were skipped. $skippedfiles = array(); $uploadedfiles = array(); $failedfiles = array(); $fs = get_file_storage(); foreach ($data->attachments as $attachmenttype => $attachments) { foreach ($attachments as $attachment) { mtrace("--- Processing attachment '{$attachment->filename}'"); if (file_is_draft_area_limit_reached($itemid, $maxbytes, $attachment->filesize)) { // The user quota will be exceeded if this file is included. $skippedfiles[] = $attachment; mtrace("---- Skipping attacment. User will be over quota."); continue; } // Create a new record for this file. $record = new \stdClass(); $record->filearea = $filearea; $record->component = $component; $record->filepath = '/'; $record->itemid = $itemid; $record->license = $license; $record->author = $author; $record->contextid = $context->id; $record->userid = $USER->id; $record->filename = $fs->get_unused_filename($context->id, $record->component, $record->filearea, $record->itemid, $record->filepath, $attachment->filename); mtrace("--> Attaching {$record->filename} to " . "/{$record->contextid}/{$record->component}/{$record->filearea}/" . "{$record->itemid}{$record->filepath}{$record->filename}"); if ($fs->create_file_from_string($record, $attachment->content)) { // File created successfully. mtrace("---- File uploaded successfully as {$record->filename}."); $uploadedfiles[] = $attachment; } else { mtrace("---- Skipping attacment. Unknown failure during creation."); $failedfiles[] = $attachment; } } } // TODO send the user a confirmation e-mail. // Note, some files may have failed because the user has been pushed over quota. This does not constitute a failure. return true; }