forked from lsuits/lsu-block_quickmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature.php
188 lines (149 loc) · 5.53 KB
/
signature.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?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/>.
/**
* @package block_quickmail
* @copyright 2008-2017 Louisiana State University
* @copyright 2008-2017 Adam Zapletal, Chad Mazilly, Philip Cali, Robert Russo
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once('lib.php');
require_once('signature_form.php');
require_login();
$courseid = required_param('courseid', PARAM_INT);
$sigid = optional_param('id', 0, PARAM_INT);
$flash = optional_param('flash', 0, PARAM_INT);
$confirm = optional_param('confirm', 0, PARAM_INT);
if ($courseid and !$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('no_course', 'block_quickmail', '', $courseid);
}
$config = quickmail::load_config($courseid);
$context = context_course::instance($courseid);
$has_permission = (
has_capability('block/quickmail:cansend', $context) or
!empty($config['allowstudents'])
);
if (!$has_permission) {
print_error('no_permission', 'block_quickmail');
}
$blockname = quickmail::_s('pluginname');
$header = quickmail::_s('signature');
$title = "{$blockname}: {$header}";
$PAGE->set_context($context);
$PAGE->set_course($course);
$PAGE->set_url('/blocks/quickmail/signature.php', array(
'courseid' => $courseid, 'id' => $sigid
));
$PAGE->navbar->add($blockname);
$PAGE->navbar->add($header);
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->set_pagetype(quickmail::PAGE_TYPE);
$PAGE->set_pagelayout('standard');
$params = array('userid' => $USER->id);
$dbsigs = $DB->get_records('block_quickmail_signatures', $params);
$sig = (!empty($sigid) and isset($sigs[$sigid])) ? $sigs[$sigid] : new stdClass;
if (empty($sigid) or !isset($dbsigs[$sigid])) {
$sig = new stdClass;
$sig->id = null;
$sig->title = '';
$sig->signature = '';
} else {
$sig = $dbsigs[$sigid];
}
$sig->courseid = $courseid;
$sig->signatureformat = $USER->mailformat;
$options = array(
'trusttext' => true,
'subdirs' => true,
'maxfiles' => EDITOR_UNLIMITED_FILES,
'context' => $context
);
$sig = file_prepare_standard_editor($sig, 'signature', $options, $context,
'block_quickmail', 'signature', $sig->id);
$form = new signature_form(null, array('signature_options' => $options));
if ($confirm) {
$DB->delete_records('block_quickmail_signatures', array('id' => $sigid));
redirect(new moodle_url('/blocks/quickmail/signature.php', array(
'courseid' => $courseid,
'flash' => 1
)));
}
if ($form->is_cancelled()) {
redirect(new moodle_url('/course/view.php', array('id' => $courseid)));
} else if ($data = $form->get_data()) {
if (isset($data->delete)) {
$delete = true;
}
if (empty($data->title)) {
$warnings[] = quickmail::_s('required');
}
if (empty($warnings) and empty($delete)) {
$data->signature = $data->signature_editor['text'];
if (empty($data->default_flag)) {
$data->default_flag = 0;
}
$params = array('userid' => $USER->id, 'default_flag' => 1);
$default = $DB->get_record('block_quickmail_signatures', $params);
if ($default and !empty($data->default_flag)) {
$default->default_flag = 0;
$DB->update_record('block_quickmail_signatures', $default);
}
if (!$default) {
$data->default_flag = 1;
}
if (empty($data->id)) {
$data->id = null;
$data->id = $DB->insert_record('block_quickmail_signatures', $data);
}
// Persist relative links
$data = file_postupdate_standard_editor($data, 'signature', $options,
$context, 'block_quickmail', 'signature', $data->id);
$DB->update_record('block_quickmail_signatures', $data);
$url = new moodle_url('signature.php', array(
'id' => $data->id, 'courseid' => $course->id, 'flash' => 1
));
redirect($url);
}
}
echo $OUTPUT->header();
echo $OUTPUT->heading($header);
$first = array(0 => quickmail::_s('new').' '.quickmail::_s('sig'));
$only_names = function ($sig) {
return ($sig->default_flag) ? $sig->title . ' (Default)': $sig->title;
};
$sig_options = $first + array_map($only_names, $dbsigs);
$form->set_data($sig);
if ($flash) {
echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess');
}
if (!empty($delete)) {
$msg = get_string('are_you_sure', 'block_quickmail', $sig);
$confirm_url = new moodle_url('/blocks/quickmail/signature.php', array(
'id' => $sig->id,
'courseid' => $courseid,
'confirm' => 1
));
$cancel_url = new moodle_url('/blocks/quickmail/signature.php', array(
'id' => $sig->id,
'courseid' => $courseid
));
echo $OUTPUT->confirm($msg, $confirm_url, $cancel_url);
} else {
echo $OUTPUT->single_select('signature.php?courseid='.$courseid, 'id', $sig_options, $sigid);
$form->display();
}
echo $OUTPUT->footer();