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