forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_check.html
275 lines (242 loc) · 10.9 KB
/
backup_check.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
<?php //$Id$
//This page prints the backup todo list to see everything
//Check login
require_login();
$loginurl = get_login_url();
if (!empty($course->id)) {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (empty($to)) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
} else {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
print_error("cannotuseadminadminorteacher", '', $loginurl);
}
}
}
} else {
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
print_error("cannotuseadmin", '', $loginurl);
}
}
$backupprefs = new StdClass;
$count = 0;
backup_fetch_prefs_from_request($backupprefs,$count,$course);
//Check site
if (!$site = get_site()) {
print_error("siteisnotdefined", 'debug');
}
if ($count == 0) {
notice("No backupable modules are installed!");
}
if (!$DB->delete_records("backup_ids", array('backup_code'=>$backupprefs->backup_unique_code))){
print_error('cannotdeletebackupids');
}
?>
<form id="form" method="post" action="backup.php">
<table cellpadding="5" style="text-align:center;margin-left:auto;margin-right:auto">
<?php
if (empty($to)) {
//Now print the Backup Name tr
echo "<tr>";
echo "<td align=\"right\"><b>";
echo get_string("name").":";
echo "</b></td><td>";
//Add as text field
echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backupprefs->backup_name."\" />";
echo "</td></tr>";
//Line
echo "<tr><td colspan=\"2\"><hr /></td></tr>";
//Now print the To Do list
echo "<tr>";
echo "<td colspan=\"2\" align=\"center\"><b>";
}
//Here we check if backup_users = None. Then, we switch off every module
//user info, user_files, logs and exercises, workshop and messages & blogs backups. A Warning is showed to
//inform the user.
// TODO: Move this logic to one function to be shared by any (manual, scheduled) backup
if ($backupprefs->backup_users == 2) {
if ($allmods = $DB->get_records('modules') ) {
foreach ($allmods as $mod) {
/// Reset global user_info settings to "no" (0)
$modname = $mod->name;
$var = 'backup_user_info_'.$modname;
if (isset($backupprefs->$var)) {
$backupprefs->$var = 0;
}
/// Reset each instance userinfo settings to "no" (0)
if (isset($backupprefs->mods[$modname])) {
/// Set the module userinfo to no (0)
$backupprefs->mods[$modname]->userinfo = 0;
/// Set the instances to no (o)
foreach ($backupprefs->mods[$modname]->instances as $key => $instance) {
$backupprefs->mods[$modname]->instances[$key]->userinfo = 0;
$var = 'backup_user_info_' . $modname . '_instance_' . $key;
$backupprefs->$var = 0;
}
}
/// If modules are workshop or exercise, disable their backup completely
if ($modname == 'exercise' || $modname == 'workshop') {
$var = 'backup_'.$modname;
if (isset($backupprefs->$var)) {
$backupprefs->$var = 0;
/// Reset each instance backup settings to "no" (0)
if (isset($backupprefs->mods[$modname])) {
/// Set the module backup to no (0)
$backupprefs->mods[$modname]->backup = 0;
$var = 'backup_' . $modname . '_instances';
$backupprefs->$var = 0;
/// Set the instances backup to no (o)
foreach ($backupprefs->mods[$modname]->instances as $key => $instance) {
$backupprefs->mods[$modname]->instances[$key]->backup = 0;
$var = 'backup_' . $modname . '_instance_' . $key;
$backupprefs->$var = 0;
}
}
}
}
}
}
$backupprefs->backup_user_files = 0;
$backupprefs->backup_logs = 0;
$backupprefs->backup_messages = 0;
$backupprefs->backup_blogs = 0;
$backupprefs->backuproleassignments = array();
print_simple_box("<font color=\"red\">".get_string("backupnoneusersinfo")."</font>","center", "70%", '', "20", "noticebox");
echo "<hr />";
}
if (empty($to)) {
echo get_string("backupdetails").":";
echo "</b></td></tr>";
}
//This is the alignment of every row in the table
$table->align = array ("left","right");
if ($allmods = $DB->get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = $CFG->dirroot.'/mod/'.$modname.'/backuplib.php';
if (!file_exists($modfile)) {
continue;
}
require_once($modfile);
$modbackup = $modname."_backup_mods";
//If exists the lib & function
$var = "exists_".$modname;
if (isset($backupprefs->$var) && $backupprefs->$var) {
$var = "backup_".$modname;
//Only if selected
if (!empty($backupprefs->$var) and ($backupprefs->$var == 1)) {
//Print the full tr
echo "<tr>";
echo "<td colspan=\"2\">";
//Print the mod name
echo "<b>".get_string("include")." ".get_string("modulenameplural",$modname)." ";
//Now look for user-data status
$backup_user_options[0] = get_string("withoutuserdata");
$backup_user_options[1] = get_string("withuserdata");
$var = "backup_user_info_".$modname;
//Print the user info
echo $backup_user_options[$backupprefs->$var]."</b>";
//Call the check function to show more info
$modcheckbackup = $modname."_check_backup_mods";
$var = $modname.'_instances';
$instancestopass = array();
if (!empty($backupprefs->$var) && is_array($backupprefs->$var) && count($backupprefs->$var)) {
$table->data = array();
$countinstances = 0;
foreach ($backupprefs->$var as $instance) {
$var1 = 'backup_'.$modname.'_instance_'.$instance->id;
$var2 = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
if (!empty($backupprefs->$var1)) {
$obj = new StdClass;
$obj->name = $instance->name;
$obj->userdata = $backupprefs->$var2;
$obj->id = $instance->id;
$instancestopass[$instance->id]= $obj;
$countinstances++;
}
}
}
$table->data = $modcheckbackup($id,$backupprefs->$var,$backupprefs->backup_unique_code,$instancestopass);
print_table($table);
echo "</td></tr>";
}
}
}
if (empty($to)) {
//Line
echo "<tr><td colspan=\"2\"><hr /></td></tr>";
//Now print the Users tr
echo "<tr>";
echo "<td colspan=\"2\"><b>";
$user_options[0] = get_string("includeallusers");
$user_options[1] = get_string("includecourseusers");
$user_options[2] = get_string("includenoneusers");
echo $user_options[$backupprefs->backup_users].'</b>';
//Print info
$table->data = user_check_backup($id,$backupprefs->backup_unique_code,$backupprefs->backup_users,$backupprefs->backup_messages, $backupprefs->backup_blogs);
print_table($table);
echo "</td></tr>";
}
//Now print the Logs tr conditionally
if ($backupprefs->backup_logs && empty($to)) {
echo "<tr>";
echo "<td colspan=\"2\"><b>";
echo get_string("includelogentries").'</b>';
//Print info
$table->data = log_check_backup($id);
print_table($table);
echo "</td></tr>";
}
//Now print the User Files tr conditionally
if ($backupprefs->backup_user_files) {
echo "<tr>";
echo "<td colspan=\"2\"><b>";
echo get_string("includeuserfiles").'</b>';
//Print info
$table->data = user_files_check_backup($id,$backupprefs->backup_unique_code);
print_table($table);
echo "</td></tr>";
}
//Now print the Course Files tr conditionally
if ($backupprefs->backup_course_files) {
echo "<tr>";
echo "<td colspan=\"2\"><b>";
echo get_string("includecoursefiles").'</b>';
//Print info
$table->data = course_files_check_backup($id,$backupprefs->backup_unique_code);
print_table($table);
echo "</td></tr>";
}
//Now print the site Files tr conditionally
if ($backupprefs->backup_site_files) {
echo "<tr>";
echo "<td colspan=\"2\"><b>";
echo get_string("includesitefiles").'</b>';
//Print info
$table->data = site_files_check_backup($id,$backupprefs->backup_unique_code);
print_table($table);
echo "</td></tr>";
}
//Now print the role assignments information conditionally
if (!empty($backupprefs->backuproleassignments)) {
echo "<tr>";
echo "<td colspan=\"2\"><b>";
echo get_string("includeroleassignments").'</b>';
//Print info
$table->data = array(array(get_string('roles'), count($backupprefs->backuproleassignments)));
print_table($table);
echo "</td></tr>";
}
}
// now keep it for next time.
$SESSION->backupprefs[$course->id] = $backupprefs;
?>
</table>
<div style="text-align:center;margin-left:auto;margin-right:auto">
<input type="hidden" name="to" value="<?php p($to) ?>" />
<input type="hidden" name="id" value="<?php p($id) ?>" />
<input type="hidden" name="launch" value="execute" />
<input type="submit" value="<?php print_string("continue") ?>" />
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
</div>
</form>