Fixing up a problem in chat login - ip address is lastip not lastIP - member variable...
[moodle.git] / backup / backup_form.html
CommitLineData
7ef0797d 1<?php //$Id$
a615cc7b 2 //This page prints the backup form to select everything
3
c563a9a0 4 //Check login
5 require_login();
6
bd38123e 7 if (!empty($course->id)) {
63bcc9b5 8 if (!isteacheredit($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 {
12 if (!isteacheredit($to)) {
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 {
18 if (!isadmin()) {
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
a615cc7b 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;
9c1ae5ae 34 $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
a615cc7b 35 $modbackup = $modname."_backup_mods";
36 $modcheckbackup = $modname."_check_backup_mods";
37 if (file_exists($modfile)) {
38 include_once($modfile);
39 if (function_exists($modbackup) and function_exists($modcheckbackup)) {
40 $var = "exists_".$modname;
41 $$var = true;
42 $count++;
43 }
44 }
45 //Check data
46 //Check module info
47 $var = "backup_".$modname;
1517803d 48 $$var = optional_param( $var,1);
a615cc7b 49 //Check include user info
50 $var = "backup_user_info_".$modname;
1517803d 51 $$var = optional_param( $var,1);
a615cc7b 52 }
53 }
54
55 //Check other parameters
1517803d 56 $backup_metacourse = optional_param('backup_metacourse',1);
57 $backup_users = optional_param('backup_users',1);
58 $backup_logs = optional_param('backup_logs',0);
59 $backup_user_files = optional_param('backup_user_files',1);
60 $backup_course_files = optional_param('backup_course_files',1);
61 $backup_messages = optional_param('backup_messages',1);
57224893 62
1517803d 63 if ($count == 0) {
64 notice("No backupable modules are installed!");
a615cc7b 65 }
66
1517803d 67?>
a615cc7b 68
1517803d 69<script language="JavaScript" type="text/javascript">
70<!--
71function selectItemInMenuByName(formId, menuName, selectIndex ) {
72 myForm = document.getElementById(formId)
73 for (i=0,n=myForm.elements.length;i<n;i++) {
74 myLen = menuName.length;
75 myName = myForm.elements[i].name;
76 myType = myForm.elements[i].type;
77 if (myName.substring(0,myLen) == menuName && myType == "select-one") {
78 myForm.elements[i].options[selectIndex].selected = true;
79 }
a615cc7b 80 }
1517803d 81}
a615cc7b 82
1517803d 83function selectItemInRadioByName(formId, radioName, selectIndex ) {
84 myForm = document.getElementById(formId)
85 for (i=0,n=myForm.elements.length;i<n;i++) {
86 myLen = radioName.length;
87 myName = myForm.elements[i].name;
88 myType = myForm.elements[i].type;
89 if (myName.substring(0,myLen) == radioName && myType == "radio") {
90 myRadioGroup = myForm.elements[myName];
91 myRadioGroup[selectIndex].checked = true;
92 }
70641539 93 }
1517803d 94}
70641539 95
1517803d 96function selectItemInCheckboxByName(formId, checkName, checked ) {
97 myForm = document.getElementById(formId)
98 for (i=0,n=myForm.elements.length;i<n;i++) {
99 myLen = checkName.length;
100 myName = myForm.elements[i].name;
101 myType = myForm.elements[i].type;
102 if (myName.substring(0,myLen) == checkName && myType == "checkbox") {
103 myForm.elements[i].checked = checked;
104 }
a615cc7b 105 }
1517803d 106}
107-->
108</script>
a615cc7b 109
1517803d 110<form name="form1" id="form1" method="post" action="backup.php">
7ef0797d 111<table cellpadding="5">
145cb8f9 112<?php
1517803d 113 //Now, check modules and info and show posibilities
a615cc7b 114 if ($allmods = get_records("modules") ) {
1517803d 115 //Print option to select/deselect everything with 1 click.
116 echo "<tr>";
117 echo "<td align=\"right\">";
118 echo '<b>'.get_string("include").":</b>";
119 echo "</td><td>";
120 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', true);\">". get_string("all")."</a>/";
121 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_', false);\">". get_string("none")."</a>";
122 echo "</td>";
123 echo "<td align=\"right\">";
124 echo '<b>&nbsp;</b>';
125 echo "</td><td>";
126 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', true);\">". get_string("all")."</a>/";
127 echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'backup_user_info_', false);\">". get_string("none")."</a>";
128 echo "</td>";
129 echo "</tr>";
130 echo "<tr><td colspan=\"4\"><hr /></td></tr>";
131 $currentrow = 0;
a615cc7b 132 foreach ($allmods as $mod) {
133 $modname = $mod->name;
134 $modbackup = $modname."_backup_mods";
135 //If exists the lib & function
136 $var = "exists_".$modname;
142a6a46 137 if (isset($$var) && $$var) {
a615cc7b 138 //Print the full tr
1517803d 139 echo "<tr class=\"r".$currentrow."\">";
140 echo " <td align=\"right\">&nbsp;";
141 echo "</td><td>\n";
a615cc7b 142 $backup_options[0] = get_string("no");
143 $backup_options[1] = get_string("yes");
144 $var = "backup_".$modname;
1517803d 145 //choose_from_menu($backup_options, $var, $$var, "");
146 //Print the checkbox
147 print_checkbox($var, $$var, $$var, get_string("modulenameplural",$modname));
a615cc7b 148 $var = "backup_user_info_".$modname;
1517803d 149 echo "</td><td align=\"right\">&nbsp;";
150 echo "</td><td>";
873bf875 151 if (empty($to)) {
152 $backup_user_options[0] = get_string("withoutuserdata");
153 $backup_user_options[1] = get_string("withuserdata");
1517803d 154 //choose_from_menu($backup_user_options, $var, $$var, "");
155 print_checkbox($var, $$var, $$var, get_string("userdata"));
156 } else {
873bf875 157 echo '<input type="hidden" name="'.$var.'" value="0" />';
158 }
35a4a791 159 echo "</td></tr>\n";
a615cc7b 160 }
161 }
162 //Line
1517803d 163 echo "<tr><td colspan=\"4\"><hr /></td></tr>\n";
873bf875 164
57224893 165 if (empty($to)) {
166 //Now print the Metacourse tr
167 echo "<tr>";
1517803d 168 echo "<td align=\"right\" colspan=\"2\"><b>";
57224893 169 echo get_string ("metacourse").":";
1517803d 170 echo "</b></td><td colspan=\"2\">";
57224893 171 $meta_options[0] = get_string("no");
172 $meta_options[1] = get_string("yes");
173 choose_from_menu($meta_options, "backup_metacourse", $backup_metacourse, "");
174 echo "</td></tr>";
175 }
176 else {
177 echo '<input type="hidden" name="backup_metacourse" value="0" />';
178 }
179
873bf875 180 if (empty($to)) {
181 //Now print the Users tr
182 echo "<tr>";
1517803d 183 echo "<td align=\"right\" colspan=\"2\"><b>";
873bf875 184 echo get_string("users").":";
1517803d 185 echo "</b></td><td colspan=\"2\">";
873bf875 186 $user_options[0] = get_string("all");
187 $user_options[1] = get_string("course");
188 $user_options[2] = get_string("none");
189 choose_from_menu($user_options, "backup_users", $backup_users, "");
190 echo "</td></tr>";
191 }
192 else {
193 echo '<input type="hidden" name="backup_users" value="0" />';
194 }
195
196 if (empty($to)) {
197 //Now print the Logs tr
198 echo "<tr>";
1517803d 199 echo "<td align=\"right\" colspan=\"2\"><b>";
873bf875 200 echo get_string("logs").":";
1517803d 201 echo "</b></td><td colspan=\"2\">";
873bf875 202 $log_options[0] = get_string("no");
203 $log_options[1] = get_string("yes");
204 choose_from_menu($log_options, "backup_logs", $backup_logs, "");
205 echo "</td></tr>";
206 }
207 else {
208 echo '<input type="hidden" name="backup_logs" value="0" />';
209 }
ef9b35a0 210
873bf875 211 if (empty($to)) {
212 //Now print the User Files tr
213 echo "<tr>";
1517803d 214 echo "<td align=\"right\" colspan=\"2\"><b>";
873bf875 215 echo get_string ("userfiles").":";
1517803d 216 echo "</b></td><td colspan=\"2\">";
873bf875 217 $user_file_options[0] = get_string("no");
218 $user_file_options[1] = get_string("yes");
219 choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, "");
220 echo "</td></tr>";
221 }
222 else {
223 echo '<input type="hidden" name="backup_user_files" value="0" />';
224 }
a615cc7b 225 //Now print the Course Files tr
226 echo "<tr>";
1517803d 227 echo "<td align=\"right\" colspan=\"2\"><b>";
a615cc7b 228 echo get_string ("coursefiles").":";
1517803d 229 echo "</b></td><td colspan=\"2\">";
a615cc7b 230 $course_file_options[0] = get_string("no");
231 $course_file_options[1] = get_string("yes");
232 choose_from_menu($course_file_options, "backup_course_files", $backup_course_files, "");
233 echo "</td></tr>";
70641539 234
235 if (empty($to) && $course->id == SITEID) {
236 //If we are in a SITEID backup print the Messages tr
237 echo "<tr>";
1517803d 238 echo "<td align=\"right\" colspan=\"2\"><b>";
70641539 239 echo get_string ('messages','message').":";
1517803d 240 echo "</b></td><td colspan=\"2\">";
70641539 241 $mess_options[0] = get_string("no");
242 $mess_options[1] = get_string("yes");
243 choose_from_menu($mess_options, "backup_messages", $backup_messages, "");
244 echo "</td></tr>";
245 }
246 else {
247 echo '<input type="hidden" name="backup_messages" value="0" />';
248 }
a615cc7b 249 }
250?>
251</table>
7ef0797d 252<br />
253<center>
873bf875 254<input type="hidden" name="id" value="<?php p($id) ?>" />
255<input type="hidden" name="to" value="<?php p($to) ?>" />
256<input type="hidden" name="launch" value="check" />
257<input type="submit" value="<?php print_string("continue") ?>" />
258<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
7ef0797d 259</center>
260</form>