Example #1
0
 protected function definition()
 {
     global $CFG, $DB;
     $collection = $this->_customdata['collection'];
     $context = $this->_customdata['context'];
     $mform = $this->_form;
     // Text search box.
     $mform->addElement('text', 'search', get_string('search'));
     $mform->setType('search', PARAM_TEXT);
     $options = array(\mod_mediagallery\base::TYPE_ALL => get_string('typeall', 'mediagallery'), \mod_mediagallery\base::TYPE_IMAGE => get_string('typeimage', 'mediagallery'), \mod_mediagallery\base::TYPE_VIDEO => get_string('typevideo', 'mediagallery'), \mod_mediagallery\base::TYPE_AUDIO => get_string('typeaudio', 'mediagallery'));
     $mform->addElement('select', 'type', get_string('mediatype', 'mediagallery'), $options);
     // Role select dropdown includes all roles, but using course-specific
     // names if applied. The reason for not restricting to roles that can
     // be assigned at course level is that upper-level roles display in the
     // enrolments table so it makes sense to let users filter by them.
     $rolenames = role_fix_names(get_profile_roles($context), $context, ROLENAME_ALIAS, true);
     if (!empty($CFG->showenrolledusersrolesonly)) {
         $rolenames = role_fix_names(get_roles_used_in_context($context));
     }
     $mform->addElement('select', 'role', get_string('role'), array(0 => get_string('all')) + $rolenames);
     // Filter by group.
     $allgroups = groups_get_all_groups($collection->course);
     $groupsmenu[0] = get_string('allparticipants');
     foreach ($allgroups as $gid => $unused) {
         $groupsmenu[$gid] = $allgroups[$gid]->name;
     }
     if (count($groupsmenu) > 1) {
         $mform->addElement('select', 'group', get_string('group'), $groupsmenu);
     }
     // Submit button does not use add_action_buttons because that adds
     // another fieldset which causes the CSS style to break in an unfixable
     // way due to fieldset quirks.
     $group = array();
     $group[] = $mform->createElement('submit', 'submitbutton', get_string('filter'));
     $group[] = $mform->createElement('submit', 'resetbutton', get_string('reset'));
     $group[] = $mform->createElement('submit', 'exportbutton', get_string('exportascsv', 'mediagallery'));
     $mform->addGroup($group, 'buttons', '', ' ', false);
     $mform->addElement('hidden', 'id', $context->instanceid);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'action', 'search');
     $mform->setType('action', PARAM_ALPHA);
 }
Example #2
0
/**
* @desc Finds all of the users in the course
* @param $courseid   -- the course id
* @return record containing user information ( username, userid)
*/
function _wwassignment_get_course_students($courseid)
{
    debugLog("Begin get_course_students({$courseid} )");
    debugLog("courseID is " . print_r($courseid, true));
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    debugLog("context is " . print_r($context, true));
    $users = array();
    $roles_used_in_context = get_roles_used_in_context($context);
    //debugLog("roles used ". print_r($roles_used_in_context, true));
    foreach ($roles_used_in_context as $role) {
        $roleid = $role->id;
        debugLog("roleid should be 5 for a student {$roleid}");
        //debugLog(get_role_users($roleid, $context, true) );
        if ($new_users = get_role_users($roleid, $context, true)) {
            $users = array_merge($users, $new_users);
            //FIXME a user could be liseted twice
        }
        debugLog("display users " . print_r($users, true));
    }
    debugLog("display users in course--on");
    debugLog("users again" . print_r($users, true));
    debugLog("End get_course_students({$courseid} )");
    return $users;
}
 /**
  * Test used role query.
  */
 public function test_get_roles_used_in_context()
 {
     global $DB;
     $this->resetAfterTest();
     $systemcontext = context_system::instance();
     $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'), '*', MUST_EXIST);
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     $otherid = create_role('Other role', 'other', 'Some other role', '');
     $teacherrename = (object) array('roleid' => $teacherrole->id, 'name' => 'Učitel', 'contextid' => $coursecontext->id);
     $DB->insert_record('role_names', $teacherrename);
     $otherrename = (object) array('roleid' => $otherid, 'name' => 'Ostatní', 'contextid' => $coursecontext->id);
     $DB->insert_record('role_names', $otherrename);
     $user1 = $this->getDataGenerator()->create_user();
     role_assign($teacherrole->id, $user1->id, $coursecontext->id);
     $roles = get_roles_used_in_context($coursecontext);
     $this->assertCount(1, $roles);
     $role = reset($roles);
     $roleid = key($roles);
     $this->assertEquals($roleid, $role->id);
     $this->assertEquals($teacherrole->id, $role->id);
     $this->assertSame($teacherrole->name, $role->name);
     $this->assertSame($teacherrole->shortname, $role->shortname);
     $this->assertEquals($teacherrole->sortorder, $role->sortorder);
     $this->assertSame($teacherrename->name, $role->coursealias);
     $user2 = $this->getDataGenerator()->create_user();
     role_assign($teacherrole->id, $user2->id, $systemcontext->id);
     role_assign($otherid, $user2->id, $systemcontext->id);
     $roles = get_roles_used_in_context($systemcontext);
     $this->assertCount(2, $roles);
 }
