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