file courseidnumber.html was added on branch MOODLE_15_STABLE on 2005-07-07 17:12...
[moodle.git] / backup / restore_check.html
blob50d5160ed9368448ec3f55228f0555c86f99c739
1 <?php //$Id$
2 //This page receive all the restore_form data. Then, if existing course
3 //has been selected, shows a list of courses to select one.
4 //It cheks that the parammeter from restore_form are coherent.
5 //It puts all the restore info in the session.
6 //Finally, it calls restore_execute to do the hard work
8 //Get objects from session
9 if ($SESSION) {
10 $info = $SESSION->info;
11 $course_header = $SESSION->course_header;
12 if (isset($SESSION->restore)) {
13 $restore = $SESSION->restore;
17 //If restore session info exists, but we are posting parameters
18 //manually, this has prioriry
19 if (isset($restore) and isset($restore_restoreto)) {
20 unset($restore);
23 // check for session objects
24 if (empty($info) or empty($course_header)) {
25 error( 'important information missing from SESSION' );
28 //If the restore object doesn't exist, we are going
29 //to check every variable individually and create it
31 if (!isset($restore)) {
32 //Check that we have all we need
33 //backup_unique_code
34 $backup_unique_code = required_param( 'backup_unique_code' );
35 //file
36 $file = required_param( 'file');
37 //Checks for the required restoremod parameters
38 if ($allmods = get_records("modules")) {
39 foreach ($allmods as $mod) {
40 $modname = $mod->name;
41 $var = "restore_".$modname;
42 $$var = required_param( $var);
43 $var = "restore_user_info_".$modname;
44 $$var = required_param( $var);
47 //restoreto
48 $restore_restoreto = required_param('restore_restoreto');
49 //restore_metacourse
50 $restore_metacourse = required_param('restore_metacourse');
51 //restore_users
52 $restore_users = required_param('restore_users');
53 //restore_logs
54 $restore_logs = required_param('restore_logs');
55 //restore_user_files
56 $restore_user_files = required_param('restore_user_files');
57 //restore_course_files
58 $restore_course_files = required_param('restore_course_files');
59 //restore_messages
60 $restore_messages = required_param('restore_messages');
62 //Check we've selected a course
63 if (!isset($course_id)) {
64 $course_id = 0;
67 //We are here, having all we need !!
68 //Create the restore object and put it in the session
69 $restore->backup_unique_code = $backup_unique_code;
70 $restore->file = $file;
71 if ($allmods = get_records("modules")) {
72 foreach ($allmods as $mod) {
73 $modname = $mod->name;
74 $var = "restore_".$modname;
75 $restore->mods[$modname]->restore=$$var;
76 $var = "restore_user_info_".$modname;
77 $restore->mods[$modname]->userinfo=$$var;
80 $restore->restoreto=$restore_restoreto;
81 $restore->metacourse=$restore_metacourse;
82 $restore->users=$restore_users;
83 $restore->logs=$restore_logs;
84 $restore->user_files=$restore_user_files;
85 $restore->course_files=$restore_course_files;
86 $restore->messages=$restore_messages;
87 $restore->course_id=$course_id;
88 } else {
89 //We have the object, so check if we have a new course_id
90 //passed as parammeter
91 if ($course_id) {
92 $restore->course_id=$course_id;
95 //We have the object with data, put it in the session
96 $SESSION->restore = $restore;
98 //From here to the end of the script, only use the $restore object
100 //Check login
101 require_login();
103 //Check admin
104 if (!empty($id)) {
105 if (!isteacheredit($id)) {
106 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
108 } else {
109 if (!isadmin()) {
110 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
114 //Check site
115 if (!$site = get_site()) {
116 error("Site not found!");
119 //Depending the selected restoreto:
120 // If user is a teacher (and not creator):
121 // 0-Current course, deleting: Put $restore->course_id and $restore->deleting (true), create the restore object
122 // 1-Current course, adding: Put $restore->course_id and $restore->deleting (false), create the restore object
123 // If the uses is a creator:
124 // 0-Existing course, deleting: Select the destination course and launch the check again, then
125 // put $restore->course_id and $restore->deleting (true), create the restore object.
126 // 1-Existing course, adding: Select the destination course and launch the check again, then
127 // put $restore->course_id and $restore->deleting (false), create the restore object.
128 // 2-New course: Create the restore object and launch the execute.
130 //If the user is a teacher and not a creator
131 if (isteacheredit($id) and !iscreator()) {
132 $restore->course_id = $id;
133 if ($restore->restoreto == 0) {
134 $restore->deleting = true;
135 } else {
136 $restore->deleting = false;
140 //If the user is a creator (or admin)
141 if (iscreator()) {
142 //Set restore->deleting as needed
143 if ($restore->restoreto == 0) {
144 $restore->deleting = true;
145 } else {
146 $restore->deleting = false;
150 //Now, select the course if needed
151 if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) and (iscreator())) {
152 if ($courses = get_courses("all","c.fullname","c.id,c.fullname,c.shortname")) {
153 print_heading(get_string("choosecourse"));
154 print_simple_box_start("center");
155 foreach ($courses as $course) {
156 echo "<a href=\"restore.php?course_id=$course->id&launch=check&id=$id&file=$file\">$course->fullname ($course->shortname)</a><br />";
158 print_simple_box_end();
159 } else {
160 print_heading(get_string("nocoursesyet"));
161 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
163 //Checks everything and execute restore
164 } else if ((($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id != 0)) or ($restore->restoreto == 2)) {
165 $show_continue_button = true;
166 //Check if we've selected any mod's user info and restore->users
167 //is set to none. Change it to course and inform.
168 if ($restore->users == 2) {
169 $changed = false;
170 $mods = $restore->mods;
171 foreach ($mods as $mod) {
172 if ($mod->userinfo) {
173 $changed = true;
176 //If we have selected user files or messages, then users must be restored too
177 if ($restore->user_files || $restore->messages) {
178 $changed = 1;
180 if ($changed) {
181 echo get_string ("noteuserschangednonetocourse");
182 echo "<hr noshade size=\"1\">";
183 $restore->users = 1;
186 //Save the restore session object
187 $SESSION->restore = $restore;
188 if ($show_continue_button) {
189 //Print the continue button to execute the restore NOW !!!!
190 //All is prepared !!!
191 echo "<center>";
192 $hidden["launch"] = "execute";
193 $hidden["file"] = $file;
194 $hidden["id"] = $id;
195 print_single_button("restore.php", $hidden, get_string("restorecoursenow"),"post");
196 echo "</center>";
197 } else {
198 //Show error
199 error ("Something was wrong checking restore preferences");
202 //If we are here. Something must be wrong. Debug !!!
203 } else {
204 print_object($restore);
205 print_object($info);
206 print_object($course_header);
207 error ("Something must be wrong");