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