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