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
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)) {
23 //Check required objects from session
26 require_variable($info);
29 require_variable($course_header);
31 //If the restore object doesn't exist, we are going
32 //to check every variable individually and create it
34 if (!isset($restore)) {
35 //Check that we have all we need
37 require_variable($backup_unique_code);
39 require_variable($file);
40 //Checks for the required restoremod parameters
41 if ($allmods = get_records(
"modules")) {
42 foreach ($allmods as $mod) {
43 $modname = $mod-
>name;
44 $var =
"restore_".$modname;
45 require_variable($$var);
46 $var =
"restore_user_info_".$modname;
47 require_variable($$var);
51 require_variable($restore_restoreto);
53 require_variable($restore_users);
55 require_variable($restore_logs);
57 require_variable($restore_user_files);
58 //restore_course_files
59 require_variable($restore_course_files);
60 //restore_course_files
61 require_variable($restore_course_files);
63 //Check we've selected a course
64 if (!isset($course_id)) {
68 //We are here, having all we need !!
69 //Create the restore object and put it in the session
70 $restore-
>backup_unique_code = $backup_unique_code;
71 $restore-
>file = $file;
72 if ($allmods = get_records(
"modules")) {
73 foreach ($allmods as $mod) {
74 $modname = $mod-
>name;
75 $var =
"restore_".$modname;
76 $restore-
>mods[$modname]-
>restore=$$var;
77 $var =
"restore_user_info_".$modname;
78 $restore-
>mods[$modname]-
>userinfo=$$var;
81 $restore-
>restoreto=$restore_restoreto;
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-
>course_id=$course_id;
88 //We have the object, so check if we have a new course_id
89 //passed as parammeter
91 $restore-
>course_id=$course_id;
94 //We have the object with data, put it in the session
95 $SESSION-
>restore = $restore;
97 //From here to the wnd of the script, only use the $restore object
104 if (!isteacheredit($id)) {
105 error(
"You need to be a teacher or admin user to use this page.",
"$CFG->wwwroot/login/index.php");
109 error(
"You need to be an admin user to use this page.",
"$CFG->wwwroot/login/index.php");
114 if (!$site = get_site()) {
115 error(
"Site not found!");
118 //Depending the selected restoreto:
119 // If user is a teacher (and nor admin):
120 //
0-Current course, deleting: Put $restore-
>course_id and $restore-
>deleting (true), create the restore object
121 //
1-Current course, adding: Put $restore-
>course_id and $restore-
>deleting (false), create the restore object
122 // If the uses is an admin:
123 //
0-Existing course, deleting: Select the destination course and launch the check again, then
124 // put $restore-
>course_id and $restore-
>deleting (true), create the restore object.
125 //
1-Existing course, adding: Select the destination course and launch the check again, then
126 // put $restore-
>course_id and $restore-
>deleting (false), create the restore object.
127 //
2-New course: Create the restore object and launch the execute.
129 //If the user is a teacher and not an admin
130 if (isteacher($id) and !isadmin()) {
131 $restore-
>course_id = $id;
132 if ($restore-
>restoreto ==
0) {
133 $restore-
>deleting = true;
135 $restore-
>deleting = false;
139 //If the user is an admin
141 //Set restore-
>deleting as needed
142 if ($restore-
>restoreto ==
0) {
143 $restore-
>deleting = true;
145 $restore-
>deleting = false;
149 //Now, select the course if needed
150 if (($restore-
>restoreto ==
0 or $restore-
>restoreto ==
1) and ($restore-
>course_id ==
0) and (isadmin())) {
151 if ($courses = get_courses()) {
152 print_heading(get_string(
"choosecourse"));
153 print_simple_box_start(
"CENTER");
154 foreach ($courses as $course) {
155 echo
"<A HREF=\"restore.php?course_id=$course-
>id&launch=check&id=$id&file=$file\
">$course->fullname ($course->shortname)</A><BR>";
157 print_simple_box_end();
159 print_heading(get_string(
"nocoursesyet"));
160 print_continue(
"$CFG->wwwroot/$CFG->admin/index.php");
162 //Checks everything and execute restore
163 } else if ((($restore-
>restoreto ==
0 or $restore-
>restoreto ==
1) and ($restore-
>course_id !=
0)) or ($restore-
>restoreto ==
2)) {
164 $show_continue_button = true;
165 //Check if we've selected any mod's user info and restore-
>users
166 //is set to none. Change it to course and inform.
167 if ($restore-
>users ==
2) {
169 $mods = $restore-
>mods;
170 foreach ($mods as $mod) {
171 if ($mod-
>userinfo) {
176 echo get_string (
"noteuserschangednonetocourse");
177 echo
"<hr noshade size=\"1\
">";
181 //Save the restore session object
182 $SESSION-
>restore = $restore;
183 if ($show_continue_button) {
184 //Print the continue button to execute the restore NOW !!!!
185 //All is prepared !!!
187 $hidden[
"launch"] =
"execute";
188 $hidden[
"file"] = $file;
190 print_single_button(
"restore.php", $hidden, get_string(
"restorecoursenow"),
"post");
194 error (
"Something was wrong checking restore preferences");
197 //If we are here. Something must be wrong. Debug !!!
199 print_object($restore);
201 print_object($course_header);
202 error (
"Something must be wrong");