Example #4
0
/**
 * Gets potential group members for grouping
 * @param int $courseid The id of the course
 * @param int $roleid The role to select users from
 * @param string $orderby The colum to sort users by
 * @return array An array of the users
 */
function groups_get_potential_members($courseid, $roleid = null, $orderby = 'lastname,firstname')
{
    global $CFG;
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    $rolenames = array();
    $avoidroles = array();
    if ($roles = get_roles_used_in_context($context, true)) {
        $canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
        $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);
        foreach ($roles as $role) {
            if (!isset($canviewroles[$role->id])) {
                // Avoid this role (eg course creator)
                $avoidroles[] = $role->id;
                unset($roles[$role->id]);
                continue;
            }
            if (isset($doanythingroles[$role->id])) {
                // Avoid this role (ie admin)
                $avoidroles[] = $role->id;
                unset($roles[$role->id]);
                continue;
            }
            $rolenames[$role->id] = strip_tags(role_get_name($role, $context));
            // Used in menus etc later on
        }
    }
    $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.idnumber ';
    $from = "FROM {$CFG->prefix}user u INNER JOIN\n               {$CFG->prefix}role_assignments r on u.id=r.userid ";
    if ($avoidroles) {
        $adminroles = 'AND r.roleid NOT IN (';
        $adminroles .= implode(',', $avoidroles);
        $adminroles .= ')';
    } else {
        $adminroles = '';
    }
    // we are looking for all users with this role assigned in this context or higher
    if ($usercontexts = get_parent_contexts($context)) {
        $listofcontexts = '(' . implode(',', $usercontexts) . ')';
    } else {
        $listofcontexts = '(' . $sitecontext->id . ')';
        // must be site
    }
    if ($roleid) {
        $selectrole = " AND r.roleid = {$roleid} ";
    } else {
        $selectrole = " ";
    }
    $where = "WHERE (r.contextid = {$context->id} OR r.contextid in {$listofcontexts})\n                     AND u.deleted = 0 {$selectrole}\n                     AND u.username != 'guest'\n                     {$adminroles} ";
    $order = "ORDER BY {$orderby} ";
    return get_records_sql($select . $from . $where . $order);
}
Example #5
0
$alternates = $DB->get_records_menu('block_clampmail_alternate', $alt_params, '', 'id, address');
$blockname = clampmail::_s('pluginname');
$header = clampmail::_s('email');
$PAGE->set_context($context);
$PAGE->set_course($course);
$PAGE->navbar->add($blockname);
$PAGE->navbar->add($header);
$PAGE->set_title($blockname . ': ' . $header);
$PAGE->set_heading($blockname . ': ' . $header);
$PAGE->set_url('/course/view.php', array('courseid' => $courseid));
$PAGE->set_pagetype($blockname);
$PAGE->set_pagelayout('standard');
$PAGE->requires->js('/blocks/clampmail/js/jquery.js');
$PAGE->requires->js('/blocks/clampmail/js/selection.js');
// Build role arrays.
$course_roles = get_roles_used_in_context($context);
$filter_roles = $DB->get_records_select('role', sprintf('id IN (%s)', $config['roleselection']));
$roles = clampmail::filter_roles($course_roles, $filter_roles);
// Add role names.
foreach ($roles as $id => $role) {
    if (empty($role->name)) {
        $roles[$id]->name = role_get_name($role, $context);
    }
}
$allgroups = groups_get_all_groups($courseid);
$mastercap = true;
$groups = $allgroups;
if (!has_capability('moodle/site:accessallgroups', $context)) {
    $mastercap = false;
    $mygroups = groups_get_user_groups($courseid);
    $gids = implode(',', array_values($mygroups['0']));
Example #6
0
$praxeaction = optional_param('praxeaction', null, PARAM_ALPHAEXT);
/// extra praxe action ///
if (!is_null($praxeaction)) {
    require_once $CFG->dirroot . '/mod/praxe/praxeaction.php';
}
/// rights to all actions in this module ///
if (has_capability('mod/praxe:manageallincourse', $context) || has_capability('mod/praxe:assignselftoinspection', $context)) {
    $viewrole = 'EDITTEACHER';
    $role_title = get_string('teacher', 'praxe');
    /// rights to create or manage own record of praxe - for students ///
} else {
    if (has_capability('mod/praxe:editownrecord', $context)) {
        $viewrole = 'STUDENT';
        $role_title = get_string('student', 'praxe');
    } else {
        foreach (get_roles_used_in_context($context) as $role) {
            if (user_has_role_assignment($USER->id, $role->id, $context->id)) {
                if ($role->shortname == 'extheadmaster') {
                    $viewrole = 'HEADM';
                    $role_title = get_string('headmaster', 'praxe');
                } else {
                    if ($role->shortname == 'extteacher') {
                        $viewrole = 'EXTTEACHER';
                        $role_title = get_string('extteacher', 'praxe');
                    }
                }
                break;
            }
        }
    }
}
Example #7
0
} else {
    $groupid = 0;
}
$usrcanjoin = false;
$usrgroups = groups_get_user_groups($cm->course, $usrobj->id);
$usrgroups = $usrgroups[0];
// Just want groups and not groupings
// If separate groups is enabled, check if the user is a part of the selected group
if (0 != $cm->groupmode) {
    if (false !== array_search($groupid, $usrgroups)) {
        $usrcanjoin = true;
    }
}
$context = get_context_instance(CONTEXT_COURSE, $cm->course);
// Make sure the user has a role in the course
$crsroles = get_roles_used_in_context($context);
if (empty($crsroles)) {
    $crsroles = array();
}
foreach ($crsroles as $roleid => $crsrole) {
    if (user_has_role_assignment($usrobj->id, $roleid, $context->id)) {
        $usrcanjoin = true;
    }
}
// user has to be in a group
if ($usrcanjoin and confirm_sesskey($sesskey)) {
    $usrprincipal = 0;
    $validuser = true;
    $groupobj = groups_get_group($groupid);
    // Get the meeting sco-id
    $param = array('instanceid' => $cm->instance, 'groupid' => $groupid);
/**
 * This function show all participants of one course. Choose user/s to sent mail.
 *
 * @uses $CFG, $USER
 * @param int $courseid Course ID
 * @param int $roleid   Role ID
 * @param int $currentgroup Current group
 * @return Array Users to sending mail.
 * @todo Finish documenting this function
 */
function email_choose_users_to_send($courseid, $roleid, $currentgroup)
{
    global $CFG, $USER;
    if (!($course = get_record('course', 'id', $courseid))) {
        print_error('invalidcourseid', 'block_email_list');
    }
    // Prepare users to choose us
    if ($courseid) {
        if ($course->id == SITEID) {
            $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
            // SYSTEM context
        } else {
            $context = get_context_instance(CONTEXT_COURSE, $course->id);
            // Course context
        }
        // Security issue
        $sitecontext = get_context_instance(CONTEXT_SYSTEM);
        $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);
        if ($context->id != $frontpagectx->id) {
            require_capability('moodle/course:viewparticipants', $context);
        } else {
            require_capability('moodle/site:viewparticipants', $sitecontext);
        }
        $rolesnames = array();
        $avoidroles = array();
        if ($roles = get_roles_used_in_context($context, true)) {
            $canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
            $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);
            if (!$CFG->email_add_admins) {
                $adminsroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW, $sitecontext);
            }
            foreach ($roles as $role) {
                if (!isset($canviewroles[$role->id])) {
                    // Avoid this role (eg course creator)
                    $avoidroles[] = $role->id;
                    unset($roles[$role->id]);
                    continue;
                }
                if (isset($doanythingroles[$role->id])) {
                    // Avoid this role (ie admin)
                    $avoidroles[] = $role->id;
                    unset($roles[$role->id]);
                    continue;
                }
                if (!$CFG->email_add_admins) {
                    if (isset($adminsroles[$role->id])) {
                        // Avoid this role (ie admin)
                        $avoidroles[] = $role->id;
                        unset($roles[$role->id]);
                        continue;
                    }
                }
                // Prevent - CONTRIB-609
                if (function_exists('role_get_name')) {
                    $rolenames[$role->id] = strip_tags(role_get_name($role, $context));
                    // Used in menus etc later on
                } else {
                    $rolenames[$role->id] = strip_tags(format_string($role->name));
                    // Used in menus etc later on
                }
            }
        }
        // we are looking for all users with this role assigned in this context or higher
        if ($usercontexts = get_parent_contexts($context)) {
            $listofcontexts = '(' . implode(',', $usercontexts) . ')';
        } else {
            $listofcontexts = '(' . $sitecontext->id . ')';
            // must be site
        }
        if ($roleid) {
            $selectrole = " AND r.roleid = {$roleid} ";
        } else {
            $selectrole = " ";
        }
        if ($context->id != $frontpagectx->id) {
            $select = 'SELECT DISTINCT u.id, u.username, u.firstname, u.lastname ';
        } else {
            $select = 'SELECT u.id, u.username, u.firstname, u.lastname ';
        }
        if ($context->id != $frontpagectx->id) {
            $from = "FROM {$CFG->prefix}user u\n\t                LEFT OUTER JOIN {$CFG->prefix}context ctx\n\t                    ON (u.id=ctx.instanceid AND ctx.contextlevel = " . CONTEXT_USER . ")\n\t                JOIN {$CFG->prefix}role_assignments r\n\t                    ON u.id=r.userid\n\t                LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul\n\t                    ON (r.userid=ul.userid and ul.courseid = {$course->id}) ";
        } else {
            $from = "FROM {$CFG->prefix}user u\n\t                LEFT OUTER JOIN {$CFG->prefix}context ctx\n\t                    ON (u.id=ctx.instanceid AND ctx.contextlevel = " . CONTEXT_USER . ") ";
        }
        $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context) ? '' : ' AND r.hidden = 0 ';
        // exclude users with roles we are avoiding
        if ($avoidroles) {
            $adminroles = 'AND r.roleid NOT IN (';
            $adminroles .= implode(',', $avoidroles);
            $adminroles .= ')';
        } else {
            $adminroles = '';
        }
        // join on 2 conditions
        // otherwise we run into the problem of having records in ul table, but not relevant course
        // and user record is not pulled out
        if ($context->id != $frontpagectx->id) {
            $where = "WHERE (r.contextid = {$context->id} OR r.contextid in {$listofcontexts})\n\t            AND u.deleted = 0 {$selectrole}\n\t            AND (ul.courseid = {$course->id} OR ul.courseid IS NULL)\n\t            AND u.username != 'guest'\n\t            {$adminroles}\n\t            {$hiddensql} ";
        } else {
            $where = "WHERE u.deleted = 0\n\t            AND u.username != 'guest'";
        }
        if ($currentgroup and $course->groupmode != 0) {
            // Displaying a group by choice
            $from .= 'LEFT JOIN ' . $CFG->prefix . 'groups_members gm ON u.id = gm.userid ';
            // $currentgroup can be an array of groups id
            if (is_array($currentgroup)) {
                $where .= ' AND gm.groupid IN (' . implode(',', $currentgroup) . ') ';
            } else {
                if ($currentgroup == 0) {
                    if (!has_capability('block/email_list:viewallgroups', $context) && $COURSE->groupmode == 1) {
                        $groupids = groups_get_groups_for_user($USER->id, $COURSE->id);
                        $where .= 'AND gm.groupid IN (' . implode(',', $groupids) . ')';
                    }
                } else {
                    $where .= 'AND gm.groupid = ' . $currentgroup;
                }
            }
            $where .= ' AND gm.groupid = ' . $currentgroup;
        }
        $sort = ' ORDER BY u.firstname, u.lastname';
        $userlist = get_records_sql($select . $from . $where . $sort);
        if ($userlist) {
            foreach ($userlist as $user) {
                $unselectedusers[$user->id] = addslashes(fullname($user, has_capability('moodle/site:viewfullnames', $context)));
            }
        }
        /// If there are multiple Roles in the course, then show a drop down menu for switching
        if (count($rolenames) > 1) {
            echo '<div class="rolesform">';
            echo get_string('currentrole', 'role') . ': ';
            $rolenames = array(0 => get_string('all')) + $rolenames;
            popup_form("{$CFG->wwwroot}/blocks/email_list/email/participants.php?id={$courseid}&amp;group={$currentgroup}&amp;contextid={$context->id}&amp;roleid=", $rolenames, 'rolesform', $roleid, '');
            echo '</div>';
        }
        // Prints group selector for users with a viewallgroups capability if course groupmode is separate
        echo '<br />';
        groups_print_course_menu($course, $CFG->wwwroot . '/blocks/email_list/email/participants.php?id=' . $course->id);
        echo '<br /><br />';
    }
    // Prepare tags
    $straddusersto = get_string('addusersto', 'block_email_list');
    $stradduserscc = get_string('cc', 'block_email_list');
    $straddusersbcc = get_string('bcc', 'block_email_list');
    $stradd = get_string('ok');
    $strto = get_string('to', 'block_email_list');
    $strcc = get_string('cc', 'block_email_list');
    $strbcc = get_string('bcc', 'block_email_list');
    $strselectedusersremove = get_string('selectedusersremove', 'block_email_list');
    $straction = get_string('selectaction', 'block_email_list');
    $strcancel = get_string('cancel');
    // Create an object for define parametrer
    $options = new stdClass();
    $options->id = $courseid;
    // Prepare url
    $toform = email_build_url($options, true);
    -($url = $CFG->wwwroot . '/blocks/email_list/email/sendmail.php');
    if ($options) {
        $urlhtml = email_build_url($options);
    }
    include_once 'participants.html';
}
 function get_roster($onlyrole = null)
 {
     //edited below, replaced old method
     $coursecontext = context_course::instance($this->courseid);
     $allroles = get_roles_used_in_context($coursecontext);
     arsort($allroles);
     if (!$this->visible) {
         foreach ($allroles as $key => $role) {
             if ($role->shortname != 'editingteacher') {
                 unset($allroles[$key]);
             }
         }
     }
     $roles = array_keys($allroles);
     // can't used canned function as its likely to return a student role
     // when the user has both a student and a teacher role
     // so this bit will allow the lower roleid (higher value role) to overwrite the lower one
     foreach ($roles as $role) {
         $temp = get_role_users($role, $coursecontext, false, '', null, false);
         if ($temp !== false && sizeof($temp) !== 0) {
             if (isset($course->users)) {
                 $course->users = array_merge($course->users, $temp);
             } else {
                 $course = new stdclass();
                 $course->users = $temp;
             }
         }
     }
     $members = array();
     $suspended = get_suspended_userids($coursecontext);
     foreach ($course->users as $cuser) {
         if (array_key_exists($cuser->id, $suspended)) {
             /* Explanation of changes made: */
             //edited use of unset below: previous implementation wasn't working
             //because $cuser->id was a number larger than the size of
             //$course->users.
             //$course->users is an array of stdClass objects, which have their own IDs,
             //but those IDs could not be directly accessed in $course->users without callling on the $cuser object.
             //So the compiler was seeing $cuser->id as an index into the array $course->users
             //$cuser->id is normally too large to be used to index into $course->users
             //unset was not working because the index $cuser->id was out of range (larger than the size of $course->users)
             //
             ///*unset($course->users[$cuser->id]);*/
             //solution has been reimplemented below, and it should now work (hopefully)
             $deleteUser = array_search($cuser, $course->users);
             unset($course->users[$deleteUser]);
         } else {
             if ($onlyrole === null || $onlyrole == $allroles[$cuser->roleid]->shortname) {
                 $members[strtolower($cuser->email)] = $allroles[$cuser->roleid]->shortname;
             }
         }
     }
     return $members;
 }
