forked from moodleou/moodle-mod_oublog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editinstance.php
117 lines (99 loc) · 4.19 KB
/
editinstance.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
<?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 edit their personal blog
*
* @author Matt Clarkson <[email protected]>
* @author Sam Marshall <[email protected]>
* @package oublog
*/
define('OUBLOG_EDIT_INSTANCE', true);
require_once('../../config.php');
require_once('locallib.php');
require_once('lib.php');
require_once('mod_form.php');
$bloginstancesid = required_param('instance', PARAM_INT); // Bloginstance
$postid = optional_param('post', 0, PARAM_INT); // Post ID for editing
if (!$oubloginstance = $DB->get_record('oublog_instances', array('id'=>$bloginstancesid))) {
throw new moodle_exception('invalidblog', 'oublog');
}
if (!$oublog = $DB->get_record("oublog", array("id"=>$oubloginstance->oublogid))) {
throw new moodle_exception('invalidblog', 'oublog');
}
if (!$oublog->global) {
throw new moodle_exception('invalidblog', 'oublog');
}
if (!$cm = get_coursemodule_from_instance('oublog', $oublog->id)) {
throw new moodle_exception('invalidcoursemodule');
}
if (!$course = $DB->get_record("course", array("id"=>$oublog->course))) {
throw new moodle_exception('invalidcoursemodule');
}
// Check security.
if (!$oublog->global) {
throw new moodle_exception('onlyworkspersonal', 'oublog');
}
$url = new moodle_url('/mod/oublog/editinstance.php', array('instance'=>$bloginstancesid, 'post'=>$postid));
$PAGE->set_url($url);
$context = context_module::instance($cm->id);
oublog_check_view_permissions($oublog, $context, $cm);
$oubloguser = $DB->get_record('user', array('id'=>$oubloginstance->userid));
$viewurl = 'view.php?user='.$oubloginstance->userid;
if ($USER->id != $oubloginstance->userid && !has_capability('mod/oublog:manageposts', $context)) {
throw new moodle_exception('accessdenied', 'oublog');
}
// Get strings.
$stroublogs = get_string('modulenameplural', 'oublog');
$stroublog = get_string('modulename', 'oublog');
$streditpost = get_string('editpost', 'oublog');
$strblogoptions = get_string('blogoptions', 'oublog');
// Set-up groups.
$currentgroup = oublog_get_activity_group($cm, true);
$groupmode = oublog_get_activity_groupmode($cm, $course);
$mform = new mod_oublog_mod_form('editinstance.php', array('maxvisibility' => $oublog->maxvisibility, 'edit' => !empty($postid),
'postperpage' => $oublog->postperpage));
if ($mform->is_cancelled()) {
redirect($viewurl);
exit;
}
$textfieldoptions = array(
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $CFG->maxbytes,
'context' => $context,
);
if (!$frmoubloginstance = $mform->get_data()) {
$oubloginstance->instance = $oubloginstance->id;
$oubloginstance->summaryformat = FORMAT_HTML;
$oubloginstance = file_prepare_standard_editor($oubloginstance, 'summary', $textfieldoptions, $context,
'mod_oublog', 'summary', $oubloginstance->id);
$mform->set_data($oubloginstance);
// Print the header.
oublog_build_navigation($oublog, $oubloginstance, $oubloguser);
$PAGE->navbar->add($strblogoptions);
$PAGE->set_title(format_string($oublog->name));
echo $OUTPUT->header();
echo '<br />';
$mform->display();
echo $OUTPUT->footer();
} else {
// Handle form submission.
$frmoubloginstance->id = $frmoubloginstance->instance;
$frmoubloginstance->summaryformat = FORMAT_HTML;
$frmoubloginstance = file_postupdate_standard_editor($frmoubloginstance, 'summary', $textfieldoptions, $context,
'mod_oublog', 'summary', $frmoubloginstance->id);
$DB->update_record('oublog_instances', $frmoubloginstance);
redirect($viewurl);
}