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
);
11 require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM
, SITEID
));
13 if (!$site = get_site()) {
14 error("Site isn't defined!");
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
40 $navlinks[] = array('name' => $stradmin, 'link' => "../$CFG->admin/index.php", 'type' => 'misc');
41 $navlinks[] = array('name' => $strconfiguration, 'link' => "../$CFG->admin/configure.php", 'type' => 'misc');
42 $navlinks[] = array('name' => $strbackup, 'link' => "../$CFG->admin/backup.php?sesskey=$USER->sesskey", 'type' => 'misc');
43 $navlinks[] = array('name' => $strlogs, 'link' => null, 'type' => 'misc');
44 $navigation = build_navigation($navlinks);
46 print_header("$site->shortname: $strconfiguration: $strbackup", $site->fullname
, $navigation);
48 print_heading($backuploglaststatus);
49 print_simple_box_start('center');
50 //Now, get every record from backup_courses
51 $courses = get_records("backup_courses");
54 notify("No logs found!");
56 echo "<table border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">";
59 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strcourse</font></td>";
60 echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\"><font size=\"3\">$strtimetaken</font></td>";
61 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strstatus</font></td>";
62 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strnext</font></td></tr>";
63 foreach ($courses as $course) {
64 //Get the course shortname
65 $coursename = get_field ("course","fullname","id",$course->courseid
);
68 echo "<td nowrap=\"nowrap\"><font size=\"2\"><a href=\"log.php?courseid=$course->courseid\">".$coursename."</a></font></td>";
69 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->laststarttime
,$strftimedatetime)."</font></td>";
70 echo "<td nowrap=\"nowrap\"><font size=\"2\"> - </font></td>";
71 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->lastendtime
,$strftimedatetime)."</font></td>";
72 if ($course->laststatus
== 1) {
73 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strok."</font></td>";
74 } else if ($course->laststatus
== 2) {
75 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strunfinished."</font></td>";
76 } else if ($course->laststatus
== 3) {
77 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"green\">".$strskipped."</font></td>";
79 echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"2\" color=\"red\">".$strerror."</font></td>";
81 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($course->nextstarttime
,$strftimedatetime)."</font></td>";
87 print_simple_box_end();
91 $navlinks[] = array('name' => $stradmin, 'link' => "../$CFG->admin/index.php", 'type' => 'misc');
92 $navlinks[] = array('name' => $strconfiguration, 'link' => "../$CFG->admin/configure.php", 'type' => 'misc');
93 $navlinks[] = array('name' => $strbackup, 'link' => "../$CFG->admin/backup.php?sesskey=$USER->sesskey", 'type' => 'misc');
94 $navlinks[] = array('name' => $strlogs, 'link' => 'log.php', 'type' => 'misc');
95 $navlinks[] = array('name' => $strbackupdetails, 'link' => null, 'type' => 'misc');
96 $navigation = build_navigation($navlinks);
98 print_header("$site->shortname: $strconfiguration: $strbackup", $site->fullname
, $navigation);
100 print_heading($backuplogdetailed);
102 $coursename = get_field("course","fullname","id","$courseid");
103 print_heading("$strcourse: $coursename");
105 print_simple_box_start('center');
107 //First, me get all the distinct backups for that course in backup_log
108 $executions = get_records_sql("SELECT DISTINCT laststarttime,laststarttime
109 FROM {$CFG->prefix}backup_log
110 WHERE courseid = '$courseid'
111 ORDER BY laststarttime DESC");
113 //Iterate over backup executions
115 notify("No logs found!");
117 echo "<table border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\">";
118 foreach($executions as $execution) {
120 echo "<td nowrap=\"nowrap\" align=\"center\" colspan=\"3\">";
121 print_simple_box("<center>".userdate($execution->laststarttime
)."</center>", "center");
124 $logs = get_records_sql("SELECT *
125 FROM {$CFG->prefix}backup_log
126 WHERE courseid = '$courseid' AND
127 laststarttime = '$execution->laststarttime'
130 foreach ($logs as $log) {
132 echo "<td nowrap=\"nowrap\"><font size=\"2\">".userdate($log->time
,$strftimetime)."</font></td>";
133 $log->info
= str_replace("- ERROR!!","- <font color=\"red\">ERROR!!</font>",$log->info
);
134 $log->info
= str_replace("- OK","- <font color=\"green\">OK</font>",$log->info
);
135 echo "<td nowrap=\"nowrap\"><font size=\"2\">".str_replace(" "," ",$log->info
)."</font></td>";
142 print_simple_box_end();