Added link to Cloze
[moodle.git] / backup / log.php
blob0e90fa2436ae40c9b1b308c4a7edd139085a721c
1 <?PHP // $Id$
2 // backup.php - allows admin to edit all configuration variables for scheduled backups
4 require_once("../config.php");
5 require_once("../backup/lib.php");
7 optional_variable($courseid);
9 require_login();
11 if (!isadmin()) {
12 error("Only an admin can use this page");
15 if (!$site = get_site()) {
16 error("Site isn't defined!");
19 //Get needed strings
20 $backuploglaststatus = get_string("backuploglaststatus");
21 $backuplogdetailed = get_string("backuplogdetailed");
22 $stradmin = get_string("administration");
23 $strconfiguration = get_string("configuration");
24 $strbackup = get_string("backup");
25 $strbackupdetails = get_string("backupdetails");
26 $strlogs = get_string("logs");
27 $strftimedatetime = get_string("strftimerecent");
28 $strftimetime = get_string("strftimetime").":%S";
29 $strerror = get_string("error");
30 $strok = get_string("ok");
31 $strcourse = get_string("course");
32 $strtimetaken = get_string("timetaken","quiz");
33 $strstatus = get_string("status");
34 $strnext = get_string("next");
36 //Decide when to show last execution logs or detailed logs
37 //Lastlog view
38 if (!$courseid) {
39 print_header("$site->shortname: $strconfiguration: $strbackup", $site->fullname,
40 "<a href=\"../admin/index.php\">$stradmin</a> -> ".
41 "<a href=\"../admin/configure.php\">$strconfiguration</a> -> ".
42 "<a href=\"../admin/backup.php\">$strbackup</a> -> ".
43 $strlogs);
45 print_heading($backuploglaststatus);
46 print_simple_box_start("center", "", "$THEME->cellheading");
47 //Now, get every record from backup_courses
48 $courses = get_records("backup_courses");
50 if (!$courses) {
51 notify("No logs found!");
52 } else {
53 echo "<table border=0 align=center cellpadding=3 cellspacing=3>";
54 //Print table header
55 echo "<tr nowrap>";
56 echo "<td nowrap align=center><font size=3>$strcourse</font></td>";
57 echo "<td nowrap align=center colspan=3><font size=3>$strtimetaken</font></td>";
58 echo "<td nowrap align=center><font size=3>$strstatus</font></td>";
59 echo "<td nowrap align=center><font size=3>$strnext</font></td>";
60 foreach ($courses as $course) {
61 //Get the course shortname
62 $coursename = get_field ("course","fullname","id",$course->courseid);
63 if ($coursename) {
64 echo "<tr nowrap>";
65 echo "<td nowrap><font size=2><a href=\"log.php?courseid=$course->courseid\">".$coursename."</a></td>";
66 echo "<td nowrap><font size=2>".userdate($course->laststarttime,$strftimedatetime)."</td>";
67 echo "<td nowrap><font size=2> - </td>";
68 echo "<td nowrap><font size=2>".userdate($course->lastendtime,$strftimedatetime)."</td>";
69 if (!$course->laststatus) {
70 echo "<td nowrap align=center><font size=2 color=red>".$strerror."</td>";
71 } else {
72 echo "<td nowrap align=center><font size=2 color=green>".$strok."</td>";
74 echo "<td nowrap><font size=2>".userdate($course->nextstarttime,$strftimedatetime)."</td>";
75 echo "</tr>";
78 echo "</table>";
80 print_simple_box_end();
81 //Detailed View !!
82 } else {
83 print_header("$site->shortname: $strconfiguration: $strbackup", $site->fullname,
84 "<a href=\"../admin/index.php\">$stradmin</a> -> ".
85 "<a href=\"../admin/configure.php\">$strconfiguration</a> -> ".
86 "<a href=\"../admin/backup.php\">$strbackup</a> -> ".
87 "<a href=\"log.php\">$strlogs</a> -> ".
88 $strbackupdetails);
90 print_heading($backuplogdetailed);
92 $coursename = get_field("course","fullname","id","$courseid");
93 print_heading("$strcourse: $coursename");
95 print_simple_box_start("center", "", "$THEME->cellheading");
97 //First, me get all the distinct backups for that course in backup_log
98 $executions = get_records_sql("SELECT DISTINCT laststarttime,laststarttime
99 FROM {$CFG->prefix}backup_log
100 WHERE courseid = '$courseid'
101 ORDER BY laststarttime DESC");
103 //Iterate over backup executions
104 if (!$executions) {
105 notify("No logs found!");
106 } else {
107 echo "<table border=0 align=center cellpadding=3 cellspacing=3>";
108 foreach($executions as $execution) {
109 echo "<tr nowrap>";
110 echo "<td nowrap align=center colspan=3>";
111 print_simple_box("<center>".userdate($execution->laststarttime)."</center>", "center");
112 echo "</td>";
113 echo "</tr>";
114 $logs = get_records_sql("SELECT *
115 FROM {$CFG->prefix}backup_log
116 WHERE courseid = '$courseid' AND
117 laststarttime = '$execution->laststarttime'
118 ORDER BY time");
119 if ($logs) {
120 foreach ($logs as $log) {
121 echo "<tr nowrap>";
122 echo "<td nowrap><font size=2>".userdate($log->time,$strftimetime)."</font></td>";
123 $log->info = str_replace("- ERROR!!","- <font color=red>ERROR!!</font>",$log->info);
124 $log->info = str_replace("- OK","- <font color=green>OK</font>",$log->info);
125 echo "<td nowrap><font size=2>".str_replace(" ","&nbsp;&nbsp;&nbsp;&nbsp;",$log->info)."</font></td>";
126 echo "</tr>";
130 echo "</table>";
132 print_simple_box_end();
136 print_footer();