-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrenderer.php
451 lines (392 loc) · 19.2 KB
/
renderer.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<?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/>.
/**
* Block renderer
*
* @package blocks
* @subpackage jmail
* @copyright 2011 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
class block_jmail_renderer extends plugin_renderer_base {
/**
* Returns a plugin icon
* @param string $icon Icon name
* @return string
*/
function plugin_icon($icon) {
return '<img src="'.$this->output->pix_url($icon, 'block_jmail') . '" class="icon" alt="" /> ';
}
/**
* Link to the global inbox
* @return moodle_url
*/
function global_inbox() {
$url = new moodle_url('/blocks/jmail/mailbox.php', array('id'=>SITEID));
$inboxname = get_string('viewglobalinbox', 'block_jmail');
return html_writer::link($url, $inboxname, array('title'=>$inboxname));
return '';
}
/**
* Returns the course inbox
* @param object $course Course object
* @return moodle_url
*/
function course_inbox($course) {
$url = new moodle_url('/blocks/jmail/mailbox.php', array('id'=>$course->id));
$str = get_string('viewinbox', 'block_jmail');
return html_writer::link($url, $str, array('title'=>$str));
}
/**
* Prints the link to the inbox and the unread messages
* @param block_jmail_mailbox $mailbox Mailbox object
* @return moodle_url
*/
function unread_messages($mailbox) {
$url = new moodle_url('/blocks/jmail/mailbox.php', array('id'=>$mailbox->course->id));
$coursename = format_string($mailbox->course->shortname);
return html_writer::link($url, "$coursename (".get_string('unreadmessages', 'block_jmail', $mailbox->unreadcount).")", array('title'=>$coursename));
}
/**
* Load the html of the message print window
* @param block_jmail_message $message A message object
* @return string The html for the print window
*/
function message_print($message) {
$message = $message->full();
$destname = array('to' => get_string('to', 'block_jmail'),
'cc' => get_string('cc', 'block_jmail'),
'bcc' => get_string('bcc', 'block_jmail'));
$output = html_writer::start_tag('html');
$output .= html_writer::start_tag('head');
$output .= html_writer::tag('script', 'function Print(){document.body.offsetHeight;window.print()};');
$output .= html_writer::end_tag('head');
$output .= html_writer::start_tag('body', array('onload'=>'Print();'));
$output .= $this->output->heading($message->subject, 2);
$output .= $this->output->heading(get_string('from', 'block_jmail').': '.$message->from, 3);
$output .= $this->output->heading($message->date, 4);
if ($message->destinataries) {
foreach ($message->destinataries as $type => $destinataries) {
foreach ($destinataries as $dest) {
$output .= $this->output->heading($destname[$type].': '.$dest->fullname, 5);
}
}
}
$output .= html_writer::tag('p', $message->body);
$output .= html_writer::end_tag('body');
$output .= html_writer::end_tag('html');
return $output;
}
/**
* Loads the user interface
*/
function load_ui($mailbox) {
global $CFG;
$mystrings = array('subject','check','new'=>'newmail','inbox', 'drafts' => 'draft',
'sent'=>'sent', 'bin','toapprove','approve','delete','mymailboxes',
'reply','move','forward','print','addlabel','to','cc','bcc',
'send','save','more','preferences', 'markread', 'markunread', 'addlabel',
'replytoall' => 'replyall', 'receivecopies' , 'subscription', 'none', 'selected'
);
foreach ($mystrings as $key=>$value) {
$varname = 'str';
$varname .= is_numeric($key)? $value : $key;
$$varname = get_string($value, 'block_jmail');
}
$strfirstname = get_string('firstname');
$strlastname = get_string('lastname');
$strroles = get_string('roles');
$strgroups = get_string('groups');
$strall = get_string('all');
$strname = get_string('name');
$stredit = get_string('edit');
$cansend = $mailbox->cansend;
$loadingicon = $this->plugin_icon('loading');
// TODO - Making it works for AJAX added new labels
$optionslabels = '';
if ($labels = $mailbox->get_labels()) {
foreach ($labels as $l) {
$optionslabels .= '<option value="'.$l->id.'">'.$l->name.'</option>';
}
}
$alphabetfilter = '<a href="#" class="alphabetreset">'.$strall.'</a> ';
$alphabet = explode(',', get_string('alphabet', 'langconfig'));
list($groups, $roles) = $mailbox->get_groups_roles();
$groupsselect = '';
$rolesselect = '';
if (count($groups) > 0) {
$selector = html_writer::select($groups, 'groupselector', '', array(''=>'choosedots'), array('id'=>'groupselector'));
$groupsselect = '<input type="submit" id="groupselectorb" name="groupselectorb" value="'.$strgroups.'">'.$selector;
}
if (count($roles) > 1) {
$selector = html_writer::select($roles, 'rolesselector', '', null, array('id'=>'rolesselector'));
$rolesselect = '<input type="submit" id="rolesselectorb" name="rolesselectorb" value="'.$strroles.'">'.$selector;
}
foreach ($alphabet as $letter) {
$alphabetfilter .= '<a href="#" class="alphabet">'.$letter.'</a> ';
}
// Main toolbar html
$toolbar = '<button type="button" id="deleteb" name="deleteb" value="'.$strdelete.'">'.$strdelete.'</button>';
$toolbar .= '<button type="button" id="editb" name="editb" value="'.$stredit.'">'.$stredit.'</button>';
if (!empty($mailbox->config->approvemode) and has_capability('block/jmail:approvemessages', $mailbox->blockcontext)) {
$toolbar .= '<button type="button" id="approveb" name="approveb" value="'.$strapprove.'">'.$strapprove.'</button>';
}
if ($cansend) {
$toolbar .= '<button type="button" id="replyb" name="replyb" value="'.$strreply.'">'.$strreply.'</button>';
$toolbar .= '<button type="button" id="replytoallb" name="replytoallb" value="'.$strreplytoall.'">'.$strreplytoall.'</button>';
$toolbar .= '<button type="button" id="forwardb" name="forwardb" value="'.$strforward.'">'.$strforward.'</button>';
}
$toolbar .= '<button type="button" id="moveb" name="moveb" value="'.$strmove.'">'.$strmove.'</button>';
$toolbar .= ' <select id="labelsmenu" name="labelsmenu">
<option value="inbox">'.$strinbox.'</option>
</select> ';
$toolbar .= '<button type="button" id="moreb" name="moreb" value="'.$strmore.'">'.$strmore.'</button>';
$toolbar .= ' <select id="moremenu" name="moremenu">
<option value="markread">'.$strmarkread.'</option>
<option value="markunread">'.$strmarkunread.'</option>
</select> ';
$toolbar .= '<button type="button" id="printb" name="printb" value="'.$strprint.'">'.$strprint.'</button>';
// Action buttons html
$actionbuttons = '<button type="button" id="checkmail" name="checkmail" value="'.$strcheck.'">'.$strcheck.'</button>';
if ($cansend) {
$actionbuttons .= '<button type="button" id="newmail" name="newmail" value="'.$strnew.'">'.$strnew.'</button>';
}
// Contacts html
$contacts = '';
if ($cansend) {
$contacts = '
<div id="contact_list_filter">
<div>'.$groupsselect.'</div>
<div>'.$rolesselect.'</div>
<b>'.$strfirstname.'</b>
<div id="firstnamefilter">'.$alphabetfilter.'</div>
<b>'.$strlastname.'</b>
<div id="lastnamefilter">'.$alphabetfilter.'</div>
</div>
<div id="contact_list">
<div id="contact_list_users">'.$loadingicon.'</div>
<div id="selbuttons" style="clear: both">
<input type="checkbox" id="selectall">'.$strselected.'
<input type="button" class="selto" value=" '.$strto.' ">
<input type="button" class="selcc" value=" '.$strcc.' ">
<input type="button" class="selbcc" value=" '.$strbcc.' ">
</div>
</div>
';
}
$approvelabel = '';
if (!empty($mailbox->config->approvemode) and has_capability('block/jmail:approvemessages', $mailbox->blockcontext)) {
$approvelabel = '
<li class="inbox">
<em></em>
<a href="#" id="toapprove">'.$strtoapprove.'</a>
</li>';
}
// Preferences and labels
$preferences = '';
if ($mailbox->canmanagelabels) {
$preferences .= '<p><img src="'.$this->output->pix_url('add', 'block_jmail').'"><a href="#" id="addlabel"> '.$straddlabel.'</a></p>';
}
if ($mailbox->canmanagepreferences) {
$preferences .= '<p><img src="'.$this->output->pix_url('settings', 'block_jmail').'"><a href="#" id="preferences"> '.$strpreferences.'</a></p>';
}
// My mailboxes
$mymailboxes = '';
if ($mailboxes = $mailbox::get_my_mailboxes()) {
$mymailboxes .= '<button type="button" id="mailboxesb" name="mailboxesb" value="'.$strmymailboxes.'">'.$strmymailboxes.'</button>';
$mymailboxes .= '<select id="mailboxesmenu" name="mailboxesmenu">';
$counter = 0;
foreach ($mailboxes as $box) {
if ($box->id == $mailbox->course->id) {
continue;
}
$counter++;
// Apply some pad to the menu elements, we fill with white spaces.
$boxname = str_replace(' ', " ", str_pad(format_string($box->shortname), strlen($strmymailboxes) * 2));
$mymailboxes .= '<option value="'.$box->id.'">'.$boxname.'</option>';
}
$mymailboxes .= '</select> ';
if (!$counter) {
$mymailboxes = '';
}
}
// Tinymce editor
$editor = editors_get_preferred_editor(FORMAT_HTML);
$editor->use_editor('body');
// Moodle 2.3 and onwards
if ($CFG->version >= 2012062500) {
$script = '//<![CDATA[
M.yui.add_module({"core_dndupload":{"name":"core_dndupload","fullpath":"'.$CFG->wwwroot.'/lib\/form\/dndupload.js","requires":["node","event","json","core_filepicker"]},"form_filemanager":{"name":"form_filemanager","fullpath":"'.$CFG->wwwroot.'/lib\/form\/filemanager.js","requires":["core_filepicker","base","io-base","node","json","core_dndupload","panel","resize-plugin","dd-plugin"]}});
//]]>';
}
else {
$script = '//<![CDATA[
M.yui.add_module({"editor_tinymce":{"name":"editor_tinymce","fullpath":"'.$CFG->wwwroot.'/lib\/editor\/tinymce\/module.js","requires":[]},"form_filemanager":{"name":"form_filemanager","fullpath":"'.$CFG->wwwroot.'/lib\/form\/filemanager.js","requires":["core_filepicker","base","io","node","json","yui2-button","yui2-container","yui2-layout","yui2-menu","yui2-treeview"]}});
//]]>';
}
$warnings = '';
if (debugging('', DEBUG_NORMAL) and !empty($CFG->debugdisplay)) {
$warnings = $this->output->error_text(get_string('errordebugging', 'block_jmail')) . '<br />';
}
return '
<script type="text/javascript">
' . $script . '
</script>
' . $warnings . '
<div id="jmailui">
<div id="jmailleft">
<div id="action_buttons">
'.$actionbuttons.'
</div>
<div id="search_bar">
<input type="text" name="search" id="input_search"><span id="search_button"></span>
</div>
<div id="label_list">
<ul>
<li class="inbox">
<em></em>
<a href="#" id="inbox">'.$strinbox.'</a>
</li>
<li class="draft">
<em></em>
<a href="#" id="draft">'.$strdrafts.'</a>
</li>
<li class="sent">
<em></em>
<a href="#" id="sent">'.$strsent.'</a>
</li>
<li class="trash">
<em></em>
<a href="#" id="trash">'.$strbin.'</a>
</li>
'.$approvelabel.'
</ul>
<div id="user_labels">
'.$loadingicon.'
</div>
<div id="menulabel">
</div>
'.$preferences.'
<div id="mymailboxes">
'.$mymailboxes.'
</div>
<div id="loginfo" style="overflow: auto; width: 100%; height: 200px; border: solid 1px red; display: none">
</div>
</div>
</div>
<div id="jmailcenter">
<div id="mailarea">
<div id="jmailtoolbar">
'.$toolbar.'
</div>
<div id="maillist">
</div>
</div>
<div id="mailcontents">
</div>
</div>
<div id="jmailright">
'.$contacts.'
</div>
</div>
<div id="messagepanel"></div>
<div id="newemailpanel" style="display: none">
<div class="hd">'.$strnew.'</div>
<div id="newemailform" class="bd mform">
<div class="fitem">
<div class="fitemtitle">
<label for="composetoac">'.$strto.'</label>
</div>
<div class="felement ftext">
<input type="text" name="composetoac" id="composetoac" value="" size="50">
<div id="composetolist" class="composelist"></div>
</div>
</div>
<div class="fitem">
<div class="fitemtitle">
<label for="composeccac">'.$strcc.'</label>
</div>
<div class="felement ftext">
<input type="text" name="composeccac" id="composeccac" value="" size="50">
<div id="composecclist" class="composelist"></div>
</div>
</div>
<div class="fitem">
<div class="fitemtitle">
<label for="composebccac">'.$strbcc.'</label><br>
</div>
<div class="felement ftext">
<input type="text" name="composebccac" id="composebccac" value="" size="50">
<div id="composebcclist" class="composelist"></div>
</div>
</div>
<div class="fitem">
<div class="fitemtitle">
<label for="subject">'.$strsubject.'</label><br>
</div>
<div class="felement ftext">
<input type="text" name="subject" id="subject" value="" size="50">
</div>
</div>
<div id="newemailformremote"></div>
<div class="fitem">
<div class="fitemtitle">
</div>
<div class="felement ftext">
<input type="button" name="sendbutton" id="sendbutton" value="'.$strsend.'">
<input type="button" name="savebutton" id="savebutton" value="'.$strsave.'">
</div>
</div>
<input type="hidden" name="to" id="hiddento">
<input type="hidden" name="cc" id="hiddencc">
<input type="hidden" name="bcc" id="hiddenbcc">
</div>
<div class="ft"></div>
</div>
<div id="newlabelpanel" style="display: none">
<div class="yui3-widget-bd">
<form>
<fieldset>
<p>
<label for="id">'.$strname.'</label><br/>
<input type="text" name="newlabelname" id="newlabelname" placeholder="" maxlength="16">
</p>
</fieldset>
</form>
</div>
</div>
<div id="preferencespanel" style="display: none">
<div id="panelContent">
<div class="yui3-widget-bd">
<form>
<fieldset>
<p>
<label for="subscription">'.$strsubscription.'</label><br/>
<select name="subscription" id="subscription">
<option value="">'.$strnone.'</option>
<option value="receivecopies">'.$strreceivecopies.'</option>
</select>
</p>
</fieldset>
</form>
</div>
</div>
</div>
<div id="rendertarget"></div>
';
}
}