2 // index.php - scheduled backup logs
4 require_once('../../../config.php');
5 require_once($CFG->libdir
.'/adminlib.php');
6 require_once($CFG->dirroot
.'/backup/lib.php');
8 admin_externalpage_setup('reportbackups');
10 admin_externalpage_print_header();
12 $courseid = optional_param('courseid', 0, PARAM_INT
);
14 require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM
));
16 /// Scheduled backups are disabled by the server admin
17 if (!empty($CFG->disablescheduledbackups
)) {
18 print_error('scheduledbackupsdisabled', '', '', NULL, true);
21 /// Scheduled backups aren't active by the site admin
22 $backup_config = backup_get_config();
23 if (empty($backup_config->backup_sche_active
)) {
24 notify(get_string('scheduledbackupsinactive'));
27 /// Get needed strings
28 $backuploglaststatus = get_string("backuploglaststatus");
29 $backuplogdetailed = get_string("backuplogdetailed");
30 $stradmin = get_string("administration");
31 $strconfiguration = get_string("configuration");
32 $strbackup = get_string("backup");
33 $strbackupdetails = get_string("backupdetails");
34 $strlogs = get_string("logs");
35 $strftimedatetime = get_string("strftimerecent");
36 $strftimetime = get_string("strftimetime").":%S";
37 $strerror = get_string("error");
38 $strok = get_string("ok");
39 $strunfinished = get_string("unfinished");
40 $strskipped = get_string("skipped");
41 $strcourse = get_string("course");
42 $strtimetaken = get_string("timetaken","quiz");
43 $strstatus = get_string("status");
44 $strnext = get_string("next");
46 /// Decide when to show last execution logs or detailed logs
49 print_heading($backuploglaststatus);
50 print_simple_box_start('center');
51 /// Now, get every record from backup_courses
52 $courses = get_records("backup_courses");
55 notify(get_string('nologsfound'));
57 echo "<table border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">";
60 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strcourse</font></td>";
61 echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\"><font size=\"3\">$strtimetaken</font></td>";
62 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strstatus</font></td>";
63 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strnext</font></td></tr>";
64 foreach ($courses as $course) {
65 /// Get the course shortname
66 $coursename = get_field ("course","fullname","id",$course->courseid
);
69 echo "<td nowrap=\"nowrap\"><font size=\"2\"><a href=\"index.php?courseid=$course->courseid\">".$coursename."</a></font></td>";
70 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->laststarttime
,$strftimedatetime)."</font></td>";
71 echo "<td nowrap=\"nowrap\"><font size=\"2\"> - </font></td>";
72 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->lastendtime
,$strftimedatetime)."</font></td>";
73 if ($course->laststatus
== 1) {
74 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strok."</font></td>";
75 } else if ($course->laststatus
== 2) {
76 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strunfinished."</font></td>";
77 } else if ($course->laststatus
== 3) {
78 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strskipped."</font></td>";
80 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strerror."</font></td>";
82 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->nextstarttime
,$strftimedatetime)."</font></td>";
88 print_simple_box_end();
91 print_heading($backuplogdetailed);
93 $coursename = get_field("course","fullname","id","$courseid");
94 print_heading("$strcourse: $coursename");
96 print_simple_box_start('center');
98 /// First, me get all the distinct backups for that course in backup_log
99 $executions = get_records_sql("SELECT DISTINCT laststarttime,laststarttime
100 FROM {$CFG->prefix}backup_log
101 WHERE courseid = '$courseid'
102 ORDER BY laststarttime DESC");
104 /// Iterate over backup executions
106 notify(get_string('nologsfound'));
108 echo "<table border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">";
109 foreach($executions as $execution) {
111 echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\">";
112 print_simple_box("<center>".userdate($execution->laststarttime
)."</center>", "center");
115 $logs = get_records_sql("SELECT *
116 FROM {$CFG->prefix}backup_log
117 WHERE courseid = '$courseid' AND
118 laststarttime = '$execution->laststarttime'
121 foreach ($logs as $log) {
123 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($log->time
,$strftimetime)."</font></td>";
124 $log->info
= str_replace("- ERROR!!","- <font color=\"red\">ERROR!!</font>",$log->info
);
125 $log->info
= str_replace("- OK","- <font color=\"green\">OK</font>",$log->info
);
126 echo "<td nowrap=\"nowrap\"><font size=\"2\">".str_replace(" "," ",$log->info
)."</font></td>";
133 print_simple_box_end();