MDL-9268
[moodle-pu.git] / backup / log.php
blob456f1f2ddbc14d11c4b037e8b58f4a1cb19ce227
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 $courseid = optional_param('courseid',0,PARAM_INT);
9 require_login();
11 require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID));
13 if (!$site = get_site()) {
14 error("Site isn't defined!");
17 //Get needed strings
18 $backuploglaststatus = get_string("backuploglaststatus");
19 $backuplogdetailed = get_string("backuplogdetailed");
20 $stradmin = get_string("administration");
21 $strconfiguration = get_string("configuration");
22 $strbackup = get_string("backup");
23 $strbackupdetails = get_string("backupdetails");
24 $strlogs = get_string("logs");
25 $strftimedatetime = get_string("strftimerecent");
26 $strftimetime = get_string("strftimetime").":%S";
27 $strerror = get_string("error");
28 $strok = get_string("ok");
29 $strunfinished = get_string("unfinished");
30 $strskipped = get_string("skipped");
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=\"../$CFG->admin/index.php\">$stradmin</a> -> ".
41 "<a href=\"../$CFG->admin/configure.php\">$strconfiguration</a> -> ".
42 "<a href=\"../$CFG->admin/backup.php?sesskey=$USER->sesskey\">$strbackup</a> -> ".
43 $strlogs);
45 print_heading($backuploglaststatus);
46 print_simple_box_start('center');
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>";
56 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strcourse</font></td>";
57 echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\"><font size=\"3\">$strtimetaken</font></td>";
58 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strstatus</font></td>";
59 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strnext</font></td></tr>";
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>";
65 echo "<td nowrap=\"nowrap\"><font size=\"2\"><a href=\"log.php?courseid=$course->courseid\">".$coursename."</a></font></td>";
66 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->laststarttime,$strftimedatetime)."</font></td>";
67 echo "<td nowrap=\"nowrap\"><font size=\"2\"> - </font></td>";
68 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->lastendtime,$strftimedatetime)."</font></td>";
69 if ($course->laststatus == 1) {
70 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strok."</font></td>";
71 } else if ($course->laststatus == 2) {
72 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strunfinished."</font></td>";
73 } else if ($course->laststatus == 3) {
74 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strskipped."</font></td>";
75 } else {
76 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strerror."</font></td>";
78 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->nextstarttime,$strftimedatetime)."</font></td>";
79 echo "</tr>";
82 echo "</table>";
84 print_simple_box_end();
85 //Detailed View !!
86 } else {
87 print_header("$site->shortname: $strconfiguration: $strbackup", $site->fullname,
88 "<a href=\"../$CFG->admin/index.php\">$stradmin</a> -> ".
89 "<a href=\"../$CFG->admin/configure.php\">$strconfiguration</a> -> ".
90 "<a href=\"../$CFG->admin/backup.php?sesskey=$USER->sesskey\">$strbackup</a> -> ".
91 "<a href=\"log.php\">$strlogs</a> -> ".
92 $strbackupdetails);
94 print_heading($backuplogdetailed);
96 $coursename = get_field("course","fullname","id","$courseid");
97 print_heading("$strcourse: $coursename");
99 print_simple_box_start('center');
101 //First, me get all the distinct backups for that course in backup_log
102 $executions = get_records_sql("SELECT DISTINCT laststarttime,laststarttime
103 FROM {$CFG->prefix}backup_log
104 WHERE courseid = '$courseid'
105 ORDER BY laststarttime DESC");
107 //Iterate over backup executions
108 if (!$executions) {
109 notify("No logs found!");
110 } else {
111 echo "<table border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">";
112 foreach($executions as $execution) {
113 echo "<tr>";
114 echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\">";
115 print_simple_box("<center>".userdate($execution->laststarttime)."</center>", "center");
116 echo "</td>";
117 echo "</tr>";
118 $logs = get_records_sql("SELECT *
119 FROM {$CFG->prefix}backup_log
120 WHERE courseid = '$courseid' AND
121 laststarttime = '$execution->laststarttime'
122 ORDER BY id");
123 if ($logs) {
124 foreach ($logs as $log) {
125 echo "<tr>";
126 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($log->time,$strftimetime)."</font></td>";
127 $log->info = str_replace("- ERROR!!","- <font color=\"red\">ERROR!!</font>",$log->info);
128 $log->info = str_replace("- OK","- <font color=\"green\">OK</font>",$log->info);
129 echo "<td nowrap=\"nowrap\"><font size=\"2\">".str_replace(" ","&nbsp;&nbsp;&nbsp;&nbsp;",$log->info)."</font></td>";
130 echo "</tr>";
134 echo "</table>";
136 print_simple_box_end();
140 print_footer();