1 <?php
// preliminary page to find a course to import data from & interface with the backup/restore functionality
3 require_once('../../../config.php');
4 require_once('../../lib.php');
5 require_once($CFG->dirroot
.'/backup/restorelib.php');
7 $id = required_param('id', PARAM_INT
); // course id to import TO
8 $fromcourse = optional_param('fromcourse', 0, PARAM_INT
);
9 $fromcoursesearch = optional_param('fromcoursesearch', '', PARAM_RAW
);
10 $page = optional_param('page', 0, PARAM_INT
);
11 $filename = optional_param('filename', 0, PARAM_PATH
);
13 $strimportactivities = get_string('importactivities');
15 if (! ($course = get_record("course", "id", $id)) ) {
16 error("That's an invalid course id");
19 if (!$site = get_site()){
20 error("Couldn't get site course");
23 require_login($course->id
);
24 $tocontext = get_context_instance(CONTEXT_COURSE
, $id);
26 $fromcontext = get_context_instance(CONTEXT_COURSE
, $fromcourse);
28 $syscontext = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
30 if (!has_capability('moodle/course:manageactivities', $tocontext)) {
31 error("You need do not have the required permissions to import activities to this course");
34 // if we're not a course creator , we can only import from our own courses.
35 if (has_capability('moodle/course:create', $syscontext)) {
39 if ($from = get_record('course', 'id', $fromcourse)) {
40 if (!has_capability('moodle/course:manageactivities', $fromcontext)) {
41 error("You need to have the required permissions in the course you are importing data from, as well");
43 if (!empty($filename) && file_exists($CFG->dataroot
.'/'.$filename) && !empty($SESSION->import_preferences
)) {
44 $restore = backup_to_restore_array($SESSION->import_preferences
);
45 $restore->restoreto
= 1;
46 $restore->course_id
= $id;
47 $restore->importing
= 1; // magic variable so we know that we're importing rather than just restoring.
49 $SESSION->restore
= $restore;
50 redirect($CFG->wwwroot
.'/backup/restore.php?file='.$filename.'&id='.$fromcourse.'&to='.$id);
53 redirect($CFG->wwwroot
.'/backup/backup.php?id='.$from->id
.'&to='.$course->id
);
57 print_header("$course->shortname: $strimportactivities", $course->fullname
,
58 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ".
59 "-> <a href=\"$CFG->wwwroot/course/import.php?id=$course->id\">".get_string('import')."</a> ".
60 "-> $strimportactivities");
61 require_once('mod.php');