function get_content()
 {
     global $CFG, $COURSE, $USER;
     if (empty($this->instance)) {
         $this->content = '';
         return $this->content;
     }
     // the following 3 lines is need to pass _self_test();
     if (empty($this->instance->pageid)) {
         return '';
     }
     $this->content = new object();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     /// MDL-13252 Always get the course context or else the context may be incorrect in the user/index.php
     if (!($currentcontext = get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
         $this->content = '';
         return $this->content;
     }
     if ($COURSE->id == SITEID) {
         if (!has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
             $this->content = '';
             return $this->content;
         }
     } else {
         if (!has_capability('moodle/course:viewparticipants', $currentcontext)) {
             $this->content = '';
             return $this->content;
         }
     }
     // a nice sample of how to get a data from a table:
     $uif = get_field('user_info_field', 'id', 'shortname', 'class');
     //echo "uif = $uif<br/>";
     $currentuserclass = get_field('user_info_data', 'data', 'userid', $USER->id, 'fieldid', $uif);
     //echo "udf data (class) = $udf<br/>";
     $courseusers = get_course_users($COURSE->id);
     foreach ($courseusers as $cuser) {
         $currentclass = get_field('user_info_data', 'data', 'userid', $cuser->id, 'fieldid', $uif);
         if ($currentclass == $currentuserclass) {
             $this->content->items[] = "<a href=\"{$CFG->wwwroot}/blog/index.php?userid={$cuser->id}&courseid={$COURSE->id}\" >{$cuser->firstname} {$cuser->lastname}</a>";
             $this->content->icons[] = "<img src=\"{$CFG->wwwroot}/user/pix.php/{$cuser->id}/f2.jpg\" class=\"icon\" alt=\"\" />";
         }
     }
     return $this->content;
 }
Пример #2
0
/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod.html) this function
 * will create a new instance and return the id number
 * of the new instance.
 * @param object $forum add forum instance (with magic quotes)
 * @return int intance id
 */
function forum_add_instance($forum)
{
    global $CFG;
    $forum->timemodified = time();
    if (empty($forum->assessed)) {
        $forum->assessed = 0;
    }
    if (empty($forum->ratingtime) or empty($forum->assessed)) {
        $forum->assesstimestart = 0;
        $forum->assesstimefinish = 0;
    }
    if (!($forum->id = insert_record('forum', $forum))) {
        return false;
    }
    if ($forum->type == 'single') {
        // Create related discussion.
        $discussion = new object();
        $discussion->course = $forum->course;
        $discussion->forum = $forum->id;
        $discussion->name = $forum->name;
        $discussion->intro = $forum->intro;
        $discussion->assessed = $forum->assessed;
        $discussion->format = $forum->type;
        $discussion->mailnow = false;
        $discussion->groupid = -1;
        if (!forum_add_discussion($discussion, $discussion->intro)) {
            error('Could not add the discussion for this forum');
        }
    }
    if ($forum->forcesubscribe == FORUM_INITIALSUBSCRIBE) {
        // all users should be subscribed initially
        $users = get_course_users($forum->course);
        foreach ($users as $user) {
            forum_subscribe($user->id, $forum->id);
        }
    }
    $forum = stripslashes_recursive($forum);
    forum_grade_item_update($forum);
    return $forum->id;
}
Пример #3
0
/**
 * Gets the users for a course who are not in a specified group
 * @param int $groupid The id of the group
 * @return array An array of the userids of the non-group members,  or false if 
 * an error occurred. 
 */
