//Define some globals for all the script
- //MUST CHANGE WITH FINAL BACKUP LOCATION !! WITHOUT TRAILING SLASH !!
- //ALL RELATIVE FROM THE LOCATION OF THE backup.php SCRIPT !!!
-
- $moodle_home = "..";
- $mods_home = "../mod";
-
- //END MUST CHANGE
-
- //Units used
- require_once ("$moodle_home/config.php");
- require_once ("$moodle_home/version.php");
+ require_once ("../config.php");
require_once ("lib.php");
require_once ("backuplib.php");
- //Optional variables
optional_variable($id); // course id
- //Check login
require_login();
- //Check admin
- if (!isadmin()) {
- error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
+ if (!empty($id)) {
+ if (!isteacher($id)) {
+ error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
+ }
+ } else {
+ if (!isadmin()) {
+ error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
+ }
}
//Check site
//If no course has been selected or cancel button pressed
if (!$id or $cancel) {
print_header("$site->shortname: $strcoursebackup", $site->fullname,
- "<A HREF=\"$moodle_home/$CFG->admin/index.php\">$stradministration</A> -> $strcoursebackup");
+ "<A HREF=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</A> -> $strcoursebackup");
if ($courses = get_courses()) {
print_heading(get_string("choosecourse"));
print_simple_box_end();
} else {
print_heading(get_string("nocoursesyet"));
- print_continue("$moodle_home/$CFG->admin/index.php");
+ print_continue("$CFG->wwwroot/$CFG->admin/index.php");
}
print_footer();
exit;
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect (can't find it)");
}
+
//Print header
- print_header("$site->shortname: $strcoursebackup", $site->fullname,
- "<A HREF=\"$moodle_home/$CFG->admin/index.php\">$stradministration</A> ->
- <A HREF=\"backup.php\">$strcoursebackup</A> -> $course->fullname ($course->shortname)");
+ if (isadmin()) {
+ print_header("$site->shortname: $strcoursebackup", $site->fullname,
+ "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
+ <a href=\"backup.php\">$strcoursebackup</a> -> $course->fullname ($course->shortname)");
+ } else {
+ print_header("$site->shortname: $strcoursebackup", $site->fullname,
+ "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
+ <a href=\"backup.php\">$strcoursebackup</a> -> $course->fullname ($course->shortname)");
+ }
//Print form
print_heading("$strcoursebackup: $course->fullname ($course->shortname)");
if ($allmods = get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
- $modfile = "$mods_home/$modname/backuplib.php";
+ $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
$modbackup = $modname."_backup_mods";
$modcheckbackup = $modname."_check_backup_mods";
if (file_exists($modfile)) {
if ($allmods = get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
- $modfile = "$mods_home/$modname/backuplib.php";
+ $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
$modbackup = $modname."_backup_mods";
$modcheckbackup = $modname."_check_backup_mods";
if (file_exists($modfile)) {
$preferences->backup_unique_code = $backup_unique_code;
//Another Info
- $preferences->moodle_version = $version;
- $preferences->moodle_release = $release;
- $preferences->backup_version = $backup_version;
- $preferences->backup_release = $backup_release;
+ $preferences->moodle_version = $CFG->version;
+ $preferences->moodle_release = $CFG->release;
+ $preferences->backup_version = $CFG->backup_version;
+ $preferences->backup_release = $CFG->backup_release;
if ($count == 0) {
notice("No backupable modules are installed!");
//Now, zip all the backup directory contents
if ($status) {
echo "<li>".get_string("zippingbackup");
- $status = backup_zip ($preferences,$moodle_home);
+ $status = backup_zip ($preferences);
}
//Now, copy the zip file to course directory
//Print final message
print_simple_box(get_string("backupfinished"),"CENTER");
- print_continue($moodle_home."/files/index.php?id=".$preferences->backup_course."&wdir=/".get_string("backupdir"));
+ print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&wdir=/".get_string("backupdir"));
?>
if ($allmods = get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
- $modfile = "$mods_home/$modname/backuplib.php";
+ $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
$modbackup = $modname."_backup_mods";
$modcheckbackup = $modname."_check_backup_mods";
if (file_exists($modfile)) {
//The zipped file is created in the backup directory and named with
//the "oficial" name of the backup
//It uses "pclzip" if available or system "zip" (unix only)
- function backup_zip ($preferences,$moodle_home) {
+ function backup_zip ($preferences) {
global $CFG;
//Include into array
$files[] = $basedir."/".$file;
}
- include_once($moodle_home."/lib/pclzip/pclzip.lib.php");
+ include_once("$CFG->dirroot/lib/pclzip/pclzip.lib.php");
$archive = new PclZip("$basedir/$name");
if (($list = $archive->create($files,PCLZIP_OPT_REMOVE_PATH,$basedir)) == 0) {
error($archive->errorInfo(true));
//Define some globals for all the script
- $moodle_home = "..";
- $mods_home = "../mod";
-
//Units used
- require_once ("$moodle_home/config.php");
- require_once ("$moodle_home/version.php");
- require_once ("$moodle_home/lib/xmlize.php");
- require_once ("$moodle_home/course/lib.php");
+ require_once ("../config.php");
+ require_once ("../lib/xmlize.php");
+ require_once ("../course/lib.php");
require_once ("lib.php");
require_once ("restorelib.php");
//If no file has been selected from the FileManager, inform and end
if (!$file) {
print_header("$site->shortname: $strcourserestore", $site->fullname,
- "<A HREF=\"$moodle_home/$CFG->admin/index.php\">$stradministration</A> -> $strcourserestore");
+ "<A HREF=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</A> -> $strcourserestore");
print_heading(get_string("nofilesselected"));
- print_continue("$moodle_home/$CFG->admin/index.php");
+ print_continue("$CFG->wwwroot/$CFG->admin/index.php");
print_footer();
exit;
}
//If cancel has been selected, inform and end
if ($cancel) {
print_header("$site->shortname: $strcourserestore", $site->fullname,
- "<A HREF=\"$moodle_home/$CFG->admin/index.php\">$stradministration</A> -> $strcourserestore");
+ "<A HREF=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</A> -> $strcourserestore");
print_heading(get_string("restorecancelled"));
- print_continue("$moodle_home/$CFG->admin/index.php");
+ print_continue("$CFG->wwwroot/$CFG->admin/index.php");
print_footer();
exit;
}
//We are here, so me have a file.
//Print header
print_header("$site->shortname: $strcourserestore", $site->fullname,
- "<A HREF=\"$moodle_home/$CFG->admin/index.php\">$stradministration</A> ->
+ "<A HREF=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</A> ->
$strcourserestore -> ".basename($file));
//Print form
print_heading("$strcourserestore: ".basename($file));
print_simple_box_end();
} else {
print_heading(get_string("nocoursesyet"));
- print_continue("$moodle_home/$CFG->admin/index.php");
+ print_continue("$CFG->wwwroot/$CFG->admin/index.php");
}
//Checks everything and execute restore
} else if ((($restore->restoreto == 0) and ($restore->course_id != 0)) or ($restore->restoreto == 1)) {
if ($allmods = get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
- $modfile = "$mods_home/$modname/restorelib.php";
+ $modfile = "$CFG->dirroot/mod/$modname/restorelib.php";
//If file exists and we have selected to restore that type of module
if ((file_exists($modfile)) and ($restore->mods[$modname]->restore)) {
include_once($modfile);
//Print final message
print_simple_box(get_string("restorefinished"),"CENTER");
- print_continue($moodle_home."/course/view.php?id=".$restore->course_id);
+ print_continue("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
?>
if ($allmods = get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
- $modfile = "$mods_home/$modname/restorelib.php";
+ $modfile = "$CFG->dirroot/mod/$modname/restorelib.php";
$modrestore = $modname."_restore_mods";
if (file_exists($modfile)) {
include_once($modfile);
//Now unzip the file
if ($status) {
echo "<li>".get_string("unzippingbackup");
- $status = restore_unzip ($CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file),$moodle_home);
+ $status = restore_unzip ($CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file));
}
//Now check for the moodle.xml file
//This function unzips a zip file in the same directory that it is
//It automatically uses pclzip or command line unzip
- function restore_unzip ($file,$moodle_home) {
+ function restore_unzip ($file) {
global $CFG;
$status = true;
if (empty($CFG->unzip)) { // Use built-in php-based unzip function
- include_once($moodle_home."/lib/pclzip/pclzip.lib.php");
+ include_once("$CFG->wwwroot/lib/pclzip/pclzip.lib.php");
$archive = new PclZip($file);
if (!$list = $archive->extract(dirname($file))) {
$status = false;