<?
include_once("./_common.php");

@include_once("$board_skin_path/good.head.skin.php");

echo "<meta http-equiv='content-type' content='text/html; charset=$g4[charset]'>";

if (!$is_member) 
{
    $href = "/bbs/login.php?$qstr&url=".urlencode("/bbs/board.php?bo_table=$bo_table&wr_id=$wr_id");

    echo "<script language='JavaScript'>alert('需要登录后使用！'); top.location.href = '$href';</script>";
    exit;
}

if (!($bo_table && $wr_id)) 
    alert_close("数据传输出错！");

$ss_name = "ss_view_{$bo_table}_{$wr_id}";
if (!get_session($ss_name))
    alert_close("您只能对开放投票功能论坛进行推荐或反对操作");

$row = sql_fetch(" select count(*) as cnt from {$g4[write_prefix]}{$bo_table} ", FALSE);
if (!$row[cnt])
    alert_close("没有找到您访问的论坛！可能已被关闭或删除！");

if ($good == "good" || $good == "nogood") 
{
    if($write[mb_id] == $member[mb_id])
        alert_close("您不可以对自己的文章进行投票！");

    if (!$board[bo_use_good] && $good == "good")
        alert_close("论坛关闭了推荐投票功能");

    if (!$board[bo_use_nogood] && $good == "nogood")
        alert_close("论坛关闭了反对投票功能！");

    $sql = " select bg_flag from $g4[board_good_table]
              where bo_table = '$bo_table'
                and wr_id = '$wr_id' 
                and mb_id = '$member[mb_id]' 
                and bg_flag in ('good', 'nogood') ";
    $row = sql_fetch($sql);
    if ($row[bg_flag])
    {
        if ($row[bg_flag] == "good")
            $status = "推荐";
        else 
            $status = "反对";
        
        echo "<script language='JavaScript'>alert('您已经对此文章进行过\'$status\'！');</script>";
    }
    else
    {
        // 推荐 反对 计数
        sql_query(" update {$g4[write_prefix]}{$bo_table} set wr_{$good} = wr_{$good} + 1 where wr_id = '$wr_id' ");
        // 创建详情
        sql_query(" insert $g4[board_good_table] set bo_table = '$bo_table', wr_id = '$wr_id', mb_id = '$member[mb_id]', bg_flag = '$good', bg_datetime = '$g4[time_ymdhis]' ");

        if ($good == "good") 
            $status = "推荐";
        else 
            $status = "反对";

        echo "<script language='JavaScript'> alert('您对此文章进行了\'$status\'操作');</script>";
    }
}

@include_once("$board_skin_path/good.tail.skin.php");
?>
<script language="JavaScript"> window.close(); </script>