function groups_get_users_not_in_group($courseid, $groupid)
{
    $users = get_course_users($courseid);
    $userids = groups_users_to_userids($users);
    $nongroupmembers = array();
    foreach ($userids as $userid) {
        if (!groups_is_member($groupid, $userid)) {
            array_push($nongroupmembers, $userid);
        }
    }
    return $nongroupmembers;
}
Пример #4
0
/**
* @desc Finds all the participants in the course
* @param string $wwassignmentid The Moodle wwassignment ID.
* @return array An array of course users (IDs).
*/
function wwassignment_get_participants($wwassignmentid)
{
    $wwassignment = get_record('wwassignment', 'id', $wwassignmentid);
    if (!isset($wwassignment)) {
        return array();
    }
    return get_course_users($wwassignment->course);
}
Пример #5
0
 * This view provides a summary for the teacher
 * 
 * @package mod-poodllflashcard
 * @category mod
 * @author Valery Fremaux, Gustav Delius
 * @contributors
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 */
// security
if (!defined('MOODLE_INTERNAL')) {
    error("Illegal direct access to this screen");
}
if ($action != '') {
    include "{$CFG->dirroot}/mod/poodllflashcard/usersummaryview.controller.php";
}
$courseusers = get_course_users($COURSE->id);
$struser = get_string('username');
$strdeckstates = get_string('deckstates', 'poodllflashcard');
$strcounts = get_string('counters', 'poodllflashcard');
$table->head = array("<b>{$struser}</b>", "<b>{$strdeckstates}</b>", "<b>{$strcounts}</b>");
$table->size = array('30%', '50%', '20%');
$table->width = "90%";
if (!empty($courseusers)) {
    foreach ($courseusers as $auser) {
        $status = poodllflashcard_get_deck_status($flashcard, $auser->id);
        // if (has_capability('mod/poodllflashcard:manage', $context, $auser->id)) continue;
        $userbox = print_user_picture($auser, $COURSE->id, true, false, true, true, '', true);
        $userbox .= fullname($auser);
        if ($status) {
            $flashcard->cm =& $cm;
            $deckbox = poodllflashcard_print_deck_status($flashcard, $auser->id, $status, true);
/**
 * This function is the responsable of printing the group mode menu
 *
 * There are 9 possible combinations of groupmode-studentmode.
 *
 * 	Groupmode	Studentmode				Description
 * 		0			0			No groups-Users in groups
 * 		0			1			No groups-Separate Users
 * 		0			2			No groups-Visible Users
 * 		1			0			Separate Groups-Users in groups
 * 		1			1			Separate Groups-Separate Users
 * 		1			2			Separate Groups-Visible Users
 * 		2			0			Visible Groups-Users in groups
 * 		2			1			Visible Groups-Separate Users
 * 		2			2			Visible Groups-Visible Users
 *
 *
 * @param WikiStorage $WS.
 *
 * @TODO: this function is filled of bugs. We have to rewrite it.
 *
 */
function wiki_print_groupmode_selection(&$WS)
{
    global $USER, $CFG, $COURSE;
    //this function is the responsable of printing the group mode menu
    //Course groups list
    $wikimanager = wiki_manager_get_instance();
    $listgroups = $wikimanager->get_course_groups($COURSE->id);
    $listmembers = $listgroupsmembers = $wikimanager->get_course_members($COURSE->id);
    $context = get_context_instance(CONTEXT_MODULE, $WS->cm->id);
    $cm->id = isset($WS->dfcourse) ? $COURSE->id : $WS->cm->id;
    switch ($WS->cm->groupmode) {
        //Without groups:
        case '0':
            // if no groups then get all the users of the course
            $listmembers = get_course_users($COURSE->id, 'u.lastname');
            switch ($WS->dfwiki->studentmode) {
                //Commune wiki
                case '0':
                    //no menu
                    break;
                    //Separate students
                //Separate students
                case '1':
                    if (has_capability('mod/wiki:editanywiki', $context)) {
                        wiki_print_menu_students($listmembers, $WS->member->id, $cm);
                    }
                    break;
                    //Visible students
                //Visible students
                case '2':
                    wiki_print_menu_students($listmembers, $WS->member->id, $cm);
                    break;
                default:
                    break;
            }
            break;
            //Separate groups:
        //Separate groups:
        case '1':
            switch ($WS->dfwiki->studentmode) {
                //Students in group
                case '0':
                    wiki_print_menu_groups($listgroups, $WS->groupmember->groupid, $cm, $WS);
                    break;
                    //Separate students
                //Separate students
                case '1':
                    wiki_print_menu_groups_and_students($listgroups, $listgroupsmembers, $WS);
                    break;
                    //Visible students
                //Visible students
                case '2':
                    wiki_print_menu_groups_and_students($listgroups, $listgroupsmembers, $WS);
                    break;
                default:
                    break;
            }
            break;
            //Visible groups:
        //Visible groups:
        case '2':
            switch ($WS->dfwiki->studentmode) {
                //Students in group
                case '0':
                    wiki_print_menu_groups($listgroups, $WS->groupmember->groupid, $cm, $WS);
                    break;
                    //Separate students
                //Separate students
                case '1':
                    wiki_print_menu_groups_and_students($listgroups, $listgroupsmembers, $WS);
                    break;
                    //Visible students
                //Visible students
                case '2':
                    wiki_print_menu_groups_and_students($listgroups, $listgroupsmembers, $WS);
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}
Пример #7
0
    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);
        $question->text = get_string($question->text, "survey");
        $question->options = get_string($question->options, "survey");
 /**
  * Lookup the avatar/real name associations for everybody in the current course.
  * NOTE: fails if a course is not loaded in the current {@link SloodleSession}
  * @return array|bool An associative array of avatar names to (full) real names if successful, or false if a course is not available
  */
 function find_real_names_course()
 {
     // Make sure we have a course loaded
     if (!isset($this->_session)) {
         return false;
     }
     if (!$this->_session->course->is_loaded()) {
         return false;
     }
     $user = new SloodleUser($this->_session);
     // Get a list of users of the course
     $courseusers = get_course_users($this->_session->course->get_course_id());
     if (!is_array($courseusers)) {
         $courseusers = array();
     }
     // Go through each user
     $output = array();
     foreach ($courseusers as $u) {
         // Attempt to fetch the avatar data for this Moodle user
         $user->load_user($u->id);
         if (!$user->load_linked_avatar()) {
             continue;
         }
         // Store the name association
         $output[$user->get_avatar_name()] = $u->firstname . ' ' . $u->lastname;
     }
     return $output;
 }
Пример #9
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;
}
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>';
}
function wiki_grade_get_users_info($courseid, $wikiid)
{
    global $CFG;
    $USERS_PER_PAGE = 18;
    $group = optional_param('group', -1, PARAM_INT);
    if ($group >= 0) {
        $users = get_group_students($group);
        $groups = groups_get_all_groups($courseid);
        $groupname = $groups[$group]->name;
        $a->of = 'of group ' . $groupname;
    } else {
        $users = get_course_users($courseid, 'u.lastname', '', 'u.id, u.firstname, u.lastname, u.idnumber');
        $a->of = '';
    }
    $users = array_values($users);
    $num_users = count($users);
    $num_pages = wiki_grade_get_num_userpages($num_users, $USERS_PER_PAGE);
    $userlistpage = optional_param('userlistpage', 0, PARAM_INT);
    if ($userlistpage >= $num_pages) {
        $userlistpage = 0;
    }
    $from = $userlistpage * $USERS_PER_PAGE;
    if ($userlistpage == $num_pages - 1) {
        $to = $from + $num_users % $USERS_PER_PAGE;
    } else {
        $to = $from + $USERS_PER_PAGE;
    }
    $output = print_box_start('generalbox', '', true);
    $output .= '<div style="float:left">';
    $a->from = $from + 1;
    $a->to = $to;
    $a->total = $num_users;
    $output .= get_string('eval_show_userlist', 'wiki', $a);
    $output .= '</div>';
    $output .= '<div style="float:right">';
    $output .= '<table><tr><td><i>' . get_string('legend', 'wiki') . ':&nbsp;</i></td>';
    $output .= '<td class="borderred">' . get_string('eval_legend_user_nograde', 'wiki') . '</td>';
    $output .= '<td>&nbsp;&nbsp;</td>';
    $output .= '<td class="bordergreen">' . get_string('eval_legend_user_grade', 'wiki') . '</td>';
    $output .= '</tr></table>';
    $output .= '</div>';
    $output .= '<div style="clear:both">&nbsp;</div>';
    if (!$users) {
        echo 'grades.lib.php: there is not any user in this course';
    } else {
        $wikimanager = wiki_manager_get_instance();
        $output .= '<ul class="userlist">';
        $output .= "\n\n" . '<div class="container"><br/>';
        for ($i = $from; $i < $to; $i++) {
            $myuser = $users[$i];
            $output .= '<li>';
            $info = $wikimanager->get_user_info_by_id($myuser->id);
            $grade = grade_get_grades($courseid, 'mod', 'wiki', $wikiid, $myuser->id);
            if (isset($grade->items[0]->grades[$myuser->id])) {
                $grade = $grade->items[0]->grades[$myuser->id]->str_grade;
            } else {
                $grade = null;
            }
            $output .= "\n" . wiki_grade_get_user_info($info, $courseid, $grade);
            $output .= '</li>';
        }
        $output .= '</ul>' . "\n\n";
        $output .= wiki_grade_get_userpages($num_users, $userlistpage, $courseid, $USERS_PER_PAGE);
        $output .= '</tr></td></table>';
        $output .= print_box_end(true);
        echo $output;
    }
}
Пример #12
0
/// Get all discussions that have had posts since the old post date.
if ($discussions = get_records_select('forum_discussions', 'timemodified > ' . $dateafter, 'course', 'id,course,forum,groupid,userid')) {
    $dtotal = count($discussions);
    print_heading('Updating forum post read/unread records for ' . $dtotal . ' discussions...' . 'Please keep this window open until it completes', '', 3);
    $groups = array();
    $currcourse = 0;
    $users = 0;
    $count = 0;
    $dcount = 0;
    foreach ($discussions as $discussion) {
        $dcount++;
        print_progress($dcount, $dtotal);
        if ($discussion->course != $currcourse) {
            /// Discussions are ordered by course, so we only need to get any course's users once.
            $currcourse = $discussion->course;
            $users = get_course_users($currcourse, '', '', 'u.id,u.confirmed');
        }
        /// If this course has users, and posts more than a day old, mark them for each user.
        if ($users && ($posts = get_records_select('forum_posts', 'discussion = ' . $discussion->id . ' AND ' . $dateafter . ' < modified AND modified < ' . $onedayago, '', 'id,discussion,modified'))) {
            foreach ($users as $user) {
                /// If its a group discussion, make sure the user is in the group.
                if ($discussion->groupid) {
                    if (!isset($groups[$discussion->groupid][$user->id])) {
                        $groups[$discussion->groupid][$user->id] = ismember($discussion->groupid, $user->id);
                    }
                }
                if (!$discussion->groupid || !empty($groups[$discussion->groupid][$user->id])) {
                    foreach ($posts as $post) {
                        print_progress($dcount, $dtotal);
                        forum_tp_mark_post_read($user->id, $post, $discussion->forum);
                    }
Пример #13
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);
    }
}
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;
}
Пример #15
0
/**
 * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
 * @author: Patrick Cool <*****@*****.**>, Ghent University
 */
function show_user_group_filter_form()
{
    echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
    echo "<option value=\"agenda.php?user=none&action=view\">" . get_lang("ShowAll") . "</option>";
    // Groups
    $group_list = get_course_groups();
    $group_available_to_access = array();
    $option = '';
    if (!empty($group_list)) {
        $option = "<optgroup label=\"" . get_lang("Groups") . "\">";
        foreach ($group_list as $this_group) {
            // echo "<option value=\"agenda.php?isStudentView=true&amp;group=".$this_group['id']."\">".$this_group['name']."</option>";
            $has_access = GroupManager::user_has_access(api_get_user_id(), $this_group['id'], GroupManager::GROUP_TOOL_CALENDAR);
            $result = GroupManager::get_group_properties($this_group['id']);
            if ($result['calendar_state'] != '0') {
                $group_available_to_access[] = $this_group['id'];
            }
            // lastedit
            if ($has_access || $result['calendar_state'] == '1') {
                $option .= "<option value=\"agenda.php?action=view&group=" . $this_group['id'] . "\" ";
                $option .= $this_group['id'] == $_SESSION['group'] ? " selected" : "";
                $option .= ">" . $this_group['name'] . "</option>";
            }
        }
        $option .= "</optgroup>";
    }
    echo $option;
    // Users
    $user_list = get_course_users();
    if (!empty($user_list)) {
        echo "<optgroup label=\"" . get_lang("Users") . "\">";
        foreach ($user_list as $this_user) {
            echo "<option value=\"agenda.php?action=view&user="******"\" ";
            echo isset($_SESSION['user']) && $this_user['uid'] == $_SESSION['user'] ? " selected" : "";
            echo ">" . api_get_person_name($this_user['firstName'], $this_user['lastName']) . "</option>";
        }
        echo "</optgroup>";
    }
    echo "</select>";
}
Пример #16
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;
}
Пример #17
0
 /**
  * Render the view of the module or feature.
  * This MUST be overridden to provide functionality.
  */
 function render()
 {
     global $CFG, $USER;
     // Get the localization strings
     $strsloodle = get_string('modulename', 'sloodle');
     $strsloodles = get_string('modulenameplural', 'sloodle');
     // Open the main body section
     echo '<div style="text-align:center;padding-left:8px;padding-right:8px;">';
     //------------------------------------------------------
     print_box_start('generalbox boxwidthwide boxaligncenter');
     echo '<table style="text-align:left; vertical-align:top; margin-left:auto; margin-right:auto;">';
     // // SEARCH FORMS // //
     echo '<tr>';
     // COURSE SELECT FORM //
     echo '<td style="width:350px; border:solid 1px #bbbbbb; padding:4px; vertical-align:top; width:33%;">';
     echo "<form action=\"{$CFG->wwwroot}/mod/sloodle/view.php\" method=\"get\">";
     echo '<input type="hidden" name="_type" value="users" />';
     echo '<span style="font-weight:bold;">' . get_string('changecourse', 'sloodle') . '</span><br/>';
     echo '<select name="course" size="1">';
     // Get a list of all courses
     $allcourses = get_courses('all', 'c.shortname', 'c.id, c.shortname, c.fullname');
     if (!$allcourses) {
         $allcourses = array();
     }
     foreach ($allcourses as $as) {
         // Is the user able to view this particular course?
         if ($as->id == SITEID || has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $as->id))) {
             // Output this as an option
             echo "<option value=\"{$as->id}\"";
             if ($as->id == $this->courseid) {
                 echo "selected";
             }
             echo ">{$as->fullname}</option>";
         }
     }
     echo '</select><br/>';
     echo '<input type="checkbox" value="true" name="sloodleonly"';
     if ($this->sloodleonly) {
         echo "checked";
     }
     echo '/>' . get_string('showavatarsonly', 'sloodle') . '<br/>';
     echo '<input type="submit" value="' . get_string('submit', 'sloodle') . '" />';
     echo '</form>';
     echo '</td>';
     // USER SEARCH FORM //
     echo '<td style="width:350px; border:solid 1px #bbbbbb; padding:4px; vertical-align:top; width:33%;">';
     echo "<form action=\"{$CFG->wwwroot}/mod/sloodle/view.php\" method=\"get\">";
     echo '<input type="hidden" name="_type" value="users" />';
     echo '<span style="font-weight:bold;">' . get_string('usersearch', 'sloodle') . '</span><br/>';
     echo '<input type="hidden" value="' . $this->courseid . '" name="course"/>';
     echo '<input type="text" value="' . $this->searchstr . '" name="search" size="30" maxlength="30"/><br/>';
     echo '<input type="checkbox" value="true" name="sloodleonly"';
     if ($this->sloodleonly) {
         echo "checked";
     }
     echo '/>' . get_string('showavatarsonly', 'sloodle') . '<br/>';
     echo '<input type="submit" value="' . get_string('submit', 'sloodle') . '" />';
     echo '</form>';
     echo '</td>';
     // AVATAR SEARCH //
     echo '<td style="width:350px; border:solid 1px #bbbbbb; padding:4px; vertical-align:top; width:33%;">';
     //echo '<span style="font-weight:bold;">'.get_string('specialpages','sloodle').'</span><br/>';
     echo "<form action=\"{$CFG->wwwroot}/mod/sloodle/view.php\" method=\"get\">";
     echo '<input type="hidden" name="_type" value="user" />';
     echo '<span style="font-weight:bold;">' . get_string('avatarsearch', 'sloodle') . '</span><br/>';
     echo '<input type="hidden" value="search" name="id"/>';
     echo '<input type="hidden" value="' . $this->courseid . '" name="course"/>';
     echo '<input type="text" value="' . $this->searchstr . '" name="search" size="30" maxlength="30"/><br/>';
     echo '<br/><input type="submit" value="' . get_string('submit', 'sloodle') . '" />';
     echo '</form>';
     // Only provide an "all" link if the user is an admin
     if (isadmin()) {
         echo '<p>';
         echo "<a href=\"{$CFG->wwwroot}/mod/sloodle/view.php?_type=user&amp;id=all\" title=\"" . get_string('viewall', 'sloodle') . "\">";
         print_string('viewall', 'sloodle');
         echo '</a><br/>';
         echo '</p>';
     }
     echo '</td>';
     // // - END FORMS - // //
     echo '</tr>';
     echo '</table>';
     print_box_end();
     //------------------------------------------------------
     // Are we searching for users?
     if ($this->searchstr != NULL) {
         // Display the search term
         echo '<br/><span style="font-size:16pt; font-weight:bold;">' . get_string('usersearch', 'sloodle') . ': ' . $this->searchstr . '</span><br/><br/>';
         // Search the list of users
         $fulluserlist = get_users(true, $this->searchstr);
         if (!$fulluserlist) {
             $fulluserlist = array();
         }
         $userlist = array();
         // Filter it down to members of the course
         foreach ($fulluserlist as $ful) {
             // Is this user on this course?
             if (has_capability('moodle/course:view', $this->course_context, $ful->id)) {
                 // Copy it to our filtered list
                 $userlist[] = $ful;
             }
         }
     } else {
         // Getting all users in a course
         // Display the name of the course
         echo '<br/><span style="font-size:18pt; font-weight:bold;">' . $this->coursefullname . '</span><br/><br/>';
         // Obtain a list of all Moodle users enrolled in the specified course
         $userlist = get_course_users($this->courseid, 'lastname, firstname', '', 'u.id, firstname, lastname');
     }
     // Construct and display a table of Sloodle entries
     if ($userlist) {
         $sloodletable = new stdClass();
         $sloodletable->head = array(get_string('user', 'sloodle'), get_string('avatar', 'sloodle'));
         $sloodletable->align = array('left', 'left');
         $sloodletable->size = array('50%', '50%');
         // Check if our start is past the end of our results
         if ($this->start >= count($userlist)) {
             $this->start = 0;
         }
         // Go through each entry to add it to the table
         $resultnum = 0;
         $resultsdisplayed = 0;
         $maxperpage = 20;
         foreach ($userlist as $u) {
             // Only display this result if it is after our starting result number
             if ($resultnum >= $this->start) {
                 // Reset the line's content
                 $line = array();
                 // Construct URLs to this user's Moodle and SLOODLE profile pages
                 $url_moodleprofile = $CFG->wwwroot . "/user/view.php?id={$u->id}&amp;course={$this->courseid}";
                 $url_sloodleprofile = SLOODLE_WWWROOT . "/view.php?_type=user&amp;id={$u->id}&amp;course={$this->courseid}";
                 // Add the Moodle name
                 $line[] = "<a href=\"{$url_moodleprofile}\">{$u->firstname} {$u->lastname}</a>";
                 // Get the Sloodle data for this Moodle user
                 $sloodledata = get_records('sloodle_users', 'userid', $u->id);
                 if ($sloodledata) {
                     // Display all avatars names, if available
                     $avnames = '';
                     $firstentry = true;
                     foreach ($sloodledata as $sd) {
                         // If this entry is empty, then skip it
                         if (empty($sd->avname) || ctype_space($sd->avname)) {
                             continue;
                         }
                         // Comma separated entries
                         if ($firstentry) {
                             $firstentry = false;
                         } else {
                             $avnames .= ', ';
                         }
                         // Add the current name
                         $avnames .= $sd->avname;
                     }
                     // Add the avatar name(s) to the line
                     $line[] = "<a href=\"{$url_sloodleprofile}\">{$avnames}</a>";
                 } else {
                     // The query failed - if we are showing only Sloodle-enabled users, then skip the rest
                     if ($this->sloodleonly) {
                         continue;
                     }
                     $line[] = '-';
                 }
                 // Add the line to the table
                 $sloodletable->data[] = $line;
                 $resultsdisplayed++;
             }
             // Have we displayed the maximum number of results for this page?
             $resultnum++;
             if ($resultsdisplayed >= $maxperpage) {
                 break;
             }
         }
         // Construct our basic URL to this page
         $basicurl = SLOODLE_WWWROOT . "/view.php?_type=users&amp;course={$this->courseid}";
         if ($this->sloodleonly) {
             $basicurl .= "&amp;sloodleonly=true";
         }
         if (!empty($this->searchstr)) {
             $basicurl .= "&amp;search={$this->searchstr}";
         }
         // Construct the next/previous links
         $previousstart = max(0, $this->start - $maxperpage);
         $nextstart = $this->start + $maxperpage;
         $prevlink = null;
         $nextlink = null;
         if ($previousstart != $this->start) {
             $prevlink = "<a href=\"{$basicurl}&amp;start={$previousstart}\" style=\"color:#0000ff;\">&lt;&lt;</a>&nbsp;&nbsp;";
         }
         if ($nextstart < count($userlist)) {
             $nextlink = "<a href=\"{$basicurl}&amp;start={$nextstart}\" style=\"color:#0000ff;\">&gt;&gt;</a>";
         }
         // Display the next/previous links, if we have at least one
         if (!empty($prevlink) || !empty($nextlink)) {
             echo '<p style="text-align:center; font-size:14pt;">';
             if (!empty($prevlink)) {
                 echo $prevlink;
             } else {
                 echo '<span style="color:#777777;">&lt;&lt;</span>&nbsp;&nbsp;';
             }
             if (!empty($nextlink)) {
                 echo $nextlink;
             } else {
                 echo '<span style="color:#777777;">&gt;&gt;</span>&nbsp;&nbsp;';
             }
             echo '</p>';
         }
         // Display the table
         print_table($sloodletable);
     } else {
         // Failed to query for list of users
         echo '<div style="font-weight:bold; color:red;">';
         print_string('nouserdata', 'sloodle');
         echo '</div>';
     }
     echo '</div>';
     // Close the main body section
     echo '</div>';
 }
 /**
  * Loads data from the database.
  * Note: even if the function fails, it may still have overwritten some or all existing data in the object.
  * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
  * @return bool True if successful, or false otherwise
  */
 function load($id)
 {
     // Make sure the ID is valid
     $id = (int) $id;
     if ($id <= 0) {
         return false;
     }
     // Fetch the course module data
     if (!($this->cm = get_coursemodule_from_id('choice', $id))) {
         sloodle_debug("Failed to load course module instance #{$id}.<br/>");
         return false;
     }
     // Make sure the module is visible
     if ($this->cm->visible == 0) {
         sloodle_debug("Error: course module instance #{$id} not visible.<br/>");
         return false;
     }
     // Load from the primary table: choice instance
     if (!($this->moodle_choice_instance = get_record('choice', 'id', $this->cm->instance))) {
         sloodle_debug("Failed to load choice with instance ID #{$cm->instance}.<br/>");
         return false;
     }
     // Fetch options
     $this->options = array();
     if ($options = get_records('choice_options', 'choiceid', $this->moodle_choice_instance->id)) {
         // Get response data (this uses the standard choice function, in "moodle/mod/choice/lib.php")
         $allresponses = choice_get_response_data($this->moodle_choice_instance, $this->cm, 0);
         foreach ($options as $opt) {
             // Create our option object and add our data
             $this->options[$opt->id] = new SloodleChoiceOption();
             $this->options[$opt->id]->id = $opt->id;
             $this->options[$opt->id]->text = $opt->text;
             $this->options[$opt->id]->maxselections = $opt->maxanswers;
             $this->options[$opt->id]->timemodified = (int) $opt->timemodified;
             // Count the number of selections made
             $numsels = 0;
             if (isset($allresponses[$opt->id])) {
                 $numsels = count($allresponses[$opt->id]);
             }
             $this->options[$opt->id]->numselections = $numsels;
         }
     }
     // Determine how many people on the course have not yet answered
     $users = get_course_users($this->cm->course);
     if (!is_array($users)) {
         $users = array();
     }
     $num_users = count($users);
     $numanswers = (int) count_records('choice_answers', 'choiceid', $this->moodle_choice_instance->id);
     $this->numunanswered = max(0, $num_users - $numanswers);
     return true;
 }
