|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // Lists all the users within a given course 00004 00005 require_once('../config.php'); 00006 require_once($CFG->libdir.'/tablelib.php'); 00007 require_once($CFG->libdir.'/filelib.php'); 00008 00009 define('USER_SMALL_CLASS', 20); // Below this is considered small 00010 define('USER_LARGE_CLASS', 200); // Above this is considered large 00011 define('DEFAULT_PAGE_SIZE', 20); 00012 define('SHOW_ALL_PAGE_SIZE', 5000); 00013 define('MODE_BRIEF', 0); 00014 define('MODE_USERDETAILS', 1); 00015 00016 $page = optional_param('page', 0, PARAM_INT); // which page to show 00017 $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // how many per page 00018 $mode = optional_param('mode', NULL, PARAM_INT); // use the MODE_ constants 00019 $accesssince = optional_param('accesssince',0,PARAM_INT); // filter by last access. -1 = never 00020 $search = optional_param('search','',PARAM_RAW); // make sure it is processed with p() or s() when sending to output! 00021 $roleid = optional_param('roleid', 0, PARAM_INT); // optional roleid, 0 means all enrolled users (or all on the frontpage) 00022 00023 $contextid = optional_param('contextid', 0, PARAM_INT); // one of this or 00024 $courseid = optional_param('id', 0, PARAM_INT); // this are required 00025 00026 $PAGE->set_url('/user/index.php', array( 00027 'page' => $page, 00028 'perpage' => $perpage, 00029 'mode' => $mode, 00030 'accesssince' => $accesssince, 00031 'search' => $search, 00032 'roleid' => $roleid, 00033 'contextid' => $contextid, 00034 'id' => $courseid)); 00035 00036 if ($contextid) { 00037 $context = get_context_instance_by_id($contextid, MUST_EXIST); 00038 if ($context->contextlevel != CONTEXT_COURSE) { 00039 print_error('invalidcontext'); 00040 } 00041 $course = $DB->get_record('course', array('id'=>$context->instanceid), '*', MUST_EXIST); 00042 } else { 00043 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); 00044 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST); 00045 } 00046 // not needed anymore 00047 unset($contextid); 00048 unset($courseid); 00049 00050 require_login($course); 00051 00052 $systemcontext = get_context_instance(CONTEXT_SYSTEM); 00053 $isfrontpage = ($course->id == SITEID); 00054 00055 $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID); 00056 00057 if ($isfrontpage) { 00058 $PAGE->set_pagelayout('admin'); 00059 require_capability('moodle/site:viewparticipants', $systemcontext); 00060 } else { 00061 $PAGE->set_pagelayout('incourse'); 00062 require_capability('moodle/course:viewparticipants', $context); 00063 } 00064 00065 $rolenamesurl = new moodle_url("$CFG->wwwroot/user/index.php?contextid=$context->id&sifirst=&silast="); 00066 00067 $allroles = get_all_roles(); 00068 $roles = get_profile_roles($context); 00069 $allrolenames = array(); 00070 if ($isfrontpage) { 00071 $rolenames = array(0=>get_string('allsiteusers', 'role')); 00072 } else { 00073 $rolenames = array(0=>get_string('allparticipants')); 00074 } 00075 00076 foreach ($allroles as $role) { 00077 $allrolenames[$role->id] = strip_tags(role_get_name($role, $context)); // Used in menus etc later on 00078 if (isset($roles[$role->id])) { 00079 $rolenames[$role->id] = $allrolenames[$role->id]; 00080 } 00081 } 00082 00083 // make sure other roles may not be selected by any means 00084 if (empty($rolenames[$roleid])) { 00085 print_error('noparticipants'); 00086 } 00087 00088 // no roles to display yet? 00089 // frontpage course is an exception, on the front page course we should display all users 00090 if (empty($rolenames) && !$isfrontpage) { 00091 if (has_capability('moodle/role:assign', $context)) { 00092 redirect($CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id); 00093 } else { 00094 print_error('noparticipants'); 00095 } 00096 } 00097 00098 add_to_log($course->id, 'user', 'view all', 'index.php?id='.$course->id, ''); 00099 00100 $bulkoperations = has_capability('moodle/course:bulkmessaging', $context); 00101 00102 $countries = get_string_manager()->get_list_of_countries(); 00103 00104 $strnever = get_string('never'); 00105 00106 $datestring = new stdClass(); 00107 $datestring->year = get_string('year'); 00108 $datestring->years = get_string('years'); 00109 $datestring->day = get_string('day'); 00110 $datestring->days = get_string('days'); 00111 $datestring->hour = get_string('hour'); 00112 $datestring->hours = get_string('hours'); 00113 $datestring->min = get_string('min'); 00114 $datestring->mins = get_string('mins'); 00115 $datestring->sec = get_string('sec'); 00116 $datestring->secs = get_string('secs'); 00117 00118 if ($mode !== NULL) { 00119 $mode = (int)$mode; 00120 $SESSION->userindexmode = $mode; 00121 } else if (isset($SESSION->userindexmode)) { 00122 $mode = (int)$SESSION->userindexmode; 00123 } else { 00124 $mode = MODE_BRIEF; 00125 } 00126 00129 00130 $groupmode = groups_get_course_groupmode($course); // Groups are being used 00131 $currentgroup = groups_get_course_group($course, true); 00132 00133 if (!$currentgroup) { // To make some other functions work better later 00134 $currentgroup = NULL; 00135 } 00136 00137 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)); 00138 00139 $PAGE->set_title("$course->shortname: ".get_string('participants')); 00140 $PAGE->set_heading($course->fullname); 00141 $PAGE->set_pagetype('course-view-' . $course->format); 00142 $PAGE->add_body_class('path-user'); // So we can style it independently 00143 $PAGE->set_other_editing_capability('moodle/course:manageactivities'); 00144 00145 echo $OUTPUT->header(); 00146 00147 echo '<div class="userlist">'; 00148 00149 if ($isseparategroups and (!$currentgroup) ) { 00150 // The user is not in the group so show message and exit 00151 echo $OUTPUT->heading(get_string("notingroup")); 00152 echo $OUTPUT->footer(); 00153 exit; 00154 } 00155 00156 00157 // Should use this variable so that we don't break stuff every time a variable is added or changed. 00158 $baseurl = new moodle_url('/user/index.php', array( 00159 'contextid' => $context->id, 00160 'roleid' => $roleid, 00161 'id' => $course->id, 00162 'perpage' => $perpage, 00163 'accesssince' => $accesssince, 00164 'search' => s($search))); 00165 00167 if ($course->id == SITEID) { 00168 $filtertype = 'site'; 00169 } else if ($course->id && !$currentgroup) { 00170 $filtertype = 'course'; 00171 $filterselect = $course->id; 00172 } else { 00173 $filtertype = 'group'; 00174 $filterselect = $currentgroup; 00175 } 00176 00177 00178 00180 if (has_capability('moodle/course:viewhiddenuserfields', $context)) { 00181 $hiddenfields = array(); // teachers and admins are allowed to see everything 00182 } else { 00183 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); 00184 } 00185 00186 if (isset($hiddenfields['lastaccess'])) { 00187 // do not allow access since filtering 00188 $accesssince = 0; 00189 } 00190 00192 $controlstable = new html_table(); 00193 $controlstable->attributes['class'] = 'controls'; 00194 $controlstable->cellspacing = 0; 00195 $controlstable->data[] = new html_table_row(); 00196 00198 if ($mycourses = enrol_get_my_courses()) { 00199 $courselist = array(); 00200 $popupurl = new moodle_url('/user/index.php?roleid='.$roleid.'&sifirst=&silast='); 00201 foreach ($mycourses as $mycourse) { 00202 $coursecontext = get_context_instance(CONTEXT_COURSE, $mycourse->id); 00203 $courselist[$mycourse->id] = format_string($mycourse->shortname, true, array('context' => $coursecontext)); 00204 } 00205 if (has_capability('moodle/site:viewparticipants', $systemcontext)) { 00206 unset($courselist[SITEID]); 00207 $courselist = array(SITEID => format_string($SITE->shortname, true, array('context' => $systemcontext))) + $courselist; 00208 } 00209 $select = new single_select($popupurl, 'id', $courselist, $course->id, array(''=>'choosedots'), 'courseform'); 00210 $select->set_label(get_string('mycourses')); 00211 $controlstable->data[0]->cells[] = $OUTPUT->render($select); 00212 } 00213 00214 $controlstable->data[0]->cells[] = groups_print_course_menu($course, $baseurl->out(), true); 00215 00216 if (!isset($hiddenfields['lastaccess'])) { 00217 // get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far. 00218 // we need to make it diferently for normal courses and site course 00219 if (!$isfrontpage) { 00220 $minlastaccess = $DB->get_field_sql('SELECT min(timeaccess) 00221 FROM {user_lastaccess} 00222 WHERE courseid = ? 00223 AND timeaccess != 0', array($course->id)); 00224 $lastaccess0exists = $DB->record_exists('user_lastaccess', array('courseid'=>$course->id, 'timeaccess'=>0)); 00225 } else { 00226 $minlastaccess = $DB->get_field_sql('SELECT min(lastaccess) 00227 FROM {user} 00228 WHERE lastaccess != 0'); 00229 $lastaccess0exists = $DB->record_exists('user', array('lastaccess'=>0)); 00230 } 00231 00232 $now = usergetmidnight(time()); 00233 $timeaccess = array(); 00234 $baseurl->remove_params('accesssince'); 00235 00236 // makes sense for this to go first. 00237 $timeoptions[0] = get_string('selectperiod'); 00238 00239 // days 00240 for ($i = 1; $i < 7; $i++) { 00241 if (strtotime('-'.$i.' days',$now) >= $minlastaccess) { 00242 $timeoptions[strtotime('-'.$i.' days',$now)] = get_string('numdays','moodle',$i); 00243 } 00244 } 00245 // weeks 00246 for ($i = 1; $i < 10; $i++) { 00247 if (strtotime('-'.$i.' weeks',$now) >= $minlastaccess) { 00248 $timeoptions[strtotime('-'.$i.' weeks',$now)] = get_string('numweeks','moodle',$i); 00249 } 00250 } 00251 // months 00252 for ($i = 2; $i < 12; $i++) { 00253 if (strtotime('-'.$i.' months',$now) >= $minlastaccess) { 00254 $timeoptions[strtotime('-'.$i.' months',$now)] = get_string('nummonths','moodle',$i); 00255 } 00256 } 00257 // try a year 00258 if (strtotime('-1 year',$now) >= $minlastaccess) { 00259 $timeoptions[strtotime('-1 year',$now)] = get_string('lastyear'); 00260 } 00261 00262 if (!empty($lastaccess0exists)) { 00263 $timeoptions[-1] = get_string('never'); 00264 } 00265 00266 if (count($timeoptions) > 1) { 00267 $select = new single_select($baseurl, 'accesssince', $timeoptions, $accesssince, null, 'timeoptions'); 00268 $select->set_label(get_string('usersnoaccesssince')); 00269 $controlstable->data[0]->cells[] = $OUTPUT->render($select); 00270 } 00271 } 00272 00273 $formatmenu = array( '0' => get_string('brief'), 00274 '1' => get_string('userdetails')); 00275 $select = new single_select($baseurl, 'mode', $formatmenu, $mode, null, 'formatmenu'); 00276 $select->set_label(get_string('userlist')); 00277 $userlistcell = new html_table_cell(); 00278 $userlistcell->attributes['class'] = 'right'; 00279 $userlistcell->text = $OUTPUT->render($select); 00280 $controlstable->data[0]->cells[] = $userlistcell; 00281 00282 echo html_writer::table($controlstable); 00283 00284 if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', $context))) { 00285 if ($group = groups_get_group($currentgroup)) { 00286 if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) { 00287 $groupinfotable = new html_table(); 00288 $groupinfotable->attributes['class'] = 'groupinfobox'; 00289 $picturecell = new html_table_cell(); 00290 $picturecell->attributes['class'] = 'left side picture'; 00291 $picturecell->text = print_group_picture($group, $course->id, true, true, false); 00292 00293 $contentcell = new html_table_cell(); 00294 $contentcell->attributes['class'] = 'content'; 00295 00296 $contentheading = $group->name; 00297 if (has_capability('moodle/course:managegroups', $context)) { 00298 $aurl = new moodle_url('/group/group.php', array('id' => $group->id, 'courseid' => $group->courseid)); 00299 $contentheading .= ' ' . $OUTPUT->action_icon($aurl, new pix_icon('t/edit', get_string('editgroupprofile'))); 00300 } 00301 00302 $group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'group', 'description', $group->id); 00303 if (!isset($group->descriptionformat)) { 00304 $group->descriptionformat = FORMAT_MOODLE; 00305 } 00306 $options = array('overflowdiv'=>true); 00307 $contentcell->text = $OUTPUT->heading($contentheading, 3) . format_text($group->description, $group->descriptionformat, $options); 00308 $groupinfotable->data[] = new html_table_row(array($picturecell, $contentcell)); 00309 echo html_writer::table($groupinfotable); 00310 } 00311 } 00312 } 00313 00315 00316 $tablecolumns = array('userpic', 'fullname'); 00317 $extrafields = get_extra_user_fields($context); 00318 $tableheaders = array(get_string('userpic'), get_string('fullnameuser')); 00319 if ($mode === MODE_BRIEF) { 00320 foreach ($extrafields as $field) { 00321 $tablecolumns[] = $field; 00322 $tableheaders[] = get_user_field_name($field); 00323 } 00324 } 00325 if ($mode === MODE_BRIEF && !isset($hiddenfields['city'])) { 00326 $tablecolumns[] = 'city'; 00327 $tableheaders[] = get_string('city'); 00328 } 00329 if ($mode === MODE_BRIEF && !isset($hiddenfields['country'])) { 00330 $tablecolumns[] = 'country'; 00331 $tableheaders[] = get_string('country'); 00332 } 00333 if (!isset($hiddenfields['lastaccess'])) { 00334 $tablecolumns[] = 'lastaccess'; 00335 $tableheaders[] = get_string('lastaccess'); 00336 } 00337 00338 if ($bulkoperations) { 00339 $tablecolumns[] = 'select'; 00340 $tableheaders[] = get_string('select'); 00341 } 00342 00343 $table = new flexible_table('user-index-participants-'.$course->id); 00344 $table->define_columns($tablecolumns); 00345 $table->define_headers($tableheaders); 00346 $table->define_baseurl($baseurl->out()); 00347 00348 if (!isset($hiddenfields['lastaccess'])) { 00349 $table->sortable(true, 'lastaccess', SORT_DESC); 00350 } else { 00351 $table->sortable(true, 'firstname', SORT_ASC); 00352 } 00353 00354 $table->no_sorting('roles'); 00355 $table->no_sorting('groups'); 00356 $table->no_sorting('groupings'); 00357 $table->no_sorting('select'); 00358 00359 $table->set_attribute('cellspacing', '0'); 00360 $table->set_attribute('id', 'participants'); 00361 $table->set_attribute('class', 'generaltable generalbox'); 00362 00363 $table->set_control_variables(array( 00364 TABLE_VAR_SORT => 'ssort', 00365 TABLE_VAR_HIDE => 'shide', 00366 TABLE_VAR_SHOW => 'sshow', 00367 TABLE_VAR_IFIRST => 'sifirst', 00368 TABLE_VAR_ILAST => 'silast', 00369 TABLE_VAR_PAGE => 'spage' 00370 )); 00371 $table->setup(); 00372 00373 // we are looking for all users with this role assigned in this context or higher 00374 $contextlist = get_related_contexts_string($context); 00375 00376 list($esql, $params) = get_enrolled_sql($context, NULL, $currentgroup, true); 00377 $joins = array("FROM {user} u"); 00378 $wheres = array(); 00379 00380 $extrasql = get_extra_user_fields_sql($context, 'u', '', array( 00381 'id', 'username', 'firstname', 'lastname', 'email', 'city', 'country', 00382 'picture', 'lang', 'timezone', 'maildisplay', 'imagealt', 'lastaccess')); 00383 00384 if ($isfrontpage) { 00385 $select = "SELECT u.id, u.username, u.firstname, u.lastname, 00386 u.email, u.city, u.country, u.picture, 00387 u.lang, u.timezone, u.maildisplay, u.imagealt, 00388 u.lastaccess$extrasql"; 00389 $joins[] = "JOIN ($esql) e ON e.id = u.id"; // everybody on the frontpage usually 00390 if ($accesssince) { 00391 $wheres[] = get_user_lastaccess_sql($accesssince); 00392 } 00393 00394 } else { 00395 $select = "SELECT u.id, u.username, u.firstname, u.lastname, 00396 u.email, u.city, u.country, u.picture, 00397 u.lang, u.timezone, u.maildisplay, u.imagealt, 00398 COALESCE(ul.timeaccess, 0) AS lastaccess$extrasql"; 00399 $joins[] = "JOIN ($esql) e ON e.id = u.id"; // course enrolled users only 00400 $joins[] = "LEFT JOIN {user_lastaccess} ul ON (ul.userid = u.id AND ul.courseid = :courseid)"; // not everybody accessed course yet 00401 $params['courseid'] = $course->id; 00402 if ($accesssince) { 00403 $wheres[] = get_course_lastaccess_sql($accesssince); 00404 } 00405 } 00406 00407 // performance hacks - we preload user contexts together with accounts 00408 list($ccselect, $ccjoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx'); 00409 $select .= $ccselect; 00410 $joins[] = $ccjoin; 00411 00412 00413 // limit list to users with some role only 00414 if ($roleid) { 00415 $wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid $contextlist)"; 00416 $params['roleid'] = $roleid; 00417 } 00418 00419 $from = implode("\n", $joins); 00420 if ($wheres) { 00421 $where = "WHERE " . implode(" AND ", $wheres); 00422 } else { 00423 $where = ""; 00424 } 00425 00426 $totalcount = $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params); 00427 00428 if (!empty($search)) { 00429 $fullname = $DB->sql_fullname('u.firstname','u.lastname'); 00430 $wheres[] = "(". $DB->sql_like($fullname, ':search1', false, false) . 00431 " OR ". $DB->sql_like('email', ':search2', false, false) . 00432 " OR ". $DB->sql_like('idnumber', ':search3', false, false) .") "; 00433 $params['search1'] = "%$search%"; 00434 $params['search2'] = "%$search%"; 00435 $params['search3'] = "%$search%"; 00436 } 00437 00438 list($twhere, $tparams) = $table->get_sql_where(); 00439 if ($twhere) { 00440 $wheres[] = $twhere; 00441 $params = array_merge($params, $tparams); 00442 } 00443 00444 $from = implode("\n", $joins); 00445 if ($wheres) { 00446 $where = "WHERE " . implode(" AND ", $wheres); 00447 } else { 00448 $where = ""; 00449 } 00450 00451 if ($table->get_sql_sort()) { 00452 $sort = ' ORDER BY '.$table->get_sql_sort(); 00453 } else { 00454 $sort = ''; 00455 } 00456 00457 $matchcount = $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params); 00458 00459 $table->initialbars(true); 00460 $table->pagesize($perpage, $matchcount); 00461 00462 // list of users at the current visible page - paging makes it relatively short 00463 $userlist = $DB->get_recordset_sql("$select $from $where $sort", $params, $table->get_page_start(), $table->get_page_size()); 00464 00466 if (count($rolenames) > 1) { 00467 echo '<div class="rolesform">'; 00468 echo '<label for="rolesform_jump">'.get_string('currentrole', 'role').' </label>'; 00469 echo $OUTPUT->single_select($rolenamesurl, 'roleid', $rolenames, $roleid, null, 'rolesform'); 00470 echo '</div>'; 00471 00472 } else if (count($rolenames) == 1) { 00473 // when all users with the same role - print its name 00474 echo '<div class="rolesform">'; 00475 echo get_string('role').get_string('labelsep', 'langconfig'); 00476 $rolename = reset($rolenames); 00477 echo $rolename; 00478 echo '</div>'; 00479 } 00480 00481 if ($roleid > 0) { 00482 $a = new stdClass(); 00483 $a->number = $totalcount; 00484 $a->role = $rolenames[$roleid]; 00485 $heading = format_string(get_string('xuserswiththerole', 'role', $a)); 00486 00487 if ($currentgroup and $group) { 00488 $a->group = $group->name; 00489 $heading .= ' ' . format_string(get_string('ingroup', 'role', $a)); 00490 } 00491 00492 if ($accesssince) { 00493 $a->timeperiod = $timeoptions[$accesssince]; 00494 $heading .= ' ' . format_string(get_string('inactiveformorethan', 'role', $a)); 00495 } 00496 00497 $heading .= ": $a->number"; 00498 00499 if (user_can_assign($context, $roleid)) { 00500 $heading .= ' <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?roleid='.$roleid.'&contextid='.$context->id.'">'; 00501 $heading .= '<img src="'.$OUTPUT->pix_url('i/edit') . '" class="icon" alt="" /></a>'; 00502 } 00503 echo $OUTPUT->heading($heading, 3); 00504 } else { 00505 if ($course->id != SITEID && has_capability('moodle/course:enrolreview', $context)) { 00506 $editlink = $OUTPUT->action_icon(new moodle_url('/enrol/users.php', array('id' => $course->id)), 00507 new pix_icon('i/edit', get_string('edit'))); 00508 } else { 00509 $editlink = ''; 00510 } 00511 if ($course->id == SITEID and $roleid < 0) { 00512 $strallparticipants = get_string('allsiteusers', 'role'); 00513 } else { 00514 $strallparticipants = get_string('allparticipants'); 00515 } 00516 if ($matchcount < $totalcount) { 00517 echo $OUTPUT->heading($strallparticipants.get_string('labelsep', 'langconfig').$matchcount.'/'.$totalcount . $editlink, 3); 00518 } else { 00519 echo $OUTPUT->heading($strallparticipants.get_string('labelsep', 'langconfig').$matchcount . $editlink, 3); 00520 } 00521 } 00522 00523 00524 if ($bulkoperations) { 00525 echo '<form action="action_redir.php" method="post" id="participantsform">'; 00526 echo '<div>'; 00527 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; 00528 echo '<input type="hidden" name="returnto" value="'.s(me()).'" />'; 00529 } 00530 00531 if ($mode === MODE_USERDETAILS) { // Print simple listing 00532 if ($totalcount < 1) { 00533 echo $OUTPUT->heading(get_string('nothingtodisplay')); 00534 } else { 00535 if ($totalcount > $perpage) { 00536 00537 $firstinitial = $table->get_initial_first(); 00538 $lastinitial = $table->get_initial_last(); 00539 $strall = get_string('all'); 00540 $alpha = explode(',', get_string('alphabet', 'langconfig')); 00541 00542 // Bar of first initials 00543 00544 echo '<div class="initialbar firstinitial">'.get_string('firstname').' : '; 00545 if(!empty($firstinitial)) { 00546 echo '<a href="'.$baseurl->out().'&sifirst=">'.$strall.'</a>'; 00547 } else { 00548 echo '<strong>'.$strall.'</strong>'; 00549 } 00550 foreach ($alpha as $letter) { 00551 if ($letter == $firstinitial) { 00552 echo ' <strong>'.$letter.'</strong>'; 00553 } else { 00554 echo ' <a href="'.$baseurl->out().'&sifirst='.$letter.'">'.$letter.'</a>'; 00555 } 00556 } 00557 echo '</div>'; 00558 00559 // Bar of last initials 00560 00561 echo '<div class="initialbar lastinitial">'.get_string('lastname').' : '; 00562 if(!empty($lastinitial)) { 00563 echo '<a href="'.$baseurl->out().'&silast=">'.$strall.'</a>'; 00564 } else { 00565 echo '<strong>'.$strall.'</strong>'; 00566 } 00567 foreach ($alpha as $letter) { 00568 if ($letter == $lastinitial) { 00569 echo ' <strong>'.$letter.'</strong>'; 00570 } else { 00571 echo ' <a href="'.$baseurl->out().'&silast='.$letter.'">'.$letter.'</a>'; 00572 } 00573 } 00574 echo '</div>'; 00575 00576 $pagingbar = new paging_bar($matchcount, intval($table->get_page_start() / $perpage), $perpage, $baseurl); 00577 $pagingbar->pagevar = 'spage'; 00578 echo $OUTPUT->render($pagingbar); 00579 } 00580 00581 if ($matchcount > 0) { 00582 $usersprinted = array(); 00583 foreach ($userlist as $user) { 00584 if (in_array($user->id, $usersprinted)) { 00585 continue; 00586 } 00587 $usersprinted[] = $user->id; 00588 00589 context_instance_preload($user); 00590 00591 $context = get_context_instance(CONTEXT_COURSE, $course->id); 00592 $usercontext = get_context_instance(CONTEXT_USER, $user->id); 00593 00594 $countries = get_string_manager()->get_list_of_countries(); 00595 00597 if (has_capability('moodle/course:viewhiddenuserfields', $context)) { 00598 $hiddenfields = array(); 00599 } else { 00600 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); 00601 } 00602 $table = new html_table(); 00603 $table->attributes['class'] = 'userinfobox'; 00604 00605 $row = new html_table_row(); 00606 $row->cells[0] = new html_table_cell(); 00607 $row->cells[0]->attributes['class'] = 'left side'; 00608 00609 $row->cells[0]->text = $OUTPUT->user_picture($user, array('size' => 100, 'courseid'=>$course->id)); 00610 $row->cells[1] = new html_table_cell(); 00611 $row->cells[1]->attributes['class'] = 'content'; 00612 00613 $row->cells[1]->text = $OUTPUT->container(fullname($user, has_capability('moodle/site:viewfullnames', $context)), 'username'); 00614 $row->cells[1]->text .= $OUTPUT->container_start('info'); 00615 00616 if (!empty($user->role)) { 00617 $row->cells[1]->text .= get_string('role').get_string('labelsep', 'langconfig').$user->role.'<br />'; 00618 } 00619 if ($user->maildisplay == 1 or ($user->maildisplay == 2 and ($course->id != SITEID) and !isguestuser()) or 00620 has_capability('moodle/course:viewhiddenuserfields', $context) or 00621 in_array('email', $extrafields)) { 00622 $row->cells[1]->text .= get_string('email').get_string('labelsep', 'langconfig').html_writer::link("mailto:$user->email", $user->email) . '<br />'; 00623 } 00624 foreach ($extrafields as $field) { 00625 if ($field === 'email') { 00626 // Skip email because it was displayed with different 00627 // logic above (because this page is intended for 00628 // students too) 00629 continue; 00630 } 00631 $row->cells[1]->text .= get_user_field_name($field) . 00632 get_string('labelsep', 'langconfig') . s($user->{$field}) . '<br />'; 00633 } 00634 if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) { 00635 $row->cells[1]->text .= get_string('city').get_string('labelsep', 'langconfig'); 00636 if ($user->city && !isset($hiddenfields['city'])) { 00637 $row->cells[1]->text .= $user->city; 00638 } 00639 if (!empty($countries[$user->country]) && !isset($hiddenfields['country'])) { 00640 if ($user->city && !isset($hiddenfields['city'])) { 00641 $row->cells[1]->text .= ', '; 00642 } 00643 $row->cells[1]->text .= $countries[$user->country]; 00644 } 00645 $row->cells[1]->text .= '<br />'; 00646 } 00647 00648 if (!isset($hiddenfields['lastaccess'])) { 00649 if ($user->lastaccess) { 00650 $row->cells[1]->text .= get_string('lastaccess').get_string('labelsep', 'langconfig').userdate($user->lastaccess); 00651 $row->cells[1]->text .= ' ('. format_time(time() - $user->lastaccess, $datestring) .')'; 00652 } else { 00653 $row->cells[1]->text .= get_string('lastaccess').get_string('labelsep', 'langconfig').get_string('never'); 00654 } 00655 } 00656 00657 $row->cells[1]->text .= $OUTPUT->container_end(); 00658 00659 $row->cells[2] = new html_table_cell(); 00660 $row->cells[2]->attributes['class'] = 'links'; 00661 $row->cells[2]->text = ''; 00662 00663 $links = array(); 00664 00665 if ($CFG->bloglevel > 0) { 00666 $links[] = html_writer::link(new moodle_url('/blog/index.php?userid='.$user->id), get_string('blogs','blog')); 00667 } 00668 00669 if (!empty($CFG->enablenotes) and (has_capability('moodle/notes:manage', $context) || has_capability('moodle/notes:view', $context))) { 00670 $links[] = html_writer::link(new moodle_url('/notes/index.php?course=' . $course->id. '&user='.$user->id), get_string('notes','notes')); 00671 } 00672 00673 if (has_capability('moodle/site:viewreports', $context) or has_capability('moodle/user:viewuseractivitiesreport', $usercontext)) { 00674 $links[] = html_writer::link(new moodle_url('/course/user.php?id='. $course->id .'&user='. $user->id), get_string('activity')); 00675 } 00676 00677 if ($USER->id != $user->id && !session_is_loggedinas() && has_capability('moodle/user:loginas', $context) && !is_siteadmin($user->id)) { 00678 $links[] = html_writer::link(new moodle_url('/course/loginas.php?id='. $course->id .'&user='. $user->id .'&sesskey='. sesskey()), get_string('loginas')); 00679 } 00680 00681 $links[] = html_writer::link(new moodle_url('/user/view.php?id='. $user->id .'&course='. $course->id), get_string('fullprofile') . '...'); 00682 00683 $row->cells[2]->text .= implode('', $links); 00684 00685 if (!empty($messageselect)) { 00686 $row->cells[2]->text .= '<br /><input type="checkbox" name="user'.$user->id.'" /> '; 00687 } 00688 $table->data = array($row); 00689 echo html_writer::table($table); 00690 } 00691 00692 } else { 00693 echo $OUTPUT->heading(get_string('nothingtodisplay')); 00694 } 00695 } 00696 00697 } else { 00698 $countrysort = (strpos($sort, 'country') !== false); 00699 $timeformat = get_string('strftimedate'); 00700 00701 00702 if ($userlist) { 00703 00704 $usersprinted = array(); 00705 foreach ($userlist as $user) { 00706 if (in_array($user->id, $usersprinted)) { 00707 continue; 00708 } 00709 $usersprinted[] = $user->id; 00710 00711 context_instance_preload($user); 00712 00713 if ($user->lastaccess) { 00714 $lastaccess = format_time(time() - $user->lastaccess, $datestring); 00715 } else { 00716 $lastaccess = $strnever; 00717 } 00718 00719 if (empty($user->country)) { 00720 $country = ''; 00721 00722 } else { 00723 if($countrysort) { 00724 $country = '('.$user->country.') '.$countries[$user->country]; 00725 } 00726 else { 00727 $country = $countries[$user->country]; 00728 } 00729 } 00730 00731 $usercontext = get_context_instance(CONTEXT_USER, $user->id); 00732 00733 if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext))) { 00734 $profilelink = '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user).'</a></strong>'; 00735 } else { 00736 $profilelink = '<strong>'.fullname($user).'</strong>'; 00737 } 00738 00739 $data = array ($OUTPUT->user_picture($user, array('size' => 35, 'courseid'=>$course->id)), $profilelink); 00740 00741 if ($mode === MODE_BRIEF) { 00742 foreach ($extrafields as $field) { 00743 $data[] = $user->{$field}; 00744 } 00745 } 00746 if ($mode === MODE_BRIEF && !isset($hiddenfields['city'])) { 00747 $data[] = $user->city; 00748 } 00749 if ($mode === MODE_BRIEF && !isset($hiddenfields['country'])) { 00750 $data[] = $country; 00751 } 00752 if (!isset($hiddenfields['lastaccess'])) { 00753 $data[] = $lastaccess; 00754 } 00755 00756 if (isset($userlist_extra) && isset($userlist_extra[$user->id])) { 00757 $ras = $userlist_extra[$user->id]['ra']; 00758 $rastring = ''; 00759 foreach ($ras AS $key=>$ra) { 00760 $rolename = $allrolenames[$ra['roleid']] ; 00761 if ($ra['ctxlevel'] == CONTEXT_COURSECAT) { 00762 $rastring .= $rolename. ' @ ' . '<a href="'.$CFG->wwwroot.'/course/category.php?id='.$ra['ctxinstanceid'].'">'.s($ra['ccname']).'</a>'; 00763 } elseif ($ra['ctxlevel'] == CONTEXT_SYSTEM) { 00764 $rastring .= $rolename. ' - ' . get_string('globalrole','role'); 00765 } else { 00766 $rastring .= $rolename; 00767 } 00768 } 00769 $data[] = $rastring; 00770 if ($groupmode != 0) { 00771 // htmlescape with s() and implode the array 00772 $data[] = implode(', ', array_map('s',$userlist_extra[$user->id]['group'])); 00773 $data[] = implode(', ', array_map('s', $userlist_extra[$user->id]['gping'])); 00774 } 00775 } 00776 00777 if ($bulkoperations) { 00778 $data[] = '<input type="checkbox" class="usercheckbox" name="user'.$user->id.'" />'; 00779 } 00780 $table->add_data($data); 00781 } 00782 } 00783 00784 $table->print_html(); 00785 00786 } 00787 00788 if ($bulkoperations) { 00789 echo '<br /><div class="buttons">'; 00790 echo '<input type="button" id="checkall" value="'.get_string('selectall').'" /> '; 00791 echo '<input type="button" id="checknone" value="'.get_string('deselectall').'" /> '; 00792 $displaylist = array(); 00793 $displaylist['messageselect.php'] = get_string('messageselectadd'); 00794 if (!empty($CFG->enablenotes) && has_capability('moodle/notes:manage', $context) && $context->id != $frontpagectx->id) { 00795 $displaylist['addnote.php'] = get_string('addnewnote', 'notes'); 00796 $displaylist['groupaddnote.php'] = get_string('groupaddnewnote', 'notes'); 00797 } 00798 00799 echo $OUTPUT->help_icon('withselectedusers'); 00800 echo html_writer::tag('label', get_string("withselectedusers"), array('for'=>'formactionid')); 00801 echo html_writer::select($displaylist, 'formaction', '', array(''=>'choosedots'), array('id'=>'formactionid')); 00802 00803 echo '<input type="hidden" name="id" value="'.$course->id.'" />'; 00804 echo '<noscript style="display:inline">'; 00805 echo '<div><input type="submit" value="'.get_string('ok').'" /></div>'; 00806 echo '</noscript>'; 00807 echo '</div></div>'; 00808 echo '</form>'; 00809 00810 $module = array('name'=>'core_user', 'fullpath'=>'/user/module.js'); 00811 $PAGE->requires->js_init_call('M.core_user.init_participation', null, false, $module); 00812 } 00813 00814 if (has_capability('moodle/site:viewparticipants', $context) && $totalcount > ($perpage*3)) { 00815 echo '<form action="index.php" class="searchform"><div><input type="hidden" name="id" value="'.$course->id.'" />'.get_string('search').': '."\n"; 00816 echo '<input type="text" name="search" value="'.s($search).'" /> <input type="submit" value="'.get_string('search').'" /></div></form>'."\n"; 00817 } 00818 00819 $perpageurl = clone($baseurl); 00820 $perpageurl->remove_params('perpage'); 00821 if ($perpage == SHOW_ALL_PAGE_SIZE) { 00822 $perpageurl->param('perpage', DEFAULT_PAGE_SIZE); 00823 echo $OUTPUT->container(html_writer::link($perpageurl, get_string('showperpage', '', DEFAULT_PAGE_SIZE)), array(), 'showall'); 00824 00825 } else if ($matchcount > 0 && $perpage < $matchcount) { 00826 $perpageurl->param('perpage', SHOW_ALL_PAGE_SIZE); 00827 echo $OUTPUT->container(html_writer::link($perpageurl, get_string('showall', '', $matchcount)), array(), 'showall'); 00828 } 00829 00830 echo '</div>'; // userlist 00831 00832 echo $OUTPUT->footer(); 00833 00834 if ($userlist) { 00835 $userlist->close(); 00836 } 00837 00838 00839 function get_course_lastaccess_sql($accesssince='') { 00840 if (empty($accesssince)) { 00841 return ''; 00842 } 00843 if ($accesssince == -1) { // never 00844 return 'ul.timeaccess = 0'; 00845 } else { 00846 return 'ul.timeaccess != 0 AND ul.timeaccess < '.$accesssince; 00847 } 00848 } 00849 00850 function get_user_lastaccess_sql($accesssince='') { 00851 if (empty($accesssince)) { 00852 return ''; 00853 } 00854 if ($accesssince == -1) { // never 00855 return 'u.lastaccess = 0'; 00856 } else { 00857 return 'u.lastaccess != 0 AND u.lastaccess < '.$accesssince; 00858 } 00859 }