-
Notifications
You must be signed in to change notification settings - Fork 1
/
import.php
113 lines (95 loc) · 3.77 KB
/
import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* blocks/taskchain_navigation/import.php
*
* @package blocks
* @subpackage taskchain_navigation
* @copyright 2014 Gordon Bateson <gordon.bateson@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
/** Include required files */
require_once('../../config.php');
require_once($CFG->dirroot.'/lib/xmlize.php');
require_once($CFG->dirroot.'/blocks/taskchain_navigation/import_form.php');
// cache the plugin name - because it is quite long ;-)
$plugin = 'block_taskchain_navigation';
// get the incoming block_instance id
$id = required_param('id', PARAM_INT);
if (! $block_instance = $DB->get_record('block_instances', array('id' => $id))) {
print_error('invalidinstanceid', $plugin, '', $id);
}
if (! $block = $DB->get_record('block', array('name' => $block_instance->blockname))) {
print_error('invalidblockname', $plugin, '', $block_instance);
}
if (! $context = $DB->get_record('context', array('id' => $block_instance->parentcontextid))) {
print_error('invalidcontextid', $plugin, '', $block_instance);
}
if (! $course = $DB->get_record('course', array('id' => $context->instanceid))) {
print_error('invalidcourseid', $plugin, '', $context);
}
require_login($course->id);
if (class_exists('context')) {
$context = context::instance_by_id($context->id);
} else {
$context = get_context_instance_by_id($context->id);
}
require_capability('moodle/site:manageblocks', $context);
// $SCRIPT is set by initialise_fullme() in 'lib/setuplib.php'
// It is the path below $CFG->wwwroot of this script
$url = new moodle_url($SCRIPT, array('id' => $id));
// initialize form
$mform = new block_taskchain_navigation_import_form($url);
if ($mform->is_cancelled()) {
$params = array('id' => $course->id,
'sesskey' => sesskey(),
'bui_editid' => $block_instance->id);
redirect(new moodle_url('/course/view.php', $params));
}
$blockname = get_string('blockname', $plugin);
$pagetitle = get_string('importsettings', $plugin);
$PAGE->set_url($url);
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('incourse');
$PAGE->navbar->add($blockname);
$PAGE->navbar->add($pagetitle, $url);
echo $OUTPUT->header();
echo $OUTPUT->heading($pagetitle);
echo $OUTPUT->box_start('generalbox');
if ($xml = $mform->get_file_content('importfile')) {
if ($mform->import($xml, $block_instance, $course)) {
// successful import
$msg = get_string('validimportfile', $plugin);
$style = 'notifysuccess';
} else {
// import didn't work - shouldn't happen !!
$msg = get_string('invalidimportfile', $plugin);
$style = 'notifyproblem';
}
echo $OUTPUT->notification($msg, $style);
$params = array('id' => $course->id,
'sesskey' => sesskey(),
'bui_editid' => $block_instance->id);
$url = new moodle_url('/course/view.php', $params);
echo $OUTPUT->continue_button($url);
} else {
// show the import form
$mform->display();
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);