Example #10
0
/**
 * Print filter form.
 *
 * @param stdClass $course course object.
 * @param int $timefrom Time from which records should be fetched.
 * @param int $minlog Time of first record present in log store.
 * @param string $action action to be filtered.
 * @param int $roleid Role to be filtered.
 * @param int $instanceid Instance id of module.
 */
function report_participation_print_filter_form($course, $timefrom, $minlog, $action, $roleid, $instanceid)
{
    global $DB;
    $timeoptions = report_participation_get_time_options($minlog);
    $actionoptions = report_participation_get_action_options();
    // TODO: we need a new list of roles that are visible here.
    $context = context_course::instance($course->id);
    $roles = get_roles_used_in_context($context);
    $guestrole = get_guest_role();
    $roles[$guestrole->id] = $guestrole;
    $roleoptions = role_fix_names($roles, $context, ROLENAME_ALIAS, true);
    $modinfo = get_fast_modinfo($course);
    $modules = $DB->get_records_select('modules', "visible = 1", null, 'name ASC');
    $instanceoptions = array();
    foreach ($modules as $module) {
        if (empty($modinfo->instances[$module->name])) {
            continue;
        }
        $instances = array();
        foreach ($modinfo->instances[$module->name] as $cm) {
            // Skip modules such as label which do not actually have links;
            // this means there's nothing to participate in.
            if (!$cm->has_view()) {
                continue;
            }
            $instances[$cm->id] = format_string($cm->name);
        }
        if (count($instances) == 0) {
            continue;
        }
        $instanceoptions[] = array(get_string('modulenameplural', $module->name) => $instances);
    }
    echo '<form class="participationselectform" action="index.php" method="get"><div>' . "\n" . '<input type="hidden" name="id" value="' . $course->id . '" />' . "\n";
    echo '<label for="menuinstanceid">' . get_string('activitymodule') . '</label>' . "\n";
    echo html_writer::select($instanceoptions, 'instanceid', $instanceid);
    echo '<label for="menutimefrom">' . get_string('lookback') . '</label>' . "\n";
    echo html_writer::select($timeoptions, 'timefrom', $timefrom);
    echo '<label for="menuroleid">' . get_string('showonly') . '</label>' . "\n";
    echo html_writer::select($roleoptions, 'roleid', $roleid, false);
    echo '<label for="menuaction">' . get_string('showactions') . '</label>' . "\n";
    echo html_writer::select($actionoptions, 'action', $action, false);
    echo '<input type="submit" value="' . get_string('go') . '" />' . "\n</div></form>\n";
}
Example #11
0
/**
 * This function returns an object of all users whithin current course who match
 * the search query.
 *  *Modified version of datalib.php's search_user() function
 *
 * @param object $course Current Course object
 * @param string $query Search query
 * @param boolean $dispadmins Flag to return course admins or not
 * @param boolean $displayunconfirmed Flag to specify to return unconfirmed users
 * @return object result set of all matching users
 * @todo Add option to remove active user from results
 */
