+++ /dev/null
-<?PHP // $Id$
- // backup.php - allows admin to edit all configuration variables for scheduled backups
-
- require_once("../config.php");
- require_once("../backup/lib.php");
- require_once("../backup/backup_scheduled.php");
-
- require_login();
-
- require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
-
- if (!$site = get_site()) {
- error("Site isn't defined!");
- }
-
- //Initialise error variables
- $error = false;
- $sche_destination_error = "";
-
- /// If data submitted, then process and store.
-
- if (($config = data_submitted()) && confirm_sesskey()) {
-
- //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");
- }
-
- //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
-
- foreach ($config as $name => $value) {
- backup_set_config($name, $value);
- }
-
- //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
- if (! $backup_config = backup_get_config()) {
- $status = false;
- }
- if ($status) {
- //get courses
- if ($courses = get_records('course', '', '', '', 'id,shortname')) {
- //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);
- }
- }
- }
-
- if (!$error) {
- redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
- exit;
- }
- }
-
-/// 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> -> ".
- $strbackup);
-
- echo "<p align=\"right\"><a href=\"../backup/log.php\">".get_string("logs")."</a></p>";
-
- print_heading($strbackup);
-
- print_simple_box("<center>".get_string("adminhelpbackup")."</center>", "center", "50%");
- echo "<br />";
-
- print_simple_box_start("center");
-
- //Check for required functions...
- if (!function_exists('utf8_encode')) {
- notify("You need to add XML support to your PHP installation");
- }
- include ("$CFG->dirroot/backup/config.html");
-
- print_simple_box_end();
-
- print_footer();
-
-?>
+++ /dev/null
-<?php
- //Get some strings
-
- $yes = get_string("yes");
- $no = get_string("no");
- $withuserdata = get_string("withuserdata");
- $withoutuserdata = get_string("withoutuserdata");
- $course = get_string("course");
- $all = get_string("all");
- $include = get_string("include");
- $modules = get_string("modules");
-
- //Get backup_config pairs
- $backup_config = backup_get_config();
-
- //Checks backup_config pairs exist
- if (!isset($backup_config->backup_sche_modules)) {
- $backup_config->backup_sche_modules = 1;
- }
- if (!isset($backup_config->backup_sche_withuserdata)) {
- $backup_config->backup_sche_withuserdata = 1;
- }
- if (!isset($backup_config->backup_sche_metacourse)) {
- $backup_config->backup_sche_metacourse = 1;
- }
- if (!isset($backup_config->backup_sche_users)) {
- $backup_config->backup_sche_users = 1;
- }
- if (!isset($backup_config->backup_sche_logs)) {
- $backup_config->backup_sche_logs = 0;
- }
- if (!isset($backup_config->backup_sche_userfiles)) {
- $backup_config->backup_sche_userfiles = 1;
- }
- if (!isset($backup_config->backup_sche_coursefiles)) {
- $backup_config->backup_sche_coursefiles = 1;
- }
- if (!isset($backup_config->backup_sche_messages)) {
- $backup_config->backup_sche_messages = 0;
- }
- if (!isset($backup_config->backup_sche_active)) {
- $backup_config->backup_sche_active = 0;
- }
- if (!isset($backup_config->backup_sche_weekdays)) {
- $backup_config->backup_sche_weekdays = "0000000";
- }
- if (!isset($backup_config->backup_sche_hour)) {
- $backup_config->backup_sche_hour = 00;
- }
- if (!isset($backup_config->backup_sche_minute)) {
- $backup_config->backup_sche_minute = 00;
- }
- if (!isset($backup_config->backup_sche_destination)) {
- $backup_config->backup_sche_destination = "";
- }
- if (!isset($backup_config->backup_sche_keep)) {
- $backup_config->backup_sche_keep = 1;
- }
-
- //print_object($backup_config); //Debug
-
- //Yes/no array for use in yes/no menu
- $yesno_array[0] = $no;
- $yesno_array[1] = $yes;
-
- //With user data/without user data array for use in menu
- $withwithout_array[0] = $withoutuserdata;
- $withwithout_array[1] = $withuserdata;
-
- //Course/alla array for use in course/all menu
- $courseall_array[0] = $all;
- $courseall_array[1] = $course;
-
- //Keep array for use in keep menu
- $keep_array[0] = $all;
- $keep_array[1] = "1";
- $keep_array[2] = "2";
- $keep_array[5] = "5";
- $keep_array[10] = "10";
- $keep_array[20] = "20";
- $keep_array[30] = "30";
- $keep_array[40] = "40";
- $keep_array[50] = "50";
- $keep_array[100] = "100";
- $keep_array[200] = "200";
- $keep_array[300] = "300";
- $keep_array[400] = "400";
- $keep_array[500] = "500";
-?>
-<form method="post" action="backup.php" name="form">
-<?php echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\"/>"; ?>
-
-<table cellpadding="9" cellspacing="0" >
-<tr valign="top">
- <td colspan ="3" align="center"><strong><?php print_string("settings") ?></strong></td>
-</tr>
-<tr valign="top">
- <td align="right"><?php print_string("includemodules") ?>:</td>
- <td nowrap="nowrap">
- <?php choose_from_menu($yesno_array, "backup_sche_modules", $backup_config->backup_sche_modules, "") ?>
- <?php choose_from_menu($withwithout_array, "backup_sche_withuserdata", $backup_config->backup_sche_withuserdata, "") ?>
- </td>
- <td>
- <?php print_string("backupincludemoduleshelp") ?>
- </td>
-</tr>
-<tr valign="top">
- <td align="right"><?php print_string("metacourse") ?>:</td>
- <td>
- <?php choose_from_menu($yesno_array, "backup_sche_metacourse", $backup_config->backup_sche_metacourse, "") ?>
- </td>
- <td>
- <?php print_string("backupmetacoursehelp") ?>
- </td>
-</tr>
-<tr valign="top">
- <td align="right"><?php print_string("users") ?>:</td>
- <td>
- <?php choose_from_menu($courseall_array, "backup_sche_users", $backup_config->backup_sche_users, "") ?>
- </td>
- <td>
- <?php print_string("backupusershelp") ?>
- </td>
-</tr>
-<tr valign="top">
- <td align="right"><?php print_string("logs") ?>:</td>
- <td>
- <?php choose_from_menu($yesno_array, "backup_sche_logs", $backup_config->backup_sche_logs, "") ?>
- </td>
- <td>
- <?php print_string("backuplogshelp") ?>
- </td>
-</tr>
-<tr valign="top">
- <td align="right"><?php print_string("userfiles") ?>:</td>
- <td>
- <?php choose_from_menu($yesno_array, "backup_sche_userfiles", $backup_config->backup_sche_userfiles, "") ?>
- </td>
- <td>
- <?php print_string("backupuserfileshelp") ?>
- </td>
-</tr>
-<tr valign="top">
- <td align="right"><?php print_string("coursefiles") ?>:</td>
- <td>
- <?php choose_from_menu($yesno_array, "backup_sche_coursefiles", $backup_config->backup_sche_coursefiles, "") ?>
- </td>
- <td>
- <?php print_string("backupcoursefileshelp") ?>
- </td>
-</tr>
-<tr valign="top">
- <td align="right"><?php print_string("messages","message") ?>:</td>
- <td>
- <?php choose_from_menu($yesno_array, "backup_sche_messages", $backup_config->backup_sche_messages, "") ?>
- </td>
- <td>
- <?php print_string("backupmessageshelp","message") ?>
- </td>
-</tr>
-<tr valign="top">
- <td align="right"><?php print_string("keep") ?>:</td>
- <td>
- <?php
- choose_from_menu($keep_array, "backup_sche_keep", $backup_config->backup_sche_keep, "");
- print_string("files");
- ?>
- </td>
- <td>
- <?php print_string("backupkeephelp") ?>
- </td>
-</tr>
-<tr valign="top">
- <td colspan="3" align="center"><strong><?php print_string("schedule") ?></strong></td>
-</tr>
-<tr valign="top">
- <td colspan="3" align="center">
- <?php print_string("active") ?>: <?php choose_from_menu($yesno_array, "backup_sche_active", $backup_config->backup_sche_active, "") ?>
- </td>
-</tr>
-<tr>
- <td colspan="3" align="center">
- <?php
- //Get first day of week from languaje files
- //after searching the web I haven't find a sytem to retrieve it in php from locale info
- $firstdayofweek = get_string("firstdayofweek");
- //If it is empty ot it is different of 1, default to 0
- if (!isset($firstdayofweek) || $firstdayofweek != 1) {
- $firstdayofweek = 0;
- }
- //Now create the GMT timestamp of a well-know sunday (02/25/2001, my 31th birthday (stronk7) !!)
- $onesunday = gmmktime(0,0,0,2,25,2001);
- $i = 0;
- $day_names = "";
- $check_names = "";
- while ($i<7) {
- $day_names[] = gmstrftime("%A",$onesunday + (($firstdayofweek+$i)*86400));
- //Calculate standard day of week (0=Sunday......6=Saturday)
- //to store info in that exact order in DB
- $stddayofweek = ($i+$firstdayofweek) % 7;
- //Calculate the status of the checkbox
- if (substr($backup_config->backup_sche_weekdays,$stddayofweek,1) == "1") {
- $strchecked = " checked=\"checked\"";
- } else {
- $strchecked = "";
- }
- $check_names[] = "<input type=\"checkbox\" name=\"dayofweek_$stddayofweek\" value=\"1\"$strchecked />";
- $i++;
- }
- $table->align = array("center","center","center","center","center","center","center");
- $table->head = $day_names;
- $table->data[] = $check_names;
- print_table($table);
- ?>
- </td>
-</tr>
-<tr valign="top">
- <td colspan ="3" align="center">
- <?php print_string("executeat") ?>: <?php print_time_selector("backup_sche_hour","backup_sche_minute",make_timestamp(2000,1,1,$backup_config->backup_sche_hour,$backup_config->backup_sche_minute)) ?>
- </td>
-</tr>
-<tr valign="top">
- <td colspan ="3" align="center">
- <?php print_string("saveto") ?>: <input name="backup_sche_destination" type="text" size="40" value="<?php p($backup_config->backup_sche_destination) ?>" /><?php helpbutton("directorypaths", strip_tags(get_string("directorypaths"))) ?><br /><?php if (!empty($sche_destination_error)) { formerr($sche_destination_error); echo "<br />"; } ?><?php print_string("backupsavetohelp") ?>
- </td>
-</tr>
-<tr>
- <td colspan="3" align="center">
- <input type="submit" value="<?php print_string("savechanges") ?>" /></td>
-</tr>
-</table>
-
-</form>