|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Gorlum 08.10.2017 17:14 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Pages\Deprecated; |
|
7
|
|
|
|
|
8
|
|
|
use \SN; |
|
9
|
|
|
use \classLocale; |
|
10
|
|
|
use \DBAL\DbQuery; |
|
11
|
|
|
use DBAL\DbSqlPaging; |
|
12
|
|
|
use Fleet\MissionEspionageReport; |
|
13
|
|
|
use General\Helpers\PagingRenderer; |
|
14
|
|
|
use Pm\DecodeEspionage; |
|
15
|
|
|
use \template; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class PageMessage |
|
19
|
|
|
* @package Deprecated |
|
20
|
|
|
* |
|
21
|
|
|
* Refactor of /messages.php |
|
22
|
|
|
*/ |
|
23
|
|
|
class PageMessage extends PageDeprecated { |
|
24
|
|
|
/** |
|
25
|
|
|
* List messages amount per category |
|
26
|
|
|
*/ |
|
27
|
|
|
const MESSAGES_MODE_CATEGORIES = ''; |
|
28
|
|
|
/** |
|
29
|
|
|
* Delete message(s) |
|
30
|
|
|
*/ |
|
31
|
|
|
const MESSAGES_MODE_DELETE = 'delete'; |
|
32
|
|
|
/** |
|
33
|
|
|
* Write personal message |
|
34
|
|
|
*/ |
|
35
|
|
|
const MESSAGES_MODE_COMPOSE = 'write'; |
|
36
|
|
|
/** |
|
37
|
|
|
* Show messages in category |
|
38
|
|
|
*/ |
|
39
|
|
|
const MESSAGES_MODE_MESSAGES = 'show'; |
|
40
|
|
|
|
|
41
|
|
|
const MESSAGES_DELETE_RANGE_NONE = ''; |
|
42
|
|
|
// const MESSAGES_DELETE_RANGE_UNCHECKED = 'unchecked'; |
|
43
|
|
|
const MESSAGES_DELETE_RANGE_CHECKED = 'checked'; |
|
44
|
|
|
const MESSAGES_DELETE_RANGE_CLASS = 'class'; |
|
45
|
|
|
const MESSAGES_DELETE_RANGE_ALL = 'all'; |
|
46
|
|
|
|
|
47
|
|
|
const MESSAGES_DELETE_RANGES_ALLOWED = [ |
|
48
|
|
|
// self::MESSAGES_DELETE_RANGE_UNCHECKED, |
|
49
|
|
|
self::MESSAGES_DELETE_RANGE_CHECKED, |
|
50
|
|
|
self::MESSAGES_DELETE_RANGE_CLASS, |
|
51
|
|
|
self::MESSAGES_DELETE_RANGE_ALL, |
|
52
|
|
|
]; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var array[] $messageClassList - [int => ['name' => string, 'switchable' => bool, 'email' => bool]] |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $messageClassList = []; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var classLocale $lang |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $lang; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Current page mode |
|
66
|
|
|
* |
|
67
|
|
|
* @var $mode |
|
68
|
|
|
* // TODO - change type to INT when finish |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $mode; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var int $current_class |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $current_class; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var string $recipient_name_unsafe |
|
79
|
|
|
*/ |
|
80
|
|
|
// TODO - UNSAFE USAGES! |
|
81
|
|
|
protected $recipient_name_unsafe = ''; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @var int|string $recipient_id_unsafe |
|
85
|
|
|
*/ |
|
86
|
|
|
protected $recipient_id_unsafe = 0; |
|
87
|
|
|
|
|
88
|
|
|
protected $showAll = false; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @var string $subject_unsafe |
|
92
|
|
|
*/ |
|
93
|
|
|
protected $subject_unsafe = ''; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Text to send |
|
97
|
|
|
* |
|
98
|
|
|
* @var string $sendText_unsafe |
|
99
|
|
|
*/ |
|
100
|
|
|
protected $sendText_unsafe = ''; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Reference to current PLAYER DB record |
|
104
|
|
|
* |
|
105
|
|
|
* @var array $user |
|
106
|
|
|
*/ |
|
107
|
|
|
protected $user; |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @var int|string |
|
111
|
|
|
*/ |
|
112
|
|
|
protected $playerId = 0; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @var mixed $doSend |
|
116
|
|
|
*/ |
|
117
|
|
|
protected $doSend = false; |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @var string $deleteRange |
|
121
|
|
|
*/ |
|
122
|
|
|
protected $deleteRange = ''; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @var \DBAL\db_mysql $db |
|
126
|
|
|
*/ |
|
127
|
|
|
protected $db; |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @var array |
|
131
|
|
|
*/ |
|
132
|
|
|
protected $markedMessageIdList = []; |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* PageMessage constructor. |
|
137
|
|
|
*/ |
|
138
|
|
|
public function __construct() { |
|
139
|
|
|
parent::__construct(); |
|
140
|
|
|
|
|
141
|
|
|
global $sn_message_class_list; |
|
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
$this->lang = SN::$lang; |
|
144
|
|
|
$this->messageClassList = $sn_message_class_list; |
|
145
|
|
|
|
|
146
|
|
|
$this->db = SN::$gc->db; |
|
147
|
|
|
|
|
148
|
|
|
$this->loadParams(); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function route() { |
|
152
|
|
|
$this->getUserRef(); |
|
153
|
|
|
|
|
154
|
|
|
$template = null; |
|
155
|
|
|
|
|
156
|
|
|
switch ($this->mode) { |
|
157
|
|
|
case static::MESSAGES_MODE_COMPOSE: |
|
158
|
|
|
$this->modelCompose(); |
|
159
|
|
|
$template = $this->viewCompose(); |
|
160
|
|
|
break; |
|
161
|
|
|
|
|
162
|
|
|
/** @noinspection PhpMissingBreakStatementInspection */ |
|
163
|
|
|
case static::MESSAGES_MODE_DELETE: |
|
|
|
|
|
|
164
|
|
|
$this->modelDelete(); |
|
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
case static::MESSAGES_MODE_MESSAGES: |
|
167
|
|
|
if (sys_get_param_int('return')) { |
|
168
|
|
|
sys_redirect('messages.php'); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
$template = $this->viewMessageList(); |
|
172
|
|
|
break; |
|
173
|
|
|
|
|
174
|
|
|
default: |
|
175
|
|
|
$template = $this->viewCategories(); |
|
176
|
|
|
break; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
display($template, $this->lang['msg_page_header']); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
protected function modelCompose() { |
|
183
|
|
|
$this->getRecipientData(); |
|
184
|
|
|
|
|
185
|
|
|
if ($this->recipient_id_unsafe == $this->playerId) { |
|
186
|
|
|
$this->resultAdd($this->lang['msg_err_self_send'], ERR_ERROR); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
if ($this->doSend) { |
|
190
|
|
|
if (empty($this->recipient_id_unsafe)) { |
|
191
|
|
|
$this->resultAdd($this->lang['msg_err_player_not_found'], ERR_ERROR); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
if (!$this->sendText_unsafe) { |
|
195
|
|
|
$this->resultAdd($this->lang['msg_err_no_text'], ERR_ERROR); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
if (!$this->resultCount()) { |
|
199
|
|
|
$this->wrapSendPm(); |
|
200
|
|
|
|
|
201
|
|
|
$this->sendText_unsafe = ''; |
|
202
|
|
|
|
|
203
|
|
|
$this->resultAdd($this->lang['msg_not_message_sent'], ERR_NONE); |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @return template |
|
210
|
|
|
*/ |
|
211
|
|
|
protected function viewCompose() { |
|
212
|
|
|
$template = gettemplate('msg_message_compose', true); |
|
|
|
|
|
|
213
|
|
|
$template->assign_vars([ |
|
214
|
|
|
'RECIPIENT_ID' => $this->recipient_id_unsafe, |
|
215
|
|
|
'RECIPIENT_NAME' => htmlspecialchars($this->recipient_name_unsafe), |
|
216
|
|
|
'SUBJECT' => htmlspecialchars($this->subject_unsafe), |
|
217
|
|
|
'TEXT' => htmlspecialchars($this->sendText_unsafe), |
|
218
|
|
|
]); |
|
219
|
|
|
|
|
220
|
|
|
$this->resultTemplatize($template); |
|
221
|
|
|
|
|
222
|
|
|
$recipientIdSafe = db_escape($this->recipient_id_unsafe); |
|
223
|
|
|
$message_query = doquery( |
|
224
|
|
|
"SELECT * FROM {{messages}} |
|
225
|
|
|
WHERE |
|
226
|
|
|
`message_type` = '" . MSG_TYPE_PLAYER . "' AND |
|
227
|
|
|
((`message_owner` = '{$this->playerId}' AND `message_sender` = '{$recipientIdSafe}') |
|
228
|
|
|
OR |
|
229
|
|
|
(`message_sender` = '{$this->playerId}' AND `message_owner` = '{$recipientIdSafe}')) |
|
230
|
|
|
ORDER BY `message_time` DESC LIMIT 20;"); |
|
231
|
|
|
while ($message_row = db_fetch($message_query)) { |
|
232
|
|
|
$template->assign_block_vars('messages', array( |
|
233
|
|
|
'ID' => $message_row['message_id'], |
|
234
|
|
|
'DATE' => date(FMT_DATE_TIME, $message_row['message_time'] + SN_CLIENT_TIME_DIFF), |
|
235
|
|
|
'FROM' => htmlspecialchars($message_row['message_from']), |
|
236
|
|
|
'SUBJ' => htmlspecialchars($message_row['message_subject']), |
|
237
|
|
|
'TEXT' => in_array($message_row['message_type'], array(MSG_TYPE_PLAYER, MSG_TYPE_ALLIANCE)) && $message_row['message_sender'] ? nl2br(htmlspecialchars($message_row['message_text'])) : nl2br($message_row['message_text']), |
|
238
|
|
|
|
|
239
|
|
|
'FROM_ID' => $message_row['message_sender'], |
|
240
|
|
|
// 'SUBJ_SANITIZED' => htmlspecialchars($message_row['message_subject']), |
|
|
|
|
|
|
241
|
|
|
)); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
return $template; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
|
|
248
|
|
|
protected function modelDelete() { |
|
249
|
|
|
// No range specified - nothing to do |
|
250
|
|
|
if ($this->deleteRange == static::MESSAGES_DELETE_RANGE_NONE) { |
|
251
|
|
|
return; |
|
252
|
|
|
} |
|
253
|
|
|
// Сurrent range is CHECKED and NO messages marked - nothing to do |
|
254
|
|
|
if ($this->deleteRange == static::MESSAGES_DELETE_RANGE_CHECKED && empty($this->markedMessageIdList)) { |
|
255
|
|
|
return; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
$query_add = ''; |
|
259
|
|
|
|
|
260
|
|
|
switch ($this->deleteRange) { |
|
261
|
|
|
// case static::MESSAGES_DELETE_RANGE_UNCHECKED: |
|
|
|
|
|
|
262
|
|
|
/** @noinspection PhpMissingBreakStatementInspection */ |
|
263
|
|
|
case static::MESSAGES_DELETE_RANGE_CHECKED: |
|
|
|
|
|
|
264
|
|
|
$query_add = implode(',', $this->markedMessageIdList); |
|
265
|
|
|
if ($query_add) { |
|
266
|
|
|
$query_add = "IN ({$query_add})"; |
|
267
|
|
|
// if ($this->deleteRange == static::MESSAGES_DELETE_RANGE_UNCHECKED) { |
|
|
|
|
|
|
268
|
|
|
// $query_add = "NOT {$query_add}"; |
|
269
|
|
|
// } |
|
270
|
|
|
$query_add = " AND `message_id` {$query_add}"; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** @noinspection PhpMissingBreakStatementInspection */ |
|
274
|
|
|
case static::MESSAGES_DELETE_RANGE_CLASS: |
|
|
|
|
|
|
275
|
|
|
if ($this->current_class != MSG_TYPE_OUTBOX && $this->current_class != MSG_TYPE_NEW) { |
|
|
|
|
|
|
276
|
|
|
$query_add .= " AND `message_type` = {$this->current_class}"; |
|
277
|
|
|
} |
|
278
|
|
|
case static::MESSAGES_DELETE_RANGE_ALL: |
|
279
|
|
|
$query_add = $query_add ? $query_add : true; |
|
280
|
|
|
break; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
if ($this->deleteRange && $query_add) { |
|
284
|
|
|
$query_add = $query_add === true ? '' : $query_add; |
|
285
|
|
|
doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '{$this->playerId}'{$query_add};"); |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* @return template |
|
291
|
|
|
*/ |
|
292
|
|
|
protected function viewMessageList() { |
|
293
|
|
|
require_once('includes/includes/coe_simulator_helpers.php'); |
|
294
|
|
|
|
|
295
|
|
|
$pager = null; |
|
296
|
|
|
|
|
297
|
|
|
if ($this->current_class == MSG_TYPE_OUTBOX) { |
|
298
|
|
|
$message_query = "SELECT {{messages}}.message_id, {{messages}}.message_owner, {{users}}.id AS message_sender, {{messages}}.message_time, |
|
299
|
|
|
{{messages}}.message_type, {{users}}.username AS message_from, {{messages}}.message_subject, {{messages}}.message_text |
|
300
|
|
|
FROM |
|
301
|
|
|
{{messages}} LEFT JOIN {{users}} ON {{users}}.id = {{messages}}.message_owner WHERE `message_sender` = '{$this->playerId}' AND `message_type` = 1 |
|
302
|
|
|
ORDER BY `message_time` DESC;"; |
|
303
|
|
|
} else { |
|
304
|
|
|
if ($this->current_class == MSG_TYPE_NEW) { |
|
305
|
|
|
$SubUpdateQry = array(); |
|
306
|
|
|
foreach ($this->messageClassList as $message_class_id => $message_class) { |
|
307
|
|
|
if ($message_class_id != MSG_TYPE_OUTBOX) { |
|
308
|
|
|
$SubUpdateQry[] = "`{$message_class['name']}` = '0'"; |
|
309
|
|
|
$this->user[$message_class['name']] = 0; |
|
310
|
|
|
} |
|
311
|
|
|
} |
|
312
|
|
|
$SubUpdateQry = implode(',', $SubUpdateQry); |
|
313
|
|
|
} else { |
|
314
|
|
|
$messageClassNameNew = $this->messageClassList[MSG_TYPE_NEW]['name']; |
|
315
|
|
|
$messageClassNameCurrent = $this->messageClassList[$this->current_class]['name']; |
|
316
|
|
|
$SubUpdateQry = "`{$messageClassNameCurrent}` = '0', `{$messageClassNameNew}` = `{$messageClassNameNew}` - '{$this->user[$messageClassNameCurrent]}'"; |
|
317
|
|
|
$SubSelectQry = "AND `message_type` = '{$this->current_class}'"; |
|
318
|
|
|
|
|
319
|
|
|
$this->user[$messageClassNameNew] -= $this->user[$messageClassNameCurrent]; |
|
320
|
|
|
$this->user[$messageClassNameCurrent] = 0; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
db_user_set_by_id($this->playerId, $SubUpdateQry); |
|
|
|
|
|
|
324
|
|
|
$message_query = |
|
325
|
|
|
"SELECT * |
|
326
|
|
|
FROM `{{messages}}` |
|
327
|
|
|
WHERE `message_owner` = '{$this->playerId}' {$SubSelectQry} |
|
|
|
|
|
|
328
|
|
|
ORDER BY `message_time` DESC;"; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
if($this->showAll) { |
|
332
|
|
|
$message_query = $this->db->selectIterator($message_query); |
|
333
|
|
|
} else { |
|
334
|
|
|
$message_query = new DbSqlPaging($message_query, PAGING_PAGE_SIZE_DEFAULT_MESSAGES, sys_get_param_int(PagingRenderer::KEYWORD)); |
|
335
|
|
|
$pager = new PagingRenderer($message_query, 'messages.php?mode=show&message_class=' . $this->current_class); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
$template = gettemplate('msg_message_list', true); |
|
|
|
|
|
|
339
|
|
|
foreach ($message_query as $message_row) { |
|
340
|
|
|
$text = $message_row['message_text']; |
|
341
|
|
|
if ($message_row['message_json']) { |
|
342
|
|
|
switch ($message_row['message_type']) { |
|
343
|
|
|
case MSG_TYPE_SPY: |
|
344
|
|
|
$text = DecodeEspionage::decode(MissionEspionageReport::fromJson($text)); |
|
345
|
|
|
break; |
|
346
|
|
|
default: |
|
347
|
|
|
$text = '{ Unauthorised access - please contact Administration! }'; |
|
348
|
|
|
break; |
|
349
|
|
|
|
|
350
|
|
|
} |
|
351
|
|
|
} else { |
|
352
|
|
|
if (in_array($message_row['message_type'], array(MSG_TYPE_PLAYER, MSG_TYPE_ALLIANCE)) && $message_row['message_sender']) { |
|
353
|
|
|
$text = htmlspecialchars($message_row['message_text']); |
|
354
|
|
|
} |
|
355
|
|
|
$text = nl2br($text); |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
$template->assign_block_vars('messages', array( |
|
359
|
|
|
'ID' => $message_row['message_id'], |
|
360
|
|
|
'DATE' => date(FMT_DATE_TIME, $message_row['message_time'] + SN_CLIENT_TIME_DIFF), |
|
361
|
|
|
'FROM' => htmlspecialchars($message_row['message_from']), |
|
362
|
|
|
'SUBJ' => htmlspecialchars($message_row['message_subject']), |
|
363
|
|
|
'TEXT' => $text, |
|
364
|
|
|
|
|
365
|
|
|
'FROM_ID' => $message_row['message_sender'], |
|
366
|
|
|
'SUBJ_SANITIZED' => htmlspecialchars($message_row['message_subject']), |
|
367
|
|
|
'STYLE' => $this->current_class == MSG_TYPE_OUTBOX ? $this->messageClassList[MSG_TYPE_OUTBOX]['name'] : $this->messageClassList[$message_row['message_type']]['name'], |
|
368
|
|
|
)); |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
$current_class_text = $this->lang['msg_class'][$this->current_class]; |
|
372
|
|
|
|
|
373
|
|
|
$template->assign_vars(array( |
|
374
|
|
|
"MESSAGE_CLASS" => $this->current_class, |
|
375
|
|
|
"MESSAGE_CLASS_TEXT" => $current_class_text, |
|
376
|
|
|
"PAGER_MESSAGES" => $pager ? $pager->render() : '', |
|
377
|
|
|
)); |
|
378
|
|
|
|
|
379
|
|
|
return $template; |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* @return template |
|
384
|
|
|
*/ |
|
385
|
|
|
protected function viewCategories() { |
|
386
|
|
|
$messages_total = []; |
|
387
|
|
|
|
|
388
|
|
|
$query = doquery( |
|
389
|
|
|
"SELECT `message_owner`, `message_type`, COUNT(`message_id`) AS `message_count` |
|
390
|
|
|
FROM `{{messages}}` |
|
391
|
|
|
WHERE `message_owner` = {$this->playerId} |
|
392
|
|
|
GROUP BY `message_owner`, `message_type` |
|
393
|
|
|
ORDER BY `message_owner` ASC, `message_type`;" |
|
394
|
|
|
); |
|
395
|
|
|
while ($message_row = db_fetch($query)) { |
|
396
|
|
|
$messages_total[$message_row['message_type']] = $message_row['message_count']; |
|
397
|
|
|
$messages_total[MSG_TYPE_NEW] += $message_row['message_count']; |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
$query = doquery( |
|
401
|
|
|
"SELECT COUNT(`message_id`) AS message_count |
|
402
|
|
|
FROM `{{messages}}` |
|
403
|
|
|
WHERE `message_sender` = {$this->playerId} AND `message_type` = " . MSG_TYPE_PLAYER . |
|
404
|
|
|
" GROUP BY `message_sender`;", |
|
405
|
|
|
'', |
|
406
|
|
|
true |
|
407
|
|
|
); |
|
408
|
|
|
$messages_total[MSG_TYPE_OUTBOX] = intval($query['message_count']); |
|
409
|
|
|
|
|
410
|
|
|
$template = gettemplate('msg_message_class', true); |
|
|
|
|
|
|
411
|
|
|
foreach ($this->messageClassList as $message_class_id => $message_class) { |
|
412
|
|
|
$template->assign_block_vars('message_class', array( |
|
413
|
|
|
'ID' => $message_class_id, |
|
414
|
|
|
'STYLE' => $message_class['name'], |
|
415
|
|
|
'TEXT' => $this->lang['msg_class'][$message_class_id], |
|
416
|
|
|
'UNREAD' => $this->user[$message_class['name']], |
|
417
|
|
|
'TOTAL' => intval($messages_total[$message_class_id]), |
|
418
|
|
|
)); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
$template->assign_vars(array( |
|
422
|
|
|
'PAGE_HINT' => $this->lang['msg_page_hint_class'], |
|
423
|
|
|
)); |
|
424
|
|
|
|
|
425
|
|
|
return $template; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
|
|
429
|
|
|
protected function getRecipientData() { |
|
430
|
|
|
if (!empty($this->recipient_name_unsafe)) { |
|
431
|
|
|
$recipient_row = db_user_by_username($this->recipient_name_unsafe); |
|
|
|
|
|
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
if (empty($recipient_row) && !empty($this->recipient_id_unsafe)) { |
|
435
|
|
|
$recipient_row = db_user_by_id($this->recipient_id_unsafe); |
|
|
|
|
|
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
if (is_array($recipient_row) && !empty($recipient_row)) { |
|
|
|
|
|
|
439
|
|
|
$this->recipient_id_unsafe = $recipient_row['id']; |
|
440
|
|
|
$this->recipient_name_unsafe = $recipient_row['username']; |
|
441
|
|
|
} else { |
|
442
|
|
|
$this->recipient_id_unsafe = 0; |
|
443
|
|
|
$this->recipient_name_unsafe = ''; |
|
444
|
|
|
} |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
protected function getUserRef() { |
|
448
|
|
|
global $user; |
|
|
|
|
|
|
449
|
|
|
|
|
450
|
|
|
$this->user = &$user; |
|
451
|
|
|
$this->playerId = idval($user['id']); |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
/** |
|
455
|
|
|
* Working on subject |
|
456
|
|
|
*/ |
|
457
|
|
|
protected function transformSubject() { |
|
458
|
|
|
$re = 0; |
|
459
|
|
|
// Removing extra Re:Re:Re:... from subject start |
|
460
|
|
|
if ($this->subject_unsafe) { |
|
461
|
|
|
$reLength = strlen($this->lang['msg_answer_prefix']); |
|
462
|
|
|
while (strpos($this->subject_unsafe, $this->lang['msg_answer_prefix']) === 0) { |
|
463
|
|
|
$this->subject_unsafe = trim(substr($this->subject_unsafe, $reLength)); |
|
464
|
|
|
$re++; |
|
465
|
|
|
} |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
if ($this->subject_unsafe) { |
|
469
|
|
|
$re ? $this->subject_unsafe = $this->lang['msg_answer_prefix'] . $this->subject_unsafe : false; |
|
470
|
|
|
} else { |
|
471
|
|
|
$this->subject_unsafe = $this->lang['msg_subject_default']; |
|
472
|
|
|
} |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
protected function loadParams() { |
|
476
|
|
|
parent::loadParams(); |
|
477
|
|
|
|
|
478
|
|
|
$this->current_class = sys_get_param_int('message_class'); |
|
479
|
|
|
if (!isset($this->messageClassList[$this->current_class])) { |
|
480
|
|
|
$this->current_class = 0; |
|
481
|
|
|
$this->mode = static::MESSAGES_MODE_CATEGORIES; |
|
482
|
|
|
} else { |
|
483
|
|
|
$this->mode = sys_get_param_str('msg_delete') ? static::MESSAGES_MODE_DELETE : sys_get_param_str('mode'); |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
if($this->showAll = sys_get_param_str('msg_show_all') ? true : false) { |
|
487
|
|
|
$this->mode = static::MESSAGES_MODE_MESSAGES; |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
$this->loadParamsCompose(); |
|
491
|
|
|
$this->loadParamsDelete(); |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
protected function loadParamsCompose() { |
|
495
|
|
|
$this->recipient_name_unsafe = sys_get_param_str_unsafe('recipient_name'); |
|
496
|
|
|
$this->recipient_id_unsafe = sys_get_param_id('id'); |
|
497
|
|
|
// Removing starting and trailing blank chars |
|
498
|
|
|
$this->subject_unsafe = trim(sys_get_param_str_unsafe('subject')); |
|
499
|
|
|
$this->transformSubject(); |
|
500
|
|
|
$this->sendText_unsafe = sys_get_param_str_unsafe('text'); |
|
501
|
|
|
$this->doSend = sys_get_param_str('msg_send'); |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
protected function loadParamsDelete() { |
|
505
|
|
|
$this->deleteRange = sys_get_param_str('message_range', static::MESSAGES_DELETE_RANGE_NONE); |
|
506
|
|
|
// Incorrect range - do nothing |
|
507
|
|
|
if (!in_array($this->deleteRange, static::MESSAGES_DELETE_RANGES_ALLOWED)) { |
|
508
|
|
|
return; |
|
509
|
|
|
} |
|
510
|
|
|
|
|
511
|
|
|
$this->markedMessageIdList = []; |
|
512
|
|
|
$unsafeMarkList = sys_get_param('mark', []); |
|
|
|
|
|
|
513
|
|
|
|
|
514
|
|
|
foreach ($unsafeMarkList as $unsafeMark) { |
|
515
|
|
|
if (!empty($unsafeMark = idval($unsafeMark))) { |
|
516
|
|
|
$this->markedMessageIdList[] = $unsafeMark; |
|
517
|
|
|
} |
|
518
|
|
|
} |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
protected function wrapSendPm() { |
|
522
|
|
|
msg_send_simple_message( |
|
523
|
|
|
$this->recipient_id_unsafe, |
|
524
|
|
|
$this->playerId, |
|
525
|
|
|
SN_TIME_NOW, |
|
526
|
|
|
MSG_TYPE_PLAYER, |
|
527
|
|
|
"{$this->user['username']} [{$this->user['galaxy']}:{$this->user['system']}:{$this->user['planet']}]", |
|
528
|
|
|
$this->subject_unsafe, |
|
529
|
|
|
$this->sendText_unsafe, |
|
530
|
|
|
STRING_NEED_ESCAPING |
|
531
|
|
|
); |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
} |
|
535
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state