Started out fixing MDL-6624 and it turned into a fairly major cleanup

of the participant listing.  I think it's a lot better now.

Bulk messaging fixed too, and is controlled by a new capability

      moodle/course:bulkmessaging
This commit is contained in:
moodler 2006-09-28 06:41:07 +00:00
parent 3e21903846
commit 77c645df28
3 changed files with 340 additions and 353 deletions

View File

@ -553,6 +553,22 @@ $moodle_capabilities = array(
)
),
'moodle/course:bulkmessaging' => array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'guest' => CAP_PREVENT,
'student' => CAP_PREVENT,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
'moodle/course:viewhiddenuserfields' => array(
'riskbitmask' => RISK_PERSONAL,

View File

@ -14,7 +14,6 @@
$page = optional_param('page', 0, PARAM_INT); // which page to show
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // how many per page
$mode = optional_param('mode', NULL); // '0' for less details, '1' for more
$showteachers = optional_param('teachers', 1, PARAM_INT); // do we want to see the teacher list?
$accesssince = optional_param('accesssince',0,PARAM_INT); // filter by last access. -1 = never
$search = optional_param('search','',PARAM_CLEAN);
$roleid = optional_param('roleid', 0, PARAM_INT); // optional roleid
@ -22,11 +21,8 @@
$contextid = optional_param('contextid', 0, PARAM_INT); // one of this or
$courseid = optional_param('id', 0, PARAM_INT); // this are required
$showteachers = $showteachers && empty($search); // if we're searching, we just want students.
if ($contextid) {
if (! $context = get_context_instance_by_id($contextid)) {
error("Context ID is incorrect");
}
if (! $course = get_record('course', 'id', $context->instanceid)) {
@ -71,11 +67,7 @@
add_to_log($course->id, 'user', 'view all', 'index.php?id='.$course->id, '');
$isteacher = isteacher($course->id);
if (empty($isteacher)) {
$search = false;
}
$bulkoperations = has_capability('moodle/course:bulkmessaging', $context);
$countries = get_list_of_countries();
@ -118,7 +110,7 @@
}
// Should use this variable so that we don't break stuff every time a variable is added or changed.
$baseurl = $CFG->wwwroot.'/user/index.php?contextid='.$context->id.'&roleid='.$roleid.'&id='.$course->id.'&group='.$currentgroup.'&perpage='.$perpage.'&teachers='.$showteachers.'&accesssince='.$accesssince.'&search='.$search;
$baseurl = $CFG->wwwroot.'/user/index.php?contextid='.$context->id.'&roleid='.$roleid.'&id='.$course->id.'&group='.$currentgroup.'&perpage='.$perpage.'&accesssince='.$accesssince.'&search='.$search;
/// Print headers
@ -170,7 +162,7 @@
foreach ($mycourses as $mycourse) {
$courselist[$mycourse->id] = $mycourse->shortname;
}
popup_form($CFG->wwwroot.'/user/index.php?contextid='.$context->id.'&roleid='.$roleid.'&id=',
popup_form($CFG->wwwroot.'/user/index.php?contextid='.$context->id.'&roleid='.$roleid.'&sifirst=&silast=&id=',
$courselist, 'courseform',$course->id);
echo '</td>';
}
@ -183,7 +175,6 @@
}
}
if (!empty($isteacher)) {
// get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
// this might not work anymore because you always going to get yourself as the most recent entry? added $USER!=$user ch
$minlastaccess = get_field_sql('SELECT min(timeaccess) FROM '.$CFG->prefix.'user_lastaccess WHERE courseid = '.$course->id.' AND timeaccess != 0 AND userid!='.$USER->id);
@ -228,7 +219,7 @@
echo popup_form($baseurl.'&amp;accesssince=',$timeoptions,'timeoptions',$accesssince,'','','',true);
echo '</td>';
}
}
echo '<td class="right">';
echo get_string('userlist').': ';
@ -264,8 +255,8 @@
}
/// Define a table showing a list of users in the current role.
if ($roleid) {
/// Define a table showing a list of users in the current role selection
$tablecolumns = array('picture', 'fullname');
$tableheaders = array('', get_string('fullname'));
if (!isset($hiddenfields['city'])) {
@ -286,7 +277,7 @@
$tableheaders[] = get_string('enrolmentend');
}
if ($isteacher) {
if ($bulkoperations) {
$tablecolumns[] = '';
$tableheaders[] = get_string('select');
}
@ -321,6 +312,11 @@
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
$listofcontexts = '('.$sitecontext->id.')'; // must be site
}
if ($roleid) {
$selectrole = " AND r.roleid = $roleid ";
} else {
$selectrole = " ";
}
$select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country,
u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, ul.timeaccess AS lastaccess '; // s.lastaccess
//$select .= $course->enrolperiod?', s.timeend ':'';
@ -328,8 +324,7 @@
{$CFG->prefix}role_assignments r on u.id=r.userid LEFT OUTER JOIN
{$CFG->prefix}user_lastaccess ul on r.userid=ul.userid ";
$where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
AND u.deleted = 0
AND r.roleid = $roleid
AND u.deleted = 0 $selectrole
AND (ul.courseid = $course->id OR ul.courseid IS NULL)
AND u.username <> 'guest' ";
$where .= get_lastaccess_sql($accesssince);
@ -349,7 +344,7 @@
$where .= ' AND gm.groupid = '.$currentgroup;
}
$totalcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where); // 1 person can have multiple assignments
$totalcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where); // Each user could have > 1 role
if ($table->get_sql_where()) {
$where .= ' AND '.$table->get_sql_where();
@ -375,11 +370,12 @@
echo '<div class="rolesform">';
echo get_string('currentrole', 'role').': ';
$rolenames = array(0 => get_string('all')) + $rolenames;
popup_form('index.php?contextid='.$contextid.'&amp;roleid=', $rolenames, 'rolesform', $roleid, '');
popup_form('index.php?contextid='.$context->id.'&amp;sifirst=&amp;silast=&amp;roleid=', $rolenames,
'rolesform', $roleid, '');
echo '</div>';
}
if ($roleid) {
if (!$currentrole = get_record('role','id',$roleid)) {
error('That role does not exist');
}
@ -391,13 +387,16 @@
$heading .= '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="" /></a>';
}
print_heading($heading, 'center', 3);
} else {
print_heading(get_string('allparticipants'), 'center', 3);
}
if ($isteacher) {
if ($bulkoperations) {
echo '
<script Language="JavaScript">
<!--
function checksubmit(form) {
<script Language="JavaScript">
<!--
function checksubmit(form) {
var destination = form.formaction.options[form.formaction.selectedIndex].value;
if (destination == "" || !checkchecked(form)) {
form.formaction.selectedIndex = 0;
@ -405,22 +404,22 @@ function checksubmit(form) {
} else {
return true;
}
}
}
function checkchecked(form) {
function checkchecked(form) {
var inputs = document.getElementsByTagName(\'INPUT\');
var checked = false;
inputs = filterByParent(inputs, function() {return form;});
for(var i = 0; i < inputs.length; ++i) {
if(inputs[i].type == \'checkbox\' && inputs[i].checked) {
if (inputs[i].type == \'checkbox\' && inputs[i].checked) {
checked = true;
}
}
return checked;
}
//-->
</script>
';
}
//-->
</script>
';
echo '<form action="action_redir.php" method="post" name="studentsform" onSubmit="return checksubmit(this);">';
echo '<input type="hidden" name="returnto" value="'.$_SERVER['REQUEST_URI'].'" />';
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
@ -433,10 +432,9 @@ function checkchecked(form) {
if ($fullmode) { // Print simple listing
if ($totalcount < 1) {
print_heading(get_string("nostudentsfound", "", $course->students));
}
else {
if($totalcount > $perpage) {
} else {
if ($totalcount > $perpage) {
$firstinitial = $table->get_initial_first();
$lastinitial = $table->get_initial_last();
@ -478,20 +476,19 @@ function checkchecked(form) {
echo '</div>';
print_paging_bar($matchcount, intval($table->get_page_start() / $perpage), $perpage, $baseurl.'&amp;', 'spage');
}
if($matchcount > 0) {
if ($matchcount > 0) {
foreach ($students as $student) {
print_user($student, $course, true);
}
}
else {
} else {
print_heading(get_string('nothingtodisplay'));
}
}
}
else {
} else {
$countrysort = (strpos($sort, 'country') !== false);
$timeformat = get_string('strftimedate');
if (!empty($students)) {
@ -504,8 +501,8 @@ function checkchecked(form) {
if (empty($student->country)) {
$country = '';
}
else {
} else {
if($countrysort) {
$country = '('.$student->country.') '.$countries[$student->country];
}
@ -533,7 +530,7 @@ function checkchecked(form) {
$data[] = get_string('unlimited');
}
}
if ($isteacher) {
if ($bulkoperations) {
$data[] = '<input type="checkbox" name="user'.$student->id.'" />';
}
$table->add_data($data);
@ -545,8 +542,8 @@ function checkchecked(form) {
}
if ($isteacher) {
echo '<br /><center>';
if ($bulkoperations) {
echo '<br /><div class="form-buttons" align="center">';
echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> ';
echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> ';
$displaylist['messageselect.php'] = get_string('messageselectadd');
@ -555,54 +552,28 @@ function checkchecked(form) {
}
choose_from_menu ($displaylist, "formaction", "", get_string("withselectedusers"), "if(checksubmit(this.form))this.form.submit();", "");
helpbutton("participantswithselectedusers", get_string("withselectedusers"));
echo '<input type="submit" value="' . get_string('ok') . '"';
echo '</center></form>';
echo '<input type="text" name="id" value="'.$course->id.'" />';
echo '<input type="submit" value="' . get_string('ok') . '" />';
echo '</div></form>';
}
if ($isteacher && $totalcount > ($perpage*3)) {
if ($bulkoperations && $totalcount > ($perpage*3)) {
echo '<form action="index.php"><p align="center"><input type="hidden" name="id" value="'.$course->id.'" />'.get_string('search').':&nbsp;'."\n";
echo '<input type="text" name="search" value="'.$search.'" />&nbsp;<input type="submit" value="'.get_string('search').'" /></p></form>'."\n";
}
if ($perpage == SHOW_ALL_PAGE_SIZE) {
echo '<div id="showall"><a href="'.$baseurl.'&amp;perpage='.DEFAULT_PAGE_SIZE.'">'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'</a></div>';
}
else if ($matchcount > 0 && $perpage < $matchcount) {
} else if ($matchcount > 0 && $perpage < $matchcount) {
echo '<div id="showall"><a href="'.$baseurl.'&amp;perpage='.SHOW_ALL_PAGE_SIZE.'">'.get_string('showall', '', $matchcount).'</a></div>';
}
} else {
/// If no role is selected, then print an overview of the roles in this course
$table->tablealign = 'center';
$table->cellpadding = 5;
$table->cellspacing = 0;
$table->width = '20%';
$table->head = array(get_string('roles', 'role'), get_string('users'));
$table->wrap = array('nowrap', 'nowrap');
$table->align = array('right', 'center');
$baseurl = $CFG->wwwroot.'/user/index.php?contextid='.$context->id;
foreach ($rolenames as $roleid => $rolename) {
$countusers = 0;
if ($contextusers = count_role_users($roleid, $context)) {
$countusers = count($contextusers);
}
if ($countusers) {
$table->data[] = array('<a href="'.$baseurl.'&amp;roleid='.$roleid.'">'.$rolename.'</a>', $countusers);
} else {
$table->data[] = array($rolename, $countusers);
}
}
print_table($table);
}
print_footer($course);
function get_lastaccess_sql($accesssince='') {
if (empty($accesssince)) {
return '';

View File

@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
$version = 2006092601; // YYYYMMDD = date
$version = 2006092800; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.7 dev'; // Human-friendly version name