Noted that xml format can now handle images.
[moodle-linuxchix.git] / admin / backup.php
blob1e757d129fe8f4f75a00013583d5099ffe2879c5
1 <?PHP // $Id$
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");
8 require_login();
10 if (!isadmin()) {
11 error("Only an admin can use this page");
14 if (!$site = get_site()) {
15 error("Site isn't defined!");
18 //Initialise error variables
19 $error = false;
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) == "\\")) {
30 $error = true;
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)) {
35 $error = true;
36 $sche_destination_error = get_string("pathnotexists");
39 //We need to do some weekdays conversions prior to continue
40 $i = 0;
41 $temp = "";
42 $a_config = (array)$config;
43 while ($i<7) {
44 $tocheck = "dayofweek_".$i;
45 if (isset($a_config[$tocheck])) {
46 $temp .= "1";
47 } else {
48 $temp .= "0";
50 unset($a_config[$tocheck]);
51 $i++;
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.
63 $status = true;
64 //get admin
65 $admin = get_admin();
66 if (!$admin) {
67 $status = false;
69 //get backup config
70 if (! $backup_config = backup_get_config()) {
71 $status = false;
73 if ($status) {
74 //get courses
75 if ($courses = get_records('course', '', '', '', 'id,shortname')) {
76 //For each course, we check (insert, update) the backup_course table
77 //with needed data
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);
85 //And get it from db
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);
90 //Save it to db
91 set_field("backup_courses","nextstarttime",$nextstarttime,"courseid",$backup_course->courseid);
96 if (!$error) {
97 redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
98 exit;
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> -> ".
111 $strbackup);
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%");
118 echo "<br />";
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();
130 print_footer();