Restore into new course and existing course implemented.
[moodle.git] / backup / restore_execute.html
CommitLineData
a2c7397c 1<?PHP //$Id$
2 //This page receives the required info and executes the restore
3 //with the parameters suplied. Whe finished, delete temporary
4 //data from backup_tables and temp directory
5
6 //Get objects from session
7 if ($SESSION) {
8 $info = $SESSION->info;
9 $course_header = $SESSION->course_header;
10 $restore = $SESSION->restore;
11 }
12
13 //Check login
14 require_login();
15
16 //Check admin
17 if (!isadmin()) {
18 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
19 }
20
21 //Check site
22 if (!$site = get_site()) {
23 error("Site not found!");
24 }
25
26 //Start the main table
27 echo "<table cellpadding=5>";
28 echo "<tr><td>";
29
30 //Start the main ul
31 echo "<ul>";
32
33 //Init status
34 $status = true;
35
36 //Localtion of the xml file
37 $xml_file = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code."/moodle.xml";
38
39 //If we've selected to restore into new course
40 //create it (course)
41 //Saving conversion id variables into backup_tables
42 if ($restore->restoreto ==1) {
43 echo "<li>Creating new course";
44 $status = restore_create_new_course($restore,&$course_header);
45 //Print course fullname and shortname and category
46 if ($status) {
47 echo "<ul>";
48 echo "<li>".$course_header->course_fullname." (".$course_header->course_shortname.")";
49 echo "<li>".get_string("category").": ".$course_header->category->name;
50 echo "</ul>";
51 //Put the destination course_id
52 $restore->course_id = $course_header->course_id;
53 }
54 } else {
55 $course = get_record("course","id",$restore->course_id);
56 if ($course) {
57 echo "<li>Using existing course";
58 echo "<ul>";
59 echo "<li>From: ".$course_header->course_fullname." (".$course_header->course_shortname.")";
60 echo "<li>To: ".$course->fullname." (".$course->shortname.")";
61 echo "</ul>";
62 }
63 }
64
65 //Now create the course_sections and their associated course_modules
66 if (($restore->restoreto ==1) and ($status)) {
67 echo "<li>Creating sections";
68 $status = restore_create_sections($restore,$xml_file);
69 }
70
71 //Now create users as needed
72 if ($status and ($restore->users == 0 or $restore->users == 1)) {
73 echo "<li>Creating users";
74 $status = restore_create_users($restore,$xml_file);
75 }
76
77
78
79
80
81
82
83 //Now, if all is OK, adjust the instance field in course_modules !!
84
85 //Now if all is OK, update course modinfo field !!
86
87 //End the main ul
88 echo "</ul>";
89
90
91 //End the main table
92 echo "</tr></td>";
93 echo "</table>";
94
95 if (!$status) {
96 error ("An error has ocurred");
97 }
98
99?>