function usersdata($courseID = '')
{
    global $CFG, $DB;
    $users = array();
    $course = $DB->get_record('course', array('id' => $courseID));
    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');
            $context = get_context_instance(CONTEXT_COURSE, $courseID);
            $query = 'select u.id as id, firstname, lastname, idnumber, imagealt, email from ' . $CFG->prefix . 'role_assignments as a, ' . $CFG->prefix . 'user as u where contextid=' . $context->id . ' and roleid=5 and a.userid=u.id;';
            $courseusers = $DB->get_recordset_sql($query);
        }
    } 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);
        //}
    }
    return $users;
}
function get_groups($sub_id)
{
    $dbconn =& new DBConn();
    $groups = array();
    $sql_str = "SELECT " . "gid, " . "gname " . "FROM " . "tng_group " . "ORDER BY gname";
    $dbconn->connect();
    $result = pg_query($dbconn->conn, $sql_str);
    if (!$result) {
        echo "An error occurred while executing the query - " . $sql_str . " - " . pg_last_error($this->dbconn->conn);
        $dbconn->disconnect();
        return NULL;
    }
    $n_groups = pg_num_rows($result);
    for ($i = 0; $i < $n_groups; $i++) {
        $groups[$i] = array("gid" => pg_fetch_result($result, $i, 'gid'), "gname" => pg_fetch_result($result, $i, 'gname'), "children" => get_group_users(pg_fetch_result($result, $i, 'gid'), $sub_id));
    }
    return $groups;
}
Ejemplo n.º 3
0
                $count++;
            }
            $entrybyuser[$entry->userid]->rating = $vals['r'];
            $entrybyuser[$entry->userid]->entrycomment = $vals['c'];
            $entrybyuser[$entry->userid]->teacher = $USER->id;
            $entrybyuser[$entry->userid]->timemarked = $timenow;
        }
    }
    add_to_log($course->id, "journal", "update feedback", "report.php?id={$cm->id}", "{$count} users", $cm->id);
    notify(get_string("feedbackupdated", "journal", "{$count}"), "green");
} else {
    add_to_log($course->id, "journal", "view responses", "report.php?id={$cm->id}", "{$journal->id}", $cm->id);
}
/// Print out the journal entries
if ($currentgroup) {
    $users = get_group_users($currentgroup);
} else {
    $users = get_course_students($course->id);
}
if (!$users) {
    print_heading(get_string("nousersyet"));
} else {
    $grades = make_grades_menu($journal->assessed);
    $teachers = get_course_teachers($course->id);
    $allowedtograde = ($groupmode != VISIBLEGROUPS or isteacheredit($course->id) or ismember($currentgroup));
    if ($allowedtograde) {
        echo '<form action="report.php" method="post">';
    }
    if ($usersdone = journal_get_users_done($journal)) {
        foreach ($usersdone as $user) {
            if ($currentgroup) {
Ejemplo n.º 4
0
/// Get all existing subscribers for this forum.
if (!($subscribers = forum_subscribed_users($course, $forum, $currentgroup))) {
    $subscribers = array();
}
$subscriberarray = array();
foreach ($subscribers as $subscriber) {
    $subscriberarray[] = $subscriber->id;
}
$subscriberlist = implode(',', $subscriberarray);
unset($subscriberarray);
/// Get search results excluding any users already subscribed
if (!empty($frm->searchtext) and $previoussearch) {
    $searchusers = search_users($course->id, $currentgroup, $frm->searchtext, 'firstname ASC, lastname ASC', $subscriberlist);
}
/// If no search results then get potential subscribers for this forum excluding users already subscribed
if (empty($searchusers)) {
    if ($currentgroup) {
        $users = get_group_users($currentgroup, 'firstname ASC, lastname ASC', $subscriberlist);
    } else {
        $users = get_course_users($course->id, 'firstname ASC, lastname ASC', $subscriberlist);
    }
    if (!$users) {
        $users = array();
    }
}
$searchtext = isset($frm->searchtext) ? $frm->searchtext : "";
$previoussearch = $previoussearch ? '1' : '0';
print_simple_box_start('center');
include 'subscriber.html';
print_simple_box_end();
print_footer($course);
Ejemplo n.º 5
0
function get_list_members($course, &$nonmembers, &$listgroups)
{
    /// First, get everyone into the nonmembers array
    if ($students = get_course_students($course->id)) {
        foreach ($students as $student) {
            $nonmembers[$student->id] = fullname($student, true);
        }
        unset($students);
    }
    if ($teachers = get_course_teachers($course->id)) {
        foreach ($teachers as $teacher) {
            $prefix = '- ';
            if (isteacheredit($course->id, $teacher->id)) {
                $prefix = '# ';
            }
            $nonmembers[$teacher->id] = $prefix . fullname($teacher, true);
        }
        unset($teachers);
    }
    /// Pull out all the members into little arrays
    $groups = get_groups($course->id);
    if ($groups) {
        foreach ($groups as $group) {
            $countusers = 0;
            $listmembers[$group->id] = array();
            if ($groupusers = get_group_users($group->id)) {
                foreach ($groupusers as $groupuser) {
                    $listmembers[$group->id][$groupuser->id] = $nonmembers[$groupuser->id];
                    //unset($nonmembers[$groupuser->id]);
                    $countusers++;
                }
                natcasesort($listmembers[$group->id]);
            }
            $listgroups[$group->id] = $group->name . " ({$countusers})";
        }
        natcasesort($listgroups);
    }
    natcasesort($nonmembers);
    if (empty($selectedgroup)) {
        // Choose the first group by default
        if (!empty($listgroups) && ($selectedgroup = array_shift(array_keys($listgroups)))) {
            $members = $listmembers[$selectedgroup];
        }
    } else {
        $members = $listmembers[$selectedgroup];
    }
    return $listmembers;
}
Ejemplo n.º 6
0
function hotpot_get_report_users($course, $formdata)
{
    $users = array();
    /// Check to see if groups are being used in this module
    $groupmode = groupmode($course, $cm);
    //TODO: there is no $cm defined!
    $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id={$cm->id}&mode=simple");
    $sort = "u.lastname ASC";
    switch ($formdata['reportusers']) {
        case 'students':
            if ($currentgroup) {
                $users = get_group_students($currentgroup, $sort);
            } else {
                $users = get_course_students($course->id, $sort);
            }
            break;
        case 'all':
            if ($currentgroup) {
                $users = get_group_users($currentgroup, $sort);
            } else {
                $users = get_course_users($course->id, $sort);
            }
            break;
    }
    return $users;
}
Ejemplo n.º 7
0
/**
 * Sends the reminder message for the specified reminder.
 *
 * @param int $reminderid ID of the reminder to send a message for.
 * @return boolean True on success, False otherwise.
 */
function elluminate_reminder_send($reminderid)
{
    // Make sure the reminder exists
    if (!($reminder = $DB->get_record('event_reminder', array('id' => intval($reminderid))))) {
        return false;
    }
    // Get the event record that this reminder belongs to
    if (!($event = $DB->get_record('event', array('id' => $reminder->event)))) {
        return false;
    }
    // Determine the type of event
    $type = elluminate_reminder_event_type($event->id);
    // General message information.
    $userfrom = get_admin();
    $site = get_site();
    $subject = get_string('remindersubject', 'event_reminder', $site->fullname);
    $message = elluminate_reminder_message($event->id, $type);
    // Send the reminders to user(s) based on the type of event.
    switch ($type) {
        case 'user':
            // Send a reminder to the user
            if (!empty($CFG->messaging)) {
                // use message system
            } else {
                $user = $DB->get_record('user', array('id' => $event->userid));
                email_to_user($user, $userfrom, $subject, $message);
            }
            break;
        case 'course':
            // Get all the users in the course and send them the reminder
            $users = get_course_users($event->courseid);
            foreach ($users as $user) {
                if (!empty($CFG->messaging)) {
                    // use message system
                } else {
                    email_to_user($user, $userfrom, $subject, $message);
                }
            }
            break;
        case 'group':
            // Get all the users in the group and send them the reminder
            $users = get_group_users($event->groupid);
            foreach ($users as $user) {
                if (!empty($CFG->messaging)) {
                    // use message system
                } else {
                    email_to_user($user, $userfrom, $subject, $message);
                }
            }
            break;
        default:
            return false;
            break;
    }
    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>';
}
 /**
  *  Display all the submissions ready for grading
  */
 function display_submissions()
 {
     global $CFG, $db, $USER;
     /* first we check to see if the form has just been submitted
      * to request user_preference updates
      */
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 10, PARAM_INT);
         $perpage = $perpage <= 0 ? 10 : $perpage;
         set_user_preference('webquestscorm_perpage', $perpage);
         set_user_preference('webquestscorm_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
     }
     /* next we get perpage and quickgrade (allow quick grade) params 
      * from database
      */
     $perpage = get_user_preferences('webquestscorm_perpage', 10);
     $quickgrade = get_user_preferences('webquestscorm_quickgrade', 0);
     $teacherattempts = true;
     /// Temporary measure
     $page = optional_param('page', 0, PARAM_INT);
     $strsaveallfeedback = get_string('saveallfeedback', 'webquestscorm');
     /// Some shortcuts to make the code read better
     $tabindex = 1;
     //tabindex for quick grading tabbing; Not working for dropdowns yet
     add_to_log($this->course->id, 'webquestscorm', 'view submission', 'editsubmissions.php?cmid=' . $this->cm->id . '&element=uploadedTasks&subelement=all', $this->wqid, $this->cm->id);
     $strwebquestscorms = get_string('modulenameplural', 'webquestscorm');
     $strwebquestscorm = get_string('modulename', 'webquestscorm');
     ///Position swapped
     if ($groupmode = groupmode($this->course, $this->cm)) {
         // Groups are being used
         $currentgroup = setup_and_print_groups($this->course, $groupmode, 'editsubmissions.php?cmid=' . $this->cm->id . '&element=uploadedTasks&subelement=all');
     } else {
         $currentgroup = false;
     }
     /// Get all teachers and students
     if ($currentgroup) {
         $users = get_group_users($currentgroup);
     } else {
         //$users = get_users_by_capability($this->context, 'mod/webquestscorm:submit'); // everyone with this capability set to non-prohibit
         $users = get_course_students($this->course->id);
     }
     $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status');
     $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'webquestscorm'), get_string('lastmodified') . ' (' . $this->course->student . ')', get_string('lastmodified') . ' (' . $this->course->teacher . ')', get_string('status'));
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-webquestscorm-submissions');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/webquestscorm/editsubmissions.php?cmid=' . $this->cm->id . '&element=uploadedTasks&subelement=all&amp;currentgroup=' . $currentgroup);
     $table->define_baseurl($CFG->wwwroot . '/mod/webquestscorm/editsubmissions.php?cmid=' . $this->cm->id . '&amp;currentgroup=' . $currentgroup . '&element=uploadedTasks&subelement=all');
     $table->sortable(true, 'lastname');
     //sorted by lastname by default
     $table->collapsible(true);
     $table->initialbars(true);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('grade', 'grade');
     $table->column_class('submissioncomment', 'comment');
     $table->column_class('timemodified', 'timemodified');
     $table->column_class('timemarked', 'timemarked');
     $table->column_class('status', 'status');
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'submissions');
     $table->set_attribute('width', '90%');
     $table->set_attribute('align', 'center');
     // Start working -- this is necessary as soon as the niceties are over
     $table->setup();
     /// Check to see if groups are being used in this webquestscorm
     if (!$teacherattempts) {
         $teachers = get_course_teachers($this->course->id);
         if (!empty($teachers)) {
             $keys = array_keys($teachers);
         }
         foreach ($keys as $key) {
             unset($users[$key]);
         }
     }
     if (empty($users)) {
         print_heading(get_string('noattempts', 'webquestscorm'));
         print_footer($this->course);
         return true;
     }
     /// Construct the SQL
     if ($where = $table->get_sql_where()) {
         $where .= ' AND ';
     }
     if ($sort = $table->get_sql_sort()) {
         $sort = ' ORDER BY ' . $sort;
     }
     $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 ' . $where . 'u.id IN (' . implode(',', array_keys($users)) . ') ';
     $table->pagesize($perpage, count($users));
     ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
     $offset = $page * $perpage;
     $strupdate = get_string('update');
     $strgrade = get_string('grade');
     $grademenu = make_grades_menu($this->wqgrade);
     if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) {
         foreach ($ausers as $auser) {
             /// Calculate user status
             $auser->status = $auser->timemarked > 0 && $auser->timemarked >= $auser->timemodified;
             $picture = print_user_picture($auser->id, $this->course->id, $auser->picture, false, true);
             if (empty($auser->submissionid)) {
                 $auser->grade = -1;
                 //no submission yet
             }
             if (!empty($auser->submissionid)) {
                 ///Prints student answer and student modified date
                 ///attach file or print link to student answer, depending on the type of the webquestscorm.
                 ///Refer to print_student_answer in inherited classes.
                 if ($auser->timemodified > 0) {
                     $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>';
                 } else {
                     $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 }
                 ///Print grade, dropdown or text
                 if ($auser->timemarked > 0) {
                     $teachermodified = '<div id="tt' . $auser->id . '">' . userdate($auser->timemarked) . '</div>';
                     if ($quickgrade) {
                         $grade = '<div id="g' . $auser->id . '">' . choose_from_menu(make_grades_menu($this->wqgrade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++) . '</div>';
                     } else {
                         $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                     }
                 } else {
                     $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                     if ($quickgrade) {
                         $grade = '<div id="g' . $auser->id . '">' . choose_from_menu(make_grades_menu($this->wqgrade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++) . '</div>';
                     } else {
                         $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                     }
                 }
                 ///Print Comment
                 if ($quickgrade) {
                     $comment = '<div id="com' . $auser->id . '"><textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment[' . $auser->id . ']">' . $auser->submissioncomment . '</textarea></div>';
                 } else {
                     $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($auser->submissioncomment), 15) . '</div>';
                 }
             } else {
                 $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                 $status = '<div id="st' . $auser->id . '">&nbsp;</div>';
                 if ($quickgrade) {
                     // allow editing
                     $grade = '<div id="g' . $auser->id . '">' . choose_from_menu(make_grades_menu($this->wqgrade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++) . '</div>';
                 } else {
                     $grade = '<div id="g' . $auser->id . '">-</div>';
                 }
                 if ($quickgrade) {
                     $comment = '<div id="com' . $auser->id . '"><textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment[' . $auser->id . ']">' . $auser->submissioncomment . '</textarea></div>';
                 } else {
                     $comment = '<div id="com' . $auser->id . '">&nbsp;</div>';
                 }
             }
             if (empty($auser->status)) {
                 /// Confirm we have exclusively 0 or 1
                 $auser->status = 0;
             } else {
                 $auser->status = 1;
             }
             $buttontext = $auser->status == 1 ? $strupdate : $strgrade;
             ///No more buttons, we use popups ;-).
             $button = link_to_popup_window('/mod/webquestscorm/submissions.php?cmid=' . $this->cm->id . '&element=uploadedTasks&amp;userid=' . $auser->id . '&amp;subelement=single' . '&amp;offset=' . $offset++, 'grade' . $auser->id, $buttontext, 500, 780, $buttontext, 'none', true, 'button' . $auser->id);
             $status = '<div id="up' . $auser->id . '" class="s' . $auser->status . '">' . $button . '</div>';
             $row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status);
             $table->add_data($row);
         }
     }
     /// Print quickgrade form around the table
     if ($quickgrade) {
         echo '<form action="submissions.php?cmid=' . $this->cm->id . '" name="fastg" method="post">';
         echo '<input type="hidden" name="id" value="' . $this->cm->id . '">';
         echo '<input type="hidden" name="mode" value="fastgrade">';
         echo '<input type="hidden" name="page" value="' . $page . '">';
         echo '<input type="hidden" name="tabs" value="required" />';
         echo '<p align="center"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'webquestscorm') . '" /></p>';
     }
     $table->print_html();
     /// Print the whole table
     if ($quickgrade) {
         echo '<p align="center"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'webquestscorm') . '" /></p>';
         echo '</form>';
     }
     /// End of fast grading form
     /// Mini form for setting user preference
     echo '<br />';
     echo '<form name="options" action="submissions.php?cmid=' . $this->cm->id . '" method="post">';
     echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
     echo '<input type="hidden" name="tabs" value="required" />';
     echo '<table id="optiontable" align="center">';
     echo '<tr align="right"><td>';
     echo '<label for="perpage">' . get_string('pagesize', 'webquestscorm') . '</label>';
     echo ':</td>';
     echo '<td align="left">';
     echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />';
     helpbutton('pagesize', get_string('pagesize', 'webquestscorm'), 'webquestscorm');
     echo '</td></tr>';
     echo '<tr align="right">';
     echo '<td>';
     print_string('quickgrade', 'webquestscorm');
     echo ':</td>';
     echo '<td align="left">';
     if ($quickgrade) {
         echo '<input type="checkbox" name="quickgrade" value="1" checked="checked" />';
     } else {
         echo '<input type="checkbox" name="quickgrade" value="1" />';
     }
     helpbutton('quickgrade', get_string('quickgrade', 'webquestscorm'), 'webquestscorm') . '</p></div>';
     echo '</td></tr>';
     echo '<tr>';
     echo '<td colspan="2" align="right">';
     echo '<input type="submit" value="' . get_string('savepreferences') . '" />';
     echo '</td></tr></table>';
     echo '</form>';
     ///End of mini form
     print_footer($this->course);
 }
