id); // to extend enrolments current user needs to be able to do role assignments require_capability('moodle/role:assign', $context); if ((count($users) > 0) and ($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) { // find all roles this student have in this course if ($students = get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend FROM {$CFG->prefix}role_assignments ra WHERE userid = $v AND contextid = $context->id")) { // enrol these users again, with time extension // not that this is not necessarily a student role foreach ($students as $student) { // only extend if the user can make role assignments on this role if (user_can_assign($context, $student->roleid)) { role_assign($student->roleid, $v, 0, $context->id, $student->timestart, $student->timeend + $form->extendperiod[$k], 0); } } } } redirect("$CFG->wwwroot/user/index.php?id=$id", get_string('changessaved')); } /// Print headers if ($course->id != SITEID) { print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname, "id\">$course->shortname -> ". get_string('extendenrol'), "", "", true, " ", navmenu($course)); } else { print_header("$course->shortname: ".get_string('extendenrol'), $course->fullname, get_string('extendenrol'), "", "", true, " ", navmenu($course)); } for ($i=1; $i<=365; $i++) { $seconds = $i * 86400; $periodmenu[$seconds] = get_string('numdays', '', $i); } print_heading(get_string('extendenrol')); echo "
\n"; echo ''; echo ''; $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'); $notavailable = get_string('notavailable'); $unlimited = get_string('unlimited'); foreach ($_POST 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}role_assignments ra ON u.id=ra.userid WHERE u.id={$m[1]} AND ra.contextid = $context->id"))) { continue; } if ($user->timestart) { $timestart = userdate($user->timestart, $timeformat); } else { $timestart = $notavailable; } if ($user->timeend) { $timeend = userdate($user->timeend, $timeformat); $checkbox = choose_from_menu($periodmenu, "extendperiod[{$m[1]}]", "0", $nochange, '', '0', true); } else { $timeend = $unlimited; $checkbox = ''.$nochange; } $table->data[] = array( fullname($user, true), $timestart, $timeend, ''.$checkbox ); } } print_table($table); echo "\n
\n
\n"; print_footer($course); ?>