Пример #19
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);
Пример #20
0
/**
 * Returns list of user objects that are subscribed to this forum
 */
function forum_subscribed_users($course, $forum, $groupid = 0, $cache = false)
{
    global $CFG;
    static $resultscache = array();
    if ($cache && isset($resultscache[$forum->id][$groupid])) {
        return $resultscache[$forum->id][$groupid];
    }
    if ($groupid) {
        $grouptables = ", {$CFG->prefix}groups_members gm ";
        $groupselect = "AND gm.groupid = '{$groupid}' AND u.id = gm.userid";
    } else {
        $grouptables = '';
        $groupselect = '';
    }
    if (forum_is_forcesubscribed($forum)) {
        $results = get_course_users($course->id);
        // Otherwise get everyone in the course
    } else {
        $results = get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest, u.emailstop, u.imagealt,\n                                   u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.timezone, u.theme, u.lang, u.trackforums, u.mnethostid\n                              FROM {$CFG->prefix}user u,\n                                   {$CFG->prefix}forum_subscriptions s {$grouptables}\n                             WHERE s.forum = '{$forum->id}'\n                               AND s.userid = u.id\n                               AND u.deleted <> 1  {$groupselect}\n                          ORDER BY u.email ASC");
    }
    // Guest user should never be subscribed to a forum.
    if ($guest = guest_user()) {
        unset($results[$guest->id]);
    }
    if ($cache) {
        $resultscache[$forum->id][$groupid] = $results;
    }
    return $results;
}
Пример #21
0
/**
 * Gets the users for the course who are not in any group of a grouping.
 * @param int $courseid The id of the course
 * @param int $groupingid The id of the grouping
 * @param int $groupid Excludes members of a particular group
 * @return array An array of the userids of the users not in any group of 
 * the grouping or false if an error occurred. 
 */
