| 1 |
<?php</span> |
|---|
| 2 |
<span class="code-lang">$root_path = './'; |
|---|
| 3 |
require ($root_path . 'include/config.php'); |
|---|
| 4 |
require ($root_path . 'include/bbcode/bbcode.lib.php'); |
|---|
| 5 |
require ($root_path . 'include/functions_check.php'); |
|---|
| 6 |
require ($root_path . 'include/functions_post.php'); |
|---|
| 7 |
require ($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_pms.php'); |
|---|
| 8 |
|
|---|
| 9 |
$userdata = session_pagestart($user_ip); |
|---|
| 10 |
init_userprefs($userdata); |
|---|
| 11 |
loggedinorreturn();</span> |
|---|
| 12 |
<span class="code-lang"> |
|---|
| 13 |
if ( $config['privmsg_disable'] ) { |
|---|
| 14 |
trigger_error($lang['private_messages_disabled']); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
function return_messages_history ( $message_id, $skip_last = false ) { |
|---|
| 18 |
global $db; |
|---|
| 19 |
|
|---|
| 20 |
if ( !$message_id ) { |
|---|
| 21 |
return; |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
$origmsg = 0; |
|---|
| 25 |
$subject = ''; |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
$sql = 'SELECT p.id, p.receiver, p.added, p.msg, p.subject, u.name, u.uid, u.class |
|---|
| 29 |
FROM ' . PRIVATE_MESSAGES_TABLE . ' p, ' . USERS_TABLE . ' u |
|---|
| 30 |
WHERE p.id = ' . $message_id . ' AND u.uid = p.sender'; |
|---|
| 31 |
$result = $db->sql_query($sql); |
|---|
| 32 |
|
|---|
| 33 |
while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 34 |
$reply_msg[$message_id] = $row; |
|---|
| 35 |
$subject = 'Re: ' . $row['subject']; |
|---|
| 36 |
$origmsg = $row['id']; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
$sql = 'SELECT p.id, p.receiver, p.added, p.msg, p.subject, u.name, u.uid, u.class |
|---|
| 40 |
FROM ' . PRIVATE_MESSAGES_TABLE . ' p, ' . USERS_TABLE . ' u |
|---|
| 41 |
WHERE p.reply_to = ' . $message_id . ' AND u.uid = p.sender ORDER BY p.added ASC'; |
|---|
| 42 |
$result = $db->sql_query($sql); |
|---|
| 43 |
|
|---|
| 44 |
while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 45 |
$reply_msg[$row['id']] = $row; |
|---|
| 46 |
$subject = 'Re: ' . $row['subject']; |
|---|
| 47 |
$origmsg = $row['id']; |
|---|
| 48 |
} |
|---|
| 49 |
if ( $skip_last && $origmsg ) { |
|---|
| 50 |
unset($reply_msg[$origmsg]); |
|---|
| 51 |
} |
|---|
| 52 |
krsort($reply_msg); |
|---|
| 53 |
|
|---|
| 54 |
if ( !sizeof($reply_msg) ) { |
|---|
| 55 |
return false; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
return array ( $reply_msg, $subject, $origmsg ); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
$action = request_var('action', '');</span> |
|---|
| 63 |
<span class="code-lang"> |
|---|
| 64 |
switch ( $action ) { |
|---|
| 65 |
|
|---|
| 66 |
case 'viewmessage': |
|---|
| 67 |
|
|---|
| 68 |
$pm_id = request_var('id', 0); |
|---|
| 69 |
if ( !$pm_id ) { |
|---|
| 70 |
trigger_error( sprintf($lang['invalid_id'], $id) ); |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
$sql = 'SELECT p.*, u.name, u.uid, u.class |
|---|
| 74 |
FROM ' . PRIVATE_MESSAGES_TABLE . ' p, ' . USERS_TABLE . ' u |
|---|
| 75 |
WHERE p.id = ' . $pm_id . ' AND p.receiver = ' . $userdata['uid'] . ' AND p.sender = u.uid'; |
|---|
| 76 |
$result = $db->sql_query($sql); |
|---|
| 77 |
|
|---|
| 78 |
if ( !$message = $db->sql_fetchrow($result) ) { |
|---|
| 79 |
$sql = 'SELECT p.*, u.name, u.uid, u.class |
|---|
| 80 |
FROM ' . PRIVATE_MESSAGES_TABLE . ' p, ' . USERS_TABLE . ' u |
|---|
| 81 |
WHERE p.id = ' . $pm_id . ' AND p.sender = ' . $userdata['uid'] . ' AND p.receiver = u.uid AND p.saved = 1'; |
|---|
| 82 |
$result = $db->sql_query($sql); |
|---|
| 83 |
if ( !$message = $db->sql_fetchrow($result) ) { |
|---|
| 84 |
trigger_error( sprintf($lang['invalid_id'], $pm_id)); |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
$bb_code = new bbcode(); |
|---|
| 89 |
|
|---|
| 90 |
if ( $message['sender'] == $userdata['uid'] ) { |
|---|
| 91 |
$sender = parse_username($message); |
|---|
| 92 |
$id = $message['sender']; |
|---|
| 93 |
$sql = 'SELECT id FROM ' . FRIENDS_TABLE . ' WHERE userid = ' . $userdata['uid'] . ' AND friendid = ' . $id; |
|---|
| 94 |
$result = $db->sql_query($sql); |
|---|
| 95 |
if ( $db->sql_fetchrow($result) ) { |
|---|
| 96 |
$sender .= ' <a href="' . append_sid('my.php?type=friends&action=del_friend&fr_type=1&targetid=' . $id) . '">[' . $lang['remove_from_friends_list'] . ']</a>'; |
|---|
| 97 |
} |
|---|
| 98 |
else { |
|---|
| 99 |
$sender .= ' <a href="' . append_sid('my.php?type=friends&action=add_friend&fr_type=1&targetid=' . $id) . '">[' . $lang['add_to_friends_list'] . ']</a>'; |
|---|
| 100 |
} |
|---|
| 101 |
$reply = ''; |
|---|
| 102 |
$from = $lang['message_to']; |
|---|
| 103 |
} |
|---|
| 104 |
else { |
|---|
| 105 |
$from = $lang['message_from']; |
|---|
| 106 |
if ( $message['sender'] == ANONYMOUS ) { |
|---|
| 107 |
$sender = $lang['system']; |
|---|
| 108 |
$reply = ''; |
|---|
| 109 |
} |
|---|
| 110 |
else { |
|---|
| 111 |
$sender = parse_username($message); |
|---|
| 112 |
$id = $message['sender']; |
|---|
| 113 |
$reply_to = ( $message['reply_to'] ? $message['reply_to'] : $pm_id ); |
|---|
| 114 |
$sql = 'SELECT id FROM ' . FRIENDS_TABLE . ' WHERE userid = ' . $userdata['uid'] . ' AND friendid = ' . $id; |
|---|
| 115 |
$result = $db->sql_query($sql); |
|---|
| 116 |
if ( $db->sql_fetchrow($result) ) { |
|---|
| 117 |
$sender .= ' <a href="' . append_sid('my.php?type=friends&action=del_friend&fr_type=1&targetid=' . $id) . '">[' . $lang['remove_from_friends_list'] . ']</a>'; |
|---|
| 118 |
} |
|---|
| 119 |
elseif ( $userdata['uid'] != $message['sender'] ) { |
|---|
| 120 |
$sender .= ' <a href="' . append_sid('my.php?type=friends&action=add_friend&fr_type=1&targetid=' . $id) . '">[' . $lang['add_to_friends_list'] . ']</a>'; |
|---|
| 121 |
} |
|---|
| 122 |
$reply = ' [ <a href="' . append_sid('message.php?action=send&receiver=' . $message['sender'] . '&replyto=' . $reply_to) . '">' . $lang['message_answer'] . '</a> ]'; |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
$bb_code->parse($message['msg']); |
|---|
| 127 |
$body = $bb_code->get_html(); |
|---|
| 128 |
$body = censor_text($body); |
|---|
| 129 |
|
|---|
| 130 |
$added = create_date($message['added']); |
|---|
| 131 |
if ( $message['sender'] == $userdata['uid'] ) { |
|---|
| 132 |
$unread = ( $message['unread'] ? '<span style="color: #FF0000;"><b>(' . $lang['message_new'] . ')</b></span>' : '' ); |
|---|
| 133 |
} |
|---|
| 134 |
else { |
|---|
| 135 |
$unread = ''; |
|---|
| 136 |
} |
|---|
| 137 |
$subject = $message['subject']; |
|---|
| 138 |
|
|---|
| 139 |
if ( $message['unread'] ) { |
|---|
| 140 |
$sql = 'UPDATE ' . PRIVATE_MESSAGES_TABLE . ' SET unread = 0 WHERE id = ' . $pm_id . ' AND receiver=' . $userdata['uid'] . ' LIMIT 1'; |
|---|
| 141 |
$db->sql_query($sql); |
|---|
| 142 |
if ( $db->sql_affectedrows() && $message['location'] == PM_INBOX ) { |
|---|
| 143 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms - 1 WHERE uid = ' . $userdata['uid']; |
|---|
| 144 |
$db->sql_query($sql); |
|---|
| 145 |
} |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
$template->assign_vars(array( |
|---|
| 150 |
'U_DELETE' => append_sid('message.php?action=moveordel&id=' . $pm_id . '&delete=1'), |
|---|
| 151 |
'U_FORWARD' => append_sid('message.php?action=forward&id=' . $pm_id), |
|---|
| 152 |
'SUBJECT' => $subject, |
|---|
| 153 |
'FROM' => $from, |
|---|
| 154 |
'SENDER' => $sender, |
|---|
| 155 |
'ADDED' => $added, |
|---|
| 156 |
'UNREAD' => $unread, |
|---|
| 157 |
'BODY' => $body, |
|---|
| 158 |
'PM_ID'=> $pm_id, |
|---|
| 159 |
'REPLY' => $reply |
|---|
| 160 |
)); |
|---|
| 161 |
|
|---|
| 162 |
if ( list ( $msg_history_ary ) = return_messages_history($message['reply_to'], true) ) { |
|---|
| 163 |
$template->assign_block_vars('messages_history', array()); |
|---|
| 164 |
foreach ( $msg_history_ary AS $msg_id => $ary ) { |
|---|
| 165 |
$added = create_date($ary['added']); |
|---|
| 166 |
|
|---|
| 167 |
$body = censor_text($ary['msg']); |
|---|
| 168 |
$bb_code->parse($body); |
|---|
| 169 |
$body = $bb_code->get_html(); |
|---|
| 170 |
|
|---|
| 171 |
$user_name = parse_username($ary); |
|---|
| 172 |
|
|---|
| 173 |
$template->assign_block_vars('messages_history.messages_history_row', array( |
|---|
| 174 |
'SUBJECT' => $ary['subject'], |
|---|
| 175 |
'MESSAGE' => $body, |
|---|
| 176 |
'ADDED' => $added, |
|---|
| 177 |
'USERNAME' => $user_name, |
|---|
| 178 |
)); |
|---|
| 179 |
} |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
stdhead(sprintf($lang['message_pm_subject'], $subject)); |
|---|
| 183 |
$template->set_filenames(array( |
|---|
| 184 |
'body' => 'message_viewmessage_body.html' |
|---|
| 185 |
)); |
|---|
| 186 |
stdfoot(); |
|---|
| 187 |
|
|---|
| 188 |
break; |
|---|
| 189 |
|
|---|
| 190 |
case 'send': |
|---|
| 191 |
parked(); |
|---|
| 192 |
|
|---|
| 193 |
$receiver = request_var('receiver', 0); |
|---|
| 194 |
$reply_to = request_var('replyto', 0); |
|---|
| 195 |
|
|---|
| 196 |
if ( $userdata['class'] < UC_MODERATOR ) { |
|---|
| 197 |
$sql = 'SELECT COUNT(*) AS count FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE sender = ' . $userdata['uid'] . ' AND saved = 1'; |
|---|
| 198 |
$result = $db->sql_query($sql); |
|---|
| 199 |
$count = ( $row = $db->sql_fetchrow($result) ) ? intval($row['count']) : 0; |
|---|
| 200 |
if ( $count > $config['max_sentbox_privmsgs'] ) { |
|---|
| 201 |
trigger_error($lang['sentbox_limit_reached']); |
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
$sql = 'SELECT MAX(added) AS max_added FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE sender = ' . $userdata['uid']; |
|---|
| 206 |
$result = $db->sql_query($sql); |
|---|
| 207 |
$max_added = ( $flood_row = $db->sql_fetchrow($result) ) ? $flood_row['max_added'] : 0; |
|---|
| 208 |
|
|---|
| 209 |
if ( $max_added > 0 && (time() - $max_added) < intval($config['flood_interval']) ) { |
|---|
| 210 |
trigger_error($lang['flood_error']); |
|---|
| 211 |
} |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
if ( isset($_POST['submit']) ) { |
|---|
| 215 |
$origmsg = request_var('origmsg', 0); |
|---|
| 216 |
$save = ( isset($_POST['save']) ? 1 : 0 ); |
|---|
| 217 |
$delete = ( isset($_POST['delete']) ? 1 : 0 ); |
|---|
| 218 |
$returnto = request_var('returnto', ''); |
|---|
| 219 |
$msg = request_var('message', ''); |
|---|
| 220 |
$subject = request_var('subject', ''); |
|---|
| 221 |
if ( !$msg ) { |
|---|
| 222 |
trigger_error($lang['post_something']); |
|---|
| 223 |
} |
|---|
| 224 |
if ( !$subject ) { |
|---|
| 225 |
trigger_error($lang['please_enter_subject']); |
|---|
| 226 |
} |
|---|
| 227 |
|
|---|
| 228 |
$sql = 'SELECT email, acceptpms, notifs, parked, user_session_time, language, name, class FROM ' . USERS_TABLE . ' WHERE uid = ' . $receiver; |
|---|
| 229 |
$result = $db->sql_query($sql); |
|---|
| 230 |
if ( !($user = $db->sql_fetchrow($result)) || !$receiver ) { |
|---|
| 231 |
trigger_error(sprintf($lang['invalid_id'], $receiver)); |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
if ( $userdata['class'] < UC_MODERATOR ) { |
|---|
| 235 |
if ( $user['acceptpms'] == 1 ) { |
|---|
| 236 |
$sql = 'SELECT * FROM ' . FRIENDS_TABLE . ' WHERE userid = ' . $receiver . ' AND blockid = ' . $userdata['uid']; |
|---|
| 237 |
$result = $db->sql_query($sql); |
|---|
| 238 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 239 |
trigger_error($lang['you_in_block_list']); |
|---|
| 240 |
} |
|---|
| 241 |
} |
|---|
| 242 |
elseif ( $user['acceptpms'] == 2 ) { |
|---|
| 243 |
$sql = 'SELECT * FROM ' . FRIENDS_TABLE . ' WHERE userid = ' . $receiver . ' AND friendid=' . $userdata['uid']; |
|---|
| 244 |
$result = $db->sql_query($sql); |
|---|
| 245 |
if ( !($row = $db->sql_fetchrow($result)) ) { |
|---|
| 246 |
trigger_error($lang['only_from_friends']); |
|---|
| 247 |
} |
|---|
| 248 |
} |
|---|
| 249 |
elseif ( !$user['acceptpms'] ) { |
|---|
| 250 |
trigger_error($lang['only_from_admins']); |
|---|
| 251 |
} |
|---|
| 252 |
|
|---|
| 253 |
if ( $user['parked'] ) { |
|---|
| 254 |
trigger_error($lang['this_account_parked']); |
|---|
| 255 |
} |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
$pm_ary = array(array( |
|---|
| 259 |
'sender' => $userdata['uid'], |
|---|
| 260 |
'sender_name' => $userdata['name'], |
|---|
| 261 |
'receiver' => $receiver, |
|---|
| 262 |
'msg' => $msg, |
|---|
| 263 |
'subject' => $subject, |
|---|
| 264 |
'saved' => $save, |
|---|
| 265 |
'reply_to' => $reply_to, |
|---|
| 266 |
|
|---|
| 267 |
'name' => $user['name'], |
|---|
| 268 |
'email' => $user['email'], |
|---|
| 269 |
'notifs' => $user['notifs'], |
|---|
| 270 |
'language' => $user['language'], |
|---|
| 271 |
'class' => $user['class'] |
|---|
| 272 |
)); |
|---|
| 273 |
|
|---|
| 274 |
send_pm($pm_ary); |
|---|
| 275 |
|
|---|
| 276 |
if ( $origmsg && $delete ) { |
|---|
| 277 |
|
|---|
| 278 |
$sql = 'SELECT * FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE id = ' . $origmsg; |
|---|
| 279 |
$result = $db->sql_query($sql); |
|---|
| 280 |
if ( $arr = $db->sql_fetchrow($result) ) { |
|---|
| 281 |
if ( $arr['receiver'] != $userdata['uid'] ) { |
|---|
| 282 |
trigger_error($lang['bad_data']); |
|---|
| 283 |
} |
|---|
| 284 |
if ( !$arr['saved'] ) { |
|---|
| 285 |
$sql = 'DELETE FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE id = ' . $origmsg; |
|---|
| 286 |
$db->sql_query($sql); |
|---|
| 287 |
} |
|---|
| 288 |
elseif ( $arr['saved'] ) { |
|---|
| 289 |
$sql = 'UPDATE ' . PRIVATE_MESSAGES_TABLE . ' SET location = 0 WHERE id = ' . $origmsg; |
|---|
| 290 |
$db->sql_query($sql); |
|---|
| 291 |
} |
|---|
| 292 |
} |
|---|
| 293 |
} |
|---|
| 294 |
|
|---|
| 295 |
$returnto = ( $returnto ? $returnto : 'message.php' ); |
|---|
| 296 |
$returnto = append_sid($returnto); |
|---|
| 297 |
|
|---|
| 298 |
meta_refresh(3, $returnto); |
|---|
| 299 |
trigger_error($lang['sucefully_sended']); |
|---|
| 300 |
} |
|---|
| 301 |
else { |
|---|
| 302 |
if ( $receiver == $userdata['uid'] && $userdata['class'] < UC_SYSOP ) { |
|---|
| 303 |
trigger_error(sprintf($lang['invalid_id'], $receiver)); |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
$sql = 'SELECT name, uid, class FROM ' . USERS_TABLE . ' WHERE uid = ' . $receiver; |
|---|
| 307 |
$result = $db->sql_query($sql); |
|---|
| 308 |
if ( !($user = $db->sql_fetchrow($result)) || !$receiver ) { |
|---|
| 309 |
trigger_error(sprintf($lang['invalid_id'], $receiver)); |
|---|
| 310 |
} |
|---|
| 311 |
|
|---|
| 312 |
$body = ''; |
|---|
| 313 |
$subject = ''; |
|---|
| 314 |
$origmsg = $reply_to; |
|---|
| 315 |
|
|---|
| 316 |
$bb_code = new bbcode(); |
|---|
| 317 |
|
|---|
| 318 |
if ( $reply_to ) { |
|---|
| 319 |
$template->assign_block_vars('reply_to', array()); |
|---|
| 320 |
|
|---|
| 321 |
list( $reply_msg, $subject, $origmsg ) = return_messages_history ($reply_to); |
|---|
| 322 |
|
|---|
| 323 |
foreach ( $reply_msg AS $msg_id => $ary ) { |
|---|
| 324 |
$added = create_date($ary['added']); |
|---|
| 325 |
$bb_code->parse($ary['msg']); |
|---|
| 326 |
$msg = $bb_code->get_html(); |
|---|
| 327 |
$msg = censor_text($msg); |
|---|
| 328 |
|
|---|
| 329 |
$template->assign_block_vars('reply_to.reply_to_row', array( |
|---|
| 330 |
'SUBJECT' => $ary['subject'], |
|---|
| 331 |
'MESSAGE' => $msg, |
|---|
| 332 |
'ADDED' => $added, |
|---|
| 333 |
'USERNAME' => ( $ary['uid'] == ANONYMOUS ? $lang['system'] : $ary['name'] ) |
|---|
| 334 |
)); |
|---|
| 335 |
} |
|---|
| 336 |
} |
|---|
| 337 |
|
|---|
| 338 |
$tpl = textbbcode($body); |
|---|
| 339 |
|
|---|
| 340 |
$template->assign_vars(array( |
|---|
| 341 |
'S_FORM_ACTION' => append_sid('message.php'), |
|---|
| 342 |
'RECEIVER_ID' => $receiver, |
|---|
| 343 |
'REPLY_TO' => $reply_to, |
|---|
| 344 |
'ORIGMSG' => $origmsg, |
|---|
| 345 |
'RECEIVER_USERNAME' => parse_username($user), |
|---|
| 346 |
'SUBJECT' => $subject, |
|---|
| 347 |
'DELETEPM_CHECKED' => ( $userdata['deletepms'] ? 'checked="checked"' : '' ), |
|---|
| 348 |
'SAVEPM_CHECKED' => ( $userdata['savepms'] ? 'checked="checked"' :'' ), |
|---|
| 349 |
|
|---|
| 350 |
'TEXTBBCODE' => $tpl |
|---|
| 351 |
)); |
|---|
| 352 |
|
|---|
| 353 |
stdhead($lang['send_message']); |
|---|
| 354 |
$template->set_filenames(array( |
|---|
| 355 |
'body' => 'message_sendmessage.html' |
|---|
| 356 |
)); |
|---|
| 357 |
stdfoot(); |
|---|
| 358 |
} |
|---|
| 359 |
break; |
|---|
| 360 |
|
|---|
| 361 |
case 'moveordel': |
|---|
| 362 |
$pm_id = request_var('id', 0); |
|---|
| 363 |
$pm_box = request_var('box', PM_INBOX); |
|---|
| 364 |
$pm_messages = request_var('messages', array( 0 => 0 ) ); |
|---|
| 365 |
$delete = isset($_REQUEST['delete']); |
|---|
| 366 |
$markread = isset($_REQUEST['markread']); |
|---|
| 367 |
|
|---|
| 368 |
if ( $pm_id ) { |
|---|
| 369 |
$pm_messages = array($pm_id); |
|---|
| 370 |
} |
|---|
| 371 |
|
|---|
| 372 |
if ( !sizeof($pm_messages) ) { |
|---|
| 373 |
redirect( append_sid('message.php?action=viewmailbox&box=' . $pm_box)); |
|---|
| 374 |
} |
|---|
| 375 |
|
|---|
| 376 |
$sql = 'SELECT * FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE id IN (' . implode(', ', $pm_messages) . ')'; |
|---|
| 377 |
$result = $db->sql_query($sql); |
|---|
| 378 |
if ( !($message = $db->sql_fetchrow($result)) ) { |
|---|
| 379 |
trigger_error(sprintf($lang['invalid_id'], $pm_id)); |
|---|
| 380 |
} |
|---|
| 381 |
|
|---|
| 382 |
if ( $delete ) { |
|---|
| 383 |
do { |
|---|
| 384 |
if ( ( $message['receiver'] == $userdata['uid'] && !$message['saved'] ) || ( $message['sender'] == $userdata['uid'] && $message['location'] == PM_DELETED ) ) { |
|---|
| 385 |
$sql = 'DELETE FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE id = ' . $message['id']; |
|---|
| 386 |
$db->sql_query($sql); |
|---|
| 387 |
} |
|---|
| 388 |
elseif ( $message['receiver'] == $userdata['uid'] && $message['saved'] ) { |
|---|
| 389 |
$sql = 'UPDATE ' . PRIVATE_MESSAGES_TABLE . ' SET location = 0 WHERE id = ' . $message['id']; |
|---|
| 390 |
$db->sql_query($sql); |
|---|
| 391 |
} |
|---|
| 392 |
elseif ( $message['sender'] == $userdata['uid'] && $message['location'] != PM_DELETED ) { |
|---|
| 393 |
$sql = 'UPDATE ' . PRIVATE_MESSAGES_TABLE . ' SET saved = 0 WHERE id = ' . $message['id']; |
|---|
| 394 |
$db->sql_query($sql); |
|---|
| 395 |
} |
|---|
| 396 |
if ( $db->sql_affectedrows() && $message['unread'] && $message['location'] == PM_INBOX && $message['receiver'] == $userdata['uid'] ) { |
|---|
| 397 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms - 1 WHERE uid = ' . $userdata['uid']; |
|---|
| 398 |
$db->sql_query($sql); |
|---|
| 399 |
} |
|---|
| 400 |
} |
|---|
| 401 |
while ( $message = $db->sql_fetchrow($result) ); |
|---|
| 402 |
} |
|---|
| 403 |
|
|---|
| 404 |
if ( $markread ) { |
|---|
| 405 |
do { |
|---|
| 406 |
if ( $message['receiver'] == $userdata['uid'] ) { |
|---|
| 407 |
$sql = 'UPDATE ' . PRIVATE_MESSAGES_TABLE . ' SET unread = 0 WHERE id = ' . $message['id']; |
|---|
| 408 |
$db->sql_query($sql); |
|---|
| 409 |
if ( $db->sql_affectedrows() && $message['unread'] && $message['location'] == PM_INBOX ) { |
|---|
| 410 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = user_unread_pms - 1 WHERE uid = ' . $userdata['uid']; |
|---|
| 411 |
$db->sql_query($sql); |
|---|
| 412 |
} |
|---|
| 413 |
} |
|---|
| 414 |
} |
|---|
| 415 |
while ( $message = $db->sql_fetchrow($result) ); |
|---|
| 416 |
} |
|---|
| 417 |
|
|---|
| 418 |
redirect( append_sid('message.php?action=viewmailbox&box=' . $pm_box)); |
|---|
| 419 |
break; |
|---|
| 420 |
|
|---|
| 421 |
case 'forward': |
|---|
| 422 |
if ( $userdata['class'] < UC_MODERATOR ) { |
|---|
| 423 |
$sql = 'SELECT COUNT(*) AS count FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE sender = ' . $userdata['uid'] . ' AND saved = 1'; |
|---|
| 424 |
$result = $db->sql_query($sql); |
|---|
| 425 |
$count = ( $row = $db->sql_fetchrow($result) ) ? intval($row['count']) : 0; |
|---|
| 426 |
if ( $count > $config['max_sentbox_privmsgs'] ) { |
|---|
| 427 |
trigger_error($lang['sentbox_limit_reached']); |
|---|
| 428 |
} |
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
$sql = 'SELECT MAX(added) AS max_added FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE sender = ' . $userdata['uid']; |
|---|
| 432 |
$result = $db->sql_query($sql); |
|---|
| 433 |
$max_added = ( $flood_row = $db->sql_fetchrow($result) ) ? $flood_row['max_added'] : 0; |
|---|
| 434 |
|
|---|
| 435 |
if ( intval($flood_row['max_added']) > 0 && (time() - intval($flood_row['max_added'])) < intval($config['flood_interval']) ) { |
|---|
| 436 |
trigger_error($lang['flood_error']); |
|---|
| 437 |
} |
|---|
| 438 |
} |
|---|
| 439 |
|
|---|
| 440 |
if ( isset($_GET['id']) ) { |
|---|
| 441 |
$pm_id = (int) $_GET['id']; |
|---|
| 442 |
|
|---|
| 443 |
|
|---|
| 444 |
$sql = 'SELECT * |
|---|
| 445 |
FROM ' . PRIVATE_MESSAGES_TABLE . ' |
|---|
| 446 |
WHERE id=' . $pm_id . ' AND (receiver=' . $userdata['uid'] . ' OR sender=' . $userdata['uid'] . ') LIMIT 1'; |
|---|
| 447 |
$result = $db->sql_query($sql); |
|---|
| 448 |
if ( !$message = $db->sql_fetchrow($result) ) { |
|---|
| 449 |
trigger_error(sprintf($lang['invalid_id'], $pm_id) ); |
|---|
| 450 |
} |
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
$subject = 'Fwd: ' . $message['subject']; |
|---|
| 454 |
$from = $message['sender']; |
|---|
| 455 |
$orig = $message['receiver']; |
|---|
| 456 |
|
|---|
| 457 |
$sql = 'SELECT name, uid, class |
|---|
| 458 |
FROM ' . USERS_TABLE . ' |
|---|
| 459 |
WHERE uid = ' . $from; |
|---|
| 460 |
$result = $db->sql_query($sql); |
|---|
| 461 |
if ( !$orig2 = $db->sql_fetchrow($result) ) { |
|---|
| 462 |
trigger_error(sprintf($lang['invalid_id'], $pm_id) ); |
|---|
| 463 |
} |
|---|
| 464 |
|
|---|
| 465 |
$from_name = parse_username($userdata); |
|---|
| 466 |
$orig_name = parse_username($orig2); |
|---|
| 467 |
|
|---|
| 468 |
$bb_code = new bbcode(); |
|---|
| 469 |
|
|---|
| 470 |
$body = sprintf($lang['pm_message_separator'], $orig2['name'], $message['msg']); |
|---|
| 471 |
$bb_code->parse($body); |
|---|
| 472 |
$body = $bb_code->get_html(); |
|---|
| 473 |
$body = censor_text($body); |
|---|
| 474 |
|
|---|
| 475 |
$template->assign_vars(array( |
|---|
| 476 |
'S_FORM_ACTION' => append_sid('message.php'), |
|---|
| 477 |
'SUBJECT' => $subject, |
|---|
| 478 |
'PM_ID' => $pm_id, |
|---|
| 479 |
'FROM_NAME' => $from_name, |
|---|
| 480 |
'BODY' => $body, |
|---|
| 481 |
'SAVE_PM_CHECKED' => ( $userdata['savepms'] ? 'checked="checked"' : '' ), |
|---|
| 482 |
'ORIG_NAME' => $orig_name |
|---|
| 483 |
)); |
|---|
| 484 |
|
|---|
| 485 |
stdhead($subject); |
|---|
| 486 |
$template->set_filenames(array( |
|---|
| 487 |
'body' => 'message_forward_message.html' |
|---|
| 488 |
)); |
|---|
| 489 |
stdfoot(); |
|---|
| 490 |
} |
|---|
| 491 |
else { |
|---|
| 492 |
|
|---|
| 493 |
$pm_id = request_var('id', 0); |
|---|
| 494 |
$subject = request_var('subject', ''); |
|---|
| 495 |
$username = request_var('to', ''); |
|---|
| 496 |
$body = request_var('msg', ''); |
|---|
| 497 |
$save = isset($_POST['save']); |
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
$sql = 'SELECT * FROM ' . PRIVATE_MESSAGES_TABLE . ' WHERE id = ' . $pm_id . ' AND (receiver=' . $userdata['uid'] . ' OR sender=' . $userdata['uid'] . ') LIMIT 1'; |
|---|
| 501 |
$result = $db->sql_query($sql); |
|---|
| 502 |
|
|---|
| 503 |
if ( !($message = $db->sql_fetchrow($result)) ) { |
|---|
| 504 |
trigger_error(sprintf($lang['invalid_id'], $pm_id) ); |
|---|
| 505 |
} |
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
$sql = 'SELECT uid, email, language, name, class, notifs FROM ' . USERS_TABLE . ' WHERE LOWER(name) = ' . "'" . $db->sql_escape(utf_strtolower($username)) . "'" . ' AND uid != ' . ANONYMOUS . ' LIMIT 1'; |
|---|
| 509 |
$result = $db->sql_query($sql); |
|---|
| 510 |
if ( !($to_arr = $db->sql_fetchrow($result)) ) { |
|---|
| 511 |
trigger_error($lang['no_user_with_that_username']); |
|---|
| 512 |
} |
|---|
| 513 |
$to = $to_arr['uid']; |
|---|
| 514 |
$to_email = $to_arr['email']; |
|---|
| 515 |
$to_language = $to_arr['language']; |
|---|
| 516 |
$to_username = $to_arr['name']; |
|---|
| 517 |
if (!check_language($to_language)) { |
|---|
| 518 |
$to_language = $config['default_lang']; |
|---|
| 519 |
} |
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 |
if ( !($message['sender']) ) { |
|---|
| 523 |
$from_username = $lang['system']; |
|---|
| 524 |
} |
|---|
| 525 |
else { |
|---|
| 526 |
$sql = 'SELECT name, acceptpms, parked FROM ' . USERS_TABLE . ' WHERE uid=' . $message['sender']; |
|---|
| 527 |
$result = $db->sql_query($sql); |
|---|
| 528 |
$from = $db->sql_fetchrow($result); |
|---|
| 529 |
$from_username = $from['name']; |
|---|
| 530 |
} |
|---|
| 531 |
$body .= sprintf($lang['pm_message_separator'], $from_username, $message['msg']); |
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
if ( $userdata['class'] < UC_MODERATOR ) { |
|---|
| 535 |
if ( $from['acceptpms'] == 1 ) { |
|---|
| 536 |
$sql = 'SELECT * FROM ' . FRIENDS_TABLE . ' WHERE userid=' . $to . ' AND blockid=' . $userdata['uid']; |
|---|
| 537 |
$result = $db->sql_query($sql); |
|---|
| 538 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 539 |
trigger_error($lang['you_in_block_list']); |
|---|
| 540 |
} |
|---|
| 541 |
} |
|---|
| 542 |
elseif ( $from['acceptpms'] == 2 ) { |
|---|
| 543 |
$sql = 'SELECT * FROM ' . FRIENDS_TABLE . ' WHERE userid=' . $to . ' AND friendid=' . $userdata['uid']; |
|---|
| 544 |
$result = $db->sql_query($sql); |
|---|
| 545 |
if ( !($row = $db->sql_fetchrow($result)) ) { |
|---|
| 546 |
trigger_error($lang['only_from_friends']); |
|---|
| 547 |
} |
|---|
| 548 |
} |
|---|
| 549 |
elseif ( !$from['acceptpms'] ) { |
|---|
| 550 |
trigger_error($lang['only_from_admins']); |
|---|
| 551 |
} |
|---|
| 552 |
elseif ( $from['parked'] ) { |
|---|
| 553 |
trigger_error($lang['this_account_parked']); |
|---|
| 554 |
} |
|---|
| 555 |
} |
|---|
| 556 |
|
|---|
| 557 |
$pm_ary = array(array( |
|---|
| 558 |
'sender' => $userdata['uid'], |
|---|
| 559 |
'sender_name' => $userdata['name'], |
|---|
| 560 |
'receiver' => $to, |
|---|
| 561 |
'msg' => $body, |
|---|
| 562 |
'subject' => $subject, |
|---|
| 563 |
'saved' => $save, |
|---|
| 564 |
|
|---|
| 565 |
'name' => $to_arr['name'], |
|---|
| 566 |
'email' => $to_arr['email'], |
|---|
| 567 |
'notifs' => $to_arr['notifs'], |
|---|
| 568 |
'language' => $to_arr['language'], |
|---|
| 569 |
'class' => $to_arr['class'] |
|---|
| 570 |
)); |
|---|
| 571 |
|
|---|
| 572 |
send_pm($pm_ary); |
|---|
| 573 |
|
|---|
| 574 |
meta_refresh(3, append_sid($root_path . 'message.php')); |
|---|
| 575 |
trigger_error($lang['sucefully_sended']); |
|---|
| 576 |
} |
|---|
| 577 |
break; |
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
case 'viewmailbox': |
|---|
| 581 |
default: |
|---|
| 582 |
|
|---|
| 583 |
$mailbox = request_var('box', PM_INBOX); |
|---|
| 584 |
$warning_text = ''; |
|---|
| 585 |
|
|---|
| 586 |
if ( $mailbox == PM_INBOX ) { |
|---|
| 587 |
$mailbox_name = $lang['inbox']; |
|---|
| 588 |
$box_limit = $config['max_inbox_privmsgs']; |
|---|
| 589 |
$sender_title = $lang['sender']; |
|---|
| 590 |
$sql_where = 'm.receiver = ' . $userdata['uid'] . ' AND m.location = ' . $mailbox . ' AND m.sender = u.uid'; |
|---|
| 591 |
} |
|---|
| 592 |
else{ |
|---|
| 593 |
$mailbox_name = $lang['sentbox']; |
|---|
| 594 |
$box_limit = $config['max_sentbox_privmsgs']; |
|---|
| 595 |
$sender_title = $lang['receiver']; |
|---|
| 596 |
$sql_where = 'm.sender=' . $userdata['uid'] . ' AND m.saved = 1 AND m.receiver = u.uid'; |
|---|
| 597 |
} |
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
$sql = 'SELECT COUNT(*) as count |
|---|
| 601 |
FROM ' . PRIVATE_MESSAGES_TABLE . ' m, ' . USERS_TABLE . ' u |
|---|
| 602 |
WHERE ' . $sql_where; |
|---|
| 603 |
$result = $db->sql_query($sql); |
|---|
| 604 |
$count = $count_pager = ( $row = $db->sql_fetchrow($result) ) ? intval($row['count']) : 0; |
|---|
| 605 |
|
|---|
| 606 |
if ( $box_limit && ( $count > $box_limit ) && ( $userdata['class'] < UC_MODERATOR ) ) { |
|---|
| 607 |
$limit = 40; |
|---|
| 608 |
$offset = $count - $box_limit; |
|---|
| 609 |
$warning_text = sprintf($lang['inbox_pm_limit_reached_js_text'], $mailbox_name, $box_limit, $count); |
|---|
| 610 |
$count_pager = $box_limit; |
|---|
| 611 |
} |
|---|
| 612 |
list($pagertop, $pagerbottom, $offset_pager, $limit_pager) = pager(40, $count_pager, 'message.php?action=viewmailbox&box=' . $mailbox . '&'); |
|---|
| 613 |
|
|---|
| 614 |
$limit = ( isset($limit) ? $limit : $limit_pager ); |
|---|
| 615 |
$offset = ( isset($offset) ? $offset : $offset_pager ); |
|---|
| 616 |
|
|---|
| 617 |
$pm_box_select = '<select name="box">'; |
|---|
| 618 |
$pm_box_select .= '<option value="' . PM_INBOX . '"' . ( $mailbox == PM_INBOX ? ' selected="selected"' : '' ) . '>' . $lang['inbox'] . '</option>'; |
|---|
| 619 |
$pm_box_select .= '<option value="' . PM_SENTBOX . '"' . ( $mailbox == PM_SENTBOX ? ' selected="selected"' : '' ) . '>' . $lang['sentbox'] . '</option>'; |
|---|
| 620 |
$pm_box_select .= '</select>'; |
|---|
| 621 |
|
|---|
| 622 |
$template->assign_vars(array( |
|---|
| 623 |
'S_FORM_ACTION' => append_sid('message.php'), |
|---|
| 624 |
'MAILBOX' => $mailbox, |
|---|
| 625 |
'MAILBOX_NAME' => $mailbox_name, |
|---|
| 626 |
'PM_BOX_SELECT' => $pm_box_select, |
|---|
| 627 |
'SENDER_RECEIVER' => $sender_title, |
|---|
| 628 |
'PAGERBOTTOM' => $pagerbottom, |
|---|
| 629 |
|
|---|
| 630 |
'MESSAGES_COUNT' => $count, |
|---|
| 631 |
|
|---|
| 632 |
'S_LIMIT_REACHED_WARNING' => $warning_text |
|---|
| 633 |
)); |
|---|
| 634 |
|
|---|
| 635 |
$sql = 'SELECT m.*, u.name, u.uid, u.class |
|---|
| 636 |
FROM ' . PRIVATE_MESSAGES_TABLE . ' m, ' . USERS_TABLE . ' u |
|---|
| 637 |
WHERE ' . $sql_where . |
|---|
| 638 |
' ORDER BY added DESC'; |
|---|
| 639 |
$result = $db->sql_query_limit($sql, $limit, $offset); |
|---|
| 640 |
|
|---|
| 641 |
if ( !$count ) { |
|---|
| 642 |
if ( $userdata['user_unread_pms'] ) { |
|---|
| 643 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = 0 WHERE uid = ' . $userdata['uid']; |
|---|
| 644 |
$db->sql_query($sql); |
|---|
| 645 |
} |
|---|
| 646 |
} |
|---|
| 647 |
else { |
|---|
| 648 |
$unread_pms = 0; |
|---|
| 649 |
|
|---|
| 650 |
while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 651 |
$username = parse_username($row); |
|---|
| 652 |
|
|---|
| 653 |
$subject = ( !$row['subject'] ? $lang['no_subject'] : $row['subject'] ); |
|---|
| 654 |
|
|---|
| 655 |
$template->assign_block_vars('messages_row', array( |
|---|
| 656 |
'U_MESSAGE' => append_sid('message.php?action=viewmessage&id=' . $row['id']), |
|---|
| 657 |
'ID' => $row['id'], |
|---|
| 658 |
'SENDER_RECEIVER_NAME' => $username, |
|---|
| 659 |
'SUBJECT' => $row['subject'], |
|---|
| 660 |
'IMG_SRC' => ( $row['unread'] && $mailbox != PM_SENTBOX ? $images['inboxnew'] : $images['inbox'] ), |
|---|
| 661 |
'IMG_TITLE' => ( $row['unread'] && $mailbox != PM_SENTBOX ? $lang['new_unread_pm'] : $lang['old_read_pm'] ), |
|---|
| 662 |
'DATE' => create_date($row['added']) |
|---|
| 663 |
)); |
|---|
| 664 |
|
|---|
| 665 |
if ( $row['unread'] && $mailbox != PM_SENTBOX ) { |
|---|
| 666 |
++$unread_pms; |
|---|
| 667 |
} |
|---|
| 668 |
|
|---|
| 669 |
} |
|---|
| 670 |
|
|---|
| 671 |
// $sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = ' . $unread_pms . ' WHERE uid = ' . $userdata['uid']; |
|---|
| 672 |
// $db->sql_query($sql); |
|---|
| 673 |
//} |
|---|
| 674 |
} |
|---|
| 675 |
|
|---|
| 676 |
stdhead($mailbox_name); |
|---|
| 677 |
$template->set_filenames(array( |
|---|
| 678 |
'body' => 'message_viewmailbox.html' |
|---|
| 679 |
)); |
|---|
| 680 |
stdfoot(); |
|---|
| 681 |
break; |
|---|
| 682 |
} |
|---|
| 683 |
|
|---|
| 684 |
?> |
|---|