Polished.
[moodle.git] / backup / restore_form.html
blobf11c26fa123a0957257ace12c8b87526d94012a5
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 (!isadmin()) {
26 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
29 //Check site
30 if (!$site = get_site()) {
31 error("Site not found!");
34 //Checks for the required files/functions to restore every mod
35 $count = 0;
36 if ($allmods = get_records("modules") ) {
37 foreach ($allmods as $mod) {
38 $modname = $mod->name;
39 $modfile = "$mods_home/$modname/restorelib.php";
40 $modrestore = $modname."_restore_mods";
41 if (file_exists($modfile)) {
42 include_once($modfile);
43 if (function_exists($modrestore)) {
44 $var = "exists_".$modname;
45 $$var = true;
46 $count++;
49 //Check data
50 //Check module info
51 $var = "restore_".$modname;
52 if (!isset($$var)) {
53 $$var = 1;
55 //Check include user info
56 $var = "restore_user_info_".$modname;
57 if (!isset($$var)) {
58 $$var = 1;
63 //Check other parameters
64 if (!isset($restore_users)) {
65 $restore_users = 1;
68 if (!isset($restore_logs)) {
69 $restore_logs = 1;
72 if (!isset($restore_user_files)) {
73 $restore_user_files = 1;
76 if (!isset($restore_course_files)) {
77 $restore_course_files = 1;
80 if (!isset($restore_restoreto)) {
81 $restore_restoreto = 1;
84 if ($count == 0) {
85 notice("No restorable modules are installed!");
90 <form name="form" method="post" <?=$onsubmit ?> action="<?=$ME ?>">
91 <table cellpadding=5>
94 //First, course destination
95 //Print the full tr
96 echo "<tr>";
97 echo "<td align=\"right\"><P><b>";
98 echo get_string("restoreto").":</b>";
99 echo "</td><td>";
100 $restore_restoreto_options[0] = get_string("existingcourse");
101 $restore_restoreto_options[1] = get_string("newcourse");
102 choose_from_menu($restore_restoreto_options, "restore_restoreto", $restore_restoreto, "");
103 echo "</td></tr>";
104 //Line
105 echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
106 //Now, check modules and info and show posibilities
107 if ($allmods = get_records("modules") ) {
108 foreach ($allmods as $mod) {
109 $modname = $mod->name;
110 $modrestore = $modname."_restore_mods";
111 //If exists the lib & function
112 $exist = "exists_".$modname;
113 $restore_var = "restore_".$modname;
114 $user_info_var = "restore_user_info_".$modname;
115 if ($$exist) {
116 //Now check that we have that module info in the backup file
117 if ($info->mods[$modname]->backup == "true") {
118 //Print the full tr
119 echo "<tr>";
120 echo "<td align=\"right\"><P><B>";
121 echo get_string("include")." ". get_string("modulenameplural",$modname).":";
122 echo "</td><td>";
123 $restore_options[0] = get_string("no");
124 $restore_options[1] = get_string("yes");
125 choose_from_menu($restore_options, $restore_var, $$restore_var, "");
126 //If backup contains user data, then show menu, else fix it to
127 //without user data
128 if ($info->mods[$modname]->userinfo == "true") {
129 $restore_user_options[0] = get_string("withoutuserdata");
130 $restore_user_options[1] = get_string("withuserdata");
131 choose_from_menu($restore_user_options, $user_info_var, $$user_info_var, "");
132 } else {
133 //Module haven't userdata
134 echo get_string("withoutuserdata");
135 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\">";
137 echo "</td></tr>";
138 } else {
139 //Module isn't restorable
140 echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\">";
141 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\">";
143 } else {
144 //Module isn't restorable
145 echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\">";
146 echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\">";
149 //Line
150 echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
152 //Now print the Users tr
153 echo "<tr>";
154 echo "<td align=\"right\"><P><B>";
155 echo get_string("users").":";
156 echo "</td><td>";
157 //If all users are in the backup file
158 if ($info->backup_users == "all") {
159 $user_options[0] = get_string("all");
161 $user_options[1] = get_string("course");
162 $user_options[2] = get_string("none");
163 //$user_options[2] = get_string("needed");-->NOT IMPLEMENTED
164 choose_from_menu($user_options, "restore_users", $restore_users, "");
165 echo "</td></tr>";
167 //Now print the Logs tr
168 echo "<tr>";
169 echo "<td align=\"right\"><P><B>";
170 echo get_string("logs").":";
171 echo "</td><td>";
172 //If logs are in the backup file, show menu, else fixed to no
173 if ($info->backup_logs == "true") {
174 $log_options[0] = get_string("no");
175 $log_options[1] = get_string("yes");
176 choose_from_menu($log_options, "restore_logs", $restore_logs, "");
177 } else {
178 echo get_string("no");
179 echo "<input type=\"hidden\" name=\"restore_logs\" value=\"0\">";
181 echo "</td></tr>";
183 //Now print the User Files tr
184 echo "<tr>";
185 echo "<td align=\"right\"><P><B>";
186 echo get_string ("userfiles").":";
187 echo "</td><td>";
188 //If user files are in the backup file, show menu, else fixed to no
189 if ($info->backup_user_files == "true") {
190 $user_file_options[0] = get_string("no");
191 $user_file_options[1] = get_string("yes");
192 choose_from_menu($user_file_options, "restore_user_files", $restore_user_files, "");
193 } else {
194 echo get_string("no");
195 echo "<input type=\"hidden\" name=\"restore_user_files\" value=\"0\">";
197 echo "</td></tr>";
199 //Now print the Course Files tr
200 echo "<tr>";
201 echo "<td align=\"right\"><P><B>";
202 echo get_string ("coursefiles").":";
203 echo "</td><td>";
204 //If course files are in the backup file, show menu, else fixed to no
205 if ($info->backup_course_files == "true") {
206 $course_file_options[0] = get_string("no");
207 $course_file_options[1] = get_string("yes");
208 choose_from_menu($course_file_options, "restore_course_files", $restore_course_files, "");
209 } else {
210 echo get_string("no");
211 echo "<input type=\"hidden\" name=\"restore_course_files\" value=\"0\">";
213 echo "</td></tr>";
214 echo "<input type=\"hidden\" name=\"backup_unique_code\" value=\"$backup_unique_code\">";
215 echo "<input type=\"hidden\" name=\"file\" value=\"$file\">";
218 </table>
219 <BR>
220 <CENTER>
221 <input type="hidden" name=id value="<? p($id) ?>">
222 <input type="hidden" name=launch value="check">
223 <input type="submit" value="<? print_string("continue") ?>">
224 <input type="submit" name=cancel value="<? print_string("cancel") ?>">
225 </CENTER>
226 </FORM>