* @package moodle * @subpackage local * @author Penny Leach <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com * * go find users to assign to yourself. */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once $CFG->libdir . '/formslib.php'; require_once $CFG->dirroot . '/local/forms.php'; require_login(); $strtitle = get_string('finduser', 'local'); $strdesc = get_string('finduserdesc', 'local'); print_header($strtitle, $strtitle, build_navigation($strtitle)); $userroles = tao_get_assignable_userroles(); $sitecontext = get_context_instance(CONTEXT_COURSE, SITEID); $canassign = array(); foreach ($userroles as $key => $roledata) { $roledata = (object) $roledata; if (has_capability('moodle/local:' . $roledata->canassigncap, $sitecontext)) { $canassign[$key] = $roledata; } } if (count($canassign) == 0) { print_error('nopermissions', 'error', null, get_string('finduser', 'local')); } $mform = new tao_finduser_form(); if ($fromform = $mform->get_data()) { if ($user = get_record('user', 'idnumber', $fromform->idnumber, 'email', $fromform->email)) { $count = 0;
/** * prints the assign me this user stuff (18.4/18.5) * * @param object $user user being viewed * @param object $course course being viewed (often SITE) */ function tao_can_assign_user($user, $course) { global $USER, $CFG; if ($USER == $user) { return; } // able to be overridden by valery if necessary $userroles = tao_get_assignable_userroles(); $canassign = array(); $sitecontext = get_context_instance(CONTEXT_COURSE, SITEID); foreach ($userroles as $cappart => $roledata) { if (has_capability('moodle/local:canassign' . $cappart, $sitecontext) && has_capability('moodle/local:isassignable' . $cappart, $sitecontext, $user->id, false)) { $canassign[$cappart] = $roledata; } } if (count($canassign) == 0) { return; } if (count($canassign) != 1) { // something weird has happened debugging('something weird happened in the TAO local_user_view hook - more than one role to assign: ' . implode(',', $canassign)); return; } $cappart = array_shift(array_keys($canassign)); $roledata = (object) array_shift($canassign); if (!($reciprole = get_record('role', 'shortname', $roledata->recipientrole))) { debugging('something weird happened in the TAO local_user_view_hook - found a role to assign by capability, but not in db: ' . $roledata->recipientrole); return; } if (!($assignrole = get_record('role', 'shortname', $roledata->assignerrole))) { debugging('something weird happened in the TAO local_user_view_hook - found a role to assign by capability, but not in db: ' . $roledata->assignerrole); return; } $url = $CFG->wwwroot . '/local/user/assign.php'; $buttonstring = get_string('assignrole', 'local', $reciprole->name); $options = array('sesskey' => sesskey(), 'user' => $user->id, 'cap' => $cappart, 'course' => $course->id, 'assignrole' => $assignrole->id, 'reciprole' => $reciprole->id); $usercontext = get_context_instance(CONTEXT_USER, $user->id); if (user_has_role_assignment($USER->id, $assignrole->id, $usercontext->id)) { $options['unassign'] = 1; $buttonstring = get_string('unassignrole', 'local', $reciprole->name); } echo '<div class="buttons">'; print_single_button($url, $options, $buttonstring); echo '</div>'; }