Exemple #1
0
function get_selection_data($ufiltering)
{
    global $SESSION, $DB;
    // get the SQL filter
    $guest = get_guest();
    list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest' => $guest->id));
    $total = $DB->count_records_select('user', "id<>:exguest AND deleted <> 1", array('exguest' => $guest->id));
    $acount = $DB->count_records_select('user', $sqlwhere, $params);
    $scount = count($SESSION->bulk_users);
    $userlist = array('acount' => $acount, 'scount' => $scount, 'ausers' => false, 'susers' => false, 'total' => $total);
    $userlist['ausers'] = $DB->get_records_select_menu('user', $sqlwhere, $params, 'fullname', 'id,' . $DB->sql_fullname() . ' AS fullname', 0, MAX_BULK_USERS);
    if ($scount) {
        if ($scount < MAX_BULK_USERS) {
            $in = implode(',', $SESSION->bulk_users);
        } else {
            $bulkusers = array_slice($SESSION->bulk_users, 0, MAX_BULK_USERS, true);
            $in = implode(',', $bulkusers);
        }
        $userlist['susers'] = $DB->get_records_select_menu('user', "id IN ({$in})", null, 'fullname', 'id,' . $DB->sql_fullname() . ' AS fullname');
    }
    return $userlist;
}
function get_selection_data($ufiltering)
{
    global $SESSION;
    // get the SQL filter
    $guest = get_guest();
    $sqlwhere = $ufiltering->get_sql_filter("id<>{$guest->id} AND deleted <> 1");
    $total = count_records_select('user', "id<>{$guest->id} AND deleted <> 1");
    $acount = count_records_select('user', $sqlwhere);
    $scount = count($SESSION->bulk_users);
    $userlist = array('acount' => $acount, 'scount' => $scount, 'ausers' => false, 'susers' => false, 'total' => $total);
    if ($scount) {
        if ($scount < MAX_BULK_USERS) {
            $in = implode(',', $SESSION->bulk_users);
        } else {
            $bulkusers = array_slice($SESSION->bulk_users, 0, MAX_BULK_USERS, true);
            $in = implode(',', $bulkusers);
        }
        $userlist['susers'] = get_records_select_menu('user', "id IN ({$in})", 'fullname', 'id,' . sql_fullname() . ' AS fullname');
        $sqlwhere .= " AND id NOT IN ({$in})";
    }
    $userlist['ausers'] = get_records_select_menu('user', $sqlwhere, 'fullname', 'id,' . sql_fullname() . ' AS fullname', 0, MAX_BULK_USERS);
    return $userlist;
}
Exemple #3
0
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>';
}
$logofile = Get_LogoFile();
access("billing");
$bill = array();
$book = array();
$guest = array();
$inv = $_GET['inv'];
get_bill($inv, $bill);
if ($bill['book_id']) {
    get_booking($bill['book_id'], $book);
} else {
    if ($bill['reservation_id']) {
        get_reservation($bill['reservation_id'], $book);
    }
}
if ($book['guestid']) {
    get_guest($book['guestid'], $guest);
}
// Default page size A4 - 210mm x 297mm
//  Header is set to 60mm
//  Footer is set to 27mm
//  body of invoice is set to 210mm
//  Rough rules of thumb
//  font 12px has 59 lines
//  font 13px has 52 lines
//  font 14px has 45 lines
$px = 12;
$LC = 55;
/**
 * Print the header for the invoice
 * @param $logofile [in] Logo for header
 * @param $px [in] Pixel size of phone
 function definition()
 {
     global $CFG, $COURSE, $USER;
     $mform =& $this->_form;
     $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     $modinfo = get_fast_modinfo($COURSE);
     $mform->addElement('header', 'filters', get_string('managefilters'));
     //TODO: add better string
     if ($COURSE->id == SITEID) {
         $viewparticipants = has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM));
     } else {
         $viewparticipants = has_capability('moodle/course:viewparticipants', $context);
     }
     $viewfullnames = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id));
     if ($viewparticipants) {
         $options = array();
         $options[0] = get_string('allparticipants');
         if ($guest = get_guest()) {
             $options[$guest->id] = fullname($guest);
         }
         if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS) {
             $groups = groups_get_user_groups($COURSE->id);
             $groups = $groups[0];
         } else {
             $groups = '';
         }
         if ($courseusers = get_users_by_capability($context, 'moodle/course:view', 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname DESC', '', '', $groups)) {
             foreach ($courseusers as $courseuser) {
                 $options[$courseuser->id] = fullname($courseuser, $viewfullnames);
             }
         }
         $mform->addElement('select', 'user', get_string('participants'), $options);
         $mform->setAdvanced('user');
     }
     switch ($COURSE->format) {
         case 'weeks':
             $sectiontitle = get_string('week');
             break;
         case 'topics':
             $sectiontitle = get_string('topic');
             break;
         default:
             $sectiontitle = get_string('section');
             break;
     }
     $options = array('' => get_string('allactivities'));
     $modsused = array();
     foreach ($modinfo->cms as $cm) {
         if (!$cm->uservisible) {
             continue;
         }
         $modsused[$cm->modname] = true;
     }
     foreach ($modsused as $modname => $unused) {
         $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php";
         if (!file_exists($libfile)) {
             unset($modsused[$modname]);
             continue;
         }
         include_once $libfile;
         $libfunction = $modname . "_get_recent_mod_activity";
         if (!function_exists($libfunction)) {
             unset($modsused[$modname]);
             continue;
         }
         $options["mod/{$modname}"] = get_string('allmods', '', get_string('modulenameplural', $modname));
     }
     foreach ($modinfo->sections as $section => $cmids) {
         $options["section/{$section}"] = "-- {$sectiontitle} {$section} --";
         foreach ($cmids as $cmid) {
             $cm = $modinfo->cms[$cmid];
             if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
                 continue;
             }
             $options[$cm->id] = format_string($cm->name);
         }
     }
     $mform->addElement('select', 'modid', get_string('activities'), $options);
     $mform->setAdvanced('modid');
     if (has_capability('moodle/site:accessallgroups', $context)) {
         if ($groups = groups_get_all_groups($COURSE->id)) {
             $options = array('0' => get_string('allgroups'));
             foreach ($groups as $group) {
                 $options[$group->id] = format_string($group->name);
             }
             $mform->addElement('select', 'group', get_string('groups'), $options);
             $mform->setAdvanced('group');
         }
     } else {
         $mform->addElement('hidden', 'group');
         $mform->setType('group', PARAM_INT);
         $mform->setConstants(array('group' => 0));
     }
     $options = array('default' => get_string('bycourseorder'), 'dateasc' => get_string('datemostrecentlast'), 'datedesc' => get_string('datemostrecentfirst'));
     $mform->addElement('select', 'sortby', get_string('sortby'), $options);
     $mform->setAdvanced('sortby');
     $mform->addElement('date_time_selector', 'date', get_string('since'), array('optional' => true));
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->setType('courseid', PARAM_INT);
     $this->add_action_buttons(false, get_string('showrecent'));
 }
                // keep allowing them to read the whole blog
                $allowedvisibility = OUBLOG_VISIBILITY_COURSEUSER;
            }
        } else {
            error('Access denied');
        }
    }
} elseif ($loggedin) {
    if ($loggedin == md5($accesstoken . $viewer . OUBLOG_VISIBILITY_LOGGEDINUSER) && ($user = get_record('user', 'id', $viewer))) {
        $allowedvisibility = OUBLOG_VISIBILITY_LOGGEDINUSER;
    } else {
        error('Access denied');
    }
} else {
    $allowedvisibility = OUBLOG_VISIBILITY_PUBLIC;
    $user = get_guest();
}
// Check individual
if ($blog->individual) {
    if (!oublog_individual_has_permissions($cm, $blog, $groupid, $individualid, $user->id)) {
        error('Access denied (you have no permission to view this individual blog)');
    }
}
// Check separate groups
if ($groupmode == SEPARATEGROUPS) {
    // If you are a member of the group and viewing a specified group then
    // you are OK
    if ($groupid && groups_is_member($groupid, $user->id)) {
        // Group members are OK
    } else {
        // Must have access all groups
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>';
}
Exemple #8
0
/**
 * Execute daily statistics gathering
 * @param int $maxdays maximum number of days to be processed
 * @return boolean success
 */
