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

/* 兑现悬赏 */
/* 162100源码 - 162100.com */


$_GET['id'] = abs($_GET['id']);
$article_url = $web['url_html_article'] == 1 ? 'article.'.$web['sitemode'].'.'.$_GET['id'].'.1.html' : 'article.php?mode='.$web['sitemode'].'&id='.$_GET['id'].'';
$text=$err = '';

if (!isset($sql['db_err'])) {
  db_conn();
}

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

  $result = @mysql_query('SELECT mess_num,ABS(writecount) AS wc,check_reg 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>';
    }
    $writecount = $row['wc'];
    unset($row);
  } else {
    $err = '帐号不存在！';
  }
  @mysql_free_result($result);

  if (empty($err)) {
    //取文章
    $result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' WHERE id="'.$_GET['id'].'"', $db);
    if ($row = @mysql_fetch_assoc($result)) {
      if (strstr($row['reward'], '（已兑现）')) {
        $err = '<a href="'.$article_url.'" target="_blank">该文</a>已经兑现完毕。';
      } elseif (floatval($row['reward']) <= 0) {
        $err = '<a href="'.$article_url.'" target="_blank">该文</a>无悬赏！出错。';
      } else {
        $text .= '<center><strong>结帖：'.$row['title'].'</strong><br />'; //preg_replace('/(\|.*)?/', '', $row['title'])
        $text .= '<span style="font-size:12px">回复/阅读（'.$row['reply'].'/'.$row['views'].'）<span class="redword"><b>悬赏值（'.$row['reward'].'）</b></span></span></center>
';
        $text .= '<div class="lan"><div style="float:right">楼主正文</div>'.$row['author_ip'].' - '.$row['date'].'</div>';
        $text .= '<div class="text">'.$row['text'].'</div>';
      }
      @mysql_free_result($result);
    } else {
      $err = '未查到此记录！可能参数传递出错或已被删除。';
    }
  }

  if (empty($err)) {
    $text .= '<button type="submit"><b>提交结帖</b></button>';
    $seek = 0;
    $result = @mysql_query('SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载回复评论的表名'].'` WHERE r_id="'.$row['id'].'" ORDER BY id ASC', $db);
    while ($row_re = mysql_fetch_assoc($result)) {
      $seek++;
      if ($row_re['author_ip'] == $session[0]) {
        $text .= '<div class="lan"><div style="float:right;">-'.$seek.'楼回复</div>'.$row_re['author_ip'].' - '.$row_re['date'].' <span class="redword">（作者本人被忽略）</span></div>';
      } elseif (strstr($row_re['author_ip'], '.')) {
        $text .= '<div class="lan"><div style="float:right;">-'.$seek.'楼回复</div>'.$row_re['author_ip'].' - '.$row_re['date'].' <span class="redword">（游客被忽略）</span></div>';
      } else {
        $text .= '
		<div class="lan lan2"><div style="float:right;line-height:22px !important;line-height:26px;">-'.$seek.'楼回复</div>'.$row_re['author_ip'].' - '.$row_re['date'].' 得分：<input type="text" name="f[]" id="f[]" style="width:60px" onkeyup="isDigit(this,0,1,\'.\');ck(this);" onMouseOver="cc(this)" onmouseout="out()" /><input type="hidden" name="r_author[]" id="r_author[]" value="'.$row_re['author_ip'].'" /><input type="hidden" name="r_id[]" id="r_id[]" value="'.$row_re['id'].'" /></div>
		<div class="text">'.$row_re['text'].'</div>';
      }
      unset($row_re);
    }
    @mysql_free_result($result);
    $text .= $row['reply'] > $seek ? '<div style="padding:6px; border:1px #DB696E solid;">'.($row['reply'] - $seek).'条回复已被删除，不再显示。</div>' : '';
  }




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

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


?>
<style type="text/css">
<!--
.lan { margin-top:5px; margin-bottom:5px; padding:4px; font-size:12px; background-color:#DDDDDD; line-height:normal; }
.lan2 { background-color:#D3E5FA; padding-top:1px; padding-bottom:1px; }
#fen_obj { display:none; font-size:12px; color:#FFFFCC; padding:6px; position:absolute; }
-->
</style>
<script language="javascript" type="text/javascript">
<!--
var zhong=<?php echo floatval($row['reward']); ?>; //得到总分值

//结帖
function sendPoint() {
  if (fen() != 0) {
    alert("无法兑现悬赏！\n原因：所给分总和不对！\n或其它原因");
    return false;
  }
  return true;
}

function fen() {
  var a = document.getElementsByName("f[]");
  var gei = 0;
  for (var i=0; i<a.length; i++) {
    gei = (a[i].value == '') ? gei : (gei + parseFloat(a[i].value));
  }
  var n = zhong - gei;
  return Math.round(n * 100) / 100;
}

function cc(obj) {
  if (obj.name != 'f[]') return;
  var n = fen();
  var tho = obj;
  var t = obj.offsetTop;
  var l = obj.offsetLeft;
  while(tho=tho.offsetParent){t+=tho.offsetTop;l+=tho.offsetLeft;}
  var fenO = $('fen_obj');
  fenO.style.display = 'block';
  fenO.style.top = t+'px';
  fenO.style.left = (60 + l)+'px';
  fenO.style.background = (n < 0) ? "#FF6600" : "#009900";
  fenO.innerHTML = "该问题总悬赏："+zhong+"<br />现可付货币值："+n;
}

function ck(obj) {
  var n = fen();
  if (n < 0) {
    alert('填错！超额'+(-n)+'！重填！');
    obj.value = '';
  }
}

function out(){
  var fenO = $('fen_obj');
  fenO.style.display = 'none';
  fenO.innerHTML = '';
}


-->
</script>
<span id="fen_obj"></span>
<form method="post" id="manageform" action="?post=unity_run&dataname=listdata&limit=reward_cash" onsubmit="return sendPoint()">
<?php

if (empty($err)) {
  echo $text;
  echo '<button type="submit"><b>提交结帖</b></button>';
  echo $row['reply'] == 0 || $seek == 0 ? '<span class="redword">尚无回复，不能兑现悬赏</span>' : '';
} else {
  echo $err;
}
?>
<input type="hidden" name="id[]" value="<?php echo $_GET['id']; ?>" />
</form>
<script> try { if ($("bar_id_") != null) { $("bar_id_").id = ""; } $("bar-reward").parentNode.id = "bar_id_"; } catch (err) {} </script>
