/** * Output a select menu of question categories. * * Categories from this course and (optionally) published categories from other courses * are included. Optionally, only categories the current user may edit can be included. * * @param integer $courseid the id of the course to get the categories for. * @param integer $published if true, include publised categories from other courses. * @param integer $only_editable if true, exclude categories this user is not allowed to edit. * @param integer $selected optionally, the id of a category to be selected by default in the dropdown. */ function question_category_select_menu($contexts, $top = false, $currentcat = 0, $selected = "", $nochildrenof = -1) { $categoriesarray = question_category_options($contexts, $top, $currentcat, false, $nochildrenof); if ($selected) { $nothing = ''; } else { $nothing = 'choose'; } choose_from_menu_nested($categoriesarray, 'category', $selected, $nothing); }
function print_mnet_log_selector_form($hostid, $course, $selecteduser = 0, $selecteddate = 'today', $modname = "", $modid = 0, $modaction = '', $selectedgroup = -1, $showcourses = 0, $showusers = 0, $logformat = 'showashtml') { 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"; if ($hosts = get_records_sql($sql)) { foreach ($hosts as $host) { $hostarray[$host->id] = $host->name; } } $hostarray[$CFG->mnet_localhost_id] = $SITE->fullname; asort($hostarray); foreach ($hostarray as $hostid => $name) { $courses = array(); $sites = array(); if ($CFG->mnet_localhost_id == $hostid) { if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { 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 { if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { $sql = "select distinct course, coursename from {$CFG->prefix}mnet_log where hostid = '{$hostid}'"; if ($ccc = get_records_sql($sql)) { foreach ($ccc as $cc) { if (1 == $cc->course) { // TODO: 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/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 = 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->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>'; }
} $roleoptions = array(); if ($roles = get_roles_used_in_context($context)) { foreach ($roles as $r) { $roleoptions[$r->id] = $r->name; } } $guestrole = get_guest_role(); if (empty($roleoptions[$guestrole->id])) { $roleoptions[$guestrole->id] = $guestrole->name; } $roleoptions = role_fix_names($roleoptions, $context); // print first controls. echo '<form class="participationselectform" action="index.php" method="get"><div>' . "\n" . '<input type="hidden" name="id" value="' . $course->id . '" />' . "\n"; echo '<label for="menuinstanceid">' . get_string('activitymodule') . '</label>' . "\n"; choose_from_menu_nested($instanceoptions, 'instanceid', $instanceid); echo '<label for="menutimefrom">' . get_string('lookback') . '</label>' . "\n"; choose_from_menu($timeoptions, 'timefrom', $timefrom); echo '<label for="menuroleid">' . get_string('showonly') . '</label>' . "\n"; choose_from_menu($roleoptions, 'roleid', $roleid, ''); echo '<label for="menuaction">' . get_string('showactions') . '</label>' . "\n"; choose_from_menu($actionoptions, 'action', $action, ''); helpbutton('participationreport', get_string('participationreport')); echo '<input type="submit" value="' . get_string('go') . '" />' . "\n</div></form>\n"; $baseurl = $CFG->wwwroot . '/course/report/participation/index.php?id=' . $course->id . '&roleid=' . $roleid . '&instanceid=' . $instanceid . '&timefrom=' . $timefrom . '&action=' . $action . '&perpage=' . $perpage; if (!empty($instanceid) && !empty($roleid)) { // from here assume we have at least the module we're using. $cm = $modinfo->cms[$instanceid]; $modulename = get_string('modulename', $cm->modname); include_once $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'; $viewfun = $cm->modname . '_get_view_actions';