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
7 //Get objects from session
8 $info = $SESSION->info
;
9 $course_header = $SESSION->course_header
;
11 //Check that we have all we need
13 require_variable($backup_unique_code);
15 require_variable($file);
17 require_variable($info);
19 require_variable($course_header);
26 if (!isteacheredit($id)) {
27 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
31 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
36 if (!$site = get_site()) {
37 error("Site not found!");
40 //Checks for the required files/functions to restore every mod
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;
57 $var = "restore_".$modname;
61 //Check include user info
62 $var = "restore_user_info_".$modname;
69 //Check other parameters
70 if (!isset($restore_metacourse)) {
71 $restore_metacourse = 1;
74 if (!isset($restore_users)) {
78 if (!isset($restore_logs)) {
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;
99 $restore_restoreto = 2;
104 notice("No restorable modules are installed!");
109 <script language=
"JavaScript" type=
"text/javascript">
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;
124 <form name=
"form1" id=
"form1" method=
"post" action=
"restore.php">
125 <table cellpadding=
"5">
128 //First, course destination
131 echo "<td align=\"right\"><b>";
132 echo get_string("restoreto").":</b>";
134 if (isteacheredit($id) and !iscreator()) {
135 $restore_restoreto_options[0] = get_string("currentcoursedeleting");
136 $restore_restoreto_options[1] = get_string("currentcourseadding");
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, "");
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 :-)
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>";
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)) {
169 //Now check that we have that module info in the backup file
170 if (isset($info->mods
[$modname]) && $info->mods
[$modname]->backup
== "true") {
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
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, "");
186 //Module haven't userdata
187 echo get_string("withoutuserdata");
188 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\" />";
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\" />";
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\" />";
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\" />";
208 echo "<tr><td colspan=\"2\"><hr /></td></tr>";
210 //Now print the Metacourse 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, "");
221 echo get_string("no");
222 echo "<input type=\"hidden\" name=\"restore_metacourse\" value=\"0\" />";
225 //Now print the Users 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, "");
240 echo get_string("none");
241 echo "<input type=\"hidden\" name=\"restore_users\" value=\"2\" />";
246 //Now print the Logs 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, "");
257 echo get_string("no");
258 echo "<input type=\"hidden\" name=\"restore_logs\" value=\"0\" />";
262 //Now print the User Files 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, "");
273 echo get_string("no");
274 echo "<input type=\"hidden\" name=\"restore_user_files\" value=\"0\" />";
278 //Now print the Course Files 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, "");
291 echo get_string("no");
292 echo "<input type=\"hidden\" name=\"restore_course_files\" value=\"0\" />";
296 //Now print the Messages 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, "");
310 echo " </b></td><td>";
311 echo "<input type=\"hidden\" name=\"restore_messages\" value=\"0\" />";
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
") ?>" />