Skip to content

Commit

Permalink
New feature to extend student enrolment period and improvements to th…
Browse files Browse the repository at this point in the history
…e action list in participants list
  • Loading branch information
patrickslee committed Sep 29, 2005
1 parent d937f3a commit 6746bb8
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 14 deletions.
5 changes: 5 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@
$string['enrollfirst'] = 'You have to enrol in one of the courses before you can use the site activities';
$string['enrolme'] = 'Enrol me in this course';
$string['enrolmentconfirmation'] = 'You are about to enrol yourself as a member of this course.<br />Are you sure you wish to do this?';
$string['enrolmentend'] = 'Enrolment Ends';
$string['enrolmentkey'] = 'Enrolment key';
$string['enrolmentkeyfrom'] = 'This course requires an \'enrolment key\' - a one-time<br />
password that you should have received from $a';
Expand All @@ -442,6 +443,7 @@
$string['enrolmentnointernal'] = 'Manual enrolments are currently not enabled';
$string['enrolmentnotyet'] = 'Sorry, you can not access this course until <br /> $a';
$string['enrolments'] = 'Enrolments';
$string['enrolmentstart'] = 'Enrolment Started';
$string['enrolperiod'] = 'Enrolment duration';
$string['entercourse'] = 'Click to enter this course';
$string['enteremailaddress'] = 'Enter in your email address to reset your
Expand All @@ -461,6 +463,8 @@
$string['existingstudents'] = 'Enrolled students';
$string['existingteachers'] = 'Existing teachers';
$string['explanation'] = 'Explanation';
$string['extendenrol'] = 'Extend enrolment';
$string['extendperiod'] = 'Extended period';
$string['failedloginattempts'] = '$a->attempts failed logins since your last login';
$string['failedloginattemptsall'] = '$a->attempts failed logins for $a->accounts accounts';
$string['feedback'] = 'Feedback';
Expand Down Expand Up @@ -803,6 +807,7 @@
$string['next'] = 'Next';
$string['no'] = 'No';
$string['nobody'] = 'Nobody';
$string['nochange'] = 'No change';
$string['nocoursesfound'] = 'No courses were found with the words \'$a\'';
$string['nocoursesyet'] = 'No courses in this category';
$string['nodstpresets'] = 'The administrator has not enabled Daylight Savings Time support.';
Expand Down
34 changes: 34 additions & 0 deletions user/action_redir.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/*
* Wrapper script redirecting user operations to correct destination
*/
require_once("../config.php");

if (empty($_GET) || empty($_GET['formaction']) || empty($_GET['id'])) {
die();
}

// Add every page will be redirected by this script
$actions = array(
'messageselect.php',
'extendenrol.php'
);

if (array_search($_GET['formaction'], $actions) === false) {
die();
}

if (!confirm_sesskey()) {
die();
}

$pass = false;
foreach ($_GET as $k => $v) {
$pass = $pass || preg_match('/^user(\d+)$/',$k);
}
if (!$pass) {
die();
}

header("Location: $CFG->wwwroot/user/" . $_GET['formaction'] . '?' . $_SERVER['QUERY_STRING']);
?>
73 changes: 73 additions & 0 deletions user/extendenrol.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
require_once("../config.php");

$id = required_param('id', PARAM_INT); // course id
$users = optional_param('userid', PARAM_RAW); // array of user id

if (! $course = get_record('course', 'id', $id)) {
error("Course ID is incorrect");
}

require_login($course->id);

if (!isteacheredit($course->id)) {
error("You must be an editing teacher in this course, or an admin");
}

if ($users && ($form = data_submitted() and confirm_sesskey())) {
if (count($form->userid) != count($form->extendperiod)) {
error('Parameters malformation', $CFG->wwwroot.'/user/index.php?id='.$id);
}

foreach ($form->userid as $k => $v) {
if ($student = get_record('user_students', 'userid', $v, 'course', $id)) {
enrol_student($v, $id, $student->timestart, $student->timeend + $form->extendperiod[$k]);
}
}

redirect("$CFG->wwwroot/user/index.php?id=$id", get_string('changessaved'));
}

/// Print headers

if ($course->category) {
print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname,
"<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> -> ".
get_string('extendenrol'), "", "", true, "&nbsp;", navmenu($course));
} else {
print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname,
get_string('extendenrol'), "", "", true, "&nbsp;", navmenu($course));
}

for ($i=1; $i<=365; $i++) {
$seconds = $i * 86400;
$periodmenu[$seconds] = get_string('numdays', '', $i);
}

print_heading(get_string('extendenrol'));
echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\" name=\"form\">\n";
echo '<input type="hidden" name="id" value="'.$course->id.'" />';
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
$table->head = array (get_string('fullname'), get_string('enrolmentstart'), get_string('enrolmentend'), get_string('extendperiod'));
$table->align = array ('left', 'center', 'center', 'center');
$table->width = "600";
$timeformat = get_string('strftimedate');
$nochange = get_string('nochange');
foreach ($_GET as $k => $v) {
if (preg_match('/^user(\d+)$/',$k,$m)) {
if (!($user = get_record_sql("SELECT * FROM {$CFG->prefix}user u INNER JOIN {$CFG->prefix}user_students s ON u.id=s.userid WHERE u.id={$m[1]}"))) {
continue;
}
$table->data[] = array(
fullname($user, true),
userdate($user->timestart, $timeformat),
userdate($user->timeend, $timeformat),
'<input type="hidden" name="userid['.$m[1].']" value="'.$m[1].'" >'.choose_from_menu($periodmenu, "extendperiod[{$m[1]}]", "0", $nochange, '', '0', true)
);
}
}
print_table($table);
echo "\n<div style=\"width:100%;text-align:center;\"><input type=\"submit\" value=\"".get_string('savechanges')."\" /></div>\n</form>\n";

