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');
28 require_once($CFG->dirroot
.'/backup/lib.php');
30 admin_externalpage_setup('reportbackups', '', null, '', array('pagelayout'=>'report'));
32 $table = new html_table
;
35 get_string("timetaken", "quiz"),
37 get_string("backupnext")
39 $table->headspan
= array(1, 3, 1, 1);
40 $table->attributes
= array('class' => 'generaltable backup-report');
41 $table->data
= array();
43 $strftimedatetime = get_string("strftimerecent");
44 $strerror = get_string("error");
45 $strok = get_string("ok");
46 $strunfinished = get_string("unfinished");
47 $strskipped = get_string("skipped");
49 list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE
, 'ctx');
50 $sql = "SELECT bc.*, c.fullname $select
51 FROM {backup_courses} bc
52 JOIN {course} c ON c.id = bc.courseid
54 $rs = $DB->get_recordset_sql($sql);
55 foreach ($rs as $backuprow) {
57 // Cache the course context
58 context_instance_preload($backuprow);
60 // Prepare a cell to display the status of the entry
61 if ($backuprow->laststatus
== 1) {
63 $statusclass = 'backup-ok'; // Green
64 } else if ($backuprow->laststatus
== 2) {
65 $status = $strunfinished;
66 $statusclass = 'backup-unfinished'; // Red
67 } else if ($backuprow->laststatus
== 3) {
68 $status = $strskipped;
69 $statusclass = 'backup-skipped'; // Green
72 $statusclass = 'backup-error'; // Red
74 $status = new html_table_cell($status);
75 $status->attributes
= array('class' => $statusclass);
77 // Create the row and add it to the table
79 format_string($backuprow->fullname
, true, array('context' => get_context_instance(CONTEXT_COURSE
, $backuprow->courseid
))),
80 userdate($backuprow->laststarttime
, $strftimedatetime),
82 userdate($backuprow->lastendtime
, $strftimedatetime),
84 userdate($backuprow->nextstarttime
, $strftimedatetime)
86 $table->data
[] = new html_table_row($cells);
90 // Check if we have any results and if not add a no records notification
91 if (empty($table->data
)) {
92 $cell = new html_table_cell($OUTPUT->notification(get_string('nologsfound')));
94 $table->data
[] = new html_table_row(array($cell));
97 $automatedbackupsenabled = get_config('backup', 'backup_auto_active');
99 // Display the backup report
100 echo $OUTPUT->header();
101 echo $OUTPUT->heading(get_string("backuploglaststatus"));
102 echo $OUTPUT->box_start();
103 if (empty($automatedbackupsenabled)) {
104 // Automated backups aren't active, display a notification.
105 // Not we don't stop because of this as perhaps scheduled backups are being run
106 // automatically, or were enabled in the page.
107 echo $OUTPUT->notification(get_string('automatedbackupsinactive', 'backup'));
109 echo html_writer
::table($table);
110 echo $OUTPUT->box_end();
111 echo $OUTPUT->footer();