<?php
error_reporting(0);
close_browse();
if (!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit();}
global $db, $CcTvAi_com_userid;
$callback=SafeRequest("callback", "get");
if ($CcTvAi_com_userid) {
	if (!IsNumID($CcTvAi_com_userid)) {exit();}
	$cd_path=SafeRequest("skinPath", "post");
	$cd_showtype=SafeRequest("showType", "post");
	if ($cd_showtype) {
		$sql="select cd_id,cd_points,cd_name from " . tname('skin') . " where cd_path='$cd_path'";
		$result=$db->query($sql);
		if ($row=$db->fetch_array($result)) {
			if ($CcTvAi_com_points<$row['cd_points']) {
				die('20005');
			} else {
				$db->query("update " . tname('user') . " set cd_skin='" . $row['cd_id'] . "' where cd_id='$CcTvAi_com_userid'");
				$db->query("update " . tname('user') . " set cd_points=cd_points-" . $row['cd_points'] . " where cd_id='$CcTvAi_com_userid'");
				if($row['cd_points']>=1){
				//记录账单
				$setarr=array(
					'cd_type' => 0, //1为加,0为减
					'cd_uid' => $CcTvAi_com_userid,
					'cd_uname' => $CcTvAi_com_username,
					'cd_icon' => 'skin',
					'cd_title' => '购买空间皮肤【'.$row['cd_name'].'】',
					'cd_points' =>  $row['cd_points'],
					'cd_addtime' => date('Y-m-d H:i:s')
				);
				inserttable('bill', $setarr, 1);
				die('10000');
				}
				die('10000');


			}
		} else {
			die('10004');
		}
	} else {
		$db->query("update " . tname('user') . " set cd_skin='0' where cd_id='$CcTvAi_com_userid'");
		die('10000');
	}
} else {
	die('20001');
}
?>