MDL-20169 fixed coding style, parameter type required
[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 //Print the checkbox
1ecea976 160 print_checkbox($var, $$var, $$var, get_string("modulenameplural",$modname),'','selectItemInCheckboxByName(\'form1\',\'backup_'.$modname.'\',this.checked)');
1517803d 161 echo "</td><td align=\"right\">&nbsp;";
162 echo "</td><td>";
1ecea976 163 $var = "backup_user_info_".$modname;
873bf875 164 if (empty($to)) {
3bee1ead 165 $backup_user_options[0] = get_string("withoutuserdata");
873bf875 166 $backup_user_options[1] = get_string("withuserdata");
1ecea976 167 print_checkbox($var, $$var, $$var, get_string("userdata"),'','selectItemInCheckboxByName(\'form1\',\'backup_user_info_'.$modname.'\',this.checked)');
1517803d 168 } else {
873bf875 169 echo '<input type="hidden" name="'.$var.'" value="0" />';
170 }
3bee1ead 171 echo "</td></tr>\n";
0c94e43d 172 echo '<tr><td></td><td colspan="3"><table class="backup-form-instances">';
173 $instances = get_all_instances_in_course($modname, $course, NULL, true);
174 $var = $exvar;
175 foreach ($instances as $instance) {
176 echo '<tr><td>';
177 $var = 'backup_'.$modname.'_instance_'.$instance->id;
178 $$var = optional_param($var,1);
179 print_checkbox($var,$$var,$$var,$instance->name,$instance->name,'this.form.elements[\'backup_'.$modname.'\'].checked=1;');
180 echo '</td><td align="right">&nbsp;';
181 $var = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
182 $$var = optional_param($var,1);
183 if (empty($to)) {
184 print_checkbox($var,$$var,$$var,get_string('userdata'),'','this.form.elements[\'backup_user_info_'.$modname.'\'].checked=1;');
185 } else {
186 echo '<input type="hidden" name="'.$var.'" value="0" />';
1ecea976 187 }
0c94e43d 188 echo '</td></tr>';
1ecea976 189 }
0c94e43d 190 echo '</table></td></tr>';
a615cc7b 191 }
192 }
193 //Line
1517803d 194 echo "<tr><td colspan=\"4\"><hr /></td></tr>\n";
3bee1ead 195
7a2957d3 196 if (empty($to) && !empty($course->metacourse)) {
57224893 197 //Now print the Metacourse tr
198 echo "<tr>";
1517803d 199 echo "<td align=\"right\" colspan=\"2\"><b>";
7f9bd149 200 echo '<label for="menubackup_metacourse">'.get_string ("metacourse").'</label>';
1517803d 201 echo "</b></td><td colspan=\"2\">";
3bee1ead 202 $meta_options[0] = get_string("no");
203 $meta_options[1] = get_string("yes");
dad2baef 204 echo $OUTPUT->select(html_select::make($meta_options, "backup_metacourse", $backup_metacourse, false));
57224893 205 echo "</td></tr>";
206 }
207 else {
7a2957d3 208 $hidden_options .= '<input type="hidden" name="backup_metacourse" value="0" />';
57224893 209 }
210
873bf875 211 if (empty($to)) {
212 //Now print the Users tr
213 echo "<tr>";
1517803d 214 echo "<td align=\"right\" colspan=\"2\"><b>";
7f9bd149 215 echo '<label for="menubackup_users">'.get_string ("users").'</label>';
1517803d 216 echo "</b></td><td colspan=\"2\">";
873bf875 217 $user_options[0] = get_string("all");
218 $user_options[1] = get_string("course");
219 $user_options[2] = get_string("none");
dad2baef 220 echo $OUTPUT->select(html_select::make($user_options, "backup_users", $backup_users, false));
873bf875 221 echo "</td></tr>";
222 }
223 else {
7a2957d3 224 $hidden_options .= '<input type="hidden" name="backup_users" value="0" />';
873bf875 225 }
3bee1ead 226
873bf875 227 if (empty($to)) {
228 //Now print the Logs tr
229 echo "<tr>";
1517803d 230 echo "<td align=\"right\" colspan=\"2\"><b>";
7f9bd149 231 echo '<label for="menubackup_logs">'.get_string ("logs").'</label>';
1517803d 232 echo "</b></td><td colspan=\"2\">";
873bf875 233 $log_options[0] = get_string("no");
3bee1ead 234 $log_options[1] = get_string("yes");
dad2baef 235 echo $OUTPUT->select(html_select::make($log_options, "backup_logs", $backup_logs, false));
873bf875 236 echo "</td></tr>";
237 }
238 else {
7a2957d3 239 $hidden_options .= '<input type="hidden" name="backup_logs" value="0" />';
873bf875 240 }
3bee1ead 241
873bf875 242 if (empty($to)) {
243 //Now print the User Files tr
244 echo "<tr>";
1517803d 245 echo "<td align=\"right\" colspan=\"2\"><b>";
7f9bd149 246 echo '<label for="menubackup_user_files">'.get_string ("userfiles").'</label>';
1517803d 247 echo "</b></td><td colspan=\"2\">";
3bee1ead 248 $user_file_options[0] = get_string("no");
249 $user_file_options[1] = get_string("yes");
dad2baef 250 echo $OUTPUT->select(html_select::make($user_file_options, "backup_user_files", $backup_user_files, false));
873bf875 251 echo "</td></tr>";
252 }
253 else {
7a2957d3 254 $hidden_options .= '<input type="hidden" name="backup_user_files" value="0" />';
873bf875 255 }
7f9bd149 256
a615cc7b 257 //Now print the Course Files tr
258 echo "<tr>";
1517803d 259 echo "<td align=\"right\" colspan=\"2\"><b>";
7f9bd149 260 echo '<label for="menubackup_course_files">'.get_string ("coursefiles").'</label>';
1517803d 261 echo "</b></td><td colspan=\"2\">";
a615cc7b 262 $course_file_options[0] = get_string("no");
263 $course_file_options[1] = get_string("yes");
dad2baef 264 echo $OUTPUT->select(html_select::make($course_file_options, "backup_course_files", $backup_course_files, false));
a615cc7b 265 echo "</td></tr>";
70641539 266
3bee1ead 267
268 if ($course->id != SITEID){
269 //Now print the site Files tr
270 echo "<tr>";
271 echo "<td align=\"right\" colspan=\"2\"><b>";
7f9bd149 272 echo '<label for="menubackup_site_files">'.get_string ("sitefilesused").'</label>';
9549b986 273 echo $OUTPUT->help_icon(moodle_help_icon::make('sitefilesused', get_string('sitefilesused')));
3bee1ead 274 echo "</b></td><td colspan=\"2\">";
275 $course_file_options[0] = get_string("no");
276 $course_file_options[1] = get_string("yes");
dad2baef 277 echo $OUTPUT->select(html_select::make($course_file_options, "backup_site_files", $backup_site_files, false));
3bee1ead 278 echo "</td></tr>";
279 }
280
9107bee6 281 // do you want grade histories to be backed up?
7f9bd149 282 if (empty($CFG->disablegradehistory)) {
283 echo "<tr>";
284 echo "<td align=\"right\" colspan=\"2\"><b>";
285 echo '<label for="menubackup_gradebook_history">'.get_string ('gradebookhistories', 'grades').'</label>';
286 echo "</b></td><td colspan=\"2\">";
287 $gradebook_history_options[0] = get_string("no");
288 $gradebook_history_options[1] = get_string("yes");
dad2baef 289 echo $OUTPUT->select(html_select::make($gradebook_history_options, "backup_gradebook_history", $backup_gradebook_history, false));
7f9bd149 290 echo "</td></tr>";
291 } else {
292 $hidden_options .= '<input type="hidden" name="backup_gradebook_history" value="0" />';
293 }
9107bee6 294
70641539 295 if (empty($to) && $course->id == SITEID) {
296 //If we are in a SITEID backup print the Messages tr
297 echo "<tr>";
1517803d 298 echo "<td align=\"right\" colspan=\"2\"><b>";
7f9bd149 299 echo '<label for="menubackup_messages">'.get_string ('messages', 'message').'</label>';
1517803d 300 echo "</b></td><td colspan=\"2\">";
3bee1ead 301 $mess_options[0] = get_string("no");
302 $mess_options[1] = get_string("yes");
dad2baef 303 echo $OUTPUT->select(html_select::make($mess_options, "backup_messages", $backup_messages, false));
70641539 304 echo "</td></tr>";
305 }
306 else {
7a2957d3 307 $hidden_options .= '<input type="hidden" name="backup_messages" value="0" />';
70641539 308 }
fe75799d 309
310 if (empty($to) && $course->id == SITEID && !empty($CFG->bloglevel)) {
311 //If we are in a SITEID backup and blogs are enabled print the Blogs tr
312 echo "<tr>";
313 echo "<td align=\"right\" colspan=\"2\"><b>";
314 echo get_string ('blogs','blog').":";
315 echo "</b></td><td colspan=\"2\">";
316 $blog_options[0] = get_string("no");
317 $blog_options[1] = get_string("yes");
dad2baef 318 echo $OUTPUT->select(html_select::make($blog_options, "backup_blogs", $backup_blogs, false));
fe75799d 319 echo "</td></tr>";
320 }
321 else {
322 $hidden_options .= '<input type="hidden" name="backup_blogs" value="0" />';
323 }
a615cc7b 324 }
a94baeaf 325
f8f95b45 326 //Now print a place to select which role assignments to back up.
327 if (empty($to)) {
328 //Line
329 echo "<tr><td colspan=\"4\"><hr /></td></tr>\n";
330
331 echo "<tr>";
332 echo "<td align=\"right\" valign=\"top\" colspan=\"2\"><b>";
7f9bd149 333 echo get_string("backuproleassignments");
f8f95b45 334 echo "</b></td><td colspan=\"2\">";
9101efd3 335 $roles = get_all_roles();
f8f95b45 336 foreach ($roles as $role) {
337 print_checkbox('backupassignments_' . $role->shortname, 1, true, strip_tags(format_string($role->name, true)));
338 echo "<br />";
339 }
340 echo "<a href=\"#\" onclick=\"selectItemInCheckboxByName('form1', 'backupassignments_', true); return false;\">". get_string("all")."</a>/";
341 echo "<a href=\"#\" onclick=\"selectItemInCheckboxByName('form1', 'backupassignments_', false); return false;\">". get_string("none")."</a>";
342 echo "</td></tr>";
343 }
344
a94baeaf 345 $backup_unique_code = time();
346
347 //Calculate the backup string
a94baeaf 348 //Calculate the backup unique code to allow simultaneus backups (to define
349 //the temp-directory name and records in backup temp tables
9e3775db 350 $backup_name = backup_get_zipfile_name($course, $backup_unique_code);
3bee1ead 351
352
a615cc7b 353?>
354</table>
7f9bd149 355<div style="text-align:center;margin-left:auto;margin-right:auto">
7a2957d3 356<?php
357/// Print captured hidden options, now that we have closed the table
358 echo $hidden_options;
359?>
873bf875 360<input type="hidden" name="id" value="<?php p($id) ?>" />
361<input type="hidden" name="to" value="<?php p($to) ?>" />
a94baeaf 362<input type="hidden" name="backup_unique_code" value="<?php p($backup_unique_code); ?>" />
363<input type="hidden" name="backup_name" value="<?php p($backup_name); ?>" />
873bf875 364<input type="hidden" name="launch" value="check" />
365<input type="submit" value="<?php print_string("continue") ?>" />
366<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
fbe31d22 367</div>
9e3775db 368</form>