[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/backup/ -> backup.php (source)

   1  <?php //$Id: backup.php,v 1.46.2.1 2008/03/08 15:36:00 skodak Exp $
   2      //This script is used to configure and execute the backup proccess.
   3  
   4      //Define some globals for all the script
   5  
   6      require_once ("../config.php");
   7      require_once  ("lib.php");
   8      require_once  ("backuplib.php");
   9      require_once ("$CFG->libdir/blocklib.php");
  10      require_once ("$CFG->libdir/adminlib.php");
  11  
  12      $id = optional_param( 'id' );       // course id
  13      $to = optional_param( 'to' ); // id of course to import into afterwards.
  14      $cancel = optional_param( 'cancel' );
  15      $launch = optional_param( 'launch' );
  16  
  17  
  18      if (!empty($id)) {
  19          require_login($id);
  20          if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $id))) {
  21              error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
  22          }
  23      } else {
  24          require_login();
  25          if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
  26              error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
  27          }
  28      }
  29  
  30      if (!empty($to)) {
  31          if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
  32              error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
  33          }
  34      }
  35  
  36      //Check site
  37      if (!$site = get_site()) {
  38          error("Site not found!");
  39      }
  40  
  41      //Check necessary functions exists. Thanks to gregb@crowncollege.edu
  42      backup_required_functions();
  43  
  44      //Check backup_version
  45      if ($id) {
  46          $linkto = "backup.php?id=".$id.((!empty($to)) ? '&to='.$to : '');
  47      } else {
  48          $linkto = "backup.php";
  49      }
  50      upgrade_backup_db($linkto);
  51  
  52      //Get strings
  53      if (empty($to)) {
  54          $strcoursebackup = get_string("coursebackup");
  55      }
  56      else {
  57          $strcoursebackup = get_string('importdata');
  58      }
  59      $stradministration = get_string("administration");
  60  
  61      //If cancel has been selected, go back to course main page (bug 2817)
  62      if ($cancel) {
  63          if ($id) {
  64              $redirecto = $CFG->wwwroot . '/course/view.php?id=' . $id; //Course page
  65          } else {
  66              $redirecto = $CFG->wwwroot.'/';
  67          }
  68          redirect ($redirecto, get_string('backupcancelled')); //Site page
  69          exit;
  70      }
  71  
  72      //If no course has been selected, show a list of available courses
  73  
  74      $navlinks = array();
  75      if (!$id) {
  76          $navlinks[] = array('name' => $stradministration, 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc');
  77          $navlinks[] = array('name' => $strcoursebackup, 'link' => null, 'type' => 'misc');
  78          $navigation = build_navigation($navlinks);
  79  
  80          print_header("$site->shortname: $strcoursebackup", $site->fullname, $navigation);
  81  
  82          if ($courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname')) {
  83              print_heading(get_string("choosecourse"));
  84              print_simple_box_start("center");
  85              foreach ($courses as $course) {
  86                  echo '<a href="backup.php?id='.$course->id.'">'.format_string($course->fullname).' ('.format_string($course->shortname).')</a><br />'."\n";
  87              }
  88              print_simple_box_end();
  89          } else {
  90              print_heading(get_string("nocoursesyet"));
  91              print_continue("$CFG->wwwroot/$CFG->admin/index.php");
  92          }
  93          print_footer();
  94          exit;
  95      }
  96  
  97      //Get and check course
  98      if (! $course = get_record("course", "id", $id)) {
  99          error("Course ID was incorrect (can't find it)");
 100      }
 101  
 102      //Print header
 103      if (has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) {
 104          $navlinks[] = array('name' => $stradministration, 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc');
 105          $navlinks[] = array('name' => $strcoursebackup, 'link' => 'backup.php', 'type' => 'misc');
 106          $navlinks[] = array('name' => "$course->fullname ($course->shortname)", 'link' => null, 'type' => 'misc');
 107          $navigation = build_navigation($navlinks);
 108  
 109          print_header("$site->shortname: $strcoursebackup", $site->fullname, $navigation);
 110      } else {
 111          $navlinks[] = array('name' => $course->fullname, 'link' => "$CFG->wwwroot/course/view.php?id=$course->id", 'type' => 'misc');
 112          $navlinks[] = array('name' => $strcoursebackup, 'link' => null, 'type' => 'misc');
 113          $navigation = build_navigation($navlinks);
 114          print_header("$course->shortname: $strcoursebackup", $course->fullname, $navigation);
 115      }
 116  
 117      //Print form
 118      print_heading(format_string("$strcoursebackup: $course->fullname ($course->shortname)"));
 119      print_simple_box_start("center");
 120  
 121      //Adjust some php variables to the execution of this script
 122      @ini_set("max_execution_time","3000");
 123      raise_memory_limit("192M");
 124  
 125      //Call the form, depending the step we are
 126      if (!$launch) {
 127          // if we're at the start, clear the cache of prefs
 128          if (isset($SESSION->backupprefs[$course->id])) {
 129              unset($SESSION->backupprefs[$course->id]);
 130          }
 131          include_once ("backup_form.html");
 132      } else if ($launch == "check") {
 133          include_once ("backup_check.html");
 134      } else if ($launch == "execute") {
 135          include_once ("backup_execute.html");
 136      }
 137      print_simple_box_end();
 138  
 139      //Print footer
 140      print_footer();
 141  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7