print_footer($course);
?>
73 changes: 61 additions & 12 deletions user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,18 @@
$guest = get_guest();
$exceptions[] = $guest->id;

$tablecolumns = array('picture', 'fullname', 'city', 'country', 'lastaccess','');
$tableheaders = array('', get_string('fullname'), get_string('city'), get_string('country'), get_string('lastaccess'), ($isteacher) ? get_string('select') : '');
$tablecolumns = array('picture', 'fullname', 'city', 'country', 'lastaccess');
$tableheaders = array('', get_string('fullname'), get_string('city'), get_string('country'), get_string('lastaccess'));

if ($course->enrolperiod) {
$tablecolumns[] = 'timeend';
$tableheaders[] = get_string('enrolmentend');
}

if ($isteacher) {
$tablecolumns[] = '';
$tableheaders[] = get_string('select');
}

$table = new flexible_table('user-index-students');

Expand Down Expand Up @@ -277,6 +287,7 @@
else {
$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, s.timeaccess AS lastaccess ';
$select .= $course->enrolperiod?', s.timeend ':'';
$from = 'FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'user_students s ON s.userid = u.id ';
$where = 'WHERE s.course = '.$course->id.' AND u.deleted = 0 ';
}
Expand Down Expand Up @@ -332,9 +343,37 @@
}

if ($isteacher) {
echo '<form action="messageselect.php" method="post" name="messageselect">';
echo '
<script Language="JavaScript">
<!--
function checksubmit(form) {
var destination = form.formaction.options[form.formaction.selectedIndex].value;
if (destination == "" || !checkchecked(form)) {
form.formaction.selectedIndex = 0;
return false;
} else {
return true;
}
}
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) {
checked = true;
}
}
return checked;
}
//-->
</script>
';
echo '<form action="action_redir.php" method="get" name="studentsform" onSubmit="return checksubmit(this);">';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '<input type="hidden" name="returnto" value="'.$_SERVER['REQUEST_URI'].'" />';
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
}

if ($fullmode) { // Print simple listing
Expand Down Expand Up @@ -400,6 +439,7 @@
}
else {
$countrysort = (strpos($sort, 'country') !== false);
$timeformat = get_string('strftimedate');
if (!empty($students)) {
foreach ($students as $student) {
if ($student->lastaccess) {
Expand All @@ -420,15 +460,20 @@
}
}

$table->add_data(array (
$data = array (
//'<input type="checkbox" name="userid[]" value="'.$teacher->id.'" />',
print_user_picture($student->id, $course->id, $student->picture, false, true),
'<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id.'">'.fullname($student).'</a></strong>',
$student->city,
$country,
$lastaccess,
($isteacher ? '<input type="checkbox" name="email'.$student->id.'" />' : '')
));
$lastaccess);
if ($course->enrolperiod) {
$data[] = userdate($student->timeend, $timeformat);
}
if ($isteacher) {
$data[] = '<input type="checkbox" name="user'.$student->id.'" />';
}
$table->add_data($data);

}
}
Expand All @@ -438,11 +483,15 @@
}

if ($isteacher) {
echo '<center>';
echo '<input type="button" onclick="checkall()" value="'.get_string('checkall').'" />';
echo '<input type="button" onclick="checknone()" value="'.get_string('checknone').'" />';
$displaylist[1] = get_string('messageselectadd');
choose_from_menu ($displaylist, "messageselect", "", get_string("withselectedusers"), "javascript:document.messageselect.submit()");
echo '<br /><center>';
echo '<input type="button" onclick="checkall()" value="'.get_string('checkall').'" /> ';
echo '<input type="button" onclick="checknone()" value="'.get_string('checknone').'" /> ';
$displaylist['messageselect.php'] = get_string('messageselectadd');
if ($course->enrolperiod) {
$displaylist['extendenrol.php'] = get_string('extendenrol');
}
choose_from_menu ($displaylist, "formaction", "", get_string("withselectedusers"), "this.form.submit();", "");
echo '<input type="submit" value="' . get_string('ok') . '"';
echo '</center></form>';
}

Expand Down
4 changes: 2 additions & 2 deletions user/messageselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

$count = 0;

foreach ($_POST as $k => $v) {
if (preg_match('/email(\d+)/',$k,$m)) {
foreach ($_GET as $k => $v) {
if (preg_match('/^user(\d+)$/',$k,$m)) {
if (!array_key_exists($m[1],$SESSION->emailto[$id])) {
if ($user = get_record_select('user','id = '.$m[1],'id,firstname,lastname,idnumber,email,emailstop,mailformat')) {
$SESSION->emailto[$id][$m[1]] = $user;
Expand Down

0 comments on commit 6746bb8

Please sign in to comment.