Automatic installer.php lang files by installer_builder (20070117)
[moodle.git] / backup / backup_execute.html
blobdabed9e04dfe9ee950c827410206aee4e1f536e1
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 (!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");
24 //Check site
25 if (!$site = get_site()) {
26 error("Site not found!");
29 $preferences = new StdClass;
30 backup_fetch_prefs_from_request($preferences,$count,$course);
31 //Another Info
32 $preferences->moodle_version = $CFG->version;
33 $preferences->moodle_release = $CFG->release;
34 $preferences->backup_version = $CFG->backup_version;
35 $preferences->backup_release = $CFG->backup_release;
37 if ($count == 0) {
38 notice("No backupable modules are installed!");
42 if (empty($to)) {
43 //Start the main table
44 echo "<table cellpadding=\"5\">";
46 //Now print the Backup Name tr
47 echo "<tr>";
48 echo "<td align=\"right\"><b>";
49 echo get_string("name").":";
50 echo "</b></td><td>";
51 echo $preferences->backup_name;
52 echo "</td></tr>";
54 //Start the main tr, where all the backup progress is done
55 echo "<tr>";
56 echo "<td colspan=\"2\">";
58 //Start the main ul
59 echo "<ul>";
61 //Check for temp and backup and backup_unique_code directory
62 //Create them as needed
63 echo "<li>".get_string("creatingtemporarystructures").'</li>';
64 $status = check_and_create_backup_dir($preferences->backup_unique_code);
65 //Empty dir
66 if ($status) {
67 $status = clear_backup_dir($preferences->backup_unique_code);
70 //Delete old_entries from backup tables
71 echo "<li>".get_string("deletingolddata").'</li>';
72 $status = backup_delete_old_data();
73 if (!$status) {
74 error ("An error occurred deleting old backup data");
77 //Create the moodle.xml file
78 if ($status) {
79 echo "<li>".get_string("creatingxmlfile");
80 //Begin a new list to xml contents
81 echo "<ul>";
82 echo "<li>".get_string("writingheader").'</li>';
83 //Obtain the xml file (create and open) and print prolog information
84 $backup_file = backup_open_xml($preferences->backup_unique_code);
85 echo "<li>".get_string("writinggeneralinfo").'</li>';
86 //Prints general info about backup to file
87 if ($backup_file) {
88 if (!$status = backup_general_info($backup_file,$preferences)) {
89 notify("An error occurred while backing up general info");
92 echo "<li>".get_string("writingcoursedata");
94 //Start new ul (for course)
95 echo "<ul>";
97 echo "<li>".get_string("courseinfo").'</li>';
98 //Prints course start (tag and general info)
99 if ($status) {
100 if (!$status = backup_course_start($backup_file,$preferences)) {
101 notify("An error occurred while backing up course start");
104 //Metacourse information
105 if ($status && $preferences->backup_metacourse) {
106 echo "<li>".get_string("metacourse").'</li>';
107 if (!$status = backup_course_metacourse($backup_file,$preferences)) {
108 notify("An error occurred while backing up metacourse info");
111 echo "<li>".get_string("blocks").'</li>';
112 //Blocks information
113 if ($status) {
114 if (!$status = backup_course_blocks($backup_file,$preferences)) {
115 notify("An error occurred while backing up course blocks");
118 echo "<li>".get_string("sections").'</li>';
119 //Section info
120 if ($status) {
121 if (!$status = backup_course_sections($backup_file,$preferences)) {
122 notify("An error occurred while backing up course sections");
126 //End course contents (close ul)
127 echo "</ul></li>";
129 //User info
130 if ($status) {
131 echo "<li>".get_string("writinguserinfo").'</li>';
132 if (!$status = backup_user_info($backup_file,$preferences)) {
133 notify("An error occurred while backing up user info");
137 //If we have selected to backup messages and we are
138 //doing a SITE backup, let's do it
139 if ($status && $preferences->backup_messages && $preferences->backup_course == SITEID) {
140 echo "<li>".get_string("writingmessagesinfo").'</li>';
141 if (!$status = backup_messages($backup_file,$preferences)) {
142 notify("An error occurred while backing up messages");
146 //If we have selected to backup quizzes, backup categories and
147 //questions structure (step 1). See notes on mod/quiz/backuplib.php
148 if ($status and !empty($preferences->mods['quiz']->backup)) {
149 echo "<li>".get_string("writingcategoriesandquestions").'</li>';
150 require_once($CFG->dirroot.'/mod/quiz/backuplib.php');
151 if (!$status = backup_question_categories($backup_file,$preferences)) {
152 notify("An error occurred while backing up quiz categories");
156 //Print logs if selected
157 if ($status) {
158 if ($preferences->backup_logs) {
159 echo "<li>".get_string("writingloginfo").'</li>';
160 if (!$status = backup_log_info($backup_file,$preferences)) {
161 notify("An error occurred while backing up log info");
166 //Print scales info
167 if ($status) {
168 echo "<li>".get_string("writingscalesinfo").'</li>';
169 if (!$status = backup_scales_info($backup_file,$preferences)) {
170 notify("An error occurred while backing up scales");
174 //Print groups info
175 if ($status) {
176 echo "<li>".get_string("writinggroupsinfo").'</li>';
177 if (!$status = backup_groups_info($backup_file,$preferences)) {
178 notify("An error occurred while backing up groups");
182 //Print events info
183 if ($status) {
184 echo "<li>".get_string("writingeventsinfo").'</li>';
185 if (!$status = backup_events_info($backup_file,$preferences)) {
186 notify("An error occurred while backing up events");
190 //Print gradebook info
191 if ($status) {
192 echo "<li>".get_string("writinggradebookinfo").'</li>';
193 if (!$status = backup_gradebook_info($backup_file,$preferences)) {
194 notify("An error occurred while backing up gradebook");
198 //Module info, this unique function makes all the work!!
199 //db export and module fileis copy
200 if ($status) {
201 $mods_to_backup = false;
202 //Check if we have any mod to backup
203 foreach ($preferences->mods as $module) {
204 if ($module->backup) {
205 $mods_to_backup = true;
208 //If we have to backup some module
209 if ($mods_to_backup) {
210 echo "<li>".get_string("writingmoduleinfo");
211 //Start modules tag
212 if (!$status = backup_modules_start ($backup_file,$preferences)) {
213 notify("An error occurred while backing up module info");
215 //Open ul for module list
216 echo "<ul>";
217 //Iterate over modules and call backup
218 foreach ($preferences->mods as $module) {
219 if ($module->backup and $status) {
220 echo "<li>".get_string("modulenameplural",$module->name).'</li>';
221 if (!$status = backup_module($backup_file,$preferences,$module->name)) {
222 notify("An error occurred while backing up '$module->name'");
226 //Close ul for module list
227 echo "</ul></li>";
228 //Close modules tag
229 if (!$status = backup_modules_end ($backup_file,$preferences)) {
230 notify("An error occurred while finishing the module backups");
235 //Prints course end
236 if ($status) {
237 if (!$status = backup_course_end($backup_file,$preferences)) {
238 notify("An error occurred while closing the course backup");
241 //Close the xml file and xml data
242 if ($backup_file) {
243 backup_close_xml($backup_file);
246 //End xml contents (close ul)
247 echo "</ul></li>";
250 //Now, if selected, copy user files
251 if ($status) {
252 if ($preferences->backup_user_files) {
253 echo "<li>".get_string("copyinguserfiles").'</li>';
254 if (!$status = backup_copy_user_files ($preferences)) {
255 notify("An error occurred while copying user files");
260 //Now, if selected, copy course files
261 if ($status) {
262 if ($preferences->backup_course_files) {
263 echo "<li>".get_string("copyingcoursefiles").'</li>';
264 if (!$status = backup_copy_course_files ($preferences)) {
265 notify("An error occurred while copying course files");
270 //Now, zip all the backup directory contents
271 if ($status) {
272 echo "<li>".get_string("zippingbackup").'</li>';
273 if (!$status = backup_zip ($preferences)) {
274 notify("An error occurred while zipping the backup");
278 //Now, copy the zip file to course directory
279 if ($status) {
280 echo "<li>".get_string("copyingzipfile").'</li>';
281 if (!$status = copy_zip_to_course_dir ($preferences)) {
282 notify("An error occurred while copying the zip file to the course directory");
286 //Now, clean temporary data (db and filesystem)
287 if ($status) {
288 echo "<li>".get_string("cleaningtempdata").'</li>';
289 if (!$status = clean_temp_data ($preferences)) {
290 notify("An error occurred while cleaning up temporary data");
294 //Ends th main ul
295 echo "</ul>";
297 //End the main tr, where all the backup is done
298 echo "</td></tr>";
300 //End the main table
301 echo "</table>";
303 if (!$status) {
304 error ("The backup did not complete successfully",
305 "$CFG->wwwroot/course/view.php?id=$course->id");
308 if (empty($to)) {
309 //Print final message
310 print_simple_box(get_string("backupfinished"),"center");
311 print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&amp;wdir=/backupdata");
312 } else {
313 print_simple_box(get_string('importdataexported'),"CENTER");
314 if (!empty($preferences->backup_destination)) {
315 $filename = $preferences->backup_destination."/".$preferences->backup_name;
316 } else {
317 $filename = $preferences->backup_course."/backupdata/".$preferences->backup_name;
319 error_log($filename);
320 $SESSION->import_preferences = $preferences;
321 print_continue($CFG->wwwroot.'/course/import/activities/index.php?id='.$to.'&fromcourse='.$id.'&filename='.$filename);
324 $SESSION->backupprefs[$course->id] = null; // unset it so we're clear next time.