function email_search_course_users($course, $query = '', $dispadmins = false, $dispunconfirmed = true)
{
    global $CFG, $USER;
    $LIKE = sql_ilike();
    $order = 'ORDER BY firstname, lastname, id';
    $select = 'u.deleted = \'0\'';
    if (!$dispunconfirmed) {
        $select .= ' AND u.confirmed = \'1\'';
    }
    if (!$course or $course->id == SITEID) {
        $results = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email\n                      FROM {$CFG->prefix}user u\n                      WHERE {$select}\n                          AND (u.firstname {$LIKE} '{$query}%' OR u.lastname {$LIKE} '{$query}%')\n                          AND u.username != 'guest'\n                          {$order}");
    } else {
        if ($course->id == SITEID) {
            $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
        } else {
            $context = get_context_instance(CONTEXT_COURSE, $course->id);
        }
        $contextlists = get_related_contexts_string($context);
        // Returns only group(s) members for users without the viewallgroups capability
        $groupmembers = '';
        // Separate groups
        $groupmode = groups_get_course_groupmode($course);
        if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
            // Returns all groups current user is assigned to in course
            if ($groups = groups_get_all_groups($course->id, $USER->id)) {
                $groupmembers = array();
                foreach ($groups as $group) {
                    $groupmembers += groups_get_members($group->id, 'u.id');
                }
                if (!empty($groupmembers)) {
                    $groupmembers = 'AND u.id IN (' . implode(',', array_keys($groupmembers)) . ')';
                } else {
                    // Nobody in their groups :(
                    return false;
                }
            } else {
                // They have no group :(
                return false;
            }
        }
        // Hides course admin roles (eg: admin && course creator) if requested (default)
        if (!$dispadmins) {
            $avoidroles = array();
            if ($roles = get_roles_used_in_context($context, true)) {
                $canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
                $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $context);
                if (!$CFG->email_add_admins) {
                    $adminsroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW, $context);
                }
                foreach ($roles as $role) {
                    if (!isset($canviewroles[$role->id])) {
                        // Avoid this role (eg course creator)
                        $avoidroles[] = $role->id;
                        unset($roles[$role->id]);
                        continue;
                    }
                    if (isset($doanythingroles[$role->id])) {
                        // Avoid this role (ie admin)
                        $avoidroles[] = $role->id;
                        unset($roles[$role->id]);
                        continue;
                    }
                    if (!$CFG->email_add_admins) {
                        if (isset($adminsroles[$role->id])) {
                            // Avoid this role (ie admin)
                            $avoidroles[] = $role->id;
                            unset($roles[$role->id]);
                            continue;
                        }
                    }
                }
            }
            // exclude users with roles we are avoiding
            if ($avoidroles) {
                $adminroles = 'AND ra.roleid NOT IN (';
                $adminroles .= implode(',', $avoidroles);
                $adminroles .= ')';
            } else {
                $adminroles = '';
            }
        } else {
            $adminroles = '';
        }
        $results = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email\n                      FROM {$CFG->prefix}user u,\n                           {$CFG->prefix}role_assignments ra\n                      WHERE {$select} AND ra.contextid {$contextlists} AND ra.userid = u.id\n                          AND (u.firstname {$LIKE} '{$query}%' OR u.lastname {$LIKE} '{$query}%')\n                          AND (u.username != 'guest')\n                          {$adminroles} {$groupmembers} {$order}");
    }
    return $results;
}
Example #12
0
 function get_roster($onlyrole = null)
 {
     //edited below, replaced old method
     $coursecontext = context_course::instance($this->courseid);
     $allroles = get_roles_used_in_context($coursecontext);
     arsort($allroles);
     if (!$this->visible) {
         foreach ($allroles as $key => $role) {
             if ($role->shortname != 'editingteacher') {
                 unset($allroles[$key]);
             }
         }
     }
     $roles = array_keys($allroles);
     // can't used canned function as its likely to return a student role
     // when the user has both a student and a teacher role
     // so this bit will allow the lower roleid (higher value role) to overwrite the lower one
     foreach ($roles as $role) {
         $temp = get_role_users($role, $coursecontext, false, '', null, false);
         if ($temp !== false && sizeof($temp) !== 0) {
             if (isset($course->users)) {
                 $course->users = array_merge($course->users, $temp);
             } else {
                 $course = new stdclass();
                 $course->users = $temp;
             }
         }
     }
     $members = array();
     $suspended = get_suspended_userids($coursecontext);
     foreach ($course->users as $cuser) {
         if (array_key_exists($cuser->id, $suspended)) {
             unset($course->users[$cuser->id]);
         } else {
             if ($onlyrole === null || $onlyrole == $allroles[$cuser->roleid]->shortname) {
                 $members[strtolower($cuser->email)] = $allroles[$cuser->roleid]->shortname;
             }
         }
     }
     return $members;
 }
