Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / backup / backup_form.html
blob1cb94ad4ec8ca919de26033a7b3eb3606f4c7496
1 <?php //$Id$
2 //This page prints the backup form to select everything
4 //Check login
5 require_login();
7 if (!empty($course->id)) {
8 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
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 {
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");
17 } else {
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");
23 //Check site
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
30 $count = 0;
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;
42 $$var = true;
43 $count++;
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;
51 //Check data
52 //Check module info
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_messages = optional_param('backup_messages',1);
69 if ($count == 0) {
70 notice("No backupable modules are installed!");
75 <script type="text/javascript">
76 <!--
77 function selectItemInMenuByName(formId, menuName, selectIndex ) {
78 myForm = document.getElementById(formId)
79 for (i=0,n=myForm.elements.length;i<n;i++) {
80 myLen = menuName.length;
81 myName = myForm.elements[i].name;
82 myType = myForm.elements[i].type;
83 if (myName.substring(0,myLen) == menuName && myType == "select-one") {
84 myForm.elements[i].options[selectIndex].selected = true;
89 function selectItemInRadioByName(formId, radioName, selectIndex ) {
90 myForm = document.getElementById(formId)
91 for (i=0,n=myForm.elements.length;i<n;i++) {
92 myLen = radioName.length;
93 myName = myForm.elements[i].name;
94 myType = myForm.elements[i].type;
95 if (myName.substring(0,myLen) == radioName && myType == "radio") {
96 myRadioGroup = myForm.elements[myName];
97 myRadioGroup[selectIndex].checked = true;
102 function selectItemInCheckboxByName(formId, checkName, checked ) {
103 myForm = document.getElementById(formId);
104 for (i=0,n=myForm.elements.length;i<n;i++) {
105 myLen = checkName.length;
106 myName = myForm.elements[i].name;
107 myType = myForm.elements[i].type;
108 if (myName.substring(0,myLen) == checkName && myType == "checkbox") {
109 myForm.elements[i].checked = checked;
114 </script>
115 <form id="form1" method="post" action="backup.php">
116 <table cellpadding="5" style="margin-left:auto;margin-right:auto;">
117 <?php
118 //Now, check modules and info and show posibilities
119 if ($allmods = get_records("modules") ) {
120 //Print option to select/deselect everything with 1 click.
121 echo "<tr>";
122 echo "<td align=\"right\">";
123 echo '<b>'.get_string("include").":</b>";
124 echo "</td><td>";
125 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', true);\">". get_string("all")."</a>/";
126 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', false);\">". get_string("none")."</a>";
127 echo "</td>";
128 echo "<td align=\"right\">";
129 echo '<b>&nbsp;</b>';
130 echo "</td><td>";
131 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', true);\">". get_string("all")."</a>/";
132 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', false);\">". get_string("none")."</a>";
133 echo "</td>";
134 echo "</tr>";
135 echo "<tr><td colspan=\"4\"><hr /></td></tr>";
136 $currentrow = 0;
137 foreach ($allmods as $mod) {
138 $modname = $mod->name;
139 $modbackup = $modname."_backup_mods";
140 //If exists the lib & function
141 $var = "exists_".$modname;
142 if (isset($$var) && $$var) {
143 //Print the full tr
144 echo "<tr class=\"r".$currentrow."\">";
145 echo " <td align=\"right\">&nbsp;";
146 echo "</td><td>\n";
147 $backup_options[0] = get_string("no");
148 $backup_options[1] = get_string("yes");
149 $var = "backup_".$modname;
150 //choose_from_menu($backup_options, $var, $$var, "");
151 //Print the checkbox
152 print_checkbox($var, $$var, $$var, get_string("modulenameplural",$modname),'','selectItemInCheckboxByName(\'form1\',\'backup_'.$modname.'\',this.checked)');
153 echo "</td><td align=\"right\">&nbsp;";
154 echo "</td><td>";
155 $var = "backup_user_info_".$modname;
156 if (empty($to)) {
157 $backup_user_options[0] = get_string("withoutuserdata");
158 $backup_user_options[1] = get_string("withuserdata");
159 //choose_from_menu($backup_user_options, $var, $$var, "");
160 print_checkbox($var, $$var, $$var, get_string("userdata"),'','selectItemInCheckboxByName(\'form1\',\'backup_user_info_'.$modname.'\',this.checked)');
161 } else {
162 echo '<input type="hidden" name="'.$var.'" value="0" />';
164 echo "</td></tr>\n";
165 // if we have the backup_one_mod function, loop here.
166 $var = 'exists_one_'.$modname;
167 if (!empty($$var)) {
168 echo '<tr><td></td><td colspan="3"><table class="backup-form-instances">';
169 $instances = get_all_instances_in_course($modname,$course);
170 foreach ($instances as $instance) {
171 echo '<tr><td>';
172 $var = 'backup_'.$modname.'_instance_'.$instance->id;
173 $$var = optional_param($var,1);
174 print_checkbox($var,$$var,$$var,$instance->name,$instance->name,'this.form.elements[\'backup_'.$modname.'\'].checked=1;');
175 echo '</td><td align="right">&nbsp;';
176 $var = 'backup_user_info_'.$modname.'_instance_'.$instance->id;
177 $$var = optional_param($var,1);
178 if (empty($to)) {
179 print_checkbox($var,$$var,$$var,get_string('userdata'),'','this.form.elements[\'backup_user_info_'.$modname.'\'].checked=1;');
180 } else {
181 echo '<input type="hidden" name="'.$var.'" value="0" />';
183 echo '</td></tr>';
185 echo '</table></td></tr>';
190 //Line
191 echo "<tr><td colspan=\"4\"><hr /></td></tr>\n";
193 if (empty($to)) {
194 //Now print the Metacourse tr
195 echo "<tr>";
196 echo "<td align=\"right\" colspan=\"2\"><b>";
197 echo get_string ("metacourse").":";
198 echo "</b></td><td colspan=\"2\">";
199 $meta_options[0] = get_string("no");
200 $meta_options[1] = get_string("yes");
201 choose_from_menu($meta_options, "backup_metacourse", $backup_metacourse, "");
202 echo "</td></tr>";
204 else {
205 echo '<input type="hidden" name="backup_metacourse" value="0" />';
208 if (empty($to)) {
209 //Now print the Users tr
210 echo "<tr>";
211 echo "<td align=\"right\" colspan=\"2\"><b>";
212 echo get_string("users").":";
213 echo "</b></td><td colspan=\"2\">";
214 $user_options[0] = get_string("all");
215 $user_options[1] = get_string("course");
216 $user_options[2] = get_string("none");
217 choose_from_menu($user_options, "backup_users", $backup_users, "");
218 echo "</td></tr>";
220 else {
221 echo '<input type="hidden" name="backup_users" value="0" />';
224 if (empty($to)) {
225 //Now print the Logs tr
226 echo "<tr>";
227 echo "<td align=\"right\" colspan=\"2\"><b>";
228 echo get_string("logs").":";
229 echo "</b></td><td colspan=\"2\">";
230 $log_options[0] = get_string("no");
231 $log_options[1] = get_string("yes");
232 choose_from_menu($log_options, "backup_logs", $backup_logs, "");
233 echo "</td></tr>";
235 else {
236 echo '<input type="hidden" name="backup_logs" value="0" />';
239 if (empty($to)) {
240 //Now print the User Files tr
241 echo "<tr>";
242 echo "<td align=\"right\" colspan=\"2\"><b>";
243 echo get_string ("userfiles").":";
244 echo "</b></td><td colspan=\"2\">";
245 $user_file_options[0] = get_string("no");
246 $user_file_options[1] = get_string("yes");
247 choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, "");
248 echo "</td></tr>";
250 else {
251 echo '<input type="hidden" name="backup_user_files" value="0" />';
253 //Now print the Course Files tr
254 echo "<tr>";
255 echo "<td align=\"right\" colspan=\"2\"><b>";
256 echo get_string ("coursefiles").":";
257 echo "</b></td><td colspan=\"2\">";
258 $course_file_options[0] = get_string("no");
259 $course_file_options[1] = get_string("yes");
260 choose_from_menu($course_file_options, "backup_course_files", $backup_course_files, "");
261 echo "</td></tr>";
263 if (empty($to) && $course->id == SITEID) {
264 //If we are in a SITEID backup print the Messages tr
265 echo "<tr>";
266 echo "<td align=\"right\" colspan=\"2\"><b>";
267 echo get_string ('messages','message').":";
268 echo "</b></td><td colspan=\"2\">";
269 $mess_options[0] = get_string("no");
270 $mess_options[1] = get_string("yes");
271 choose_from_menu($mess_options, "backup_messages", $backup_messages, "");
272 echo "</td></tr>";
274 else {
275 echo '<input type="hidden" name="backup_messages" value="0" />';
279 $backup_unique_code = time();
281 //Calculate the backup string
282 //Calculate the backup unique code to allow simultaneus backups (to define
283 //the temp-directory name and records in backup temp tables
284 $backup_name = backup_get_zipfile_name($course, $backup_unique_code);
286 </table>
288 <div style="text-align:center;margin-left:auto;margin-right:auto">
289 <input type="hidden" name="id" value="<?php p($id) ?>" />
290 <input type="hidden" name="to" value="<?php p($to) ?>" />
291 <input type="hidden" name="backup_unique_code" value="<?php p($backup_unique_code); ?>" />
292 <input type="hidden" name="backup_name" value="<?php p($backup_name); ?>" />
293 <input type="hidden" name="launch" value="check" />
294 <input type="submit" value="<?php print_string("continue") ?>" />
295 <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
296 </div>
297 </form>