-
Notifications
You must be signed in to change notification settings - Fork 9
/
mailbox.php
153 lines (129 loc) · 6.81 KB
/
mailbox.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
<?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/>.
/**
* Main block functions.
*
* @package blocks
* @subpackage jmail
* @copyright 2011 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot.'/blocks/jmail/locallib.php');
require_once($CFG->dirroot.'/blocks/jmail/block_jmail_mailbox.class.php');
$id = optional_param('id', SITEID, PARAM_INT);
$to = optional_param('to', 0, PARAM_INT);
$PAGE->set_url('/blocks/jmail/mailbox.php', array('id'=>$id));
if (! ($course = $DB->get_record('course', array('id'=>$id)))) {
throw new moodle_exception('invalidcourseid', 'error');
}
if (! ($block = $DB->get_record('block', array('name'=>'jmail', 'visible'=>1)))) {
throw new moodle_exception('invalidcourseid', 'error');
}
require_login($course->id);
$context = block_jmail_get_context(CONTEXT_COURSE, $course->id, MUST_EXIST);
$PAGE->set_context($context);
if (!$mailbox = new block_jmail_mailbox($course, $context)) {
throw new moodle_exception('Invalid mailbox');
}
// TODO, check block disabled or instance not visible?
$PAGE->blocks->show_only_fake_blocks();
$renderer = $PAGE->get_renderer('block_jmail');
$strheading = (!empty($mailbox->config->title))? format_string($mailbox->config->title) : get_string('pluginname', 'block_jmail');
$PAGE->navbar->add($strheading);
$PAGE->set_title($strheading);
$PAGE->set_heading($course->fullname . ': '.$strheading);
$module = array(
'name' => 'block_jmail',
'fullpath' => '/blocks/jmail/module.js',
'requires' => array('io', 'event-custom', 'json-parse', 'base', 'node', 'tabview', 'datasource-get', 'datasource-jsonschema', 'datatable-base', 'datatable-datasource', 'datatable-sort', 'panel', 'autocomplete', 'autocomplete-highlighters'),
'strings' => array(array('from','block_jmail'),array('subject','block_jmail'),array('date','block_jmail'),array('messagesent','block_jmail'),
array('reply','block_jmail'),array('forward','block_jmail'),array('print','block_jmail'), array('messagesaved','block_jmail'),
array('addlabel','block_jmail'),array('cc','block_jmail'),array('bcc','block_jmail'),array('messagedeleted','block_jmail'),
array('messagesdeleted','block_jmail'),array('errortorequired','block_jmail'),array('errorsubjectrequired','block_jmail'),
array('to','block_jmail'),array('confirmdelete','block_jmail'), array('label','block_jmail'), array('labels','block_jmail'),
array('nomessagesfound','block_jmail'),array('re','block_jmail'),array('fw','block_jmail'),array('attachments','block_jmail'),
array('preferences','block_jmail'),array('approvalpending','block_jmail'),array('messagehastobeapproved','block_jmail'),
array('first','block_jmail'),array('last','block_jmail'),array('next','block_jmail'),array('previous','block_jmail'),
array('delete','block_jmail'), array('save','block_jmail'),array('download','block_jmail'),array('savetomyprivatefiles','block_jmail'),array('filesaved','block_jmail'),
array('mailbox','block_jmail'),array('delivertodifferentcourse','block_jmail'),array('delivertoglobalinbox','block_jmail'),
array('inbox','block_jmail'),
array('add','moodle'),array('deletem','block_jmail'),array('rename','moodle'),array('edit','moodle'), array('ok','moodle'),
array('cancel','moodle'))
);
$usertoid = 0;
$usertoname = '';
if ($userto = $DB->get_record('user', array('id' => $to, 'deleted' => 0))) {
$d = new stdClass;
$d->type = 'to';
$d->userid = $userto->id;
$destinataries[] = $d;
if ($mailbox->check_destinataries($destinataries)) {
$usertoid = $userto->id;
$usertoname = fullname($userto);
}
}
$editor = '';
if ($CFG->version >= 2014051200) {
if ($USER->preference) {
if (!empty($USER->preference['htmleditor'])) {
$editor = $USER->preference['htmleditor'];
}
}
}
if (!$editor) {
require_once($CFG->libdir.'/editorlib.php');
$editors = array_keys(editors_get_enabled());
if (count($editors) > 1) {
$editor = array_shift($editors);
}
}
$usercontext = block_jmail_get_context(CONTEXT_USER, $USER->id);
$privatefiles = has_capability('moodle/user:manageownfiles', $usercontext);
$jmailcfg = array(
'wwwroot' => $CFG->wwwroot,
'courseid' => $course->id,
'sesskey' => sesskey(),
'pagesize' => $mailbox->pagesize,
'cansend' => $mailbox->cansend,
'canapprovemessages' => $mailbox->canapprovemessages,
'canmanagelabels' => $mailbox->canmanagelabels,
'canmanagepreferences' => $mailbox->canmanagepreferences,
'userid' => $USER->id,
'globalinbox' => $mailbox->globalinbox,
'approvemode' => (! empty($mailbox->config->approvemode))? $mailbox->config->approvemode : false,
'usertoid' => $usertoid,
'usertoname' => $usertoname,
'version' => $CFG->version,
'editor' => $editor,
'privatefiles' => $privatefiles
);
//$PAGE->requires->js('/lib/editor/tinymce/tiny_mce/3.4.2/tiny_mce.js');
//MDL-34741 switch to YUI2 to 2in3 (2.4 and above)
if ($CFG->version < 2012120300) {
$PAGE->requires->yui2_lib(array('event', 'dragdrop', 'element', 'animation', 'resize', 'layout', 'widget', 'button', 'editor', 'get', 'connection', 'datasource', 'datatable', 'container', 'utilities', 'menu', 'json', 'paginator'));
}
//MDL-34741 switch to YUI2 to 2in3 (2.4 and above)
if ($CFG->version < 2012120300) {
// 2.1, 2.2, 2.3
$PAGE->requires->js_init_call('M.block_jmail.init', array($jmailcfg), true, $module);
} else {
// 2.4 and onwards..
$PAGE->requires->js_init_call('M.block_jmail.initYAHOO', array($jmailcfg), true, $module);
}
echo $OUTPUT->header();
echo $renderer->load_ui($mailbox);
echo $OUTPUT->footer();