MDL-11433 Implemented grade_items.decimals instead of user preference in grader report.
[moodle.git] / backup / backup_form.html
CommitLineData
7ef0797d 1<?php //$Id$
a615cc7b 2 //This page prints the backup form to select everything
3
3bee1ead 4 //Check login
c563a9a0 5 require_login();
6
bd38123e 7 if (!empty($course->id)) {
ec7a8b79 8 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
873bf875 9 if (empty($to)) {
10 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
11 } else {
ec7a8b79 12 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
873bf875 13 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
14 }
15 }
bd38123e 16 }
17 } else {
ec7a8b79 18 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
bd38123e 19 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
20 }
c563a9a0 21 }
22
23 //Check site
24 if (!$site = get_site()) {
25 error("Site not found!");
26 }
27
834e58a9 28 //Checks for the required files/functions to backup every mod
3bee1ead 29 //And check if there is data about it
a615cc7b 30 $count = 0;
31 if ($allmods = get_records("modules") ) {
32 foreach ($allmods as $mod) {
33 $modname = $mod->name;
9c1ae5ae 34 $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
a615cc7b 35 $modbackup = $modname."_backup_mods";
1ecea976 36 $modbackupone = $modname.'_backup_one_mod';
a615cc7b 37 $modcheckbackup = $modname."_check_backup_mods";
38 if (file_exists($modfile)) {
39 include_once($modfile);
40 if (function_exists($modbackup) and function_exists($modcheckbackup)) {
41 $var = "exists_".$modname;
42 $$var = true;
43 $count++;
1ecea976 44 // check that there are instances and we can back them up individually
45 if (count_records('course_modules','course',$course->id,'module',$mod->id) && function_exists($modbackupone)) {
46 $var = 'exists_one_'.$modname;
47 $$var = true;
48 }
a615cc7b 49 }
50 }
51 //Check data
52 //Check module info
53 $var = "backup_".$modname;
1517803d 54 $$var = optional_param( $var,1);
a615cc7b 55 //Check include user info
56 $var = "backup_user_info_".$modname;
1517803d 57 $$var = optional_param( $var,1);
a615cc7b 58 }
59 }
60
61 //Check other parameters
1517803d 62 $backup_metacourse = optional_param('backup_metacourse',1);
63 $backup_users = optional_param('backup_users',1);
64 $backup_logs = optional_param('backup_logs',0);
65 $backup_user_files = optional_param('backup_user_files',1);
66 $backup_course_files = optional_param('backup_course_files',1);
3bee1ead 67 $backup_site_files = optional_param('backup_site_files',1);
9107bee6 68 $backup_gradebook_history = optional_param('backup_gradebook_history', 1, PARAM_INT);
1517803d 69 $backup_messages = optional_param('backup_messages',1);
57224893 70
1517803d 71 if ($count == 0) {
72 notice("No backupable modules are installed!");
a615cc7b 73 }
74
1517803d 75?>
a615cc7b 76
f4ba7e1a 77<script type="text/javascript">
1517803d 78<!--
79function selectItemInMenuByName(formId, menuName, selectIndex ) {
80 myForm = document.getElementById(formId)
81 for (i=0,n=myForm.elements.length;i<n;i++) {
82 myLen = menuName.length;
83 myName = myForm.elements[i].name;
84 myType = myForm.elements[i].type;
85 if (myName.substring(0,myLen) == menuName && myType == "select-one") {
86 myForm.elements[i].options[selectIndex].selected = true;
87 }
a615cc7b 88 }
1517803d 89}
a615cc7b 90
1517803d 91function selectItemInRadioByName(formId, radioName, selectIndex ) {
92 myForm = document.getElementById(formId)
93 for (i=0,n=myForm.elements.length;i<n;i++) {
94 myLen = radioName.length;
95 myName = myForm.elements[i].name;
96 myType = myForm.elements[i].type;
97 if (myName.substring(0,myLen) == radioName && myType == "radio") {
98 myRadioGroup = myForm.elements[myName];
99 myRadioGroup[selectIndex].checked = true;
100 }
70641539 101 }
1517803d 102}
70641539 103
1517803d 104function selectItemInCheckboxByName(formId, checkName, checked ) {
1ecea976 105 myForm = document.getElementById(formId);
1517803d 106 for (i=0,n=myForm.elements.length;i<n;i++) {
107 myLen = checkName.length;
108 myName = myForm.elements[i].name;
109 myType = myForm.elements[i].type;
110 if (myName.substring(0,myLen) == checkName && myType == "checkbox") {
111 myForm.elements[i].checked = checked;
112 }
a615cc7b 113 }
1517803d 114}
115-->
116</script>
b7dc2256 117<form id="form1" method="post" action="backup.php">
fbe31d22 118<table cellpadding="5" style="margin-left:auto;margin-right:auto;">
145cb8f9 119<?php
7a2957d3 120/// Acummulator for hidden options and proper XHTML output
121 $hidden_options = '';
1517803d 122 //Now, check modules and info and show posibilities
a615cc7b 123 if ($allmods = get_records("modules") ) {
1517803d 124 //Print option to select/deselect everything with 1 click.
125 echo "<tr>";
126 echo "<td align=\"right\">";
127 echo '<b>'.get_string("include").":</b>";
128 echo "</td><td>";
129 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', true);\">". get_string("all")."</a>/";
130 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', false);\">". get_string("none")."</a>";
131 echo "</td>";
132 echo "<td align=\"right\">";
133 echo '<b>&nbsp;</b>';
134 echo "</td><td>";
135 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', true);\">". get_string("all")."</a>/";
136 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', false);\">". get_string("none")."</a>";
137 echo "</td>";
138 echo "</tr>";
139 echo "<tr><td colspan=\"4\"><hr /></td></tr>";
140 $currentrow = 0;
a615cc7b 141 foreach ($allmods as $mod) {
142 $modname = $mod->name;
143 $modbackup = $modname."_backup_mods";
144 //If exists the lib & function
145 $var = "exists_".$modname;
142a6a46 146 if (isset($$var) && $$var) {
a615cc7b 147 //Print the full tr
1517803d 148 echo "<tr class=\"r".$currentrow."\">";
149 echo " <td align=\"right\">&nbsp;";
150 echo "</td><td>\n";
3bee1ead 151 $backup_options[0] = get_string("no");
a615cc7b 152 $backup_options[1] = get_string("yes");
153 $var = "backup_".$modname;
1517803d 154 //choose_from_menu($backup_options, $var, $$var, "");
155 //Print the checkbox
1ecea976 156 print_checkbox($var, $$var, $$var, get_string("modulenameplural",$modname),'','selectItemInCheckboxByName(\'form1\',\'backup_'.$modname.'\',this.checked)');
1517803d 157 echo "</td><td align=\"right\">&nbsp;";
158 echo "</td><td>";
1ecea976 159 $var = "backup_user_info_".$modname;
873bf875 160 if (empty($to)) {
3bee1ead 161 $backup_user_options[0] = get_string("withoutuserdata");
873bf875 162 $backup_user_options[1] = get_string("withuserdata");
1517803d 163 //choose_from_menu($backup_user_options, $var, $$var, "");
1ecea976 164 print_checkbox($var, $$var, $$var, get_string("userdata"),'','selectItemInCheckboxByName(\'form1\',\'backup_user_info_'.$modname.'\',this.checked)');
1517803d 165 } else {
873bf875 166 echo '<input type="hidden" name="'.$var.'" value="0" />';
167 }
3bee1ead 168 echo "</td></tr>\n";
1ecea976 169 // if we have the backup_one_mod function, loop here.
170 $var = 'exists_one_'.$modname;
171 if (!empty($$var)) {
172 echo '<tr><td></td><td colspan="3"><table class="backup-form-instances">';
173 $instances = get_all_instances_in_course($modname,$course);
174 foreach ($instances as $instance) {
175 echo '<tr><td>';
176 $var = 'backup_'.$modname.'_instance_'.$instance->id;
177 $$var = optional_param($var,1);
178 print_checkbox($var,$$var,$$var,$instance->name,$instance->name,'this.form.elements[\'backup_'.$modname.'\'].checked=1;');
179 echo '</td><td align="right">&nbsp;';
180 $var = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
181 $$var = optional_param($var,1);
182 if (empty($to)) {
183 print_checkbox($var,$$var,$$var,get_string('userdata'),'','this.form.elements[\'backup_user_info_'.$modname.'\'].checked=1;');
184 } else {
185 echo '<input type="hidden" name="'.$var.'" value="0" />';
186 }
187 echo '</td></tr>';
188 }
189 echo '</table></td></tr>';
190 }
3bee1ead 191
a615cc7b 192 }
193 }
194 //Line
1517803d 195 echo "<tr><td colspan=\"4\"><hr /></td></tr>\n";
3bee1ead 196
7a2957d3 197 if (empty($to) && !empty($course->metacourse)) {
57224893 198 //Now print the Metacourse tr
199 echo "<tr>";
1517803d 200 echo "<td align=\"right\" colspan=\"2\"><b>";
57224893 201 echo get_string ("metacourse").":";
1517803d 202 echo "</b></td><td colspan=\"2\">";
3bee1ead 203 $meta_options[0] = get_string("no");
204 $meta_options[1] = get_string("yes");
57224893 205 choose_from_menu($meta_options, "backup_metacourse", $backup_metacourse, "");
206 echo "</td></tr>";
207 }
208 else {
7a2957d3 209 $hidden_options .= '<input type="hidden" name="backup_metacourse" value="0" />';
57224893 210 }
211
873bf875 212 if (empty($to)) {
213 //Now print the Users tr
214 echo "<tr>";
1517803d 215 echo "<td align=\"right\" colspan=\"2\"><b>";
873bf875 216 echo get_string("users").":";
1517803d 217 echo "</b></td><td colspan=\"2\">";
873bf875 218 $user_options[0] = get_string("all");
219 $user_options[1] = get_string("course");
220 $user_options[2] = get_string("none");
221 choose_from_menu($user_options, "backup_users", $backup_users, "");
222 echo "</td></tr>";
223 }
224 else {
7a2957d3 225 $hidden_options .= '<input type="hidden" name="backup_users" value="0" />';
873bf875 226 }
3bee1ead 227
873bf875 228 if (empty($to)) {
229 //Now print the Logs tr
230 echo "<tr>";
1517803d 231 echo "<td align=\"right\" colspan=\"2\"><b>";
3bee1ead 232 echo get_string("logs").":";
1517803d 233 echo "</b></td><td colspan=\"2\">";
873bf875 234 $log_options[0] = get_string("no");
3bee1ead 235 $log_options[1] = get_string("yes");
236 choose_from_menu($log_options, "backup_logs", $backup_logs, "");
873bf875 237 echo "</td></tr>";
238 }
239 else {
7a2957d3 240 $hidden_options .= '<input type="hidden" name="backup_logs" value="0" />';
873bf875 241 }
3bee1ead 242
873bf875 243 if (empty($to)) {
244 //Now print the User Files tr
245 echo "<tr>";
1517803d 246 echo "<td align=\"right\" colspan=\"2\"><b>";
873bf875 247 echo get_string ("userfiles").":";
1517803d 248 echo "</b></td><td colspan=\"2\">";
3bee1ead 249 $user_file_options[0] = get_string("no");
250 $user_file_options[1] = get_string("yes");
873bf875 251 choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, "");
252 echo "</td></tr>";
253 }
254 else {
7a2957d3 255 $hidden_options .= '<input type="hidden" name="backup_user_files" value="0" />';
873bf875 256 }
a615cc7b 257 //Now print the Course Files tr
258 echo "<tr>";
1517803d 259 echo "<td align=\"right\" colspan=\"2\"><b>";
a615cc7b 260 echo get_string ("coursefiles").":";
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");
264 choose_from_menu($course_file_options, "backup_course_files", $backup_course_files, "");
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>";
272 echo get_string ("sitefilesused").":";
863be1a9 273 helpbutton('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");
277 choose_from_menu($course_file_options, "backup_site_files", $backup_site_files, "");
278 echo "</td></tr>";
279 }
280
9107bee6 281 // do you want grade histories to be backed up?
282 echo "<tr>";
283 echo "<td align=\"right\" colspan=\"2\"><b>";
284 echo get_string ('gradebookhistories', 'grades').":";
285 echo "</b></td><td colspan=\"2\">";
286 $gradebook_history_options[0] = get_string("no");
287 $gradebook_history_options[1] = get_string("yes");
288 choose_from_menu($gradebook_history_options, "backup_gradebook_history", $backup_gradebook_history, "");
289 echo "</td></tr>";
290
70641539 291 if (empty($to) && $course->id == SITEID) {
292 //If we are in a SITEID backup print the Messages tr
293 echo "<tr>";
1517803d 294 echo "<td align=\"right\" colspan=\"2\"><b>";
70641539 295 echo get_string ('messages','message').":";
1517803d 296 echo "</b></td><td colspan=\"2\">";
3bee1ead 297 $mess_options[0] = get_string("no");
298 $mess_options[1] = get_string("yes");
70641539 299 choose_from_menu($mess_options, "backup_messages", $backup_messages, "");
300 echo "</td></tr>";
301 }
302 else {
7a2957d3 303 $hidden_options .= '<input type="hidden" name="backup_messages" value="0" />';
70641539 304 }
a615cc7b 305 }
a94baeaf 306
307 $backup_unique_code = time();
308
309 //Calculate the backup string
a94baeaf 310 //Calculate the backup unique code to allow simultaneus backups (to define
311 //the temp-directory name and records in backup temp tables
9e3775db 312 $backup_name = backup_get_zipfile_name($course, $backup_unique_code);
3bee1ead 313
314
a615cc7b 315?>
316</table>
7a2957d3 317<?php
318/// Print captured hidden options, now that we have closed the table
319 echo $hidden_options;
320?>
fbe31d22 321
322<div style="text-align:center;margin-left:auto;margin-right:auto">
873bf875 323<input type="hidden" name="id" value="<?php p($id) ?>" />
324<input type="hidden" name="to" value="<?php p($to) ?>" />
a94baeaf 325<input type="hidden" name="backup_unique_code" value="<?php p($backup_unique_code); ?>" />
326<input type="hidden" name="backup_name" value="<?php p($backup_name); ?>" />
873bf875 327<input type="hidden" name="launch" value="check" />
328<input type="submit" value="<?php print_string("continue") ?>" />
329<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
fbe31d22 330</div>
9e3775db 331</form>