<?php
/**
 * @version        Somao_Search X1.0 9:23 2012-1-1 Somao $
 * @package        Somao_Search.Site
 * @copyright      Copyright (c) 2009 - 2012, Somao, Inc.
 * @license        http://www.somao123.com/
 * @link           http://www.somao.cc/
 */
require_once("global.php");
is_login();
$uname=$user["user_name"];
$action=$_REQUEST["action"];
$cardid=$_REQUEST["cardid"];

$row3 = $db->get_one("select * from ve123_member where user_name='$uname'");
$uid = $row3['user_id'];
$points  = $row3['points'];

if($action=="save"){
$imagecode=trim(HtmlReplace($_POST["entered_imagecode"]));
if($_SESSION['dd_ckstr']!=$imagecode)
{
	echo "<script> alert('验证码错误！') ; history.go(-1);</script>";
	exit();
}

$cardid = preg_replace("#[^0-9A-Za-z-]#", "", $cardid);
if(empty($cardid))
{
	echo "<script> alert('卡号为空！！'); history.go(-1);</script>";
    exit();
}
$row = $db->get_one("select * from ve123_moneycard_record where cardid='$cardid'");
if(!is_array($row))
{
	echo "<script> alert('卡号错误：不存在此卡号！');history.go(-1); </script>";
    exit();
}
if($row['isexp']==-1)
{
	echo "<script> alert('此卡号已经失效，不能再次使用！'); history.go(-1);</script>";
    exit();
}
$hasMoney = $row['num'];
$utime=time();

$point=$hasMoney+$points;

$array=array('uid'=>$uid,'isexp'=>-1,'utime'=>$utime);
$db->update("ve123_moneycard_record",$array,"cardid='$cardid'"); 
 
$array2=array('points'=>$point);
$db->update("ve123_member",$array2,"user_name='$uname'");  

$array3=array('card'=>$cardid,'price'=>$hasMoney,'uid'=>$uid,'time'=>$utime);
$db->insert("ve123_moneycard_orders",$array3);  

echo "<script> alert('充值成功，你本次增加的金币为：{$hasMoney} 个！');history.go(-1); </script>";
exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
		<title>首页</title>
         <link href="/css/union.css" rel="stylesheet" type="text/css" />  
	</head>
	<body>
<div id="body">
<form name="formrank" action="" method="post">
    <input type="hidden" name="action" value="save">
<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#39867B">
  <tr>
    <td class="title">用充值卡充值</td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#EFEFEF">
     <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" class="table">
      <tr>
        <td width="11%">&nbsp;</td>
        <td width="89%">&nbsp;</td>
      </tr>
      <tr>
			<td width="15%" align="right" valign="top">充值卡密码：</td>
		    <td><input name="cardid" type="text" id="cardid" size="38" class="intxt" style="width:200px"/></td>
	  </tr>
	  <tr>
			<td align="right" valign="top">验证码：</td>
			<td><input name="entered_imagecode" type="text" id="entered_imagecode"  size="8" class="intxt" style='width:50px;text-transform:uppercase;' />
							<img src="../include/vdimgck.php" alt="看不清？点击更换" align="absmiddle" style="cursor:pointer" onclick="this.src=this.src+'?'" />
           </td>
	  </tr>
      <tr>
        <td width="11%">&nbsp;</td>
	    <td valign="top" align="left"><input type="submit" value="充值"></td>
      </tr>
    </table></td>
  </tr>
  
</table>
</form>
<br>
<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#39867B">
  <tr>
    <td class="title">充值历史记录</td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#EFEFEF">
     <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" class="table">
      <tr>
        <td width="11%" bgcolor="#efefef">&nbsp;</td>
        <td bgcolor="#efefef">&nbsp;</td>
        <td bgcolor="#efefef">&nbsp;</td>
      </tr>
      <tr>
        <th  bgcolor="#efefef">充值卡号</th>
        <th  bgcolor="#efefef">充值金额</th>
        <th  bgcolor="#efefef">充值时间</th>
      </tr>
      <?php
  $query=$db->query("SELECT * FROM `ve123_moneycard_orders` where uid='$uid' LIMIT 0 , 30 ");
  while($link=$db->fetch_array($query))
  {
  ?>
      <tr align="center">
        <td><?php echo $link["card"];?></td>
        <td><?php echo $link["price"];?>&nbsp;积分</td>
        <td><?php echo MyDate('Y-m-d  H:i:s',$link["time"])?></td>
     </tr>
     <?php
  }
  ?>
      <tr>
        <td>&nbsp;</td>
        <td></td>
      </tr>
    </table></td>
  </tr>
</table>
