Too many bugs, not enough time!
[moodle.git] / admin / backup.php
blob3623bb6572d3b890c84568635b279973f6ed627f
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");
7 require_login();
9 if (!isadmin()) {
10 error("Only an admin can use this page");
13 if (!$site = get_site()) {
14 error("Site isn't defined!");
17 //Initialise error variables
18 $error = false;
19 $sche_destination_error = "";
21 /// If data submitted, then process and store.
23 if ($config = data_submitted()) {
25 //First of all we check that everything is correct
26 //Check for trailing slash and backslash in backup_sche_destination
27 if (!empty($backup_sche_destination) and
28 (substr($backup_sche_destination,-1) == "/" or substr($backup_sche_destination,-1) == "\\")) {
29 $error = true;
30 $sche_destination_error = get_string("pathslasherror");
31 //Now check that backup_sche_destination dir exists
32 } else if (!empty($backup_sche_destination) and
33 !is_dir($backup_sche_destination)) {
34 $error = true;
35 $sche_destination_error = get_string("pathnotexists");
38 //We need to do some weekdays conversions prior to continue
39 $i = 0;
40 $temp = "";
41 $a_config = (array)$config;
42 while ($i<7) {
43 $tocheck = "dayofweek_".$i;
44 if (isset($a_config[$tocheck])) {
45 $temp .= "1";
46 } else {
47 $temp .= "0";
49 unset($a_config[$tocheck]);
50 $i++;
52 $a_config['backup_sche_weekdays'] = $temp;
53 $config = (object)$a_config;
54 //weekdays conversions done. Continue
56 print_header();
57 foreach ($config as $name => $value) {
58 backup_set_config($name, $value);
60 if (!$error) {
61 redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
62 exit;
66 /// Otherwise print the form.
68 $stradmin = get_string("administration");
69 $strconfiguration = get_string("configuration");
70 $strbackup = get_string("backup");
72 print_header("$site->shortname: $strconfiguration: $strbackup", $site->fullname,
73 "<a href=\"index.php\">$stradmin</a> -> ".
74 "<a href=\"configure.php\">$strconfiguration</a> -> ".
75 $strbackup);
77 echo "<p align=right><a href=\"../backup/log.php\">".get_string("logs")."</a></p>";
79 print_heading($strbackup);
81 print_simple_box("<center>".get_string("adminhelpbackup")."</center>", "center", "50%");
82 echo "<br />";
84 print_simple_box_start("center", "", "$THEME->cellheading");
85 include("$CFG->dirroot/backup/config.html");
86 print_simple_box_end();
88 print_footer();