<?php
/**
 *
 * 投票
 *
 * @version        $Id: vote.php 1 20:54 2010年7月8日Z tianya $
 * @package        DedeCMS.Site
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require(dirname(__FILE__)."/../include/common.inc.php");
require(DEDEINC."/dedevote.class.php");
require(DEDEINC."/memberlogin.class.php");
require(DEDEINC."/userlogin.class.php");

$member = new MemberLogin;
$memberID = $member->M_LoginID;
$time = time();
$content = $memberID.'|'.$time;
$file = DEDEDATA.'/cache/vote_'.$aid.'_'.$member->M_ID.'.inc';//存放會員投票記錄的緩存文件

$loginurl = $cfg_basehost."/member";
$ENV_GOBACK_URL = empty($_SERVER['HTTP_REFERER']) ? '':$_SERVER['HTTP_REFERER'];

if(empty($dopost)) $dopost = '';

$aid = (isset($aid) && is_numeric($aid)) ? $aid : 0;
if($aid==0) die(" Request Error! ");

if($aid==0)
{
    ShowMsg("沒指定投票項目的ID！","-1");
    exit();
}
$vo = new DedeVote($aid);
$rsmsg = '';


$row = $dsql->GetOne("SELECT * FROM #@__vote WHERE aid='$aid'");
//判斷是否允許遊客進行投票
if($row['range'] == 1)
{
    if(!$member->IsLogin())
    {
        ShowMsg('請先登錄再進行投票',$loginurl);
        exit();
    }
}

if($dopost=='send')
{
    
    if(!empty($voteitem))
    {
        $rsmsg = "<br />&nbsp;你方纔的投票狀態：".$vo->SaveVote($voteitem)."<br />";
    }
    else
    {
        $rsmsg = "<br />&nbsp;你剛才沒選擇任何投票項目！<br />";
    }
    
    if($row['isenable'] == 1)
    {
        ShowMsg('此投票項未啟用,暫時不能進行投票',$ENV_GOBACK_URL);
        exit();
    }
}

$voname = $vo->VoteInfos['votename'];
$totalcount = $vo->VoteInfos['totalcount'];
$starttime = GetDateMk($vo->VoteInfos['starttime']);
$endtime = GetDateMk($vo->VoteInfos['endtime']);
$votelist = $vo->GetVoteResult("98%",30,"30%");





//判斷是否允許被查看
$admin = new userLogin;
if($dopost == 'view')
{
    if($row['view'] == 1 && empty($admin->userName))
    {
        ShowMsg('此投票項不允許查看結果',$ENV_GOBACK_URL);
        exit();
    }
}
//顯示模板(簡單PHP文件)
include(DEDETEMPLATE.'/plus/vote.htm');