-
Notifications
You must be signed in to change notification settings - Fork 138
/
mail.php
313 lines (255 loc) · 10.6 KB
/
mail.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
<?php
/**
* Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
* CC-BY License - http://creativecommons.org/licenses/by/3.0/
*/
require_once( 'inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
require_once( BX_DIRECTORY_PATH_ROOT . 'templates/tmpl_' . $tmpl . '/scripts/BxTemplMailBox.php');
$iProfileId = getLoggedId();
$aProfile = getProfileInfo($iProfileId);
// init some needed parameters ;
$sOutputHtml = '';
$sComposedPage = '';
// define message id (for view mode) ;
$iMessageID = ( isset($_GET['messageID']) )
? (int) $_GET['messageID']
: 0;
// define the message status such as : read, unread ;
$iMessageStatus = ( isset($_GET['status']) && $_GET['status'] == 'read' )
? 0
: 1 ;
// define the recipient ID ;
$vRecipientID = ( isset($_GET['recipient_id']) )
? $_GET['recipient_id']
: '';
// contain message's subject ;
$sMessageSubject = ( isset($_POST['subject']) )
? $_POST['subject']
: null;
// contain messages' body ;
$sMessageBody = ( isset($_POST['message']) )
? $_POST['message']
: '';
//? process_db_input( nl2br( urldecode($_POST['message']) ), BX_TAGS_VALIDATE) : null;
// contain all receivied messages id separeted by comma ;
$sMessagesList = isset( $_GET['messages'] )
? $_GET['messages']
: '';
// contain query from js for autocomplete;
$sAutoCompleteQ = ( isset($_GET['term']) )
? $_GET['term']
: '';
// try to segregate received messages list;
if ( $sMessagesList ) {
// array : contain all received messages id ;
$aMessagesList = array();
$aMessagesList = explode(',', $sMessagesList);
}
// contain some needed settings for the MailBox's object ;
$aMailBoxSettings = array
(
// logged member's ID ;
'member_id' => ($iProfileId || $aProfile['Role'] & BX_DOL_ROLE_ADMIN)
? $iProfileId
: 0,
// message recipient's ID ;
'recipient_id' => ($vRecipientID)
? (int) $vRecipientID
: 0,
// mailbox mode such as : inbox, outbox, trash ;
'mailbox_mode' => (isset($_GET['mode']))
? $_GET['mode']
: 'inbox',
// type of message's sort ;
'sort_mode' => (isset($_GET['sorting']))
? $_GET['sorting']
: 'date_desc',
// contain number of current page ;
'page' => (isset($_GET['page']))
? (int) $_GET['page']
: 0,
// contain per page number for current page ;
'per_page' => (isset($_GET['per_page']))
? (int) $_GET['per_page']
: 0,
// contain type of needed type of contacts (friends, faves ...)
'contacts_mode' => (isset($_GET['contacts_mode']))
? $_GET['contacts_mode']
: '',
// contain number of current contacts page ;
'contacts_page' => (isset($_GET['contacts_page']))
? (int) $_GET['contacts_page']
: 0,
// contain number of needed message ;
'messageID' => (isset($_GET['messageID']))
? (int) $_GET['messageID']
: 0,
);
// contain all needed settings for compose message ;
$aComposeSettings = array
(
// allow to send message to phisical recipient's email ;
'send_copy' => ( isset($_GET['copy_message']) )
? true
: false ,
// allow to send message to phisical sender's email;
'send_copy_to_me' => ( isset($_GET['copy_message_to_me']) )
? true
: false ,
// allow to send notification to the recipient's email ;
'notification' => ( isset($_GET['notify']) )
? true
: false ,
);
// define the type of message (greet, mail ...) ;
if ( isset($_GET['messages_types']) ) {
$aMailBoxSettings['messages_types'] = $_GET['messages_types'];
}
// ** swith the compose page;
switch($aMailBoxSettings['mailbox_mode']) {
case 'inbox' :
case 'outbox' :
case 'trash' :
$sComposedPage = 'mail_page';
break;
case 'compose' :
case 'view_message' :
$sComposedPage = $aMailBoxSettings['mailbox_mode'] == 'compose'
? 'mail_page_compose'
: 'mail_page_view';
//add some translation
$GLOBALS['oSysTemplate']->addJsTranslation('_Mailbox title empty');
$GLOBALS['oSysTemplate']->addJsTranslation('_Mailbox recipient empty');
$GLOBALS['oSysTemplate']->addJsTranslation('_Mailbox description empty');
break;
default :
$sComposedPage = 'mail_page';
}
// create BxTemplMailBox object
$oMailBox = new BxTemplMailBox($sComposedPage, $aMailBoxSettings);
if ( isset($_GET['ajax_mode']) and false !== bx_get('action') ) {
// contain all the available callback functions ;
$aCallbackFunctions = array( 'genMessagesRows', 'genArchiveMessages', 'getInboxMessagesCount' );
switch( bx_get('action') ) {
case 'sort' :
case 'paginate' :
case 'get_page' :
$sOutputHtml = $oMailBox -> genMessagesRows();
break;
// mark all the received messages ;
case 'mark' :
// mark action only for post method
if( isset($_POST['action']) && $_POST['action'] == 'mark') {
// mark message with received mode ;
if ( is_array($aMessagesList) and !empty($aMessagesList) ) {
foreach( $aMessagesList AS $iKey ) {
$iMessageID = (int) $iKey;
if ( $iMessageID )
$oMailBox -> setMarkMessage($iMessageID, $iMessageStatus);
}
$sOutputHtml = 'ok';
}
}
break;
// hide deleted messages ;
case 'hide_deleted' :
if ( is_array($aMessagesList ) and !empty($aMessagesList) ) {
foreach( $aMessagesList AS $iKey ) {
$iMessageID = (int) $iKey;
if ($iMessageID)
$oMailBox -> setTrashedMessage($iMessageID, 'TrashNotView');
}
}
break;
// delete all the received messages ;
case 'delete' :
// mark action only for post method
if( isset($_POST['action']) && $_POST['action'] == 'delete') {
if ( is_array($aMessagesList ) and !empty($aMessagesList) ) {
foreach( $aMessagesList AS $iKey ) {
$iMessageID = (int) $iKey;
if ( $iMessageID )
$oMailBox -> setTrashedMessage($iMessageID);
}
}
}
break;
// restore all the deleted messages from trash;
case 'restore' :
if( isset($_POST['action']) && $_POST['action'] == 'restore') {
if ( is_array($aMessagesList) and !empty($aMessagesList) ) {
foreach( $aMessagesList AS $iKey ) {
$iMessageID = (int) $iKey;
if ( $iMessageID )
$oMailBox -> setRestoredMessage($iMessageID);
}
}
}
break;
// will return count of inbox messages ;
case 'get_messages_count' :
$iMessageCount = $oMailBox -> getInboxMessagesCount();
$sResponceText = ( $iMessageCount ) ? ' (' . $iMessageCount . ') ' : null;
$sOutputHtml = $sResponceText;
break;
// will return all the arhive's message list ;
case 'archives_paginate' :
$sOutputHtml = $oMailBox -> genArchiveMessages();
break;
// will return message's replay window;
case 'reply_message' :
if ( $iMessageID and $vRecipientID ) {
$vRecipientID = (int) $vRecipientID;
$sOutputHtml = $oMailBox -> genReplayMessage($vRecipientID, $iMessageID);
}
break;
case 'compose_mail' :
$sErrorMessage = '';
//check message's options
if(!$sMessageSubject) {
$sErrorMessage = '_Mailbox title empty';
}
if(!$sMessageBody) {
$sErrorMessage = '_Mailbox description empty';
}
if(!$vRecipientID) {
$sErrorMessage = '_Mailbox recipient empty';
}
$sOutputHtml = !$sErrorMessage
? $oMailBox -> sendMessage($sMessageSubject, $sMessageBody, $vRecipientID, $aComposeSettings)
: _t_err($sErrorMessage);
break;
case 'auto_complete' :
if ( $sAutoCompleteQ )
$sOutputHtml = $oMailBox -> getAutoCompleteList($sAutoCompleteQ);
break;
case 'get_thumbnail' :
$iRecipientID = getId($vRecipientID);
if ( $iRecipientID )
$sOutputHtml = get_member_thumbnail($iRecipientID, 'none');
break;
}
// try to define the callback function name ;
if ( isset($_GET['callback_function']) and in_array($_GET['callback_function'], $aCallbackFunctions) ) {
if (method_exists($oMailBox, $_GET['callback_function']))
$sOutputHtml = $oMailBox->{$_GET['callback_function']}();
}
header('Content-Type: text/html; charset=utf-8');
echo $sOutputHtml;
exit;
}
// ** prepare to output page in normal mode ;
$sPageTitle = _t('_Mailbox');
$_page['name_index'] = 7;
$_page['header'] = $sPageTitle;
$_page['header_text'] = $sPageTitle;
$_page['js_name'] = $oMailBox->getJs();
$_page['css_name'] = $oMailBox->getCss();
$aVars = array ('BaseUri' => BX_DOL_URL_ROOT);
$GLOBALS['oTopMenu']->setCustomSubActions($aVars, 'Mailbox', false);
if(!$aMailBoxSettings['member_id'])
login_form(_t( "_LOGIN_OBSOLETE" ), 0, false);
$_ni = $_page['name_index'];
$_page_cont[$_ni]['page_main_code'] = $oMailBox->getCode();
PageCode();