MDL-15942 - separate data escaped for database entry from unescaped data
[moodle-linuxchix.git] / backup / backup_form.html
blobcd2bfc3eee74f31ef3d4e4761e18c98cd1f3b116
1 <?php //$Id$
2 //This page prints the backup form to select everything
4 //Check login
5 require_login();
7 if (!empty($course->id)) {
8 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
9 if (empty($to)) {
10 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
11 } else {
12 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
13 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
17 } else {
18 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
19 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
23 //Check site
24 if (!$site = get_site()) {
25 error("Site not found!");
28 //Checks for the required files/functions to backup every mod
29 //And check if there is data about it
30 $count = 0;
31 if ($allmods = get_records('modules', 'visible', 1) ) {
32 foreach ($allmods as $mod) {
33 $modname = $mod->name;
34 $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
35 $modbackup = $modname."_backup_mods";
36 $modbackupone = $modname.'_backup_one_mod';
37 $modcheckbackup = $modname."_check_backup_mods";
38 if (file_exists($modfile)) {
39 include_once($modfile);
40 if (function_exists($modbackup) and function_exists($modcheckbackup)) {
41 $var = "exists_".$modname;
42 $$var = true;
43 $count++;
44 // check that there are instances and we can back them up individually
45 if (count_records('course_modules','course',$course->id,'module',$mod->id) && function_exists($modbackupone)) {
46 $var = 'exists_one_'.$modname;
47 $$var = true;
51 //Check data
52 //Check module info
53 $var = "backup_".$modname;
54 $$var = optional_param( $var,1);
55 //Check include user info
56 $var = "backup_user_info_".$modname;
57 $$var = optional_param( $var,1);
61 //Check other parameters
62 $backup_metacourse = optional_param('backup_metacourse',1);
63 $backup_users = optional_param('backup_users',1);
64 $backup_logs = optional_param('backup_logs',0);
65 $backup_user_files = optional_param('backup_user_files',1);
66 $backup_course_files = optional_param('backup_course_files',1);
67 $backup_site_files = optional_param('backup_site_files',1);
68 $backup_gradebook_history = optional_param('backup_gradebook_history', 0, PARAM_INT);
69 $backup_messages = optional_param('backup_messages',1);
70 $backup_blogs = optional_param('backup_blogs',1);
72 if ($count == 0) {
73 notice("No backupable modules are installed!");
78 <script type="text/javascript">
79 <!--
80 function selectItemInMenuByName(formId, menuName, selectIndex ) {
81 myForm = document.getElementById(formId)
82 for (i=0,n=myForm.elements.length;i<n;i++) {
83 myLen = menuName.length;
84 myName = myForm.elements[i].name;
85 myType = myForm.elements[i].type;
86 if (myName.substring(0,myLen) == menuName && myType == "select-one") {
87 myForm.elements[i].options[selectIndex].selected = true;
92 function selectItemInRadioByName(formId, radioName, selectIndex ) {
93 myForm = document.getElementById(formId)
94 for (i=0,n=myForm.elements.length;i<n;i++) {
95 myLen = radioName.length;
96 myName = myForm.elements[i].name;
97 myType = myForm.elements[i].type;
98 if (myName.substring(0,myLen) == radioName && myType == "radio") {
99 myRadioGroup = myForm.elements[myName];
100 myRadioGroup[selectIndex].checked = true;
105 function selectItemInCheckboxByName(formId, checkName, checked ) {
106 myForm = document.getElementById(formId);
107 for (i=0,n=myForm.elements.length;i<n;i++) {
108 myLen = checkName.length;
109 myName = myForm.elements[i].name;
110 myType = myForm.elements[i].type;
111 if (myName.substring(0,myLen) == checkName && myType == "checkbox") {
112 myForm.elements[i].checked = checked;
117 </script>
118 <form id="form1" method="post" action="backup.php">
119 <table cellpadding="5" style="margin-left:auto;margin-right:auto;">
120 <?php
121 /// Acummulator for hidden options and proper XHTML output
122 $hidden_options = '';
123 //Now, check modules and info and show posibilities
124 if ($allmods = get_records('modules', 'visible', 1) ) {
125 //Print option to select/deselect everything with 1 click.
126 echo "<tr>";
127 echo "<td align=\"right\">";
128 echo '<b>'.get_string("include")."</b>";
129 echo "</td><td>";
130 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', true);\">". get_string("all")."</a>/";
131 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', false);\">". get_string("none")."</a>";
132 echo "</td>";
133 echo "<td align=\"right\">";
134 echo '<b>&nbsp;</b>';
135 echo "</td><td>";
136 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', true);\">". get_string("all")."</a>/";
137 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', false);\">". get_string("none")."</a>";
138 echo "</td>";
139 echo "</tr>";
140 echo "<tr><td colspan=\"4\"><hr /></td></tr>";
141 $currentrow = 0;
142 foreach ($allmods as $mod) {
143 $modname = $mod->name;
144 $modbackup = $modname."_backup_mods";
145 //If exists the lib & function
146 $var = 'exists_'.$modname;
147 $exvar = 'exists_one_'.$modname;
148 if (!empty($$var) and !empty($$exvar)) {
149 //Print the full tr
150 echo "<tr class=\"r".$currentrow."\">";
151 echo " <td align=\"right\">&nbsp;";
152 echo "</td><td>\n";
153 $backup_options[0] = get_string("no");
154 $backup_options[1] = get_string("yes");
155 $var = "backup_".$modname;
156 //choose_from_menu($backup_options, $var, $$var, "");
157 //Print the checkbox
158 print_checkbox($var, $$var, $$var, get_string("modulenameplural",$modname),'','selectItemInCheckboxByName(\'form1\',\'backup_'.$modname.'\',this.checked)');
159 echo "</td><td align=\"right\">&nbsp;";
160 echo "</td><td>";
161 $var = "backup_user_info_".$modname;
162 if (empty($to)) {
163 $backup_user_options[0] = get_string("withoutuserdata");
164 $backup_user_options[1] = get_string("withuserdata");
165 //choose_from_menu($backup_user_options, $var, $$var, "");
166 print_checkbox($var, $$var, $$var, get_string("userdata"),'','selectItemInCheckboxByName(\'form1\',\'backup_user_info_'.$modname.'\',this.checked)');
167 } else {
168 echo '<input type="hidden" name="'.$var.'" value="0" />';
170 echo "</td></tr>\n";
171 echo '<tr><td></td><td colspan="3"><table class="backup-form-instances">';
172 $instances = get_all_instances_in_course($modname, $course, NULL, true);
173 $var = $exvar;
174 foreach ($instances as $instance) {
175 echo '<tr><td>';
176 $var = 'backup_'.$modname.'_instance_'.$instance->id;
177 $$var = optional_param($var,1);
178 print_checkbox($var,$$var,$$var,$instance->name,$instance->name,'this.form.elements[\'backup_'.$modname.'\'].checked=1;');
179 echo '</td><td align="right">&nbsp;';
180 $var = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
181 $$var = optional_param($var,1);
182 if (empty($to)) {
183 print_checkbox($var,$$var,$$var,get_string('userdata'),'','this.form.elements[\'backup_user_info_'.$modname.'\'].checked=1;');
184 } else {
185 echo '<input type="hidden" name="'.$var.'" value="0" />';
187 echo '</td></tr>';
189 echo '</table></td></tr>';
192 //Line
193 echo "<tr><td colspan=\"4\"><hr /></td></tr>\n";
195 if (empty($to) && !empty($course->metacourse)) {
196 //Now print the Metacourse tr
197 echo "<tr>";
198 echo "<td align=\"right\" colspan=\"2\"><b>";
199 echo '<label for="menubackup_metacourse">'.get_string ("metacourse").'</label>';
200 echo "</b></td><td colspan=\"2\">";
201 $meta_options[0] = get_string("no");
202 $meta_options[1] = get_string("yes");
203 choose_from_menu($meta_options, "backup_metacourse", $backup_metacourse, "");
204 echo "</td></tr>";
206 else {
207 $hidden_options .= '<input type="hidden" name="backup_metacourse" value="0" />';
210 if (empty($to)) {
211 //Now print the Users tr
212 echo "<tr>";
213 echo "<td align=\"right\" colspan=\"2\"><b>";
214 echo '<label for="menubackup_users">'.get_string ("users").'</label>';
215 echo "</b></td><td colspan=\"2\">";
216 $user_options[0] = get_string("all");
217 $user_options[1] = get_string("course");
218 $user_options[2] = get_string("none");
219 choose_from_menu($user_options, "backup_users", $backup_users, "");
220 echo "</td></tr>";
222 else {
223 $hidden_options .= '<input type="hidden" name="backup_users" value="0" />';
226 if (empty($to)) {
227 //Now print the Logs tr
228 echo "<tr>";
229 echo "<td align=\"right\" colspan=\"2\"><b>";
230 echo '<label for="menubackup_logs">'.get_string ("logs").'</label>';
231 echo "</b></td><td colspan=\"2\">";
232 $log_options[0] = get_string("no");
233 $log_options[1] = get_string("yes");
234 choose_from_menu($log_options, "backup_logs", $backup_logs, "");
235 echo "</td></tr>";
237 else {
238 $hidden_options .= '<input type="hidden" name="backup_logs" value="0" />';
241 if (empty($to)) {
242 //Now print the User Files tr
243 echo "<tr>";
244 echo "<td align=\"right\" colspan=\"2\"><b>";
245 echo '<label for="menubackup_user_files">'.get_string ("userfiles").'</label>';
246 echo "</b></td><td colspan=\"2\">";
247 $user_file_options[0] = get_string("no");
248 $user_file_options[1] = get_string("yes");
249 choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, "");
250 echo "</td></tr>";
252 else {
253 $hidden_options .= '<input type="hidden" name="backup_user_files" value="0" />';
256 //Now print the Course Files tr
257 echo "<tr>";
258 echo "<td align=\"right\" colspan=\"2\"><b>";
259 echo '<label for="menubackup_course_files">'.get_string ("coursefiles").'</label>';
260 echo "</b></td><td colspan=\"2\">";
261 $course_file_options[0] = get_string("no");
262 $course_file_options[1] = get_string("yes");
263 choose_from_menu($course_file_options, "backup_course_files", $backup_course_files, "");
264 echo "</td></tr>";
267 if ($course->id != SITEID){
268 //Now print the site Files tr
269 echo "<tr>";
270 echo "<td align=\"right\" colspan=\"2\"><b>";
271 echo '<label for="menubackup_site_files">'.get_string ("sitefilesused").'</label>';
272 helpbutton('sitefilesused', get_string('sitefilesused'));
273 echo "</b></td><td colspan=\"2\">";
274 $course_file_options[0] = get_string("no");
275 $course_file_options[1] = get_string("yes");
276 choose_from_menu($course_file_options, "backup_site_files", $backup_site_files, "");
277 echo "</td></tr>";
280 // do you want grade histories to be backed up?
281 if (empty($CFG->disablegradehistory)) {
282 echo "<tr>";
283 echo "<td align=\"right\" colspan=\"2\"><b>";
284 echo '<label for="menubackup_gradebook_history">'.get_string ('gradebookhistories', 'grades').'</label>';
285 echo "</b></td><td colspan=\"2\">";
286 $gradebook_history_options[0] = get_string("no");
287 $gradebook_history_options[1] = get_string("yes");
288 choose_from_menu($gradebook_history_options, "backup_gradebook_history", $backup_gradebook_history, "");
289 echo "</td></tr>";
290 } else {
291 $hidden_options .= '<input type="hidden" name="backup_gradebook_history" value="0" />';
294 if (empty($to) && $course->id == SITEID) {
295 //If we are in a SITEID backup print the Messages tr
296 echo "<tr>";
297 echo "<td align=\"right\" colspan=\"2\"><b>";
298 echo '<label for="menubackup_messages">'.get_string ('messages', 'message').'</label>';
299 echo "</b></td><td colspan=\"2\">";
300 $mess_options[0] = get_string("no");
301 $mess_options[1] = get_string("yes");
302 choose_from_menu($mess_options, "backup_messages", $backup_messages, "");
303 echo "</td></tr>";
305 else {
306 $hidden_options .= '<input type="hidden" name="backup_messages" value="0" />';
309 if (empty($to) && $course->id == SITEID && !empty($CFG->bloglevel)) {
310 //If we are in a SITEID backup and blogs are enabled print the Blogs tr
311 echo "<tr>";
312 echo "<td align=\"right\" colspan=\"2\"><b>";
313 echo get_string ('blogs','blog').":";
314 echo "</b></td><td colspan=\"2\">";
315 $blog_options[0] = get_string("no");
316 $blog_options[1] = get_string("yes");
317 choose_from_menu($blog_options, "backup_blogs", $backup_blogs, "");
318 echo "</td></tr>";
320 else {
321 $hidden_options .= '<input type="hidden" name="backup_blogs" value="0" />';
325 //Now print a place to select which role assignments to back up.
326 if (empty($to)) {
327 //Line
328 echo "<tr><td colspan=\"4\"><hr /></td></tr>\n";
330 echo "<tr>";
331 echo "<td align=\"right\" valign=\"top\" colspan=\"2\"><b>";
332 echo get_string("backuproleassignments");
333 echo "</b></td><td colspan=\"2\">";
334 $roles = get_records('role', '', '', 'sortorder');
335 foreach ($roles as $role) {
336 print_checkbox('backupassignments_' . $role->shortname, 1, true, strip_tags(format_string($role->name, true)));
337 echo "<br />";
339 echo "<a href=\"#\" onclick=\"selectItemInCheckboxByName('form1', 'backupassignments_', true); return false;\">". get_string("all")."</a>/";
340 echo "<a href=\"#\" onclick=\"selectItemInCheckboxByName('form1', 'backupassignments_', false); return false;\">". get_string("none")."</a>";
341 echo "</td></tr>";
344 $backup_unique_code = time();
346 //Calculate the backup string
347 //Calculate the backup unique code to allow simultaneus backups (to define
348 //the temp-directory name and records in backup temp tables
349 $backup_name = backup_get_zipfile_name($course, $backup_unique_code);
353 </table>
354 <div style="text-align:center;margin-left:auto;margin-right:auto">
355 <?php
356 /// Print captured hidden options, now that we have closed the table
357 echo $hidden_options;
359 <input type="hidden" name="id" value="<?php p($id) ?>" />
360 <input type="hidden" name="to" value="<?php p($to) ?>" />
361 <input type="hidden" name="backup_unique_code" value="<?php p($backup_unique_code); ?>" />
362 <input type="hidden" name="backup_name" value="<?php p($backup_name); ?>" />
363 <input type="hidden" name="launch" value="check" />
364 <input type="submit" value="<?php print_string("continue") ?>" />
365 <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
366 </div>
367 </form>