Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/publish/backup.php
Go to the documentation of this file.
00001 <?php
00002 
00004 //                                                                       //
00005 // This file is part of Moodle - http://moodle.org/                      //
00006 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00007 //                                                                       //
00008 // Moodle is free software: you can redistribute it and/or modify        //
00009 // it under the terms of the GNU General Public License as published by  //
00010 // the Free Software Foundation, either version 3 of the License, or     //
00011 // (at your option) any later version.                                   //
00012 //                                                                       //
00013 // Moodle is distributed in the hope that it will be useful,             //
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00016 // GNU General Public License for more details.                          //
00017 //                                                                       //
00018 // You should have received a copy of the GNU General Public License     //
00019 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.       //
00020 //                                                                       //
00022 
00023 /*
00024  * @package    course
00025  * @subpackage publish
00026  * @author     Jerome Mouneyrac <jerome@mouneyrac.com>
00027  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
00028  * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
00029  *
00030  * This page display the publication backup form
00031  */
00032 
00033 require_once('../../config.php');
00034 require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
00035 require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
00036 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
00037 require_once($CFG->dirroot . '/course/publish/lib.php');
00038 require_once($CFG->libdir . '/filelib.php');
00039 
00040 
00041 //retrieve initial page parameters
00042 $id = required_param('id', PARAM_INT);
00043 $hubcourseid = required_param('hubcourseid', PARAM_INT);
00044 $huburl = required_param('huburl', PARAM_URL);
00045 $hubname = optional_param('hubname', '', PARAM_TEXT);
00046 
00047 //some permissions and parameters checking
00048 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
00049 require_login($course);
00050 if (!has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))
00051         or !confirm_sesskey()) {
00052     throw new moodle_exception('nopermission');
00053 }
00054 
00055 //page settings
00056 $PAGE->set_url('/course/publish/backup.php');
00057 $PAGE->set_pagelayout('course');
00058 $PAGE->set_title(get_string('course') . ': ' . $course->fullname);
00059 $PAGE->set_heading($course->fullname);
00060 
00061 //BEGIN backup processing
00062 $backupid = optional_param('backup', false, PARAM_ALPHANUM);
00063 if (!($bc = backup_ui::load_controller($backupid))) {
00064     $bc = new backup_controller(backup::TYPE_1COURSE, $id, backup::FORMAT_MOODLE,
00065                     backup::INTERACTIVE_YES, backup::MODE_HUB, $USER->id);
00066 }
00067 $backup = new backup_ui($bc,
00068         array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => $huburl, 'hubname' => $hubname));
00069 $backup->process();
00070 if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
00071     $backup->execute();
00072 } else {
00073     $backup->save_controller();
00074 }
00075 
00076 if ($backup->get_stage() !== backup_ui::STAGE_COMPLETE) {
00077     $renderer = $PAGE->get_renderer('core', 'backup');
00078     echo $OUTPUT->header();
00079     echo $OUTPUT->heading(get_string('publishcourseon', 'hub', !empty($hubname)?$hubname:$huburl), 3, 'main');
00080     if ($backup->enforce_changed_dependencies()) {
00081         echo $renderer->dependency_notification(get_string('dependenciesenforced', 'backup'));
00082     }
00083     echo $renderer->progress_bar($backup->get_progress_bar());
00084     echo $backup->display();
00085     echo $OUTPUT->footer();
00086     die();
00087 }
00088 
00089 //$backupfile = $backup->get_stage_results();
00090 $backupfile = $bc->get_results();
00091 $backupfile = $backupfile['backup_destination'];
00092 //END backup processing
00093 
00094 //retrieve the token to call the hub
00095 $registrationmanager = new registration_manager();
00096 $registeredhub = $registrationmanager->get_registeredhub($huburl);
00097 
00098 //display the sending file page
00099 echo $OUTPUT->header();
00100 echo $OUTPUT->heading(get_string('sendingcourse', 'hub'), 3, 'main');
00101 $renderer = $PAGE->get_renderer('core', 'publish');
00102 echo $renderer->sendingbackupinfo($backupfile);
00103 if (ob_get_level()) {
00104     ob_flush();
00105 }
00106 flush();
00107 
00108 //send backup file to the hub
00109 $curl = new curl();
00110 $params = array();
00111 $params['filetype'] = HUB_BACKUP_FILE_TYPE;
00112 $params['courseid'] = $hubcourseid;
00113 $params['file'] = $backupfile;
00114 $params['token'] = $registeredhub->token;
00115 $curl->post($huburl . "/local/hub/webservice/upload.php", $params);
00116 
00117 //delete the temp backup file from user_tohub aera
00118 $backupfile->delete();
00119 $bc->destroy();
00120 
00121 //Output sending success
00122 echo $renderer->sentbackupinfo($id, $huburl, $hubname);
00123 
00124 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations