<?php
!defined('IN_MYMPS') && exit('FORBIDDEN');
require MYMPS_DATA."/config.db.php";
require MYMPS_INC."/db.class.php";
require MYMPS_INC."/member.class.php";
if(!$member_log->chk_in()) write_msg("对不起,您还没有登录！");

$row = $db -> getRow("SELECT score FROM `{$db_mymps}member` WHERE userid = '$s_uid'");

if($action == 'post'){
	$score = isset($_POST['score']) ? intval($_POST['score']) : '';
	if(!$score) write_msg('请输入您要兑换的积分数额。');
	
	if($score > $row['score']) write_msg('您输入的积分数额已经超过您的用户积分');
	$coin = floor($score/$mymps_global['cfg_score_fee']);
	if(empty($coin)) write_msg('兑换失败，请重新设置有效的兑换积分');
	$truescore = $coin*$mymps_global['cfg_score_fee'];
	$db -> query("UPDATE `{$db_mymps}member` SET score = score - ".$truescore.",money_own=money_own + ".$coin." WHERE userid = '$s_uid'");
	
	write_msg('兑换成功! 您的帐户已成功增加<font color=red>'.$coin.'</font>金币','olmsg');
} else {
	/*积分变化参数配置*/
	$score_change = get_credit_score();
	$array = array(
			'注册成功'=>'register',
			'登录成功'=>'login',
			'发布分类信息'=>'information',
			'营业执照认证'=>'com_certify',
			'身份证认证'=>'per_certify'
			
	);
	
	@include MYMPS_DATA.'/caches/plugin.php';
	$pluginsettings = $data;
	unset($data);
	
	if(is_array($pluginsettings)){
		foreach($pluginsettings as $k => $v){
			if($v['disable'] != 1 && $v['flag'] != 'news'){
				$array['发布'.$v['name']] = $v['flag'];
			}
		}
	}
	include MYMPS_ROOT.'/template/box/score_coin.tpl.php';
}
$row = $coin = $score = NULL;
?>