2 //This page prints the backup form to select everything
7 if (!empty($course->id
)) {
8 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
10 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
12 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE
, $to))) {
13 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
18 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
19 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
24 if (!$site = get_site()) {
25 error("Site not found!");
28 //Checks for the required files/functions to backup every mod
29 //And check if there is data about it
31 if ($allmods = get_records("modules") ) {
32 foreach ($allmods as $mod) {
33 $modname = $mod->name
;
34 $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
35 $modbackup = $modname."_backup_mods";
36 $modbackupone = $modname.'_backup_one_mod';
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;
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;
53 $var = "backup_".$modname;
54 $
$var = optional_param( $var,1);
55 //Check include user info
56 $var = "backup_user_info_".$modname;
57 $
$var = optional_param( $var,1);
61 //Check other parameters
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);
67 $backup_site_files = optional_param('backup_site_files',1);
68 $backup_gradebook_history = optional_param('backup_gradebook_history', 1, PARAM_INT
);
69 $backup_messages = optional_param('backup_messages',1);
72 notice("No backupable modules are installed!");
77 <script type=
"text/javascript">
79 function 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;
91 function 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;
104 function selectItemInCheckboxByName(formId
, checkName
, checked
) {
105 myForm
= document
.getElementById(formId
);
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
;
117 <form id=
"form1" method=
"post" action=
"backup.php">
118 <table cellpadding=
"5" style=
"margin-left:auto;margin-right:auto;">
120 //Now, check modules and info and show posibilities
121 if ($allmods = get_records("modules") ) {
122 //Print option to select/deselect everything with 1 click.
124 echo "<td align=\"right\">";
125 echo '<b>'.get_string("include").":</b>";
127 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', true);\">". get_string("all")."</a>/";
128 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', false);\">". get_string("none")."</a>";
130 echo "<td align=\"right\">";
131 echo '<b> </b>';
133 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', true);\">". get_string("all")."</a>/";
134 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', false);\">". get_string("none")."</a>";
137 echo "<tr><td colspan=\"4\"><hr /></td></tr>";
139 foreach ($allmods as $mod) {
140 $modname = $mod->name
;
141 $modbackup = $modname."_backup_mods";
142 //If exists the lib & function
143 $var = "exists_".$modname;
144 if (isset($
$var) && $
$var) {
146 echo "<tr class=\"r".$currentrow."\">";
147 echo " <td align=\"right\"> ";
149 $backup_options[0] = get_string("no");
150 $backup_options[1] = get_string("yes");
151 $var = "backup_".$modname;
152 //choose_from_menu($backup_options, $var, $$var, "");
154 print_checkbox($var, $
$var, $
$var, get_string("modulenameplural",$modname),'','selectItemInCheckboxByName(\'form1\',\'backup_'.$modname.'\',this.checked)');
155 echo "</td><td align=\"right\"> ";
157 $var = "backup_user_info_".$modname;
159 $backup_user_options[0] = get_string("withoutuserdata");
160 $backup_user_options[1] = get_string("withuserdata");
161 //choose_from_menu($backup_user_options, $var, $$var, "");
162 print_checkbox($var, $
$var, $
$var, get_string("userdata"),'','selectItemInCheckboxByName(\'form1\',\'backup_user_info_'.$modname.'\',this.checked)');
164 echo '<input type="hidden" name="'.$var.'" value="0" />';
167 // if we have the backup_one_mod function, loop here.
168 $var = 'exists_one_'.$modname;
170 echo '<tr><td></td><td colspan="3"><table class="backup-form-instances">';
171 $instances = get_all_instances_in_course($modname,$course);
172 foreach ($instances as $instance) {
174 $var = 'backup_'.$modname.'_instance_'.$instance->id
;
175 $
$var = optional_param($var,1);
176 print_checkbox($var,$
$var,$
$var,$instance->name
,$instance->name
,'this.form.elements[\'backup_'.$modname.'\'].checked=1;');
177 echo '</td><td align="right"> ';
178 $var = 'backup_user_info_'.$modname.'_instance_'.$instance->id
;
179 $
$var = optional_param($var,1);
181 print_checkbox($var,$
$var,$
$var,get_string('userdata'),'','this.form.elements[\'backup_user_info_'.$modname.'\'].checked=1;');
183 echo '<input type="hidden" name="'.$var.'" value="0" />';
187 echo '</table></td></tr>';
193 echo "<tr><td colspan=\"4\"><hr /></td></tr>\n";
196 //Now print the Metacourse tr
198 echo "<td align=\"right\" colspan=\"2\"><b>";
199 echo get_string ("metacourse").":";
200 echo "</b></td><td colspan=\"2\">";
201 $meta_options[0] = get_string("no");
202 $meta_options[1] = get_string("yes");
203 choose_from_menu($meta_options, "backup_metacourse", $backup_metacourse, "");
207 echo '<input type="hidden" name="backup_metacourse" value="0" />';
211 //Now print the Users tr
213 echo "<td align=\"right\" colspan=\"2\"><b>";
214 echo get_string("users").":";
215 echo "</b></td><td colspan=\"2\">";
216 $user_options[0] = get_string("all");
217 $user_options[1] = get_string("course");
218 $user_options[2] = get_string("none");
219 choose_from_menu($user_options, "backup_users", $backup_users, "");
223 echo '<input type="hidden" name="backup_users" value="0" />';
227 //Now print the Logs tr
229 echo "<td align=\"right\" colspan=\"2\"><b>";
230 echo get_string("logs").":";
231 echo "</b></td><td colspan=\"2\">";
232 $log_options[0] = get_string("no");
233 $log_options[1] = get_string("yes");
234 choose_from_menu($log_options, "backup_logs", $backup_logs, "");
238 echo '<input type="hidden" name="backup_logs" value="0" />';
242 //Now print the User Files tr
244 echo "<td align=\"right\" colspan=\"2\"><b>";
245 echo get_string ("userfiles").":";
246 echo "</b></td><td colspan=\"2\">";
247 $user_file_options[0] = get_string("no");
248 $user_file_options[1] = get_string("yes");
249 choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, "");
253 echo '<input type="hidden" name="backup_user_files" value="0" />';
255 //Now print the Course Files tr
257 echo "<td align=\"right\" colspan=\"2\"><b>";
258 echo get_string ("coursefiles").":";
259 echo "</b></td><td colspan=\"2\">";
260 $course_file_options[0] = get_string("no");
261 $course_file_options[1] = get_string("yes");
262 choose_from_menu($course_file_options, "backup_course_files", $backup_course_files, "");
266 if ($course->id
!= SITEID
){
267 //Now print the site Files tr
269 echo "<td align=\"right\" colspan=\"2\"><b>";
270 echo get_string ("sitefilesused").":";
271 helpbutton('sitefilesused', get_string('sitefilesused'));
272 echo "</b></td><td colspan=\"2\">";
273 $course_file_options[0] = get_string("no");
274 $course_file_options[1] = get_string("yes");
275 choose_from_menu($course_file_options, "backup_site_files", $backup_site_files, "");
279 // do you want grade histories to be backed up?
281 echo "<td align=\"right\" colspan=\"2\"><b>";
282 echo get_string ('gradebookhistories', 'grades').":";
283 echo "</b></td><td colspan=\"2\">";
284 $gradebook_history_options[0] = get_string("no");
285 $gradebook_history_options[1] = get_string("yes");
286 choose_from_menu($gradebook_history_options, "backup_gradebook_history", $backup_gradebook_history, "");
289 if (empty($to) && $course->id
== SITEID
) {
290 //If we are in a SITEID backup print the Messages tr
292 echo "<td align=\"right\" colspan=\"2\"><b>";
293 echo get_string ('messages','message').":";
294 echo "</b></td><td colspan=\"2\">";
295 $mess_options[0] = get_string("no");
296 $mess_options[1] = get_string("yes");
297 choose_from_menu($mess_options, "backup_messages", $backup_messages, "");
301 echo '<input type="hidden" name="backup_messages" value="0" />';
305 $backup_unique_code = time();
307 //Calculate the backup string
308 //Calculate the backup unique code to allow simultaneus backups (to define
309 //the temp-directory name and records in backup temp tables
310 $backup_name = backup_get_zipfile_name($course, $backup_unique_code);
316 <div style=
"text-align:center;margin-left:auto;margin-right:auto">
317 <input type=
"hidden" name=
"id" value=
"<?php p($id) ?>" />
318 <input type
="hidden" name
="to" value
="<?php p($to) ?>" />
319 <input type
="hidden" name
="backup_unique_code" value
="<?php p($backup_unique_code); ?>" />
320 <input type
="hidden" name
="backup_name" value
="<?php p($backup_name); ?>" />
321 <input type
="hidden" name
="launch" value
="check" />
322 <input type
="submit" value
="<?php print_string("continue") ?>" />
323 <input type
="submit" name
="cancel" value
="<?php print_string("cancel
") ?>" />