2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * A report to display the outcome of scheduled backups
22 * @copyright 2007 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../../config.php');
27 require_once($CFG->libdir
.'/adminlib.php');
29 // Required for constants in backup_cron_automated_helper
30 require_once($CFG->dirroot
.'/backup/util/helper/backup_cron_helper.class.php');
32 admin_externalpage_setup('reportbackups', '', null, '', array('pagelayout'=>'report'));
34 $table = new html_table
;
37 get_string("timetaken", "quiz"),
39 get_string("backupnext")
41 $table->headspan
= array(1, 3, 1, 1);
42 $table->attributes
= array('class' => 'generaltable backup-report');
43 $table->data
= array();
45 $strftimedatetime = get_string("strftimerecent");
46 $strerror = get_string("error");
47 $strok = get_string("ok");
48 $strunfinished = get_string("unfinished");
49 $strskipped = get_string("skipped");
50 $strwarning = get_string("warning");
52 list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE
, 'ctx');
53 $sql = "SELECT bc.*, c.fullname $select
54 FROM {backup_courses} bc
55 JOIN {course} c ON c.id = bc.courseid
57 $rs = $DB->get_recordset_sql($sql);
58 foreach ($rs as $backuprow) {
60 // Cache the course context
61 context_instance_preload($backuprow);
63 // Prepare a cell to display the status of the entry
64 if ($backuprow->laststatus
== backup_cron_automated_helper
::BACKUP_STATUS_OK
) {
66 $statusclass = 'backup-ok'; // Green
67 } else if ($backuprow->laststatus
== backup_cron_automated_helper
::BACKUP_STATUS_UNFINISHED
) {
68 $status = $strunfinished;
69 $statusclass = 'backup-unfinished'; // Red
70 } else if ($backuprow->laststatus
== backup_cron_automated_helper
::BACKUP_STATUS_SKIPPED
) {
71 $status = $strskipped;
72 $statusclass = 'backup-skipped'; // Green
73 } else if ($backuprow->laststatus
== backup_cron_automated_helper
::BACKUP_STATUS_WARNING
) {
74 $status = $strwarning;
75 $statusclass = 'backup-warning'; // Orange
78 $statusclass = 'backup-error'; // Red
80 $status = new html_table_cell($status);
81 $status->attributes
= array('class' => $statusclass);
83 // Create the row and add it to the table
85 format_string($backuprow->fullname
, true, array('context' => context_course
::instance($backuprow->courseid
))),
86 userdate($backuprow->laststarttime
, $strftimedatetime),
88 userdate($backuprow->lastendtime
, $strftimedatetime),
90 userdate($backuprow->nextstarttime
, $strftimedatetime)
92 $table->data
[] = new html_table_row($cells);
96 // Check if we have any results and if not add a no records notification
97 if (empty($table->data
)) {
98 $cell = new html_table_cell($OUTPUT->notification(get_string('nologsfound')));
100 $table->data
[] = new html_table_row(array($cell));
103 $automatedbackupsenabled = get_config('backup', 'backup_auto_active');
105 // Display the backup report
106 echo $OUTPUT->header();
107 echo $OUTPUT->heading(get_string("backuploglaststatus"));
108 echo $OUTPUT->box_start();
109 if (empty($automatedbackupsenabled)) {
110 // Automated backups aren't active, display a notification.
111 // Not we don't stop because of this as perhaps scheduled backups are being run
112 // automatically, or were enabled in the page.
113 echo $OUTPUT->notification(get_string('automatedbackupsinactive', 'backup'));
115 echo html_writer
::table($table);
116 echo $OUTPUT->box_end();
117 echo $OUTPUT->footer();