/*
[Discuz!] (C)2001-2007 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: pm.inc.php 10920 2007-10-19 00:53:10Z monkey $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
$discuz_action = 197;
if(!$discuz_uid) {
wapmsg('not_loggedin');
}
if(empty($do)) {
$num_read = $num_unread = 0;
$query = $db->query("SELECT COUNT(*) AS num, new FROM {$tablepre}pms WHERE msgtoid='$discuz_uid' AND folder='inbox' GROUP BY new='0'");
while($pm = $db->fetch_array($query)) {
$pm['new'] ? $num_unread = $pm['num'] : $num_read = $pm['num'];
}
echo "$lang[pm_unread]($num_unread)\n".
"$lang[pm_all](".($num_read + $num_unread).")\n".
"$lang[pm_send]\n".
"$lang[pm_delete_all]";
} else {
if($do == 'list') {
echo "$lang[pm_list]\n";
$unreadadd = empty($unread) ? '' : 'AND new>\'0\'';
$pageadd = empty($unread) ? '' : '&unread=yes';
$page = max(1, intval($page));
$start_limit = $number = ($page - 1) * $waptpp;
if(!($totalpms = $db->result_first("SELECT COUNT(*) FROM {$tablepre}pms WHERE msgtoid='$discuz_uid' AND folder='inbox' $unreadadd"))) {
wapmsg('pm_nonexistence');
}
$query = $db->query("SELECT pmid, new, msgfrom, subject, dateline FROM {$tablepre}pms
WHERE msgtoid='$discuz_uid' AND folder='inbox' $unreadadd
ORDER BY dateline DESC
LIMIT $start_limit, $waptpp");
while($pm = $db->fetch_array($query)) {
echo "#".++$number.' '.(empty($unread) && $pm['new'] ? "($lang[unread])" : '').cutstr($pm['subject'], 30)."\n".
" ".gmdate("$wapdateformat $timeformat", $pm['dateline'] + $timeoffset * 3600)."\n".
" $pm[msgfrom]\n";
}
echo wapmulti($totalpms, $waptpp, $page, "index.php?action=pm&do=$do$pageadd");
echo "$lang[pm_send]\n";
} elseif($do == 'view') {
$pm = $db->fetch_first("SELECT * FROM {$tablepre}pms WHERE pmid='$pmid' AND msgtoid='$discuz_uid' AND folder='inbox'");
if(!$pm) {
wapmsg('pm_nonexistence');
}
echo "$lang[thread]$pm[subject]\n".
$lang['from'].$pm['msgfrom']."\n".
$lang['dateline'].gmdate("$wapdateformat $timeformat", $pm['dateline'] + $timeoffset * 3600)."\n".
"".nl2br(dhtmlspecialchars(trim($pm['message'])))."\n".
"$lang[reply]\n".
"$lang[delete]\n".
"$lang[pm_all]";
$db->query("UPDATE {$tablepre}pms SET new='0' WHERE pmid='$pmid'");
} elseif($do == 'send') {
if(empty($msgto)) {
if(!empty($pmid)) {
$pm = $db->fetch_first("SELECT msgfrom, subject FROM {$tablepre}pms WHERE pmid='$pmid' AND msgtoid='$discuz_uid' AND folder='inbox'");
$pm['subject'] = 'Re: '.$pm['subject'];
} else {
$pm = array('msgfrom' => '', 'subject' => '');
}
echo "$lang[pm_to]:\n".
"$lang[subject]:\n".
"$lang[message]:\n".
"$lang[submit]".
"\n".
"\n".
"\n".
"\n".
"\n".
"\n";
} else {
$floodctrl = $floodctrl * 2;
if($floodctrl && !$disablepostctrl && $timestamp - $lastpost < $floodctrl) {
wapmsg('pm_flood_ctrl');
}
if($formhash != formhash()) {
wapmsg('wap_submit_invalid');
}
$member = $db->fetch_first("SELECT m.uid AS msgtoid, mf.ignorepm FROM {$tablepre}members m
LEFT JOIN {$tablepre}memberfields mf USING (uid)
WHERE username='$msgto'");
if(!$member) {
wapmsg('pm_send_nonexistence');
}
if(preg_match("/(^{ALL}$|(,|^)\s*".preg_quote($discuz_user, '/')."\s*(,|$))/i", $member['ignorepm'])) {
wapmsg('pm_send_ignore');
}
if(empty($subject) || empty($message)) {
wapmsg('pm_sm_isnull');
}
$subject = dhtmlspecialchars(cutstr(trim($subject), 75));
$db->query("INSERT INTO {$tablepre}pms (msgfrom, msgfromid, msgtoid, folder, new, subject, dateline, message)
VALUES('$discuz_user', '$discuz_uid', '$member[msgtoid]', 'inbox', '1', '$subject', '$timestamp', '$message')");
$db->query("UPDATE {$tablepre}members SET newpm='1' WHERE uid='$member[msgtoid]'", 'UNBUFFERED');
if($floodctrl) {
$db->query("UPDATE {$tablepre}members SET lastpost='$timestamp' WHERE uid='$discuz_uid'");
}
wapmsg('pm_send_succeed', array('title' => 'pm_home', 'link' => "index.php?action=pm"));
}
} elseif($do == 'delete') {
if(!empty($pmid)) {
$db->query("DELETE FROM {$tablepre}pms WHERE pmid='$pmid' AND msgtoid='$discuz_uid' AND folder='inbox'");
wapmsg('pm_delete_succeed');
} else {
if(empty($confirm)) {
echo "$lang[pm_delete_confirm]";
} else {
$db->query("DELETE FROM {$tablepre}pms WHERE new='0' AND msgtoid='$discuz_uid' AND folder='inbox'");
wapmsg('pm_delete_succeed');
}
}
}
echo "$lang[pm_home]\n";
}
?>