[ Index ]

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

title

Body

[close]

/backup/ -> restore.php (source)

   1  <?php //$Id: restore.php,v 1.44.2.3 2008/05/02 04:07:30 dongsheng Exp $
   2      //This script is used to configure and execute the restore proccess.
   3  
   4      //Define some globals for all the script
   5  
   6      //Units used
   7      require_once("../config.php");
   8      require_once ("../lib/xmlize.php");
   9      require_once ("../course/lib.php");
  10      require_once ("lib.php");
  11      require_once ("restorelib.php");
  12      require_once ("bb/restore_bb.php");
  13      require_once("$CFG->libdir/blocklib.php");
  14      require_once("$CFG->libdir/wiki_to_markdown.php" );
  15      require_once("$CFG->libdir/adminlib.php");
  16  
  17      //Optional
  18      $id = optional_param( 'id' );
  19      $file = optional_param( 'file' );
  20      $cancel = optional_param( 'cancel' );
  21      $launch = optional_param( 'launch' );
  22      $to = optional_param( 'to' );
  23      $method = optional_param( 'method' );
  24      $backup_unique_code = optional_param('backup_unique_code',0,PARAM_INT);
  25  
  26      //Check login
  27      require_login();
  28  
  29  /// With method=manual, we come from the FileManager so we delete all the backup/restore/import session structures
  30      if ($method == 'manual') {
  31          if (isset($SESSION->course_header)) {
  32              unset ($SESSION->course_header);
  33          }
  34          if (isset($SESSION->info)) {
  35              unset ($SESSION->info);
  36          }
  37          if (isset($SESSION->backupprefs)) {
  38              unset ($SESSION->backupprefs);
  39          }
  40          if (isset($SESSION->restore)) {
  41              unset ($SESSION->restore);
  42          }
  43          if (isset($SESSION->import_preferences)) {
  44              unset ($SESSION->import_preferences);
  45          }
  46      }
  47  
  48      if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
  49          $to = $SESSION->restore->course_id;
  50      }
  51  
  52      if (!empty($id)) {
  53          require_login($id);
  54          if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
  55              if (empty($to)) {
  56                  error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
  57              } else {
  58                  if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))
  59                      && !has_capability('moodle/site:import',  get_context_instance(CONTEXT_COURSE, $to))) {
  60                      error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
  61                  }
  62              }
  63          }
  64      } else {
  65          if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) {
  66              error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
  67          }
  68      }
  69  
  70      //Check site
  71      if (!$site = get_site()) {
  72          error("Site not found!");
  73      }
  74  
  75      //Check necessary functions exists. Thanks to gregb@crowncollege.edu
  76      backup_required_functions();
  77  
  78      //Check backup_version
  79      if ($file) {
  80          $linkto = "restore.php?id=".$id."&amp;file=".$file;
  81      } else {
  82          $linkto = "restore.php";
  83      }
  84      upgrade_backup_db($linkto);
  85  
  86      //Get strings
  87      if (empty($to)) {
  88          $strcourserestore = get_string("courserestore");
  89      } else {
  90          $strcourserestore = get_string("importdata");
  91      }
  92      $stradministration = get_string("administration");
  93  
  94      //If no file has been selected from the FileManager, inform and end
  95      $navlinks = array();
  96      $navlinks[] = array('name' => $stradministration, 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc');
  97      $navlinks[] = array('name' => $strcourserestore, 'link' => null, 'type' => 'misc');
  98      $navigation = build_navigation($navlinks);
  99  
 100      if (!$file) {
 101          print_header("$site->shortname: $strcourserestore", $site->fullname, $navigation);
 102          print_heading(get_string("nofilesselected"));
 103          print_continue("$CFG->wwwroot/$CFG->admin/index.php");
 104          print_footer();
 105          exit;
 106      }
 107  
 108      //If cancel has been selected, inform and end
 109      if ($cancel) {
 110          print_header("$site->shortname: $strcourserestore", $site->fullname, $navigation);
 111          print_heading(get_string("restorecancelled"));
 112          print_continue("$CFG->wwwroot/course/view.php?id=".$id);
 113          print_footer();
 114          exit;
 115      }
 116  
 117      //We are here, so me have a file.
 118  
 119      //Get and check course
 120      if (! $course = get_record("course", "id", $id)) {
 121          error("Course ID was incorrect (can't find it)");
 122      }
 123  
 124      //Print header
 125      if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
 126          $navlinks[] = array('name' => basename($file), 'link' => null, 'type' => 'misc');
 127          $navigation = build_navigation($navlinks);
 128  
 129          print_header("$site->shortname: $strcourserestore", $site->fullname, $navigation);
 130      } else {
 131          $navlinks = array();
 132          $navlinks[] = array('name' => $course->shortname, 'link' => "$CFG->wwwroot/course/view.php?id=$course->id", 'type' => 'misc');
 133          $navlinks[] = array('name' => $strcourserestore, 'link' => null, 'type' => 'misc');
 134          $navigation = build_navigation($navlinks);
 135          print_header("$course->shortname: $strcourserestore", $course->fullname, $navigation);
 136      }
 137      //Print form
 138      print_heading("$strcourserestore".((empty($to) ? ': '.basename($file) : '')));
 139      print_simple_box_start('center');
 140  
 141      //Adjust some php variables to the execution of this script
 142      @ini_set("max_execution_time","3000");
 143      raise_memory_limit("192M");
 144  
 145      //Call the form, depending the step we are
 146  
 147      if (!$launch) {
 148          include_once ("restore_precheck.html");
 149      } else if ($launch == "form") {
 150          if (!empty($SESSION->restore->importing)) {
 151              // set up all the config stuff and skip asking the user about it.
 152              restore_setup_for_check($SESSION->restore,$backup_unique_code);
 153              include_once ("restore_execute.html");
 154          } else {
 155              include_once ("restore_form.html");
 156          }
 157      } else if ($launch == "check") {
 158          include_once ("restore_check.html");
 159          //To avoid multiple restore executions...
 160          $SESSION->cancontinue = true;
 161      } else if ($launch == "execute") {
 162          //Prevent multiple restore executions...
 163          if (empty($SESSION->cancontinue)) {
 164              error("Multiple restore execution not allowed!");
 165          }
 166          //Unset this for the future
 167          unset($SESSION->cancontinue);
 168          include_once ("restore_execute.html");
 169      }
 170      print_simple_box_end();
 171  
 172      //Print footer
 173      print_footer();
 174  
 175  ?>


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