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