Incorrect variable name used for parameter.
[moodle-linuxchix.git] / backup / restore_form.html
blobc12920a1d20a708ea1b9490c33d04e61dba4bf30
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_metacourse)) {
71 $restore_metacourse = 1;
74 if (!isset($restore_users)) {
75 $restore_users = 1;
78 if (!isset($restore_logs)) {
79 $restore_logs = 1;
82 if (!isset($restore_user_files)) {
83 $restore_user_files = 1;
86 if (!isset($restore_course_files)) {
87 $restore_course_files = 1;
90 if (!isset($restore_messages)) {
91 $restore_messages = 1;
94 if (!isset($restore_restoreto)) {
95 if (isteacheredit($id) and !isadmin()) {
96 $restore_restoreto = 1;
98 if (isadmin()) {
99 $restore_restoreto = 2;
103 if ($count == 0) {
104 notice("No restorable modules are installed!");
109 <script language="JavaScript" type="text/javascript">
110 <!--
111 function selectItemInMenuByName(formId, menuName, selectIndex ) {
112 myForm = document.getElementById(formId)
113 for (i=0,n=myForm.elements.length;i<n;i++) {
114 myLen = menuName.length;
115 myName = myForm.elements[i].name;
116 myType = myForm.elements[i].type;
117 if (myName.substring(0,myLen) == menuName && myType == "select-one")
118 myForm.elements[i].options[selectIndex].selected = true;
122 </script>
124 <form name="form1" id="form1" method="post" action="restore.php">
125 <table cellpadding="5">
126 <?php
128 //First, course destination
129 //Print the full tr
130 echo "<tr>";
131 echo "<td align=\"right\"><b>";
132 echo get_string("restoreto").":</b>";
133 echo "</td><td>";
134 if (isteacheredit($id) and !iscreator()) {
135 $restore_restoreto_options[0] = get_string("currentcoursedeleting");
136 $restore_restoreto_options[1] = get_string("currentcourseadding");
138 if (iscreator()) {
139 $restore_restoreto_options[0] = get_string("existingcoursedeleting");
140 $restore_restoreto_options[1] = get_string("existingcourseadding");
141 $restore_restoreto_options[2] = get_string("newcourse");
143 choose_from_menu($restore_restoreto_options, "restore_restoreto", $restore_restoreto, "");
144 echo "</td></tr>";
145 //Line
146 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
147 //Now, check modules and info and show posibilities
148 if ($allmods = get_records("modules") ) {
149 //Print option to select/deselect every "with user info" popup. For Gustav, lol, Eloy :-)
150 echo "<tr>";
151 echo "<td colspan=\"2\" align=\"right\"><font size=\"-1\">";
152 echo get_string("userdata").":";
153 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInMenuByName('form1', 'restore_user_info_', '1');\">".
154 get_string("all")."</a>/";
155 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInMenuByName('form1', 'restore_user_info_', '0');\">".
156 get_string("none")."</a>";
157 echo "</font></td>";
158 echo "</tr>";
159 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
160 foreach ($allmods as $mod) {
161 $modname = $mod->name;
162 $modrestore = $modname."_restore_mods";
163 //If exists the lib & function
164 $exist = "exists_".$modname;
165 $restore_var = "restore_".$modname;
166 $user_info_var = "restore_user_info_".$modname;
167 if (isset($$exist)) {
168 if ($$exist) {
169 //Now check that we have that module info in the backup file
170 if (isset($info->mods[$modname]) && $info->mods[$modname]->backup == "true") {
171 //Print the full tr
172 echo "<tr>";
173 echo "<td align=\"right\"><b>";
174 echo get_string("include")." ". get_string("modulenameplural",$modname).":";
175 echo "</b></td><td>";
176 $restore_options[0] = get_string("no");
177 $restore_options[1] = get_string("yes");
178 choose_from_menu($restore_options, $restore_var, $$restore_var, "");
179 //If backup contains user data, then show menu, else fix it to
180 //without user data
181 if ($info->mods[$modname]->userinfo == "true") {
182 $restore_user_options[0] = get_string("withoutuserdata");
183 $restore_user_options[1] = get_string("withuserdata");
184 choose_from_menu($restore_user_options, $user_info_var, $$user_info_var, "");
185 } else {
186 //Module haven't userdata
187 echo get_string("withoutuserdata");
188 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\" />";
190 echo "</td></tr>";
191 } else {
192 //Module isn't restorable
193 echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\" />";
194 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\" />";
196 } else {
197 //Module isn't restorable
198 echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\" />";
199 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\" />";
201 } else {
202 //Module isn't restorable
203 echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\" />";
204 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\" />";
207 //Line
208 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
210 //Now print the Metacourse tr
211 echo "<tr>";
212 echo "<td align=\"right\"><b>";
213 echo get_string("metacourse").":";
214 echo "</b></td><td>";
215 //If metacourse are in the backup file, show menu, else fixed to no
216 if ($info->backup_metacourse == "true") {
217 $metacourse_options[0] = get_string("no");
218 $metacourse_options[1] = get_string("yes");
219 choose_from_menu($metacourse_options, "restore_metacourse", $restore_metacourse, "");
220 } else {
221 echo get_string("no");
222 echo "<input type=\"hidden\" name=\"restore_metacourse\" value=\"0\" />";
224 echo "</td></tr>";
225 //Now print the Users tr
226 echo "<tr>";
227 echo "<td align=\"right\"><b>";
228 echo get_string("users").":";
229 echo "</b></td><td>";
230 //If some user is present in the backup file
231 if ($info->backup_users == "all" or $info->backup_users == "course") {
232 //If all users are in the backup file
233 if ($info->backup_users == "all") {
234 $user_options[0] = get_string("all");
236 $user_options[1] = get_string("course");
237 $user_options[2] = get_string("none");
238 choose_from_menu($user_options, "restore_users", $restore_users, "");
239 } else {
240 echo get_string("none");
241 echo "<input type=\"hidden\" name=\"restore_users\" value=\"2\" />";
244 echo "</td></tr>";
246 //Now print the Logs tr
247 echo "<tr>";
248 echo "<td align=\"right\"><b>";
249 echo get_string("logs").":";
250 echo "</b></td><td>";
251 //If logs are in the backup file, show menu, else fixed to no
252 if ($info->backup_logs == "true") {
253 $log_options[0] = get_string("no");
254 $log_options[1] = get_string("yes");
255 choose_from_menu($log_options, "restore_logs", $restore_logs, "");
256 } else {
257 echo get_string("no");
258 echo "<input type=\"hidden\" name=\"restore_logs\" value=\"0\" />";
260 echo "</td></tr>";
262 //Now print the User Files tr
263 echo "<tr>";
264 echo "<td align=\"right\"><b>";
265 echo get_string ("userfiles").":";
266 echo "</b></td><td>";
267 //If user files are in the backup file, show menu, else fixed to no
268 if ($info->backup_user_files == "true") {
269 $user_file_options[0] = get_string("no");
270 $user_file_options[1] = get_string("yes");
271 choose_from_menu($user_file_options, "restore_user_files", $restore_user_files, "");
272 } else {
273 echo get_string("no");
274 echo "<input type=\"hidden\" name=\"restore_user_files\" value=\"0\" />";
276 echo "</td></tr>";
278 //Now print the Course Files tr
279 echo "<tr>";
280 echo "<td align=\"right\"><b>";
281 echo get_string ("coursefiles").":";
282 echo "</b></td><td>";
283 echo "<input type=\"hidden\" name=\"backup_unique_code\" value=\"$backup_unique_code\" />";
284 echo "<input type=\"hidden\" name=\"file\" value=\"$file\" />";
285 //If course files are in the backup file, show menu, else fixed to no
286 if ($info->backup_course_files == "true") {
287 $course_file_options[0] = get_string("no");
288 $course_file_options[1] = get_string("yes");
289 choose_from_menu($course_file_options, "restore_course_files", $restore_course_files, "");
290 } else {
291 echo get_string("no");
292 echo "<input type=\"hidden\" name=\"restore_course_files\" value=\"0\" />";
294 echo "</td></tr>";
296 //Now print the Messages tr
297 echo "<tr>";
298 echo "<td align=\"right\"><b>";
300 //This tr is slighty different. Everything becomes hidden if
301 //we haven't messages is the backup, to avoid confusions to users.
302 //If messages are in the backup file, show menu, else fixed to no and show nothing
303 if ($info->backup_messages == "true") {
304 echo get_string ('messages','message').":";
305 echo "</b></td><td>";
306 $message_options[0] = get_string("no");
307 $message_options[1] = get_string("yes");
308 choose_from_menu($message_options, "restore_messages", $restore_messages, "");
309 } else {
310 echo "&nbsp;</b></td><td>";
311 echo "<input type=\"hidden\" name=\"restore_messages\" value=\"0\" />";
313 echo "</td></tr>";
316 </table>
317 <br />
318 <center>
319 <input type="hidden" name="id" value="<?php p($id) ?>" />
320 <input type="hidden" name="launch" value="check" />
321 <input type="submit" value="<?php print_string("continue") ?>" />
322 <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
323 </center>
324 </form>