<?php
require ('authentication_member.php');
?>
<?php

/* 取：我的货币值 */
/* 162100源码 - 162100.com */

$_GET['act']=@$_GET['act'];
if ($_GET['act'] == 'add') {
  $where_eval = ' AND money>0';
  $list_title = '"<a href=\"?get=myfunds\">全部记录</a><a class=\"list_title_in\">增值记录<span>（".$n."）</span></a><a href=\"?get=myfunds&act=del\">支出记录</a><a href=\"?get=myfunds&act=recharge\">充值记录</a>"';
  $funds_sum_mark = ' disabled="disabled"';
} elseif ($_GET['act'] == 'del') {
  $where_eval = ' AND money<0';
  $list_title = '"<a href=\"?get=myfunds\">全部记录</a><a href=\"?get=myfunds&act=add\">增值记录</a><a class=\"list_title_in\">支出记录<span>（".$n."）</span></a><a href=\"?get=myfunds&act=recharge\">充值记录</a>"';
  $funds_sum_mark = ' disabled="disabled"';
} elseif ($_GET['act'] == 'recharge') {
  $where_eval = ' AND description="在线充值"';
  $list_title = '"<a href=\"?get=myfunds\">全部记录</a><a href=\"?get=myfunds&act=add\">增值记录</a><a href=\"?get=myfunds&act=del\">支出记录</a><a class=\"list_title_in\">充值记录<span>（".$n."）</span></a>"';
  $funds_sum_mark = ' disabled="disabled"';
} else {
  $where_eval = '';
  $list_title = '"<a class=\"list_title_in\">全部记录<span>（".$n."）</span></a><a href=\"?get=myfunds&act=add\">增值记录</a><a href=\"?get=myfunds&act=del\">支出记录</a><a href=\"?get=myfunds&act=recharge\">充值记录</a>"';
  $funds_sum_mark = '';
}


$mess = 0;
$text =$err='';
if (!isset($sql['db_err'])) {
  db_conn();
}

if ($sql['db_err'] == '') {

  $result = @mysql_query('SELECT mess_num,check_reg,point FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username="'.$session[0].'" LIMIT 1', $db);
  if ($row = @mysql_fetch_assoc($result)) {
    if ($row['check_reg'] == '1') {
      $err = '帐号注册审核中！';
    } elseif ($row['check_reg'] == '2') {
      $err = '帐号已被移除至<a href="list_member.php?act=punished" target="_blank">黑名单</a>！';
    } else {
      $mess = '<span class="grayword">'.preg_replace('/^\d+/', '<span>$0</span>', $row['mess_num']).'</span>';
    }
    $my_point = abs($row['point']);
    unset($row);
  } else {
    $err = '帐号不存在！';
  }
  @mysql_free_result($result);

  if (empty($err)) {

    //求和货币值
    $result = @mysql_query('SELECT SUM(money) AS total FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE (username="'.$session[0].'" AND type="0")', $db);
    if ($row = @mysql_fetch_assoc($result)) {
      $total = $row['total'] ? $row['total'] : 0;
      unset($row);
    }
    @mysql_free_result($result);
    
    $result = @mysql_query('SELECT COUNT(id) AS total FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE (username="'.$session[0].'" AND type="0")'.$where_eval.'', $db);
    $row = @mysql_fetch_assoc($result);
    $n = abs($row['total']);
    @mysql_free_result($result);
    unset($row);

    require ('inc/function/get_page.php');
    if ($n > 0) {
    
      $p = get_page($n); //页数
      $seek = $web['pagesize'] * ($p-1);
      $result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE (username="'.$session[0].'" AND type="0")'.$where_eval.' ORDER BY date DESC LIMIT '.$seek.','.$web['pagesize'].'', $db);
      $text .= '
<div class="list_title_">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <th>货币值明细</th>
      <th width="100">货币出入</th>
      <th width="200">日期</th>
      <th width="200">备注</th>
    </tr>
  </table>
</div>
';
      while ($row = @mysql_fetch_assoc($result)) {
        $row['money'] = $row['money'] > 0 ? '+'.$row['money'] : $row['money'];
        $text .= '
<div class="li">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>'.$row['description'].'</td>
      <td width="100" align="center">'.$row['money'].'</td>
      <td width="200" align="center">'.$row['date'].'</td>
      <td width="200" align="center">'.$row['other'].'</td>
    </tr>
  </table>
</div>
';
        unset($row);

      }
      @mysql_free_result($result);

      $text .= get_page_foot($n, $web['pagesize'], $p, '?get=myfunds&act='.$_GET['act'].'&p=');
    } else {
    $text = '暂无相应记录';
    }

  }

} else {
  $err .= $sql['db_err'];
}

@ require ('inc/function/add_online.php'); //在线
@mysql_close();

