<?php
/*
转换用户自定义积分：pre_common_count
*/

$query = $xc->db['source']->query("SELECT * FROM {$source_tablepre}credits LIMIT 5") or dexit();
$i = 5;
$ce = array();
while($credit = $xc->db['source']->fetch_array($query)) {
	$extcreditsarray[$i] = array(
		'title'	=> htmlspecialchars(stripslashes($credit['name'])),
		'unit' => htmlspecialchars(stripslashes($credit['unit'])),
		'ratio' => 0,
		'available' => 1,
		'lowerlimit' => 0,
		'showinthread' => 0
	);
	$ce[$credit['cid']] = $i;
	$i++;
}
$ce = serialize($ce);
if($start <= 1) {
	$extcreditsarray[1] = array(
		'title'	=> '威望',
		'unit' => '点',
		'ratio' => 0,
		'available' => 1,
		'lowerlimit' => 0,
		'showinthread' => 1
	);
	$extcreditsarray[2] = array(
		'title'	=> '金钱',
		'unit' => 'RMB',
		'ratio' => 0,
		'available' => 1,
		'lowerlimit' => 0,
		'showinthread' => 1
	);
	$extcreditsarray[3] = array(
		'title'	=> '贡献值',
		'unit' => '点',
		'ratio' => 0,
		'available' => 1,
		'lowerlimit' => 0,
		'showinthread' => 1
	);
	$extcreditsarray[4] = array(
		'title'	=> '银元',
		'unit' => '个',
		'ratio' => 0,
		'available' => 1,
		'lowerlimit' => 0,
		'showinthread' => 1
	);
	$extcreditsarray[5] = array(
		'title'	=> '好评度',
		'unit' => '点',
		'ratio' => 0,
		'available' => 1,
		'lowerlimit' => 0,
		'showinthread' => 1
	);
	$extcredits = addslashes(serialize($extcreditsarray));
	$xc->db['discuz']->query("UPDATE {$discuz_tablepre}common_setting SET svalue='$extcredits' WHERE skey='extcredits'");
}

if($ce) {
	$ce = unserialize($ce);
	$maxuserid = $xc->db['source']->result($xc->db['source']->query("SELECT max(uid) FROM {$source_tablepre}members"), 0);
	if($start < $maxuserid){
		$converted = 1;
	}
	$query = $xc->db['source']->query("SELECT uid FROM {$source_tablepre}members WHERE uid >= $start AND uid < $start + $rpp") or dexit();
	while($user	=	$xc->db['source']->fetch_array($query)) {
		$creditquery = $xc->db['source']->query("SELECT * FROM {$source_tablepre}membercredit WHERE uid='$user[uid]'") or dexit();
		$update = $comma = '';
		while($cresit = $xc->db['source']->fetch_array($creditquery)) {
			if(isset($ce[$cresit[cid]]) && $ce[$cresit[cid]] < 9) {
				$update .= $comma.'extcredits'.$ce[$cresit['cid']].'='.$cresit['value'];
				$comma = ',';
			}
		}
		if($update) {
			if ($xc->db['discuz']->query("UPDATE {$discuz_tablepre}common_member_count SET $update WHERE uid='$user[uid]'")) {
				$convertedrows ++;
			} else {
				reportlog();
			}
			$converted = 1;
			$totalrows ++;
		}
	}
}
?>