MDL-16106 report - fix old double-column trick causing problems in backup logs. Merge...
[moodle.git] / admin / report / backups / index.php
1 <?php
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     $courseid = optional_param('courseid', 0, PARAM_INT);
10     admin_externalpage_setup('reportbackups');
11     echo $OUTPUT->header();
13 /// Scheduled backups are disabled by the server admin
14     if (!empty($CFG->disablescheduledbackups)) {
15         print_error('scheduledbackupsdisabled', 'error');
16     }
18 /// Scheduled backups aren't active by the site admin
19     $backup_config = backup_get_config();
20     if (empty($backup_config->backup_sche_active)) {
21         echo $OUTPUT->notification(get_string('scheduledbackupsinactive'));
22     }
24 /// Get needed strings
25     $backuploglaststatus = get_string("backuploglaststatus");
26     $backuplogdetailed = get_string("backuplogdetailed");
27     $stradmin = get_string("administration");
28     $strconfiguration = get_string("configuration");
29     $strbackup = get_string("backup");
30     $strbackupdetails = get_string("backupdetails");
31     $strlogs = get_string("logs");
32     $strftimedatetime = get_string("strftimerecent");
33     $strftimetime = get_string("strftimetime").":%S";
34     $strerror = get_string("error");
35     $strok = get_string("ok");
36     $strunfinished = get_string("unfinished");
37     $strskipped = get_string("skipped");
38     $strcourse = get_string("course");
39     $strtimetaken = get_string("timetaken","quiz");
40     $strstatus = get_string("status");
41     $strnext = get_string("backupnext");
43 /// Decide when to show last execution logs or detailed logs
44 /// Lastlog view
45     if (!$courseid) {
46         echo $OUTPUT->heading($backuploglaststatus);
47         echo $OUTPUT->box_start();
48     /// Now, get every record from backup_courses
49         $courses = $DB->get_records("backup_courses");
51         if (!$courses) {
52             echo $OUTPUT->notification(get_string('nologsfound'));
53         } else {
54             echo "<table border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">";
55             //Print table header
56             echo "<tr>";
57             echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strcourse</font></td>";
58             echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\"><font size=\"3\">$strtimetaken</font></td>";
59             echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strstatus</font></td>";
60             echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strnext</font></td></tr>";
61             foreach ($courses as $course) {
62             /// Get the course shortname
63                 $coursename = $DB->get_field ("course", "fullname", array("id"=>$course->courseid));
64                 if ($coursename) {
65                     echo "<tr>";
66                     echo "<td nowrap=\"nowrap\"><font size=\"2\"><a href=\"index.php?courseid=$course->courseid\">".$coursename."</a></font></td>";
67                     echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->laststarttime,$strftimedatetime)."</font></td>";
68                     echo "<td nowrap=\"nowrap\"><font size=\"2\"> - </font></td>";
69                     echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->lastendtime,$strftimedatetime)."</font></td>";
70                     if ($course->laststatus == 1) {
71                         echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strok."</font></td>";
72                     } else if ($course->laststatus == 2) {
73                         echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strunfinished."</font></td>";
74                     } else if ($course->laststatus == 3) {
75                         echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strskipped."</font></td>";
76                     } else {
77                         echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strerror."</font></td>";
78                     }
79                     echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->nextstarttime,$strftimedatetime)."</font></td>";
80                     echo "</tr>";
81                 }
82             }
83             echo "</table>";
84         }
85         echo $OUTPUT->box_end();
86 /// Detailed View !!
87     } else {
88         echo $OUTPUT->heading($backuplogdetailed);
90         $coursename = $DB->get_field("course", "fullname", array("id"=>"$courseid"));
91         echo $OUTPUT->heading("$strcourse: $coursename");
93         echo $OUTPUT->box_start();
95     /// First, me get all the distinct backups for that course in backup_log
96         $executions = $DB->get_records_sql("SELECT DISTINCT laststarttime
97                                               FROM {backup_log}
98                                              WHERE courseid = ? AND backuptype = ?
99                                           ORDER BY laststarttime DESC", array($courseid,'scheduledbackup'));
101     /// Iterate over backup executions
102         if (!$executions) {
103             echo $OUTPUT->notification(get_string('nologsfound'));
104         } else {
105             echo "<table border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">";
106             foreach($executions as $execution) {
107                 echo "<tr>";
108                 echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\">";
109                 echo $OUTPUT->box(userdate($execution->laststarttime));
110                 echo "</td>";
111                 echo "</tr>";
112                 $logs = $DB->get_records_sql("SELECT *
113                                                 FROM {backup_log}
114                                                WHERE courseid = ? AND laststarttime = ? AND backuptype = ?
115                                             ORDER BY id", array($courseid, $execution->laststarttime,'scheduledbackup'));
116                 if ($logs) {
117                     foreach ($logs as $log) {
118                         echo "<tr>";
119                         echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($log->time,$strftimetime)."</font></td>";
120                         $log->info = str_replace("- ERROR!!","- <font color=\"red\">ERROR!!</font>",$log->info);
121                         $log->info = str_replace("- OK","- <font color=\"green\">OK</font>",$log->info);
122                         echo "<td nowrap=\"nowrap\"><font size=\"2\">".str_replace("  ","&nbsp;&nbsp;&nbsp;&nbsp;",$log->info)."</font></td>";
123                         echo "</tr>";
124                     }
125                 }
126             }
127             echo "</table>";
128         }
129         echo $OUTPUT->box_end();
130     }
132     echo $OUTPUT->footer();