Merge branch 'MDL-34171_22' of git://github.com/timhunt/moodle into MOODLE_22_STABLE
[moodle.git] / report / backups / index.php
blob5a705870a37d0a8f1a7120e45e5afeac4d7e9d2a
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * A report to display the outcome of scheduled backups
20 * @package report
21 * @subpackage 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;
33 $table->head = array(
34 get_string("course"),
35 get_string("timetaken", "quiz"),
36 get_string("status"),
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
53 $join";
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) {
62 $status = $strok;
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
70 } else {
71 $status = $strerror;
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
78 $cells = array(
79 format_string($backuprow->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $backuprow->courseid))),
80 userdate($backuprow->laststarttime, $strftimedatetime),
81 '-',
82 userdate($backuprow->lastendtime, $strftimedatetime),
83 $status,
84 userdate($backuprow->nextstarttime, $strftimedatetime)
86 $table->data[] = new html_table_row($cells);
88 $rs->close();
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')));
93 $cell->colspan = 6;
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();