2 require_once("../config.php");
4 $id = required_param('id', PARAM_INT
); // course id
5 $users = optional_param('userid', array(), PARAM_INT
); // array of user id
7 if (! $course = get_record('course', 'id', $id)) {
8 error("Course ID is incorrect");
11 require_login($course->id
);
13 if (!isteacheredit($course->id
)) {
14 error("You must be an editing teacher in this course, or an admin");
17 if ((count($users) > 0) and ($form = data_submitted()) and confirm_sesskey()) {
18 if (count($form->userid
) != count($form->extendperiod
)) {
19 error('Parameters malformation', $CFG->wwwroot
.'/user/index.php?id='.$id);
22 foreach ($form->userid
as $k => $v) {
23 if ($student = get_record('user_students', 'userid', $v, 'course', $id)) {
24 enrol_student($v, $id, $student->timestart
, $student->timeend +
$form->extendperiod
[$k]);
28 redirect("$CFG->wwwroot/user/index.php?id=$id", get_string('changessaved'));
33 if ($course->category
) {
34 print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname
,
35 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> -> ".
36 get_string('extendenrol'), "", "", true, " ", navmenu($course));
38 print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname
,
39 get_string('extendenrol'), "", "", true, " ", navmenu($course));
42 for ($i=1; $i<=365; $i++
) {
43 $seconds = $i * 86400;
44 $periodmenu[$seconds] = get_string('numdays', '', $i);
47 print_heading(get_string('extendenrol'));
48 echo "<form method=\"post\" action=\"extendenrol.php\" name=\"form\">\n";
49 echo '<input type="hidden" name="id" value="'.$course->id
.'" />';
50 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey
.'" />';
51 $table->head
= array (get_string('fullname'), get_string('enrolmentstart'), get_string('enrolmentend'), get_string('extendperiod'));
52 $table->align
= array ('left', 'center', 'center', 'center');
53 $table->width
= "600";
54 $timeformat = get_string('strftimedate');
55 $nochange = get_string('nochange');
56 $notavailable = get_string('notavailable');
57 $unlimited = get_string('unlimited');
58 foreach ($_POST as $k => $v) {
59 if (preg_match('/^user(\d+)$/',$k,$m)) {
60 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]} AND s.course=$course->id"))) {
63 if ($user->timestart
) {
64 $timestart = userdate($user->timestart
, $timeformat);
66 $timestart = $notavailable;
69 $timeend = userdate($user->timeend
, $timeformat);
70 $checkbox = choose_from_menu($periodmenu, "extendperiod[{$m[1]}]", "0", $nochange, '', '0', true);
72 $timeend = $unlimited;
73 $checkbox = '<input type="hidden" name="extendperiod['.$m[1].']" value="0" />'.$nochange;
75 $table->data
[] = array(
76 fullname($user, true),
79 '<input type="hidden" name="userid['.$m[1].']" value="'.$m[1].'" />'.$checkbox
84 echo "\n<div style=\"width:100%;text-align:center;\"><input type=\"submit\" value=\"".get_string('savechanges')."\" /></div>\n</form>\n";
86 print_footer($course);