|
indvdum@0
|
1 |
<?php
|
|
indvdum@0
|
2 |
/**
|
|
indvdum@0
|
3 |
*
|
|
indvdum@0
|
4 |
* @package phpBB3
|
|
indvdum@0
|
5 |
* @version $Id$
|
|
indvdum@0
|
6 |
* @copyright (c) 2005 phpBB Group
|
|
indvdum@0
|
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
indvdum@0
|
8 |
*
|
|
indvdum@0
|
9 |
*/
|
|
indvdum@0
|
10 |
|
|
indvdum@0
|
11 |
/**
|
|
indvdum@0
|
12 |
*/
|
|
indvdum@0
|
13 |
if (!defined('IN_PHPBB'))
|
|
indvdum@0
|
14 |
{
|
|
indvdum@0
|
15 |
exit;
|
|
indvdum@0
|
16 |
}
|
|
indvdum@0
|
17 |
|
|
indvdum@0
|
18 |
/*
|
|
indvdum@0
|
19 |
Ability to simply add own rules by doing three things:
|
|
indvdum@0
|
20 |
1) Add an appropriate constant
|
|
indvdum@0
|
21 |
2) Add a new check array to the global_privmsgs_rules variable and the condition array (if one is required)
|
|
indvdum@0
|
22 |
3) Add a new language variable to ucp.php
|
|
indvdum@0
|
23 |
|
|
indvdum@0
|
24 |
The user is then able to select the new rule. It will be checked against and handled as specified.
|
|
indvdum@0
|
25 |
To add new actions (yes, checks can be added here too) to the rule management, the core code has to be modified.
|
|
indvdum@0
|
26 |
*/
|
|
indvdum@0
|
27 |
|
|
indvdum@0
|
28 |
define('RULE_IS_LIKE', 1); // Is Like
|
|
indvdum@0
|
29 |
define('RULE_IS_NOT_LIKE', 2); // Is Not Like
|
|
indvdum@0
|
30 |
define('RULE_IS', 3); // Is
|
|
indvdum@0
|
31 |
define('RULE_IS_NOT', 4); // Is Not
|
|
indvdum@0
|
32 |
define('RULE_BEGINS_WITH', 5); // Begins with
|
|
indvdum@0
|
33 |
define('RULE_ENDS_WITH', 6); // Ends with
|
|
indvdum@0
|
34 |
define('RULE_IS_FRIEND', 7); // Is Friend
|
|
indvdum@0
|
35 |
define('RULE_IS_FOE', 8); // Is Foe
|
|
indvdum@0
|
36 |
define('RULE_IS_USER', 9); // Is User
|
|
indvdum@0
|
37 |
define('RULE_IS_GROUP', 10); // Is In Usergroup
|
|
indvdum@0
|
38 |
define('RULE_ANSWERED', 11); // Answered
|
|
indvdum@0
|
39 |
define('RULE_FORWARDED', 12); // Forwarded
|
|
indvdum@0
|
40 |
define('RULE_TO_GROUP', 14); // Usergroup
|
|
indvdum@0
|
41 |
define('RULE_TO_ME', 15); // Me
|
|
indvdum@0
|
42 |
|
|
indvdum@0
|
43 |
define('ACTION_PLACE_INTO_FOLDER', 1);
|
|
indvdum@0
|
44 |
define('ACTION_MARK_AS_READ', 2);
|
|
indvdum@0
|
45 |
define('ACTION_MARK_AS_IMPORTANT', 3);
|
|
indvdum@0
|
46 |
define('ACTION_DELETE_MESSAGE', 4);
|
|
indvdum@0
|
47 |
|
|
indvdum@0
|
48 |
define('CHECK_SUBJECT', 1);
|
|
indvdum@0
|
49 |
define('CHECK_SENDER', 2);
|
|
indvdum@0
|
50 |
define('CHECK_MESSAGE', 3);
|
|
indvdum@0
|
51 |
define('CHECK_STATUS', 4);
|
|
indvdum@0
|
52 |
define('CHECK_TO', 5);
|
|
indvdum@0
|
53 |
|
|
indvdum@0
|
54 |
/**
|
|
indvdum@0
|
55 |
* Global private message rules
|
|
indvdum@0
|
56 |
* These rules define what to do if a rule is hit
|
|
indvdum@0
|
57 |
*/
|
|
indvdum@0
|
58 |
$global_privmsgs_rules = array(
|
|
indvdum@0
|
59 |
CHECK_SUBJECT => array(
|
|
indvdum@0
|
60 |
RULE_IS_LIKE => array('check0' => 'message_subject', 'function' => 'preg_match("/" . preg_quote({STRING}, "/") . "/i", {CHECK0})'),
|
|
indvdum@0
|
61 |
RULE_IS_NOT_LIKE => array('check0' => 'message_subject', 'function' => '!(preg_match("/" . preg_quote({STRING}, "/") . "/i", {CHECK0}))'),
|
|
indvdum@0
|
62 |
RULE_IS => array('check0' => 'message_subject', 'function' => '{CHECK0} == {STRING}'),
|
|
indvdum@0
|
63 |
RULE_IS_NOT => array('check0' => 'message_subject', 'function' => '{CHECK0} != {STRING}'),
|
|
indvdum@0
|
64 |
RULE_BEGINS_WITH => array('check0' => 'message_subject', 'function' => 'preg_match("/^" . preg_quote({STRING}, "/") . "/i", {CHECK0})'),
|
|
indvdum@0
|
65 |
RULE_ENDS_WITH => array('check0' => 'message_subject', 'function' => 'preg_match("/" . preg_quote({STRING}, "/") . "$/i", {CHECK0})'),
|
|
indvdum@0
|
66 |
),
|
|
indvdum@0
|
67 |
|
|
indvdum@0
|
68 |
CHECK_SENDER => array(
|
|
indvdum@0
|
69 |
RULE_IS_LIKE => array('check0' => 'username', 'function' => 'preg_match("/" . preg_quote({STRING}, "/") . "/i", {CHECK0})'),
|
|
indvdum@0
|
70 |
RULE_IS_NOT_LIKE => array('check0' => 'username', 'function' => '!(preg_match("/" . preg_quote({STRING}, "/") . "/i", {CHECK0}))'),
|
|
indvdum@0
|
71 |
RULE_IS => array('check0' => 'username', 'function' => '{CHECK0} == {STRING}'),
|
|
indvdum@0
|
72 |
RULE_IS_NOT => array('check0' => 'username', 'function' => '{CHECK0} != {STRING}'),
|
|
indvdum@0
|
73 |
RULE_BEGINS_WITH => array('check0' => 'username', 'function' => 'preg_match("/^" . preg_quote({STRING}, "/") . "/i", {CHECK0})'),
|
|
indvdum@0
|
74 |
RULE_ENDS_WITH => array('check0' => 'username', 'function' => 'preg_match("/" . preg_quote({STRING}, "/") . "$/i", {CHECK0})'),
|
|
indvdum@0
|
75 |
RULE_IS_FRIEND => array('check0' => 'friend', 'function' => '{CHECK0} == 1'),
|
|
indvdum@0
|
76 |
RULE_IS_FOE => array('check0' => 'foe', 'function' => '{CHECK0} == 1'),
|
|
indvdum@0
|
77 |
RULE_IS_USER => array('check0' => 'author_id', 'function' => '{CHECK0} == {USER_ID}'),
|
|
indvdum@0
|
78 |
RULE_IS_GROUP => array('check0' => 'author_in_group', 'function' => 'in_array({GROUP_ID}, {CHECK0})'),
|
|
indvdum@0
|
79 |
),
|
|
indvdum@0
|
80 |
|
|
indvdum@0
|
81 |
CHECK_MESSAGE => array(
|
|
indvdum@0
|
82 |
RULE_IS_LIKE => array('check0' => 'message_text', 'function' => 'preg_match("/" . preg_quote({STRING}, "/") . "/i", {CHECK0})'),
|
|
indvdum@0
|
83 |
RULE_IS_NOT_LIKE => array('check0' => 'message_text', 'function' => '!(preg_match("/" . preg_quote({STRING}, "/") . "/i", {CHECK0}))'),
|
|
indvdum@0
|
84 |
RULE_IS => array('check0' => 'message_text', 'function' => '{CHECK0} == {STRING}'),
|
|
indvdum@0
|
85 |
RULE_IS_NOT => array('check0' => 'message_text', 'function' => '{CHECK0} != {STRING}'),
|
|
indvdum@0
|
86 |
),
|
|
indvdum@0
|
87 |
|
|
indvdum@0
|
88 |
CHECK_STATUS => array(
|
|
indvdum@0
|
89 |
RULE_ANSWERED => array('check0' => 'pm_replied', 'function' => '{CHECK0} == 1'),
|
|
indvdum@0
|
90 |
RULE_FORWARDED => array('check0' => 'pm_forwarded', 'function' => '{CHECK0} == 1'),
|
|
indvdum@0
|
91 |
),
|
|
indvdum@0
|
92 |
|
|
indvdum@0
|
93 |
CHECK_TO => array(
|
|
indvdum@0
|
94 |
RULE_TO_GROUP => array('check0' => 'to', 'check1' => 'bcc', 'check2' => 'user_in_group', 'function' => 'in_array("g_" . {CHECK2}, {CHECK0}) || in_array("g_" . {CHECK2}, {CHECK1})'),
|
|
indvdum@0
|
95 |
RULE_TO_ME => array('check0' => 'to', 'check1' => 'bcc', 'function' => 'in_array("u_" . $user_id, {CHECK0}) || in_array("u_" . $user_id, {CHECK1})'),
|
|
indvdum@0
|
96 |
)
|
|
indvdum@0
|
97 |
);
|
|
indvdum@0
|
98 |
|
|
indvdum@0
|
99 |
/**
|
|
indvdum@0
|
100 |
* This is for defining which condition fields to show for which Rule
|
|
indvdum@0
|
101 |
*/
|
|
indvdum@0
|
102 |
$global_rule_conditions = array(
|
|
indvdum@0
|
103 |
RULE_IS_LIKE => 'text',
|
|
indvdum@0
|
104 |
RULE_IS_NOT_LIKE => 'text',
|
|
indvdum@0
|
105 |
RULE_IS => 'text',
|
|
indvdum@0
|
106 |
RULE_IS_NOT => 'text',
|
|
indvdum@0
|
107 |
RULE_BEGINS_WITH => 'text',
|
|
indvdum@0
|
108 |
RULE_ENDS_WITH => 'text',
|
|
indvdum@0
|
109 |
RULE_IS_USER => 'user',
|
|
indvdum@0
|
110 |
RULE_IS_GROUP => 'group'
|
|
indvdum@0
|
111 |
);
|
|
indvdum@0
|
112 |
|
|
indvdum@0
|
113 |
/**
|
|
indvdum@0
|
114 |
* Get all folder
|
|
indvdum@0
|
115 |
*/
|
|
indvdum@0
|
116 |
function get_folder($user_id, $folder_id = false)
|
|
indvdum@0
|
117 |
{
|
|
indvdum@0
|
118 |
global $db, $user, $template;
|
|
indvdum@0
|
119 |
global $phpbb_root_path, $phpEx;
|
|
indvdum@0
|
120 |
|
|
indvdum@0
|
121 |
$folder = array();
|
|
indvdum@0
|
122 |
|
|
indvdum@0
|
123 |
// Get folder information
|
|
indvdum@0
|
124 |
$sql = 'SELECT folder_id, COUNT(msg_id) as num_messages, SUM(pm_unread) as num_unread
|
|
indvdum@0
|
125 |
FROM ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
126 |
WHERE user_id = $user_id
|
|
indvdum@0
|
127 |
AND folder_id <> " . PRIVMSGS_NO_BOX . '
|
|
indvdum@0
|
128 |
GROUP BY folder_id';
|
|
indvdum@0
|
129 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
130 |
|
|
indvdum@0
|
131 |
$num_messages = $num_unread = array();
|
|
indvdum@0
|
132 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
133 |
{
|
|
indvdum@0
|
134 |
$num_messages[(int) $row['folder_id']] = $row['num_messages'];
|
|
indvdum@0
|
135 |
$num_unread[(int) $row['folder_id']] = $row['num_unread'];
|
|
indvdum@0
|
136 |
}
|
|
indvdum@0
|
137 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
138 |
|
|
indvdum@0
|
139 |
// Make sure the default boxes are defined
|
|
indvdum@0
|
140 |
$available_folder = array(PRIVMSGS_INBOX, PRIVMSGS_OUTBOX, PRIVMSGS_SENTBOX);
|
|
indvdum@0
|
141 |
|
|
indvdum@0
|
142 |
foreach ($available_folder as $default_folder)
|
|
indvdum@0
|
143 |
{
|
|
indvdum@0
|
144 |
if (!isset($num_messages[$default_folder]))
|
|
indvdum@0
|
145 |
{
|
|
indvdum@0
|
146 |
$num_messages[$default_folder] = 0;
|
|
indvdum@0
|
147 |
}
|
|
indvdum@0
|
148 |
|
|
indvdum@0
|
149 |
if (!isset($num_unread[$default_folder]))
|
|
indvdum@0
|
150 |
{
|
|
indvdum@0
|
151 |
$num_unread[$default_folder] = 0;
|
|
indvdum@0
|
152 |
}
|
|
indvdum@0
|
153 |
}
|
|
indvdum@0
|
154 |
|
|
indvdum@0
|
155 |
// Adjust unread status for outbox
|
|
indvdum@0
|
156 |
$num_unread[PRIVMSGS_OUTBOX] = $num_messages[PRIVMSGS_OUTBOX];
|
|
indvdum@0
|
157 |
|
|
indvdum@0
|
158 |
$folder[PRIVMSGS_INBOX] = array(
|
|
indvdum@0
|
159 |
'folder_name' => $user->lang['PM_INBOX'],
|
|
indvdum@0
|
160 |
'num_messages' => $num_messages[PRIVMSGS_INBOX],
|
|
indvdum@0
|
161 |
'unread_messages' => $num_unread[PRIVMSGS_INBOX]
|
|
indvdum@0
|
162 |
);
|
|
indvdum@0
|
163 |
|
|
indvdum@0
|
164 |
// Custom Folder
|
|
indvdum@0
|
165 |
$sql = 'SELECT folder_id, folder_name, pm_count
|
|
indvdum@0
|
166 |
FROM ' . PRIVMSGS_FOLDER_TABLE . "
|
|
indvdum@0
|
167 |
WHERE user_id = $user_id";
|
|
indvdum@0
|
168 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
169 |
|
|
indvdum@0
|
170 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
171 |
{
|
|
indvdum@0
|
172 |
$folder[$row['folder_id']] = array(
|
|
indvdum@0
|
173 |
'folder_name' => $row['folder_name'],
|
|
indvdum@0
|
174 |
'num_messages' => $row['pm_count'],
|
|
indvdum@0
|
175 |
'unread_messages' => ((isset($num_unread[$row['folder_id']])) ? $num_unread[$row['folder_id']] : 0)
|
|
indvdum@0
|
176 |
);
|
|
indvdum@0
|
177 |
}
|
|
indvdum@0
|
178 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
179 |
|
|
indvdum@0
|
180 |
$folder[PRIVMSGS_OUTBOX] = array(
|
|
indvdum@0
|
181 |
'folder_name' => $user->lang['PM_OUTBOX'],
|
|
indvdum@0
|
182 |
'num_messages' => $num_messages[PRIVMSGS_OUTBOX],
|
|
indvdum@0
|
183 |
'unread_messages' => $num_unread[PRIVMSGS_OUTBOX]
|
|
indvdum@0
|
184 |
);
|
|
indvdum@0
|
185 |
|
|
indvdum@0
|
186 |
$folder[PRIVMSGS_SENTBOX] = array(
|
|
indvdum@0
|
187 |
'folder_name' => $user->lang['PM_SENTBOX'],
|
|
indvdum@0
|
188 |
'num_messages' => $num_messages[PRIVMSGS_SENTBOX],
|
|
indvdum@0
|
189 |
'unread_messages' => $num_unread[PRIVMSGS_SENTBOX]
|
|
indvdum@0
|
190 |
);
|
|
indvdum@0
|
191 |
|
|
indvdum@0
|
192 |
// Define Folder Array for template designers (and for making custom folders usable by the template too)
|
|
indvdum@0
|
193 |
foreach ($folder as $f_id => $folder_ary)
|
|
indvdum@0
|
194 |
{
|
|
indvdum@0
|
195 |
$folder_id_name = ($f_id == PRIVMSGS_INBOX) ? 'inbox' : (($f_id == PRIVMSGS_OUTBOX) ? 'outbox' : 'sentbox');
|
|
indvdum@0
|
196 |
|
|
indvdum@0
|
197 |
$template->assign_block_vars('folder', array(
|
|
indvdum@0
|
198 |
'FOLDER_ID' => $f_id,
|
|
indvdum@0
|
199 |
'FOLDER_NAME' => $folder_ary['folder_name'],
|
|
indvdum@0
|
200 |
'NUM_MESSAGES' => $folder_ary['num_messages'],
|
|
indvdum@0
|
201 |
'UNREAD_MESSAGES' => $folder_ary['unread_messages'],
|
|
indvdum@0
|
202 |
|
|
indvdum@0
|
203 |
'U_FOLDER' => ($f_id > 0) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=' . $f_id) : append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=' . $folder_id_name),
|
|
indvdum@0
|
204 |
|
|
indvdum@0
|
205 |
'S_CUR_FOLDER' => ($f_id === $folder_id) ? true : false,
|
|
indvdum@0
|
206 |
'S_UNREAD_MESSAGES' => ($folder_ary['unread_messages']) ? true : false,
|
|
indvdum@0
|
207 |
'S_CUSTOM_FOLDER' => ($f_id > 0) ? true : false)
|
|
indvdum@0
|
208 |
);
|
|
indvdum@0
|
209 |
}
|
|
indvdum@0
|
210 |
|
|
indvdum@0
|
211 |
if ($folder_id !== false && !isset($folder[$folder_id]))
|
|
indvdum@0
|
212 |
{
|
|
indvdum@0
|
213 |
trigger_error('UNKNOWN_FOLDER');
|
|
indvdum@0
|
214 |
}
|
|
indvdum@0
|
215 |
|
|
indvdum@0
|
216 |
return $folder;
|
|
indvdum@0
|
217 |
}
|
|
indvdum@0
|
218 |
|
|
indvdum@0
|
219 |
/**
|
|
indvdum@0
|
220 |
* Delete Messages From Sentbox
|
|
indvdum@0
|
221 |
* we are doing this here because this saves us a bunch of checks and queries
|
|
indvdum@0
|
222 |
*/
|
|
indvdum@0
|
223 |
function clean_sentbox($num_sentbox_messages)
|
|
indvdum@0
|
224 |
{
|
|
indvdum@0
|
225 |
global $db, $user, $config;
|
|
indvdum@0
|
226 |
|
|
indvdum@0
|
227 |
// Check Message Limit
|
|
indvdum@0
|
228 |
if ($user->data['message_limit'] && $num_sentbox_messages > $user->data['message_limit'])
|
|
indvdum@0
|
229 |
{
|
|
indvdum@0
|
230 |
// Delete old messages
|
|
indvdum@0
|
231 |
$sql = 'SELECT t.msg_id
|
|
indvdum@0
|
232 |
FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
|
|
indvdum@0
|
233 |
WHERE t.msg_id = p.msg_id
|
|
indvdum@0
|
234 |
AND t.user_id = ' . $user->data['user_id'] . '
|
|
indvdum@0
|
235 |
AND t.folder_id = ' . PRIVMSGS_SENTBOX . '
|
|
indvdum@0
|
236 |
ORDER BY p.message_time ASC';
|
|
indvdum@0
|
237 |
$result = $db->sql_query_limit($sql, ($num_sentbox_messages - $user->data['message_limit']));
|
|
indvdum@0
|
238 |
|
|
indvdum@0
|
239 |
$delete_ids = array();
|
|
indvdum@0
|
240 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
241 |
{
|
|
indvdum@0
|
242 |
$delete_ids[] = $row['msg_id'];
|
|
indvdum@0
|
243 |
}
|
|
indvdum@0
|
244 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
245 |
delete_pm($user->data['user_id'], $delete_ids, PRIVMSGS_SENTBOX);
|
|
indvdum@0
|
246 |
}
|
|
indvdum@0
|
247 |
}
|
|
indvdum@0
|
248 |
|
|
indvdum@0
|
249 |
/**
|
|
indvdum@0
|
250 |
* Check Rule against Message Information
|
|
indvdum@0
|
251 |
*/
|
|
indvdum@0
|
252 |
function check_rule(&$rules, &$rule_row, &$message_row, $user_id)
|
|
indvdum@0
|
253 |
{
|
|
indvdum@0
|
254 |
global $user, $config;
|
|
indvdum@0
|
255 |
|
|
indvdum@0
|
256 |
if (!isset($rules[$rule_row['rule_check']][$rule_row['rule_connection']]))
|
|
indvdum@0
|
257 |
{
|
|
indvdum@0
|
258 |
return false;
|
|
indvdum@0
|
259 |
}
|
|
indvdum@0
|
260 |
|
|
indvdum@0
|
261 |
$check_ary = $rules[$rule_row['rule_check']][$rule_row['rule_connection']];
|
|
indvdum@0
|
262 |
|
|
indvdum@0
|
263 |
// Replace Check Literals
|
|
indvdum@0
|
264 |
$evaluate = $check_ary['function'];
|
|
indvdum@0
|
265 |
$evaluate = preg_replace('/{(CHECK[0-9])}/', '$message_row[$check_ary[strtolower("\1")]]', $evaluate);
|
|
indvdum@0
|
266 |
|
|
indvdum@0
|
267 |
// Replace Rule Literals
|
|
indvdum@0
|
268 |
$evaluate = preg_replace('/{(STRING|USER_ID|GROUP_ID)}/', '$rule_row["rule_" . strtolower("\1")]', $evaluate);
|
|
indvdum@0
|
269 |
|
|
indvdum@0
|
270 |
// Evil Statement
|
|
indvdum@0
|
271 |
$result = false;
|
|
indvdum@0
|
272 |
eval('$result = (' . $evaluate . ') ? true : false;');
|
|
indvdum@0
|
273 |
|
|
indvdum@0
|
274 |
if (!$result)
|
|
indvdum@0
|
275 |
{
|
|
indvdum@0
|
276 |
return false;
|
|
indvdum@0
|
277 |
}
|
|
indvdum@0
|
278 |
|
|
indvdum@0
|
279 |
switch ($rule_row['rule_action'])
|
|
indvdum@0
|
280 |
{
|
|
indvdum@0
|
281 |
case ACTION_PLACE_INTO_FOLDER:
|
|
indvdum@0
|
282 |
return array('action' => $rule_row['rule_action'], 'folder_id' => $rule_row['rule_folder_id']);
|
|
indvdum@0
|
283 |
break;
|
|
indvdum@0
|
284 |
|
|
indvdum@0
|
285 |
case ACTION_MARK_AS_READ:
|
|
indvdum@0
|
286 |
case ACTION_MARK_AS_IMPORTANT:
|
|
indvdum@0
|
287 |
return array('action' => $rule_row['rule_action'], 'pm_unread' => $message_row['pm_unread'], 'pm_marked' => $message_row['pm_marked']);
|
|
indvdum@0
|
288 |
break;
|
|
indvdum@0
|
289 |
|
|
indvdum@0
|
290 |
case ACTION_DELETE_MESSAGE:
|
|
indvdum@0
|
291 |
global $db, $auth;
|
|
indvdum@0
|
292 |
|
|
indvdum@0
|
293 |
// Check for admins/mods - users are not allowed to remove those messages...
|
|
indvdum@0
|
294 |
// We do the check here to make sure the data we use is consistent
|
|
indvdum@0
|
295 |
$sql = 'SELECT user_id, user_type, user_permissions
|
|
indvdum@0
|
296 |
FROM ' . USERS_TABLE . '
|
|
indvdum@0
|
297 |
WHERE user_id = ' . (int) $message_row['author_id'];
|
|
indvdum@0
|
298 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
299 |
$userdata = $db->sql_fetchrow($result);
|
|
indvdum@0
|
300 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
301 |
|
|
indvdum@0
|
302 |
$auth2 = new auth();
|
|
indvdum@0
|
303 |
$auth2->acl($userdata);
|
|
indvdum@0
|
304 |
|
|
indvdum@0
|
305 |
if (!$auth2->acl_get('a_') && !$auth2->acl_get('m_') && !$auth2->acl_getf_global('m_'))
|
|
indvdum@0
|
306 |
{
|
|
indvdum@0
|
307 |
return array('action' => $rule_row['rule_action'], 'pm_unread' => $message_row['pm_unread'], 'pm_marked' => $message_row['pm_marked']);
|
|
indvdum@0
|
308 |
}
|
|
indvdum@0
|
309 |
|
|
indvdum@0
|
310 |
return false;
|
|
indvdum@0
|
311 |
break;
|
|
indvdum@0
|
312 |
|
|
indvdum@0
|
313 |
default:
|
|
indvdum@0
|
314 |
return false;
|
|
indvdum@0
|
315 |
}
|
|
indvdum@0
|
316 |
|
|
indvdum@0
|
317 |
return false;
|
|
indvdum@0
|
318 |
}
|
|
indvdum@0
|
319 |
|
|
indvdum@0
|
320 |
/**
|
|
indvdum@0
|
321 |
* Update user PM count
|
|
indvdum@0
|
322 |
*/
|
|
indvdum@0
|
323 |
function update_pm_counts()
|
|
indvdum@0
|
324 |
{
|
|
indvdum@0
|
325 |
global $user, $db;
|
|
indvdum@0
|
326 |
|
|
indvdum@0
|
327 |
// Update unread count
|
|
indvdum@0
|
328 |
$sql = 'SELECT COUNT(msg_id) as num_messages
|
|
indvdum@0
|
329 |
FROM ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
330 |
WHERE pm_unread = 1
|
|
indvdum@0
|
331 |
AND folder_id <> ' . PRIVMSGS_OUTBOX . '
|
|
indvdum@0
|
332 |
AND user_id = ' . $user->data['user_id'];
|
|
indvdum@0
|
333 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
334 |
$user->data['user_unread_privmsg'] = (int) $db->sql_fetchfield('num_messages');
|
|
indvdum@0
|
335 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
336 |
|
|
indvdum@0
|
337 |
// Update new pm count
|
|
indvdum@0
|
338 |
$sql = 'SELECT COUNT(msg_id) as num_messages
|
|
indvdum@0
|
339 |
FROM ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
340 |
WHERE pm_new = 1
|
|
indvdum@0
|
341 |
AND folder_id IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ')
|
|
indvdum@0
|
342 |
AND user_id = ' . $user->data['user_id'];
|
|
indvdum@0
|
343 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
344 |
$user->data['user_new_privmsg'] = (int) $db->sql_fetchfield('num_messages');
|
|
indvdum@0
|
345 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
346 |
|
|
indvdum@0
|
347 |
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array(
|
|
indvdum@0
|
348 |
'user_unread_privmsg' => (int) $user->data['user_unread_privmsg'],
|
|
indvdum@0
|
349 |
'user_new_privmsg' => (int) $user->data['user_new_privmsg'],
|
|
indvdum@0
|
350 |
)) . ' WHERE user_id = ' . $user->data['user_id']);
|
|
indvdum@0
|
351 |
|
|
indvdum@0
|
352 |
// Ok, here we need to repair something, other boxes than privmsgs_no_box and privmsgs_hold_box should not carry the pm_new flag.
|
|
indvdum@0
|
353 |
if (!$user->data['user_new_privmsg'])
|
|
indvdum@0
|
354 |
{
|
|
indvdum@0
|
355 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
356 |
SET pm_new = 0
|
|
indvdum@0
|
357 |
WHERE pm_new = 1
|
|
indvdum@0
|
358 |
AND folder_id NOT IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ')
|
|
indvdum@0
|
359 |
AND user_id = ' . $user->data['user_id'];
|
|
indvdum@0
|
360 |
$db->sql_query($sql);
|
|
indvdum@0
|
361 |
}
|
|
indvdum@0
|
362 |
}
|
|
indvdum@0
|
363 |
|
|
indvdum@0
|
364 |
/**
|
|
indvdum@0
|
365 |
* Place new messages into appropriate folder
|
|
indvdum@0
|
366 |
*/
|
|
indvdum@0
|
367 |
function place_pm_into_folder(&$global_privmsgs_rules, $release = false)
|
|
indvdum@0
|
368 |
{
|
|
indvdum@0
|
369 |
global $db, $user, $config;
|
|
indvdum@0
|
370 |
|
|
indvdum@0
|
371 |
if (!$user->data['user_new_privmsg'])
|
|
indvdum@0
|
372 |
{
|
|
indvdum@0
|
373 |
return array('not_moved' => 0, 'removed' => 0);
|
|
indvdum@0
|
374 |
}
|
|
indvdum@0
|
375 |
|
|
indvdum@0
|
376 |
$user_message_rules = (int) $user->data['user_message_rules'];
|
|
indvdum@0
|
377 |
$user_id = (int) $user->data['user_id'];
|
|
indvdum@0
|
378 |
|
|
indvdum@0
|
379 |
$action_ary = $move_into_folder = array();
|
|
indvdum@0
|
380 |
$num_removed = 0;
|
|
indvdum@0
|
381 |
|
|
indvdum@0
|
382 |
// Newly processing on-hold messages
|
|
indvdum@0
|
383 |
if ($release)
|
|
indvdum@0
|
384 |
{
|
|
indvdum@0
|
385 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
386 |
SET folder_id = ' . PRIVMSGS_NO_BOX . '
|
|
indvdum@0
|
387 |
WHERE folder_id = ' . PRIVMSGS_HOLD_BOX . "
|
|
indvdum@0
|
388 |
AND user_id = $user_id";
|
|
indvdum@0
|
389 |
$db->sql_query($sql);
|
|
indvdum@0
|
390 |
}
|
|
indvdum@0
|
391 |
|
|
indvdum@0
|
392 |
// Get those messages not yet placed into any box
|
|
indvdum@0
|
393 |
$retrieve_sql = 'SELECT t.*, p.*, u.username, u.user_id, u.group_id
|
|
indvdum@0
|
394 |
FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u
|
|
indvdum@0
|
395 |
WHERE t.user_id = $user_id
|
|
indvdum@0
|
396 |
AND p.author_id = u.user_id
|
|
indvdum@0
|
397 |
AND t.folder_id = " . PRIVMSGS_NO_BOX . '
|
|
indvdum@0
|
398 |
AND t.msg_id = p.msg_id';
|
|
indvdum@0
|
399 |
|
|
indvdum@0
|
400 |
// Just place into the appropriate arrays if no rules need to be checked
|
|
indvdum@0
|
401 |
if (!$user_message_rules)
|
|
indvdum@0
|
402 |
{
|
|
indvdum@0
|
403 |
$result = $db->sql_query($retrieve_sql);
|
|
indvdum@0
|
404 |
|
|
indvdum@0
|
405 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
406 |
{
|
|
indvdum@0
|
407 |
$action_ary[$row['msg_id']][] = array('action' => false);
|
|
indvdum@0
|
408 |
}
|
|
indvdum@0
|
409 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
410 |
}
|
|
indvdum@0
|
411 |
else
|
|
indvdum@0
|
412 |
{
|
|
indvdum@0
|
413 |
$user_rules = $zebra = $check_rows = array();
|
|
indvdum@0
|
414 |
$user_ids = $memberships = array();
|
|
indvdum@0
|
415 |
|
|
indvdum@0
|
416 |
// First of all, grab all rules and retrieve friends/foes
|
|
indvdum@0
|
417 |
$sql = 'SELECT *
|
|
indvdum@0
|
418 |
FROM ' . PRIVMSGS_RULES_TABLE . "
|
|
indvdum@0
|
419 |
WHERE user_id = $user_id";
|
|
indvdum@0
|
420 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
421 |
$user_rules = $db->sql_fetchrowset($result);
|
|
indvdum@0
|
422 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
423 |
|
|
indvdum@0
|
424 |
if (sizeof($user_rules))
|
|
indvdum@0
|
425 |
{
|
|
indvdum@0
|
426 |
$sql = 'SELECT zebra_id, friend, foe
|
|
indvdum@0
|
427 |
FROM ' . ZEBRA_TABLE . "
|
|
indvdum@0
|
428 |
WHERE user_id = $user_id";
|
|
indvdum@0
|
429 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
430 |
|
|
indvdum@0
|
431 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
432 |
{
|
|
indvdum@0
|
433 |
$zebra[$row['zebra_id']] = $row;
|
|
indvdum@0
|
434 |
}
|
|
indvdum@0
|
435 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
436 |
}
|
|
indvdum@0
|
437 |
|
|
indvdum@0
|
438 |
// Now build a bare-bone check_row array
|
|
indvdum@0
|
439 |
$result = $db->sql_query($retrieve_sql);
|
|
indvdum@0
|
440 |
|
|
indvdum@0
|
441 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
442 |
{
|
|
indvdum@0
|
443 |
$check_rows[] = array_merge($row, array(
|
|
indvdum@0
|
444 |
'to' => explode(':', $row['to_address']),
|
|
indvdum@0
|
445 |
'bcc' => explode(':', $row['bcc_address']),
|
|
indvdum@0
|
446 |
'friend' => (isset($zebra[$row['author_id']])) ? $zebra[$row['author_id']]['friend'] : 0,
|
|
indvdum@0
|
447 |
'foe' => (isset($zebra[$row['author_id']])) ? $zebra[$row['author_id']]['foe'] : 0,
|
|
indvdum@0
|
448 |
'user_in_group' => array($user->data['group_id']),
|
|
indvdum@0
|
449 |
'author_in_group' => array())
|
|
indvdum@0
|
450 |
);
|
|
indvdum@0
|
451 |
|
|
indvdum@0
|
452 |
$user_ids[] = $row['user_id'];
|
|
indvdum@0
|
453 |
}
|
|
indvdum@0
|
454 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
455 |
|
|
indvdum@0
|
456 |
// Retrieve user memberships
|
|
indvdum@0
|
457 |
if (sizeof($user_ids))
|
|
indvdum@0
|
458 |
{
|
|
indvdum@0
|
459 |
$sql = 'SELECT *
|
|
indvdum@0
|
460 |
FROM ' . USER_GROUP_TABLE . '
|
|
indvdum@0
|
461 |
WHERE ' . $db->sql_in_set('user_id', $user_ids) . '
|
|
indvdum@0
|
462 |
AND user_pending = 0';
|
|
indvdum@0
|
463 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
464 |
|
|
indvdum@0
|
465 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
466 |
{
|
|
indvdum@0
|
467 |
$memberships[$row['user_id']][] = $row['group_id'];
|
|
indvdum@0
|
468 |
}
|
|
indvdum@0
|
469 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
470 |
}
|
|
indvdum@0
|
471 |
|
|
indvdum@0
|
472 |
// Now place into the appropriate folder
|
|
indvdum@0
|
473 |
foreach ($check_rows as $row)
|
|
indvdum@0
|
474 |
{
|
|
indvdum@0
|
475 |
// Add membership if set
|
|
indvdum@0
|
476 |
if (isset($memberships[$row['author_id']]))
|
|
indvdum@0
|
477 |
{
|
|
indvdum@0
|
478 |
$row['author_in_group'] = $memberships[$row['user_id']];
|
|
indvdum@0
|
479 |
}
|
|
indvdum@0
|
480 |
|
|
indvdum@0
|
481 |
// Check Rule - this should be very quick since we have all information we need
|
|
indvdum@0
|
482 |
$is_match = false;
|
|
indvdum@0
|
483 |
foreach ($user_rules as $rule_row)
|
|
indvdum@0
|
484 |
{
|
|
indvdum@0
|
485 |
if (($action = check_rule($global_privmsgs_rules, $rule_row, $row, $user_id)) !== false)
|
|
indvdum@0
|
486 |
{
|
|
indvdum@0
|
487 |
$is_match = true;
|
|
indvdum@0
|
488 |
$action_ary[$row['msg_id']][] = $action;
|
|
indvdum@0
|
489 |
}
|
|
indvdum@0
|
490 |
}
|
|
indvdum@0
|
491 |
|
|
indvdum@0
|
492 |
if (!$is_match)
|
|
indvdum@0
|
493 |
{
|
|
indvdum@0
|
494 |
$action_ary[$row['msg_id']][] = array('action' => false);
|
|
indvdum@0
|
495 |
}
|
|
indvdum@0
|
496 |
}
|
|
indvdum@0
|
497 |
|
|
indvdum@0
|
498 |
unset($user_rules, $zebra, $check_rows, $user_ids, $memberships);
|
|
indvdum@0
|
499 |
}
|
|
indvdum@0
|
500 |
|
|
indvdum@0
|
501 |
// We place actions into arrays, to save queries.
|
|
indvdum@0
|
502 |
$sql = $unread_ids = $delete_ids = $important_ids = array();
|
|
indvdum@0
|
503 |
|
|
indvdum@0
|
504 |
foreach ($action_ary as $msg_id => $msg_ary)
|
|
indvdum@0
|
505 |
{
|
|
indvdum@0
|
506 |
// It is allowed to execute actions more than once, except placing messages into folder
|
|
indvdum@0
|
507 |
$folder_action = $message_removed = false;
|
|
indvdum@0
|
508 |
|
|
indvdum@0
|
509 |
foreach ($msg_ary as $pos => $rule_ary)
|
|
indvdum@0
|
510 |
{
|
|
indvdum@0
|
511 |
if ($folder_action && $rule_ary['action'] == ACTION_PLACE_INTO_FOLDER)
|
|
indvdum@0
|
512 |
{
|
|
indvdum@0
|
513 |
continue;
|
|
indvdum@0
|
514 |
}
|
|
indvdum@0
|
515 |
|
|
indvdum@0
|
516 |
switch ($rule_ary['action'])
|
|
indvdum@0
|
517 |
{
|
|
indvdum@0
|
518 |
case ACTION_PLACE_INTO_FOLDER:
|
|
indvdum@0
|
519 |
// Folder actions have precedence, so we will remove any other ones
|
|
indvdum@0
|
520 |
$folder_action = true;
|
|
indvdum@0
|
521 |
$move_into_folder[(int) $rule_ary['folder_id']][] = $msg_id;
|
|
indvdum@0
|
522 |
break;
|
|
indvdum@0
|
523 |
|
|
indvdum@0
|
524 |
case ACTION_MARK_AS_READ:
|
|
indvdum@0
|
525 |
if ($rule_ary['pm_unread'])
|
|
indvdum@0
|
526 |
{
|
|
indvdum@0
|
527 |
$unread_ids[] = $msg_id;
|
|
indvdum@0
|
528 |
}
|
|
indvdum@0
|
529 |
break;
|
|
indvdum@0
|
530 |
|
|
indvdum@0
|
531 |
case ACTION_DELETE_MESSAGE:
|
|
indvdum@0
|
532 |
$delete_ids[] = $msg_id;
|
|
indvdum@0
|
533 |
$message_removed = true;
|
|
indvdum@0
|
534 |
break;
|
|
indvdum@0
|
535 |
|
|
indvdum@0
|
536 |
case ACTION_MARK_AS_IMPORTANT:
|
|
indvdum@0
|
537 |
if (!$rule_ary['pm_marked'])
|
|
indvdum@0
|
538 |
{
|
|
indvdum@0
|
539 |
$important_ids[] = $msg_id;
|
|
indvdum@0
|
540 |
}
|
|
indvdum@0
|
541 |
break;
|
|
indvdum@0
|
542 |
}
|
|
indvdum@0
|
543 |
}
|
|
indvdum@0
|
544 |
|
|
indvdum@0
|
545 |
// We place this here because it could happen that the messages are doubled if a rule marks a message and then moves it into a specific
|
|
indvdum@0
|
546 |
// folder. Here we simply move the message into the INBOX if it gets not removed and also not put into a custom folder.
|
|
indvdum@0
|
547 |
if (!$folder_action && !$message_removed)
|
|
indvdum@0
|
548 |
{
|
|
indvdum@0
|
549 |
$move_into_folder[PRIVMSGS_INBOX][] = $msg_id;
|
|
indvdum@0
|
550 |
}
|
|
indvdum@0
|
551 |
}
|
|
indvdum@0
|
552 |
|
|
indvdum@0
|
553 |
// Do not change the order of processing
|
|
indvdum@0
|
554 |
// The number of queries needed to be executed here highly depends on the defined rules and are
|
|
indvdum@0
|
555 |
// only gone through if new messages arrive.
|
|
indvdum@0
|
556 |
|
|
indvdum@0
|
557 |
// Delete messages
|
|
indvdum@0
|
558 |
if (sizeof($delete_ids))
|
|
indvdum@0
|
559 |
{
|
|
indvdum@0
|
560 |
$num_removed += sizeof($delete_ids);
|
|
indvdum@0
|
561 |
delete_pm($user_id, $delete_ids, PRIVMSGS_NO_BOX);
|
|
indvdum@0
|
562 |
}
|
|
indvdum@0
|
563 |
|
|
indvdum@0
|
564 |
// Set messages to Unread
|
|
indvdum@0
|
565 |
if (sizeof($unread_ids))
|
|
indvdum@0
|
566 |
{
|
|
indvdum@0
|
567 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
568 |
SET pm_unread = 0
|
|
indvdum@0
|
569 |
WHERE ' . $db->sql_in_set('msg_id', $unread_ids) . "
|
|
indvdum@0
|
570 |
AND user_id = $user_id
|
|
indvdum@0
|
571 |
AND folder_id = " . PRIVMSGS_NO_BOX;
|
|
indvdum@0
|
572 |
$db->sql_query($sql);
|
|
indvdum@0
|
573 |
}
|
|
indvdum@0
|
574 |
|
|
indvdum@0
|
575 |
// mark messages as important
|
|
indvdum@0
|
576 |
if (sizeof($important_ids))
|
|
indvdum@0
|
577 |
{
|
|
indvdum@0
|
578 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
579 |
SET pm_marked = 1 - pm_marked
|
|
indvdum@0
|
580 |
WHERE folder_id = ' . PRIVMSGS_NO_BOX . "
|
|
indvdum@0
|
581 |
AND user_id = $user_id
|
|
indvdum@0
|
582 |
AND " . $db->sql_in_set('msg_id', $important_ids);
|
|
indvdum@0
|
583 |
$db->sql_query($sql);
|
|
indvdum@0
|
584 |
}
|
|
indvdum@0
|
585 |
|
|
indvdum@0
|
586 |
// Move into folder
|
|
indvdum@0
|
587 |
$folder = array();
|
|
indvdum@0
|
588 |
|
|
indvdum@0
|
589 |
if (sizeof($move_into_folder))
|
|
indvdum@0
|
590 |
{
|
|
indvdum@0
|
591 |
// Determine Full Folder Action - we need the move to folder id later eventually
|
|
indvdum@0
|
592 |
$full_folder_action = ($user->data['user_full_folder'] == FULL_FOLDER_NONE) ? ($config['full_folder_action'] - (FULL_FOLDER_NONE*(-1))) : $user->data['user_full_folder'];
|
|
indvdum@0
|
593 |
|
|
indvdum@0
|
594 |
$sql_folder = array_keys($move_into_folder);
|
|
indvdum@0
|
595 |
if ($full_folder_action >= 0)
|
|
indvdum@0
|
596 |
{
|
|
indvdum@0
|
597 |
$sql_folder[] = $full_folder_action;
|
|
indvdum@0
|
598 |
}
|
|
indvdum@0
|
599 |
|
|
indvdum@0
|
600 |
$sql = 'SELECT folder_id, pm_count
|
|
indvdum@0
|
601 |
FROM ' . PRIVMSGS_FOLDER_TABLE . '
|
|
indvdum@0
|
602 |
WHERE ' . $db->sql_in_set('folder_id', $sql_folder) . "
|
|
indvdum@0
|
603 |
AND user_id = $user_id";
|
|
indvdum@0
|
604 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
605 |
|
|
indvdum@0
|
606 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
607 |
{
|
|
indvdum@0
|
608 |
$folder[(int) $row['folder_id']] = (int) $row['pm_count'];
|
|
indvdum@0
|
609 |
}
|
|
indvdum@0
|
610 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
611 |
|
|
indvdum@0
|
612 |
unset($sql_folder);
|
|
indvdum@0
|
613 |
|
|
indvdum@0
|
614 |
if (isset($move_into_folder[PRIVMSGS_INBOX]))
|
|
indvdum@0
|
615 |
{
|
|
indvdum@0
|
616 |
$sql = 'SELECT COUNT(msg_id) as num_messages
|
|
indvdum@0
|
617 |
FROM ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
618 |
WHERE user_id = $user_id
|
|
indvdum@0
|
619 |
AND folder_id = " . PRIVMSGS_INBOX;
|
|
indvdum@0
|
620 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
621 |
$folder[PRIVMSGS_INBOX] = (int) $db->sql_fetchfield('num_messages');
|
|
indvdum@0
|
622 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
623 |
}
|
|
indvdum@0
|
624 |
}
|
|
indvdum@0
|
625 |
|
|
indvdum@0
|
626 |
// Here we have ideally only one folder to move into
|
|
indvdum@0
|
627 |
foreach ($move_into_folder as $folder_id => $msg_ary)
|
|
indvdum@0
|
628 |
{
|
|
indvdum@0
|
629 |
$dest_folder = $folder_id;
|
|
indvdum@0
|
630 |
$full_folder_action = FULL_FOLDER_NONE;
|
|
indvdum@0
|
631 |
|
|
indvdum@0
|
632 |
// Check Message Limit - we calculate with the complete array, most of the time it is one message
|
|
indvdum@0
|
633 |
// But we are making sure that the other way around works too (more messages in queue than allowed to be stored)
|
|
indvdum@0
|
634 |
if ($user->data['message_limit'] && $folder[$folder_id] && ($folder[$folder_id] + sizeof($msg_ary)) > $user->data['message_limit'])
|
|
indvdum@0
|
635 |
{
|
|
indvdum@0
|
636 |
$full_folder_action = ($user->data['user_full_folder'] == FULL_FOLDER_NONE) ? ($config['full_folder_action'] - (FULL_FOLDER_NONE*(-1))) : $user->data['user_full_folder'];
|
|
indvdum@0
|
637 |
|
|
indvdum@0
|
638 |
// If destination folder itself is full...
|
|
indvdum@0
|
639 |
if ($full_folder_action >= 0 && ($folder[$full_folder_action] + sizeof($msg_ary)) > $user->data['message_limit'])
|
|
indvdum@0
|
640 |
{
|
|
indvdum@0
|
641 |
$full_folder_action = $config['full_folder_action'] - (FULL_FOLDER_NONE*(-1));
|
|
indvdum@0
|
642 |
}
|
|
indvdum@0
|
643 |
|
|
indvdum@0
|
644 |
// If Full Folder Action is to move to another folder, we simply adjust the destination folder
|
|
indvdum@0
|
645 |
if ($full_folder_action >= 0)
|
|
indvdum@0
|
646 |
{
|
|
indvdum@0
|
647 |
$dest_folder = $full_folder_action;
|
|
indvdum@0
|
648 |
}
|
|
indvdum@0
|
649 |
else if ($full_folder_action == FULL_FOLDER_DELETE)
|
|
indvdum@0
|
650 |
{
|
|
indvdum@0
|
651 |
// Delete some messages. NOTE: Ordered by msg_id here instead of message_time!
|
|
indvdum@0
|
652 |
$sql = 'SELECT msg_id
|
|
indvdum@0
|
653 |
FROM ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
654 |
WHERE user_id = $user_id
|
|
indvdum@0
|
655 |
AND folder_id = $dest_folder
|
|
indvdum@0
|
656 |
ORDER BY msg_id ASC";
|
|
indvdum@0
|
657 |
$result = $db->sql_query_limit($sql, (($folder[$dest_folder] + sizeof($msg_ary)) - $user->data['message_limit']));
|
|
indvdum@0
|
658 |
|
|
indvdum@0
|
659 |
$delete_ids = array();
|
|
indvdum@0
|
660 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
661 |
{
|
|
indvdum@0
|
662 |
$delete_ids[] = $row['msg_id'];
|
|
indvdum@0
|
663 |
}
|
|
indvdum@0
|
664 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
665 |
|
|
indvdum@0
|
666 |
$num_removed += sizeof($delete_ids);
|
|
indvdum@0
|
667 |
delete_pm($user_id, $delete_ids, $dest_folder);
|
|
indvdum@0
|
668 |
}
|
|
indvdum@0
|
669 |
}
|
|
indvdum@0
|
670 |
|
|
indvdum@0
|
671 |
//
|
|
indvdum@0
|
672 |
if ($full_folder_action == FULL_FOLDER_HOLD)
|
|
indvdum@0
|
673 |
{
|
|
indvdum@0
|
674 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
675 |
SET folder_id = ' . PRIVMSGS_HOLD_BOX . '
|
|
indvdum@0
|
676 |
WHERE folder_id = ' . PRIVMSGS_NO_BOX . "
|
|
indvdum@0
|
677 |
AND user_id = $user_id
|
|
indvdum@0
|
678 |
AND " . $db->sql_in_set('msg_id', $msg_ary);
|
|
indvdum@0
|
679 |
$db->sql_query($sql);
|
|
indvdum@0
|
680 |
}
|
|
indvdum@0
|
681 |
else
|
|
indvdum@0
|
682 |
{
|
|
indvdum@0
|
683 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
684 |
SET folder_id = $dest_folder, pm_new = 0
|
|
indvdum@0
|
685 |
WHERE folder_id = " . PRIVMSGS_NO_BOX . "
|
|
indvdum@0
|
686 |
AND user_id = $user_id
|
|
indvdum@0
|
687 |
AND pm_new = 1
|
|
indvdum@0
|
688 |
AND " . $db->sql_in_set('msg_id', $msg_ary);
|
|
indvdum@0
|
689 |
$db->sql_query($sql);
|
|
indvdum@0
|
690 |
|
|
indvdum@0
|
691 |
if ($dest_folder != PRIVMSGS_INBOX)
|
|
indvdum@0
|
692 |
{
|
|
indvdum@0
|
693 |
$sql = 'UPDATE ' . PRIVMSGS_FOLDER_TABLE . '
|
|
indvdum@0
|
694 |
SET pm_count = pm_count + ' . (int) $db->sql_affectedrows() . "
|
|
indvdum@0
|
695 |
WHERE folder_id = $dest_folder
|
|
indvdum@0
|
696 |
AND user_id = $user_id";
|
|
indvdum@0
|
697 |
$db->sql_query($sql);
|
|
indvdum@0
|
698 |
}
|
|
indvdum@0
|
699 |
}
|
|
indvdum@0
|
700 |
}
|
|
indvdum@0
|
701 |
|
|
indvdum@0
|
702 |
if (sizeof($action_ary))
|
|
indvdum@0
|
703 |
{
|
|
indvdum@0
|
704 |
// Move from OUTBOX to SENTBOX
|
|
indvdum@0
|
705 |
// We are not checking any full folder status here... SENTBOX is a special treatment (old messages get deleted)
|
|
indvdum@0
|
706 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
707 |
SET folder_id = ' . PRIVMSGS_SENTBOX . '
|
|
indvdum@0
|
708 |
WHERE folder_id = ' . PRIVMSGS_OUTBOX . '
|
|
indvdum@0
|
709 |
AND ' . $db->sql_in_set('msg_id', array_keys($action_ary));
|
|
indvdum@0
|
710 |
$db->sql_query($sql);
|
|
indvdum@0
|
711 |
}
|
|
indvdum@0
|
712 |
|
|
indvdum@0
|
713 |
// Update new/unread count
|
|
indvdum@0
|
714 |
update_pm_counts();
|
|
indvdum@0
|
715 |
|
|
indvdum@0
|
716 |
// Now check how many messages got not moved...
|
|
indvdum@0
|
717 |
$sql = 'SELECT COUNT(msg_id) as num_messages
|
|
indvdum@0
|
718 |
FROM ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
719 |
WHERE user_id = $user_id
|
|
indvdum@0
|
720 |
AND folder_id = " . PRIVMSGS_HOLD_BOX;
|
|
indvdum@0
|
721 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
722 |
$num_not_moved = (int) $db->sql_fetchfield('num_messages');
|
|
indvdum@0
|
723 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
724 |
|
|
indvdum@0
|
725 |
return array('not_moved' => $num_not_moved, 'removed' => $num_removed);
|
|
indvdum@0
|
726 |
}
|
|
indvdum@0
|
727 |
|
|
indvdum@0
|
728 |
/**
|
|
indvdum@0
|
729 |
* Move PM from one to another folder
|
|
indvdum@0
|
730 |
*/
|
|
indvdum@0
|
731 |
function move_pm($user_id, $message_limit, $move_msg_ids, $dest_folder, $cur_folder_id)
|
|
indvdum@0
|
732 |
{
|
|
indvdum@0
|
733 |
global $db, $user;
|
|
indvdum@0
|
734 |
global $phpbb_root_path, $phpEx;
|
|
indvdum@0
|
735 |
|
|
indvdum@0
|
736 |
$num_moved = 0;
|
|
indvdum@0
|
737 |
|
|
indvdum@0
|
738 |
if (!is_array($move_msg_ids))
|
|
indvdum@0
|
739 |
{
|
|
indvdum@0
|
740 |
$move_msg_ids = array($move_msg_ids);
|
|
indvdum@0
|
741 |
}
|
|
indvdum@0
|
742 |
|
|
indvdum@0
|
743 |
if (sizeof($move_msg_ids) && !in_array($dest_folder, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX, PRIVMSGS_SENTBOX)) &&
|
|
indvdum@0
|
744 |
!in_array($cur_folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)) && $cur_folder_id != $dest_folder)
|
|
indvdum@0
|
745 |
{
|
|
indvdum@0
|
746 |
// We have to check the destination folder ;)
|
|
indvdum@0
|
747 |
if ($dest_folder != PRIVMSGS_INBOX)
|
|
indvdum@0
|
748 |
{
|
|
indvdum@0
|
749 |
$sql = 'SELECT folder_id, folder_name, pm_count
|
|
indvdum@0
|
750 |
FROM ' . PRIVMSGS_FOLDER_TABLE . "
|
|
indvdum@0
|
751 |
WHERE folder_id = $dest_folder
|
|
indvdum@0
|
752 |
AND user_id = $user_id";
|
|
indvdum@0
|
753 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
754 |
$row = $db->sql_fetchrow($result);
|
|
indvdum@0
|
755 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
756 |
|
|
indvdum@0
|
757 |
if (!$row)
|
|
indvdum@0
|
758 |
{
|
|
indvdum@0
|
759 |
trigger_error('NOT_AUTHORISED');
|
|
indvdum@0
|
760 |
}
|
|
indvdum@0
|
761 |
|
|
indvdum@0
|
762 |
if ($message_limit && $row['pm_count'] + sizeof($move_msg_ids) > $message_limit)
|
|
indvdum@0
|
763 |
{
|
|
indvdum@0
|
764 |
$message = sprintf($user->lang['NOT_ENOUGH_SPACE_FOLDER'], $row['folder_name']) . '<br /><br />';
|
|
indvdum@0
|
765 |
$message .= sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=' . $row['folder_id']) . '">', '</a>', $row['folder_name']);
|
|
indvdum@0
|
766 |
trigger_error($message);
|
|
indvdum@0
|
767 |
}
|
|
indvdum@0
|
768 |
}
|
|
indvdum@0
|
769 |
else
|
|
indvdum@0
|
770 |
{
|
|
indvdum@0
|
771 |
$sql = 'SELECT COUNT(msg_id) as num_messages
|
|
indvdum@0
|
772 |
FROM ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
773 |
WHERE folder_id = ' . PRIVMSGS_INBOX . "
|
|
indvdum@0
|
774 |
AND user_id = $user_id";
|
|
indvdum@0
|
775 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
776 |
$num_messages = (int) $db->sql_fetchfield('num_messages');
|
|
indvdum@0
|
777 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
778 |
|
|
indvdum@0
|
779 |
if ($message_limit && $num_messages + sizeof($move_msg_ids) > $message_limit)
|
|
indvdum@0
|
780 |
{
|
|
indvdum@0
|
781 |
$message = sprintf($user->lang['NOT_ENOUGH_SPACE_FOLDER'], $user->lang['PM_INBOX']) . '<br /><br />';
|
|
indvdum@0
|
782 |
$message .= sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox') . '">', '</a>', $user->lang['PM_INBOX']);
|
|
indvdum@0
|
783 |
trigger_error($message);
|
|
indvdum@0
|
784 |
}
|
|
indvdum@0
|
785 |
}
|
|
indvdum@0
|
786 |
|
|
indvdum@0
|
787 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
788 |
SET folder_id = $dest_folder
|
|
indvdum@0
|
789 |
WHERE folder_id = $cur_folder_id
|
|
indvdum@0
|
790 |
AND user_id = $user_id
|
|
indvdum@0
|
791 |
AND " . $db->sql_in_set('msg_id', $move_msg_ids);
|
|
indvdum@0
|
792 |
$db->sql_query($sql);
|
|
indvdum@0
|
793 |
$num_moved = $db->sql_affectedrows();
|
|
indvdum@0
|
794 |
|
|
indvdum@0
|
795 |
// Update pm counts
|
|
indvdum@0
|
796 |
if ($num_moved)
|
|
indvdum@0
|
797 |
{
|
|
indvdum@0
|
798 |
if (!in_array($cur_folder_id, array(PRIVMSGS_INBOX, PRIVMSGS_OUTBOX, PRIVMSGS_SENTBOX)))
|
|
indvdum@0
|
799 |
{
|
|
indvdum@0
|
800 |
$sql = 'UPDATE ' . PRIVMSGS_FOLDER_TABLE . "
|
|
indvdum@0
|
801 |
SET pm_count = pm_count - $num_moved
|
|
indvdum@0
|
802 |
WHERE folder_id = $cur_folder_id
|
|
indvdum@0
|
803 |
AND user_id = $user_id";
|
|
indvdum@0
|
804 |
$db->sql_query($sql);
|
|
indvdum@0
|
805 |
}
|
|
indvdum@0
|
806 |
|
|
indvdum@0
|
807 |
if ($dest_folder != PRIVMSGS_INBOX)
|
|
indvdum@0
|
808 |
{
|
|
indvdum@0
|
809 |
$sql = 'UPDATE ' . PRIVMSGS_FOLDER_TABLE . "
|
|
indvdum@0
|
810 |
SET pm_count = pm_count + $num_moved
|
|
indvdum@0
|
811 |
WHERE folder_id = $dest_folder
|
|
indvdum@0
|
812 |
AND user_id = $user_id";
|
|
indvdum@0
|
813 |
$db->sql_query($sql);
|
|
indvdum@0
|
814 |
}
|
|
indvdum@0
|
815 |
}
|
|
indvdum@0
|
816 |
}
|
|
indvdum@0
|
817 |
else if (in_array($cur_folder_id, array(PRIVMSGS_NO_BOX, PRIVMSGS_OUTBOX)))
|
|
indvdum@0
|
818 |
{
|
|
indvdum@0
|
819 |
trigger_error('CANNOT_MOVE_SPECIAL');
|
|
indvdum@0
|
820 |
}
|
|
indvdum@0
|
821 |
|
|
indvdum@0
|
822 |
return $num_moved;
|
|
indvdum@0
|
823 |
}
|
|
indvdum@0
|
824 |
|
|
indvdum@0
|
825 |
/**
|
|
indvdum@0
|
826 |
* Update unread message status
|
|
indvdum@0
|
827 |
*/
|
|
indvdum@0
|
828 |
function update_unread_status($unread, $msg_id, $user_id, $folder_id)
|
|
indvdum@0
|
829 |
{
|
|
indvdum@0
|
830 |
if (!$unread)
|
|
indvdum@0
|
831 |
{
|
|
indvdum@0
|
832 |
return;
|
|
indvdum@0
|
833 |
}
|
|
indvdum@0
|
834 |
|
|
indvdum@0
|
835 |
global $db, $user;
|
|
indvdum@0
|
836 |
|
|
indvdum@0
|
837 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
838 |
SET pm_unread = 0
|
|
indvdum@0
|
839 |
WHERE msg_id = $msg_id
|
|
indvdum@0
|
840 |
AND user_id = $user_id
|
|
indvdum@0
|
841 |
AND folder_id = $folder_id";
|
|
indvdum@0
|
842 |
$db->sql_query($sql);
|
|
indvdum@0
|
843 |
|
|
indvdum@0
|
844 |
$sql = 'UPDATE ' . USERS_TABLE . "
|
|
indvdum@0
|
845 |
SET user_unread_privmsg = user_unread_privmsg - 1
|
|
indvdum@0
|
846 |
WHERE user_id = $user_id";
|
|
indvdum@0
|
847 |
$db->sql_query($sql);
|
|
indvdum@0
|
848 |
|
|
indvdum@0
|
849 |
if ($user->data['user_id'] == $user_id)
|
|
indvdum@0
|
850 |
{
|
|
indvdum@0
|
851 |
$user->data['user_unread_privmsg']--;
|
|
indvdum@0
|
852 |
|
|
indvdum@0
|
853 |
// Try to cope with previous wrong conversions...
|
|
indvdum@0
|
854 |
if ($user->data['user_unread_privmsg'] < 0)
|
|
indvdum@0
|
855 |
{
|
|
indvdum@0
|
856 |
$sql = 'UPDATE ' . USERS_TABLE . "
|
|
indvdum@0
|
857 |
SET user_unread_privmsg = 0
|
|
indvdum@0
|
858 |
WHERE user_id = $user_id";
|
|
indvdum@0
|
859 |
$db->sql_query($sql);
|
|
indvdum@0
|
860 |
|
|
indvdum@0
|
861 |
$user->data['user_unread_privmsg'] = 0;
|
|
indvdum@0
|
862 |
}
|
|
indvdum@0
|
863 |
}
|
|
indvdum@0
|
864 |
}
|
|
indvdum@0
|
865 |
|
|
indvdum@0
|
866 |
/**
|
|
indvdum@0
|
867 |
* Handle all actions possible with marked messages
|
|
indvdum@0
|
868 |
*/
|
|
indvdum@0
|
869 |
function handle_mark_actions($user_id, $mark_action)
|
|
indvdum@0
|
870 |
{
|
|
indvdum@0
|
871 |
global $db, $user, $phpbb_root_path, $phpEx;
|
|
indvdum@0
|
872 |
|
|
indvdum@0
|
873 |
$msg_ids = request_var('marked_msg_id', array(0));
|
|
indvdum@0
|
874 |
$cur_folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX);
|
|
indvdum@0
|
875 |
$confirm = (isset($_POST['confirm'])) ? true : false;
|
|
indvdum@0
|
876 |
|
|
indvdum@0
|
877 |
if (!sizeof($msg_ids))
|
|
indvdum@0
|
878 |
{
|
|
indvdum@0
|
879 |
return false;
|
|
indvdum@0
|
880 |
}
|
|
indvdum@0
|
881 |
|
|
indvdum@0
|
882 |
switch ($mark_action)
|
|
indvdum@0
|
883 |
{
|
|
indvdum@0
|
884 |
case 'mark_important':
|
|
indvdum@0
|
885 |
|
|
indvdum@0
|
886 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
887 |
SET pm_marked = 1 - pm_marked
|
|
indvdum@0
|
888 |
WHERE folder_id = $cur_folder_id
|
|
indvdum@0
|
889 |
AND user_id = $user_id
|
|
indvdum@0
|
890 |
AND " . $db->sql_in_set('msg_id', $msg_ids);
|
|
indvdum@0
|
891 |
$db->sql_query($sql);
|
|
indvdum@0
|
892 |
|
|
indvdum@0
|
893 |
break;
|
|
indvdum@0
|
894 |
|
|
indvdum@0
|
895 |
case 'delete_marked':
|
|
indvdum@0
|
896 |
|
|
indvdum@0
|
897 |
global $auth;
|
|
indvdum@0
|
898 |
|
|
indvdum@0
|
899 |
if (!$auth->acl_get('u_pm_delete'))
|
|
indvdum@0
|
900 |
{
|
|
indvdum@0
|
901 |
trigger_error('NO_AUTH_DELETE_MESSAGE');
|
|
indvdum@0
|
902 |
}
|
|
indvdum@0
|
903 |
|
|
indvdum@0
|
904 |
if (confirm_box(true))
|
|
indvdum@0
|
905 |
{
|
|
indvdum@0
|
906 |
delete_pm($user_id, $msg_ids, $cur_folder_id);
|
|
indvdum@0
|
907 |
|
|
indvdum@0
|
908 |
$success_msg = (sizeof($msg_ids) == 1) ? 'MESSAGE_DELETED' : 'MESSAGES_DELETED';
|
|
indvdum@0
|
909 |
$redirect = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=' . $cur_folder_id);
|
|
indvdum@0
|
910 |
|
|
indvdum@0
|
911 |
meta_refresh(3, $redirect);
|
|
indvdum@0
|
912 |
trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $redirect . '">', '</a>'));
|
|
indvdum@0
|
913 |
}
|
|
indvdum@0
|
914 |
else
|
|
indvdum@0
|
915 |
{
|
|
indvdum@0
|
916 |
$s_hidden_fields = array(
|
|
indvdum@0
|
917 |
'cur_folder_id' => $cur_folder_id,
|
|
indvdum@0
|
918 |
'mark_option' => 'delete_marked',
|
|
indvdum@0
|
919 |
'submit_mark' => true,
|
|
indvdum@0
|
920 |
'marked_msg_id' => $msg_ids
|
|
indvdum@0
|
921 |
);
|
|
indvdum@0
|
922 |
|
|
indvdum@0
|
923 |
confirm_box(false, 'DELETE_MARKED_PM', build_hidden_fields($s_hidden_fields));
|
|
indvdum@0
|
924 |
}
|
|
indvdum@0
|
925 |
|
|
indvdum@0
|
926 |
break;
|
|
indvdum@0
|
927 |
|
|
indvdum@0
|
928 |
default:
|
|
indvdum@0
|
929 |
return false;
|
|
indvdum@0
|
930 |
}
|
|
indvdum@0
|
931 |
|
|
indvdum@0
|
932 |
return true;
|
|
indvdum@0
|
933 |
}
|
|
indvdum@0
|
934 |
|
|
indvdum@0
|
935 |
/**
|
|
indvdum@0
|
936 |
* Delete PM(s)
|
|
indvdum@0
|
937 |
*/
|
|
indvdum@0
|
938 |
function delete_pm($user_id, $msg_ids, $folder_id)
|
|
indvdum@0
|
939 |
{
|
|
indvdum@0
|
940 |
global $db, $user, $phpbb_root_path, $phpEx;
|
|
indvdum@0
|
941 |
|
|
indvdum@0
|
942 |
$user_id = (int) $user_id;
|
|
indvdum@0
|
943 |
$folder_id = (int) $folder_id;
|
|
indvdum@0
|
944 |
|
|
indvdum@0
|
945 |
if (!$user_id)
|
|
indvdum@0
|
946 |
{
|
|
indvdum@0
|
947 |
return false;
|
|
indvdum@0
|
948 |
}
|
|
indvdum@0
|
949 |
|
|
indvdum@0
|
950 |
if (!is_array($msg_ids))
|
|
indvdum@0
|
951 |
{
|
|
indvdum@0
|
952 |
if (!$msg_ids)
|
|
indvdum@0
|
953 |
{
|
|
indvdum@0
|
954 |
return false;
|
|
indvdum@0
|
955 |
}
|
|
indvdum@0
|
956 |
$msg_ids = array($msg_ids);
|
|
indvdum@0
|
957 |
}
|
|
indvdum@0
|
958 |
|
|
indvdum@0
|
959 |
if (!sizeof($msg_ids))
|
|
indvdum@0
|
960 |
{
|
|
indvdum@0
|
961 |
return false;
|
|
indvdum@0
|
962 |
}
|
|
indvdum@0
|
963 |
|
|
indvdum@0
|
964 |
// Get PM Information for later deleting
|
|
indvdum@0
|
965 |
$sql = 'SELECT msg_id, pm_unread, pm_new
|
|
indvdum@0
|
966 |
FROM ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
967 |
WHERE ' . $db->sql_in_set('msg_id', array_map('intval', $msg_ids)) . "
|
|
indvdum@0
|
968 |
AND folder_id = $folder_id
|
|
indvdum@0
|
969 |
AND user_id = $user_id";
|
|
indvdum@0
|
970 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
971 |
|
|
indvdum@0
|
972 |
$delete_rows = array();
|
|
indvdum@0
|
973 |
$num_unread = $num_new = $num_deleted = 0;
|
|
indvdum@0
|
974 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
975 |
{
|
|
indvdum@0
|
976 |
$num_unread += (int) $row['pm_unread'];
|
|
indvdum@0
|
977 |
$num_new += (int) $row['pm_new'];
|
|
indvdum@0
|
978 |
|
|
indvdum@0
|
979 |
$delete_rows[$row['msg_id']] = 1;
|
|
indvdum@0
|
980 |
}
|
|
indvdum@0
|
981 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
982 |
unset($msg_ids);
|
|
indvdum@0
|
983 |
|
|
indvdum@0
|
984 |
if (!sizeof($delete_rows))
|
|
indvdum@0
|
985 |
{
|
|
indvdum@0
|
986 |
return false;
|
|
indvdum@0
|
987 |
}
|
|
indvdum@0
|
988 |
|
|
indvdum@0
|
989 |
$db->sql_transaction('begin');
|
|
indvdum@0
|
990 |
|
|
indvdum@0
|
991 |
// if no one has read the message yet (meaning it is in users outbox)
|
|
indvdum@0
|
992 |
// then mark the message as deleted...
|
|
indvdum@0
|
993 |
if ($folder_id == PRIVMSGS_OUTBOX)
|
|
indvdum@0
|
994 |
{
|
|
indvdum@0
|
995 |
// Remove PM from Outbox
|
|
indvdum@0
|
996 |
$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
997 |
WHERE user_id = $user_id AND folder_id = " . PRIVMSGS_OUTBOX . '
|
|
indvdum@0
|
998 |
AND ' . $db->sql_in_set('msg_id', array_keys($delete_rows));
|
|
indvdum@0
|
999 |
$db->sql_query($sql);
|
|
indvdum@0
|
1000 |
|
|
indvdum@0
|
1001 |
// Update PM Information for safety
|
|
indvdum@0
|
1002 |
$sql = 'UPDATE ' . PRIVMSGS_TABLE . " SET message_text = ''
|
|
indvdum@0
|
1003 |
WHERE " . $db->sql_in_set('msg_id', array_keys($delete_rows));
|
|
indvdum@0
|
1004 |
$db->sql_query($sql);
|
|
indvdum@0
|
1005 |
|
|
indvdum@0
|
1006 |
// Set delete flag for those intended to receive the PM
|
|
indvdum@0
|
1007 |
// We do not remove the message actually, to retain some basic information (sent time for example)
|
|
indvdum@0
|
1008 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
1009 |
SET pm_deleted = 1
|
|
indvdum@0
|
1010 |
WHERE ' . $db->sql_in_set('msg_id', array_keys($delete_rows));
|
|
indvdum@0
|
1011 |
$db->sql_query($sql);
|
|
indvdum@0
|
1012 |
|
|
indvdum@0
|
1013 |
$num_deleted = $db->sql_affectedrows();
|
|
indvdum@0
|
1014 |
}
|
|
indvdum@0
|
1015 |
else
|
|
indvdum@0
|
1016 |
{
|
|
indvdum@0
|
1017 |
// Delete private message data
|
|
indvdum@0
|
1018 |
$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
1019 |
WHERE user_id = $user_id
|
|
indvdum@0
|
1020 |
AND folder_id = $folder_id
|
|
indvdum@0
|
1021 |
AND " . $db->sql_in_set('msg_id', array_keys($delete_rows));
|
|
indvdum@0
|
1022 |
$db->sql_query($sql);
|
|
indvdum@0
|
1023 |
$num_deleted = $db->sql_affectedrows();
|
|
indvdum@0
|
1024 |
}
|
|
indvdum@0
|
1025 |
|
|
indvdum@0
|
1026 |
// if folder id is user defined folder then decrease pm_count
|
|
indvdum@0
|
1027 |
if (!in_array($folder_id, array(PRIVMSGS_INBOX, PRIVMSGS_OUTBOX, PRIVMSGS_SENTBOX, PRIVMSGS_NO_BOX)))
|
|
indvdum@0
|
1028 |
{
|
|
indvdum@0
|
1029 |
$sql = 'UPDATE ' . PRIVMSGS_FOLDER_TABLE . "
|
|
indvdum@0
|
1030 |
SET pm_count = pm_count - $num_deleted
|
|
indvdum@0
|
1031 |
WHERE folder_id = $folder_id";
|
|
indvdum@0
|
1032 |
$db->sql_query($sql);
|
|
indvdum@0
|
1033 |
}
|
|
indvdum@0
|
1034 |
|
|
indvdum@0
|
1035 |
// Update unread and new status field
|
|
indvdum@0
|
1036 |
if ($num_unread || $num_new)
|
|
indvdum@0
|
1037 |
{
|
|
indvdum@0
|
1038 |
$set_sql = ($num_unread) ? 'user_unread_privmsg = user_unread_privmsg - ' . $num_unread : '';
|
|
indvdum@0
|
1039 |
|
|
indvdum@0
|
1040 |
if ($num_new)
|
|
indvdum@0
|
1041 |
{
|
|
indvdum@0
|
1042 |
$set_sql .= ($set_sql != '') ? ', ' : '';
|
|
indvdum@0
|
1043 |
$set_sql .= 'user_new_privmsg = user_new_privmsg - ' . $num_new;
|
|
indvdum@0
|
1044 |
}
|
|
indvdum@0
|
1045 |
|
|
indvdum@0
|
1046 |
$db->sql_query('UPDATE ' . USERS_TABLE . " SET $set_sql WHERE user_id = $user_id");
|
|
indvdum@0
|
1047 |
|
|
indvdum@0
|
1048 |
$user->data['user_new_privmsg'] -= $num_new;
|
|
indvdum@0
|
1049 |
$user->data['user_unread_privmsg'] -= $num_unread;
|
|
indvdum@0
|
1050 |
}
|
|
indvdum@0
|
1051 |
|
|
indvdum@0
|
1052 |
// Now we have to check which messages we can delete completely
|
|
indvdum@0
|
1053 |
$sql = 'SELECT msg_id
|
|
indvdum@0
|
1054 |
FROM ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
1055 |
WHERE ' . $db->sql_in_set('msg_id', array_keys($delete_rows));
|
|
indvdum@0
|
1056 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1057 |
|
|
indvdum@0
|
1058 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1059 |
{
|
|
indvdum@0
|
1060 |
unset($delete_rows[$row['msg_id']]);
|
|
indvdum@0
|
1061 |
}
|
|
indvdum@0
|
1062 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1063 |
|
|
indvdum@0
|
1064 |
$delete_ids = array_keys($delete_rows);
|
|
indvdum@0
|
1065 |
|
|
indvdum@0
|
1066 |
if (sizeof($delete_ids))
|
|
indvdum@0
|
1067 |
{
|
|
indvdum@0
|
1068 |
// Check if there are any attachments we need to remove
|
|
indvdum@0
|
1069 |
if (!function_exists('delete_attachments'))
|
|
indvdum@0
|
1070 |
{
|
|
indvdum@0
|
1071 |
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
indvdum@0
|
1072 |
}
|
|
indvdum@0
|
1073 |
|
|
indvdum@0
|
1074 |
delete_attachments('message', $delete_ids, false);
|
|
indvdum@0
|
1075 |
|
|
indvdum@0
|
1076 |
$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
|
|
indvdum@0
|
1077 |
WHERE ' . $db->sql_in_set('msg_id', $delete_ids);
|
|
indvdum@0
|
1078 |
$db->sql_query($sql);
|
|
indvdum@0
|
1079 |
}
|
|
indvdum@0
|
1080 |
|
|
indvdum@0
|
1081 |
$db->sql_transaction('commit');
|
|
indvdum@0
|
1082 |
|
|
indvdum@0
|
1083 |
return true;
|
|
indvdum@0
|
1084 |
}
|
|
indvdum@0
|
1085 |
|
|
indvdum@0
|
1086 |
/**
|
|
indvdum@0
|
1087 |
* Rebuild message header
|
|
indvdum@0
|
1088 |
*/
|
|
indvdum@0
|
1089 |
function rebuild_header($check_ary)
|
|
indvdum@0
|
1090 |
{
|
|
indvdum@0
|
1091 |
global $db;
|
|
indvdum@0
|
1092 |
|
|
indvdum@0
|
1093 |
$address = array();
|
|
indvdum@0
|
1094 |
|
|
indvdum@0
|
1095 |
foreach ($check_ary as $check_type => $address_field)
|
|
indvdum@0
|
1096 |
{
|
|
indvdum@0
|
1097 |
// Split Addresses into users and groups
|
|
indvdum@0
|
1098 |
preg_match_all('/:?(u|g)_([0-9]+):?/', $address_field, $match);
|
|
indvdum@0
|
1099 |
|
|
indvdum@0
|
1100 |
$u = $g = array();
|
|
indvdum@0
|
1101 |
foreach ($match[1] as $id => $type)
|
|
indvdum@0
|
1102 |
{
|
|
indvdum@0
|
1103 |
${$type}[] = (int) $match[2][$id];
|
|
indvdum@0
|
1104 |
}
|
|
indvdum@0
|
1105 |
|
|
indvdum@0
|
1106 |
$_types = array('u', 'g');
|
|
indvdum@0
|
1107 |
foreach ($_types as $type)
|
|
indvdum@0
|
1108 |
{
|
|
indvdum@0
|
1109 |
if (sizeof($$type))
|
|
indvdum@0
|
1110 |
{
|
|
indvdum@0
|
1111 |
foreach ($$type as $id)
|
|
indvdum@0
|
1112 |
{
|
|
indvdum@0
|
1113 |
$address[$type][$id] = $check_type;
|
|
indvdum@0
|
1114 |
}
|
|
indvdum@0
|
1115 |
}
|
|
indvdum@0
|
1116 |
}
|
|
indvdum@0
|
1117 |
}
|
|
indvdum@0
|
1118 |
|
|
indvdum@0
|
1119 |
return $address;
|
|
indvdum@0
|
1120 |
}
|
|
indvdum@0
|
1121 |
|
|
indvdum@0
|
1122 |
/**
|
|
indvdum@0
|
1123 |
* Print out/assign recipient information
|
|
indvdum@0
|
1124 |
*/
|
|
indvdum@0
|
1125 |
function write_pm_addresses($check_ary, $author_id, $plaintext = false)
|
|
indvdum@0
|
1126 |
{
|
|
indvdum@0
|
1127 |
global $db, $user, $template, $phpbb_root_path, $phpEx;
|
|
indvdum@0
|
1128 |
|
|
indvdum@0
|
1129 |
$addresses = array();
|
|
indvdum@0
|
1130 |
|
|
indvdum@0
|
1131 |
foreach ($check_ary as $check_type => $address_field)
|
|
indvdum@0
|
1132 |
{
|
|
indvdum@0
|
1133 |
if (!is_array($address_field))
|
|
indvdum@0
|
1134 |
{
|
|
indvdum@0
|
1135 |
// Split Addresses into users and groups
|
|
indvdum@0
|
1136 |
preg_match_all('/:?(u|g)_([0-9]+):?/', $address_field, $match);
|
|
indvdum@0
|
1137 |
|
|
indvdum@0
|
1138 |
$u = $g = array();
|
|
indvdum@0
|
1139 |
foreach ($match[1] as $id => $type)
|
|
indvdum@0
|
1140 |
{
|
|
indvdum@0
|
1141 |
${$type}[] = (int) $match[2][$id];
|
|
indvdum@0
|
1142 |
}
|
|
indvdum@0
|
1143 |
}
|
|
indvdum@0
|
1144 |
else
|
|
indvdum@0
|
1145 |
{
|
|
indvdum@0
|
1146 |
$u = $address_field['u'];
|
|
indvdum@0
|
1147 |
$g = $address_field['g'];
|
|
indvdum@0
|
1148 |
}
|
|
indvdum@0
|
1149 |
|
|
indvdum@0
|
1150 |
$address = array();
|
|
indvdum@0
|
1151 |
if (sizeof($u))
|
|
indvdum@0
|
1152 |
{
|
|
indvdum@0
|
1153 |
$sql = 'SELECT user_id, username, user_colour
|
|
indvdum@0
|
1154 |
FROM ' . USERS_TABLE . '
|
|
indvdum@0
|
1155 |
WHERE ' . $db->sql_in_set('user_id', $u);
|
|
indvdum@0
|
1156 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1157 |
|
|
indvdum@0
|
1158 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1159 |
{
|
|
indvdum@0
|
1160 |
if ($check_type == 'to' || $author_id == $user->data['user_id'] || $row['user_id'] == $user->data['user_id'])
|
|
indvdum@0
|
1161 |
{
|
|
indvdum@0
|
1162 |
if ($plaintext)
|
|
indvdum@0
|
1163 |
{
|
|
indvdum@0
|
1164 |
$address[] = $row['username'];
|
|
indvdum@0
|
1165 |
}
|
|
indvdum@0
|
1166 |
else
|
|
indvdum@0
|
1167 |
{
|
|
indvdum@0
|
1168 |
$address['user'][$row['user_id']] = array('name' => $row['username'], 'colour' => $row['user_colour']);
|
|
indvdum@0
|
1169 |
}
|
|
indvdum@0
|
1170 |
}
|
|
indvdum@0
|
1171 |
}
|
|
indvdum@0
|
1172 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1173 |
}
|
|
indvdum@0
|
1174 |
|
|
indvdum@0
|
1175 |
if (sizeof($g))
|
|
indvdum@0
|
1176 |
{
|
|
indvdum@0
|
1177 |
if ($plaintext)
|
|
indvdum@0
|
1178 |
{
|
|
indvdum@0
|
1179 |
$sql = 'SELECT group_name, group_type
|
|
indvdum@0
|
1180 |
FROM ' . GROUPS_TABLE . '
|
|
indvdum@0
|
1181 |
WHERE ' . $db->sql_in_set('group_id', $g);
|
|
indvdum@0
|
1182 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1183 |
|
|
indvdum@0
|
1184 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1185 |
{
|
|
indvdum@0
|
1186 |
if ($check_type == 'to' || $author_id == $user->data['user_id'] || $row['user_id'] == $user->data['user_id'])
|
|
indvdum@0
|
1187 |
{
|
|
indvdum@0
|
1188 |
$address[] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
|
|
indvdum@0
|
1189 |
}
|
|
indvdum@0
|
1190 |
}
|
|
indvdum@0
|
1191 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1192 |
}
|
|
indvdum@0
|
1193 |
else
|
|
indvdum@0
|
1194 |
{
|
|
indvdum@0
|
1195 |
$sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type, ug.user_id
|
|
indvdum@0
|
1196 |
FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
|
|
indvdum@0
|
1197 |
WHERE ' . $db->sql_in_set('g.group_id', $g) . '
|
|
indvdum@0
|
1198 |
AND g.group_id = ug.group_id
|
|
indvdum@0
|
1199 |
AND ug.user_pending = 0';
|
|
indvdum@0
|
1200 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1201 |
|
|
indvdum@0
|
1202 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1203 |
{
|
|
indvdum@0
|
1204 |
if (!isset($address['group'][$row['group_id']]))
|
|
indvdum@0
|
1205 |
{
|
|
indvdum@0
|
1206 |
if ($check_type == 'to' || $author_id == $user->data['user_id'] || $row['user_id'] == $user->data['user_id'])
|
|
indvdum@0
|
1207 |
{
|
|
indvdum@0
|
1208 |
$row['group_name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
|
|
indvdum@0
|
1209 |
$address['group'][$row['group_id']] = array('name' => $row['group_name'], 'colour' => $row['group_colour']);
|
|
indvdum@0
|
1210 |
}
|
|
indvdum@0
|
1211 |
}
|
|
indvdum@0
|
1212 |
|
|
indvdum@0
|
1213 |
if (isset($address['user'][$row['user_id']]))
|
|
indvdum@0
|
1214 |
{
|
|
indvdum@0
|
1215 |
$address['user'][$row['user_id']]['in_group'] = $row['group_id'];
|
|
indvdum@0
|
1216 |
}
|
|
indvdum@0
|
1217 |
}
|
|
indvdum@0
|
1218 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1219 |
}
|
|
indvdum@0
|
1220 |
}
|
|
indvdum@0
|
1221 |
|
|
indvdum@0
|
1222 |
if (sizeof($address) && !$plaintext)
|
|
indvdum@0
|
1223 |
{
|
|
indvdum@0
|
1224 |
$template->assign_var('S_' . strtoupper($check_type) . '_RECIPIENT', true);
|
|
indvdum@0
|
1225 |
|
|
indvdum@0
|
1226 |
foreach ($address as $type => $adr_ary)
|
|
indvdum@0
|
1227 |
{
|
|
indvdum@0
|
1228 |
foreach ($adr_ary as $id => $row)
|
|
indvdum@0
|
1229 |
{
|
|
indvdum@0
|
1230 |
$tpl_ary = array(
|
|
indvdum@0
|
1231 |
'IS_GROUP' => ($type == 'group') ? true : false,
|
|
indvdum@0
|
1232 |
'IS_USER' => ($type == 'user') ? true : false,
|
|
indvdum@0
|
1233 |
'UG_ID' => $id,
|
|
indvdum@0
|
1234 |
'NAME' => $row['name'],
|
|
indvdum@0
|
1235 |
'COLOUR' => ($row['colour']) ? '#' . $row['colour'] : '',
|
|
indvdum@0
|
1236 |
'TYPE' => $type,
|
|
indvdum@0
|
1237 |
);
|
|
indvdum@0
|
1238 |
|
|
indvdum@0
|
1239 |
if ($type == 'user')
|
|
indvdum@0
|
1240 |
{
|
|
indvdum@0
|
1241 |
$tpl_ary = array_merge($tpl_ary, array(
|
|
indvdum@0
|
1242 |
'U_VIEW' => get_username_string('profile', $id, $row['name'], $row['colour']),
|
|
indvdum@0
|
1243 |
'NAME_FULL' => get_username_string('full', $id, $row['name'], $row['colour']),
|
|
indvdum@0
|
1244 |
));
|
|
indvdum@0
|
1245 |
}
|
|
indvdum@0
|
1246 |
else
|
|
indvdum@0
|
1247 |
{
|
|
indvdum@0
|
1248 |
$tpl_ary = array_merge($tpl_ary, array(
|
|
indvdum@0
|
1249 |
'U_VIEW' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $id),
|
|
indvdum@0
|
1250 |
));
|
|
indvdum@0
|
1251 |
}
|
|
indvdum@0
|
1252 |
|
|
indvdum@0
|
1253 |
$template->assign_block_vars($check_type . '_recipient', $tpl_ary);
|
|
indvdum@0
|
1254 |
}
|
|
indvdum@0
|
1255 |
}
|
|
indvdum@0
|
1256 |
}
|
|
indvdum@0
|
1257 |
|
|
indvdum@0
|
1258 |
$addresses[$check_type] = $address;
|
|
indvdum@0
|
1259 |
}
|
|
indvdum@0
|
1260 |
|
|
indvdum@0
|
1261 |
return $addresses;
|
|
indvdum@0
|
1262 |
}
|
|
indvdum@0
|
1263 |
|
|
indvdum@0
|
1264 |
/**
|
|
indvdum@0
|
1265 |
* Get folder status
|
|
indvdum@0
|
1266 |
*/
|
|
indvdum@0
|
1267 |
function get_folder_status($folder_id, $folder)
|
|
indvdum@0
|
1268 |
{
|
|
indvdum@0
|
1269 |
global $db, $user, $config;
|
|
indvdum@0
|
1270 |
|
|
indvdum@0
|
1271 |
if (isset($folder[$folder_id]))
|
|
indvdum@0
|
1272 |
{
|
|
indvdum@0
|
1273 |
$folder = $folder[$folder_id];
|
|
indvdum@0
|
1274 |
}
|
|
indvdum@0
|
1275 |
else
|
|
indvdum@0
|
1276 |
{
|
|
indvdum@0
|
1277 |
return false;
|
|
indvdum@0
|
1278 |
}
|
|
indvdum@0
|
1279 |
|
|
indvdum@0
|
1280 |
$return = array(
|
|
indvdum@0
|
1281 |
'folder_name' => $folder['folder_name'],
|
|
indvdum@0
|
1282 |
'cur' => $folder['num_messages'],
|
|
indvdum@0
|
1283 |
'remaining' => ($user->data['message_limit']) ? $user->data['message_limit'] - $folder['num_messages'] : 0,
|
|
indvdum@0
|
1284 |
'max' => $user->data['message_limit'],
|
|
indvdum@0
|
1285 |
'percent' => ($user->data['message_limit']) ? (($user->data['message_limit'] > 0) ? round(($folder['num_messages'] / $user->data['message_limit']) * 100) : 100) : 0,
|
|
indvdum@0
|
1286 |
);
|
|
indvdum@0
|
1287 |
|
|
indvdum@0
|
1288 |
$return['message'] = sprintf($user->lang['FOLDER_STATUS_MSG'], $return['percent'], $return['cur'], $return['max']);
|
|
indvdum@0
|
1289 |
|
|
indvdum@0
|
1290 |
return $return;
|
|
indvdum@0
|
1291 |
}
|
|
indvdum@0
|
1292 |
|
|
indvdum@0
|
1293 |
//
|
|
indvdum@0
|
1294 |
// COMPOSE MESSAGES
|
|
indvdum@0
|
1295 |
//
|
|
indvdum@0
|
1296 |
|
|
indvdum@0
|
1297 |
/**
|
|
indvdum@0
|
1298 |
* Submit PM
|
|
indvdum@0
|
1299 |
*/
|
|
indvdum@0
|
1300 |
function submit_pm($mode, $subject, &$data, $put_in_outbox = true)
|
|
indvdum@0
|
1301 |
{
|
|
indvdum@0
|
1302 |
global $db, $auth, $config, $phpEx, $template, $user, $phpbb_root_path;
|
|
indvdum@0
|
1303 |
|
|
indvdum@0
|
1304 |
// We do not handle erasing pms here
|
|
indvdum@0
|
1305 |
if ($mode == 'delete')
|
|
indvdum@0
|
1306 |
{
|
|
indvdum@0
|
1307 |
return false;
|
|
indvdum@0
|
1308 |
}
|
|
indvdum@0
|
1309 |
|
|
indvdum@0
|
1310 |
$current_time = time();
|
|
indvdum@0
|
1311 |
|
|
indvdum@0
|
1312 |
// Collect some basic information about which tables and which rows to update/insert
|
|
indvdum@0
|
1313 |
$sql_data = array();
|
|
indvdum@0
|
1314 |
$root_level = 0;
|
|
indvdum@0
|
1315 |
|
|
indvdum@0
|
1316 |
// Recipient Information
|
|
indvdum@0
|
1317 |
$recipients = $to = $bcc = array();
|
|
indvdum@0
|
1318 |
|
|
indvdum@0
|
1319 |
if ($mode != 'edit')
|
|
indvdum@0
|
1320 |
{
|
|
indvdum@0
|
1321 |
// Build Recipient List
|
|
indvdum@0
|
1322 |
// u|g => array($user_id => 'to'|'bcc')
|
|
indvdum@0
|
1323 |
$_types = array('u', 'g');
|
|
indvdum@0
|
1324 |
foreach ($_types as $ug_type)
|
|
indvdum@0
|
1325 |
{
|
|
indvdum@0
|
1326 |
if (isset($data['address_list'][$ug_type]) && sizeof($data['address_list'][$ug_type]))
|
|
indvdum@0
|
1327 |
{
|
|
indvdum@0
|
1328 |
foreach ($data['address_list'][$ug_type] as $id => $field)
|
|
indvdum@0
|
1329 |
{
|
|
indvdum@0
|
1330 |
$id = (int) $id;
|
|
indvdum@0
|
1331 |
|
|
indvdum@0
|
1332 |
// Do not rely on the address list being "valid"
|
|
indvdum@0
|
1333 |
if (!$id || ($ug_type == 'u' && $id == ANONYMOUS))
|
|
indvdum@0
|
1334 |
{
|
|
indvdum@0
|
1335 |
continue;
|
|
indvdum@0
|
1336 |
}
|
|
indvdum@0
|
1337 |
|
|
indvdum@0
|
1338 |
$field = ($field == 'to') ? 'to' : 'bcc';
|
|
indvdum@0
|
1339 |
if ($ug_type == 'u')
|
|
indvdum@0
|
1340 |
{
|
|
indvdum@0
|
1341 |
$recipients[$id] = $field;
|
|
indvdum@0
|
1342 |
}
|
|
indvdum@0
|
1343 |
${$field}[] = $ug_type . '_' . $id;
|
|
indvdum@0
|
1344 |
}
|
|
indvdum@0
|
1345 |
}
|
|
indvdum@0
|
1346 |
}
|
|
indvdum@0
|
1347 |
|
|
indvdum@0
|
1348 |
if (isset($data['address_list']['g']) && sizeof($data['address_list']['g']))
|
|
indvdum@0
|
1349 |
{
|
|
indvdum@0
|
1350 |
// We need to check the PM status of group members (do they want to receive PM's?)
|
|
indvdum@0
|
1351 |
// Only check if not a moderator or admin, since they are allowed to override this user setting
|
|
indvdum@0
|
1352 |
$sql_allow_pm = (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) ? ' AND u.user_allow_pm = 1' : '';
|
|
indvdum@0
|
1353 |
|
|
indvdum@0
|
1354 |
$sql = 'SELECT u.user_type, ug.group_id, ug.user_id
|
|
indvdum@0
|
1355 |
FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . ' ug
|
|
indvdum@0
|
1356 |
WHERE ' . $db->sql_in_set('ug.group_id', array_keys($data['address_list']['g'])) . '
|
|
indvdum@0
|
1357 |
AND ug.user_pending = 0
|
|
indvdum@0
|
1358 |
AND u.user_id = ug.user_id
|
|
indvdum@0
|
1359 |
AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')' .
|
|
indvdum@0
|
1360 |
$sql_allow_pm;
|
|
indvdum@0
|
1361 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1362 |
|
|
indvdum@0
|
1363 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1364 |
{
|
|
indvdum@0
|
1365 |
// Additionally, do not include the sender if he is in the group he wants to send to. ;)
|
|
indvdum@0
|
1366 |
if ($row['user_id'] === $user->data['user_id'])
|
|
indvdum@0
|
1367 |
{
|
|
indvdum@0
|
1368 |
continue;
|
|
indvdum@0
|
1369 |
}
|
|
indvdum@0
|
1370 |
|
|
indvdum@0
|
1371 |
$field = ($data['address_list']['g'][$row['group_id']] == 'to') ? 'to' : 'bcc';
|
|
indvdum@0
|
1372 |
$recipients[$row['user_id']] = $field;
|
|
indvdum@0
|
1373 |
}
|
|
indvdum@0
|
1374 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1375 |
}
|
|
indvdum@0
|
1376 |
|
|
indvdum@0
|
1377 |
if (!sizeof($recipients))
|
|
indvdum@0
|
1378 |
{
|
|
indvdum@0
|
1379 |
trigger_error('NO_RECIPIENT');
|
|
indvdum@0
|
1380 |
}
|
|
indvdum@0
|
1381 |
}
|
|
indvdum@0
|
1382 |
|
|
indvdum@0
|
1383 |
// First of all make sure the subject are having the correct length.
|
|
indvdum@0
|
1384 |
$subject = truncate_string($subject);
|
|
indvdum@0
|
1385 |
|
|
indvdum@0
|
1386 |
$db->sql_transaction('begin');
|
|
indvdum@0
|
1387 |
|
|
indvdum@0
|
1388 |
$sql = '';
|
|
indvdum@0
|
1389 |
|
|
indvdum@0
|
1390 |
switch ($mode)
|
|
indvdum@0
|
1391 |
{
|
|
indvdum@0
|
1392 |
case 'reply':
|
|
indvdum@0
|
1393 |
case 'quote':
|
|
indvdum@0
|
1394 |
$root_level = ($data['reply_from_root_level']) ? $data['reply_from_root_level'] : $data['reply_from_msg_id'];
|
|
indvdum@0
|
1395 |
|
|
indvdum@0
|
1396 |
// Set message_replied switch for this user
|
|
indvdum@0
|
1397 |
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
|
|
indvdum@0
|
1398 |
SET pm_replied = 1
|
|
indvdum@0
|
1399 |
WHERE user_id = ' . $data['from_user_id'] . '
|
|
indvdum@0
|
1400 |
AND msg_id = ' . $data['reply_from_msg_id'];
|
|
indvdum@0
|
1401 |
|
|
indvdum@0
|
1402 |
// no break
|
|
indvdum@0
|
1403 |
|
|
indvdum@0
|
1404 |
case 'forward':
|
|
indvdum@0
|
1405 |
case 'post':
|
|
indvdum@0
|
1406 |
case 'quotepost':
|
|
indvdum@0
|
1407 |
$sql_data = array(
|
|
indvdum@0
|
1408 |
'root_level' => $root_level,
|
|
indvdum@0
|
1409 |
'author_id' => $data['from_user_id'],
|
|
indvdum@0
|
1410 |
'icon_id' => $data['icon_id'],
|
|
indvdum@0
|
1411 |
'author_ip' => $data['from_user_ip'],
|
|
indvdum@0
|
1412 |
'message_time' => $current_time,
|
|
indvdum@0
|
1413 |
'enable_bbcode' => $data['enable_bbcode'],
|
|
indvdum@0
|
1414 |
'enable_smilies' => $data['enable_smilies'],
|
|
indvdum@0
|
1415 |
'enable_magic_url' => $data['enable_urls'],
|
|
indvdum@0
|
1416 |
'enable_sig' => $data['enable_sig'],
|
|
indvdum@0
|
1417 |
'message_subject' => $subject,
|
|
indvdum@0
|
1418 |
'message_text' => $data['message'],
|
|
indvdum@0
|
1419 |
'message_attachment'=> (!empty($data['attachment_data'])) ? 1 : 0,
|
|
indvdum@0
|
1420 |
'bbcode_bitfield' => $data['bbcode_bitfield'],
|
|
indvdum@0
|
1421 |
'bbcode_uid' => $data['bbcode_uid'],
|
|
indvdum@0
|
1422 |
'to_address' => implode(':', $to),
|
|
indvdum@0
|
1423 |
'bcc_address' => implode(':', $bcc),
|
|
indvdum@0
|
1424 |
'message_reported' => 0,
|
|
indvdum@0
|
1425 |
);
|
|
indvdum@0
|
1426 |
break;
|
|
indvdum@0
|
1427 |
|
|
indvdum@0
|
1428 |
case 'edit':
|
|
indvdum@0
|
1429 |
$sql_data = array(
|
|
indvdum@0
|
1430 |
'icon_id' => $data['icon_id'],
|
|
indvdum@0
|
1431 |
'message_edit_time' => $current_time,
|
|
indvdum@0
|
1432 |
'enable_bbcode' => $data['enable_bbcode'],
|
|
indvdum@0
|
1433 |
'enable_smilies' => $data['enable_smilies'],
|
|
indvdum@0
|
1434 |
'enable_magic_url' => $data['enable_urls'],
|
|
indvdum@0
|
1435 |
'enable_sig' => $data['enable_sig'],
|
|
indvdum@0
|
1436 |
'message_subject' => $subject,
|
|
indvdum@0
|
1437 |
'message_text' => $data['message'],
|
|
indvdum@0
|
1438 |
'message_attachment'=> (!empty($data['attachment_data'])) ? 1 : 0,
|
|
indvdum@0
|
1439 |
'bbcode_bitfield' => $data['bbcode_bitfield'],
|
|
indvdum@0
|
1440 |
'bbcode_uid' => $data['bbcode_uid']
|
|
indvdum@0
|
1441 |
);
|
|
indvdum@0
|
1442 |
break;
|
|
indvdum@0
|
1443 |
}
|
|
indvdum@0
|
1444 |
|
|
indvdum@0
|
1445 |
if (sizeof($sql_data))
|
|
indvdum@0
|
1446 |
{
|
|
indvdum@0
|
1447 |
$query = '';
|
|
indvdum@0
|
1448 |
|
|
indvdum@0
|
1449 |
if ($mode == 'post' || $mode == 'reply' || $mode == 'quote' || $mode == 'quotepost' || $mode == 'forward')
|
|
indvdum@0
|
1450 |
{
|
|
indvdum@0
|
1451 |
$db->sql_query('INSERT INTO ' . PRIVMSGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data));
|
|
indvdum@0
|
1452 |
$data['msg_id'] = $db->sql_nextid();
|
|
indvdum@0
|
1453 |
}
|
|
indvdum@0
|
1454 |
else if ($mode == 'edit')
|
|
indvdum@0
|
1455 |
{
|
|
indvdum@0
|
1456 |
$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
|
|
indvdum@0
|
1457 |
SET message_edit_count = message_edit_count + 1, ' . $db->sql_build_array('UPDATE', $sql_data) . '
|
|
indvdum@0
|
1458 |
WHERE msg_id = ' . $data['msg_id'];
|
|
indvdum@0
|
1459 |
$db->sql_query($sql);
|
|
indvdum@0
|
1460 |
}
|
|
indvdum@0
|
1461 |
}
|
|
indvdum@0
|
1462 |
|
|
indvdum@0
|
1463 |
if ($mode != 'edit')
|
|
indvdum@0
|
1464 |
{
|
|
indvdum@0
|
1465 |
if ($sql)
|
|
indvdum@0
|
1466 |
{
|
|
indvdum@0
|
1467 |
$db->sql_query($sql);
|
|
indvdum@0
|
1468 |
}
|
|
indvdum@0
|
1469 |
unset($sql);
|
|
indvdum@0
|
1470 |
|
|
indvdum@0
|
1471 |
$sql_ary = array();
|
|
indvdum@0
|
1472 |
foreach ($recipients as $user_id => $type)
|
|
indvdum@0
|
1473 |
{
|
|
indvdum@0
|
1474 |
$sql_ary[] = array(
|
|
indvdum@0
|
1475 |
'msg_id' => (int) $data['msg_id'],
|
|
indvdum@0
|
1476 |
'user_id' => (int) $user_id,
|
|
indvdum@0
|
1477 |
'author_id' => (int) $data['from_user_id'],
|
|
indvdum@0
|
1478 |
'folder_id' => PRIVMSGS_NO_BOX,
|
|
indvdum@0
|
1479 |
'pm_new' => 1,
|
|
indvdum@0
|
1480 |
'pm_unread' => 1,
|
|
indvdum@0
|
1481 |
'pm_forwarded' => ($mode == 'forward') ? 1 : 0
|
|
indvdum@0
|
1482 |
);
|
|
indvdum@0
|
1483 |
}
|
|
indvdum@0
|
1484 |
|
|
indvdum@0
|
1485 |
$db->sql_multi_insert(PRIVMSGS_TO_TABLE, $sql_ary);
|
|
indvdum@0
|
1486 |
|
|
indvdum@0
|
1487 |
$sql = 'UPDATE ' . USERS_TABLE . '
|
|
indvdum@0
|
1488 |
SET user_new_privmsg = user_new_privmsg + 1, user_unread_privmsg = user_unread_privmsg + 1, user_last_privmsg = ' . time() . '
|
|
indvdum@0
|
1489 |
WHERE ' . $db->sql_in_set('user_id', array_keys($recipients));
|
|
indvdum@0
|
1490 |
$db->sql_query($sql);
|
|
indvdum@0
|
1491 |
|
|
indvdum@0
|
1492 |
// Put PM into outbox
|
|
indvdum@0
|
1493 |
if ($put_in_outbox)
|
|
indvdum@0
|
1494 |
{
|
|
indvdum@0
|
1495 |
$db->sql_query('INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', array(
|
|
indvdum@0
|
1496 |
'msg_id' => (int) $data['msg_id'],
|
|
indvdum@0
|
1497 |
'user_id' => (int) $data['from_user_id'],
|
|
indvdum@0
|
1498 |
'author_id' => (int) $data['from_user_id'],
|
|
indvdum@0
|
1499 |
'folder_id' => PRIVMSGS_OUTBOX,
|
|
indvdum@0
|
1500 |
'pm_new' => 0,
|
|
indvdum@0
|
1501 |
'pm_unread' => 0,
|
|
indvdum@0
|
1502 |
'pm_forwarded' => ($mode == 'forward') ? 1 : 0))
|
|
indvdum@0
|
1503 |
);
|
|
indvdum@0
|
1504 |
}
|
|
indvdum@0
|
1505 |
}
|
|
indvdum@0
|
1506 |
|
|
indvdum@0
|
1507 |
// Set user last post time
|
|
indvdum@0
|
1508 |
if ($mode == 'reply' || $mode == 'quote' || $mode == 'quotepost' || $mode == 'forward' || $mode == 'post')
|
|
indvdum@0
|
1509 |
{
|
|
indvdum@0
|
1510 |
$sql = 'UPDATE ' . USERS_TABLE . "
|
|
indvdum@0
|
1511 |
SET user_lastpost_time = $current_time
|
|
indvdum@0
|
1512 |
WHERE user_id = " . $data['from_user_id'];
|
|
indvdum@0
|
1513 |
$db->sql_query($sql);
|
|
indvdum@0
|
1514 |
}
|
|
indvdum@0
|
1515 |
|
|
indvdum@0
|
1516 |
// Submit Attachments
|
|
indvdum@0
|
1517 |
if (!empty($data['attachment_data']) && $data['msg_id'] && in_array($mode, array('post', 'reply', 'quote', 'quotepost', 'edit', 'forward')))
|
|
indvdum@0
|
1518 |
{
|
|
indvdum@0
|
1519 |
$space_taken = $files_added = 0;
|
|
indvdum@0
|
1520 |
$orphan_rows = array();
|
|
indvdum@0
|
1521 |
|
|
indvdum@0
|
1522 |
foreach ($data['attachment_data'] as $pos => $attach_row)
|
|
indvdum@0
|
1523 |
{
|
|
indvdum@0
|
1524 |
$orphan_rows[(int) $attach_row['attach_id']] = array();
|
|
indvdum@0
|
1525 |
}
|
|
indvdum@0
|
1526 |
|
|
indvdum@0
|
1527 |
if (sizeof($orphan_rows))
|
|
indvdum@0
|
1528 |
{
|
|
indvdum@0
|
1529 |
$sql = 'SELECT attach_id, filesize, physical_filename
|
|
indvdum@0
|
1530 |
FROM ' . ATTACHMENTS_TABLE . '
|
|
indvdum@0
|
1531 |
WHERE ' . $db->sql_in_set('attach_id', array_keys($orphan_rows)) . '
|
|
indvdum@0
|
1532 |
AND in_message = 1
|
|
indvdum@0
|
1533 |
AND is_orphan = 1
|
|
indvdum@0
|
1534 |
AND poster_id = ' . $user->data['user_id'];
|
|
indvdum@0
|
1535 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1536 |
|
|
indvdum@0
|
1537 |
$orphan_rows = array();
|
|
indvdum@0
|
1538 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1539 |
{
|
|
indvdum@0
|
1540 |
$orphan_rows[$row['attach_id']] = $row;
|
|
indvdum@0
|
1541 |
}
|
|
indvdum@0
|
1542 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1543 |
}
|
|
indvdum@0
|
1544 |
|
|
indvdum@0
|
1545 |
foreach ($data['attachment_data'] as $pos => $attach_row)
|
|
indvdum@0
|
1546 |
{
|
|
indvdum@0
|
1547 |
if ($attach_row['is_orphan'] && !isset($orphan_rows[$attach_row['attach_id']]))
|
|
indvdum@0
|
1548 |
{
|
|
indvdum@0
|
1549 |
continue;
|
|
indvdum@0
|
1550 |
}
|
|
indvdum@0
|
1551 |
|
|
indvdum@0
|
1552 |
if (!$attach_row['is_orphan'])
|
|
indvdum@0
|
1553 |
{
|
|
indvdum@0
|
1554 |
// update entry in db if attachment already stored in db and filespace
|
|
indvdum@0
|
1555 |
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
|
|
indvdum@0
|
1556 |
SET attach_comment = '" . $db->sql_escape($attach_row['attach_comment']) . "'
|
|
indvdum@0
|
1557 |
WHERE attach_id = " . (int) $attach_row['attach_id'] . '
|
|
indvdum@0
|
1558 |
AND is_orphan = 0';
|
|
indvdum@0
|
1559 |
$db->sql_query($sql);
|
|
indvdum@0
|
1560 |
}
|
|
indvdum@0
|
1561 |
else
|
|
indvdum@0
|
1562 |
{
|
|
indvdum@0
|
1563 |
// insert attachment into db
|
|
indvdum@0
|
1564 |
if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
|
|
indvdum@0
|
1565 |
{
|
|
indvdum@0
|
1566 |
continue;
|
|
indvdum@0
|
1567 |
}
|
|
indvdum@0
|
1568 |
|
|
indvdum@0
|
1569 |
$space_taken += $orphan_rows[$attach_row['attach_id']]['filesize'];
|
|
indvdum@0
|
1570 |
$files_added++;
|
|
indvdum@0
|
1571 |
|
|
indvdum@0
|
1572 |
$attach_sql = array(
|
|
indvdum@0
|
1573 |
'post_msg_id' => $data['msg_id'],
|
|
indvdum@0
|
1574 |
'topic_id' => 0,
|
|
indvdum@0
|
1575 |
'is_orphan' => 0,
|
|
indvdum@0
|
1576 |
'poster_id' => $data['from_user_id'],
|
|
indvdum@0
|
1577 |
'attach_comment' => $attach_row['attach_comment'],
|
|
indvdum@0
|
1578 |
);
|
|
indvdum@0
|
1579 |
|
|
indvdum@0
|
1580 |
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $attach_sql) . '
|
|
indvdum@0
|
1581 |
WHERE attach_id = ' . $attach_row['attach_id'] . '
|
|
indvdum@0
|
1582 |
AND is_orphan = 1
|
|
indvdum@0
|
1583 |
AND poster_id = ' . $user->data['user_id'];
|
|
indvdum@0
|
1584 |
$db->sql_query($sql);
|
|
indvdum@0
|
1585 |
}
|
|
indvdum@0
|
1586 |
}
|
|
indvdum@0
|
1587 |
|
|
indvdum@0
|
1588 |
if ($space_taken && $files_added)
|
|
indvdum@0
|
1589 |
{
|
|
indvdum@0
|
1590 |
set_config_count('upload_dir_size', $space_taken, true);
|
|
indvdum@0
|
1591 |
set_config_count('num_files', $files_added, true);
|
|
indvdum@0
|
1592 |
}
|
|
indvdum@0
|
1593 |
}
|
|
indvdum@0
|
1594 |
|
|
indvdum@0
|
1595 |
// Delete draft if post was loaded...
|
|
indvdum@0
|
1596 |
$draft_id = request_var('draft_loaded', 0);
|
|
indvdum@0
|
1597 |
if ($draft_id)
|
|
indvdum@0
|
1598 |
{
|
|
indvdum@0
|
1599 |
$sql = 'DELETE FROM ' . DRAFTS_TABLE . "
|
|
indvdum@0
|
1600 |
WHERE draft_id = $draft_id
|
|
indvdum@0
|
1601 |
AND user_id = " . $data['from_user_id'];
|
|
indvdum@0
|
1602 |
$db->sql_query($sql);
|
|
indvdum@0
|
1603 |
}
|
|
indvdum@0
|
1604 |
|
|
indvdum@0
|
1605 |
$db->sql_transaction('commit');
|
|
indvdum@0
|
1606 |
|
|
indvdum@0
|
1607 |
// Send Notifications
|
|
indvdum@0
|
1608 |
if ($mode != 'edit')
|
|
indvdum@0
|
1609 |
{
|
|
indvdum@0
|
1610 |
pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message'], $data['msg_id']);
|
|
indvdum@0
|
1611 |
}
|
|
indvdum@0
|
1612 |
|
|
indvdum@0
|
1613 |
return $data['msg_id'];
|
|
indvdum@0
|
1614 |
}
|
|
indvdum@0
|
1615 |
|
|
indvdum@0
|
1616 |
/**
|
|
indvdum@0
|
1617 |
* PM Notification
|
|
indvdum@0
|
1618 |
*/
|
|
indvdum@0
|
1619 |
function pm_notification($mode, $author, $recipients, $subject, $message, $msg_id)
|
|
indvdum@0
|
1620 |
{
|
|
indvdum@0
|
1621 |
global $db, $user, $config, $phpbb_root_path, $phpEx, $auth;
|
|
indvdum@0
|
1622 |
|
|
indvdum@0
|
1623 |
$subject = censor_text($subject);
|
|
indvdum@0
|
1624 |
|
|
indvdum@0
|
1625 |
unset($recipients[ANONYMOUS], $recipients[$user->data['user_id']]);
|
|
indvdum@0
|
1626 |
|
|
indvdum@0
|
1627 |
if (!sizeof($recipients))
|
|
indvdum@0
|
1628 |
{
|
|
indvdum@0
|
1629 |
return;
|
|
indvdum@0
|
1630 |
}
|
|
indvdum@0
|
1631 |
|
|
indvdum@0
|
1632 |
// Get banned User ID's
|
|
indvdum@0
|
1633 |
$sql = 'SELECT ban_userid
|
|
indvdum@0
|
1634 |
FROM ' . BANLIST_TABLE . '
|
|
indvdum@0
|
1635 |
WHERE ' . $db->sql_in_set('ban_userid', array_map('intval', array_keys($recipients))) . '
|
|
indvdum@0
|
1636 |
AND ban_exclude = 0';
|
|
indvdum@0
|
1637 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1638 |
|
|
indvdum@0
|
1639 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1640 |
{
|
|
indvdum@0
|
1641 |
unset($recipients[$row['ban_userid']]);
|
|
indvdum@0
|
1642 |
}
|
|
indvdum@0
|
1643 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1644 |
|
|
indvdum@0
|
1645 |
if (!sizeof($recipients))
|
|
indvdum@0
|
1646 |
{
|
|
indvdum@0
|
1647 |
return;
|
|
indvdum@0
|
1648 |
}
|
|
indvdum@0
|
1649 |
|
|
indvdum@0
|
1650 |
$sql = 'SELECT user_id, username, user_email, user_lang, user_notify_pm, user_notify_type, user_jabber
|
|
indvdum@0
|
1651 |
FROM ' . USERS_TABLE . '
|
|
indvdum@0
|
1652 |
WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($recipients)));
|
|
indvdum@0
|
1653 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1654 |
|
|
indvdum@0
|
1655 |
$msg_list_ary = array();
|
|
indvdum@0
|
1656 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1657 |
{
|
|
indvdum@0
|
1658 |
if ($row['user_notify_pm'] == 1 && trim($row['user_email']))
|
|
indvdum@0
|
1659 |
{
|
|
indvdum@0
|
1660 |
$msg_list_ary[] = array(
|
|
indvdum@0
|
1661 |
'method' => $row['user_notify_type'],
|
|
indvdum@0
|
1662 |
'email' => $row['user_email'],
|
|
indvdum@0
|
1663 |
'jabber' => $row['user_jabber'],
|
|
indvdum@0
|
1664 |
'name' => $row['username'],
|
|
indvdum@0
|
1665 |
'lang' => $row['user_lang']
|
|
indvdum@0
|
1666 |
);
|
|
indvdum@0
|
1667 |
}
|
|
indvdum@0
|
1668 |
}
|
|
indvdum@0
|
1669 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1670 |
|
|
indvdum@0
|
1671 |
if (!sizeof($msg_list_ary))
|
|
indvdum@0
|
1672 |
{
|
|
indvdum@0
|
1673 |
return;
|
|
indvdum@0
|
1674 |
}
|
|
indvdum@0
|
1675 |
|
|
indvdum@0
|
1676 |
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
|
indvdum@0
|
1677 |
$messenger = new messenger();
|
|
indvdum@0
|
1678 |
|
|
indvdum@0
|
1679 |
foreach ($msg_list_ary as $pos => $addr)
|
|
indvdum@0
|
1680 |
{
|
|
indvdum@0
|
1681 |
$messenger->template('privmsg_notify', $addr['lang']);
|
|
indvdum@0
|
1682 |
|
|
indvdum@0
|
1683 |
$messenger->to($addr['email'], $addr['name']);
|
|
indvdum@0
|
1684 |
$messenger->im($addr['jabber'], $addr['name']);
|
|
indvdum@0
|
1685 |
|
|
indvdum@0
|
1686 |
$messenger->assign_vars(array(
|
|
indvdum@0
|
1687 |
'SUBJECT' => htmlspecialchars_decode($subject),
|
|
indvdum@0
|
1688 |
'AUTHOR_NAME' => htmlspecialchars_decode($author),
|
|
indvdum@0
|
1689 |
'USERNAME' => htmlspecialchars_decode($addr['name']),
|
|
indvdum@0
|
1690 |
|
|
indvdum@0
|
1691 |
'U_INBOX' => generate_board_url() . "/ucp.$phpEx?i=pm&folder=inbox",
|
|
indvdum@0
|
1692 |
'U_VIEW_MESSAGE' => generate_board_url() . "/ucp.$phpEx?i=pm&mode=view&p=$msg_id",
|
|
indvdum@0
|
1693 |
));
|
|
indvdum@0
|
1694 |
|
|
indvdum@0
|
1695 |
$messenger->send($addr['method']);
|
|
indvdum@0
|
1696 |
}
|
|
indvdum@0
|
1697 |
unset($msg_list_ary);
|
|
indvdum@0
|
1698 |
|
|
indvdum@0
|
1699 |
$messenger->save_queue();
|
|
indvdum@0
|
1700 |
|
|
indvdum@0
|
1701 |
unset($messenger);
|
|
indvdum@0
|
1702 |
}
|
|
indvdum@0
|
1703 |
|
|
indvdum@0
|
1704 |
/**
|
|
indvdum@0
|
1705 |
* Display Message History
|
|
indvdum@0
|
1706 |
*/
|
|
indvdum@0
|
1707 |
function message_history($msg_id, $user_id, $message_row, $folder, $in_post_mode = false)
|
|
indvdum@0
|
1708 |
{
|
|
indvdum@0
|
1709 |
global $db, $user, $config, $template, $phpbb_root_path, $phpEx, $auth, $bbcode;
|
|
indvdum@0
|
1710 |
|
|
indvdum@0
|
1711 |
// Select all receipts and the author from the pm we currently view, to only display their pm-history
|
|
indvdum@0
|
1712 |
$sql = 'SELECT author_id, user_id
|
|
indvdum@0
|
1713 |
FROM ' . PRIVMSGS_TO_TABLE . "
|
|
indvdum@0
|
1714 |
WHERE msg_id = $msg_id
|
|
indvdum@0
|
1715 |
AND folder_id <> " . PRIVMSGS_HOLD_BOX;
|
|
indvdum@0
|
1716 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1717 |
|
|
indvdum@0
|
1718 |
$recipients = array();
|
|
indvdum@0
|
1719 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1720 |
{
|
|
indvdum@0
|
1721 |
$recipients[] = (int) $row['user_id'];
|
|
indvdum@0
|
1722 |
$recipients[] = (int) $row['author_id'];
|
|
indvdum@0
|
1723 |
}
|
|
indvdum@0
|
1724 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1725 |
$recipients = array_unique($recipients);
|
|
indvdum@0
|
1726 |
|
|
indvdum@0
|
1727 |
// Get History Messages (could be newer)
|
|
indvdum@0
|
1728 |
$sql = 'SELECT t.*, p.*, u.*
|
|
indvdum@0
|
1729 |
FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . ' t, ' . USERS_TABLE . ' u
|
|
indvdum@0
|
1730 |
WHERE t.msg_id = p.msg_id
|
|
indvdum@0
|
1731 |
AND p.author_id = u.user_id
|
|
indvdum@0
|
1732 |
AND t.folder_id NOT IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ')
|
|
indvdum@0
|
1733 |
AND ' . $db->sql_in_set('t.author_id', $recipients, false, true) . "
|
|
indvdum@0
|
1734 |
AND t.user_id = $user_id";
|
|
indvdum@0
|
1735 |
|
|
indvdum@0
|
1736 |
// We no longer need those.
|
|
indvdum@0
|
1737 |
unset($recipients);
|
|
indvdum@0
|
1738 |
|
|
indvdum@0
|
1739 |
if (!$message_row['root_level'])
|
|
indvdum@0
|
1740 |
{
|
|
indvdum@0
|
1741 |
$sql .= " AND (p.root_level = $msg_id OR (p.root_level = 0 AND p.msg_id = $msg_id))";
|
|
indvdum@0
|
1742 |
}
|
|
indvdum@0
|
1743 |
else
|
|
indvdum@0
|
1744 |
{
|
|
indvdum@0
|
1745 |
$sql .= " AND (p.root_level = " . $message_row['root_level'] . ' OR p.msg_id = ' . $message_row['root_level'] . ')';
|
|
indvdum@0
|
1746 |
}
|
|
indvdum@0
|
1747 |
$sql .= ' ORDER BY p.message_time DESC';
|
|
indvdum@0
|
1748 |
|
|
indvdum@0
|
1749 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1750 |
$row = $db->sql_fetchrow($result);
|
|
indvdum@0
|
1751 |
|
|
indvdum@0
|
1752 |
if (!$row)
|
|
indvdum@0
|
1753 |
{
|
|
indvdum@0
|
1754 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1755 |
return false;
|
|
indvdum@0
|
1756 |
}
|
|
indvdum@0
|
1757 |
|
|
indvdum@0
|
1758 |
$title = $row['message_subject'];
|
|
indvdum@0
|
1759 |
|
|
indvdum@0
|
1760 |
$rowset = array();
|
|
indvdum@0
|
1761 |
$bbcode_bitfield = '';
|
|
indvdum@0
|
1762 |
$folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm') . '&folder=';
|
|
indvdum@0
|
1763 |
|
|
indvdum@0
|
1764 |
do
|
|
indvdum@0
|
1765 |
{
|
|
indvdum@0
|
1766 |
$folder_id = (int) $row['folder_id'];
|
|
indvdum@0
|
1767 |
|
|
indvdum@0
|
1768 |
$row['folder'][] = (isset($folder[$folder_id])) ? '<a href="' . $folder_url . $folder_id . '">' . $folder[$folder_id]['folder_name'] . '</a>' : $user->lang['UNKNOWN_FOLDER'];
|
|
indvdum@0
|
1769 |
|
|
indvdum@0
|
1770 |
if (isset($rowset[$row['msg_id']]))
|
|
indvdum@0
|
1771 |
{
|
|
indvdum@0
|
1772 |
$rowset[$row['msg_id']]['folder'][] = (isset($folder[$folder_id])) ? '<a href="' . $folder_url . $folder_id . '">' . $folder[$folder_id]['folder_name'] . '</a>' : $user->lang['UNKNOWN_FOLDER'];
|
|
indvdum@0
|
1773 |
}
|
|
indvdum@0
|
1774 |
else
|
|
indvdum@0
|
1775 |
{
|
|
indvdum@0
|
1776 |
$rowset[$row['msg_id']] = $row;
|
|
indvdum@0
|
1777 |
$bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
|
|
indvdum@0
|
1778 |
}
|
|
indvdum@0
|
1779 |
}
|
|
indvdum@0
|
1780 |
while ($row = $db->sql_fetchrow($result));
|
|
indvdum@0
|
1781 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1782 |
|
|
indvdum@0
|
1783 |
if (sizeof($rowset) == 1 && !$in_post_mode)
|
|
indvdum@0
|
1784 |
{
|
|
indvdum@0
|
1785 |
return false;
|
|
indvdum@0
|
1786 |
}
|
|
indvdum@0
|
1787 |
|
|
indvdum@0
|
1788 |
// Instantiate BBCode class
|
|
indvdum@0
|
1789 |
if ((empty($bbcode) || $bbcode === false) && $bbcode_bitfield !== '')
|
|
indvdum@0
|
1790 |
{
|
|
indvdum@0
|
1791 |
if (!class_exists('bbcode'))
|
|
indvdum@0
|
1792 |
{
|
|
indvdum@0
|
1793 |
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
|
|
indvdum@0
|
1794 |
}
|
|
indvdum@0
|
1795 |
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
|
|
indvdum@0
|
1796 |
}
|
|
indvdum@0
|
1797 |
|
|
indvdum@0
|
1798 |
$title = censor_text($title);
|
|
indvdum@0
|
1799 |
|
|
indvdum@0
|
1800 |
$url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm');
|
|
indvdum@0
|
1801 |
$next_history_pm = $previous_history_pm = $prev_id = 0;
|
|
indvdum@0
|
1802 |
|
|
indvdum@0
|
1803 |
// Re-order rowset to be able to get the next/prev message rows...
|
|
indvdum@0
|
1804 |
$rowset = array_values($rowset);
|
|
indvdum@0
|
1805 |
|
|
indvdum@0
|
1806 |
for ($i = 0, $size = sizeof($rowset); $i < $size; $i++)
|
|
indvdum@0
|
1807 |
{
|
|
indvdum@0
|
1808 |
$row = &$rowset[$i];
|
|
indvdum@0
|
1809 |
$id = (int) $row['msg_id'];
|
|
indvdum@0
|
1810 |
|
|
indvdum@0
|
1811 |
$author_id = $row['author_id'];
|
|
indvdum@0
|
1812 |
$folder_id = (int) $row['folder_id'];
|
|
indvdum@0
|
1813 |
|
|
indvdum@0
|
1814 |
$subject = $row['message_subject'];
|
|
indvdum@0
|
1815 |
$message = $row['message_text'];
|
|
indvdum@0
|
1816 |
|
|
indvdum@0
|
1817 |
$message = censor_text($message);
|
|
indvdum@0
|
1818 |
|
|
indvdum@0
|
1819 |
$decoded_message = false;
|
|
indvdum@0
|
1820 |
|
|
indvdum@0
|
1821 |
if ($in_post_mode && $auth->acl_get('u_sendpm') && $author_id != ANONYMOUS)
|
|
indvdum@0
|
1822 |
{
|
|
indvdum@0
|
1823 |
$decoded_message = $message;
|
|
indvdum@0
|
1824 |
decode_message($decoded_message, $row['bbcode_uid']);
|
|
indvdum@0
|
1825 |
|
|
indvdum@0
|
1826 |
$decoded_message = bbcode_nl2br($decoded_message);
|
|
indvdum@0
|
1827 |
}
|
|
indvdum@0
|
1828 |
|
|
indvdum@0
|
1829 |
if ($row['bbcode_bitfield'])
|
|
indvdum@0
|
1830 |
{
|
|
indvdum@0
|
1831 |
$bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
|
|
indvdum@0
|
1832 |
}
|
|
indvdum@0
|
1833 |
|
|
indvdum@0
|
1834 |
$message = bbcode_nl2br($message);
|
|
indvdum@0
|
1835 |
$message = smiley_text($message, !$row['enable_smilies']);
|
|
indvdum@0
|
1836 |
|
|
indvdum@0
|
1837 |
$subject = censor_text($subject);
|
|
indvdum@0
|
1838 |
|
|
indvdum@0
|
1839 |
if ($id == $msg_id)
|
|
indvdum@0
|
1840 |
{
|
|
indvdum@0
|
1841 |
$next_history_pm = (isset($rowset[$i + 1])) ? (int) $rowset[$i + 1]['msg_id'] : 0;
|
|
indvdum@0
|
1842 |
$previous_history_pm = $prev_id;
|
|
indvdum@0
|
1843 |
}
|
|
indvdum@0
|
1844 |
|
|
indvdum@0
|
1845 |
$template->assign_block_vars('history_row', array(
|
|
indvdum@0
|
1846 |
'MESSAGE_AUTHOR_QUOTE' => (($decoded_message) ? addslashes(get_username_string('username', $author_id, $row['username'], $row['user_colour'], $row['username'])) : ''),
|
|
indvdum@0
|
1847 |
'MESSAGE_AUTHOR_FULL' => get_username_string('full', $author_id, $row['username'], $row['user_colour'], $row['username']),
|
|
indvdum@0
|
1848 |
'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $author_id, $row['username'], $row['user_colour'], $row['username']),
|
|
indvdum@0
|
1849 |
'MESSAGE_AUTHOR' => get_username_string('username', $author_id, $row['username'], $row['user_colour'], $row['username']),
|
|
indvdum@0
|
1850 |
'U_MESSAGE_AUTHOR' => get_username_string('profile', $author_id, $row['username'], $row['user_colour'], $row['username']),
|
|
indvdum@0
|
1851 |
|
|
indvdum@0
|
1852 |
'SUBJECT' => $subject,
|
|
indvdum@0
|
1853 |
'SENT_DATE' => $user->format_date($row['message_time']),
|
|
indvdum@0
|
1854 |
'MESSAGE' => $message,
|
|
indvdum@0
|
1855 |
'FOLDER' => implode(', ', $row['folder']),
|
|
indvdum@0
|
1856 |
'DECODED_MESSAGE' => $decoded_message,
|
|
indvdum@0
|
1857 |
|
|
indvdum@0
|
1858 |
'S_CURRENT_MSG' => ($row['msg_id'] == $msg_id),
|
|
indvdum@0
|
1859 |
'S_AUTHOR_DELETED' => ($author_id == ANONYMOUS) ? true : false,
|
|
indvdum@0
|
1860 |
'S_IN_POST_MODE' => $in_post_mode,
|
|
indvdum@0
|
1861 |
|
|
indvdum@0
|
1862 |
'MSG_ID' => $row['msg_id'],
|
|
indvdum@0
|
1863 |
'U_VIEW_MESSAGE' => "$url&f=$folder_id&p=" . $row['msg_id'],
|
|
indvdum@0
|
1864 |
'U_QUOTE' => (!$in_post_mode && $auth->acl_get('u_sendpm') && $author_id != ANONYMOUS) ? "$url&mode=compose&action=quote&f=" . $folder_id . "&p=" . $row['msg_id'] : '',
|
|
indvdum@0
|
1865 |
'U_POST_REPLY_PM' => ($author_id != $user->data['user_id'] && $author_id != ANONYMOUS && $auth->acl_get('u_sendpm')) ? "$url&mode=compose&action=reply&f=$folder_id&p=" . $row['msg_id'] : '')
|
|
indvdum@0
|
1866 |
);
|
|
indvdum@0
|
1867 |
unset($rowset[$i]);
|
|
indvdum@0
|
1868 |
$prev_id = $id;
|
|
indvdum@0
|
1869 |
}
|
|
indvdum@0
|
1870 |
|
|
indvdum@0
|
1871 |
$template->assign_vars(array(
|
|
indvdum@0
|
1872 |
'QUOTE_IMG' => $user->img('icon_post_quote', $user->lang['REPLY_WITH_QUOTE']),
|
|
indvdum@0
|
1873 |
'HISTORY_TITLE' => $title,
|
|
indvdum@0
|
1874 |
|
|
indvdum@0
|
1875 |
'U_VIEW_NEXT_HISTORY' => ($next_history_pm) ? "$url&p=" . $next_history_pm : '',
|
|
indvdum@0
|
1876 |
'U_VIEW_PREVIOUS_HISTORY' => ($previous_history_pm) ? "$url&p=" . $previous_history_pm : '',
|
|
indvdum@0
|
1877 |
));
|
|
indvdum@0
|
1878 |
|
|
indvdum@0
|
1879 |
return true;
|
|
indvdum@0
|
1880 |
}
|
|
indvdum@0
|
1881 |
|
|
indvdum@0
|
1882 |
/**
|
|
indvdum@0
|
1883 |
* Set correct users max messages in PM folder.
|
|
indvdum@0
|
1884 |
* If several group memberships define different amount of messages, the highest will be chosen.
|
|
indvdum@0
|
1885 |
*/
|
|
indvdum@0
|
1886 |
function set_user_message_limit()
|
|
indvdum@0
|
1887 |
{
|
|
indvdum@0
|
1888 |
global $user, $db, $config;
|
|
indvdum@0
|
1889 |
|
|
indvdum@0
|
1890 |
// Get maximum about from user memberships - if it is 0, there is no limit set and we use the maximum value within the config.
|
|
indvdum@0
|
1891 |
$sql = 'SELECT MAX(g.group_message_limit) as max_message_limit
|
|
indvdum@0
|
1892 |
FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
|
|
indvdum@0
|
1893 |
WHERE ug.user_id = ' . $user->data['user_id'] . '
|
|
indvdum@0
|
1894 |
AND ug.user_pending = 0
|
|
indvdum@0
|
1895 |
AND ug.group_id = g.group_id';
|
|
indvdum@0
|
1896 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1897 |
$message_limit = (int) $db->sql_fetchfield('max_message_limit');
|
|
indvdum@0
|
1898 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1899 |
|
|
indvdum@0
|
1900 |
$user->data['message_limit'] = (!$message_limit) ? $config['pm_max_msgs'] : $message_limit;
|
|
indvdum@0
|
1901 |
}
|
|
indvdum@0
|
1902 |
|
|
indvdum@0
|
1903 |
/**
|
|
indvdum@0
|
1904 |
* Generates an array of coloured recipient names from a list of PMs - (groups & users)
|
|
indvdum@0
|
1905 |
*
|
|
indvdum@0
|
1906 |
* @param array $pm_by_id An array of rows from PRIVMSGS_TABLE, keys are the msg_ids.
|
|
indvdum@0
|
1907 |
*
|
|
indvdum@0
|
1908 |
* @return array 2D Array: array(msg_id => array('username or group string', ...), ...)
|
|
indvdum@0
|
1909 |
* Usernames are generated with {@link get_username_string get_username_string}
|
|
indvdum@0
|
1910 |
* Groups are coloured and have a link to the membership page
|
|
indvdum@0
|
1911 |
*/
|
|
indvdum@0
|
1912 |
function get_recipient_strings($pm_by_id)
|
|
indvdum@0
|
1913 |
{
|
|
indvdum@0
|
1914 |
global $db, $phpbb_root_path, $phpEx, $user;
|
|
indvdum@0
|
1915 |
|
|
indvdum@0
|
1916 |
$address_list = $recipient_list = $address = array();
|
|
indvdum@0
|
1917 |
|
|
indvdum@0
|
1918 |
$_types = array('u', 'g');
|
|
indvdum@0
|
1919 |
|
|
indvdum@0
|
1920 |
foreach ($pm_by_id as $message_id => $row)
|
|
indvdum@0
|
1921 |
{
|
|
indvdum@0
|
1922 |
$address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
|
|
indvdum@0
|
1923 |
|
|
indvdum@0
|
1924 |
foreach ($_types as $ug_type)
|
|
indvdum@0
|
1925 |
{
|
|
indvdum@0
|
1926 |
if (isset($address[$message_id][$ug_type]) && sizeof($address[$message_id][$ug_type]))
|
|
indvdum@0
|
1927 |
{
|
|
indvdum@0
|
1928 |
foreach ($address[$message_id][$ug_type] as $ug_id => $in_to)
|
|
indvdum@0
|
1929 |
{
|
|
indvdum@0
|
1930 |
$recipient_list[$ug_type][$ug_id] = array('name' => $user->lang['NA'], 'colour' => '');
|
|
indvdum@0
|
1931 |
}
|
|
indvdum@0
|
1932 |
}
|
|
indvdum@0
|
1933 |
}
|
|
indvdum@0
|
1934 |
}
|
|
indvdum@0
|
1935 |
|
|
indvdum@0
|
1936 |
foreach ($_types as $ug_type)
|
|
indvdum@0
|
1937 |
{
|
|
indvdum@0
|
1938 |
if (!empty($recipient_list[$ug_type]))
|
|
indvdum@0
|
1939 |
{
|
|
indvdum@0
|
1940 |
if ($ug_type == 'u')
|
|
indvdum@0
|
1941 |
{
|
|
indvdum@0
|
1942 |
$sql = 'SELECT user_id as id, username as name, user_colour as colour
|
|
indvdum@0
|
1943 |
FROM ' . USERS_TABLE . '
|
|
indvdum@0
|
1944 |
WHERE ';
|
|
indvdum@0
|
1945 |
}
|
|
indvdum@0
|
1946 |
else
|
|
indvdum@0
|
1947 |
{
|
|
indvdum@0
|
1948 |
$sql = 'SELECT group_id as id, group_name as name, group_colour as colour, group_type
|
|
indvdum@0
|
1949 |
FROM ' . GROUPS_TABLE . '
|
|
indvdum@0
|
1950 |
WHERE ';
|
|
indvdum@0
|
1951 |
}
|
|
indvdum@0
|
1952 |
$sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($recipient_list[$ug_type])));
|
|
indvdum@0
|
1953 |
|
|
indvdum@0
|
1954 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
1955 |
|
|
indvdum@0
|
1956 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
1957 |
{
|
|
indvdum@0
|
1958 |
if ($ug_type == 'g')
|
|
indvdum@0
|
1959 |
{
|
|
indvdum@0
|
1960 |
$row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name'];
|
|
indvdum@0
|
1961 |
}
|
|
indvdum@0
|
1962 |
|
|
indvdum@0
|
1963 |
$recipient_list[$ug_type][$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
|
|
indvdum@0
|
1964 |
}
|
|
indvdum@0
|
1965 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
1966 |
}
|
|
indvdum@0
|
1967 |
}
|
|
indvdum@0
|
1968 |
|
|
indvdum@0
|
1969 |
foreach ($address as $message_id => $adr_ary)
|
|
indvdum@0
|
1970 |
{
|
|
indvdum@0
|
1971 |
foreach ($adr_ary as $type => $id_ary)
|
|
indvdum@0
|
1972 |
{
|
|
indvdum@0
|
1973 |
foreach ($id_ary as $ug_id => $_id)
|
|
indvdum@0
|
1974 |
{
|
|
indvdum@0
|
1975 |
if ($type == 'u')
|
|
indvdum@0
|
1976 |
{
|
|
indvdum@0
|
1977 |
$address_list[$message_id][] = get_username_string('full', $ug_id, $recipient_list[$type][$ug_id]['name'], $recipient_list[$type][$ug_id]['colour']);
|
|
indvdum@0
|
1978 |
}
|
|
indvdum@0
|
1979 |
else
|
|
indvdum@0
|
1980 |
{
|
|
indvdum@0
|
1981 |
$user_colour = ($recipient_list[$type][$ug_id]['colour']) ? ' style="font-weight: bold; color:#' . $recipient_list[$type][$ug_id]['colour'] . '"' : '';
|
|
indvdum@0
|
1982 |
$link = '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $ug_id) . '"' . $user_colour . '>';
|
|
indvdum@0
|
1983 |
$address_list[$message_id][] = $link . $recipient_list[$type][$ug_id]['name'] . (($link) ? '</a>' : '');
|
|
indvdum@0
|
1984 |
}
|
|
indvdum@0
|
1985 |
}
|
|
indvdum@0
|
1986 |
}
|
|
indvdum@0
|
1987 |
}
|
|
indvdum@0
|
1988 |
|
|
indvdum@0
|
1989 |
return $address_list;
|
|
indvdum@0
|
1990 |
}
|
|
indvdum@0
|
1991 |
|
|
indvdum@0
|
1992 |
?> |