<?php

//载入全局配置和函数包
require("../../../include/global.php");

require(VI_ROOT."/module/function.php");
require(VI_ROOT."/module/vote/config.php");

require(VI_ROOT."/module/passport/function.php");
require(VI_ROOT."/module/analytic/function.php");

$mode = GetQuery("mode");
$action = GetQuery("action");
$do = GetQuery("do");
$fid = GetNumber("id",0);

//邀请码
$invite = GetQuery("invite");

if( $invite ){

	$hash = unserialize(do_mdecrypt($invite,VI_START));
	
	if( !is_array($hash) ){
		exit('Invite Error!');
	}

}else{
	$hash = array();	
}
	
//加载缓存
if( !loader_cache($appid,"forms.".$fid) ){
	exit('Cache Error!');
}

//回收站中
if( $VICACHE["mod.forms"]["status"] == -1 ){
	exit('Forbidden');	
}

$config = fix_json($VICACHE["mod.forms"]["config"]);
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $Project["charset"];?>" />
<title><?php echo $VICACHE["mod.forms"]["name"];?> - <?php echo $Global["site"];?> - Powered By VeryIDE</title>
<?php 
	echo $Global["meta"];
	
	//查看皮肤是否存在
	$skin = !empty($_GET["skin"]) ? $_GET["skin"] : $VICACHE["mod.forms"]["skin"];
	if( !file_exists("theme/".$skin) ){
		$skin = "default";
	}
	
	echo '<link type="text/css" rel="stylesheet" charset="utf-8" href="theme/'.$skin.'/style.css?ver=4.0" title="VeryIDE" />';

	echo loader_script(array(VI_BASE."js/mo.js",VI_BASE."js/mo.ajax.js",VI_BASE."js/mo.ui.js",VI_BASE."js/mo.effect.js",VI_BASE."js/mo.drag.js",VI_BASE."js/mo.form.js"),"utf-8",$Project["version"]);

	//通行证
	echo loader_style(array(VI_BASE."module/passport/style/style.css"),"UTF-8",$Project["version"]);
	echo loader_script(array(VI_BASE."module/passport/js/passport.js",VI_BASE."module/passport/js/function.js"),"UTF-8",$Project["version"]);
	
	//背景图片
	if( !empty($config["PAGE_BG"]) || !empty($config["PAGE_BG_COLOR"]) ){
		$bg = "background:".$config["PAGE_BG_COLOR"].( $config["PAGE_BG"] ? " url(".$config["PAGE_BG"].") " : "" ).$config["PAGE_BG_REPEAT"]." ".$config["PAGE_BG_ATTACHMENT"]." ".$config["PAGE_BG_X"]." ".$config["PAGE_BG_Y"].";";
	}
	
	//主体透明
	if( !empty($config["PAGE_BG_OPACITY"]) ){
		$op = "filter:alpha(opacity=".$config["PAGE_BG_OPACITY"].");opacity:".($config["PAGE_BG_OPACITY"]/100).";";
	}
	
	//页面宽度
	if( !empty($config["PAGE_WIDTH"]) ){
		$op .= "width:".$config["PAGE_WIDTH"].$config["PAGE_UNIT"].";";
	}
	
	//背景音乐
	if( !empty($config["PAGE_SOUND"]) && !$action ){
		$bs = '<bgsound src="'.$config["PAGE_SOUND"].'" autostart="true" loop="'.$config["PAGE_SOUND-LOOP"].'" />';
		echo $bs;
	}
?>

</head>
<body style="<?php echo $bg;?>">

	<?php
	
	//自定义面板
	if( $mode == "layout" && $_SESSION["Manager"]["id"] && $Group["mod-".$appid."-mod"]=="Y" ){
		require("../../passport/include.layout.php");
	}
	
	//全局导航
	if( $mode != "simple" ){
		require("../../passport/include.header.php");
	}else{
		echo loader_style(array(VI_BASE."module/passport/style/style.css"),"utf-8",$Project["version"]);
	}
	?>

	<div id="main" style="<?php echo $op;?>" class="<?php echo $config["PAGE_ALIGN"]? $config["PAGE_ALIGN"]:"";?>">
	
		<?php
		
		if( $mode != "simple" ){
		
			echo '<div id="header" style="'.($config["HIDE_TITLE"] == "Y" ? "display:none;" :"").'">';
			
			echo '<h1>'.$VICACHE["mod.forms"]["name"].'</h1> <p>'.parse_forms($VICACHE["mod.forms"]).'</p>';					
			
			if( !empty($config["FORM_MAX"]) || !empty($config["FORM_NUMBER"]) ){
				echo '<p>参加人数上限：'.$config["FORM_MAX"].'，每人限参加'.$config["FORM_NUMBER"].'次。</p>';	
			}
			
			if( empty($config["HIDE_RESULT"]) ){
				echo '<p>截止到目前，共有 '.$VICACHE["mod.forms"]["stat"].' 人参与本活动。</p>';
				
			}
			
			if( $VICACHE["mod.forms"]["start"]>time() ){
				echo '<p class="error">注意：表单还未正式启用，暂时不接受提交！</p>';
			}elseif( $VICACHE["mod.forms"]["expire"]<time() ){
				echo '<p class="error">注意：表单已经过期无效，已经不接受提交！</p>';
			}
			
			if( $hash["name"] ){
				echo '<p>你好，<strong>'.$hash["name"].'</strong> 邀请你参加此活动。</p>';
				
			}
			
			echo '</div>';
		}
		
		?>
        
        <div id="content">
        
        <a name="top"></a>
        
		<?php
		
		$active = array(''=>'include.view.php','post'=>'include.post.php','result'=>'include.result.php','status'=>'include.status.php');
		
        if(array_key_exists($action,$active)){
			
			//用户登录验证
			if( $config['USER_MODE'] == "REG" && !in_array( $action , array('result','status') ) ){
			
				//载入会员配置
				require(VI_ROOT."/module/member/config.php");
			
				$arr = array();
				
				//记录需要更新的字段
				foreach ($Modules["member"]["fieds"] as $fied => $name){				
					if( $config["REG-".$fied] ){
						$arr[] = $fied;
					}					
				}
				
				//更新特定字段
				if( count($arr) ){				
					//显示登录窗口，并需要更新资料
					passport_check( true , "['". implode("','",$arr) ."']" );				
				}else{				
					//显示登录窗口
					passport_check( true , false );				
				}
				
			}else{				
				//统计系统
				analytic_ping($appid,$fid,'view');				
			}
			
			//包含动用文件
			require($active[$action]);	
		}
		
		?>
            
        </div>
        
		<?php
        //全局页尾
        if( $mode != "simple" ) require("../../passport/include.footer.php");
        ?>
    
    </div>
	
</body>
</html>