Incorrect variable name used for parameter.
[moodle-linuxchix.git] / backup / backup_execute.html
blobeea9099b90718b078f0d6d906e9178726ceef4e8
1 <?php //$Id$
2 //This page prints the backup todo list to see everything
4 //Check login
5 require_login();
7 if (!empty($course->id)) {
8 if (!isteacheredit($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 (!isteacheredit($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 (!isadmin()) {
19 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
24 //Check site
25 if (!$site = get_site()) {
26 error("Site not found!");
29 //Checks for the required files/functions to backup every mod
30 //And check if there is data about it
31 $count = 0;
32 if ($allmods = get_records("modules") ) {
33 foreach ($allmods as $mod) {
34 $modname = $mod->name;
35 $modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
36 $modbackup = $modname."_backup_mods";
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++;
46 //Check data
47 //Check module info
48 $var = "backup_".$modname;
49 if (!isset($$var)) {
50 //Every undefined backup_XXXX isn't exported
51 $$var = 0;
53 //Now stores all the mods preferences into an array into preferences
54 $preferences->mods[$modname]->backup = $$var;
56 //Check include user info
57 $var = "backup_user_info_".$modname;
58 if (!isset($$var)) {
59 $$var = 1;
61 //Now stores all the mods preferences into an array into preferences
62 $preferences->mods[$modname]->userinfo = $$var;
63 //And the name of the mod
64 $preferences->mods[$modname]->name = $modname;
68 //Check other parameters
69 if (!isset($backup_metacourse)) {
70 $backup_metacourse = 1;
72 $preferences->backup_metacourse = $backup_metacourse;
74 if (!isset($backup_users)) {
75 $backup_users = 1;
77 $preferences->backup_users = $backup_users;
79 if (!isset($backup_logs)) {
80 $backup_logs = 0;
82 $preferences->backup_logs = $backup_logs;
84 if (!isset($backup_user_files)) {
85 $backup_user_files = 1;
87 $preferences->backup_user_files = $backup_user_files;
89 if (!isset($backup_course_files)) {
90 $backup_course_files = 2;
92 $preferences->backup_course_files = $backup_course_files;
94 if (!isset($backup_messages)) {
95 $backup_messages = 1;
97 $preferences->backup_messages = $backup_messages;
99 if (!isset($id)) {
100 error ("Course not specified");
102 $preferences->backup_course = $id;
104 if (!isset($backup_name)) {
105 error ("Backup name not specified");
107 //We clean it again (to prevent diacritics entered manually)
108 $preferences->backup_name = clean_filename($backup_name);
110 if (!isset($backup_unique_code)) {
111 error ("Backup unique code not specified");
113 $preferences->backup_unique_code = $backup_unique_code;
115 //Another Info
116 $preferences->moodle_version = $CFG->version;
117 $preferences->moodle_release = $CFG->release;
118 $preferences->backup_version = $CFG->backup_version;
119 $preferences->backup_release = $CFG->backup_release;
121 if ($count == 0) {
122 notice("No backupable modules are installed!");
126 if (empty($to)) {
127 //Start the main table
128 echo "<table cellpadding=\"5\">";
130 //Now print the Backup Name tr
131 echo "<tr>";
132 echo "<td align=\"right\"><b>";
133 echo get_string("name").":";
134 echo "</b></td><td>";
135 echo $preferences->backup_name;
136 echo "</td></tr>";
138 //Start the main tr, where all the backup progress is done
139 echo "<tr>";
140 echo "<td colspan=\"2\">";
142 //Start the main ul
143 echo "<ul>";
145 //Check for temp and backup and backup_unique_code directory
146 //Create them as needed
147 echo "<li>".get_string("creatingtemporarystructures").'</li>';
148 $status = check_and_create_backup_dir($backup_unique_code);
149 //Empty dir
150 if ($status) {
151 $status = clear_backup_dir($backup_unique_code);
154 //Delete old_entries from backup tables
155 echo "<li>".get_string("deletingolddata").'</li>';
156 $status = backup_delete_old_data();
157 if (!$status) {
158 error ("An error occurred deleting old backup data");
161 //Create the moodle.xml file
162 if ($status) {
163 echo "<li>".get_string("creatingxmlfile");
164 //Begin a new list to xml contents
165 echo "<ul>";
166 echo "<li>".get_string("writingheader").'</li>';
167 //Obtain the xml file (create and open) and print prolog information
168 $backup_file = backup_open_xml($backup_unique_code);
169 echo "<li>".get_string("writinggeneralinfo").'</li>';
170 //Prints general info about backup to file
171 if ($backup_file) {
172 if (!$status = backup_general_info($backup_file,$preferences)) {
173 notify("An error occurred while backing up general info");
176 echo "<li>".get_string("writingcoursedata");
178 //Start new ul (for course)
179 echo "<ul>";
181 echo "<li>".get_string("courseinfo").'</li>';
182 //Prints course start (tag and general info)
183 if ($status) {
184 if (!$status = backup_course_start($backup_file,$preferences)) {
185 notify("An error occurred while backing up course start");
188 //Metacourse information
189 if ($status && $preferences->backup_metacourse) {
190 echo "<li>".get_string("metacourse").'</li>';
191 if (!$status = backup_course_metacourse($backup_file,$preferences)) {
192 notify("An error occurred while backing up metacourse info");
195 echo "<li>".get_string("blocks").'</li>';
196 //Blocks information
197 if ($status) {
198 if (!$status = backup_course_blocks($backup_file,$preferences)) {
199 notify("An error occurred while backing up course blocks");
202 echo "<li>".get_string("sections").'</li>';
203 //Section info
204 if ($status) {
205 if (!$status = backup_course_sections($backup_file,$preferences)) {
206 notify("An error occurred while backing up course sections");
210 //End course contents (close ul)
211 echo "</ul></li>";
213 //User info
214 if ($status && $preferences->backup_users) {
215 echo "<li>".get_string("writinguserinfo").'</li>';
216 if (!$status = backup_user_info($backup_file,$preferences)) {
217 notify("An error occurred while backing up user info");
221 //If we have selected to backup messages and we are
222 //doing a SITE backup, let's do it
223 if ($status && $preferences->backup_messages && $preferences->backup_course == SITEID) {
224 echo "<li>".get_string("writingmessagesinfo").'</li>';
225 if (!$status = backup_messages($backup_file,$preferences)) {
226 notify("An error occurred while backing up messages");
230 //If we have selected to backup quizzes, backup categories and
231 //questions structure (step 1). See notes on mod/quiz/backuplib.php
232 if ($status and $preferences->mods['quiz']->backup) {
233 echo "<li>".get_string("writingcategoriesandquestions").'</li>';
234 if (!$status = quiz_backup_question_categories($backup_file,$preferences)) {
235 notify("An error occurred while backing up quiz categories");
239 //Print logs if selected
240 if ($status) {
241 if ($preferences->backup_logs) {
242 echo "<li>".get_string("writingloginfo").'</li>';
243 if (!$status = backup_log_info($backup_file,$preferences)) {
244 notify("An error occurred while backing up log info");
249 //Print scales info
250 if ($status) {
251 echo "<li>".get_string("writingscalesinfo").'</li>';
252 if (!$status = backup_scales_info($backup_file,$preferences)) {
253 notify("An error occurred while backing up scales");
257 //Print groups info
258 if ($status) {
259 echo "<li>".get_string("writinggroupsinfo").'</li>';
260 if (!$status = backup_groups_info($backup_file,$preferences)) {
261 notify("An error occurred while backing up groups");
265 //Print events info
266 if ($status) {
267 echo "<li>".get_string("writingeventsinfo").'</li>';
268 if (!$status = backup_events_info($backup_file,$preferences)) {
269 notify("An error occurred while backing up events");
273 //Print gradebook info
274 if ($status) {
275 echo "<li>".get_string("writinggradebookinfo").'</li>';
276 if (!$status = backup_gradebook_info($backup_file,$preferences)) {
277 notify("An error occurred while backing up gradebook");
281 //Module info, this unique function makes all the work!!
282 //db export and module fileis copy
283 if ($status) {
284 $mods_to_backup = false;
285 //Check if we have any mod to backup
286 foreach ($preferences->mods as $module) {
287 if ($module->backup) {
288 $mods_to_backup = true;
291 //If we have to backup some module
292 if ($mods_to_backup) {
293 echo "<li>".get_string("writingmoduleinfo");
294 //Start modules tag
295 if (!$status = backup_modules_start ($backup_file,$preferences)) {
296 notify("An error occurred while backing up module info");
298 //Open ul for module list
299 echo "<ul>";
300 //Iterate over modules and call backup
301 foreach ($preferences->mods as $module) {
302 if ($module->backup and $status) {
303 echo "<li>".get_string("modulenameplural",$module->name).'</li>';
304 if (!$status = backup_module($backup_file,$preferences,$module->name)) {
305 notify("An error occurred while backing up '$module->name'");
309 //Close ul for module list
310 echo "</ul></li>";
311 //Close modules tag
312 if (!$status = backup_modules_end ($backup_file,$preferences)) {
313 notify("An error occurred while finishing the module backups");
318 //Prints course end
319 if ($status) {
320 if (!$status = backup_course_end($backup_file,$preferences)) {
321 notify("An error occurred while closing the course backup");
324 //Close the xml file and xml data
325 if ($backup_file) {
326 backup_close_xml($backup_file);
329 //End xml contents (close ul)
330 echo "</ul></li>";
333 //Now, if selected, copy user files
334 if ($status) {
335 if ($preferences->backup_user_files) {
336 echo "<li>".get_string("copyinguserfiles").'</li>';
337 if (!$status = backup_copy_user_files ($preferences)) {
338 notify("An error occurred while copying user files");
343 //Now, if selected, copy course files
344 if ($status) {
345 if ($preferences->backup_course_files) {
346 echo "<li>".get_string("copyingcoursefiles").'</li>';
347 if (!$status = backup_copy_course_files ($preferences)) {
348 notify("An error occurred while copying course files");
353 //Now, zip all the backup directory contents
354 if ($status) {
355 echo "<li>".get_string("zippingbackup").'</li>';
356 if (!$status = backup_zip ($preferences)) {
357 notify("An error occurred while zipping the backup");
361 //Now, copy the zip file to course directory
362 if ($status) {
363 echo "<li>".get_string("copyingzipfile").'</li>';
364 if (!$status = copy_zip_to_course_dir ($preferences)) {
365 notify("An error occurred while copying the zip file to the course directory");
369 //Now, clean temporary data (db and filesystem)
370 if ($status) {
371 echo "<li>".get_string("cleaningtempdata").'</li>';
372 if (!$status = clean_temp_data ($preferences)) {
373 notify("An error occurred while cleaning up temporary data");
377 //Ends th main ul
378 echo "</ul>";
380 //End the main tr, where all the backup is done
381 echo "</td></tr>";
383 //End the main table
384 echo "</table>";
386 if (!$status) {
387 error ("The backup did not complete successfully",
388 "$CFG->wwwroot/course/view.php?id=$course->id");
391 if (empty($to)) {
392 //Print final message
393 print_simple_box(get_string("backupfinished"),"center");
394 print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&amp;wdir=/backupdata");
395 } else {
396 print_simple_box(get_string('importdataexported'),"CENTER");
397 if (!empty($preferences->backup_destination)) {
398 $filename = $preferences->backup_destination."/".$preferences->backup_name;
399 } else {
400 $filename = $preferences->backup_course."/backupdata/".$preferences->backup_name;
402 error_log($filename);
403 $SESSION->import_preferences = $preferences;
404 print_continue($CFG->wwwroot.'/course/import.php?id='.$to.'&fromcourse='.$id.'&filename='.$filename);