PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/report/backups/index.php

https://bitbucket.org/kudutest1/moodlegit
PHP | 117 lines | 73 code | 13 blank | 31 comment | 14 complexity | b116fe28b766f587d01b131e6bf3890c MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * A report to display the outcome of scheduled backups
  18. *
  19. * @package report
  20. * @subpackage backups
  21. * @copyright 2007 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. require_once('../../config.php');
  25. require_once($CFG->libdir.'/adminlib.php');
  26. // Required for constants in backup_cron_automated_helper
  27. require_once($CFG->dirroot.'/backup/util/helper/backup_cron_helper.class.php');
  28. admin_externalpage_setup('reportbackups', '', null, '', array('pagelayout'=>'report'));
  29. $table = new html_table;
  30. $table->head = array(
  31. get_string("course"),
  32. get_string("timetaken", "quiz"),
  33. get_string("status"),
  34. get_string("backupnext")
  35. );
  36. $table->headspan = array(1, 3, 1, 1);
  37. $table->attributes = array('class' => 'generaltable backup-report');
  38. $table->data = array();
  39. $strftimedatetime = get_string("strftimerecent");
  40. $strerror = get_string("error");
  41. $strok = get_string("ok");
  42. $strunfinished = get_string("unfinished");
  43. $strskipped = get_string("skipped");
  44. $strwarning = get_string("warning");
  45. list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
  46. $sql = "SELECT bc.*, c.fullname $select
  47. FROM {backup_courses} bc
  48. JOIN {course} c ON c.id = bc.courseid
  49. $join";
  50. $rs = $DB->get_recordset_sql($sql);
  51. foreach ($rs as $backuprow) {
  52. // Cache the course context
  53. context_instance_preload($backuprow);
  54. // Prepare a cell to display the status of the entry
  55. if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_OK) {
  56. $status = $strok;
  57. $statusclass = 'backup-ok'; // Green
  58. } else if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_UNFINISHED) {
  59. $status = $strunfinished;
  60. $statusclass = 'backup-unfinished'; // Red
  61. } else if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_SKIPPED) {
  62. $status = $strskipped;
  63. $statusclass = 'backup-skipped'; // Green
  64. } else if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_WARNING) {
  65. $status = $strwarning;
  66. $statusclass = 'backup-warning'; // Orange
  67. } else {
  68. $status = $strerror;
  69. $statusclass = 'backup-error'; // Red
  70. }
  71. $status = new html_table_cell($status);
  72. $status->attributes = array('class' => $statusclass);
  73. // Create the row and add it to the table
  74. $cells = array(
  75. format_string($backuprow->fullname, true, array('context' => context_course::instance($backuprow->courseid))),
  76. userdate($backuprow->laststarttime, $strftimedatetime),
  77. '-',
  78. userdate($backuprow->lastendtime, $strftimedatetime),
  79. $status,
  80. userdate($backuprow->nextstarttime, $strftimedatetime)
  81. );
  82. $table->data[] = new html_table_row($cells);
  83. }
  84. $rs->close();
  85. // Check if we have any results and if not add a no records notification
  86. if (empty($table->data)) {
  87. $cell = new html_table_cell($OUTPUT->notification(get_string('nologsfound')));
  88. $cell->colspan = 6;
  89. $table->data[] = new html_table_row(array($cell));
  90. }
  91. $automatedbackupsenabled = get_config('backup', 'backup_auto_active');
  92. // Display the backup report
  93. echo $OUTPUT->header();
  94. echo $OUTPUT->heading(get_string("backuploglaststatus"));
  95. echo $OUTPUT->box_start();
  96. if (empty($automatedbackupsenabled)) {
  97. // Automated backups aren't active, display a notification.
  98. // Not we don't stop because of this as perhaps scheduled backups are being run
  99. // automatically, or were enabled in the page.
  100. echo $OUTPUT->notification(get_string('automatedbackupsinactive', 'backup'));
  101. }
  102. echo html_writer::table($table);
  103. echo $OUTPUT->box_end();
  104. echo $OUTPUT->footer();