2003-11-27 23:28:29 +00:00
< ? PHP // $Id$
// backup.php - allows admin to edit all configuration variables for scheduled backups
require_once ( " ../config.php " );
require_once ( " ../backup/lib.php " );
2004-05-14 16:37:45 +00:00
require_once ( " ../backup/backup_scheduled.php " );
2003-11-27 23:28:29 +00:00
require_login ();
if ( ! isadmin ()) {
error ( " Only an admin can use this page " );
}
if ( ! $site = get_site ()) {
error ( " Site isn't defined! " );
}
2004-01-26 23:24:12 +00:00
//Initialise error variables
$error = false ;
$sche_destination_error = " " ;
2003-11-27 23:28:29 +00:00
2004-01-26 23:24:12 +00:00
/// If data submitted, then process and store.
2003-11-27 23:28:29 +00:00
if ( $config = data_submitted ()) {
2004-01-26 23:24:12 +00:00
//First of all we check that everything is correct
//Check for trailing slash and backslash in backup_sche_destination
if ( ! empty ( $backup_sche_destination ) and
( substr ( $backup_sche_destination , - 1 ) == " / " or substr ( $backup_sche_destination , - 1 ) == " \\ " )) {
$error = true ;
$sche_destination_error = get_string ( " pathslasherror " );
//Now check that backup_sche_destination dir exists
} else if ( ! empty ( $backup_sche_destination ) and
! is_dir ( $backup_sche_destination )) {
$error = true ;
$sche_destination_error = get_string ( " pathnotexists " );
}
2003-11-30 18:58:37 +00:00
//We need to do some weekdays conversions prior to continue
$i = 0 ;
$temp = " " ;
$a_config = ( array ) $config ;
while ( $i < 7 ) {
$tocheck = " dayofweek_ " . $i ;
if ( isset ( $a_config [ $tocheck ])) {
$temp .= " 1 " ;
} else {
$temp .= " 0 " ;
}
unset ( $a_config [ $tocheck ]);
$i ++ ;
}
$a_config [ 'backup_sche_weekdays' ] = $temp ;
$config = ( object ) $a_config ;
//weekdays conversions done. Continue
2003-11-27 23:28:29 +00:00
print_header ();
foreach ( $config as $name => $value ) {
backup_set_config ( $name , $value );
}
2004-05-14 16:37:45 +00:00
//And now, we execute schedule_backup_next_execution() for each course in the server to have the next
//execution time updated automatically everytime it's changed.
$status = true ;
//get admin
$admin = get_admin ();
if ( ! $admin ) {
$status = false ;
}
//get backup config
2004-05-14 17:07:48 +00:00
if ( ! $backup_config = backup_get_config ()) {
$status = false ;
}
2004-05-14 16:37:45 +00:00
if ( $status ) {
//get courses
if ( $courses = get_records ( " course " )) {
//For each course, we check (insert, update) the backup_course table
//with needed data
foreach ( $courses as $course ) {
//We check if the course exists in backup_course
$backup_course = get_record ( " backup_courses " , " courseid " , $course -> id );
//If it doesn't exist, create
if ( ! $backup_course ) {
$temp_backup_course -> courseid = $course -> id ;
$newid = insert_record ( " backup_courses " , $temp_backup_course );
//And get it from db
$backup_course = get_record ( " backup_courses " , " id " , $newid );
}
//Now, calculate next execution of the course
$nextstarttime = schedule_backup_next_execution ( $backup_course , $backup_config , time (), $admin -> timezone );
//Save it to db
set_field ( " backup_courses " , " nextstarttime " , $nextstarttime , " courseid " , $backup_course -> courseid );
}
}
}
2004-01-26 23:24:12 +00:00
if ( ! $error ) {
redirect ( " $CFG->wwwroot / $CFG->admin /index.php " , get_string ( " changessaved " ), 1 );
exit ;
}
2003-11-27 23:28:29 +00:00
}
/// Otherwise print the form.
$stradmin = get_string ( " administration " );
$strconfiguration = get_string ( " configuration " );
$strbackup = get_string ( " backup " );
print_header ( " $site->shortname : $strconfiguration : $strbackup " , $site -> fullname ,
" <a href= \" index.php \" > $stradmin </a> -> " .
" <a href= \" configure.php \" > $strconfiguration </a> -> " .
2004-02-24 13:18:22 +00:00
$strbackup );
echo " <p align=right><a href= \" ../backup/log.php \" > " . get_string ( " logs " ) . " </a></p> " ;
2003-11-27 23:28:29 +00:00
print_heading ( $strbackup );
print_simple_box ( " <center> " . get_string ( " adminhelpbackup " ) . " </center> " , " center " , " 50% " );
echo " <br /> " ;
print_simple_box_start ( " center " , " " , " $THEME->cellheading " );
2004-05-20 16:05:29 +00:00
//Check for required functions...
if ( ! function_exists ( 'utf8_encode' )) {
print_simple_box ( " <font color= \" red \" >You need to add XML support to your PHP installation</font> " , " center " , " 70% " , " $THEME->cellheading " , " 20 " , " noticebox " );
}
include ( " $CFG->dirroot /backup/config.html " );
2003-11-27 23:28:29 +00:00
print_simple_box_end ();
print_footer ();
?>