function stats_cron_daily($maxdays = 1)
{
    global $CFG;
    $now = time();
    // read last execution date from db
    if (!($timestart = get_config(NULL, 'statslastdaily'))) {
        $timestart = stats_get_base_daily(stats_get_start_from('daily'));
        set_config('statslastdaily', $timestart);
    }
    $nextmidnight = stats_get_next_day_start($timestart);
    // are there any days that need to be processed?
    if ($now < $nextmidnight) {
        return true;
        // everything ok and up-to-date
    }
    $timeout = empty($CFG->statsmaxruntime) ? 60 * 60 * 24 : $CFG->statsmaxruntime;
    if (!set_cron_lock('statsrunning', $now + $timeout)) {
        return false;
    }
    // fisrt delete entries that should not be there yet
    delete_records_select('stats_daily', "timeend > {$timestart}");
    delete_records_select('stats_user_daily', "timeend > {$timestart}");
    // Read in a few things we'll use later
    $viewactions = implode(',', stats_get_action_names('view'));
    $postactions = implode(',', stats_get_action_names('post'));
    $guest = get_guest();
    $guestrole = get_guest_role();
    list($enroljoin, $enrolwhere) = stats_get_enrolled_sql($CFG->statscatdepth, true);
    list($enroljoin_na, $enrolwhere_na) = stats_get_enrolled_sql($CFG->statscatdepth, false);
    list($fpjoin, $fpwhere) = stats_get_enrolled_sql(0, true);
    mtrace("Running daily statistics gathering, starting at {$timestart}:");
    $days = 0;
    $failed = false;
    // failed stats flag
    while ($now > $nextmidnight) {
        if ($days >= $maxdays) {
            mtrace("...stopping early, reached maximum number of {$maxdays} days - will continue next time.");
            set_cron_lock('statsrunning', null);
            return false;
        }
        $days++;
        @set_time_limit($timeout - 200);
        if ($days > 1) {
            // move the lock
            set_cron_lock('statsrunning', time() + $timeout, true);
        }
        $daystart = time();
        $timesql = "l.time >= {$timestart}  AND l.time  < {$nextmidnight}";
        $timesql1 = "l1.time >= {$timestart} AND l1.time < {$nextmidnight}";
        $timesql2 = "l2.time >= {$timestart} AND l2.time < {$nextmidnight}";
        stats_daily_progress('init');
        /// find out if any logs available for this day
        $sql = "SELECT 'x'\n                  FROM {$CFG->prefix}log l\n                 WHERE {$timesql}";
        $logspresent = get_records_sql($sql, 0, 1);
        /// process login info first
        $sql = "INSERT INTO {$CFG->prefix}stats_user_daily (stattype, timeend, courseid, userid, statsreads)\n\n                SELECT 'logins', timeend, courseid, userid, count(statsreads)\n                  FROM (\n                           SELECT {$nextmidnight} AS timeend, " . SITEID . " AS courseid, l.userid, l.id AS statsreads\n                             FROM {$CFG->prefix}log l\n                            WHERE action = 'login' AND {$timesql}\n                       ) inline_view\n              GROUP BY timeend, courseid, userid\n                HAVING count(statsreads) > 0";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('1');
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'logins' AS stattype, {$nextmidnight} AS timeend, " . SITEID . " as courseid, 0,\n                       COALESCE((SELECT SUM(statsreads)\n                                       FROM {$CFG->prefix}stats_user_daily s1\n                                      WHERE s1.stattype = 'logins' AND timeend = {$nextmidnight}), 0) AS stat1,\n                       (SELECT COUNT('x')\n                          FROM {$CFG->prefix}stats_user_daily s2\n                         WHERE s2.stattype = 'logins' AND timeend = {$nextmidnight}) AS stat2" . sql_null_from_clause();
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('2');
        // Enrolments and active enrolled users
        //
        // Unfortunately, we do not know how many users were registered
        // at given times in history :-(
        // - stat1: enrolled users
        // - stat2: enrolled users active in this period
        // - enrolment is defined now as having course:view capability in
        //   course context or above, we look 3 cats upwards only and ignore prevent
        //   and prohibit caps to simplify it
        // - SITEID is specialcased here, because it's all about default enrolment
        //   in that case, we'll count non-deleted users.
        //
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'enrolments', timeend, courseid, roleid, COUNT(DISTINCT userid), 0\n                  FROM (\n                           SELECT {$nextmidnight} AS timeend, pl.courseid, pl.roleid, pl.userid\n                             FROM (\n                                      SELECT DISTINCT ra.roleid, ra.userid, c.id as courseid\n                                        FROM {$CFG->prefix}role_assignments ra {$enroljoin_na}\n                                       WHERE {$enrolwhere_na}\n                                   ) pl\n                       ) inline_view\n              GROUP BY timeend, courseid, roleid";
        if (!execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('3');
        // using table alias in UPDATE does not work in pg < 8.2
        $sql = "UPDATE {$CFG->prefix}stats_daily\n                   SET stat2 = (SELECT COUNT(DISTINCT ra.userid)\n                                  FROM {$CFG->prefix}role_assignments ra {$enroljoin_na}\n                                 WHERE ra.roleid = {$CFG->prefix}stats_daily.roleid AND\n                                       c.id = {$CFG->prefix}stats_daily.courseid AND\n                                       {$enrolwhere_na} AND\n                                       EXISTS (SELECT 'x'\n                                                 FROM {$CFG->prefix}log l\n                                                WHERE l.course = {$CFG->prefix}stats_daily.courseid AND\n                                                      l.userid = ra.userid AND {$timesql}))\n                 WHERE {$CFG->prefix}stats_daily.stattype = 'enrolments' AND\n                       {$CFG->prefix}stats_daily.timeend = {$nextmidnight} AND\n                       {$CFG->prefix}stats_daily.courseid IN\n                          (SELECT DISTINCT l.course\n                             FROM {$CFG->prefix}log l\n                            WHERE {$timesql})";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('4');
        /// now get course total enrolments (roleid==0) - except frontpage
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'enrolments', timeend, id, nroleid, COUNT(DISTINCT userid), 0\n                  FROM (\n                           SELECT {$nextmidnight} AS timeend, c.id, 0 AS nroleid, ra.userid\n                             FROM {$CFG->prefix}role_assignments ra {$enroljoin_na}\n                            WHERE c.id <> " . SITEID . " AND {$enrolwhere_na}\n                       ) inline_view\n              GROUP BY timeend, id, nroleid\n              HAVING COUNT(DISTINCT userid) > 0";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('5');
        $sql = "UPDATE {$CFG->prefix}stats_daily\n                   SET stat2 = (SELECT COUNT(DISTINCT ra.userid)\n                                  FROM {$CFG->prefix}role_assignments ra {$enroljoin_na}\n                                 WHERE c.id = {$CFG->prefix}stats_daily.courseid AND\n                                       {$enrolwhere_na} AND\n                                       EXISTS (SELECT 'x'\n                                                 FROM {$CFG->prefix}log l\n                                                WHERE l.course = {$CFG->prefix}stats_daily.courseid AND\n                                                      l.userid = ra.userid AND {$timesql}))\n                 WHERE {$CFG->prefix}stats_daily.stattype = 'enrolments' AND\n                       {$CFG->prefix}stats_daily.timeend = {$nextmidnight} AND\n                       {$CFG->prefix}stats_daily.roleid = 0 AND\n                       {$CFG->prefix}stats_daily.courseid IN\n                          (SELECT l.course\n                             FROM {$CFG->prefix}log l\n                            WHERE {$timesql} AND l.course <> " . SITEID . ")";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('6');
        /// frontapge(==site) enrolments total
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'enrolments', {$nextmidnight}, " . SITEID . ", 0,\n                       (SELECT COUNT('x')\n                          FROM {$CFG->prefix}user u\n                         WHERE u.deleted = 0) AS stat1,\n                       (SELECT COUNT(DISTINCT u.id)\n                          FROM {$CFG->prefix}user u\n                               JOIN {$CFG->prefix}log l ON l.userid = u.id\n                         WHERE u.deleted = 0 AND {$timesql}) AS stat2" . sql_null_from_clause();
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('7');
        if (empty($CFG->defaultfrontpageroleid)) {
            // 1.9 only, so far
            $defaultfproleid = 0;
        } else {
            $defaultfproleid = $CFG->defaultfrontpageroleid;
        }
        /// Default frontpage role enrolments are all site users (not deleted)
        if ($defaultfproleid) {
            // first remove default frontpage role counts if created by previous query
            $sql = "DELETE\n                      FROM {$CFG->prefix}stats_daily\n                     WHERE stattype = 'enrolments' AND courseid = " . SITEID . " AND\n                           roleid = {$defaultfproleid} AND timeend = {$nextmidnight}";
            if ($logspresent and !execute_sql($sql, false)) {
                $failed = true;
                break;
            }
            stats_daily_progress('8');
            $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                    SELECT 'enrolments', {$nextmidnight}, " . SITEID . ", {$defaultfproleid},\n                           (SELECT COUNT('x')\n                              FROM {$CFG->prefix}user u\n                             WHERE u.deleted = 0) AS stat1,\n                           (SELECT COUNT(DISTINCT u.id)\n                              FROM {$CFG->prefix}user u\n                                   JOIN {$CFG->prefix}log l ON l.userid = u.id\n                             WHERE u.deleted = 0 AND {$timesql}) AS stat2" . sql_null_from_clause();
            if ($logspresent and !execute_sql($sql, false)) {
                $failed = true;
                break;
            }
            stats_daily_progress('9');
        } else {
            stats_daily_progress('x');
            stats_daily_progress('x');
        }
        /// individual user stats (including not-logged-in) in each course, this is slow - reuse this data if possible
        $sql = "INSERT INTO {$CFG->prefix}stats_user_daily (stattype, timeend, courseid, userid, statsreads, statswrites)\n\n                SELECT 'activity' AS stattype, {$nextmidnight} AS timeend, d.courseid, d.userid,\n                       (SELECT COUNT('x')\n                          FROM {$CFG->prefix}log l\n                         WHERE l.userid = d.userid AND\n                               l.course = d.courseid AND {$timesql} AND\n                               l.action IN ({$viewactions})) AS statsreads,\n                       (SELECT COUNT('x')\n                          FROM {$CFG->prefix}log l\n                         WHERE l.userid = d.userid AND\n                               l.course = d.courseid AND {$timesql} AND\n                               l.action IN ({$postactions})) AS statswrites\n                  FROM (SELECT DISTINCT u.id AS userid, l.course AS courseid\n                          FROM {$CFG->prefix}user u, {$CFG->prefix}log l\n                         WHERE u.id = l.userid AND {$timesql}\n                       UNION\n                        SELECT 0 AS userid, " . SITEID . " AS courseid" . sql_null_from_clause() . ") d";
        // can not use group by here because pg can not handle it :-(
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('10');
        /// how many view/post actions in each course total
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'activity' AS stattype, {$nextmidnight} AS timeend, c.id AS courseid, 0,\n                       (SELECT COUNT('x')\n                          FROM {$CFG->prefix}log l1\n                         WHERE l1.course = c.id AND l1.action IN ({$viewactions}) AND\n                               {$timesql1}) AS stat1,\n                       (SELECT COUNT('x')\n                          FROM {$CFG->prefix}log l2\n                         WHERE l2.course = c.id AND l2.action IN ({$postactions}) AND\n                               {$timesql2}) AS stat2\n                  FROM {$CFG->prefix}course c\n                 WHERE EXISTS (SELECT 'x'\n                                 FROM {$CFG->prefix}log l\n                                WHERE l.course = c.id and {$timesql})";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('11');
        /// how many view actions for each course+role - excluding guests and frontpage
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'activity', timeend, courseid, roleid, SUM(statsreads), SUM(statswrites)\n                FROM (\n                         SELECT {$nextmidnight} AS timeend, pl.courseid, pl.roleid, sud.statsreads, sud.statswrites\n                         FROM {$CFG->prefix}stats_user_daily sud,\n                                  (SELECT DISTINCT ra.userid, ra.roleid, c.id AS courseid\n                                     FROM {$CFG->prefix}role_assignments ra {$enroljoin}\n                                    WHERE c.id <> " . SITEID . " AND\n                                          ra.roleid <> {$guestrole->id} AND\n                                          ra.userid <> {$guest->id} AND\n                                          {$enrolwhere}\n                                  ) pl\n                         WHERE sud.userid = pl.userid AND\n                               sud.courseid = pl.courseid AND\n                               sud.timeend = {$nextmidnight} AND\n                               sud.stattype='activity'\n                     ) inline_view\n            GROUP BY timeend, courseid, roleid\n              HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('12');
        /// how many view actions from guests only in each course - excluding frontpage
        /// (guest is anybody with guest role or no role with course:view in course - this may not work properly if category limit too low)
        /// normal users may enter course with temporary guest acces too
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'activity', timeend, courseid, nroleid, SUM(statsreads), SUM(statswrites)\n                  FROM (\n                           SELECT {$nextmidnight} AS timeend, sud.courseid, {$guestrole->id} AS nroleid, sud.statsreads, sud.statswrites\n                             FROM {$CFG->prefix}stats_user_daily sud\n                            WHERE sud.timeend = {$nextmidnight} AND sud.courseid <> " . SITEID . " AND\n                                  sud.stattype='activity' AND\n                                  (sud.userid = {$guest->id} OR sud.userid\n                                    NOT IN (SELECT ra.userid\n                                              FROM {$CFG->prefix}role_assignments ra {$enroljoin}\n                                             WHERE c.id <> " . SITEID . " AND  ra.roleid <> {$guestrole->id} AND\n                                                   {$enrolwhere}))\n                       ) inline_view\n              GROUP BY timeend, courseid, nroleid\n                HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('13');
        /// how many view actions for each role on frontpage - excluding guests, not-logged-in and default frontpage role
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'activity', timeend, courseid, roleid, SUM(statsreads), SUM(statswrites)\n                  FROM (\n                           SELECT {$nextmidnight} AS timeend, pl.courseid, pl.roleid, sud.statsreads, sud.statswrites\n                             FROM {$CFG->prefix}stats_user_daily sud,\n                                      (SELECT DISTINCT ra.userid, ra.roleid, c.id AS courseid\n                                         FROM {$CFG->prefix}role_assignments ra {$enroljoin}\n                                        WHERE c.id = " . SITEID . " AND\n                                              ra.roleid <> {$defaultfproleid} AND\n                                              ra.roleid <> {$guestrole->id} AND\n                                              ra.userid <> {$guest->id} AND\n                                              {$enrolwhere}\n                                      ) pl\n                            WHERE sud.userid = pl.userid AND\n                                  sud.courseid = pl.courseid AND\n                                  sud.timeend = {$nextmidnight} AND\n                                  sud.stattype='activity'\n                       ) inline_view\n              GROUP BY timeend, courseid, roleid\n                HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('14');
        /// how many view actions for default frontpage role on frontpage only
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'activity', timeend, courseid, nroleid, SUM(statsreads), SUM(statswrites)\n                  FROM (\n                           SELECT {$nextmidnight} AS timeend, sud.courseid, {$defaultfproleid} AS nroleid, sud.statsreads, sud.statswrites\n                             FROM {$CFG->prefix}stats_user_daily sud\n                             WHERE sud.timeend = {$nextmidnight} AND sud.courseid = " . SITEID . " AND\n                                   sud.stattype='activity' AND\n                                   sud.userid <> {$guest->id} AND sud.userid <> 0 AND sud.userid\n                                   NOT IN (SELECT ra.userid\n                                             FROM {$CFG->prefix}role_assignments ra {$fpjoin}\n                                            WHERE c.id = " . SITEID . " AND  ra.roleid <> {$guestrole->id} AND\n                                                  ra.roleid <> {$defaultfproleid} AND {$fpwhere})\n                       ) inline_view\n              GROUP BY timeend, courseid, nroleid\n                HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('15');
        /// how many view actions for guests or not-logged-in on frontpage
        $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)\n\n                SELECT 'activity', timeend, courseid, nroleid, SUM(statsreads), SUM(statswrites)\n                  FROM (\n                           SELECT {$nextmidnight} AS timeend, " . SITEID . " AS courseid, {$guestrole->id} AS nroleid, pl.statsreads, pl.statswrites\n                             FROM (\n                                      SELECT sud.statsreads, sud.statswrites\n                                        FROM {$CFG->prefix}stats_user_daily sud\n                                      WHERE (sud.userid = {$guest->id} OR sud.userid = 0) AND\n                                            sud.timeend = {$nextmidnight} AND sud.courseid = " . SITEID . " AND\n                                            sud.stattype='activity'\n                                  ) pl\n                       ) inline_view\n              GROUP BY timeend, courseid, nroleid\n                HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
        if ($logspresent and !execute_sql($sql, false)) {
            $failed = true;
            break;
        }
        stats_daily_progress('16');
        // remember processed days
        set_config('statslastdaily', $nextmidnight);
        mtrace("  finished until {$nextmidnight}: " . userdate($nextmidnight) . " (in " . (time() - $daystart) . " s)");
        $timestart = $nextmidnight;
        $nextmidnight = stats_get_next_day_start($nextmidnight);
    }
    set_cron_lock('statsrunning', null);
    if ($failed) {
        $days--;
        mtrace("...error occured, completed {$days} days of statistics.");
        return false;
    } else {
        mtrace("...completed {$days} days of statistics.");
        return true;
    }
}
Exemple #9
0
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;
                }
                $mod->id = $mod->cm;
                if (!groups_course_module_visible($mod)) {
                    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 = groups_get_course_groupmode($course);
        if ($groupmode == VISIBLEGROUPS or $groupmode and has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
            if ($groups = groups_get_all_groups($course->id)) {
                $group_names = array();
                foreach ($groups as $group) {
                    $group_names[$group->id] = format_string($group->name);
                }
                echo '<td><b>';
                if ($groupmode == VISIBLEGROUPS) {
                    print_string('groupsvisible');
                } else {
                    print_string('groupsseparate');
                }
                echo ':</b></td><td>';
                choose_from_menu($group_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}&amp;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}&amp;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}&amp;advancedfilter=1\">" . get_string("advancedfilter") . "</a>";
        print_heading($advancedlink);
    }
}