forked from meyersh/moodle-block_quickmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_form.php
158 lines (132 loc) · 7.31 KB
/
email_form.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
require_once($CFG->libdir . '/formslib.php');
class email_form extends moodleform {
private function reduce_users($in, $user) {
return $in . '<option value="'.$this->option_value($user).'">'.
$this->option_display($user).'</option>';
}
private function option_display($user) {
$users_to_groups = $this->_customdata['users_to_groups'];
$groups = (empty($users_to_groups[$user->id])) ?
get_string('no_section', 'block_quickmail') :
implode(',', array_map(function($group) {
return $group->name;
},
$users_to_groups[$user->id]));
return sprintf("%s (%s)", fullname($user), $groups);
}
private function option_value($user) {
$users_to_groups = $this->_customdata['users_to_groups'];
$users_to_roles = $this->_customdata['users_to_roles'];
$roles = implode(',', array_map(function($role) {
return $role->shortname;
}, $users_to_roles[$user->id]));
// everyone defaults to none
$roles .= ',none';
$groups = (empty($users_to_groups[$user->id])) ? 0 : implode(',',
array_map(function($group) {
return $group->id;
}, $users_to_groups[$user->id]));
return sprintf("%s %s %s", $user->id, $groups, $roles);
}
public function definition() {
global $CFG, $USER, $COURSE, $OUTPUT;
$mform =& $this->_form;
$mform->addElement('hidden', 'mailto', '');
$mform->addElement('hidden', 'userid', $USER->id);
$mform->addElement('hidden', 'courseid', $COURSE->id);
$mform->addElement('hidden', 'type', '');
$mform->addElement('hidden', 'typeid', 0);
$links = array();
$email_link = 'emaillog.php?courseid='.$COURSE->id.'&type=';
$draft_link = '<center style="margin-left: -13%"><a href="'.$email_link.'drafts">'.
get_string('drafts', 'block_quickmail').'</a>';
$links[] =& $mform->createElement('static', 'draft_link', '', $draft_link);
$context= get_context_instance(CONTEXT_COURSE, $COURSE->id);
if(has_capability('block/quickmail:cansend', $context)) {
$history_link = '<a href="'.$email_link.'log">'.
get_string('history', 'block_quickmail').'</a></center>';
$links[] =& $mform->createElement('static', 'history_link', '', $history_link);
}
$mform->addGroup($links, 'links', ' ', array(' | '), false);
$mform->addElement('static', 'from', get_string('from', 'block_quickmail'), $USER->email);
$mform->addElement('static', 'selectors', '', '
<table>
<tr>
<td>
<strong class="required">'.get_string('selected', 'block_quickmail').'
<img class="req" title="Required field" alt="Required field" src="'.$OUTPUT->pix_url('req').'"/>
</strong>
</td>
<td align="right" colspan="2">
<strong>'.get_string('role_filter', 'block_quickmail').'</strong>
</td>
</tr>
<tr>
<td width="300">
<select id="mail_users" multiple size="30">
'.array_reduce($this->_customdata['selected'], array($this, 'reduce_users'), '').'
</select>
</td>
<td width="100" align="center">
<p>
<input type="button" id="add_button" value="'.get_string('add_button', 'block_quickmail').'"/>
</p>
<p>
<input type="button" id="remove_button" value="'.get_string('remove_button', 'block_quickmail').'"/>
</p>
<p>
<input type="button" id="add_all" value="'.get_string('add_all', 'block_quickmail').'"/>
</p>
<p>
<input type="button" id="remove_all" value="'.get_string('remove_all', 'block_quickmail').'"/>
</p>
</td>
<td width="300" align="right">
<div>
<select id="roles">
<option value="none" selected>'.get_string('no_filter', 'block_quickmail').'</option>
'.array_reduce($this->_customdata['roles'], function($in, $role) {
return $in . '<option value="'.$role->shortname.'">'.$role->name.'</option>';
}, '').'
</select>
</div>
<div class="object_labels"><strong>'.get_string('potential_sections', 'block_quickmail').'</strong></div>
<div>
<select id="groups" multiple size="5">
'.array_reduce($this->_customdata['groups'], function($in, $group) {
return $in . '<option value="'.$group->id.'">'.$group->name.'</option>';
}, '').'
<option value="0">'.get_string('no_section', 'block_quickmail').'</option>
</select>
</div>
<div class="object_labels"><strong>'.get_string('potential_users', 'block_quickmail').'</strong></div>
<div>
<select id="from_users" multiple size="20">
'.array_reduce($this->_customdata['users'], array($this, 'reduce_users'), '').'
</select>
</div>
</td>
</tr>
</table>
');
$mform->addElement('filemanager', 'attachments', get_string('attachment', 'block_quickmail'));
$mform->addElement('text', 'subject', get_string('subject', 'block_quickmail'));
$mform->setType('subject', PARAM_TEXT);
$mform->addRule('subject', null, 'required');
$mform->addElement('editor', 'message', get_string('message', 'block_quickmail'));
$options = $this->_customdata['sigs'] + array(-1 => 'No '. get_string('sig', 'block_quickmail'));
$mform->addElement('select', 'sigid', get_string('signature', 'block_quickmail'), $options);
$radio = array(
$mform->createElement('radio', 'receipt', '', get_string('yes'), 1),
$mform->createElement('radio', 'receipt', '', get_string('no'), 0)
);
$mform->addGroup($radio, 'receipt_action', get_string('receipt', 'block_quickmail'), array(' '), false);
// TODO: add receipts
$buttons = array();
$buttons[] =& $mform->createElement('submit', 'send', get_string('send_email', 'block_quickmail'));
$buttons[] =& $mform->createElement('submit', 'draft', get_string('save_draft', 'block_quickmail'));
$buttons[] =& $mform->createElement('submit', 'cancel', get_string('cancel'));
$mform->addGroup($buttons, 'buttons', get_string('actions', 'block_quickmail'), array(' '), false);
}
}