Ejemplo n.º 10
0
function grade_get_formatted_grades()
{
    global $CFG;
    global $COURSE;
    global $preferences;
    $course = $COURSE;
    $i = 2;
    // index to differentiate activities with the same name MDL-6876
    $grades = grade_get_grades();
    if (isset($grades)) {
        // iterate through all students
        foreach ($grades as $cur_category => $grade_category) {
            // $cur_category holds the value of the current category name
            // $grade_category holds an array of all the mod types that are in this category
            if (isset($grade_category)) {
                foreach ($grade_category as $cur_mod => $mod_category) {
                    // $cur_mod is the id of the current moodle module type
                    // $mod_category holds the grades for $cur_mod (current mod type)
                    $module_info = get_record('modules', 'id', $cur_mod);
                    $cur_modname = $module_info->name;
                    if (isset($mod_category)) {
                        foreach ($mod_category as $cur_cminstance => $students_grade) {
                            // $cur_cminstance is the course module instance for the cur_mod
                            $instance = get_record($cur_modname, 'id', $cur_cminstance, 'course', $course->id);
                            // it's necessary to check if the name is blank because some mods don't clean up the grades when the instance is deleted
                            // this is a bug. as it is plausible that some item could get created and have old data from a previous mod laying around
                            if ($instance->name != '') {
                                // duplicate grade item name, the user should know better than to name to things by the same name, but to make sure grades don't disappear lets modify the name slightly
                                if (isset($all_categories["{$cur_category}"]["{$instance->name}"])) {
                                    $instance->name = $instance->name . ' #' . $i++;
                                }
                                if (isset($students_grade->grades) && $students_grade->grades != '') {
                                    foreach ($students_grade->grades as $student => $grade) {
                                        // add an entry for any student that has a grade
                                        $grades_by_student["{$student}"]["{$cur_category}"]["{$instance->name}"]['grade'] = $grade;
                                        $grades_by_student["{$student}"]["{$cur_category}"]["{$instance->name}"]['sort_order'] = $students_grade->sort_order;
                                        if (!isset($grades_by_student["{$student}"]["{$cur_category}"]['stats'])) {
                                            $grades_by_student["{$student}"]["{$cur_category}"]['stats'] = array();
                                        }
                                        if (!isset($grades_by_student["{$student}"]["{$cur_category}"]['stats']['points'])) {
                                            $grades_by_student["{$student}"]["{$cur_category}"]['stats']['points'] = $grade;
                                        } else {
                                            $grades_by_student["{$student}"]["{$cur_category}"]['stats']['points'] = $grades_by_student["{$student}"]["{$cur_category}"]['stats']['points'] + $grade;
                                        }
                                        // This next block just creates a comma seperated list of all grades for the category
                                        if (isset($grades_by_student["{$student}"]["{$cur_category}"]['stats']['allgrades'])) {
                                            $grades_by_student["{$student}"]["{$cur_category}"]['stats']['allgrades'] .= ',' . $grade;
                                        } else {
                                            $grades_by_student["{$student}"]["{$cur_category}"]['stats']['allgrades'] = $grade;
                                        }
                                    }
                                }
                                // set up a list of all categories and assignments (adjusting things for extra credit where necessary)
                                $all_categories["{$cur_category}"]["{$instance->name}"]['hidden'] = $students_grade->hidden;
                                $all_categories["{$cur_category}"]["{$instance->name}"]['sort_order'] = $students_grade->sort_order;
                                $all_categories["{$cur_category}"]["{$instance->name}"]['extra_credit'] = $students_grade->extra_credit;
                                if ($all_categories["{$cur_category}"]["{$instance->name}"]['extra_credit'] != 1) {
                                    $all_categories["{$cur_category}"]["{$instance->name}"]['maxgrade'] = $students_grade->maxgrade;
                                } else {
                                    $all_categories["{$cur_category}"]["{$instance->name}"]['maxgrade'] = 0;
                                }
                                $all_categories["{$cur_category}"]["{$instance->name}"]['scale_grade'] = $students_grade->scale_grade;
                                if ($students_grade->scale_grade != 0) {
                                    $all_categories["{$cur_category}"]["{$instance->name}"]['scaled_max'] = round($all_categories["{$cur_category}"]["{$instance->name}"]['maxgrade'] / $students_grade->scale_grade);
                                } else {
                                    // avoids divide by zero... scale_grade shouldn't be set to 0 anyway
                                    $all_categories["{$cur_category}"]["{$instance->name}"]['scaled_max'] = $all_categories["{$cur_category}"]["{$instance->name}"]['maxgrade'];
                                    $all_categories["{$cur_category}"]["{$instance->name}"]['scale_grade'] = 1.0;
                                }
                                if (!isset($all_categories["{$cur_category}"]['stats'])) {
                                    $all_categories["{$cur_category}"]['stats'] = array();
                                }
                                $all_categories["{$cur_category}"]["{$instance->name}"]['grade_against'] = $all_categories["{$cur_category}"]["{$instance->name}"]['scaled_max'];
                                if (!isset($all_categories["{$cur_category}"]['stats']['weight'])) {
                                    $weight = grade_get_category_weight($course->id, addslashes($cur_category));
                                    $all_categories["{$cur_category}"]['stats']['weight'] = $weight->weight;
                                }
                                $all_categories["{$cur_category}"]["{$instance->name}"]['cminstance'] = $cur_cminstance;
                                $all_categories["{$cur_category}"]["{$instance->name}"]['modid'] = $cur_mod;
                                $modname = get_record('modules', 'id', $cur_mod);
                                $all_categories["{$cur_category}"]["{$instance->name}"]['modname'] = $modname->name;
                                // get bonus points and drop the x lowest
                                $drop = get_record('grade_category', 'courseid', $course->id, 'name', addslashes($cur_category));
                                $all_categories["{$cur_category}"]['stats']['drop'] = $drop->drop_x_lowest;
                                $all_categories["{$cur_category}"]['stats']['bonus_points'] = $drop->bonus_points;
                            }
                        }
                    }
                }
            }
        }
        if (!($students = grade_get_course_students($course->id))) {
            return false;
        }
        if (isset($students) && $students) {
            foreach ($students as $userid => $student) {
                $grades_by_student["{$userid}"]['student_data']['firstname'] = $student->firstname;
                $grades_by_student["{$userid}"]['student_data']['lastname'] = $student->lastname;
                $grades_by_student["{$userid}"]['student_data']['email'] = $student->email;
                if (isset($student->location)) {
                    $grades_by_student["{$userid}"]['student_data']['location'] = $student->location;
                }
                $grades_by_student["{$userid}"]['student_data']['department'] = $student->department;
                $grades_by_student["{$userid}"]['student_data']['idnumber'] = $student->idnumber;
            }
        }
        // unset any item that has a "" for a name at this point this inludes instructors who have grades or any student formerly enrolled.
        if (isset($grades_by_student)) {
            foreach ($grades_by_student as $student => $assignments) {
                if (!isset($grades_by_student["{$student}"]['student_data']['firstname']) && !isset($grades_by_student["{$student}"]['student_data']['lastname'])) {
                    unset($grades_by_student["{$student}"]);
                }
            }
        }
        // set the totalpoints for each category taking into account drop_x_lowest
        // also set the number of grade items for the category to make calculating grades for students who have not taken anything easier
        foreach ($all_categories as $category => $assignments) {
            $dropcount = 0;
            $all_categories["{$category}"]['stats']['totalpoints'] = 0;
            $all_categories["{$category}"]['stats']['grade_items'] = 0;
            if (isset($assignments)) {
                foreach ($assignments as $assignment => $grade) {
                    if ($assignment != 'stats') {
                        if ($dropcount < $all_categories["{$category}"]['stats']['drop']) {
                            // skip a grade in the total
                            $dropcount++;
                        } else {
                            // make sure the current assignment is not extra credit and then add it to the totalpoints
                            if ($all_categories["{$category}"][$assignment]['extra_credit'] != 1) {
                                if (is_numeric($assignments["{$assignment}"]['maxgrade'])) {
                                    $all_categories["{$category}"]['stats']['totalpoints'] = $all_categories["{$category}"]['stats']['totalpoints'] + $assignments["{$assignment}"]['grade_against'];
                                }
                                $all_categories["{$category}"]['stats']['grade_items'] = $all_categories["{$category}"]['stats']['grade_items'] + 1;
                            }
                        }
                    }
                }
            }
        }
        // if the user has selected a group to view by get the group members unless the course is not using
        if (groupmode($course) != 0) {
            if ($currentgroup = get_current_group($course->id)) {
                // get the current group
                $groupmembers = get_group_users($currentgroup);
                // group members of the group
            }
        } else {
            // if not groupmode then the group is the entire course so get all course students
            $groupmembers = grade_get_course_students($course->id);
        }
        // this next block catches any students who do not have a grade for any item in a particular category
        foreach ($all_categories as $category => $main_category) {
            // make sure each student has an entry for each category
            if (isset($grades_by_student)) {
                foreach ($grades_by_student as $student => $categories) {
                    if (isset($groupmembers) && isset($groupmembers[$student]) || !isset($groupmembers)) {
                        $grades_by_student["{$student}"]["{$category}"]['stats']['totalpoints'] = $main_category['stats']['totalpoints'];
                        $grades_by_student["{$student}"]["{$category}"]['stats']['weight'] = $main_category['stats']['weight'];
                        $grades_by_student["{$student}"]["{$category}"]['stats']['grade_items'] = $main_category['stats']['grade_items'];
                        foreach ($main_category as $assignment => $items) {
                            if ($assignment != 'stats') {
                                if (!isset($grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['grade'])) {
                                    if (isset($grades_by_student["{$student}"]["{$category}"]['stats']['allgrades'])) {
                                        $grades_by_student["{$student}"]["{$category}"]['stats']['allgrades'] .= ',0';
                                    } else {
                                        $grades_by_student["{$student}"]["{$category}"]['stats']['allgrades'] = '0';
                                    }
                                }
                            }
                        }
                        if (!isset($grades_by_student["{$student}"]["{$category}"]['stats']['points'])) {
                            $grades_by_student["{$student}"]["{$category}"]['stats']['points'] = '-';
                        } else {
                            // points are set... see if the current category is using drop the x lowest and do so
                            // also drop exceptions first, so then this grades(s) won't be recoqnized as the x lowest
                            // Get exception scores and assign them in the array
                            if ($main_category['stats']['drop'] != 0) {
                                $exceptions = grade_get_exceptions_user($course->id, $student);
                                if (isset($exceptions) && $exceptions) {
                                    foreach ($exceptions as $exception) {
                                        if (isset($grades_by_student["{$exception->userid}"])) {
                                            if ($grades_by_student["{$exception->userid}"]["{$exception->catname}"]) {
                                                $assgn = get_record($exception->modname, 'id', $exception->cminstance, 'course', $course->id);
                                                $grade = $grades_by_student["{$exception->userid}"]["{$exception->catname}"]["{$assgn->name}"]['grade'];
                                                if (isset($grade)) {
                                                    if (!isset($grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['exceptions'])) {
                                                        $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['exceptions'] = $grade;
                                                    } elseif (isset($grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['exceptions'])) {
                                                        $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['exceptions'] .= ',' . $grade;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (isset($grades_by_student["{$student}"]["{$category}"]['stats']['exceptions'])) {
                                    $grades_by_student["{$student}"]["{$category}"]['stats']['allgrades'] = grade_drop_exceptions($grades_by_student["{$student}"]["{$category}"]['stats']['allgrades'], $grades_by_student["{$student}"]["{$category}"]['stats']['exceptions']);
                                }
                                $grades_by_student["{$student}"]["{$category}"]['stats']['allgrades'] = grade_drop_lowest($grades_by_student["{$student}"]["{$category}"]['stats']['allgrades'], $main_category['stats']['drop'], $main_category['stats']['grade_items']);
                                if ($grades_by_student["{$student}"]["{$category}"]['stats']['points'] != '-') {
                                    $cat_points = 0;
                                    $count_grades = explode(',', $grades_by_student["{$student}"]["{$category}"]['stats']['allgrades']);
                                    foreach ($count_grades as $grade) {
                                        $cat_points = $cat_points + $grade;
                                    }
                                    $grades_by_student["{$student}"]["{$category}"]['stats']['points'] = $cat_points;
                                }
                            }
                        }
                        // add any bonus points for the category
                        if ($all_categories["{$category}"]['stats']['bonus_points'] != 0) {
                            $grades_by_student["{$student}"]["{$category}"]['stats']['points'] = $grades_by_student["{$student}"]["{$category}"]['stats']['points'] + $all_categories["{$category}"]['stats']['bonus_points'];
                        }
                        foreach ($main_category as $assignment => $items) {
                            if ($assignment != 'stats') {
                                if (!isset($grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['maxgrade'])) {
                                    $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['maxgrade'] = $all_categories["{$category}"]["{$assignment}"]['grade_against'];
                                }
                                if (!isset($grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['grade'])) {
                                    $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['grade'] = '-';
                                    $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['sort_order'] = $all_categories["{$category}"]["{$assignment}"]['sort_order'];
                                }
                            }
                        }
                    } else {
                        // unset grade since they are not in the selected group.
                        unset($grades_by_student["{$student}"]);
                    }
                }
            }
        }
        // set the total coursepoints
        $all_categories['stats']['weight'] = 0;
        $all_categories['stats']['totalpoints'] = 0;
        foreach ($all_categories as $category => $info) {
            if ($category != 'stats') {
                $all_categories['stats']['weight'] = $all_categories['stats']['weight'] + $all_categories["{$category}"]['stats']['weight'];
                $all_categories['stats']['totalpoints'] = $all_categories['stats']['totalpoints'] + $all_categories["{$category}"]['stats']['totalpoints'];
            }
        }
        // set each individuals total points by category so we can then exclude some grades if set to use exceptions
        if (isset($grades_by_student)) {
            foreach ($grades_by_student as $student => $categories) {
                foreach ($all_categories as $category => $assignments) {
                    if ($category != 'stats') {
                        $grades_by_student["{$student}"]["{$category}"]['stats']['totalpoints'] = $all_categories["{$category}"]['stats']['totalpoints'];
                    }
                }
                $grades_by_student["{$student}"]['student_data']['totalpoints'] = $all_categories['stats']['totalpoints'];
            }
        }
        // take into account any excluded grade_items
        $strexcluded = get_string('excluded', 'grades');
        $exceptions = grade_get_exceptions($course->id);
        if (isset($exceptions) && $exceptions) {
            foreach ($exceptions as $exception) {
                if (isset($grades_by_student["{$exception->userid}"])) {
                    if ($grades_by_student["{$exception->userid}"]["{$exception->catname}"]) {
                        $assgn = get_record($exception->modname, 'id', $exception->cminstance, 'course', $course->id);
                        $grades_by_student["{$exception->userid}"]['student_data']['totalpoints'] = $grades_by_student["{$exception->userid}"]['student_data']['totalpoints'] - $all_categories["{$exception->catname}"]["{$assgn->name}"]['maxgrade'];
                        //total point should not be smaller than grade against
                        if ($grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['totalpoints'] - $all_categories["{$exception->catname}"]["{$assgn->name}"]['grade_against'] != 0) {
                            $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['totalpoints'] = $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['totalpoints'] - $all_categories["{$exception->catname}"]["{$assgn->name}"]['grade_against'];
                        }
                        $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['grade_items'] = $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['grade_items'] - 1;
                        if ($grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['grade_items'] < 0) {
                            $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['grade_items'] = 0;
                        }
                        if ($all_categories["{$exception->catname}"]['stats']['drop'] == 0) {
                            $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['points'] = $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['points'] - $grades_by_student["{$exception->userid}"]["{$exception->catname}"]["{$assgn->name}"]['grade'];
                        }
                        $grades_by_student["{$exception->userid}"]["{$exception->catname}"]["{$assgn->name}"]['maxgrade'] = $strexcluded;
                        $grades_by_student["{$exception->userid}"]["{$exception->catname}"]["{$assgn->name}"]['grade'] = $strexcluded;
                        // see if they are excluded entirely from a category
                        if ($grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['totalpoints'] == 0) {
                            $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['totalpoints'] = $strexcluded;
                            $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['percent'] = $strexcluded;
                            $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['points'] = $strexcluded;
                            $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['weight'] = $strexcluded;
                            $grades_by_student["{$exception->userid}"]["{$exception->catname}"]['stats']['weighted'] = $strexcluded;
                        }
                    }
                } else {
                    // the user had exceptions, but was unenrolled from the course... we could delete it here, but we will leave it because the user may be re-added to the course
                }
            }
        }
        if (isset($grades_by_student)) {
            foreach ($grades_by_student as $student => $categories) {
                $grades_by_student["{$student}"]['student_data']['points'] = '-';
                $grades_by_student["{$student}"]['student_data']['totalpoints'] = 0;
                $grades_by_student["{$student}"]['student_data']['weight'] = 0;
                $grades_by_student["{$student}"]['student_data']['weighted'] = 0;
                foreach ($categories as $category => $assignments) {
                    if ($category != 'student_data') {
                        // set the student's total points earned
                        /// MDL-11235, 0 == 'Excluded', so we need to do type equality check too
                        if ($grades_by_student["{$student}"]["{$category}"]['stats']['points'] !== $strexcluded) {
                            if ($grades_by_student["{$student}"]["{$category}"]['stats']['points'] != '-') {
                                $grades_by_student["{$student}"]['student_data']['points'] = $grades_by_student["{$student}"]['student_data']['points'] + $grades_by_student["{$student}"]["{$category}"]['stats']['points'];
                            }
                            $grades_by_student["{$student}"]['student_data']['totalpoints'] = $grades_by_student["{$student}"]['student_data']['totalpoints'] + $grades_by_student["{$student}"]["{$category}"]['stats']['totalpoints'];
                        }
                        // set percents and weights for each assignment
                        foreach ($assignments as $assignment => $info) {
                            if ($assignment != 'stats') {
                                if ($grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['grade'] !== $strexcluded) {
                                    if ($grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['maxgrade'] != 0) {
                                        $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['percent'] = round($grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['grade'] / $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['maxgrade'] * 100, 2);
                                    } else {
                                        $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['percent'] = 0;
                                    }
                                    if ($grades_by_student["{$student}"]["{$category}"]['stats']['totalpoints'] != 0) {
                                        $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['weight'] = round($all_categories["{$category}"]['stats']['weight'] * ($grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['maxgrade'] / $grades_by_student["{$student}"]["{$category}"]['stats']['totalpoints']), 2);
                                    } else {
                                        $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['weight'] = 0.0;
                                    }
                                    if ($grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['weight'] != 0) {
                                        $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['weighted'] = round($grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['percent'] * $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['weight'] / 100, 2);
                                    } else {
                                        // should only be here if this is extra credit
                                        $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['weighted'] = 0.0;
                                    }
                                } else {
                                    $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['percent'] = $strexcluded;
                                    $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['weight'] = $strexcluded;
                                    $grades_by_student["{$student}"]["{$category}"]["{$assignment}"]['weighted'] = $strexcluded;
                                }
                            }
                        }
                        // set the percent and weight per category
                        if ($grades_by_student["{$student}"]["{$category}"]['stats']['totalpoints'] != 0) {
                            $grades_by_student["{$student}"]["{$category}"]['stats']['percent'] = round($grades_by_student["{$student}"]["{$category}"]['stats']['points'] / $grades_by_student["{$student}"]["{$category}"]['stats']['totalpoints'] * 100, 2);
                            $grades_by_student["{$student}"]["{$category}"]['stats']['weighted'] = round($grades_by_student["{$student}"]["{$category}"]['stats']['points'] / $grades_by_student["{$student}"]["{$category}"]['stats']['totalpoints'] * $grades_by_student["{$student}"]["{$category}"]['stats']['weight'], 2);
                        } else {
                            if ($grades_by_student["{$student}"]["{$category}"]['stats']['totalpoints'] !== $strexcluded) {
                                $grades_by_student["{$student}"]["{$category}"]['stats']['percent'] = 0.0;
                                $grades_by_student["{$student}"]["{$category}"]['stats']['weighted'] = 0.0;
                            }
                        }
                        // set students overall weight (this is what percent they will be graded against)
                        if ($grades_by_student["{$student}"]["{$category}"]['stats']['weight'] !== $strexcluded) {
                            $grades_by_student["{$student}"]['student_data']['weight'] = $grades_by_student["{$student}"]['student_data']['weight'] + $grades_by_student["{$student}"]["{$category}"]['stats']['weight'];
                        }
                        // set the students total categories towards point total we have to defer the percent calculation until we know what total weight they should be graded against since they may
                        // be excluded from a whole category.
                        if ($all_categories["{$category}"]['stats']['totalpoints'] != 0) {
                            $grades_by_student["{$student}"]['student_data']['weighted'] = $grades_by_student["{$student}"]['student_data']['weighted'] + $grades_by_student["{$student}"]["{$category}"]['stats']['weighted'];
                        }
                    }
                }
                // set the percent and weight overall
                if ($grades_by_student["{$student}"]['student_data']['totalpoints'] != 0 && $grades_by_student["{$student}"]['student_data']['totalpoints'] !== $strexcluded) {
                    $grades_by_student["{$student}"]['student_data']['percent'] = round($grades_by_student["{$student}"]['student_data']['points'] / $grades_by_student["{$student}"]['student_data']['totalpoints'] * 100, 2);
                    if ($grades_by_student["{$student}"]['student_data']['weight'] != 0) {
                        $grades_by_student["{$student}"]['student_data']['weighted'] = round($grades_by_student["{$student}"]['student_data']['weighted'] / $grades_by_student["{$student}"]['student_data']['weight'] * 100, 2);
                    } else {
                        $grades_by_student["{$student}"]['student_data']['weighted'] = 0.0;
                    }
                } else {
                    if ($grades_by_student["{$student}"]['student_data']['totalpoints'] == 0) {
                        $grades_by_student["{$student}"]['student_data']['percent'] = 0.0;
                    }
                }
            }
        }
        if (isset($grades_by_student)) {
            $sort = optional_param('sort', 'default');
            switch ($sort) {
                case 'highgrade_category':
                    uasort($grades_by_student, 'grade_sort_by_highgrade_category');
                    break;
                case 'highgrade_category_asc':
                    uasort($grades_by_student, 'grade_sort_by_highgrade_category_asc');
                    break;
                case 'highgrade':
                    if ($preferences->use_weighted_for_letter == 1) {
                        uasort($grades_by_student, 'grade_sort_by_weighted');
                    } else {
                        uasort($grades_by_student, 'grade_sort_by_percent');
                    }
                    break;
                case 'points':
                    uasort($grades_by_student, 'grade_sort_by_points');
                    break;
                case 'points_asc':
                    uasort($grades_by_student, 'grade_sort_by_points_asc');
                    break;
                case 'weighted':
                    uasort($grades_by_student, 'grade_sort_by_weighted');
                    break;
                case 'weighted_asc':
                    uasort($grades_by_student, 'grade_sort_by_weighted_asc');
                    break;
                case 'percent':
                    uasort($grades_by_student, 'grade_sort_by_percent');
                    break;
                case 'percent_asc':
                    uasort($grades_by_student, 'grade_sort_by_percent_asc');
                    break;
                case 'highgrade_asc':
                    if ($preferences->use_weighted_for_letter == 1) {
                        uasort($grades_by_student, 'grade_sort_by_weighted_asc');
                    } else {
                        uasort($grades_by_student, 'grade_sort_by_percent_asc');
                    }
                    break;
                case 'firstname':
                    uasort($grades_by_student, 'grade_sort_by_firstname');
                    break;
                default:
                    uasort($grades_by_student, 'grade_sort_by_lastname');
            }
        } else {
            $grades_by_student = 0;
        }
        $retval = array($grades_by_student, $all_categories);
    } else {
        $retval = array(0, 0);
        // echo "<center><font color=red>Could not find any graded items for this course.</font></center>";
    }
    return $retval;
}
Ejemplo n.º 11
0
function skype_show($skype, $user, $cm, $what = "form")
{
    global $USER;
    $which_group = user_group($cm->course, $user->id);
    if (!$which_group) {
        $g_id = 0;
    } else {
        foreach ($which_group as $www => $xxx) {
            $g_id = $xxx->id;
        }
    }
    if ($skype->participants == '0') {
        //0 for students, 1 for tutors of course
        if ($g_id == 0) {
            $call_users = get_course_users($cm->course);
        } else {
            $call_users = get_group_users($g_id);
        }
    } else {
        $call_users = get_course_teachers($cm->course);
    }
    $return = "";
    if ($call_users) {
        foreach ($call_users as $call_user) {
            if ($call_user->skype) {
                $skypeid = $call_user->skype;
                if ($what == "casts") {
                    $return .= '
					<script type="text/javascript" src="https://feedsskypecasts.skype.com/skypecasts/webservice/get.js?limit=100&amp;user='******'"></script>
					<script language="javascript" type="text/javascript">//<![CDATA[
					var cast;
					var cntx=0;
					for(i in Skypecasts) {
					  cntx=1;
					  cast = Skypecasts[i];
					  document.write("<a target=\\"_blank\\" href=\\""+cast.url_info+"\\"><img src=\\"skypecast_icon.gif\\" border=0 width=\\"76\\" height=\\"76\\" alt=\\""+cast.title+"\\" /></a>");
					  document.write("<p class=\\"skypecast-title\\"><a target=\\"_blank\\" href=\\""+cast.url_info+"\\">"+cast.title+"</a></p>");
					  document.write("<p class=\\"skypecast-host\\">' . get_string("moderator", "skype") . ': "+cast.host_name+"</p>");
					  document.write("<p class=\\"skypecast-date\\">"+cast.start_time_hint+"</p>");
					}
					 if(cntx == 0){
					   document.write("<p class=\\"skypecast-title\\">There are no Skypecasts for you!</p><br><br><br>");
					   document.write("<p class=\\"skypecast-title\\"><br><br><br><br><br><br><br><br>&nbsp;</p>");
					 }
					//]]></script>
					';
                } else {
                    if ($USER->id != $call_user->id) {
                        $return .= "\n\t\t\t\t\t\t<option value='{$skypeid}'>" . fullname($call_user, true) . "</option>";
                    }
                }
            }
        }
    } else {
        $call_users = get_course_users($cm->course);
        if ($call_users) {
            foreach ($call_users as $call_user) {
                if ($call_user->skype) {
                    $skypeid = $call_user->skype;
                    if ($what == "casts") {
                        $return .= '
							<script type="text/javascript" src="https://feedsskypecasts.skype.com/skypecasts/webservice/get.js?limit=100&amp;user='******'"></script>
							<script language="javascript" type="text/javascript">//<![CDATA[
							var cast;
							var cntx=0;
							for(i in Skypecasts) {
							  cntx=1;
							  cast = Skypecasts[i];
							  document.write("<a target=\\"_blank\\" href=\\""+cast.url_info+"\\"><img src=\\"skypecast_icon.gif\\" border=0 width=\\"76\\" height=\\"76\\" alt=\\""+cast.title+"\\" /></a>");
							  document.write("<p class=\\"skypecast-title\\"><a target=\\"_blank\\" href=\\""+cast.url_info+"\\">"+cast.title+"</a></p>");
							  document.write("<p class=\\"skypecast-host\\">' . get_string("moderator", "skype") . ': "+cast.host_name+"</p>");
							  document.write("<p class=\\"skypecast-date\\">"+cast.start_time_hint+"</p>");
							}
							 if(cntx == 0){
							   document.write("<p class=\\"skypecast-title\\">There are no Skypecasts for you!</p><br><br><br>");
							   document.write("<p class=\\"skypecast-title\\"><br><br><br><br><br><br><br><br>&nbsp;</p>");
							 }
							//]]></script>
							';
                    } else {
                        if ($USER->id != $call_user->id) {
                            $return .= "\n\t\t\t\t\t\t\t\t<option value='{$skypeid}'>" . fullname($call_user, true) . "</option>";
                        }
                    }
                }
            }
        }
    }
    return $return;
}
// this is how many students you see per page  (Even number is smartest for looks)
// need some security check here... I think? for read and write
// these are ones that have been checked and submitted to the page
if (isset($_REQUEST['read'])) {
    $read = $_REQUEST['read'];
} else {
    $read = array();
}
if (isset($_REQUEST['write'])) {
    $write = $_REQUEST['write'];
} else {
    $write = array();
}
// either grab all the students or grab all the students in a given group
if ($groupid != -1) {
    $students = get_group_users($groupid, 'u.firstname ASC, u.lastname ASC');
} else {
    $students = get_course_students($courseid, "u.firstname ASC, u.lastname ASC", "", 0, 99999, '', '', NULL, '', 'u.id,u.firstname,u.lastname');
}
if (!($groups = get_groups($courseid))) {
    $groups = array();
}
// dont think we need to pass anything here... ?
print_header("", "", "", "", "", true, "");
print_heading(get_string('permissions', 'netpublish'), 'center', 3);
// start the form off
echo "<form method=\"post\" action=\"permissions.php\" name=\"theform\" id=\"theform\">\n    <input type=\"hidden\" name=\"id\" value=\"{$courseid}\" />\n    <input type=\"hidden\" name=\"groupid\" value=\"\" />";
// making tabs
$tabs = array();
$tabrows = array();
// this tab is for viewing all the students
<?php 
if ($groupmode) {
    ?>
        <td width="50%">
<?php 
    /// print table of outstanding appointer (groups)
    print_heading(get_string('schedulegroups', 'scheduler'));
    if (empty($groups)) {
        notify(get_string('nogroups', 'scheduler'));
    } else {
        $mtable->head = array('', $strname, $straction);
        $mtable->align = array('CENTER', 'LEFT', 'CENTER');
        $mtable->width = array('', '', '');
        $mtable->data = array();
        foreach ($groups as $group) {
            $members = get_group_users($group->id, 'lastname', '', 'u.id, lastname, firstname, email, picture');
            if (empty($members)) {
                continue;
            }
            if (!scheduler_has_slot(implode(',', array_keys($members)), $scheduler, true, $scheduler->schedulermode == 'onetime')) {
                $actions = '<span style="font-size: x-small;">';
                $actions .= "<a href=\"view.php?what=schedulegroup&amp;id={$cm->id}&amp;groupid={$group->id}&amp;page={$page}\">";
                $actions .= get_string('schedule', 'scheduler');
                $actions .= '</a></span>';
                $groupmembers = array();
                foreach ($members as $member) {
                    $groupmembers[] = fullname($member);
                }
                $groupcrew = '[' . implode(", ", $groupmembers) . ']';
                $mtable->data[] = array('', $groups[$group->id]->name . ' ' . $groupcrew, $actions);
            }
// Instance scale
$wiki = get_record('wiki', 'id', $wikimain->instance);
// Instance wiki
///////////// MAKE A SELECTORS STUDENT - GROUP - EVERYBODY
/// Setup for group handling.
if ($cmodule->groupmode == 0) {
    $showgroups = false;
} else {
    if ($cmodule->groupmode == 1 || $cmodule->groupmode == 2) {
        $showgroups = true;
    }
}
// We're interested in all our site users
if ($selectedgroup != 0) {
    // 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');
    //print_object("Porgrupo");
} else {
    $courseusers = get_course_users($course->id, 'u.lastname ASC', '', 'u.id, u.firstname, u.lastname, u.idnumber');
    //print_object("Porcurso");
}
// Get all the possible users
$users = array();
if ($courseusers) {
    foreach ($courseusers as $courseuser) {
        $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context));
    }
}
///////////////////////////////////////////////////////////////////////
///////////////// POST-EVALUATION (GRADEBOOK) /////////////////////////
///////////////////////////////////////////////////////////////////////
Ejemplo n.º 15
0
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!has_capability('mod/survey:readresponses', $context)) {
    if ($type != "student.png" or $sid != $USER->id) {
        error("Sorry, you aren't allowed to see this.");
    } else {
        if ($groupmode and !ismember($group)) {
            error("Sorry, you aren't allowed to see this.");
        }
    }
}
if (!($survey = get_record("survey", "id", $cm->instance))) {
    error("Survey ID was incorrect");
}
/// Check to see if groups are being used in this survey
if ($groupmode and $group) {
    $users = get_group_users($group);
} else {
    $users = get_course_users($course->id);
    $group = false;
}
$stractual = get_string("actual", "survey");
$stractualclass = get_string("actualclass", "survey");
$stractualstudent = get_string("actualstudent", "survey", $course->student);
$strpreferred = get_string("preferred", "survey");
$strpreferredclass = get_string("preferredclass", "survey");
$strpreferredstudent = get_string("preferredstudent", "survey", $course->student);
$virtualscales = false;
//set default value for case clauses
switch ($type) {
    case "question.png":
        $question = get_record("survey_questions", "id", $qid);
Ejemplo n.º 16
0
$strgradeiteminfopeople = get_string('gradeiteminfopeople', 'grades');
$strgradeitemrandomassign = get_string('gradeitemrandomassign', 'grades');
$strgradeitemaddusers = get_string('gradeitemaddusers', 'grades');
$strgradeitems = get_string('gradeitems', 'grades');
$courseid = $course->id;
$listgrade_items = array();
$listmembers = array();
$nonmembers = array();
$grade_items = array();
$grade_items = get_records('grade_item', 'courseid', $course->id);
$grade_itemcount = count($grade_items);
// get current group of students and assign that to be the working list of students
if (groupmode($course) != 0) {
    if ($currentgroup = get_current_group($course->id)) {
        //groupmode is either separate or visible and there is a group
        $students = get_group_users($group);
    } else {
        //groupmode is either separate or visible and the current group is all participants
        $students = grade_get_course_students($course->id);
    }
} else {
    $students = grade_get_course_students($course->id);
    //groupmode is not set (all participants)
}
// we need to create a multidimensional array keyed by grade_itemid with all_students at each level
if (isset($grade_items)) {
    foreach ($grade_items as $grade_item) {
        $nonmembers[$grade_item->id] = array();
        if ($students) {
            foreach ($students as $student) {
                $nonmembers[$grade_item->id][$student->id] = fullname($student, true);
Ejemplo n.º 17
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>';
}
 if ($students) {
     foreach ($students as $student) {
         $nonmembers[$student->id] = fullname($student, true);
     }
     //unset($students);
 }
 if ($groups) {
     $gusers = false;
     foreach ($groups as $idx => $group) {
         /// Skip groupings.
         if (!is_numeric($idx)) {
             continue;
         }
         $countusers = 0;
         $listmembers[$group->id] = array();
         if (!($groupusers = get_group_users($group->id))) {
             $groupusers = array();
         }
         if ($sgroupid === $group->id) {
             $gusers = $groupusers;
             /// If its a grouping selection:
         } else {
             if ($sgroupid !== false && !is_numeric($sgroupid)) {
                 $gusers = array();
             }
         }
         foreach ($groupusers as $groupuser) {
             if ($groupuser->deleted == 1) {
                 unset($nonmembers[$groupuser->id]);
                 groups_remove_member($group->id, $groupuser->id);
                 //                            og_set_student($groupuser->id); /// Deassigns as a designated teacher.