<?php
/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	$Id: veryide.action.php,v2 19:47 2008-10-08 Leilei $
*/

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

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


//系统动作配置，修改时请小心
header('Content-type: text/xml');

echo ("<?xml version='1.0' encoding='".$Project["charset"]."'?>");
echo ("<response>");
	
$action = GetQuery("action");
$id = GetNumber("id",0);

echo ("<action>".$action."</action>");

switch ($action){

	//获取用户数
	case "count":
		
		//
		if( !$id){
			echo ("<result>false</result>");
		}else{

			//mysql open
			reader_mysql();

			//查询数据库
			$sql="select count(u_id) as count from ".VI_DBMODPRE."apps_user where f_id=".$id;
			$result=@mysql_query($sql,$mysql);
			
			$Project["queries"]++;
			
			if(@mysql_num_rows($result)==1){
				$row=mysql_fetch_assoc($result);
				
				$count=$row["count"];

				echo ("<result>true</result>");
				echo ("<value>".$count."</value>");
			}else{
				echo ("<result>mysql</result>");
			}
			
			//mysql close
			reader_mysql(true);

		}
	break;

	//查询票数
	case "poll":
		
		//
		if( !$id){
			echo ("<result>false</result>");
		}else{

			//mysql open
			reader_mysql();

			//查询数据库
			$sql="select o_ext2,o_id from ".VI_DBMODPRE."apps_option where f_id=".$id;
			$result=@mysql_query($sql,$mysql);
			
			$Project["queries"]++;
			
			while($row=mysql_fetch_assoc($result)){
				$o_id=$row["o_id"];
				$o_count=$row["o_ext2"];	
				
				$json.='{"id":'.$o_id.',"count":'.$o_count.'},';
				
			}
			echo ("<result>true</result>");
			echo ("<value>[".substr($json,0,strlen($json)-1)."]</value>");
			
			//mysql close
			reader_mysql(true);

		}
	break;
	
	//更新点击
	case "view":

		if($id){
			//mysql open
			reader_mysql();
			
			//查询数据库
			$sql="update ".VI_DBMODPRE."forms set f_view=f_view+1 where f_id=".$id;
			$result=@mysql_query($sql,$mysql);
			
			$Project["queries"]++;
			
			//查询数据库
			$sql="select f_view as count from ".VI_DBMODPRE."forms where f_id=".$id;
			$result=@mysql_query($sql,$mysql);
			
			$Project["queries"]++;
			
			if(@mysql_num_rows($result)==1){
				$row=mysql_fetch_assoc($result);
				
				$count=$row["count"];

				echo ("<result>true</result>");
				echo ("<value>".$count."</value>");
			}else{
				echo ("<result>mysql</result>");
			}

			//mysql close
			reader_mysql(true);
		}
	break;
}
	
echo ("</response>");
?>