Add idnumber to list of course students
[moodle.git] / backup / restore_form.html
blobe89acc6f6ae0d81a75d2cbdf92c5dc6e4957d5b4
1 <?PHP //$Id$
2 //This page prints the restore form to select everything yo want
3 //to restore. Form is dinamically buid, depending of "info" object
4 //that contains the backup contents and depending of every mod
5 //capabilities.
7 //Get objects from session
8 $info = $SESSION->info;
9 $course_header = $SESSION->course_header;
11 //Check that we have all we need
12 //backup_unique_code
13 require_variable($backup_unique_code);
14 //file
15 require_variable($file);
16 //info
17 require_variable($info);
18 //course_header
19 require_variable($course_header);
21 //Check login
22 require_login();
24 //Check admin
25 if (!empty($id)) {
26 if (!isteacheredit($id)) {
27 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
29 } else {
30 if (!isadmin()) {
31 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
35 //Check site
36 if (!$site = get_site()) {
37 error("Site not found!");
40 //Checks for the required files/functions to restore every mod
41 $count = 0;
42 if ($allmods = get_records("modules") ) {
43 foreach ($allmods as $mod) {
44 $modname = $mod->name;
45 $modfile = "$CFG->dirroot/mod/$modname/restorelib.php";
46 $modrestore = $modname."_restore_mods";
47 if (file_exists($modfile)) {
48 include_once($modfile);
49 if (function_exists($modrestore)) {
50 $var = "exists_".$modname;
51 $$var = true;
52 $count++;
55 //Check data
56 //Check module info
57 $var = "restore_".$modname;
58 if (!isset($$var)) {
59 $$var = 1;
61 //Check include user info
62 $var = "restore_user_info_".$modname;
63 if (!isset($$var)) {
64 $$var = 1;
69 //Check other parameters
70 if (!isset($restore_users)) {
71 $restore_users = 1;
74 if (!isset($restore_logs)) {
75 $restore_logs = 1;
78 if (!isset($restore_user_files)) {
79 $restore_user_files = 1;
82 if (!isset($restore_course_files)) {
83 $restore_course_files = 1;
86 if (!isset($restore_restoreto)) {
87 if (isteacheredit($id) and !isadmin()) {
88 $restore_restoreto = 1;
90 if (isadmin()) {
91 $restore_restoreto = 2;
95 if ($count == 0) {
96 notice("No restorable modules are installed!");
101 <form name="form" method="post" action="<?php echo $ME ?>">
102 <table cellpadding=5>
103 <?php
105 //First, course destination
106 //Print the full tr
107 echo "<tr>";
108 echo "<td align=\"right\"><P><b>";
109 echo get_string("restoreto").":</b>";
110 echo "</td><td>";
111 if (isteacheredit($id) and !isadmin()) {
112 $restore_restoreto_options[0] = get_string("currentcoursedeleting");
113 $restore_restoreto_options[1] = get_string("currentcourseadding");
115 if (isadmin()) {
116 $restore_restoreto_options[0] = get_string("existingcoursedeleting");
117 $restore_restoreto_options[1] = get_string("existingcourseadding");
118 $restore_restoreto_options[2] = get_string("newcourse");
120 choose_from_menu($restore_restoreto_options, "restore_restoreto", $restore_restoreto, "");
121 echo "</td></tr>";
122 //Line
123 echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
124 //Now, check modules and info and show posibilities
125 if ($allmods = get_records("modules") ) {
126 foreach ($allmods as $mod) {
127 $modname = $mod->name;
128 $modrestore = $modname."_restore_mods";
129 //If exists the lib & function
130 $exist = "exists_".$modname;
131 $restore_var = "restore_".$modname;
132 $user_info_var = "restore_user_info_".$modname;
133 if (isset($$exist)) {
134 if ($$exist) {
135 //Now check that we have that module info in the backup file
136 if (isset($info->mods[$modname]) && $info->mods[$modname]->backup == "true") {
137 //Print the full tr
138 echo "<tr>";
139 echo "<td align=\"right\"><P><B>";
140 echo get_string("include")." ". get_string("modulenameplural",$modname).":";
141 echo "</td><td>";
142 $restore_options[0] = get_string("no");
143 $restore_options[1] = get_string("yes");
144 choose_from_menu($restore_options, $restore_var, $$restore_var, "");
145 //If backup contains user data, then show menu, else fix it to
146 //without user data
147 if ($info->mods[$modname]->userinfo == "true") {
148 $restore_user_options[0] = get_string("withoutuserdata");
149 $restore_user_options[1] = get_string("withuserdata");
150 choose_from_menu($restore_user_options, $user_info_var, $$user_info_var, "");
151 } else {
152 //Module haven't userdata
153 echo get_string("withoutuserdata");
154 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\">";
156 echo "</td></tr>";
157 } else {
158 //Module isn't restorable
159 echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\">";
160 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\">";
162 } else {
163 //Module isn't restorable
164 echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\">";
165 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\">";
167 } else {
168 //Module isn't restorable
169 echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\">";
170 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\">";
173 //Line
174 echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
176 //Now print the Users tr
177 echo "<tr>";
178 echo "<td align=\"right\"><P><B>";
179 echo get_string("users").":";
180 echo "</td><td>";
181 //If all users are in the backup file
182 if ($info->backup_users == "all") {
183 $user_options[0] = get_string("all");
185 $user_options[1] = get_string("course");
186 $user_options[2] = get_string("none");
187 //$user_options[2] = get_string("needed");-->NOT IMPLEMENTED
188 choose_from_menu($user_options, "restore_users", $restore_users, "");
189 echo "</td></tr>";
191 //Now print the Logs tr
192 echo "<tr>";
193 echo "<td align=\"right\"><P><B>";
194 echo get_string("logs").":";
195 echo "</td><td>";
196 //If logs are in the backup file, show menu, else fixed to no
197 if ($info->backup_logs == "true") {
198 $log_options[0] = get_string("no");
199 $log_options[1] = get_string("yes");
200 choose_from_menu($log_options, "restore_logs", $restore_logs, "");
201 } else {
202 echo get_string("no");
203 echo "<input type=\"hidden\" name=\"restore_logs\" value=\"0\">";
205 echo "</td></tr>";
207 //Now print the User Files tr
208 echo "<tr>";
209 echo "<td align=\"right\"><P><B>";
210 echo get_string ("userfiles").":";
211 echo "</td><td>";
212 //If user files are in the backup file, show menu, else fixed to no
213 if ($info->backup_user_files == "true") {
214 $user_file_options[0] = get_string("no");
215 $user_file_options[1] = get_string("yes");
216 choose_from_menu($user_file_options, "restore_user_files", $restore_user_files, "");
217 } else {
218 echo get_string("no");
219 echo "<input type=\"hidden\" name=\"restore_user_files\" value=\"0\">";
221 echo "</td></tr>";
223 //Now print the Course Files tr
224 echo "<tr>";
225 echo "<td align=\"right\"><P><B>";
226 echo get_string ("coursefiles").":";
227 echo "</td><td>";
228 //If course files are in the backup file, show menu, else fixed to no
229 if ($info->backup_course_files == "true") {
230 $course_file_options[0] = get_string("no");
231 $course_file_options[1] = get_string("yes");
232 choose_from_menu($course_file_options, "restore_course_files", $restore_course_files, "");
233 } else {
234 echo get_string("no");
235 echo "<input type=\"hidden\" name=\"restore_course_files\" value=\"0\">";
237 echo "</td></tr>";
238 echo "<input type=\"hidden\" name=\"backup_unique_code\" value=\"$backup_unique_code\">";
239 echo "<input type=\"hidden\" name=\"file\" value=\"$file\">";
242 </table>
243 <BR>
244 <CENTER>
245 <input type="hidden" name=id value="<?php p($id) ?>">
246 <input type="hidden" name=launch value="check">
247 <input type="submit" value="<?php print_string("continue") ?>">
248 <input type="submit" name=cancel value="<?php print_string("cancel") ?>">
249 </CENTER>
250 </FORM>