Add idnumber to list of course students
[moodle.git] / backup / restore_check.html
blob3606e59a93b28ec37c878d7284ee454cab286c58
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 required objects from session
25 //info
26 require_variable($info);
28 //course_header
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
36 //backup_unique_code
37 require_variable($backup_unique_code);
38 //file
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);
50 //restoreto
51 require_variable($restore_restoreto);
52 //restore_users
53 require_variable($restore_users);
54 //restore_logs
55 require_variable($restore_logs);
56 //restore_user_files
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)) {
65 $course_id = 0;
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;
87 } else {
88 //We have the object, so check if we have a new course_id
89 //passed as parammeter
90 if ($course_id) {
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
99 //Check login
100 require_login();
102 //Check admin
103 if (!empty($id)) {
104 if (!isteacheredit($id)) {
105 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
107 } else {
108 if (!isadmin()) {
109 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
113 //Check site
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;
134 } else {
135 $restore->deleting = false;
139 //If the user is an admin
140 if (isadmin()) {
141 //Set restore->deleting as needed
142 if ($restore->restoreto == 0) {
143 $restore->deleting = true;
144 } else {
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("all","c.fullname")) {
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();
158 } else {
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) {
168 $changed = false;
169 $mods = $restore->mods;
170 foreach ($mods as $mod) {
171 if ($mod->userinfo) {
172 $changed = true;
175 if ($changed) {
176 echo get_string ("noteuserschangednonetocourse");
177 echo "<hr noshade size=\"1\">";
178 $restore->users = 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 !!!
186 echo "<CENTER>";
187 $hidden["launch"] = "execute";
188 $hidden["file"] = $file;
189 $hidden["id"] = $id;
190 print_single_button("restore.php", $hidden, get_string("restorecoursenow"),"post");
191 echo "</CENTER>";
192 } else {
193 //Show error
194 error ("Something was wrong checking restore preferences");
197 //If we are here. Something must be wrong. Debug !!!
198 } else {
199 print_object($restore);
200 print_object($info);
201 print_object($course_header);
202 error ("Something must be wrong");