[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/report/backups/ -> index.php (source)

   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  /**
  18   * A report to display the outcome of scheduled backups
  19   *
  20   * @package    report
  21   * @subpackage backups
  22   * @copyright  2007 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once('../../config.php');
  27  require_once($CFG->libdir.'/adminlib.php');
  28  
  29  // Required for constants in backup_cron_automated_helper
  30  require_once($CFG->dirroot.'/backup/util/helper/backup_cron_helper.class.php');
  31  
  32  admin_externalpage_setup('reportbackups', '', null, '', array('pagelayout'=>'report'));
  33  
  34  $table = new html_table;
  35  $table->head = array(
  36      get_string("course"),
  37      get_string("timetaken", "backup"),
  38      get_string("status"),
  39      get_string("backupnext")
  40  );
  41  $table->headspan = array(1, 3, 1, 1);
  42  $table->attributes = array('class' => 'generaltable backup-report');
  43  $table->data = array();
  44  
  45  $strftimedatetime = get_string('strftimerecent');
  46  $strerror = get_string('error');
  47  $strok = get_string('ok');
  48  $strunfinished = get_string('unfinished');
  49  $strskipped = get_string('skipped');
  50  $strwarning = get_string('warning');
  51  $strnotyetrun = get_string('backupnotyetrun');
  52  
  53  $select = ', ' . context_helper::get_preload_record_columns_sql('ctx');
  54  $join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
  55  $sql = "SELECT bc.*, c.fullname $select
  56            FROM {backup_courses} bc
  57            JOIN {course} c ON c.id = bc.courseid
  58                 $join";
  59  $rs = $DB->get_recordset_sql($sql, array('contextlevel' => CONTEXT_COURSE));
  60  foreach ($rs as $backuprow) {
  61  
  62      // Cache the course context
  63      context_helper::preload_from_record($backuprow);
  64  
  65      // Prepare a cell to display the status of the entry.
  66      if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_OK) {
  67          $status = $strok;
  68          $statusclass = 'backup-ok'; // Green.
  69      } else if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_UNFINISHED) {
  70          $status = $strunfinished;
  71          $statusclass = 'backup-unfinished'; // Red.
  72      } else if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_SKIPPED) {
  73          $status = $strskipped;
  74          $statusclass = 'backup-skipped'; // Green.
  75      } else if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_WARNING) {
  76          $status = $strwarning;
  77          $statusclass = 'backup-warning'; // Orange.
  78      } else if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_NOTYETRUN) {
  79          $status = $strnotyetrun;
  80          $statusclass = 'backup-notyetrun';
  81      } else {
  82          $status = $strerror;
  83          $statusclass = 'backup-error'; // Red.
  84      }
  85      $status = new html_table_cell($status);
  86      $status->attributes = array('class' => $statusclass);
  87  
  88      // Create the row and add it to the table
  89      $cells = array(
  90          format_string($backuprow->fullname, true, array('context' => context_course::instance($backuprow->courseid))),
  91          userdate($backuprow->laststarttime, $strftimedatetime),
  92          '-',
  93          userdate($backuprow->lastendtime, $strftimedatetime),
  94          $status,
  95          userdate($backuprow->nextstarttime, $strftimedatetime)
  96      );
  97      $table->data[] = new html_table_row($cells);
  98  }
  99  $rs->close();
 100  
 101  // Check if we have any results and if not add a no records notification
 102  if (empty($table->data)) {
 103      $cell = new html_table_cell($OUTPUT->notification(get_string('nologsfound')));
 104      $cell->colspan = 6;
 105      $table->data[] = new html_table_row(array($cell));
 106  }
 107  
 108  $automatedbackupsenabled = get_config('backup', 'backup_auto_active');
 109  
 110  // Display the backup report
 111  echo $OUTPUT->header();
 112  echo $OUTPUT->heading(get_string("backuploglaststatus"));
 113  echo $OUTPUT->box_start();
 114  if (empty($automatedbackupsenabled)) {
 115      // Automated backups aren't active, display a notification.
 116      // Not we don't stop because of this as perhaps scheduled backups are being run
 117      // automatically, or were enabled in the page.
 118      echo $OUTPUT->notification(get_string('automatedbackupsinactive', 'backup'));
 119  }
 120  echo html_writer::table($table);
 121  echo $OUTPUT->box_end();
 122  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1