-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdeletelink.php
96 lines (83 loc) · 3.69 KB
/
deletelink.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
<?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/>.
/**
* This page allows a user to delete a blog comments
*
* @author Matt Clarkson <[email protected]>
* @package oublog
*/
require_once("../../config.php");
require_once("locallib.php");
$linkid = required_param('link', PARAM_INT); // Link ID to delete
$confirm = optional_param('confirm', 0, PARAM_INT); // Confirm that it is ok to delete link
$cmid = optional_param('cmid', null, PARAM_INT);
if (!$link = $DB->get_record('oublog_links', array('id'=> $linkid))) {
throw new moodle_exception('invalidlink', 'oublog');
}
if (!$cm = get_coursemodule_from_instance('oublog', $link->oublogid)) {
throw new moodle_exception('invalidcoursemodule');
}
if (!$course = $DB->get_record("course", array("id"=> $cm->course))) {
throw new moodle_exception('coursemisconf');
}
if (!$oublog = $DB->get_record("oublog", array("id"=> $cm->instance))) {
throw new moodle_exception('invalidcoursemodule');
}
$url = new moodle_url('/mod/oublog/deletelink.php', array('link'=>$linkid, 'confirm'=>$confirm));
$PAGE->set_url($url);
// Check security.
$context = context_module::instance($cm->id);
$childdata = oublog_get_blog_data_base_on_cmid_of_childblog($cmid, $oublog);
$childoublog = null;
$childcourse = null;
if (!empty($childdata)) {
$context = $childdata['context'];
$childoublog = $childdata['ousharedblog'];
$childcourse = $childdata['course'];
oublog_check_view_permissions($childdata['ousharedblog'], $childdata['context'], $childdata['cm']);
} else {
oublog_check_view_permissions($oublog, $context, $cm);
}
$correctglobal = isset($childoublog->global) ? $childoublog->global : $oublog->global;
$oubloginstance = $link->oubloginstancesid ? $DB->get_record('oublog_instances', array('id'=>$link->oubloginstancesid)) : null;
oublog_require_userblog_permission('mod/oublog:managelinks', $childoublog ? $childoublog : $oublog, $oubloginstance, $context);
if ($correctglobal) {
$blogtype = 'personal';
$oubloguser = $USER;
} else {
$blogtype = 'course';
}
$viewurl = new moodle_url('/mod/oublog/view.php', array('id' => $cmid ? $cmid : $cm->id));
if (!empty($linkid) && !empty($confirm)) {
oublog_delete_link($childoublog ? $childoublog : $oublog, $link);
redirect($viewurl);
exit;
}
// Get Strings.
$stroublogs = get_string('modulenameplural', 'oublog');
$stroublog = get_string('modulename', 'oublog');
// Print the header.
if ($blogtype == 'personal') {
$PAGE->navbar->add(fullname($oubloguser), new moodle_url('/user/view.php', array('id'=>$oubloguser->id)));
$PAGE->navbar->add(format_string($oublog->name));
}
$PAGE->set_title(format_string(!empty($childoublog->name) ? $childoublog->name : $oublog->name));
$PAGE->set_heading(format_string(!empty($childcourse->fullname) ? $childcourse->fullname : $course->fullname));
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmdeletelink', 'oublog'),
new moodle_url('/mod/oublog/deletelink.php', array('link'=>$linkid, 'confirm'=>'1', 'cmid' => $cmid)),
$viewurl);
echo $OUTPUT->footer();