MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / admin / report / backups / index.php
blobd7fab7991578b8aa5d2ae8af44422f3cba3dd850
1 <?php // $Id$
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 $adminroot = admin_get_root();
10 admin_externalpage_setup('reportbackups', $adminroot);
12 admin_externalpage_print_header($adminroot);
14 $courseid = optional_param('courseid', 0, PARAM_INT);
16 require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID));
18 /// Scheduled backups are disabled by the server admin
19 if (!empty($CFG->disablescheduledbackups)) {
20 print_error('scheduledbackupsdisabled', '', '', NULL, true);
23 /// Scheduled backups aren't active by the site admin
24 $backup_config = backup_get_config();
25 if (empty($backup_config->backup_sche_active)) {
26 notify(get_string('scheduledbackupsinactive'));
29 /// Get needed strings
30 $backuploglaststatus = get_string("backuploglaststatus");
31 $backuplogdetailed = get_string("backuplogdetailed");
32 $stradmin = get_string("administration");
33 $strconfiguration = get_string("configuration");
34 $strbackup = get_string("backup");
35 $strbackupdetails = get_string("backupdetails");
36 $strlogs = get_string("logs");
37 $strftimedatetime = get_string("strftimerecent");
38 $strftimetime = get_string("strftimetime").":%S";
39 $strerror = get_string("error");
40 $strok = get_string("ok");
41 $strunfinished = get_string("unfinished");
42 $strskipped = get_string("skipped");
43 $strcourse = get_string("course");
44 $strtimetaken = get_string("timetaken","quiz");
45 $strstatus = get_string("status");
46 $strnext = get_string("next");
48 /// Decide when to show last execution logs or detailed logs
49 /// Lastlog view
50 if (!$courseid) {
51 print_heading($backuploglaststatus);
52 print_simple_box_start('center');
53 /// Now, get every record from backup_courses
54 $courses = get_records("backup_courses");
56 if (!$courses) {
57 notify(get_string('nologsfound'));
58 } else {
59 echo "<table border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">";
60 //Print table header
61 echo "<tr>";
62 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strcourse</font></td>";
63 echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\"><font size=\"3\">$strtimetaken</font></td>";
64 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strstatus</font></td>";
65 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strnext</font></td></tr>";
66 foreach ($courses as $course) {
67 /// Get the course shortname
68 $coursename = get_field ("course","fullname","id",$course->courseid);
69 if ($coursename) {
70 echo "<tr>";
71 echo "<td nowrap=\"nowrap\"><font size=\"2\"><a href=\"index.php?courseid=$course->courseid\">".$coursename."</a></font></td>";
72 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->laststarttime,$strftimedatetime)."</font></td>";
73 echo "<td nowrap=\"nowrap\"><font size=\"2\"> - </font></td>";
74 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->lastendtime,$strftimedatetime)."</font></td>";
75 if ($course->laststatus == 1) {
76 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strok."</font></td>";
77 } else if ($course->laststatus == 2) {
78 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strunfinished."</font></td>";
79 } else if ($course->laststatus == 3) {
80 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strskipped."</font></td>";
81 } else {
82 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strerror."</font></td>";
84 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->nextstarttime,$strftimedatetime)."</font></td>";
85 echo "</tr>";
88 echo "</table>";
90 print_simple_box_end();
91 /// Detailed View !!
92 } else {
93 print_heading($backuplogdetailed);
95 $coursename = get_field("course","fullname","id","$courseid");
96 print_heading("$strcourse: $coursename");
98 print_simple_box_start('center');
100 /// First, me get all the distinct backups for that course in backup_log
101 $executions = get_records_sql("SELECT DISTINCT laststarttime,laststarttime
102 FROM {$CFG->prefix}backup_log
103 WHERE courseid = '$courseid'
104 ORDER BY laststarttime DESC");
106 /// Iterate over backup executions
107 if (!$executions) {
108 notify(get_string('nologsfound'));
109 } else {
110 echo "<table border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">";
111 foreach($executions as $execution) {
112 echo "<tr>";
113 echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\">";
114 print_simple_box("<center>".userdate($execution->laststarttime)."</center>", "center");
115 echo "</td>";
116 echo "</tr>";
117 $logs = get_records_sql("SELECT *
118 FROM {$CFG->prefix}backup_log
119 WHERE courseid = '$courseid' AND
120 laststarttime = '$execution->laststarttime'
121 ORDER BY id");
122 if ($logs) {
123 foreach ($logs as $log) {
124 echo "<tr>";
125 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($log->time,$strftimetime)."</font></td>";
126 $log->info = str_replace("- ERROR!!","- <font color=\"red\">ERROR!!</font>",$log->info);
127 $log->info = str_replace("- OK","- <font color=\"green\">OK</font>",$log->info);
128 echo "<td nowrap=\"nowrap\"><font size=\"2\">".str_replace(" ","&nbsp;&nbsp;&nbsp;&nbsp;",$log->info)."</font></td>";
129 echo "</tr>";
133 echo "</table>";
135 print_simple_box_end();
138 admin_externalpage_print_footer($adminroot);