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