function hotpot_print_report_selector(&$course, &$hotpot, &$formdata) { global $CFG; $reports = hotpot_get_report_names('overview,simplestat,fullstat'); print '<form method="post" action="' . "{$CFG->wwwroot}/mod/hotpot/report.php?hp={$hotpot->id}" . '">'; print '<table cellpadding="2" align="center">'; $menus = array(); $menus['mode'] = array(); foreach ($reports as $name) { if ($name == 'overview' || $name == 'simplestat' || $name == 'fullstat') { $module = "quiz"; // standard reports } else { if ($name == 'click' && empty($hotpot->clickreporting)) { $module = ""; // clickreporting is disabled } else { $module = "hotpot"; // custom reports } } if ($module) { $menus['mode'][$name] = get_string("report{$name}", $module); } } $menus['reportusers'] = array('allusers' => get_string('allusers', 'hotpot'), 'allparticipants' => get_string('allparticipants')); // groups if ($groups = groups_get_groups_names($course->id)) { //TODO:check. foreach ($groups as $gid => $gname) { $menus['reportusers']["group{$gid}"] = get_string('group') . ': ' . $gname; } } // get users who have ever atetmpted this HotPot $users = get_records_sql("\n SELECT\n u.id, u.firstname, u.lastname\n FROM\n {$CFG->prefix}user u,\n {$CFG->prefix}hotpot_attempts ha\n WHERE\n u.id = ha.userid AND ha.hotpot={$hotpot->id}\n ORDER BY\n u.lastname\n "); if (!empty($users)) { // get context $cm = get_coursemodule_from_instance('hotpot', $hotpot->id); $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id); $teachers = hotpot_get_users_by_capability($modulecontext, 'mod/hotpot:viewreport'); $students = hotpot_get_users_by_capability($modulecontext, 'mod/hotpot:attempt'); // current students if (!empty($students)) { $firsttime = true; foreach ($users as $user) { if (array_key_exists($user->id, $teachers)) { continue; // skip teachers } if (array_key_exists($user->id, $students)) { if ($firsttime) { $firsttime = false; // so we only do this once $menus['reportusers']['existingstudents'] = get_string('existingstudents'); $menus['reportusers'][] = '------'; } $menus['reportusers']["{$user->id}"] = fullname($user); unset($users[$user->id]); } } unset($students); } // others (former students, teachers, admins, course creators) $firsttime = true; foreach ($users as $user) { if ($firsttime) { $firsttime = false; // so we only do this once $menus['reportusers'][] = '======'; } $menus['reportusers']["{$user->id}"] = fullname($user); } } $menus['reportattempts'] = array('all' => get_string('attemptsall', 'hotpot'), 'best' => get_string('attemptsbest', 'hotpot'), 'first' => get_string('attemptsfirst', 'hotpot'), 'last' => get_string('attemptslast', 'hotpot')); print '<tr><td>'; helpbutton('reportcontent', get_string('reportcontent', 'hotpot'), 'hotpot'); print '</td><th align="right" scope="col">' . get_string('reportcontent', 'hotpot') . ':</th><td colspan="7">'; foreach ($menus as $name => $options) { $value = $formdata[$name]; print choose_from_menu($options, $name, $value, "", "", 0, true); } print '<input type="submit" value="' . get_string('reportbutton', 'hotpot') . '" /></td></tr>'; $menus = array(); $menus['reportformat'] = array(); $menus['reportformat']['htm'] = get_string('reportformathtml', 'hotpot'); if (file_exists("{$CFG->libdir}/excel") || file_exists("{$CFG->libdir}/excellib.class.php")) { $menus['reportformat']['xls'] = get_string('reportformatexcel', 'hotpot'); } $menus['reportformat']['txt'] = get_string('reportformattext', 'hotpot'); if (trim($CFG->hotpot_excelencodings)) { $menus['reportencoding'] = array(get_string('none') => ''); $encodings = explode(',', $CFG->hotpot_excelencodings); foreach ($encodings as $encoding) { $encoding = trim($encoding); if ($encoding) { $menus['reportencoding'][$encoding] = $encoding; } } } $menus['reportwrapdata'] = array('1' => get_string('yes'), '0' => get_string('no')); $menus['reportshowlegend'] = array('1' => get_string('yes'), '0' => get_string('no')); print '<tr><td>'; helpbutton('reportformat', get_string('reportformat', 'hotpot'), 'hotpot'); print '</td>'; foreach ($menus as $name => $options) { $value = $formdata[$name]; print '<th align="right" scope="col">' . get_string($name, 'hotpot') . ':</th><td>' . choose_from_menu($options, $name, $value, "", "", 0, true) . '</td>'; } print '</tr>'; print '</table>'; print '<hr size="1" noshade="noshade" />'; print '</form>' . "\n"; }
function print_recent_selector_form($course, $advancedfilter = 0, $selecteduser = 0, $selecteddate = "lastlogin", $mod = "", $modid = "activity/All", $modaction = "", $selectedgroup = "", $selectedsort = "default") { global $USER, $CFG; if ($advancedfilter) { // Get all the possible users $users = array(); if ($courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname')) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); } } if ($guest = get_guest()) { $users[$guest->id] = fullname($guest); } if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) { if ($ccc = get_records("course", "", "", "fullname")) { foreach ($ccc as $cc) { if ($cc->category) { $courses["{$cc->id}"] = "{$cc->fullname}"; } else { $courses["{$cc->id}"] = " {$cc->fullname} (Site)"; } } } asort($courses); } $activities = array(); $selectedactivity = $modid; /// 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') { // Body $strsection = get_string("week"); } else { $strsection = get_string("topic"); } $activities["activity/All"] = "All activities"; $activities["activity/Assignments"] = "All assignments"; $activities["activity/Chats"] = "All chats"; $activities["activity/Forums"] = "All forums"; $activities["activity/Quizzes"] = "All quizzes"; $activities["activity/Workshops"] = "All workshops"; $activities["section/individual"] = "------------- Individual Activities --------------"; foreach ($modinfo as $mod) { if ($mod->mod == "label") { continue; } if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->cm))) { 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}"; } } } $strftimedate = get_string("strftimedate"); $strftimedaydate = get_string("strftimedaydate"); asort($users); // 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); $dates = array(); $dates["{$USER->lastlogin}"] = get_string("lastlogin") . ", " . userdate($USER->lastlogin, $strftimedate); $dates["{$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 === "lastlogin") { $selecteddate = $USER->lastlogin; } echo '<form action="recent.php" method="get">'; echo '<input type="hidden" name="chooserecent" value="1" />'; echo "<center>"; echo "<table>"; if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) { echo "<tr><td><b>" . get_string("courses") . "</b></td><td>"; choose_from_menu($courses, "id", $course->id, ""); echo "</td></tr>"; } else { echo '<input type="hidden" name="id" value="' . $course->id . '" />'; } $sortfields = array("default" => get_string("bycourseorder"), "dateasc" => get_string("datemostrecentlast"), "datedesc" => get_string("datemostrecentfirst")); echo "<tr><td><b>" . get_string("participants") . "</b></td><td>"; choose_from_menu($users, "user", $selecteduser, get_string("allparticipants")); echo "</td>"; echo '<td align="right"><b>' . get_string("since") . '</b></td><td>'; choose_from_menu($dates, "date", $selecteddate, get_string("alldays")); echo "</td></tr>"; echo "<tr><td><b>" . get_string("activities") . "</b></td><td>"; choose_from_menu($activities, "modid", $selectedactivity, ""); echo "</td>"; echo '<td align="right"><b>' . get_string("sortby") . "</b></td><td>"; choose_from_menu($sortfields, "sortby", $selectedsort, ""); echo "</td></tr>"; echo '<tr>'; $groupmode = groupmode($course); if ($groupmode == VISIBLEGROUPS or $groupmode and has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if ($groups_names = groups_get_groups_names($course->id)) { //TODO:check. echo '<td><b>'; if ($groupmode == VISIBLEGROUPS) { print_string('groupsvisible'); } else { print_string('groupsseparate'); } echo ':</b></td><td>'; choose_from_menu($groups_names, "selectedgroup", $selectedgroup, get_string("allgroups"), "", ""); echo '</td>'; } } echo '<td colspan="2" align="right">'; echo '<input type="submit" value="' . get_string('showrecent') . '" />'; echo "</td></tr>"; echo "</table>"; $advancedlink = "<a href=\"{$CFG->wwwroot}/course/recent.php?id={$course->id}&advancedfilter=0\">" . get_string("normalfilter") . "</a>"; print_heading($advancedlink); echo "</center>"; echo "</form>"; } else { $day_list = array("1", "7", "14", "21", "30"); $strsince = get_string("since"); $strlastlogin = get_string("lastlogin"); $strday = get_string("day"); $strdays = get_string("days"); $heading = ""; foreach ($day_list as $count) { if ($count == "1") { $day = $strday; } else { $day = $strdays; } $tmpdate = time() - $count * 3600 * 24; $heading = $heading . "<a href=\"{$CFG->wwwroot}/course/recent.php?id={$course->id}&date={$tmpdate}\"> {$count} {$day}</a> | "; } $heading = $strsince . ": <a href=\"{$CFG->wwwroot}/course/recent.php?id={$course->id}\">{$strlastlogin}</a>" . " | " . $heading; print_heading($heading); $advancedlink = "<a href=\"{$CFG->wwwroot}/course/recent.php?id={$course->id}&advancedfilter=1\">" . get_string("advancedfilter") . "</a>"; print_heading($advancedlink); } }