2006-06-26 21:58:35 +00:00
< ? php // $Id$
2005-09-29 06:30:58 +00:00
require_once ( " ../config.php " );
2006-06-26 21:58:35 +00:00
$id = required_param ( 'id' , PARAM_INT ); // course id
$users = optional_param ( 'userid' , array (), PARAM_INT ); // array of user id
2005-09-29 06:30:58 +00:00
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 " );
}
2006-06-26 21:58:35 +00:00
if (( count ( $users ) > 0 ) and ( $form = data_submitted ()) and confirm_sesskey ()) {
2005-09-29 06:30:58 +00:00
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
2006-11-12 08:55:13 +00:00
if ( $course -> id != SITEID ) {
2005-09-29 06:30:58 +00:00
print_header ( " $course->shortname : " . get_string ( 'extendenrol' ), $course -> fullname ,
" <a href= \" ../course/view.php?id= $course->id\ " > $course -> shortname </ a > -> " .
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' ));
2005-11-29 04:03:25 +00:00
echo " <form method= \" post \" action= \" extendenrol.php \" name= \" form \" > \n " ;
2005-09-29 06:30:58 +00:00
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' );
2005-11-29 04:04:16 +00:00
$notavailable = get_string ( 'notavailable' );
$unlimited = get_string ( 'unlimited' );
2005-11-08 02:34:19 +00:00
foreach ( $_POST as $k => $v ) {
2005-09-29 06:30:58 +00:00
if ( preg_match ( '/^user(\d+)$/' , $k , $m )) {
2005-11-29 04:03:25 +00:00
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 " ))) {
2005-09-29 06:30:58 +00:00
continue ;
}
2005-11-29 04:04:16 +00:00
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 = '<input type="hidden" name="extendperiod[' . $m [ 1 ] . ']" value="0" />' . $nochange ;
}
2005-09-29 06:30:58 +00:00
$table -> data [] = array (
fullname ( $user , true ),
2005-11-29 04:04:16 +00:00
$timestart ,
$timeend ,
'<input type="hidden" name="userid[' . $m [ 1 ] . ']" value="' . $m [ 1 ] . '" />' . $checkbox
2005-09-29 06:30:58 +00:00
);
}
}
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 );
?>