-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetadataupdateconfirm.php
158 lines (133 loc) · 5.8 KB
/
metadataupdateconfirm.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?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/>.
/**
* Displays the filled fields of the metadata
*
* @package mod_sharedresource
* @author Frederic Guillou, Valery Fremaux <[email protected]>
* @copyright Valery Fremaux (activeprolearn.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
/*
* form and save these metadata and the resource.
* It informs the user if there are some errors and in that
* case, the resource is not saved and the user is sent back
* to the metadata form
*/
require('../../config.php');
require_once($CFG->dirroot.'/mod/sharedresource/lib.php');
require_once($CFG->dirroot.'/mod/sharedresource/metadatalib.php');
require_once($CFG->dirroot.'/mod/sharedresource/classes/sharedresource_entry.class.php');
require_once($CFG->dirroot.'/mod/sharedresource/classes/sharedresource_metadata.class.php');
$config = get_config('sharedresource');
require_once($CFG->dirroot.'/mod/sharedresource/plugins/'.$config->schema.'/plugin.class.php');
// Receive params.
$mode = required_param('mode', PARAM_ALPHA); // Mode 'add' or 'update' sequence.
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$cancel = optional_param('cancel', 0, PARAM_BOOL);
$return = optional_param('return', '', PARAM_ALPHA); // Tells where to return.
$section = optional_param('section', 0, PARAM_INT);
$catid = optional_param('catid', 0, PARAM_INT);
$catpath = optional_param('catpath', '', PARAM_TEXT);
$course = required_param('course', PARAM_INT);
$sharingcontext = optional_param('context', 1, PARAM_INT);
if (!$course = $DB->get_record('course', ['id' => $course])) {
throw new moodle_exception(get_string('badcourseid', 'sharedresource'));
}
// Security.
require_login($course);
$context = context_course::instance($course->id);
require_capability('repository/sharedresources:create', $context);
if ($cancel) {
// We are coming from the library. Go back to it.
if ($return != 'course') {
$params = [
'course' => $course->id,
'section' => $section,
'return' => $return,
'catid' => $catid,
'catpath' => $catpath,
];
$cancelurl = new moodle_url('/local/sharedresources/index.php', $params);
} else {
// We are coming from a course, more specially from a sharedresource instance modedit form.
$params = [
'course' => $course->id,
'sr' => $section,
'add' => 'sharedresource',
'return' => 0,
];
$cancelurl = new moodle_url('/course/modedit.php', $params);
}
redirect($cancelurl);
}
$SESSION->error = '';
$srentry = $SESSION->sr_entry;
$shrentry = unserialize($srentry);
if ($confirm) {
// These two lines in comment can be used if you want to show the user values of saved fields.
$shrentry->update_instance();
// If everything was saved correctly, go back to the search page or to the library.
if ($return) {
// We are coming from the library. Go back to it.
if ($return == 1) {
$params = ['course' => $course->id, 'catid' => $catid, 'catpath' => $catpath];
$fullurl = new moodle_url('/local/sharedresources/browse.php', $params);
} else {
$fullurl = new moodle_url('/local/sharedresources/explore.php', ['course' => $course->id]);
}
} else {
// We are coming from a new sharedresource instance call.
$params = [
'course' => $course->id,
'section' => $section,
'type' => $type,
'add' => 'sharedresource',
'return' => $return,
'entryid' => $shrentry->id,
];
$fullurl = new moodle_url('/course/modedit.php', $params);
}
redirect($fullurl, get_string('correctsave', 'sharedresource'), 5);
}
// Build and print the page.
$pagetitle = strip_tags($course->shortname);
$strtitle = $pagetitle;
$PAGE->set_pagelayout('standard');
$systemcontext = context_system::instance();
$PAGE->set_context($systemcontext);
$urlparams = ['mode' => $mode, 'course' => $course->id, 'section' => $section, 'return' => $return];
$url = new moodle_url('/mod/sharedresource/metadataupdateconfirm.php', $urlparams);
$PAGE->set_url($url);
$PAGE->set_title($strtitle);
$PAGE->set_heading($SITE->fullname);
// Navigation.
$PAGE->set_cacheable(false);
$renderer = $PAGE->get_renderer('mod_sharedresource');
$cancelurlparams = $urlparams;
$cancelurlparams['cancel'] = 1;
$cancelurl = new moodle_url('/mod/sharedresource/metadataupdateconfirm.php', $cancelurlparams);
$confirmurlparams = $urlparams;
$confirmurlparams['confirm'] = 1;
$confirmurl = new moodle_url('/mod/sharedresource/metadataupdateconfirm.php', $confirmurlparams);
$message = '<div id="sharedresource-in-the-way"><p>'.get_string('resourceintheway', 'sharedresource').'</p></div>';
$oldresource = \mod_sharedresource\entry::get_by_identifier($shrentry->identifier);
$message .= $renderer->resourcecompare($shrentry, $oldresource);
$message .= '<div id="sharedresource-update-confirm"><p>'.get_string('resourceupdate', 'sharedresource').'</p></div>';
echo $OUTPUT->header();
echo $OUTPUT->box($message, 'sharedresource-compare');
echo $OUTPUT->confirm('', $confirmurl, $cancelurl);
echo $OUTPUT->footer();