fetch_first("SELECT mf.nickname, m.gender, m.groupid
FROM {$tablepre}memberfields mf, {$tablepre}members m WHERE m.uid='$discuz_uid' AND mf.uid=m.uid");
} else {
$member = array('nickname' => '');
}
$validating = array();
if($regverify == 2 && $groupid == 8) {
if($validating = $db->fetch_first("SELECT * FROM {$tablepre}validating WHERE uid='$discuz_uid'")) {
$validating['moddate'] = $validating['moddate'] ? gmdate("$dateformat $timeformat", $validating['moddate'] + $timeoffset * 3600) : 0;
$validating['adminenc'] = rawurlencode($validating['admin']);
}
}
$member = $db->fetch_first("SELECT uid, posts, digestposts, oltime, regdate, regip, lastvisit, lastip, lastpost FROM {$tablepre}members WHERE uid='$discuz_uid'");
$member['postperday'] = $timestamp - $member['regdate'] > 86400 ? round(86400 * $member['posts'] / ($timestamp - $member['regdate']), 2) : $member['posts'];
$member['regdate'] = gmdate("$dateformat", $member['regdate'] + $timeoffset * 3600);
$member['lastvisit'] = gmdate("$dateformat $timeformat", $member['lastvisit'] + ($timeoffset * 3600));
$member['lastpost'] = $member['lastpost'] ? gmdate("$dateformat $timeformat", $member['lastpost'] + ($timeoffset * 3600)) : 'x';
require_once DISCUZ_ROOT.'./include/misc.func.php';
$member['regiplocation'] = convertip($member['regip']);
$member['lastiplocation'] = convertip($member['lastip']);
$loglist = array();
$query = $db->query("SELECT * FROM {$tablepre}creditslog WHERE uid='$discuz_uid' ORDER BY dateline DESC LIMIT 10");
while($log = $db->fetch_array($query)) {
$log['fromtoenc'] = rawurlencode($log['fromto']);
$log['dateline'] = gmdate("$dateformat $timeformat", $log['dateline'] + $timeoffset * 3600);
$loglist[] = $log;
}
if($creditspolicy['promotion_visit'] || $creditspolicy['promotion_register']) {
$promotion_visit = $promotion_register = $space = '';
foreach(array('promotion_visit', 'promotion_register') as $val) {
if(!empty($creditspolicy[$val]) && is_array($creditspolicy[$val])) {
foreach($creditspolicy[$val] as $id => $policy) {
$$val .= $space.$extcredits[$id]['title'].' +'.$policy;
$space = ' ';
}
}
}
}
include template('memcp_home');
} elseif($action == 'profile') {
$typeid = empty($typeid) || !in_array($typeid, array(1, 2, 3, 4, 5, 6)) ? 2 : $typeid;
require_once DISCUZ_ROOT.'./forumdata/cache/cache_profilefields.php';
$member = $db->fetch_first("SELECT * FROM {$tablepre}members m
LEFT JOIN {$tablepre}memberfields mf ON mf.uid=m.uid
WHERE m.uid='$discuz_uid'");
$seccodecheck = ($seccodestatus & 8) && (!$seccodedata['minposts'] || $posts < $seccodedata['minposts']);
$secqaacheck = false;
if(!submitcheck('editsubmit', 0, $seccodecheck)) {
require_once DISCUZ_ROOT.'./include/editor.func.php';
if($typeid == 1) {
if($seccodecheck) {
$seccode = random(6, 1) + $seccode{0} * 1000000;
}
} elseif($typeid == 2) {
$gendercheck = array($member['gender'] => 'checked="checked"');
} elseif($typeid == 4) {
$bio = explode("\t\t\t", $member['bio']);
$member['bio'] = html2bbcode($bio[0]);
$member['biotrade'] = html2bbcode($bio[1]);
$member['signature'] = html2bbcode($member['sightml']);
} elseif($typeid == 5) {
$invisiblechecked = $member['invisible'] ? 'checked="checked"' : '';
$emailchecked = $member['showemail'] ? 'checked="checked"' : '';
$newschecked = $member['newsletter'] ? 'checked="checked"' : '';
$tppchecked = array($member['tpp'] => 'selected="selected"');
$pppchecked = array($member['ppp'] => 'selected="selected"');
$toselect = array(strval((float)$member['timeoffset']) => 'selected="selected"');
$pscheck = array(intval($member['pmsound']) => 'checked="checked"');
$emcheck = array($member['editormode'] => 'selected="selected"');
$tfcheck = array($member['timeformat'] => 'checked="checked"');
$dfcheck = array($member['dateformat'] => 'selected="selected"');
$styleselect = '';
$query = $db->query("SELECT styleid, name FROM {$tablepre}styles WHERE available='1'");
while($style = $db->fetch_array($query)) {
$styleselect .= "\n";
}
$customshow = str_pad(base_convert($member['customshow'], 10, 3), 3, 0, STR_PAD_LEFT);
$sschecked = array($customshow{0} => 'selected="selected"');
$sachecked = array($customshow{1} => 'selected="selected"');
$sichecked = array($customshow{2} => 'selected="selected"');
$dateformatlist = array();
if(!empty($userdateformat) && ($count = count($userdateformat))) {
for($num =1; $num <= $count; $num ++) {
$dateformatlist[$num] = str_replace(array('n', 'j', 'y', 'Y'), array('mm', 'dd', 'yy', 'yyyy'), $userdateformat[$num-1]);
}
}
$feedchecks = array();
$customaddfeed = intval($member['customaddfeed']);
if($customaddfeed > 0) {
$customaddfeed = sprintf('%03b', $customaddfeed);
for($i = 1; $i <= 3; $i++) {
$feedchecks[$i] = $customaddfeed[3 - $i] ? 'checked="checked"' : '';
}
}
$defaultcheck = $customaddfeed == 0 ? 'checked="checked"' : '';
$customcheck = $feedchecks ? 'checked="checked"' : '';
$showfeedcheck = $customaddfeed == 0 ? 'none' : '';
} elseif($typeid == 6) {
require_once DISCUZ_ROOT.'/uc_client/client.php';
$uc_avatarflash = uc_avatar($discuz_uid);
}
include template('memcp_profile');
} else {
require_once DISCUZ_ROOT.'./include/discuzcode.func.php';
$membersql = $memberfieldsql = $authstradd1 = $authstradd2 = $newpasswdadd = '';
if($typeid == 1) {
$emailnew = dhtmlspecialchars($emailnew);
if($questionidnew == -1) {
$secquesnew = $discuz_secques;
$questionidnew = $answernew = '';
} else {
$secquesnew = quescrypt($questionidnew, $answernew);
}
if(($adminid == 1 || $adminid == 2 || $adminid == 3) && !$secquesnew && $admincp['forcesecques']) {
showmessage('profile_admin_security_invalid');
}
if(!empty($newpassword) && $newpassword != $newpassword2) {
showmessage('profile_passwd_notmatch');
}
require_once DISCUZ_ROOT.'./uc_client/client.php';
$ucresult = uc_user_edit($discuz_user, $oldpassword, $newpassword, $emailnew);
if($ucresult == -1) {
showmessage('profile_passwd_wrong', NULL, 'HALTED');
} elseif($ucresult == -4) {
showmessage('profile_email_illegal');
} elseif($ucresult == -5) {
showmessage('profile_email_domain_illegal');
} elseif($ucresult == -6) {
showmessage('profile_email_duplicate');
}
if(!empty($newpassword)) {
$newpasswdadd = ", password='".md5(random(10))."'";
}
if($regverify == 1 && $adminid == 0 && (($grouptype == 'member' && $adminid == 0) || $groupid == 8)) {
$idstring = random(6);
$groupid = 8;
require_once DISCUZ_ROOT.'./forumdata/cache/usergroup_8.php';
$authstradd1 = ", groupid='8'";
$authstradd2 = "authstr='$timestamp\t2\t$idstring'";
sendmail("$discuz_userss <$emailnew>", 'email_verify_subject', 'email_verify_message');
}
$membersql = "secques='$secquesnew', email='$emailnew' $newpasswdadd $authstradd1";
$memberfieldsql = $authstradd2;
} elseif($typeid == 2) {
$censorexp = '/^('.str_replace(array('\\*', "\r\n", ' '), array('.*', '|', ''), preg_quote(($censoruser = trim($censoruser)), '/')).')$/i';
if($censoruser && (@preg_match($censorexp, $nicknamenew) || @preg_match($censorexp, $cstatusnew))) {
showmessage('profile_nickname_cstatus_illegal');
}
if($msnnew && !isemail($msnnew)) {
showmessage('profile_alipay_msn');
}
if($alipaynew && !isemail($alipaynew)) {
showmessage('profile_alipay_illegal');
}
$sitenew = dhtmlspecialchars(trim(preg_match("/^https?:\/\/.+/i", $sitenew) ? $sitenew : ($sitenew ? 'http://'.$sitenew : '')));
$icqnew = preg_match ("/^([0-9]+)$/", $icqnew) && strlen($icqnew) >= 5 && strlen($icqnew) <= 12 ? $icqnew : '';
$qqnew = preg_match ("/^([0-9]+)$/", $qqnew) && strlen($qqnew) >= 5 && strlen($qqnew) <= 12 ? $qqnew : '';
$bdaynew = datecheck($bdaynew) ? $bdaynew : '0000-00-00';
$yahoonew = dhtmlspecialchars($yahoonew);
$msnnew = dhtmlspecialchars($msnnew);
$taobaonew = dhtmlspecialchars($taobaonew);
$alipaynew = dhtmlspecialchars($alipaynew);
$nicknamenew = $allownickname ? cutstr(censor(dhtmlspecialchars($nicknamenew)), 30) : '';
$cstatusadd = $allowcstatus ? ', customstatus=\''.cutstr(censor(dhtmlspecialchars($cstatusnew)), 30).'\'' : '';
$gendernew = empty($gendernew) ? 0 : intval($gendernew);
$locationnew = cutstr(censor(dhtmlspecialchars($locationnew)), 30);
$membersql = "gender='$gendernew', bday='$bdaynew'";
$memberfieldsql = "nickname='$nicknamenew', site='$sitenew', location='$locationnew', icq='$icqnew', qq='$qqnew', yahoo='$yahoonew', msn='$msnnew', taobao='$taobaonew', alipay='$alipaynew' $cstatusadd";
} elseif($typeid == 3 && ($_DCACHE['fields_required'] || $_DCACHE['fields_optional'])) {
$fieldadd = array();
foreach(array_merge($_DCACHE['fields_required'], $_DCACHE['fields_optional']) as $field) {
$field_key = 'field_'.$field['fieldid'];
$field_val = trim(${'field_'.$field['fieldid'].'new'});
if($field['required'] && $field_val == '' && !($field['unchangeable'] && $member[$field_key])) {
showmessage('profile_required_info_invalid');
} elseif($field['selective'] && $field_val != '' && !isset($field['choices'][$field_val])) {
showmessage('undefined_action', NULL, 'HALTED');
} elseif(!$field['unchangeable'] || !$member[$field_key]) {
$fieldadd[] = "$field_key='".dhtmlspecialchars($field_val)."'";
}
}
$memberfieldsql = implode(', ', $fieldadd);
} elseif($typeid == 4) {
if($maxsigsize) {
if(strlen($signaturenew) > $maxsigsize) {
showmessage('profile_sig_toolong');
}
} else {
$signaturenew = '';
}
$signaturenew = censor($signaturenew);
$sigstatusnew = $signaturenew ? 1 : 0;
$bionew = censor(dhtmlspecialchars($bionew));
$sightmlnew = addslashes(discuzcode(stripslashes($signaturenew), 1, 0, 0, 0, $allowsigbbcode, $allowsigimgcode, 0, 0, 1));
$biohtmlnew = addslashes(discuzcode(stripslashes($bionew), 1, 0, 0, 0, $allowbiobbcode, $allowbioimgcode, 0, 0, 1));
$biohtmlnew .= "\t\t\t".addslashes(discuzcode(stripslashes($biotradenew), 1, 0, 0, 0, 1, 1, 0, 0, 1));
$membersql = "sigstatus='$sigstatusnew'";
$memberfieldsql = "bio='$biohtmlnew', sightml='$sightmlnew'";
} else {
$tppnew = in_array($tppnew, array(10, 20, 30)) ? $tppnew : 0;
$pppnew = in_array($pppnew, array(5, 10, 15)) ? $pppnew : 0;
$editormodenew = in_array($editormodenew, array(0, 1, 2)) ? $editormodenew : 2;
$ssnew = in_array($ssnew, array(0, 1)) ? $ssnew : 2;
$sanew = in_array($sanew, array(0, 1)) ? $sanew : 2;
$sinew = in_array($sinew, array(0, 1)) ? $sinew : 2;
$customshownew = base_convert($ssnew.$sanew.$sinew, 3, 10);
$dateformatnew = ($dateformatnew = intval($dateformatnew)) && !empty($userdateformat[$dateformatnew -1]) ? $dateformatnew : 0;
$invisiblenew = $allowinvisible && $invisiblenew ? 1 : 0;
$showemailnew = empty($showemailnew) ? 0 : 1;
$styleid = empty($styleidnew) ? $styleid : $styleidnew;
if($customaddfeednew) {
$customaddfeednew = $addfeed[1] || $addfeed[2] ||$addfeed[3] ? bindec(intval($addfeed[3]).intval($addfeed[2]).intval($addfeed[1])) : '-1';
}
$membersql = "styleid='$styleidnew', showemail='$showemailnew', timeoffset='$timeoffsetnew', tpp='$tppnew', ppp='$pppnew', editormode='$editormodenew', customshow='$customshownew', newsletter='$newsletternew', invisible='$invisiblenew', timeformat='$timeformatnew', dateformat='$dateformatnew', pmsound='$pmsoundnew', customaddfeed='$customaddfeednew'";
}
if($membersql) {
$db->query("UPDATE {$tablepre}members SET $membersql WHERE uid='$discuz_uid'");
}
$query = $db->query("SELECT uid FROM {$tablepre}memberfields WHERE uid='$discuz_uid'");
if(!$db->num_rows($query)) {
$db->query("REPLACE INTO {$tablepre}memberfields (uid) VALUES ('$discuz_uid')");
}
if($memberfieldsql) {
$db->query("UPDATE {$tablepre}memberfields SET $memberfieldsql WHERE uid='$discuz_uid'");
}
if($type == 1 && !empty($authstradd1) && !empty($authstradd2)) {
showmessage('profile_email_verify');
} else {
showmessage('profile_succeed', 'memcp.php?action=profile&typeid='.$typeid);
}
}
} elseif($action == 'credits') {
$taxpercent = sprintf('%1.2f', $creditstax * 100).'%';
if(!$operation) {
if($exchangestatus) {
$operation = 'exchange';
} elseif($transferstatus) {
$operation = 'transfer';
} elseif($ec_ratio) {
$operation = 'addfunds';
}
}
if($operation == 'transfer' && $transferstatus) {
if(!submitcheck('creditssubmit')) {
include template('memcp_credits');
} else {
$amount = intval($amount);
require_once DISCUZ_ROOT.'./uc_client/client.php';
$ucresult = uc_user_login($discuz_user, $password);
list($tmp['uid']) = daddslashes($ucresult);
if($tmp['uid'] <= 0) {
showmessage('credits_password_invalid');
} elseif($amount <= 0) {
showmessage('credits_transaction_amount_invalid');
} elseif(${'extcredits'.$creditstrans} - $amount < ($minbalance = $transfermincredits)) {
showmessage('credits_balance_insufficient');
} elseif(!($netamount = floor($amount * (1 - $creditstax)))) {
showmessage('credits_net_amount_iszero');
}
$member = $db->fetch_first("SELECT uid, username FROM {$tablepre}members WHERE username='$to'");
if(!$member) {
showmessage('credits_transfer_send_nonexistence');
} elseif($member['uid'] == $discuz_uid) {
showmessage('credits_transfer_self');
}
$db->query("UPDATE {$tablepre}members SET extcredits$creditstrans=extcredits$creditstrans-'$amount' WHERE uid='$discuz_uid'");
$db->query("UPDATE {$tablepre}members SET extcredits$creditstrans=extcredits$creditstrans+'$netamount' WHERE uid='$member[uid]'");
$db->query("INSERT INTO {$tablepre}creditslog (uid, fromto, sendcredits, receivecredits, send, receive, dateline, operation)
VALUES ('$discuz_uid', '".addslashes($member['username'])."', '$creditstrans', '$creditstrans', '$amount', '0', '$timestamp', 'TFR'),
('$member[uid]', '$discuz_user', '$creditstrans', '$creditstrans', '0', '$netamount', '$timestamp', 'RCV')");
if(!empty($transfermessage)) {
$transfermessage = stripslashes($transfermessage);
$transfertime = gmdate($GLOBALS['_DCACHE']['settings']['dateformat'].' '.$GLOBALS['_DCACHE']['settings']['timeformat'], $timestamp + $timeoffset * 3600);
sendpm($member['uid'], 'transfer_subject', 'transfer_message');
}
showmessage('credits_transaction_succeed', 'memcp.php?action=creditslog&operation=creditslog');
}
} elseif($operation == 'exchange' && $exchangestatus) {
if(!submitcheck('creditssubmit')) {
$extcredits_exchange = array();
if(!empty($extcredits)) {
foreach($extcredits as $key => $value) {
if($value['allowexchangein'] || $value['allowexchangeout']) {
$extcredits_exchange['extcredits'.$key] = array('title' => $value['title'], 'unit' => $value['unit']);
}
}
}
include template('memcp_credits');
} elseif($extcredits[$fromcredits]['outratio'] || $extcredits[$fromcredits]['ratio'] && $extcredits[$tocredits]['ratio']) {
$outexange = strexists($tocredits, '|');
if(!$outexange && !$extcredits[$tocredits]['ratio']) {
showmessage('credits_exchange_invalid');
}
$amount = intval($amount);
require_once DISCUZ_ROOT.'./uc_client/client.php';
$ucresult = uc_user_login($discuz_user, $password);
list($tmp['uid']) = daddslashes($ucresult);
if($tmp['uid'] <= 0) {
showmessage('credits_password_invalid');
} elseif($fromcredits == $tocredits) {
showmessage('credits_exchange_invalid');
} elseif($amount <= 0) {
showmessage('credits_transaction_amount_invalid');
} elseif(${'extcredits'.$fromcredits} - $amount < ($minbalance = $exchangemincredits)) {
showmessage('credits_balance_insufficient');
} elseif(!$outexange && !($netamount = floor($amount * $extcredits[$fromcredits]['ratio'] * (1 - $creditstax) / $extcredits[$tocredits]['ratio']))) {
showmessage('credits_net_amount_iszero');
}
if(!$extcredits[$fromcredits]['allowexchangeout']) {
showmessage('extcredits_disallowexchangeout');
}
if(!$outexange && !$extcredits[$tocredits]['allowexchangein']) {
showmessage('extcredits_disallowexchangein');
}
if(!$outexange) {
$db->query("UPDATE {$tablepre}members SET extcredits$fromcredits=extcredits$fromcredits-'$amount', extcredits$tocredits=extcredits$tocredits+'$netamount' WHERE uid='$discuz_uid'");
} else {
if($outextcredits[$tocredits]['creditsrc'] != $fromcredits) {
showmessage('extcredits_dataerror', NULL, 'HALTED');
}
$netamount = floor($amount * $extcredits[$fromcredits]['outratio'] / $outextcredits[$tocredits]['ratio']);
list($toappid, $tocredits) = explode('|', $tocredits);
$ucresult = uc_credit_exchange_request($discuz_uid, $fromcredits, $tocredits, $toappid, $netamount);
if(!$ucresult) {
showmessage('extcredits_dataerror', NULL, 'HALTED');
}
$db->query("UPDATE {$tablepre}members SET extcredits$fromcredits=extcredits$fromcredits-'$amount' WHERE uid='$discuz_uid'");
$netamount = $tocredits = 0;
}
$db->query("INSERT INTO {$tablepre}creditslog (uid, fromto, sendcredits, receivecredits, send, receive, dateline, operation)
VALUES ('$discuz_uid', '$discuz_user', '$fromcredits', '$tocredits', '$amount', '$netamount', '$timestamp', 'EXC')");
showmessage('credits_transaction_succeed', 'memcp.php?action=creditslog&operation=creditslog');
}
} elseif($operation == 'addfunds' && $ec_ratio) {
if(!submitcheck('creditssubmit')) {
include template('memcp_credits');
} else {
include language('misc');
$amount = intval($amount);
if(!$amount || ($ec_mincredits && $amount < $ec_mincredits) || ($ec_maxcredits && $amount > $ec_maxcredits)) {
showmessage('credits_addfunds_amount_invalid');
}
if($db->result_first("SELECT COUNT(*) FROM {$tablepre}orders WHERE uid='$discuz_uid' AND submitdate>='$timestamp'-180 LIMIT 1")) {
showmessage('credits_addfunds_ctrl');
}
if($ec_maxcreditspermonth) {
$query = $db->query("SELECT SUM(amount) FROM {$tablepre}orders WHERE uid='$discuz_uid' AND submitdate>='$timestamp'-2592000 AND status IN (2, 3)");
if(($db->result($query, 0)) + $amount > $ec_maxcreditspermonth) {
showmessage('credits_addfunds_toomuch');
}
}
$price = ceil($amount / $ec_ratio * 100) / 100;
$orderid = '';
//$apitype = 'tenpay';
require_once DISCUZ_ROOT.'./include/trade.func.php';
$requesturl = credit_payurl($price, $orderid);
$query = $db->query("SELECT orderid FROM {$tablepre}orders WHERE orderid='$orderid'");
if($db->num_rows($query)) {
showmessage('credits_addfunds_order_invalid');
}
$db->query("INSERT INTO {$tablepre}orders (orderid, status, uid, amount, price, submitdate)
VALUES ('$orderid', '1', '$discuz_uid', '$amount', '$price', '$timestamp')");
showmessage('credits_addfunds_succeed', $requesturl);
}
} else {
showmessage('action_closed', NULL, 'HALTED');
}
} elseif($action == 'creditslog') {
if($operation == 'paymentlog') {
$page = max(1, intval($page));
$start_limit = ($page - 1) * $tpp;
$query = $db->query("SELECT COUNT(*) FROM {$tablepre}paymentlog WHERE uid='$discuz_uid'");
$multipage = multi($db->result($query, 0), $tpp, $page, "memcp.php?action=creditslog&operation=paymentlog");
$totalamount = $db->result($query, 1);
$loglist = array();
$query = $db->query("SELECT p.*, f.fid, f.name, t.subject, t.author, t.dateline AS tdateline FROM {$tablepre}paymentlog p
LEFT JOIN {$tablepre}threads t ON t.tid=p.tid
LEFT JOIN {$tablepre}forums f ON f.fid=t.fid
WHERE p.uid='$discuz_uid' ORDER BY p.dateline DESC
LIMIT $start_limit, $tpp");
while($log = $db->fetch_array($query)) {
$log['authorenc'] = rawurlencode($log['authorenc']);
$log['dateline'] = gmdate("$dateformat $timeformat", $log['dateline'] + $timeoffset * 3600);
$log['tdateline'] = gmdate("$dateformat $timeformat", $log['tdateline'] + $timeoffset * 3600);
$loglist[] = $log;
}
include template('memcp_credits');
} elseif($operation == 'incomelog') {
$page = max(1, intval($page));
$start_limit = ($page - 1) * $tpp;
$query = $db->query("SELECT COUNT(*) FROM {$tablepre}paymentlog WHERE authorid='$discuz_uid'");
$multipage = multi($db->result($query, 0), $tpp, $page, "memcp.php?action=creditslog&operation=incomelog");
$loglist = array();
$query = $db->query("SELECT p.*, m.username, f.fid, f.name, t.subject, t.dateline AS tdateline FROM {$tablepre}paymentlog p
LEFT JOIN {$tablepre}threads t ON t.tid=p.tid
LEFT JOIN {$tablepre}forums f ON f.fid=t.fid
LEFT JOIN {$tablepre}members m ON m.uid=p.uid
WHERE p.authorid='$discuz_uid' ORDER BY p.dateline DESC
LIMIT $start_limit, $tpp");
while($log = $db->fetch_array($query)) {
$log['dateline'] = gmdate("$dateformat $timeformat", $log['dateline'] + $timeoffset * 3600);
$log['tdateline'] = gmdate("$dateformat $timeformat", $log['tdateline'] + $timeoffset * 3600);
$loglist[] = $log;
}
include template('memcp_credits');
} elseif($operation == 'attachpaymentlog') {
$page = max(1, intval($page));
$start_limit = ($page - 1) * $tpp;
$query = $db->query("SELECT COUNT(*) FROM {$tablepre}attachpaymentlog WHERE uid='$discuz_uid'");
$multipage = multi($db->result($query, 0), $tpp, $page, "memcp.php?action=creditslog&operation=attachpaymentlog");
$loglist = array();
$query = $db->query("SELECT ap.*, a.filename, a.pid, a.dateline as adateline, t.subject, t.tid, m.username FROM {$tablepre}attachpaymentlog ap
LEFT JOIN {$tablepre}attachments a ON a.aid=ap.aid
LEFT JOIN {$tablepre}threads t ON t.tid=a.tid
LEFT JOIN {$tablepre}members m ON m.uid=ap.authorid
WHERE ap.uid='$discuz_uid' ORDER BY ap.dateline DESC
LIMIT $start_limit, $tpp");
while($log = $db->fetch_array($query)) {
$log['dateline'] = gmdate("$dateformat $timeformat", $log['dateline'] + $timeoffset * 3600);
$log['adateline'] = gmdate("$dateformat $timeformat", $log['adateline'] + $timeoffset * 3600);
$loglist[] = $log;
}
include template('memcp_credits');
} elseif($operation == 'attachincomelog') {
$page = max(1, intval($page));
$start_limit = ($page - 1) * $tpp;
$query = $db->query("SELECT COUNT(*) FROM {$tablepre}attachpaymentlog WHERE authorid='$discuz_uid'");
$multipage = multi($db->result($query, 0), $tpp, $page, "memcp.php?action=creditslog&operation=attachincomelog");
$totalamount = $db->result($query, 1);
$loglist = array();
$query = $db->query("SELECT ap.*, a.filename, a.pid, a.dateline as adateline, t.subject, t.tid, m.username FROM {$tablepre}attachpaymentlog ap
LEFT JOIN {$tablepre}attachments a ON a.aid=ap.aid
LEFT JOIN {$tablepre}threads t ON t.tid=a.tid
LEFT JOIN {$tablepre}members m ON m.uid=ap.uid
WHERE ap.authorid='$discuz_uid' ORDER BY ap.dateline DESC
LIMIT $start_limit, $tpp");
while($log = $db->fetch_array($query)) {
$log['dateline'] = gmdate("$dateformat $timeformat", $log['dateline'] + $timeoffset * 3600);
$log['adateline'] = gmdate("$dateformat $timeformat", $log['adateline'] + $timeoffset * 3600);
$loglist[] = $log;
}
include template('memcp_credits');
} elseif($operation == 'rewardpaylog') {
$page = max(1, intval($page));
$start_limit = ($page - 1) * $tpp;
$query = $db->query("SELECT COUNT(*) FROM {$tablepre}rewardlog WHERE authorid='$discuz_uid'");
$multipage = multi($db->result($query, 0), $tpp, $page, "memcp.php?action=creditslog&operation=incomelog");
$loglist = array();
$query = $db->query("SELECT
r.*, m.uid, m.username
, f.fid, f.name, t.subject, t.price
FROM
{$tablepre}rewardlog r
LEFT JOIN {$tablepre}threads t ON t.tid=r.tid
LEFT JOIN {$tablepre}forums f ON f.fid=t.fid
LEFT JOIN {$tablepre}members m ON m.uid=r.answererid
WHERE r.authorid='$discuz_uid' ORDER BY r.dateline DESC
LIMIT $start_limit, $tpp");
while($log = $db->fetch_array($query)) {
$log['dateline'] = gmdate("$dateformat $timeformat", $log['dateline'] + $timeoffset * 3600);
$log['price'] = abs($log['price']);
$loglist[] = $log;
}
include template('memcp_credits');
} elseif($operation == 'rewardincomelog') {
$page = max(1, intval($page));
$start_limit = ($page - 1) * $tpp;
$query = $db->query("SELECT COUNT(*) FROM {$tablepre}rewardlog WHERE answererid='$discuz_uid'");
$multipage = multi($db->result($query, 0), $tpp, $page, "memcp.php?action=creditslog&operation=incomelog");
$loglist = array();
$query = $db->query("SELECT r.*, m.uid, m.username, f.fid, f.name, t.subject, t.price FROM {$tablepre}rewardlog r
LEFT JOIN {$tablepre}threads t ON t.tid=r.tid
LEFT JOIN {$tablepre}forums f ON f.fid=t.fid
LEFT JOIN {$tablepre}members m ON m.uid=r.authorid
WHERE r.answererid='$discuz_uid' and r.authorid>0 ORDER BY r.dateline DESC
LIMIT $start_limit, $tpp");
while($log = $db->fetch_array($query)) {
$log['dateline'] = gmdate("$dateformat $timeformat", $log['dateline'] + $timeoffset * 3600);
$log['price'] = abs($log['price']);
$loglist[] = $log;
}
include template('memcp_credits');
} else {
$operation = 'creditslog';
$page = max(1, intval($page));
$start_limit = ($page - 1) * $tpp;
$query = $db->query("SELECT COUNT(*) FROM {$tablepre}creditslog WHERE uid='$discuz_uid'");
$multipage = multi($db->result($query, 0), $tpp, $page, "memcp.php?action=creditslog&operation=creditslog");
$loglist = array();
$query = $db->query("SELECT * FROM {$tablepre}creditslog WHERE uid='$discuz_uid' ORDER BY dateline DESC LIMIT $start_limit, $tpp");
while($log = $db->fetch_array($query)) {
$log['fromtoenc'] = rawurlencode($log['fromto']);
$log['dateline'] = gmdate("$dateformat $timeformat", $log['dateline'] + $timeoffset * 3600);
$loglist[] = $log;
}
include template('memcp_credits');
}
} elseif($action == 'usergroups') {
if(!$allowmultigroups) {
showmessage('group_nopermission', NULL, 'NOPERM');
}
$switchmaingroup = $grouppublic || $grouptype == 'member' ? 1 : 0;
if(empty($type)) {
$groupterms = unserialize($db->result_first("SELECT groupterms FROM {$tablepre}memberfields WHERE uid='$discuz_uid'"));
$grouplist = array();
$extgroupidarray = explode("\t", $extgroupids);
$query = $db->query("SELECT groupid, grouptitle, type, system, allowmultigroups FROM {$tablepre}usergroups WHERE (type='special' AND system<>'private' AND radminid='0') OR (type='member' AND '$credits'>=creditshigher AND '$credits'fetch_array($query)) {
if(in_array($group['groupid'], $extgroupidarray) && ($group['groupid'] == $groupid || ($group['type'] != 'member' && $group['system'] == 'private'))) {
$group['grouptitle'] = ''.$group['grouptitle'].'';
} elseif(!$group['allowmultigroups']) {
$group['grouptitle'] = ''.$group['grouptitle'].'';
}
$group['mainselected'] = $group['groupid'] == $groupid ? 'checked="checked"' : '';
$group['maindisabled'] = $switchmaingroup && (($group['system'] != 'private' && ($group['system'] == "0\t0" || $group['groupid'] == $groupid || in_array($group['groupid'], $extgroupidarray))) || $group['type'] == 'member') ? '' : 'disabled';
$group['dailyprice'] = $group['minspan'] = 0;
if($group['system'] != 'private') {
list($group['dailyprice'], $group['minspan']) = explode("\t", $group['system']);
}
if($group['groupid'] == $groupid && !empty($groupterms['main'])) {
$group['expiry'] = gmdate($dateformat, $groupterms['main']['time'] + $timeoffset * 3600);
} elseif(isset($groupterms['ext'][$group['groupid']])) {
$group['expiry'] = gmdate($dateformat, $groupterms['ext'][$group['groupid']] + $timeoffset * 3600);
} else {
$group['expiry'] = 'N/A';
}
$grouplist[$group['groupid']] = $group;
}
include template('memcp_usergroups');
} else {
if($type == 'main' && submitcheck('groupsubmit') && $switchmaingroup) {
$group = $db->fetch_first("SELECT groupid, type, system, grouptitle FROM {$tablepre}usergroups WHERE groupid='$groupidnew' AND (".($extgroupids ? 'groupid IN ('.str_replace("\t", ',', $extgroupids).') OR ' : '')."(type='special' AND system='0\t0' AND radminid='0') OR (type='member' AND '$credits'>=creditshigher AND '$credits'query("UPDATE {$tablepre}members SET groupid='$groupidnew', adminid='$adminidnew', extgroupids='$extgroupidsnew' WHERE uid='$discuz_uid'");
showmessage('usergroups_update_succeed', 'memcp.php?action=usergroups');
} elseif($type == 'extended') {
$group = $db->fetch_first("SELECT groupid, type, system, grouptitle FROM {$tablepre}usergroups WHERE groupid='$edit' AND (".($extgroupids ? 'groupid IN ('.str_replace("\t", ',', $extgroupids).') OR ' : '')."(type='special' AND system<>'private' AND radminid='0'))");
if(!$group) {
showmessage('undefined_action', NULL, 'HALTED');
}
$join = !in_array($group['groupid'], explode("\t", $extgroupids));
$group['dailyprice'] = $group['minspan'] = 0;
if($group['system'] != 'private') {
list($group['dailyprice'], $group['minspan']) = explode("\t", $group['system']);
}
if(!isset($extcredits[$creditstrans])) {
showmessage('credits_transaction_disabled');
}
if(!submitcheck('groupsubmit')) {
$group['minamount'] = $group['dailyprice'] * $group['minspan'];
include template('memcp_usergroups');
} else {
$groupterms = unserialize($db->result_first("SELECT groupterms FROM {$tablepre}memberfields WHERE uid='$discuz_uid'"));
if($join) {
$extgroupidsarray = array();
foreach(array_unique(array_merge(explode("\t", $extgroupids), array($edit))) as $extgroupid) {
if($extgroupid) {
$extgroupidsarray[] = $extgroupid;
}
}
$extgroupidsnew = implode("\t", $extgroupidsarray);
if($group['dailyprice']) {
if(($days = intval($days)) < $group['minspan']) {
showmessage('usergroups_span_invalid');
}
if(${'extcredits'.$creditstrans} - ($amount = $days * $group['dailyprice']) < ($minbalance = 0)) {
showmessage('credits_balance_insufficient');
}
$groupexpirynew = $timestamp + $days * 86400;
$groupterms['ext'][$edit] = $groupexpirynew;
$groupexpirynew = groupexpiry($groupterms);
$db->query("UPDATE {$tablepre}members SET groupexpiry='$groupexpirynew', extgroupids='$extgroupidsnew', extcredits$creditstrans=extcredits$creditstrans-'$amount' WHERE uid='$discuz_uid'");
$db->query("UPDATE {$tablepre}memberfields SET groupterms='".addslashes(serialize($groupterms))."' WHERE uid='$discuz_uid'");
$db->query("INSERT INTO {$tablepre}creditslog (uid, fromto, sendcredits, receivecredits, send, receive, dateline, operation)
VALUES ('$discuz_uid', '$discuz_user', '$creditstrans', '0', '$amount', '0', '$timestamp', 'UGP')");
} else {
$db->query("UPDATE {$tablepre}members SET extgroupids='$extgroupidsnew' WHERE uid='$discuz_uid'");
}
showmessage('usergroups_join_succeed', 'memcp.php?action=usergroups');
} else {
if($edit != $groupid) {
if(isset($groupterms['ext'][$edit])) {
unset($groupterms['ext'][$edit]);
}
$groupexpirynew = groupexpiry($groupterms);
$db->query("UPDATE {$tablepre}memberfields SET groupterms='".addslashes(serialize($groupterms))."' WHERE uid='$discuz_uid'");
} else {
$groupexpirynew = 'groupexpiry';
}
$extgroupidsarray = array();
foreach(explode("\t", $extgroupids) as $extgroupid) {
if($extgroupid && $extgroupid != $edit) {
$extgroupidsarray[] = $extgroupid;
}
}
$extgroupidsnew = implode("\t", array_unique($extgroupidsarray));
$db->query("UPDATE {$tablepre}members SET groupexpiry='$groupexpirynew', extgroupids='$extgroupidsnew' WHERE uid='$discuz_uid'");
showmessage('usergroups_exit_succeed', 'memcp.php?action=usergroups');
}
}
} else {
showmessage('usergroups_nonexistence');
}
}
}
?>