/** * Constructor for the webquestscorm class * * Constructor for the base assignment class. * If cmid is set create the cm, course, assignment objects. * If the assignment is hidden and the user is not a teacher then * this prints a page header and notice. * * @param cmid integer, the current course module id - not set for new assignments * @param assignment object, usually null, but if we have it we pass it to save db access * @param cm object, usually null, but if we have it we pass it to save db access * @param course object, usually null, but if we have it we pass it to save db access */ function webquestscorm($cmid = 0, $webquestscorm = NULL, $cm = NULL, $course = NULL) { global $CFG; if ($cmid) { if ($cm) { $this->cm = $cm; } else { if (!($this->cm = get_coursemodule_from_id('webquestscorm', $cmid))) { error('Course Module ID was incorrect'); } } $this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id); if ($course) { $this->course = $course; } else { if (!($this->course = get_record('course', 'id', $this->cm->course))) { error('Course is misconfigured'); } } if ($webquestscorm) { $this->webquestscorm = $webquestscorm; } else { if (!($this->webquestscorm = get_record('webquestscorm', 'id', $this->cm->instance))) { error('webquestscorm ID was incorrect'); } } $this->strwebquestscorm = get_string('modulename', 'webquestscorm'); $this->strwebquestscorms = get_string('modulenameplural', 'webquestscorm'); $this->strsubmissions = get_string('submissions', 'webquestscorm'); $this->strlastmodified = get_string('lastmodified'); if ($this->course->category) { $this->navigation = "<a target=\"{$CFG->framename}\" href=\"{$CFG->wwwroot}/course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> -> " . "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">{$this->strwebquestscorms}</a> ->"; } else { $this->navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">{$this->strwebquestscorms}</a> ->"; } $this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strwebquestscorm . ': ' . format_string($this->webquestscorm->name, true)); // visibility $this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id); if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $this->context)) { $this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strwebquestscorm); print_header($this->pagetitle, $this->course->fullname, "{$this->navigation} {$this->strwebquestscorm}", "", "", true, '', navmenu($this->course, $this->cm)); notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}"); } $this->currentgroup = get_current_group($this->course->id); $this->path = $CFG->dataroot . '/' . $this->cm->course . '/moddata/webquestscorm' . '/' . $this->cm->id; } if ($this->usehtmleditor = can_use_html_editor()) { $this->defaultformat = FORMAT_HTML; } else { $this->defaultformat = FORMAT_MOODLE; } }
function journal_user_complete_index($course, $user, $journal, $journalopen, $heading) { /// Prints a journal, entry and feedback ... used on the journal index page. if (isteacher($course->id)) { $entrycount = journal_count_entries($journal, get_current_group($course->id)); $entryinfo = " (<a href=\"report.php?id={$journal->coursemodule}\">" . get_string("viewallentries", "journal", $entrycount) . "</a>)"; } else { $entryinfo = ""; } $journal->name = "<a href=\"view.php?id={$journal->coursemodule}\">" . format_string($journal->name, true) . "</a>"; if ($heading) { echo "<h3>{$heading} - {$journal->name}{$entryinfo}</h3>"; } else { echo "<h3>{$journal->name}{$entryinfo}</h3>"; } print_simple_box_start("left", "90%"); echo format_text($journal->intro, $journal->introformat); print_simple_box_end(); echo "<br clear=\"all\" />"; echo "<br />"; if (isstudent($course->id) or isteacher($course->id)) { print_simple_box_start("right", "90%"); if ($journalopen) { echo "<p align=\"right\"><a href=\"edit.php?id={$journal->coursemodule}\">"; echo get_string("edit") . "</a></p>"; } else { echo "<p align=\"right\"><a href=\"view.php?id={$journal->coursemodule}\">"; echo get_string("view") . "</a></p>"; } if ($entry = get_record("journal_entries", "userid", $user->id, "journal", $journal->id)) { if ($entry->modified) { echo "<p align=\"center\"><font size=\"1\">" . get_string("lastedited") . ": " . userdate($entry->modified) . "</font></p>"; } if ($entry->text) { echo format_text($entry->text, $entry->format); } if ($entry->teacher) { $grades = make_grades_menu($journal->assessed); journal_print_feedback($course, $entry, $grades); } } else { print_string("noentry", "journal"); } print_simple_box_end(); echo "<br clear=\"all\" />"; echo "<br />"; } }
function choice_show_results($choice, $course, $cm, $forcepublish = '') { global $CFG, $COLUMN_HEIGHT, $USER; $context = get_context_instance(CONTEXT_MODULE, $cm->id); print_heading(get_string("responses", "choice")); if (empty($forcepublish)) { //alow the publish setting to be overridden $forcepublish = $choice->publish; } $groupmode = groupmode($course, $cm); if ($groupmode > 0) { $currentgroup = get_current_group($course->id); } else { $currentgroup = 0; } $users = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', false, true); if (!$users) { print_heading(get_string("nousersyet")); } $answers = array(); if ($allresponses = get_records("choice_answers", "choiceid", $choice->id)) { foreach ($allresponses as $aa) { //TODO: rewrite with SQL if ($groupmode and $currentgroup) { if (ismember($currentgroup, $aa->userid)) { $answers[$aa->userid] = $aa; } } else { $answers[$aa->userid] = $aa; } } } $timenow = time(); foreach ($choice->option as $optionid => $text) { $useranswer[$optionid] = array(); } if (!empty($users)) { foreach ($users as $user) { if (!empty($user->id) and !empty($answers[$user->id])) { $answer = $answers[$user->id]; $useranswer[(int) $answer->optionid][] = $user; } else { $useranswer[0][] = $user; } } } foreach ($choice->option as $optionid => $text) { if (!$choice->option[$optionid]) { unset($useranswer[$optionid]); // Throw away any data that doesn't apply } } ksort($useranswer); switch ($forcepublish) { case CHOICE_PUBLISH_NAMES: $tablewidth = (int) (100.0 / count($useranswer)); if (has_capability('mod/choice:readresponses', $context)) { echo '<div id="tablecontainer">'; echo '<form id="attemptsform" method="post" action="' . $_SERVER['PHP_SELF'] . '" onsubmit="var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? \'' . addslashes(get_string('deleteattemptcheck', 'quiz')) . '\' : true);">'; echo '<div>'; echo '<input type="hidden" name="id" value="' . $cm->id . '" />'; echo '<input type="hidden" name="mode" value="overview" />'; } echo "<table cellpadding=\"5\" cellspacing=\"10\" class=\"results names\">"; echo "<tr>"; $count = 0; $columncount = array(); // number of votes in each column foreach ($useranswer as $optionid => $userlist) { $columncount[$optionid] = 0; // init counters if ($optionid) { echo "<th class=\"col{$count} header\" style=\"width:{$tablewidth}%\" scope=\"col\">"; } else { if ($choice->showunanswered) { echo "<th class=\"col{$count} header\" style=\"width:{$tablewidth}%\" scope=\"col\">"; } else { continue; } } echo format_string(choice_get_option_text($choice, $optionid)); echo "</th>"; $count++; } echo "</tr><tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if ($optionid) { echo "<td class=\"col{$count} data\" style=\"width:{$tablewidth}%;\">"; } else { if ($choice->showunanswered) { echo "<td class=\"col{$count} data\" style=\"width:{$tablewidth}%;\">"; } else { continue; } } // added empty row so that when the next iteration is empty, // we do not get <table></table> erro from w3c validator // MDL-7861 echo "<table class=\"choiceresponse\"><tr><td></td></tr>"; foreach ($userlist as $user) { if ($optionid != 0 or has_capability('mod/choice:choose', $context, $user->id, false)) { $columncount[$optionid] += 1; echo "<tr>"; if (has_capability('mod/choice:readresponses', $context) && $optionid != 0) { echo '<td class="attemptcell"><input type="checkbox" name="attemptid[]" value="' . $answers[$user->id]->id . '" /></td>'; } echo "<td class=\"picture\">"; print_user_picture($user->id, $course->id, $user->picture); echo "</td><td class=\"fullname\">"; echo "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$course->id}\">"; echo fullname($user, has_capability('moodle/site:viewfullnames', $context)); echo "</a>"; echo "</td></tr>"; } } $count++; echo "</table>"; echo "</td>"; } echo "</tr><tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if (!$optionid and !$choice->showunanswered) { continue; } echo "<td align=\"center\" class=\"count\">"; if ($choice->limitanswers && !$optionid == 0) { echo get_string("taken", "choice") . ":"; echo $columncount[$optionid]; echo "<br/>"; echo get_string("limit", "choice") . ":"; $choice_option = get_record("choice_options", "id", $optionid); echo $choice_option->maxanswers; } else { if (isset($columncount[$optionid])) { echo $columncount[$optionid]; } } echo "</td>"; $count++; } echo "</tr>"; /// Print "Select all" etc. if (has_capability('mod/choice:readresponses', $context)) { echo '<tr><td></td><td>'; echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectall', 'quiz') . '</a> / '; echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectnone', 'quiz') . '</a> '; echo ' '; $options = array('delete' => get_string('delete')); echo choose_from_menu($options, 'action', '', get_string('withselected', 'quiz'), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true); echo '<noscript id="noscriptmenuaction" style="display: inline;">'; echo '<div>'; echo '<input type="submit" value="' . get_string('go') . '" /></div></noscript>'; echo '<script type="text/javascript">' . "\n<!--\n" . 'document.getElementById("noscriptmenuaction").style.display = "none";' . "\n-->\n" . '</script>'; echo '</td><td></td></tr>'; } echo "</table>"; if (has_capability('mod/choice:readresponses', $context)) { echo "</div></form></div>"; } break; case CHOICE_PUBLISH_ANONYMOUS: $tablewidth = (int) (100.0 / count($useranswer)); echo "<table cellpadding=\"5\" cellspacing=\"0\" class=\"results anonymous\">"; echo "<tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if ($optionid) { echo "<th style=\"width:{$tablewidth}%\" class=\"col{$count} header\" scope=\"col\">"; } else { if ($choice->showunanswered) { echo "<th style=\"width:{$tablewidth}%\" class=\"col{$count} header\" scope=\"col\">"; } else { continue; } } echo format_string(choice_get_option_text($choice, $optionid)); echo "</th>"; $count++; } echo "</tr>"; $maxcolumn = 0; foreach ($useranswer as $optionid => $userlist) { if (!$optionid and !$choice->showunanswered) { continue; } $column[$optionid] = 0; foreach ($userlist as $user) { if ($optionid != 0 or has_capability('mod/choice:choose', $context, $user->id, false)) { $column[$optionid]++; } } if ($column[$optionid] > $maxcolumn) { $maxcolumn = $column[$optionid]; } } echo "<tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if (!$optionid and !$choice->showunanswered) { continue; } $height = 0; if ($maxcolumn) { $height = $COLUMN_HEIGHT * ((double) $column[$optionid] / (double) $maxcolumn); } echo "<td style=\"vertical-align:bottom\" align=\"center\" class=\"col{$count} data\">"; echo "<img src=\"column.png\" height=\"{$height}\" width=\"49\" alt=\"\" />"; echo "</td>"; $count++; } echo "</tr>"; echo "<tr>"; $count = 0; foreach ($useranswer as $optionid => $userlist) { if (!$optionid and !$choice->showunanswered) { continue; } echo "<td align=\"center\" class=\"col{$count} count\">"; if ($choice->limitanswers && !$optionid == 0) { echo get_string("taken", "choice") . ":"; echo $column[$optionid]; echo "<br/>"; echo get_string("limit", "choice") . ":"; $choice_option = get_record("choice_options", "id", $optionid); echo $choice_option->maxanswers; } else { echo $column[$optionid]; } echo "</td>"; $count++; } echo "</tr></table>"; break; } }
/** * Return a list of teachers that the current user is able to open a dialogue with * * Called by dialogue_get_available_users(). The list is used to populate a drop-down * list in the UI. The returned array of usernames is filtered to hide teacher names * if those teachers have a hidden role assignment, unless the list is being returned * for a teacher in which case those hidden teachers are listed * @param object $dialogue * @param object $context for a user in this activity * @param int $editconversationid * @return array usernames and ids */ function dialogue_get_available_teachers($dialogue, $context, $editconversationid = 0) { global $USER, $CFG; $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context); if (!($course = get_record('course', 'id', $dialogue->course))) { error('Course is misconfigured'); } if (!($cm = get_coursemodule_from_instance('dialogue', $dialogue->id, $course->id))) { error('Course Module ID was incorrect'); } // get the list of teachers (actually, those who have dialogue:manage capability) $hiddenTeachers = array(); if ($users = get_users_by_capability($context, 'mod/dialogue:manage', '', null, null, null, null, null, null, true, null)) { foreach ($users as $user) { $userRoles = get_user_roles($context, $user->id, true); foreach ($userRoles as $role) { if ($role->hidden == 1) { $hiddenTeachers[$user->id] = 1; break; } } } $canSeeHidden = false; if (has_capability('moodle/role:viewhiddenassigns', $context)) { $canSeeHidden = true; } $groupid = get_current_group($course->id); foreach ($users as $otheruser) { // ...exclude self and ... if ($USER->id != $otheruser->id) { // ...if groupmode is SEPARATEGROUPS then exclude teachers not in student's group if ($groupid and groupmode($course, $cm) == SEPARATEGROUPS) { if (!ismember($groupid, $otheruser->id)) { continue; } } if (!$canSeeHidden && array_key_exists($otheruser->id, $hiddenTeachers) && $hiddenTeachers[$otheruser->id] == 1) { continue; } // ...any already in open conversations unless multiple conversations allowed if ($dialogue->multipleconversations or count_records_select('dialogue_conversations', "dialogueid = {$dialogue->id} AND id != {$editconversationid} AND ((userid = {$USER->id} AND \n recipientid = {$otheruser->id}) OR (userid = {$otheruser->id} AND \n recipientid = {$USER->id})) AND closed = 0") == 0) { $names[$otheruser->id] = fullname($otheruser); } } } } if (isset($names)) { natcasesort($names); return $names; } return; }
function build_logs_array($course, $user = 0, $date = 0, $order = "l.time ASC", $limitfrom = '', $limitnum = '', $modname = "", $modid = 0, $modaction = "", $groupid = 0) { // It is assumed that $date is the GMT time of midnight for that day, // and so the next 86400 seconds worth of logs are printed. /// Setup for group handling. /// If the group mode is separate, and this user does not have editing privileges, /// then only the user's group can be viewed. if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { $groupid = get_current_group($course->id); } else { if (!$course->groupmode) { $groupid = 0; } } $joins = array(); if ($course->id != SITEID || $modid != 0) { $joins[] = "l.course='{$course->id}'"; } if ($modname) { $joins[] = "l.module = '{$modname}'"; } if ('site_errors' === $modid) { $joins[] = "( l.action='error' OR l.action='infected' )"; } else { if ($modid) { $joins[] = "l.cmid = '{$modid}'"; } } if ($modaction) { $firstletter = substr($modaction, 0, 1); if (preg_match('/[[:alpha:]]/', $firstletter)) { $joins[] = "lower(l.action) LIKE '%" . strtolower($modaction) . "%'"; } else { if ($firstletter == '-') { $joins[] = "lower(l.action) NOT LIKE '%" . strtolower(substr($modaction, 1)) . "%'"; } } } /// Getting all members of a group. if ($groupid and !$user) { if ($gusers = groups_get_members($groupid)) { $gusers = array_keys($gusers); $joins[] = 'l.userid IN (' . implode(',', $gusers) . ')'; } else { $joins[] = 'l.userid = 0'; // No users in groups, so we want something that will always be false. } } else { if ($user) { $joins[] = "l.userid = '{$user}'"; } } if ($date) { $enddate = $date + 86400; $joins[] = "l.time > '{$date}' AND l.time < '{$enddate}'"; } $selector = implode(' AND ', $joins); $totalcount = 0; // Initialise $result = array(); $result['logs'] = get_logs($selector, $order, $limitfrom, $limitnum, $totalcount); $result['totalcount'] = $totalcount; return $result; }
$strweek = get_string('week'); $strtopic = get_string('topic'); $strissued = get_string('issued', 'certificate'); if ($course->format == 'weeks') { $table->head = array($strweek, $strname, $strissued); $table->align = array('CENTER', 'LEFT'); } else { if ($course->format == 'topics') { $table->head = array($strtopic, $strname, $strissued); $table->align = array('CENTER', 'LEFT', 'LEFT', 'LEFT'); } else { $table->head = array($strname, $strissued); $table->align = array('LEFT', 'LEFT', 'LEFT'); } } $currentgroup = get_current_group($course->id); if ($currentgroup and has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $id))) { $group = get_record('groups', 'id', $currentgroup); $groupname = " ({$group->name})"; } else { $groupname = ""; } $currentsection = ""; foreach ($certificates as $certificate) { if (!$certificate->visible) { //Show dimmed if the mod is hidden $link = "<a class=\"dimmed\" href=\"view.php?id={$certificate->coursemodule}\">{$certificate->name}</a>"; } else { //Show normal if the mod is visible $link = "<a href=\"view.php?id={$certificate->coursemodule}\">{$certificate->name}</a>"; }
/** * this function handles the access policy to contents indexed as searchable documents. If this * function does not exist, the search engine assumes access is allowed. * When this point is reached, we already know that : * - user is legitimate in the surrounding context * - user may be guest and guest access is allowed to the module * - the function may perform local checks within the module information logic * @param path the access path to the module script code * @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard') * @param this_id the item id within the information class denoted by itemtype. In forums, this id * points out the individual post. * @param user the user record denoting the user who searches * @param group_id the current group used by the user when searching * @uses CFG, USER * @return true if access is allowed, false elsewhere */ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id) { global $CFG, $USER; include_once "{$CFG->dirroot}/{$path}/lib.php"; // get the forum post and all related stuff $post = get_record('forum_posts', 'id', $this_id); $discussion = get_record('forum_discussions', 'id', $post->discussion); $context = get_record('context', 'id', $context_id); $cm = get_record('course_modules', 'id', $context->instanceid); if (empty($cm)) { return false; } // Shirai 20093005 - MDL19342 - course module might have been delete if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) { if (!empty($CFG->search_access_debug)) { echo "search reject : hidden forum resource "; } return false; } // approval check : entries should be approved for being viewed, or belongs to the user if ($post->userid != $USER->id && !$post->mailed && !has_capability('mod/forum:viewhiddentimeposts', $context)) { if (!empty($CFG->search_access_debug)) { echo "search reject : time hidden forum item"; } return false; } // group check : entries should be in accessible groups $current_group = get_current_group($discussion->course); $course = get_record('course', 'id', $discussion->course); if ($group_id >= 0 && groupmode($course, $cm) == SEPARATEGROUPS && $group_id != $current_group && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)) { if (!empty($CFG->search_access_debug)) { echo "search reject : separated grouped forum item"; } return false; } return true; }
function print_mnet_log_selector_form($hostid, $course, $selecteduser = 0, $selecteddate = 'today', $modname = "", $modid = 0, $modaction = '', $selectedgroup = -1, $showcourses = 0, $showusers = 0) { global $USER, $CFG, $SITE; require_once $CFG->dirroot . '/mnet/peer.php'; $mnet_peer = new mnet_peer(); $mnet_peer->set_id($hostid); $sql = "select distinct course, hostid, coursename from {$CFG->prefix}mnet_log"; $courses = get_records_sql($sql); $remotecoursecount = count($courses); // first check to see if we can override showcourses and showusers $numcourses = $remotecoursecount + count_records_select("course", "", "COUNT(id)"); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { $showcourses = 1; } $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); // Context for remote data is always SITE // Groups for remote data are always OFF if ($hostid == $CFG->mnet_localhost_id) { $context = get_context_instance(CONTEXT_COURSE, $course->id); /// Setup for group handling. if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { $selectedgroup = get_current_group($course->id); $showgroups = false; } else { if ($course->groupmode) { $selectedgroup = $selectedgroup == -1 ? get_current_group($course->id) : $selectedgroup; $showgroups = true; } else { $selectedgroup = 0; $showgroups = false; } } } else { $context = $sitecontext; } // Get all the possible users $users = array(); // If looking at a different host, we're interested in all our site users if ($hostid == $CFG->mnet_localhost_id && $course->id != SITEID) { if ($selectedgroup) { // If using a group, only get users in that group. $courseusers = get_group_users($selectedgroup, 'u.lastname ASC', '', 'u.id, u.firstname, u.lastname, u.idnumber'); } else { $courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname, u.idnumber'); } } 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); } } // Get all the hosts that have log records $sql = "select distinct\n h.id,\n h.name\n from\n {$CFG->prefix}mnet_host h,\n {$CFG->prefix}mnet_log l\n where\n h.id = l.hostid\n order by\n h.name"; $hostarray = array(); $dropdown = array(); if ($hosts = get_records_sql($sql)) { foreach ($hosts as $host) { $hostarray[$host->id] = $host->name; } } $hostarray[$CFG->mnet_localhost_id] = $SITE->fullname; asort($hostarray); // $hostid already exists foreach ($hostarray as $hostid_ => $name) { $courses = array(); $sites = array(); if (has_capability('moodle/site:viewreports', $context) && $showcourses) { if ($CFG->mnet_localhost_id == $hostid_) { if ($ccc = get_records("course", "", "", "fullname", "id,fullname,category")) { foreach ($ccc as $cc) { if ($cc->id == SITEID) { $sites["{$hostid_}/{$cc->id}"] = format_string($cc->fullname) . ' (' . get_string('site') . ')'; } else { $courses["{$hostid_}/{$cc->id}"] = format_string($cc->fullname); } } } } else { $sql = "select distinct course, coursename from mdl_mnet_log where hostid = '{$hostid_}'"; if ($ccc = get_records_sql($sql)) { foreach ($ccc as $cc) { if (1 == $cc->course) { // TODO: MDL-8187 : this might be wrong - site course may have another id $sites["{$hostid_}/{$cc->course}"] = $cc->coursename . ' (' . get_string('site') . ')'; } else { $courses["{$hostid_}/{$cc->course}"] = $cc->coursename; } } } } } asort($courses); $dropdown[$name] = $sites + $courses; } $activities = array(); $selectedactivity = ""; /// Casting $course->modinfo to string prevents one notice when the field is null if ($modinfo = unserialize((string) $course->modinfo)) { $section = 0; if ($course->format == 'weeks') { // Bodgy $strsection = get_string("week"); } else { $strsection = get_string("topic"); } foreach ($modinfo as $mod) { if ($mod->mod == "label") { continue; } if ($mod->section > 0 and $section != $mod->section) { $activities["section/{$mod->section}"] = "-------------- {$strsection} {$mod->section} --------------"; } $section = $mod->section; $mod->name = strip_tags(format_string(urldecode($mod->name), true)); if (strlen($mod->name) > 55) { $mod->name = substr($mod->name, 0, 50) . "..."; } if (!$mod->visible) { $mod->name = "(" . $mod->name . ")"; } $activities["{$mod->cm}"] = $mod->name; if ($mod->cm == $modid) { $selectedactivity = "{$mod->cm}"; } } } if (has_capability('moodle/site:viewreports', $sitecontext) && !$course->category) { $activities["site_errors"] = get_string("siteerrors"); if ($modid === "site_errors") { $selectedactivity = "site_errors"; } } $strftimedate = get_string("strftimedate"); $strftimedaydate = get_string("strftimedaydate"); asort($users); // Prepare the list of action options. $actions = array('view' => get_string('view'), 'add' => get_string('add'), 'update' => get_string('update'), 'delete' => get_string('delete'), '-view' => get_string('allchanges')); // Get all the possible dates // Note that we are keeping track of real (GMT) time and user time // User time is only used in displays - all calcs and passing is GMT $timenow = time(); // GMT // What day is it now for the user, and when is midnight that day (in GMT). $timemidnight = $today = usergetmidnight($timenow); // Put today up the top of the list $dates = array("{$timemidnight}" => get_string("today") . ", " . userdate($timenow, $strftimedate)); if (!$course->startdate or $course->startdate > $timenow) { $course->startdate = $course->timecreated; } $numdates = 1; while ($timemidnight > $course->startdate and $numdates < 365) { $timemidnight = $timemidnight - 86400; $timenow = $timenow - 86400; $dates["{$timemidnight}"] = userdate($timenow, $strftimedaydate); $numdates++; } if ($selecteddate == "today") { $selecteddate = $today; } echo "<form class=\"logselectform\" action=\"{$CFG->wwwroot}/course/report/log_timeline/index.php\" method=\"get\">\n"; echo "<div>\n"; //invisible fieldset here breaks wrapping echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; echo "<input type=\"hidden\" name=\"showusers\" value=\"{$showusers}\" />\n"; echo "<input type=\"hidden\" name=\"showcourses\" value=\"{$showcourses}\" />\n"; /* if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { $cid = empty($course->id)? '1' : $course->id; choose_from_menu_nested($dropdown, "host_course", $hostid.'/'.$cid, ""); } else { $courses = array(); $courses[$course->id] = $course->fullname . ((empty($course->category)) ? ' ('.get_string('site').') ' : ''); choose_from_menu($courses,"id",$course->id,false); if (has_capability('moodle/site:viewreports', $sitecontext)) { $a = new object(); $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser" ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers"; print_string('logtoomanycourses','moodle',$a); } } */ if ($showgroups) { if ($cgroups = get_groups($course->id)) { foreach ($cgroups as $cgroup) { $groups[$cgroup->id] = $cgroup->name; } } else { $groups = array(); } choose_from_menu($groups, "group", 0, get_string("allgroups")); // 0=$selectedgroup } if ($showusers) { choose_from_menu($users, "user", $selecteduser, get_string("allparticipants")); } else { $users = array(); if (!empty($selecteduser)) { $user = get_record('user', 'id', $selecteduser); $users[$selecteduser] = fullname($user); } else { $users[0] = get_string('allparticipants'); } choose_from_menu($users, 'user', $selecteduser, false); $a->url = "{$CFG->wwwroot}/course/report/log/index.php?chooselog=0&group={$selectedgroup}&user={$selecteduser}" . "&id={$course->id}&date={$selecteddate}&modid={$selectedactivity}&showusers=1&showcourses={$showcourses}"; print_string('logtoomanyusers', 'moodle', $a); } choose_from_menu_date($dates, "date", $selecteddate, get_string("alldays")); choose_from_menu($activities, "modid", $selectedactivity, get_string("allactivities"), "", ""); choose_from_menu($actions, 'modaction', $modaction, get_string("allactions")); echo '<input type="button" id="button_highlight" value="HighlightOff" onClick="return func_high();"/>'; echo '<input type="button" id="button_count" value="Count" onClick="count_events();"/>'; echo '</div>'; echo '</form>'; echo '<div id="menu_highlight">'; echo '</div>'; }
function exercise_print_league_table($exercise) { // print an order table of (student) submissions in grade order, only print the student's best submission when // there are multiple submissions if (!($course = get_record("course", "id", $exercise->course))) { error("Print league table: Course is misconfigured"); } $groupid = get_current_group($course->id); $nentries = $exercise->showleaguetable; if ($nentries == 99) { $nentries = 999999; // a large number } if ($exercise->anonymous and isstudent($course->id)) { $table->head = array(get_string("title", "exercise"), get_string("grade")); $table->align = array("left", "center"); $table->size = array("*", "*"); } else { // show names $table->head = array(get_string("title", "exercise"), get_string("name"), get_string("grade")); $table->align = array("left", "left", "center"); $table->size = array("*", "*", "*"); } $table->cellpadding = 2; $table->cellspacing = 0; if ($submissions = exercise_get_student_submissions($exercise, "grade", $groupid)) { $n = 1; foreach ($submissions as $submission) { if (empty($done[$submission->userid])) { if ($submission->late) { continue; } if (!($user = get_record("user", "id", $submission->userid))) { error("Print league table: user not found"); } if ($exercise->anonymous and isstudent($course->id)) { $table->data[] = array(exercise_print_submission_title($exercise, $submission), number_format($submission->grade * $exercise->grade / 100.0, 1)); } else { $table->data[] = array(exercise_print_submission_title($exercise, $submission), fullname($user), number_format($submission->grade * $exercise->grade / 100.0, 1)); } $n++; if ($n > $nentries) { break; } $done[$submission->userid] = 'ok'; } } print_heading(get_string("leaguetable", "exercise")); print_table($table); } }
function grade_download($download, $id) { global $CFG; require_login(); if (!($course = get_record("course", "id", $id))) { error("Course ID was incorrect"); } require_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $id)); $strgrades = get_string("grades"); $strgrade = get_string("grade"); $strmax = get_string("maximumshort"); $stractivityreport = get_string("activityreport"); /// Check to see if groups are being used in this course $currentgroup = get_current_group($course->id); if (($currentgroup = get_current_group($course->id)) && groupmode($course) != 0) { $students = get_group_students($currentgroup, "u.lastname ASC"); } else { $students = grade_get_course_students($course->id); } if (!empty($students)) { foreach ($students as $student) { $grades[$student->id] = array(); // Collect all grades in this array $gradeshtml[$student->id] = array(); // Collect all grades html formatted in this array $totals[$student->id] = array(); // Collect all totals in this array } } $columns = array(); // Accumulate column names in this array. $columnhtml = array(); // Accumulate column html in this array. /// Collect modules data get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); /// Search through all the modules, pulling out grade data $sections = get_all_sections($course->id); // Sort everything the same as the course for ($i = 0; $i <= $course->numsections; $i++) { if (isset($sections[$i])) { // should always be true $section = $sections[$i]; if ($section->sequence) { $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $sectionmod) { $mod = $mods[$sectionmod]; $instance = get_record("{$mod->modname}", "id", "{$mod->instance}"); $libfile = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php"; if (file_exists($libfile)) { require_once $libfile; $gradefunction = $mod->modname . "_grades"; if (function_exists($gradefunction)) { // Skip modules without grade function if ($modgrades = $gradefunction($mod->instance)) { if (!empty($modgrades->maxgrade)) { if ($mod->visible) { $maxgrade = "{$strmax}: {$modgrades->maxgrade}"; } else { $maxgrade = "{$strmax}: {$modgrades->maxgrade}"; } } else { $maxgrade = ""; } $columns[] = "{$mod->modfullname}: " . format_string($instance->name, true) . " - {$maxgrade}"; if (!empty($students)) { foreach ($students as $student) { if (!empty($modgrades->grades[$student->id])) { $grades[$student->id][] = $currentstudentgrade = $modgrades->grades[$student->id]; } else { $grades[$student->id][] = $currentstudentgrade = ""; $gradeshtml[$student->id][] = ""; } if (!empty($modgrades->maxgrade)) { $totals[$student->id] = (double) $totals[$student->id] + (double) $currentstudentgrade; } else { $totals[$student->id] = (double) $totals[$student->id] + 0; } } } } } } } } } } // a new Moodle nesting record? ;-) /// OK, we have all the data, now present it to the user /// OK, we have all the data, now present it to the user if ($download == "ods" and confirm_sesskey()) { require_once "../lib/odslib.class.php"; /// Calculate file name $downloadfilename = clean_filename("{$course->shortname} {$strgrades}.ods"); /// Creating a workbook $workbook = new MoodleODSWorkbook("-"); /// Sending HTTP headers $workbook->send($downloadfilename); /// Adding the worksheet $myxls =& $workbook->add_worksheet($strgrades); /// Print names of all the fields $myxls->write_string(0, 0, get_string("firstname")); $myxls->write_string(0, 1, get_string("lastname")); $myxls->write_string(0, 2, get_string("idnumber")); $myxls->write_string(0, 3, get_string("institution")); $myxls->write_string(0, 4, get_string("department")); $myxls->write_string(0, 5, get_string("email")); $pos = 6; foreach ($columns as $column) { $myxls->write_string(0, $pos++, strip_tags($column)); } $myxls->write_string(0, $pos, get_string("total")); /// Print all the lines of data. $i = 0; if (!empty($grades)) { foreach ($grades as $studentid => $studentgrades) { $i++; $student = $students[$studentid]; if (empty($totals[$student->id])) { $totals[$student->id] = ''; } $myxls->write_string($i, 0, $student->firstname); $myxls->write_string($i, 1, $student->lastname); $myxls->write_string($i, 2, $student->idnumber); $myxls->write_string($i, 3, $student->institution); $myxls->write_string($i, 4, $student->department); $myxls->write_string($i, 5, $student->email); $j = 6; foreach ($studentgrades as $grade) { if (is_numeric($grade)) { $myxls->write_number($i, $j++, strip_tags($grade)); } else { $myxls->write_string($i, $j++, strip_tags($grade)); } } $myxls->write_number($i, $j, $totals[$student->id]); } } /// Close the workbook $workbook->close(); exit; } else { if ($download == "xls" and confirm_sesskey()) { require_once "../lib/excellib.class.php"; /// Calculate file name $downloadfilename = clean_filename("{$course->shortname} {$strgrades}.xls"); /// Creating a workbook $workbook = new MoodleExcelWorkbook("-"); /// Sending HTTP headers $workbook->send($downloadfilename); /// Adding the worksheet $myxls =& $workbook->add_worksheet($strgrades); /// Print names of all the fields $myxls->write_string(0, 0, get_string("firstname")); $myxls->write_string(0, 1, get_string("lastname")); $myxls->write_string(0, 2, get_string("idnumber")); $myxls->write_string(0, 3, get_string("institution")); $myxls->write_string(0, 4, get_string("department")); $myxls->write_string(0, 5, get_string("email")); $pos = 6; foreach ($columns as $column) { $myxls->write_string(0, $pos++, strip_tags($column)); } $myxls->write_string(0, $pos, get_string("total")); /// Print all the lines of data. $i = 0; if (!empty($grades)) { foreach ($grades as $studentid => $studentgrades) { $i++; $student = $students[$studentid]; if (empty($totals[$student->id])) { $totals[$student->id] = ''; } $myxls->write_string($i, 0, $student->firstname); $myxls->write_string($i, 1, $student->lastname); $myxls->write_string($i, 2, $student->idnumber); $myxls->write_string($i, 3, $student->institution); $myxls->write_string($i, 4, $student->department); $myxls->write_string($i, 5, $student->email); $j = 6; foreach ($studentgrades as $grade) { if (is_numeric($grade)) { $myxls->write_number($i, $j++, strip_tags($grade)); } else { $myxls->write_string($i, $j++, strip_tags($grade)); } } $myxls->write_number($i, $j, $totals[$student->id]); } } /// Close the workbook $workbook->close(); exit; } else { if ($download == "txt" and confirm_sesskey()) { /// Print header to force download header("Content-Type: application/download\n"); $downloadfilename = clean_filename("{$course->shortname} {$strgrades}"); header("Content-Disposition: attachment; filename=\"{$downloadfilename}.txt\""); /// Print names of all the fields echo get_string("firstname") . "\t" . get_string("lastname") . "\t" . get_string("idnumber") . "\t" . get_string("institution") . "\t" . get_string("department") . "\t" . get_string("email"); foreach ($columns as $column) { $column = strip_tags($column); echo "\t{$column}"; } echo "\t" . get_string("total") . "\n"; /// Print all the lines of data. foreach ($grades as $studentid => $studentgrades) { $student = $students[$studentid]; if (empty($totals[$student->id])) { $totals[$student->id] = ''; } echo "{$student->firstname}\t{$student->lastname}\t{$student->idnumber}\t{$student->institution}\t{$student->department}\t{$student->email}"; foreach ($studentgrades as $grade) { $grade = strip_tags($grade); echo "\t{$grade}"; } echo "\t" . $totals[$student->id]; echo "\n"; } exit; } else { if ($download == '' and confirm_sesskey()) { error("No file type specified"); exit; } } } } }
/** * this function handles the access policy to contents indexed as searchable documents. If this * function does not exist, the search engine assumes access is allowed. * When this point is reached, we already know that : * - user is legitimate in the surrounding context * - user may be guest and guest access is allowed to the module * - the function may perform local checks within the module information logic * @param path the access path to the module script code * @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard') * @param this_id the item id within the information class denoted by itemtype. In databases, this id * points out an indexed data record page. * @param user the user record denoting the user who searches * @param group_id the current group used by the user when searching * @return true if access is allowed, false elsewhere */ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id) { global $CFG; // get the database object and all related stuff if ($itemtype == 'record') { $record = get_record('data_records', 'id', $this_id); } elseif ($itemtype == 'comment') { $comment = get_record('data_comments', 'id', $this_id); $record = get_record('data_records', 'id', $comment->recordid); } else { // we do not know what type of information is required return false; } $data = get_record('data', 'id', $record->dataid); $course = get_record('course', 'id', $data->course); $module_context = get_record('context', 'id', $context_id); $cm = get_record('course_modules', 'id', $module_context->instanceid); if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)) { return false; } //group consistency check : checks the following situations about groups // trap if user is not same group and groups are separated $current_group = get_current_group($course->id); if (groupmode($course) == SEPARATEGROUPS && !groups_is_member($group_id) && !has_capability('moodle/site:accessallgroups', $module_context)) { return false; } //ownership check : checks the following situations about user // trap if user is not owner and has cannot see other's entries if ($itemtype == 'record') { if ($user->id != $record->userid && !has_capability('mod/data:viewentry', $module_context) && !has_capability('mod/data:manageentries', $module_context)) { return false; } } //approval check // trap if unapproved and has not approval capabilities // TODO : report a potential capability lack of : mod/data:approve $approval = get_field('data_records', 'approved', 'id', $record->id); if (!$approval && !isteacher($data->course) && !has_capability('mod/data:manageentries', $module_context)) { return false; } //minimum records to view check // trap if too few records // TODO : report a potential capability lack of : mod/data:viewhiddenentries $recordsAmount = count_records('data_records', 'dataid', $data->id); if ($data->requiredentriestoview > $recordsAmount && !isteacher($data->course) && !has_capability('mod/data:manageentries', $module_context)) { return false; } //opening periods check // trap if user has not capability to see hidden records and date is out of opening range // TODO : report a potential capability lack of : mod/data:viewhiddenentries $now = usertime(time()); if ($data->timeviewfrom > 0) { if ($now < $data->timeviewfrom && !isteacher($data->course) && !has_capability('mod/data:manageentries', $module_context)) { return false; } } if ($data->timeviewto > 0) { if ($now > $data->timeviewto && !isteacher($data->course) && !has_capability('mod/data:manageentries', $module_context)) { return false; } } return true; }
function get_questions() { global $conn; $sql = 'select * from vcn_data' . (get_current_group() ? ' where group_id="' . get_current_group()->id . '"' : ''); $rs = mysql_query($sql); return $rs; }
function print_section($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%") { /// Prints a section full of activity modules global $CFG, $USER; static $groupbuttons; static $groupbuttonslink; static $isteacher; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $untracked; static $usetracking; $labelformatoptions = new stdClass(); if (!isset($isteacher)) { $groupbuttons = ($course->groupmode or !$course->groupmodeforce); $groupbuttonslink = !$course->groupmodeforce; $isediting = isediting($course->id); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'")); } include_once $CFG->dirroot . '/mod/forum/lib.php'; if ($usetracking = forum_tp_can_track_forums()) { $strunreadpostsone = get_string('unreadpostsone', 'forum'); $untracked = forum_tp_get_untracked_forums($USER->id, $course->id); } } $labelformatoptions->noclean = true; /// Casting $course->modinfo to string prevents one notice when the field is null $modinfo = unserialize((string) $course->modinfo); //Acccessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { // Fix bug #5027, don't want style=\"width:$width\". echo "<ul class=\"section img-text\">\n"; $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $course->id))) { echo '<li class="activity ' . $mod->modname . '" id="module-' . $modnumber . '">'; // Unique ID if ($ismoving) { if ($mod->id == $USER->activitycopy) { echo "</li>\n"; continue; } echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br /> '; } $instancename = urldecode($modinfo[$modnumber]->name); $instancename = format_string($instancename, true, $course->id); if (!empty($modinfo[$modnumber]->extra)) { $extra = urldecode($modinfo[$modnumber]->extra); } else { $extra = ""; } if (!empty($modinfo[$modnumber]->icon)) { $icon = "{$CFG->pixpath}/" . urldecode($modinfo[$modnumber]->icon); } else { $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif"; } if ($mod->indent) { print_spacer(12, 20 * $mod->indent, false); } if ($mod->modname == "label") { if (!$mod->visible) { echo "<span class=\"dimmed_text\">"; } echo format_text($extra, FORMAT_HTML, $labelformatoptions); if (!$mod->visible) { echo "</span>"; } } else { // Normal activity //Accessibility: for files get description via icon. $altname = ''; if ('resource' == $mod->modname) { if (!empty($modinfo[$modnumber]->icon)) { $possaltname = $modinfo[$modnumber]->icon; $mimetype = mimeinfo_from_icon('type', $possaltname); $altname = get_mimetype_description($mimetype); //get_string($mimetype, 'mimetypes'); } else { $altname = $mod->modfullname; } } else { $altname = $mod->modfullname; } // Avoid unnecessary duplication. if (false !== stripos($instancename, $altname)) { $altname = ''; } // File type after name, for alphabetic lists. if ($altname) { $altname = get_accesshide(' ' . $altname); } $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>'; } if ($usetracking && $mod->modname == 'forum') { $groupmode = groupmode($course, $mod); $groupid = $groupmode == SEPARATEGROUPS && !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id)) ? get_current_group($course->id) : false; if (forum_tp_can_track_forums() && !isset($untracked[$mod->instance])) { $unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid); if ($unread) { echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">'; if ($unread == 1) { echo $strunreadpostsone; } else { print_string('unreadpostsnumber', 'forum', $unread); } echo '</a> </span>'; } } } if ($isediting) { // TODO: we must define this as mod property! if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } echo ' '; echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); } echo "</li>\n"; } } } elseif ($ismoving) { echo "<ul class=\"section\">\n"; } if ($ismoving) { echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li> '; } if (!empty($section->sequence) || $ismoving) { echo "</ul><!--class='section'-->\n\n"; } }
/** * Display a single submission, ready for grading on a popup window * * This default method prints the teacher info and submissioncomment box at the top and * the student info and submission at the bottom. * This method also fetches the necessary data in order to be able to * provide a "Next submission" button. * Calls preprocess_submission() to give assignment type plug-ins a chance * to process submissions before they are graded * This method gets its arguments from the page parameters userid and offset */ function display_submission($extra_javascript = '') { global $CFG; $userid = optional_param('userid', PARAM_INT); $offset = required_param('offset', PARAM_INT); //offset for where to start looking for student. //echo '<p>userid: '.$userid; if (!($user = get_record('user', 'id', $userid))) { error('No such user!'); } if (!($submission = $this->get_submission($user->id))) { $submission = $this->prepare_new_submission($userid); } if ($submission->timemodified > $submission->timemarked) { $subtype = 'webquestscormnew'; } else { $subtype = 'webquestscormold'; } /// Get all teachers and students $currentgroup = get_current_group($this->course->id); if ($currentgroup) { $users = get_group_users($currentgroup); } else { $users = get_users_by_capability($this->context, 'mod/webquestscorm:submit'); //$users = get_course_users($this->course->id); } $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked '; $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'webquestscorm_submissions s ON u.id = s.userid AND s.webquestscorm = ' . $this->wqid . ' ' . 'WHERE u.id IN (' . implode(',', array_keys($users)) . ') '; require_once $CFG->libdir . '/tablelib.php'; if ($sort = flexible_table::get_sql_sort('mod-webquestscorm-submissions')) { $sort = 'ORDER BY ' . $sort . ' '; } $nextid = 0; if (($auser = get_records_sql($select . $sql . $sort, $offset + 1, 1)) !== false) { $nextuser = array_shift($auser); /// Calculate user status $nextuser->status = $nextuser->timemarked > 0 && $nextuser->timemarked >= $nextuser->timemodified; $nextid = $nextuser->id; } print_header(get_string('feedback', 'webquestscorm') . ':' . fullname($user, true) . ':' . format_string($this->wqname)); /// Print any extra javascript needed for saveandnext echo $extra_javascript; ///SOme javascript to help with setting up >.> echo '<script type="text/javascript">' . "\n"; echo 'function setNext(){' . "\n"; echo 'document.submitform.mode.value=\'next\';' . "\n"; echo 'document.submitform.userid.value="' . $nextid . '";' . "\n"; echo '}' . "\n"; echo 'function saveNext(){' . "\n"; echo 'document.submitform.mode.value=\'saveandnext\';' . "\n"; echo 'document.submitform.userid.value="' . $nextid . '";' . "\n"; echo 'document.submitform.saveuserid.value="' . $userid . '";' . "\n"; echo 'document.submitform.menuindex.value = document.submitform.grade.selectedIndex;' . "\n"; echo '}' . "\n"; echo '</script>' . "\n"; echo '<table cellspacing="0" class="feedback ' . $subtype . '" >'; ///Start of teacher info row echo '<tr>'; echo '<td width="35" valign="top" class="picture teacher">'; if ($submission->teacher) { $teacher = get_record('user', 'id', $submission->teacher); } else { global $USER; $teacher = $USER; } print_user_picture($teacher->id, $this->course->id, $teacher->picture); echo '</td>'; echo '<td class="content">'; echo '<form name="submitform" action="submissions.php?cmid=' . $this->cm->id . '" method="post">'; echo '<input type="hidden" name="offset" value="' . ++$offset . '">'; echo '<input type="hidden" name="userid" value="' . $userid . '" />'; echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />'; echo '<input type="hidden" name="mode" value="grade" />'; //echo '<input type="hidden" name="tabs" value="required" />'; echo '<input type="hidden" name="menuindex" value="0" />'; //selected menu index //new hidden field, initialized to -1. echo '<input type="hidden" name="saveuserid" value="-1" />'; if ($submission->timemarked) { echo '<div class="from">'; echo '<div class="fullname">' . fullname($teacher, true) . '</div>'; echo '<div class="time">' . userdate($submission->timemarked) . '</div>'; echo '</div>'; } echo '<div class="grade">' . get_string('grade') . ':'; choose_from_menu(make_grades_menu($this->wqgrade), 'grade', $submission->grade, get_string('nograde'), '', -1); echo '</div>'; echo '<div class="clearer"></div>'; echo '<br />'; if ($usehtmleditor = can_use_html_editor()) { $defaultformat = FORMAT_HTML; $editorfields = ''; } else { $defaultformat = FORMAT_MOODLE; } print_textarea($usehtmleditor, 14, 58, 0, 0, 'submissioncomment', $submission->submissioncomment, $this->course->id); if ($usehtmleditor) { echo '<input type="hidden" name="format" value="' . FORMAT_HTML . '" />'; } else { echo '<div align="right" class="format">'; choose_from_menu(format_text_menu(), "format", $submission->format, ""); helpbutton("textformat", get_string("helpformatting")); echo '</div>'; } ///Print Buttons in Single View echo '<div class="buttons" align="center">'; echo '<input type="submit" name="submit" value="' . get_string('savechanges') . '" onclick = "document.submitform.menuindex.value = document.submitform.grade.selectedIndex" />'; echo '<input type="submit" name="cancel" value="' . get_string('cancel') . '" />'; //if there are more to be graded. if ($nextid) { echo '<input type="submit" name="saveandnext" value="' . get_string('saveandnext') . '" onclick="saveNext()" />'; echo '<input type="submit" name="next" value="' . get_string('next') . '" onclick="setNext();" />'; } echo '</div>'; echo '</form>'; /* $customfeedback = $this->custom_feedbackform($submission, true); if (!empty($customfeedback)) { echo $customfeedback; } */ echo '</td></tr>'; ///End of teacher info row, Start of student info row echo '<tr>'; echo '<td width="35" valign="top" class="picture user">'; print_user_picture($user->id, $this->course->id, $user->picture); echo '</td>'; echo '<td class="topic">'; echo '<div class="from">'; echo '<div class="fullname">' . fullname($user, true) . '</div>'; if ($submission->timemodified) { echo '<div class="time">' . userdate($submission->timemodified) . $this->display_lateness($submission->timemodified, $this->wqtimedue) . '</div>'; } echo '</div>'; $this->print_user_files($user->id); echo '</td>'; echo '</tr>'; ///End of student info row echo '</table>'; if ($usehtmleditor) { use_html_editor(); } }
/** * a raster for xls printing of a report structure header * with all the relevant data about a user. * */ function training_reports_print_header_xls(&$worksheet, $userid, $courseid, $data, $xls_formats) { global $CFG; $user = get_record('user', 'id', $userid); $course = get_record('course', 'id', $courseid); $row = 0; $worksheet->set_row(0, 40, $xls_formats['t']); $worksheet->write_string($row, 0, get_string('sessionreports', 'report_trainingsessions'), $xls_formats['t']); $worksheet->merge_cells($row, 0, 0, 12); $row++; $worksheet->write_string($row, 0, get_string('user') . ' :', $xls_formats['p']); $worksheet->write_string($row, 1, fullname($user)); $row++; $worksheet->write_string($row, 0, get_string('email') . ' :', $xls_formats['p']); $worksheet->write_string($row, 1, $user->email); $row++; $worksheet->write_string($row, 0, get_string('city') . ' :', $xls_formats['p']); $worksheet->write_string($row, 1, $user->city); $row++; $worksheet->write_string($row, 0, get_string('institution') . ' :', $xls_formats['p']); $worksheet->write_string($row, 1, $user->institution); $row++; $worksheet->write_string($row, 0, get_string('course', 'report_trainingsessions') . ' :', $xls_formats['p']); $worksheet->write_string($row, 1, $course->fullname); $row++; $worksheet->write_string($row, 0, get_string('from') . ' :', $xls_formats['p']); $worksheet->write_string($row, 1, userdate($data->from)); $row++; $worksheet->write_string($row, 0, get_string('to') . ' :', $xls_formats['p']); $worksheet->write_string($row, 1, userdate(time())); $row++; $usergroups = groups_get_all_groups($courseid, $userid, 0, 'g.id, g.name'); // print group status $worksheet->write_string($row, 0, get_string('groups') . ' :', $xls_formats['p']); $str = ''; if (!empty($usergroups)) { foreach ($usergroups as $group) { $str = $group->name; if ($group->id == get_current_group($courseid)) { $str = "[{$str}]"; } $groupnames[] = $str; } $str = implode(', ', $groupnames); } $worksheet->write_string($row, 1, $str); $row++; $context = get_context_instance(CONTEXT_COURSE, $courseid); $worksheet->write_string($row, 0, get_string('roles') . ' :', $xls_formats['p']); $worksheet->write_string($row, 1, strip_tags(get_user_roles_in_context($userid, $context))); $row++; // print completion bar $completed = $data->done / $data->items; $remaining = 1 - $completed; $completedpc = ceil($completed * 100); $remainingpc = 100 - $completedpc; $worksheet->write_string($row, 0, get_string('done', 'report_trainingsessions'), $xls_formats['p']); $worksheet->write_string($row, 1, $data->done . ' ' . get_string('over', 'report_trainingsessions') . ' ' . $data->items . ' (' . $completedpc . ' %)'); $row++; $worksheet->write_string($row, 0, get_string('elapsed', 'report_trainingsessions') . ' :', $xls_formats['p']); $worksheet->write_number($row, 1, training_reports_format_time($data->elapsed, 'xls'), $xls_formats['zt']); $row++; $worksheet->write_string($row, 0, get_string('hits', 'report_trainingsessions') . ' :', $xls_formats['p']); $worksheet->write_number($row, 1, $data->events); return $row; }
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="js/myjs.js"></script> <script src="js/jquery-1.5.2.min.js"></script> <script src="js/js.js"></script> <link rel="stylesheet" type="text/css" href="css/style.css"> <link rel="stylesheet" type="text/css" href="css/style1.css"> </head> <body> <?php include 'include/functions.php'; //save_current_group(1);exit(); //set group if (isset($_GET['set_group']) && is_numeric($_GET['set_group'])) { change_group($_GET['set_group'], isset($_GET['active']) && $_GET['active']); } $current_group = get_current_group(); //current group ?> <div id='vcn_wrap'> <div id="header"><h1>Vaycanhan.com</h1></div> <div class="topbar"> <table> <tr> <td>|</td> <td><?php if ($current_group) { ?> <span><strong>Nhóm câu hỏi hiện tại:</strong> <?php echo $current_group->group_title; ?> (ID=<?php
/** * this function handles the access policy to contents indexed as searchable documents. If this * function does not exist, the search engine assumes access is allowed. * When this point is reached, we already know that : * - user is legitimate in the surrounding context * - user may be guest and guest access is allowed to the module * - the function may perform local checks within the module information logic * @param path the access path to the module script code * @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard') * @param this_id the item id within the information class denoted by entry_type. In chats, this id * points out a session history which is a close sequence of messages. * @param user the user record denoting the user who searches * @param group_id the current group used by the user when searching * @return true if access is allowed, false elsewhere */ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id) { global $CFG; include_once "{$CFG->dirroot}/{$path}/lib.php"; list($chat_id, $sessionstart, $sessionend) = split('-', $id); // get the chat session and all related stuff $chat = get_record('chat', 'id', $chat_id); $course = get_record('course', 'id', $chat->course); $module_context = get_record('context', 'id', $context_id); $cm = get_record('course_modules', 'id', $module_context->instanceid); if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)) { return false; } //group consistency check : checks the following situations about groups // trap if user is not same group and groups are separated $current_group = get_current_group($course->id); if (groupmode($course) == SEPARATEGROUPS && !groups_is_member($group_id) && !has_capability('moodle/site:accessallgroups', $module_context)) { return false; } //ownership check : checks the following situations about user // trap if user is not owner and has cannot see other's entries // TODO : typically may be stored into indexing cache if (!has_capability('mod/chat:readlog', $module_context)) { return false; } return true; }
/** * Constructor for the base bookings class * * Constructor for the base bookings class. * If cmid is set create the cm, course, bookings objects. * * @param cmid integer, the current course module id - not set for new bookingss * @param bookings object, usually null, but if we have it we pass it to save db access */ function bookings_base($cmid = 0, $bookings = NULL, $cm = NULL, $course = NULL) { global $CFG; if ($cmid) { if ($cm) { $this->cm = $cm; } else { if (!($this->cm = get_record('course_modules', 'id', $cmid))) { error('Course Module ID was incorrect'); } } if ($course) { $this->course = $course; } else { if (!($this->course = get_record('course', 'id', $this->cm->course))) { error('Course is misconfigured'); } } if ($bookings) { $this->bookings = $bookings; } else { if (!($this->bookings = get_record('bookings', 'id', $this->cm->instance))) { error('bookings ID was incorrect'); } } $this->strbookings = get_string('modulename', 'bookings'); $this->strbookingss = get_string('modulenameplural', 'bookings'); $this->strsubmissions = get_string('submissions', 'bookings'); $this->strlastmodified = get_string('lastmodified'); if ($this->course->category) { $this->navigation = "<a target=\"{$CFG->framename}\" href=\"{$CFG->wwwroot}/course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> -> " . "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">{$this->strbookingss}</a> ->"; } else { $this->navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">{$this->strbookingss}</a> ->"; } $this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strbookings . ': ' . format_string($this->bookings->name, true)); if (!$this->cm->visible and !isteacher($this->course->id)) { $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strbookings); print_header($pagetitle, $this->course->fullname, "{$this->navigation} {$this->strbookings}", "", "", true, '', navmenu($this->course, $this->cm)); notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}"); } $this->currentgroup = get_current_group($this->course->id); } /// Set up things for a HTML editor if it's needed if ($this->usehtmleditor = can_use_html_editor()) { $this->defaultformat = FORMAT_HTML; } else { $this->defaultformat = FORMAT_MOODLE; } }
/** * */ function forum_user_can_post_discussion($forum, $currentgroup = -1, $groupmode = -1, $cm = NULL, $context = NULL) { // $forum is an object global $USER, $SESSION; if (!$cm) { if (!($cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course))) { error('Course Module ID was incorrect'); } } if (!$context) { $context = get_context_instance(CONTEXT_MODULE, $cm->id); } if ($currentgroup == -1) { $currentgroup = get_current_group($cm->course); } if ($groupmode == -1) { if (!($course = get_record('course', 'id', $cm->course))) { error('Can not find course'); } $groupmode = groups_get_activity_groupmode($cm); } if ($forum->type == 'news') { $capname = 'mod/forum:addnews'; } else { $capname = 'mod/forum:startdiscussion'; } if (!has_capability($capname, $context)) { return false; } if ($forum->type == 'eachuser') { if (forum_user_has_posted_discussion($forum->id, $USER->id)) { return false; } } if (!$groupmode or has_capability('moodle/site:accessallgroups', $context)) { return true; } if ($currentgroup) { return groups_is_member($currentgroup); } else { //else it might be group 0 in visible mode if ($groupmode == VISIBLEGROUPS) { return true; } else { return false; } } }
function choice_show_reportlink($choice, $courseid, $cmid, $groupmode) { //TODO: rewrite with SQL $currentgroup = get_current_group($courseid); if ($allanswers = get_records("choice_answers", "choiceid", $choice->id)) { $responsecount = 0; foreach ($allanswers as $aa) { if ($groupmode and $currentgroup) { if (groups_is_member($currentgroup, $aa->userid)) { $responsecount++; } } else { $responsecount++; } } } else { $responsecount = 0; } echo '<div class="reportlink">'; echo "<a href=\"report.php?id={$cmid}\">" . get_string("viewallresponses", "choice", $responsecount) . "</a>"; echo '</div>'; }
/** * this function handles the access policy to contents indexed as searchable documents. If this * function does not exist, the search engine assumes access is allowed. * When this point is reached, we already know that : * - user is legitimate in the surrounding context * - user may be guest and guest access is allowed to the module * - the function may perform local checks within the module information logic * @param path the access path to the module script code * @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard') * @param this_id the item id within the information class denoted by itemtype. In wikies, this id * points out the indexed wiki page. * @param user the user record denoting the user who searches * @param group_id the current group used by the user when searching * @uses CFG * @return true if access is allowed, false elsewhere */ function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id) { global $CFG; // get the wiki object and all related stuff $page = get_record('wiki_pages', 'id', $id); $entry = get_record('wiki_entries', 'id', $page->wiki); $course = get_record('course', 'id', $entry->course); $context = get_record('context', 'id', $context_id); $cm = get_record('course_modules', 'id', $context->instanceid); // $cm = get_coursemodule_from_instance('wiki', $wiki->id, $wiki->course); // $context = get_record('context', 'id', $cm->id); if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) { if (!empty($CFG->search_access_debug)) { echo "search reject : hidden wiki "; } return false; } //group consistency check : checks the following situations about groups // trap if user is not same group and groups are separated $current_group = get_current_group($course->id); if (groupmode($course) == SEPARATEGROUPS && $group_id != $current_group && !has_capability('moodle/site:accessallgroups', $context)) { if (!empty($CFG->search_access_debug)) { echo "search reject : separated group owner wiki "; } return false; } return true; }
echo "<p><small>Exercise Version-> {$module->version}</small></p>"; exercise_list_submissions_for_admin($exercise); print_continue("view.php?id={$cm->id}"); } elseif ($action == 'adminupdatetitle') { if (!isteacher($course->id)) { error("Only teachers can look at this page"); } if (empty($sid)) { error("Admin Update Title: submission id missing"); } if (set_field("exercise_submissions", "title", $title, "id", $sid)) { print_heading(get_string("amendtitle", "exercise") . " " . get_string("ok")); } redirect("submissions.php?id={$cm->id}&action=adminlist"); } elseif ($action == 'displayfinalgrades') { $groupid = get_current_group($course->id); // Get all the students if (!($users = get_course_students($course->id, "u.lastname, u.firstname"))) { print_heading(get_string("nostudentsyet")); print_footer($course); exit; } // show the final grades as stored in the tables... print_heading_with_help(get_string("displayoffinalgrades", "exercise"), "finalgrades", "exercise"); echo "<center><table border=\"1\" width=\"90%\"><tr>\n"; echo "<td><b>" . $course->student . "</b></td>"; echo "<td><b>" . get_string("submission", "exercise") . "</b></td>"; echo "<td align=\"center\"><b>" . get_string("gradeforassessment", "exercise") . "</b></td>"; echo "<td align=\"center\"><b>" . get_string("gradeforsubmission", "exercise") . "</b></td>"; echo "<td align=\"center\"><b>" . get_string("overallgrade", "exercise") . "</b></td></tr>\n"; // now the weights
/** * this function handles the access policy to contents indexed as searchable documents. If this * function does not exist, the search engine assumes access is allowed. * When this point is reached, we already know that : * - user is legitimate in the surrounding context * - user may be guest and guest access is allowed to the module * - the function may perform local checks within the module information logic * @param path the access path to the module script code * @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard') * @param this_id the item id within the information class denoted by itemtype. In forums, this id * points out the individual post. * @param user the user record denoting the user who searches * @param group_id the current group used by the user when searching * @return true if access is allowed, false elsewhere */ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id) { global $CFG; include_once "{$CFG->dirroot}/{$path}/lib.php"; // get the glossary object and all related stuff $post = get_record('forum_posts', 'id', $this_id); $discussion = get_record('forum_discussions', 'id', $post->discussion); $course = get_record('course', 'id', $discussion->course); $cm = get_coursemodule_from_instance('forum', $discussion->forum, $course->id); $context_module = get_context_instance(CONTEXT_MODULE, $cm->id); if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context_module)) { return false; } // approval check : entries should be approved for being viewed, or belongs to the user if (!$post->mailed && !has_capability('mod/forum:viewhiddentimeposts', $context_module)) { return false; } // group check : entries should be in accessible groups $current_group = get_current_group($course->id); if (groupmode($course, $cm) == SEPARATEGROUPS && $group_id != $current_group && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context_module)) { return false; } return true; }
// MARSUPIAL ************* MODIFICAT -> Add extra control for just show the users confirmed and non deleted in the assigment books credentials process // 2012.09.05 @mmartinez $users_to_show = $DB->get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email FROM {user} u WHERE u.id NOT IN (SELECT DISTINCT euserid FROM {rcommon_user_credentials} WHERE isbn = '{$book->isbn}') AND deleted = 0 AND confirmed = 1{$search_where} ORDER BY lastname"); // ************ ORIGINAL //$users_to_show = $DB->get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email FROM {$CFG->prefix}user u WHERE u.id NOT IN (SELECT DISTINCT euserid FROM {$CFG->prefix}rcommon_user_credentials WHERE isbn = '{$book->isbn}'){$search_where} ORDER BY lastname"); // ************ FI } else { /// Setup for group handling. $context = context_system::instance(); // pinned blocks do not have own context if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { $selectedgroup = get_current_group($course->id); $showgroups = false; } else { if ($course->groupmode) { $selectedgroup = get_current_group($course->id); $showgroups = true; } else { $selectedgroup = 0; $showgroups = false; } } // Get all the possible users if ($course->id != SITEID) { if ($selectedgroup) { // If using a group, only get users in that group. // MARSUPIAL ************ MODIFICAT -> Deprecated code in Moodle 2.x // 2012.12.14 @abertranb require_once $CFG->dirroot . '/group/lib.php'; $users_to_show_role = groups_get_members_by_role($selectedgroup, $course->id, 'u.id,u.firstname,u.lastname,u.email', 'u.lastname ASC', 'u.id not in (SELECT DISTINCT euserid FROM ' . $CFG->prefix . 'rcommon_user_credentials WHERE isbn = \'' . $book->isbn . '\')'); $users_to_show = array();
/** * */ function forum_print_overview($courses, &$htmlarray) { global $USER, $CFG; $LIKE = sql_ilike(); if (empty($courses) || !is_array($courses) || count($courses) == 0) { return array(); } if (!($forums = get_all_instances_in_courses('forum', $courses))) { return; } // get all forum logs in ONE query (much better!) $sql = "SELECT instance,cmid,l.course,COUNT(l.id) as count FROM {$CFG->prefix}log l " . " JOIN {$CFG->prefix}course_modules cm ON cm.id = cmid " . " WHERE ("; foreach ($courses as $course) { $sql .= '(l.course = ' . $course->id . ' AND l.time > ' . $course->lastaccess . ') OR '; } $sql = substr($sql, 0, -3); // take off the last OR $sql .= ") AND l.module = 'forum' AND action {$LIKE} 'add post%' " . " AND userid != " . $USER->id . " GROUP BY cmid,l.course,instance"; if (!($new = get_records_sql($sql))) { $new = array(); // avoid warnings } // also get all forum tracking stuff ONCE. $trackingforums = array(); foreach ($forums as $forum) { if (forum_tp_can_track_forums($forum)) { $trackingforums[$forum->id] = $forum; } } if (count($trackingforums) > 0) { $cutoffdate = isset($CFG->forum_oldpostdays) ? time() - $CFG->forum_oldpostdays * 24 * 60 * 60 : 0; $sql = 'SELECT d.forum,d.course,COUNT(p.id) AS count ' . ' FROM ' . $CFG->prefix . 'forum_posts p ' . ' JOIN ' . $CFG->prefix . 'forum_discussions d ON p.discussion = d.id ' . ' LEFT JOIN ' . $CFG->prefix . 'forum_read r ON r.postid = p.id AND r.userid = ' . $USER->id . ' WHERE ('; foreach ($trackingforums as $track) { $sql .= '(d.forum = ' . $track->id . ' AND (d.groupid = -1 OR d.groupid = 0 OR d.groupid = ' . get_current_group($track->course) . ')) OR '; } $sql = substr($sql, 0, -3); // take off the last OR $sql .= ') AND p.modified >= ' . $cutoffdate . ' AND r.id is NULL GROUP BY d.forum,d.course'; if (!($unread = get_records_sql($sql))) { $unread = array(); } } else { $unread = array(); } if (empty($unread) and empty($new)) { return; } $strforum = get_string('modulename', 'forum'); $strnumunread = get_string('overviewnumunread', 'forum'); $strnumpostssince = get_string('overviewnumpostssince', 'forum'); foreach ($forums as $forum) { $str = ''; $count = 0; $thisunread = 0; $showunread = false; // either we have something from logs, or trackposts, or nothing. if (array_key_exists($forum->id, $new) && !empty($new[$forum->id])) { $count = $new[$forum->id]->count; } if (array_key_exists($forum->id, $unread)) { $thisunread = $unread[$forum->id]->count; $showunread = true; } if ($count > 0 || $thisunread > 0) { $str .= '<div class="overview forum"><div class="name">' . $strforum . ': <a title="' . $strforum . '" href="' . $CFG->wwwroot . '/mod/forum/view.php?f=' . $forum->id . '">' . $forum->name . '</a></div>'; $str .= '<div class="info">'; $str .= $count . ' ' . $strnumpostssince; if (!empty($showunread)) { $str .= '<br />' . $thisunread . ' ' . $strnumunread; } $str .= '</div></div>'; } if (!empty($str)) { if (!array_key_exists($forum->course, $htmlarray)) { $htmlarray[$forum->course] = array(); } if (!array_key_exists('forum', $htmlarray[$forum->course])) { $htmlarray[$forum->course]['forum'] = ''; // initialize, avoid warnings } $htmlarray[$forum->course]['forum'] .= $str; } } }
/** * this function handles the access policy to contents indexed as searchable documents. If this * function does not exist, the search engine assumes access is allowed. * When this point is reached, we already know that : * - user is legitimate in the surrounding context * - user may be guest and guest access is allowed to the module * - the function may perform local checks within the module information logic * @param path the access path to the module script code * @param entry_type the information subclassing (usefull for complex modules, defaults to 'standard') * @param this_id the item id within the information class denoted by entry_type. In techprojects, this id * points to the techproject instance in which all resources are indexed. * @param user the user record denoting the user who searches * @param group_id the current group used by the user when searching * @return true if access is allowed, false elsewhere */ function techproject_check_text_access($path, $entry_type, $this_id, $user, $group_id, $context_id) { global $CFG; include_once "{$CFG->dirroot}/{$path}/lib.php"; // get the techproject object and all related stuff $techproject = get_record('techproject', 'id', $this_id); $course = get_record('course', 'id', $techproject->course); $module_context = get_record('context', 'id', $context_id); $cm = get_record('course_modules', 'id', $module_context->instanceid); if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)) { return false; } //group consistency check : checks the following situations about groups // if user is guest check access capabilities for guests : // guests can see default project, and other records if groups are liberal // TODO : change guestsallowed in a capability if (isguest() && $techproject->guestsallowed) { if ($group_id && groupmode($course, $cm) == SEPARATEGROUPS) { return false; } return true; } // trap if user is not same group and groups are separated $current_group = get_current_group($course->id); if (groupmode($course) == SEPARATEGROUPS && $group_id != $current_group && $group_id) { return false; } //trap if ungroupedsees is off in strict access mode and user is not teacher if (groupmode($course) == SEPARATEGROUPS && !$techproject->ungroupedsees && !$group_id && isteacher($user->id)) { return false; } return true; }
/** * A combination function to make it easier for modules * to set up groups. * * It will use a given "groupid" parameter and try to use * that to reset the current group for the user. * * @uses VISIBLEGROUPS * @param course $course A {@link $COURSE} object * @param int $groupmode Either NOGROUPS, SEPARATEGROUPS or VISIBLEGROUPS * @param int $groupid Will try to use this optional parameter to * reset the current group for the user * @return int|false Returns the current group id or false if error. */ function get_and_set_current_group($course, $groupmode, $groupid = -1) { // Sets to the specified group, provided the current user has view permission if (!$groupmode) { // Groups don't even apply return false; } $currentgroupid = get_current_group($course->id); if ($groupid < 0) { // No change was specified return $currentgroupid; } $context = get_context_instance(CONTEXT_COURSE, $course->id); if ($groupid and $group = get_record('groups', 'id', $groupid)) { // Try to change the current group to this groupid if ($group->courseid == $course->id) { if (has_capability('moodle/site:accessallgroups', $context)) { // Sets current default group $currentgroupid = set_current_group($course->id, $groupid); } elseif ($groupmode == VISIBLEGROUPS) { // All groups are visible //if (groups_is_member($group->id)){ $currentgroupid = set_current_group($course->id, $groupid); //set this since he might post /*)}else { $currentgroupid = $group->id;*/ } elseif ($groupmode == SEPARATEGROUPS) { // student in separate groups switching if (groups_is_member($groupid)) { //check if is a member $currentgroupid = set_current_group($course->id, $groupid); //might need to set_current_group? } else { notify('You do not belong to this group! (' . $groupid . ')', 'error'); } } } } else { // When groupid = 0 it means show ALL groups // this is changed, non editting teacher needs access to group 0 as well, // for viewing work in visible groups (need to set current group for multiple pages) if (has_capability('moodle/site:accessallgroups', $context)) { // Sets current default group $currentgroupid = set_current_group($course->id, 0); } else { if ($groupmode == VISIBLEGROUPS) { // All groups are visible $currentgroupid = set_current_group($course->id, 0); } } } return $currentgroupid; }
function workshop_print_league_table($workshop) { // print an order table of (student) submissions showing teacher's and student's assessments if (!($course = get_record("course", "id", $workshop->course))) { error("Print league table: Course is misconfigured"); } if (!($cm = get_coursemodule_from_instance("workshop", $workshop->id, $workshop->course))) { error("Course Module ID was incorrect"); } // set $groupid if workshop is in SEPARATEGROUPS mode if (groupmode($course, $cm) == SEPARATEGROUPS) { $groupid = get_current_group($course->id); } else { $groupid = 0; } $nentries = $workshop->showleaguetable; if ($workshop->anonymous and workshop_is_student($workshop)) { $table->head = array(get_string("title", "workshop"), get_string("teacherassessments", "workshop", $course->teacher), get_string("studentassessments", "workshop", $course->student), get_string("overallgrade", "workshop")); $table->align = array("left", "center", "center", "center"); $table->size = array("*", "*", "*", "*"); } else { // show names $table->head = array(get_string("title", "workshop"), get_string("name"), get_string("teacherassessments", "workshop", $course->teacher), get_string("studentassessments", "workshop", $course->student), get_string("overallgrade", "workshop")); $table->align = array("left", "left", "center", "center", "center"); $table->size = array("*", "*", "*", "*", "*"); } $table->cellpadding = 2; $table->cellspacing = 0; if ($submissions = workshop_get_student_submissions($workshop)) { foreach ($submissions as $submission) { if ($groupid) { // check submission's group if (!groups_is_member($groupid, $submission->userid)) { continue; // skip this submission } } $grades[$submission->id] = workshop_submission_grade($workshop, $submission); } arsort($grades); // largest grade first reset($grades); $n = 1; while (list($submissionid, $grade) = each($grades)) { if (!($submission = get_record("workshop_submissions", "id", $submissionid))) { error("Print league table: submission not found"); } if (!($user = get_record("user", "id", $submission->userid))) { error("Print league table: user not found"); } if ($workshop->anonymous and workshop_is_student($workshop)) { $table->data[] = array(workshop_print_submission_title($workshop, $submission), workshop_print_submission_assessments($workshop, $submission, "teacher"), workshop_print_submission_assessments($workshop, $submission, "student"), $grade); } else { $table->data[] = array(workshop_print_submission_title($workshop, $submission), fullname($user), workshop_print_submission_assessments($workshop, $submission, "teacher"), workshop_print_submission_assessments($workshop, $submission, "student"), $grade); } $n++; if ($n > $nentries) { break; } } print_heading(get_string("leaguetable", "workshop")); print_table($table); workshop_print_key($workshop); } }
function print_log_selector_form($course, $selecteduser = 0, $selecteddate = 'today', $modname = "", $modid = 0, $modaction = '', $selectedgroup = -1, $showcourses = 0, $showusers = 0, $logformat = 'showashtml') { global $USER, $CFG; // first check to see if we can override showcourses and showusers $numcourses = count_records_select("course", "", "COUNT(id)"); if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) { $showcourses = 1; } $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); $context = get_context_instance(CONTEXT_COURSE, $course->id); /// Setup for group handling. if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { $selectedgroup = get_current_group($course->id); $showgroups = false; } else { if ($course->groupmode) { $selectedgroup = $selectedgroup == -1 ? get_current_group($course->id) : $selectedgroup; $showgroups = true; } else { $selectedgroup = 0; $showgroups = false; } } // Get all the possible users $users = array(); if ($course->id != SITEID) { if ($selectedgroup) { // If using a group, only get users in that group. $courseusers = get_group_users($selectedgroup, 'u.lastname ASC', '', 'u.id, u.firstname, u.lastname, u.idnumber'); } else { $courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname, u.idnumber'); } } 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); } } if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { if ($ccc = get_records("course", "", "", "fullname", "id,fullname,category")) { foreach ($ccc as $cc) { if ($cc->category) { $courses["{$cc->id}"] = format_string($cc->fullname); } else { $courses["{$cc->id}"] = format_string($cc->fullname) . ' (Site)'; } } } asort($courses); } $activities = array(); $selectedactivity = ""; /// Casting $course->modinfo to string prevents one notice when the field is null if ($modinfo = unserialize((string) $course->modinfo)) { $section = 0; if ($course->format == 'weeks') { // Bodgy $strsection = get_string("week"); } else { $strsection = get_string("topic"); } foreach ($modinfo as $mod) { if ($mod->mod == "label") { continue; } if ($mod->section > 0 and $section != $mod->section) { $activities["section/{$mod->section}"] = "-------------- {$strsection} {$mod->section} --------------"; } $section = $mod->section; $mod->name = strip_tags(format_string(urldecode($mod->name), true)); if (strlen($mod->name) > 55) { $mod->name = substr($mod->name, 0, 50) . "..."; } if (!$mod->visible) { $mod->name = "(" . $mod->name . ")"; } $activities["{$mod->cm}"] = $mod->name; if ($mod->cm == $modid) { $selectedactivity = "{$mod->cm}"; } } } if (has_capability('moodle/site:viewreports', $sitecontext) && $course->id == SITEID) { $activities["site_errors"] = get_string("siteerrors"); if ($modid === "site_errors") { $selectedactivity = "site_errors"; } } $strftimedate = get_string("strftimedate"); $strftimedaydate = get_string("strftimedaydate"); asort($users); // Prepare the list of action options. $actions = array('view' => get_string('view'), 'add' => get_string('add'), 'update' => get_string('update'), 'delete' => get_string('delete'), '-view' => get_string('allchanges')); // Get all the possible dates // Note that we are keeping track of real (GMT) time and user time // User time is only used in displays - all calcs and passing is GMT $timenow = time(); // GMT // What day is it now for the user, and when is midnight that day (in GMT). $timemidnight = $today = usergetmidnight($timenow); // Put today up the top of the list $dates = array("{$timemidnight}" => get_string("today") . ", " . userdate($timenow, $strftimedate)); if (!$course->startdate or $course->startdate > $timenow) { $course->startdate = $course->timecreated; } $numdates = 1; while ($timemidnight > $course->startdate and $numdates < 365) { $timemidnight = $timemidnight - 86400; $timenow = $timenow - 86400; $dates["{$timemidnight}"] = userdate($timenow, $strftimedaydate); $numdates++; } if ($selecteddate == "today") { $selecteddate = $today; } echo "<form class=\"logselectform\" action=\"{$CFG->wwwroot}/course/report/log/index.php\" method=\"get\">\n"; echo "<div>\n"; echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n"; echo "<input type=\"hidden\" name=\"showusers\" value=\"{$showusers}\" />\n"; echo "<input type=\"hidden\" name=\"showcourses\" value=\"{$showcourses}\" />\n"; if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { choose_from_menu($courses, "id", $course->id, ""); } else { // echo '<input type="hidden" name="id" value="'.$course->id.'" />'; $courses = array(); $courses[$course->id] = $course->fullname . ($course->id == SITEID ? ' (' . get_string('site') . ') ' : ''); choose_from_menu($courses, "id", $course->id, false); if (has_capability('moodle/site:viewreports', $sitecontext)) { $a = new object(); $a->url = "{$CFG->wwwroot}/course/report/log/index.php?chooselog=0&group={$selectedgroup}&user={$selecteduser}" . "&id={$course->id}&date={$selecteddate}&modid={$selectedactivity}&showcourses=1&showusers={$showusers}"; print_string('logtoomanycourses', 'moodle', $a); } } if ($showgroups) { if ($cgroups = groups_get_all_groups($course->id)) { foreach ($cgroups as $cgroup) { $groups[$cgroup->id] = $cgroup->name; } } else { $groups = array(); } choose_from_menu($groups, "group", $selectedgroup, get_string("allgroups")); } if ($showusers) { choose_from_menu($users, "user", $selecteduser, get_string("allparticipants")); } else { $users = array(); if (!empty($selecteduser)) { $user = get_record('user', 'id', $selecteduser); $users[$selecteduser] = fullname($user); } else { $users[0] = get_string('allparticipants'); } choose_from_menu($users, 'user', $selecteduser, false); $a = new object(); $a->url = "{$CFG->wwwroot}/course/report/log/index.php?chooselog=0&group={$selectedgroup}&user={$selecteduser}" . "&id={$course->id}&date={$selecteddate}&modid={$selectedactivity}&showusers=1&showcourses={$showcourses}"; print_string('logtoomanyusers', 'moodle', $a); } choose_from_menu($dates, "date", $selecteddate, get_string("alldays")); choose_from_menu($activities, "modid", $selectedactivity, get_string("allactivities"), "", ""); choose_from_menu($actions, 'modaction', $modaction, get_string("allactions")); $logformats = array('showashtml' => get_string('displayonpage'), 'downloadascsv' => get_string('downloadtext'), 'downloadasods' => get_string('downloadods'), 'downloadasexcel' => get_string('downloadexcel')); choose_from_menu($logformats, 'logformat', $logformat, false); echo '<input type="submit" value="' . get_string('gettheselogs') . '" />'; echo '</div>'; echo '</form>'; }
/** * this function handles the access policy to contents indexed as searchable documents. If this * function does not exist, the search engine assumes access is allowed. * When this point is reached, we already know that : * - user is legitimate in the surrounding context * - user may be guest and guest access is allowed to the module * - the function may perform local checks within the module information logic * @param string $path the access path to the module script code * @param string $itemtype the information subclassing (usefull for complex modules, defaults to 'standard') * @param int $this_id the item id within the information class denoted by itemtype. In wikies, this id * points out the indexed wiki page. * @param object $user the user record denoting the user who searches * @param int $group_id the current group used by the user when searching * @param int $context_id a context that eventually comes with the object * @uses $CFG, $DB * @return true if access is allowed, false elsewhere */ function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id) { global $CFG, $DB; // get the wiki object and all related stuff $page = $DB->get_record('wiki_pages', array('id' => $this_id)); $wiki = $DB->get_record('wiki', array('id' => $page->wiki)); $course = $DB->get_record('course', array('id' => $wiki->course)); $context = $DB->get_record('context', array('id' => $context_id)); $cm = $DB->get_record('course_modules', array('id' => $context->instanceid)); if (empty($cm)) { return false; } // Shirai 20090530 - MDL19342 - course module might have been delete if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) { if (!empty($CFG->search_access_debug)) { echo "search reject : hidden wiki "; } return false; } //group consistency check : checks the following situations about groups // trap if user is not same group and groups are separated $current_group = get_current_group($course->id); if (groupmode($course) == SEPARATEGROUPS && $group_id != $current_group && !has_capability('moodle/site:accessallgroups', $context)) { if (!empty($CFG->search_access_debug)) { echo "search reject : separated group owner wiki "; } return false; } return true; }