MDL-29148 MNet - improved handling of a verification function return code
[moodle.git] / course / recent_form.php
blobbeb08bc53c6b9d39edb2a745d66673a5c7b83f4e
1 <?php //$$
3 if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
7 require_once($CFG->libdir.'/formslib.php');
9 class recent_form extends moodleform {
10 function definition() {
11 global $CFG, $COURSE, $USER;
13 $mform =& $this->_form;
14 $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
15 $modinfo = get_fast_modinfo($COURSE);
17 $mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string
19 if ($COURSE->id == SITEID) {
20 $viewparticipants = has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM));
21 } else {
22 $viewparticipants = has_capability('moodle/course:viewparticipants', $context);
25 $viewfullnames = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id));
27 if ($viewparticipants) {
28 $options = array();
29 $options[0] = get_string('allparticipants');
30 if ($guest = get_guest()) {
31 $options[$guest->id] = fullname($guest);
34 if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS) {
35 $groups = groups_get_user_groups($COURSE->id);
36 $groups = $groups[0];
37 } else {
38 $groups = '';
41 if ($courseusers = get_users_by_capability($context, 'moodle/course:view', 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname DESC', '', '', $groups)) {
42 foreach ($courseusers as $courseuser) {
43 $options[$courseuser->id] = fullname($courseuser, $viewfullnames);
46 $mform->addElement('select', 'user', get_string('participants'), $options);
47 $mform->setAdvanced('user');
50 switch ($COURSE->format) {
51 case 'weeks': $sectiontitle = get_string('week'); break;
52 case 'topics': $sectiontitle = get_string('topic'); break;
53 default: $sectiontitle = get_string('section'); break;
56 $options = array(''=>get_string('allactivities'));
57 $modsused = array();
59 foreach($modinfo->cms as $cm) {
60 if (!$cm->uservisible) {
61 continue;
63 $modsused[$cm->modname] = true;
66 foreach ($modsused as $modname=>$unused) {
67 $libfile = "$CFG->dirroot/mod/$modname/lib.php";
68 if (!file_exists($libfile)) {
69 unset($modsused[$modname]);
70 continue;
72 include_once($libfile);
73 $libfunction = $modname."_get_recent_mod_activity";
74 if (!function_exists($libfunction)) {
75 unset($modsused[$modname]);
76 continue;
78 $options["mod/$modname"] = get_string('allmods', '', get_string('modulenameplural', $modname));
81 foreach ($modinfo->sections as $section=>$cmids) {
82 $options["section/$section"] = "-- $sectiontitle $section --";
83 foreach ($cmids as $cmid) {
84 $cm = $modinfo->cms[$cmid];
85 if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
86 continue;
88 $options[$cm->id] = format_string($cm->name);
91 $mform->addElement('select', 'modid', get_string('activities'), $options);
92 $mform->setAdvanced('modid');
95 if (has_capability('moodle/site:accessallgroups', $context)) {
96 if ($groups = groups_get_all_groups($COURSE->id)) {
97 $options = array('0'=>get_string('allgroups'));
98 foreach($groups as $group) {
99 $options[$group->id] = format_string($group->name);
101 $mform->addElement('select', 'group', get_string('groups'), $options);
102 $mform->setAdvanced('group');
104 } else {
105 $mform->addElement('hidden','group');
106 $mform->setType('group', PARAM_INT);
107 $mform->setConstants(array('group'=>0));
110 $options = array('default' => get_string('bycourseorder'),
111 'dateasc' => get_string('datemostrecentlast'),
112 'datedesc' => get_string('datemostrecentfirst'));
113 $mform->addElement('select', 'sortby', get_string('sortby'), $options);
114 $mform->setAdvanced('sortby');
116 $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true));
118 $mform->addElement('hidden','id');
119 $mform->setType('id', PARAM_INT);
120 $mform->setType('courseid', PARAM_INT);
122 $this->add_action_buttons(false, get_string('showrecent'));