if (empty($err)) {


  @ require ('pay/alipay.config.php');
  if (!$alipay_config['partner'] || !$alipay_config['key'] || !$alipay_config['seller_email']) {
    $pay_0 = ' disabled="disabled"';
    $pay_1 = '系统当前收款支付宝帐户未配置，不可充值';
  } else {
    $pay_0 = '';
    $pay_1 = '使用支付宝、财富通、或网银等在线支付。';
  }
?>
<div class="column aline">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="250" align="center"><?php
echo '您当前可用的货币值为：<span'.($total == 0 ? '' : ' class="redword"').' style="font-size:24px;">'.$total.'</span>', $err;

if (abs($web['point_funds'][0]) == 0 || abs($web['point_funds'][1]) == 0) {
  $point_funds_0 = ' disabled="disabled"';
  $point_funds_1 = '当前系统设置为：不可转换';
} else {
  $point_funds_0 = '';
  $point_funds_1 = '您当前的等级分为'.$my_point.'，最多可转换'.(($my_point * abs($web['point_funds'][1])) /abs($web['point_funds'][0])).'元货币值。';
}


?>
      </td>
      <td style="border-left:1px #CCCCCC dotted;padding-left:10px;text-align:left;">
        <?php echo $total < 100 ? '<b>建议充值！</b>' : ''; ?><br />
        <span class="grayword">充足的货币积分可应用于刷新、置顶、购买广告位等。</span>
<div style="border-top:1px #CCCCCC dotted; padding-top:5px; padding-bottom:5px;">
<form action="?post=myfunds" method="post" name="manageform" target="_blank" id="manageform" onsubmit="return chkSend(this);">
        我要在线充值货币：<input name="WIDtotal_fee" id="WIDtotal_fee" type="text" size="12" maxlength="8"<?php echo $pay_0; ?> />
        元
        <!-- onpropertychange="confirmNum(this)" oninput="confirmNum(this)" -->
        <button name="submit" type="submit"<?php echo $pay_0; ?>><b>提交订单</b></button>
      </form>
        <span class="grayword"><?php echo $pay_1; ?></span>
</div>
<div style="border-top:1px #CCCCCC dotted; padding-top:5px; padding-bottom:5px;">
<form action="?post=myfunds&act=class_c" method="post" name="manageform2" target="_blank" id="manageform2" onsubmit="return chkSend(this);">
        用等级分转换货币：<input name="WIDtotal_fee" id="WIDtotal_fee" type="text" size="12" maxlength="8"<?php echo $point_funds_0; ?> />
        元
        <!-- onpropertychange="confirmNum(this)" oninput="confirmNum(this)" -->
        <button name="submit" type="submit"<?php echo $point_funds_0; ?>><b>提交转换</b></button>
      </form>
        <span class="grayword"><?php echo $point_funds_1; ?></span>
</div>


</td>
    </tr>
  </table>
</div>
<script type="text/javascript">
<!--
function chkSend(form) {
  if (isNaN(form.WIDtotal_fee.value) || form.WIDtotal_fee.value < 0.01) {
    alert("你输入的值不对，要为数字并大于0.01元！");
    form.WIDtotal_fee.value="";
    return false;
  }
  return true;
}

function confirmNum(obj){
  if (isNaN(obj.value)) {
    alert('要输入数字！');
    obj.value = '';
    return;
  }
  obj.value=obj.value.replace(/(\.\d{2})\d*$/, '$1');
}
-->
  </script>
<iframe id="lastFrame" name="lastFrame" frameborder="0" marginheight="0" marginwidth="0" style="display:none;"></iframe>
<div class="list_title"><?php echo eval('return '.$list_title.';'); ?></div>
<div class="manager_menu">
  <?php
if ($funds_sum_mark == '') {
  $oncli = ' onclick="'.($n > 100 ? 'if(confirm(\'此举将删除收支明细，只留汇总余额\n（但有利于数据库性能，推荐执行）\n点确定执行\')){addSubmitSafe();location.href=\'?post=unity_run&dataname=myaccount&limit=fundssum&id[]=1\';}' : 'alert(\'明细数量不多，可不必汇总\');return false;').'"';

  $funds_sum_arr = @glob('__temp__/temp/fundssum-'.urlencode($session[0]).'-*');
  if (is_array($funds_sum_arr) && count($funds_sum_arr) > 0) {
    $funds_sum = '汇总日志：';
    foreach ($funds_sum_arr as $funds_sum_file) {
      $funds_sum_file = basename($funds_sum_file);
      $funds_sum .= '<span id="fundsbackup_'.$funds_sum_file.'"><a href="__temp__/temp/'.urlencode($funds_sum_file).'" target="_blank" title="汇总备份，点右键可另存为">'.$funds_sum_file.'</a> <a href="?post=unity_run&dataname=myaccount&limit=del_fundssum&id[]='.urlencode($funds_sum_file).'" target="lastFrame" title="删除日志">×</a></span> ';
    }
  }
}
?>
  <button type="button"<?php echo $oncli.$funds_sum_mark; ?>><b>汇总余额</b></button>
  <?php echo @$funds_sum; ?>
</div>
<?php
  echo $text;

} else {
  echo $err;
}
?>
