$overwrite = new restore_course_overwrite_conf_setting('overwrite_conf', base_setting::IS_BOOLEAN, false);
$overwrite->set_ui(new backup_setting_ui_select($overwrite, $overwrite->get_name(), array(1=>get_string('yes'), 0=>get_string('no'))));
$overwrite->get_ui()->set_label(get_string('setting_overwriteconf', 'backup'));
+ $fixedtargets = array(backup::TARGET_NEW_COURSE, backup::TARGET_EXISTING_DELETING, backup::TARGET_CURRENT_DELETING);
+ if (in_array($this->get_target(), $fixedtargets)) {
+ $overwrite->set_value(true);
+ $overwrite->set_status(backup_setting::LOCKED_BY_CONFIG);
+ $overwrite->set_visibility(backup_setting::HIDDEN);
+ }
$this->add_setting($overwrite);
}
$PAGE->set_pagelayout('standard');
require_login($course, null, $cm);
+require_capability('moodle/restore:restorecourse', $context);
$isfrontpage = ($course->id == SITEID);
$restore = restore_ui::engage_independent_stage($stage/2, $contextid);
if ($restore->process()) {
$rc = new restore_controller($restore->get_filepath(), $restore->get_course_id(), backup::INTERACTIVE_YES,
- backup::MODE_GENERAL, $USER->id, backup::TARGET_NEW_COURSE);
+ backup::MODE_GENERAL, $USER->id, $restore->get_target());
}
}
if ($rc) {
*/
protected $type;
/**
- * @var base_setting
+ * The setting this UI belongs to (parent reference)
+ * @var base_setting|backup_setting
*/
protected $setting;
/**
));
echo $OUTPUT->box_start();
- echo get_string('executionsuccess', 'backup');
+ echo $OUTPUT->notification(get_string('executionsuccess', 'backup'), 'notifysuccess');
echo $OUTPUT->continue_button($fileurl);
echo $OUTPUT->box_end();
}
*/
function add_setting(backup_setting $setting, base_task $task=null) {
- // If the setting cant be changed then add it as a fixed setting.
- if (!$setting->get_ui()->is_changeable()) {
+ // If the setting cant be changed or isn't visible then add it as a fixed setting.
+ if (!$setting->get_ui()->is_changeable() || $setting->get_visibility() != backup_setting::VISIBLE) {
return $this->add_fixed_setting($setting);
}
return $this->ui;
}
- final public function is_first_stage() {
+ public function is_first_stage() {
return $this->stage == 1;
}
}
\ No newline at end of file
$html .= html_writer::end_tag('form');
}
- // New course
- $html .= $form;
- $html .= html_writer::start_tag('div', array('class'=>'bcs-new-course backup-section'));
- $html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header'));
- $html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked'));
- $html .= $this->backup_detail_select(get_string('coursecategory', 'backup'), 'targetid', $categories);
- $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
- $html .= html_writer::end_tag('div');
- $html .= html_writer::end_tag('form');
+ if (count($categories) > 0) {
+ // New course
+ $html .= $form;
+ $html .= html_writer::start_tag('div', array('class'=>'bcs-new-course backup-section'));
+ $html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header'));
+ $html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked'));
+ $html .= $this->backup_detail_select(get_string('coursecategory', 'backup'), 'targetid', $categories);
+ $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
+ $html .= html_writer::end_tag('div');
+ $html .= html_writer::end_tag('form');
+ }
- // Existing course
- $html .= $form;
- $html .= html_writer::start_tag('div', array('class'=>'bcs-existing-course backup-section'));
- $html .= $this->output->heading(get_string('restoretoexistingcourse', 'backup'), 2, array('class'=>'header'));
- $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING);
- $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING);
- $html .= $this->backup_detail_select(get_string('restoretocourse', 'backup'), 'targetid', $courses);
- $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
- $html .= html_writer::end_tag('div');
- $html .= html_writer::end_tag('form');
+ if (count($courses) > 0) {
+ // Existing course
+ $html .= $form;
+ $html .= html_writer::start_tag('div', array('class'=>'bcs-existing-course backup-section'));
+ $html .= $this->output->heading(get_string('restoretoexistingcourse', 'backup'), 2, array('class'=>'header'));
+ $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING);
+ $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING);
+ $html .= $this->backup_detail_select(get_string('restoretocourse', 'backup'), 'targetid', $courses);
+ $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
+ $html .= html_writer::end_tag('div');
+ $html .= html_writer::end_tag('form');
+ }
$html .= html_writer::end_tag('div');
return $html;
return $output.html_writer::end_tag('div');
}
- public function continue_button($url) {
+ public function continue_button($url, $method='post') {
if (!($url instanceof moodle_url)) {
$url = new moodle_url($url);
}
+ if ($method != 'post') {
+ $method = 'get';
+ }
$url->param('sesskey', sesskey());
- $button = new single_button($url, get_string('continue'), 'post');
+ $button = new single_button($url, get_string('continue'), $method);
$button->class = 'continuebutton';
return $this->render($button);
}
final public function get_name() {
return get_string('restorestage'.$this->stage,'backup');
}
+ final public function is_first_stage() {
+ return $this->stage == restore_ui::STAGE_SETTINGS;
+ }
}
abstract class restore_ui_independent_stage {
if (!file_exists("$CFG->dataroot/temp/backup/".$this->filename)) {
throw new restore_ui_exception('invalidrestorefile');
}
- return $this->extract_file_to_dir();
+ $outcome = $this->extract_file_to_dir();
+ if ($outcome) {
+ fulldelete($this->filename);
+ }
+ return $outcome;
}
protected function extract_file_to_dir() {
global $CFG, $USER;
protected $filepath = null;
protected $details;
protected $courseid = null;
+ protected $target = backup::TARGET_NEW_COURSE;
public function __construct($contextid) {
$this->contextid = $contextid;
$this->filepath = required_param('filepath', PARAM_ALPHANUM);
if (!file_exists("$CFG->dataroot/temp/backup/".$this->filepath) || !is_dir("$CFG->dataroot/temp/backup/".$this->filepath)) {
throw new restore_ui_exception('invalidrestorepath');
}
- $target = optional_param('target', null, PARAM_INT);
- if (!is_null($target) && confirm_sesskey()) {
- $targetid = required_param('targetid', PARAM_INT);
- if ($target == backup::TARGET_NEW_COURSE) {
+ $this->target = optional_param('target', backup::TARGET_NEW_COURSE, PARAM_INT);
+ $targetid = optional_param('targetid', null, PARAM_INT);
+ if (!is_null($this->target) && !is_null($targetid) && confirm_sesskey()) {
+ if ($this->target == backup::TARGET_NEW_COURSE) {
list($fullname, $shortname) = restore_dbops::calculate_course_names(0, get_string('restoringcourse', 'backup'), get_string('restoringcourseshortname', 'backup'));
$this->courseid = restore_dbops::create_new_course($fullname, $shortname, $targetid);
} else {
* @return string
*/
public function display($renderer) {
- global $DB;
+ global $DB, $USER;
$this->details = backup_general_helper::get_backup_information($this->filepath);
$url = new moodle_url('/backup/restore.php', array('contextid'=>$this->contextid, 'filepath'=>$this->filepath, 'stage'=>restore_ui::STAGE_SETTINGS));
+
$context = get_context_instance_by_id($this->contextid);
- $currentcourse = ($context->contextlevel == CONTEXT_COURSE)?$context->instanceid:false;
+ $currentcourse = ($context->contextlevel == CONTEXT_COURSE && has_capability('moodle/restore:restorecourse', $context))?$context->instanceid:false;
+
$courselist = array();
- $courses = $DB->get_recordset('course', array(), 'id,fullname,shortname');
+ $courses = get_user_capability_course('moodle/restore:restorecourse', $USER->id, true, 'fullname,shortname,visible,sortorder');
foreach ($courses as $course) {
$courselist[$course->id] = $course->fullname.' ['.$course->shortname.']';
}
- $courses->close();
- $html = $renderer->course_selector($url, $this->details, make_categories_options(), $courselist, $currentcourse);
+
+ $categories = make_categories_options();
+ foreach ($categories as $categoryid=>$category) {
+ if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $categoryid))) {
+ unset($categories[$categoryid]);
+ }
+ }
+
+ $html = $renderer->course_selector($url, $this->details, $categories, $courselist, $currentcourse);
return $html;
}
public function get_stage_name() {
public function get_stage() {
return restore_ui::STAGE_DESTINATION;
}
+ public function get_target() {
+ return $this->target;
+ }
}
class restore_ui_stage_settings extends restore_ui_stage {
* appropriate message.
*
* @global core_renderer $OUTPUT
+ * @param core_backup_renderer $renderer
*/
- public function display($renderer) {
+ public function display(core_backup_renderer $renderer) {
global $OUTPUT;
echo $OUTPUT->box_start();
echo $OUTPUT->notification(get_string('restoreexecutionsuccess', 'backup'), 'notifysuccess');
- echo $renderer->continue_button(new moodle_url('/course/view.php', array('id'=>$this->get_ui()->get_controller()->get_courseid())));
+ echo $renderer->continue_button(new moodle_url('/course/view.php', array('id'=>$this->get_ui()->get_controller()->get_courseid())), 'get');
echo $OUTPUT->box_end();
}
}
\ No newline at end of file