2 //This page prints the backup todo list to see everything
7 if (!empty($course->id
)) {
8 if (!isteacheredit($course->id
)) {
10 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
12 if (!isteacheredit($to)) {
13 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
19 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
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
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;
48 $var = "backup_".$modname;
50 //Every undefined backup_XXXX isn't exported
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;
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)) {
77 $preferences->backup_users
= $backup_users;
79 if (!isset($backup_logs)) {
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)) {
97 $preferences->backup_messages
= $backup_messages;
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;
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
;
122 notice("No backupable modules are installed!");
127 //Start the main table
128 echo "<table cellpadding=\"5\">";
130 //Now print the Backup Name tr
132 echo "<td align=\"right\"><b>";
133 echo get_string("name").":";
134 echo "</b></td><td>";
135 echo $preferences->backup_name
;
138 //Start the main tr, where all the backup progress is done
140 echo "<td colspan=\"2\">";
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);
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();
158 error ("An error occurred deleting old backup data");
161 //Create the moodle.xml file
163 echo "<li>".get_string("creatingxmlfile");
164 //Begin a new list to xml contents
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
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)
181 echo "<li>".get_string("courseinfo").'</li>';
182 //Prints course start (tag and general info)
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>';
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>';
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)
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
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");
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");
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");
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
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
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");
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
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
312 if (!$status = backup_modules_end ($backup_file,$preferences)) {
313 notify("An error occurred while finishing the module backups");
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
326 backup_close_xml($backup_file);
329 //End xml contents (close ul)
333 //Now, if selected, copy user files
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
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
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
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)
371 echo "<li>".get_string("cleaningtempdata").'</li>';
372 if (!$status = clean_temp_data ($preferences)) {
373 notify("An error occurred while cleaning up temporary data");
380 //End the main tr, where all the backup is done
387 error ("The backup did not complete successfully",
388 "$CFG->wwwroot/course/view.php?id=$course->id");
392 //Print final message
393 print_simple_box(get_string("backupfinished"),"center");
394 print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course
."&wdir=/backupdata");
396 print_simple_box(get_string('importdataexported'),"CENTER");
397 if (!empty($preferences->backup_destination
)) {
398 $filename = $preferences->backup_destination
."/".$preferences->backup_name
;
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);