Example #13
0
/**
 * Gets potential group members for grouping
 * @param int $courseid The id of the course
 * @param int $roleid The role to select users from
 * @param string $orderby The colum to sort users by
 * @return array An array of the users
 */
function groups_get_potential_members($courseid, $roleid = null, $orderby = 'lastname,firstname')
{
    global $DB;
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    $rolenames = array();
    $avoidroles = array();
    if ($roles = get_roles_used_in_context($context, true)) {
        $canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
        $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);
        foreach ($roles as $role) {
            if (!isset($canviewroles[$role->id])) {
                // Avoid this role (eg course creator)
                $avoidroles[] = $role->id;
                unset($roles[$role->id]);
                continue;
            }
            if (isset($doanythingroles[$role->id])) {
                // Avoid this role (ie admin)
                $avoidroles[] = $role->id;
                unset($roles[$role->id]);
                continue;
            }
            $rolenames[$role->id] = strip_tags(role_get_name($role, $context));
            // Used in menus etc later on
        }
    }
    if ($avoidroles) {
        list($adminroles, $params) = $DB->get_in_or_equal($avoidroles, SQL_PARAMS_NAMED, 'ar0', false);
        $adminroles = "AND r.roleid {$adminroles}";
    } else {
        $adminroles = "";
        $params = array();
    }
    // we are looking for all users with this role assigned in this context or higher
    if ($usercontexts = get_parent_contexts($context)) {
        $listofcontexts = 'IN (' . implode(',', $usercontexts) . ')';
    } else {
        $listofcontexts = '=' . $sitecontext->id . ')';
        // must be site
    }
    if ($roleid) {
        $selectrole = "AND r.roleid = :roleid";
        $params['roleid'] = $roleid;
    } else {
        $selectrole = "";
    }
    $sql = "SELECT u.id, u.username, u.firstname, u.lastname, u.idnumber\n              FROM {user} u\n              JOIN {role_assignments} r on u.id=r.userid\n             WHERE (r.contextid = :contextid OR r.contextid {$listofcontexts})\n                   AND u.deleted = 0 AND u.username != 'guest'\n                   {$selectrole} {$adminroles}\n          ORDER BY {$orderby}";
    $params['contextid'] = $context->id;
    return $DB->get_records_sql($sql, $params);
}
 /**
  *this function determins the desktops started and available in this course
  *TODO: this function needs performance improvements
  * @return array of moodle_urls or empty array
  */
 private function available_desktops()
 {
     global $CFG, $PAGE, $USER, $DB;
     $url = array();
     if (has_capability('mod/opendesktop:joinactive', $this->context) or has_capability('mod/opendesktop:joinpassive', $this->context)) {
         if ($roles = get_roles_used_in_context($this->context, true)) {
             $canstartusers = get_users_by_capability($this->context, 'mod/opendesktop:start', 'u.id,username,firstname,lastname');
         }
         foreach ($canstartusers as $canstartuser) {
             $sql = 'SELECT MAX(starttime) AS starttime FROM {opendesktop_sessions} WHERE userid=' . $canstartuser->id;
             $maxstarttime = $DB->get_field_sql($sql);
             $sessionmode = $DB->get_field('opendesktop_sessions', 'sessionmode', array('userid' => $canstartuser->id, 'starttime' => $maxstarttime));
             if ($USER->username != $canstartuser->username && $this->opendesktop->id == $DB->get_field('opendesktop_sessions', 'opendesktop', array('userid' => $canstartuser->id, 'starttime' => $maxstarttime))) {
                 // check if any user with the capability to start a desktop in this course has started OVD
                 $sessvaldetect = $this->session->sessionstatus($CFG->opendesktop_useprefix . $canstartuser->username);
                 // check if the opendesktop was started in the same course, if not do not display the possibility to join
                 if ($sessvaldetect['status'] == 'active' && $sessvaldetect['isregistered']) {
                     if (has_capability('mod/opendesktop:joinactive', $this->context)) {
                         $url[$canstartuser->username]['active'] = new moodle_url($PAGE->url, array('id' => $this->cm->id, 'task' => 'join', 'join' => 'active', 'sesskey' => sesskey(), 'sessionmode' => $sessionmode, 'ovduser' => $canstartuser->id));
                     }
                     if (has_capability('mod/opendesktop:joinpassive', $this->context)) {
                         $url[$canstartuser->username]['passive'] = new moodle_url($PAGE->url, array('id' => $this->cm->id, 'task' => 'join', 'join' => 'passive', 'sesskey' => sesskey(), 'sessionmode' => $sessionmode, 'ovduser' => $canstartuser->id));
                     }
                     $url[$canstartuser->username]['fullname'] = $canstartuser->firstname . ' ' . $canstartuser->lastname;
                 }
             }
         }
     }
     return $url;
 }
        $timeoptions[strtotime('-' . $i . ' weeks', $now)] = get_string('numweeks', 'moodle', $i);
    }
}
// months
for ($i = 2; $i < 12; $i++) {
    if (strtotime('-' . $i . ' months', $now) >= $minlog) {
        $timeoptions[strtotime('-' . $i . ' months', $now)] = get_string('nummonths', 'moodle', $i);
    }
}
// try a year
if (strtotime('-1 year', $now) >= $minlog) {
    $timeoptions[strtotime('-1 year', $now)] = get_string('lastyear');
}
$roleoptions = array();
// TODO: we need a new list of roles that are visible here
if ($roles = get_roles_used_in_context($context)) {
    foreach ($roles as $r) {
        $roleoptions[$r->id] = $r->name;
    }
}
$guestrole = get_guest_role();
if (empty($roleoptions[$guestrole->id])) {
    $roleoptions[$guestrole->id] = $guestrole->name;
}
$roleoptions = role_fix_names($roleoptions, $context);
// print first controls.
echo '<form class="participationselectform" action="index.php" method="get"><div>' . "\n" . '<input type="hidden" name="id" value="' . $course->id . '" />' . "\n";
echo '<label for="menuinstanceid">' . get_string('activitymodule') . '</label>' . "\n";
echo html_writer::select($instanceoptions, 'instanceid', $instanceid);
echo '<label for="menutimefrom">' . get_string('lookback') . '</label>' . "\n";
echo html_writer::select($timeoptions, 'timefrom', $timefrom);
$header->group = get_string('report_group', 'ouwiki');
$header->total = get_string('report_total', 'ouwiki');
$header->active = get_string('report_active', 'ouwiki');
$header->inactive = get_string('report_inactive', 'ouwiki');
$header->pages = get_string('report_pages', 'ouwiki');
$header->percentageparticipation = get_string('report_percentageparticipation', 'ouwiki');
$header->totalpages = get_string('report_totalpages', 'ouwiki');
$header->editedpages = get_string('report_editedpages', 'ouwiki');
$header->uneditedpages = get_string('report_uneditedpages', 'ouwiki');
$header->edits = get_string('report_edits', 'ouwiki');
$header->comments = get_string('report_comments', 'ouwiki');
$header->grouptabletitle = get_string('report_grouptabletitle', 'ouwiki');
$pagetexts = ouwiki_get_pages($subwiki->id);
$contexts = get_related_contexts_string($context);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$allroles = get_roles_used_in_context($context, true);
$header->grouptabletitle = get_string('report_grouptabletitle', 'ouwiki');
if (!$csv) {
    print <<<EOF
<div class='ouw_grouplist'>
\t<h3>{$header->grouptabletitle}</h3> 
\t<table>
\t<tr class="ouw_dodgyextrarow">
    \t\t<td>&nbsp;</td>\t
\t\t\t
EOF;
} else {
    print $csv->quote($header->grouptabletitle) . $csv->line() . $csv->sep();
}
$rolenames = array();
$roleids = array();
Example #17
0
unset($contextid);
unset($courseid);
require_login($course);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);
if ($context->id != $frontpagectx->id) {
    require_capability('moodle/course:viewparticipants', $context);
} else {
    require_capability('moodle/site:viewparticipants', $systemcontext);
    // override the default on frontpage
    $roleid = optional_param('roleid', -1, PARAM_INT);
}
/// front page course is different
$rolenames = array();
$avoidroles = array();
if ($roles = get_roles_used_in_context($context, true)) {
    // We should ONLY allow roles with moodle/course:view because otherwise we get little niggly issues
    // like MDL-8093
    // We should further exclude "admin" users (those with "doanything" at site level) because
    // Otherwise they appear in every participant list
    $canviewroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $context);
    $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $systemcontext);
    if ($context->id == $frontpagectx->id) {
        //we want admins listed on frontpage too
        foreach ($doanythingroles as $dar) {
            $canviewroles[$dar->id] = $dar;
        }
        $doanythingroles = array();
    }
    foreach ($roles as $role) {
        if (!isset($canviewroles[$role->id])) {
function exabis_eportfolio_get_shareable_courses_with_users()
{
    global $USER, $COURSE;
    $courses = array();
    // loop through all my courses
    foreach (get_my_courses($USER->id) as $dbCourse) {
        $course = array('id' => $dbCourse->id, 'fullname' => $dbCourse->fullname, 'users' => array());
        $context = get_context_instance(CONTEXT_COURSE, $dbCourse->id);
        $roles = get_roles_used_in_context($context);
        foreach ($roles as $role) {
            $users = get_role_users($role->id, $context, false, 'u.id, u.firstname, u.lastname');
            if (!$users) {
                continue;
            }
            foreach ($users as $user) {
                if ($user->id == $USER->id) {
                    continue;
                }
                $course['users'][$user->id] = array('id' => $user->id, 'name' => $user->firstname . ' ' . $user->lastname, 'rolename' => $role->name);
            }
        }
        $courses[$course['id']] = $course;
    }
    // move active course to first position
    if (isset($courses[$COURSE->id])) {
        $course = $courses[$COURSE->id];
        unset($courses[$COURSE->id]);
        array_unshift($courses, $course);
    }
    return $courses;
}