forked from lsuits/lsu-block_quickmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature.php
107 lines (79 loc) · 2.97 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
<?php
// Written at Louisiana State University
require_once('../../config.php');
require_once('lib.php');
require_once('signature_form.php');
require_login();
$courseid = optional_param('courseid', null, PARAM_INT);
$sigid = optional_param('id', 0, PARAM_INT);
if ($courseid and !$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('no_course', 'block_quickmail', '', $courseid);
}
$context = empty($courseid) ?
get_context_instance(CONTEXT_SYSTEM) :
get_context_instance(CONTEXT_COURSE, $courseid);
if ($data = data_submitted()) {
if (isset($data->cancel)) {
$to = $courseid ? '/course/view.php?id='.$courseid : '/my';
redirect(new moodle_url($to));
}
if (empty($data->title) or empty($data->signature_editor['text'])) {
$warnings[] = quickmail::_s('required');
}
if (empty($warnings)) {
$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);
} else {
$DB->update_record('block_quickmail_signatures', $data);
}
$url = new moodle_url('signature.php', array('id' => $data->id, 'courseid' => $course->id));
redirect($url);
}
}
$params = array('userid' => $USER->id);
$dbsigs = $DB->get_records('block_quickmail_signatures', $params);
$sigs = array_map(function($sig) {
$sig->signature_editor = array('text' => $sig->signature, 'format' => 1);
return $sig;
},$dbsigs);
$blockname = quickmail::_s('pluginname');
$header = quickmail::_s('signature');
$title = "{$blockname}: {$header}";
$PAGE->set_context($context);
if($course) {
$PAGE->set_course($course);
$PAGE->set_url('/course/view.php', array('id' => $courseid));
}
$PAGE->navbar->add($blockname);
$PAGE->navbar->add($header);
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->set_pagetype($blockname);
echo $OUTPUT->header();
echo $OUTPUT->heading($header);
$first = array(0 => 'New '.quickmail::_s('sig'));
$only_names = function ($sig) {
return ($sig->default_flag) ? $sig->title . ' (Default)': $sig->title;
};
$sig_options = $first + array_map($only_names, $sigs);
echo $OUTPUT->single_select('signature.php?courseid='.$courseid, 'id', $sig_options, $sigid);
$sig = (!empty($sigid) and isset($sigs[$sigid])) ? $sigs[$sigid] : new stdClass;
$sig->courseid = $courseid;
$form = new signature_form();
$form->set_data($sig);
$form->display();
echo $OUTPUT->footer();