function groups_get_users_not_in_any_group_in_grouping($courseid, $groupingid, $groupid = false)
{
    $users = get_course_users($courseid);
    $userids = groups_users_to_userids($users);
    $nongroupmembers = array();
    if (!$userids) {
        return $nongroupmembers;
    }
    foreach ($userids as $userid) {
        if (!groups_is_member_of_some_group_in_grouping($userid, $groupingid)) {
            // If a group has been specified don't include members of that group
            if ($groupid and !groups_is_member($userid, $groupid)) {
                array_push($nongroupmembers, $userid);
            } else {
                ///array_push($nongroupmembers, $userid);
            }
        }
    }
    return $nongroupmembers;
}
Пример #22
0
/**
 * Returns a list of all site users
 * Obsolete, just calls get_course_users(SITEID)
 *
 * @uses SITEID
 * @deprecated Use {@link get_course_users()} instead.
 * @param string $fields A comma separated list of fields to be returned from the chosen table.
 * @return object|false  {@link $USER} records or false if error.
 */
function get_site_users($sort = 'u.lastaccess DESC', $fields = '*', $exceptions = '')
{
    return get_course_users(SITEID, $sort, $exceptions, $fields);
}
Пример #23
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>';
}
///////////// 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) /////////////////////////
///////////////////////////////////////////////////////////////////////
if (optional_param('gradebook', NULL, PARAM_ALPHA) === get_string('set', 'wiki')) {
    $evaluateduser = optional_param('select_users_grades', 0, PARAM_INT);
    $evaluatedgrade = optional_param('grade_evaluation_page', 0, PARAM_INT);