2 // backup.php - allows admin to edit all configuration variables for scheduled backups
4 require_once("../config.php");
5 require_once("../backup/lib.php");
6 require_once("../backup/backup_scheduled.php");
11 error("Only an admin can use this page");
14 if (!$site = get_site()) {
15 error("Site isn't defined!");
18 //Initialise error variables
20 $sche_destination_error = "";
22 /// If data submitted, then process and store.
24 if (($config = data_submitted()) && confirm_sesskey()) {
26 //First of all we check that everything is correct
27 //Check for trailing slash and backslash in backup_sche_destination
28 if (!empty($backup_sche_destination) and
29 (substr($backup_sche_destination,-1) == "/" or substr($backup_sche_destination,-1) == "\\")) {
31 $sche_destination_error = get_string("pathslasherror");
32 //Now check that backup_sche_destination dir exists
33 } else if (!empty($backup_sche_destination) and
34 !is_dir($backup_sche_destination)) {
36 $sche_destination_error = get_string("pathnotexists");
39 //We need to do some weekdays conversions prior to continue
42 $a_config = (array)$config;
44 $tocheck = "dayofweek_".$i;
45 if (isset($a_config[$tocheck])) {
50 unset($a_config[$tocheck]);
53 $a_config['backup_sche_weekdays'] = $temp;
54 $config = (object)$a_config;
55 //weekdays conversions done. Continue
57 foreach ($config as $name => $value) {
58 backup_set_config($name, $value);
61 //And now, we execute schedule_backup_next_execution() for each course in the server to have the next
62 //execution time updated automatically everytime it's changed.
70 if (! $backup_config = backup_get_config()) {
75 if ($courses = get_records('course', '', '', '', 'id,shortname')) {
76 //For each course, we check (insert, update) the backup_course table
78 foreach ($courses as $course) {
79 //We check if the course exists in backup_course
80 $backup_course = get_record("backup_courses","courseid",$course->id
);
81 //If it doesn't exist, create
82 if (!$backup_course) {
83 $temp_backup_course->courseid
= $course->id
;
84 $newid = insert_record("backup_courses",$temp_backup_course);
86 $backup_course = get_record("backup_courses","id",$newid);
88 //Now, calculate next execution of the course
89 $nextstarttime = schedule_backup_next_execution ($backup_course,$backup_config,time(),$admin->timezone
);
91 set_field("backup_courses","nextstarttime",$nextstarttime,"courseid",$backup_course->courseid
);
97 redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
102 /// Otherwise print the form.
104 $stradmin = get_string("administration");
105 $strconfiguration = get_string("configuration");
106 $strbackup = get_string("backup");
108 print_header("$site->shortname: $strconfiguration: $strbackup", $site->fullname
,
109 "<a href=\"index.php\">$stradmin</a> -> ".
110 "<a href=\"configure.php\">$strconfiguration</a> -> ".
113 echo "<p align=\"right\"><a href=\"../backup/log.php\">".get_string("logs")."</a></p>";
115 print_heading($strbackup);
117 print_simple_box("<center>".get_string("adminhelpbackup")."</center>", "center", "50%");
120 print_simple_box_start("center");
122 //Check for required functions...
123 if (!function_exists('utf8_encode')) {
124 notify("You need to add XML support to your PHP installation");
126 include ("$CFG->dirroot/backup/config.html");
128 print_simple_box_end();