<?php
/*
 * 注意：此文件由tpl_engine编译型模板引擎编译生成。
 * 如果您的模板要进行修改，请修改 templates/default/modules/poll/poll_show.html
 * 如果您的模型要进行修改，请修改 models/modules/poll/poll_show.php
 *
 * 修改完成之后需要您进入后台重新编译，才会重新生成。
 * 如果您开启了debug模式运行，那么您可以省去上面这一步，但是debug模式每次都会判断程序是否更新，debug模式只适合开发调试。
 * 如果您正式运行此程序时，请切换到service模式运行！
 * 
 * 如有您有问题请到官方论坛（http://tech.jooyea.com/bbs/）提问，谢谢您的支持。
 */
?><?php
  //引入公共模块
  require("foundation/module_users.php");
	require("foundation/module_restore.php");
	require("foundation/module_mypals.php");
	require("foundation/module_poll.php");
	require("foundation/fcontent_format.php");
	
  //语言包引入
  $pol_langpackage=new polllp;
  $g_langpackage=new grouplp;
	$mn_langpackage=new menulp;
    
  //变量区
	$ses_uid=get_sess_userid();
	$u_sex=get_sess_usersex();
	$pid=short_check(get_argg('p_id'));
	$url_uid=short_check(get_argg('user_id'));
	$is_admin=get_sess_admin();
	//当前页面参数
	$page_num=trim(get_argg('page'));
	
  //引入模块公共权限过程文件
	$is_self_mode='partLimit';
	$is_login_mode='';
	require("foundation/auser_validate.php");
	
	$button_show="content_none";
	if($is_self=='Y'){
		$button_show="";
	}

	 dbtarget('r',$dbServs);
   $dbo=new dbex;
				
//数据表定义区
	$t_mypals=$tablePreStr."pals_mine";
	$t_poll=$tablePreStr."poll";
	$t_polloption=$tablePreStr."polloption";
	$t_polluser=$tablePreStr."polluser";
	
	$p_result_rs=array();
	$p_com_rs=array();
	$p_put_info=array();
	$poll_row=array();
	$sum_poll_num=array();
	$is_poll=array();
	$pals_id='';
	$refuse_str='';
	$error_str='';
	$poll_row=get_poll_row($dbo,$t_poll,$pid);
	
	$sql="select * from $t_polloption where pid=$pid";
 	$p_result_rs=$dbo->getRs($sql);
 	
 	$sql="select sum(votenum) as sum_votenum from $t_polloption where pid=$pid";
 	$sum_poll_num=$dbo->getRow($sql);
 	
 	$pals_id=getMypals($dbo,$poll_row['user_id'],$t_mypals);
 	
	$sql="select * from $t_polluser where pid=$pid order by dateline desc limit 10";
	$p_put_info=$dbo->getRs($sql);
	
//投票信息
	$show_poll_info="";
	if(empty($p_put_info)){
		$show_poll_info="content_none";
	}
	if($ses_uid!=''){
		$sql="select username from $t_polluser where uid=$ses_uid and pid=$pid";
		$is_poll=$dbo->getRs($sql);
	}
	//防止重复投票
	if(empty($is_poll)){
		$check_form="check_form();";
		$show_check="";
		$action_URL="do.php?act=poll_submit&pid=".$poll_row['p_id'];
	}else{
		$show_check="content_none";
		$action_URL='#';
		$check_form="refuse_poll();";
		$refuse_str=$pol_langpackage->pol_repeat;
	}	
	
//性别限定
if($ses_uid!=''){
	if($poll_row['sex']!=2&&$poll_row['sex']!=$u_sex){
		$show_check="content_none";
		$action_URL='#';
		$check_form="refuse_poll();";
		$refuse_str=str_replace("{sex}",get_user_sex($poll_row['sex']),$pol_langpackage->pol_sex_limit);
	}
}

//按钮颜色显示	
	$mod=short_check(get_argg('m'));
	$n_l='';$n_r='';$h_l='';$h_r='';
	$r_l='';$r_r='';$m_l='';$m_r='';
	switch($mod){
			case "new":
				$n_l="class='nowbutl'";
				$n_r="class='nowbutr'";
			break;
			case "hot":
				$h_l="class='nowbutl'";
				$h_r="class='nowbutr'";			
			break;		
			case "reward":
				$r_l="class='nowbutl'";
				$r_r="class='nowbutr'";			
			break;
			default:
				$m_l="class='nowbutl'";
				$m_r="class='nowbutr'";					
	}		
	
//锁定判断	
	$show_error="content_none";
	if($poll_row['is_pass']==0 && $is_admin==''){
    $error_str=$pol_langpackage->pol_lock;
    $show_error="";
	}	
	
//总结报告
	$show_sumary="";
	if(empty($poll_row['summary'])){
		$show_sumary="content_none";
	}
	
//操作显示
	$action_ctrl="";
	$sendor_info="content_none";
	$show_share="content_none";
	$show_i_com="";
	if($ses_uid!=$poll_row['user_id']){
		$sendor_info="";
		$action_ctrl="content_none";
		$show_share="";
	//评论好友限定	
		if($poll_row['noreply']==1&&!strstr($pals_id,$ses_uid)||$ses_uid==NULL){
			$show_i_com="content_none";
		}
	}

//显示奖励积分
	$show_award_int="";
	if(empty($poll_row['percredit'])){
		$show_award_int="content_none";
	}
	
//控制数据显示
	$show_data="";
	if(empty($poll_row)){
		$error_str=$pol_langpackage->pol_error;
		$show_error="";
		$show_data="content_none";
		$show_com="content_none";
		$show_sumary="content_none";
		$isNull=1;
		$sendor_info="content_none";
		$action_ctrl="content_none";
		$show_i_com="content_none";
		$show_poll_info="content_none";
		$show_award_int="content_none";
	}	

//投票结束
	if(strtotime($poll_row['expiration']) < strtotime(date("Y-m-d",time()))){
		$show_check="content_none";
		$action_URL='#';
		$check_form="refuse_poll();";
		$refuse_str=$pol_langpackage->pol_date_over;
		$date_color='color:red';
	}
//未登录
	if(!$ses_uid){
		$show_check="content_none";
		$action_URL='#';
		$check_form="refuse_poll();";
		$refuse_str=$pol_langpackage->pol_not_login;
	}	
?>
<!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=utf-8">
<title>poll</title>
<link rel="stylesheet" type="text/css" href="skin/<?php echo $skinUrl;?>/css/row_menus.css">
<link rel="stylesheet" type="text/css" href="skin/<?php echo $skinUrl;?>/css/iframe.css">
<link rel="stylesheet" type="text/css" href="skin/<?php echo $skinUrl;?>/css/user_ico_small.css">
<!--[if lt IE 7]>
<style type="text/css">
.uico_photo_small span { behavior: url(skin/<?php echo $skinUrl;?>/css/ie_png_fix.htc);}
</style>
<![endif]-->
<SCRIPT language=JavaScript src="servtools/ajax_client/ajax.js"></SCRIPT>
<script type='text/javascript' src='servtools/calendar.js'></script>
<script type='text/javascript' src="skin/default/js/jooyea.js"></script>
<script type='text/javascript'>
	parent.guide("poll");

function CheckForm(){
	if(trim(document.myform.CONTENT.value)==""){
		parent.Dialog.alert("<?php echo $g_langpackage->g_not_null;?>");
		return (false);
	}
		return (true);
}	
	
	function check_form(){
		var checked_num=0;
		var def=0;
		var pol_cho=document.getElementsByName("pol_cho[]");
		for(def=0;def<pol_cho.length;def++){
			if(pol_cho[def].checked){
				checked_num++;
			}
		}
		if(checked_num==0||checked_num><?php echo $poll_row['maxchoice'];?>){
			parent.Dialog.alert('<?php echo $pol_langpackage->pol_num_option;?>:1~<?php echo $poll_row["maxchoice"];?>');
			return false;
		}
	}
	
	function refuse_poll(){
		parent.Dialog.alert('<?php echo $refuse_str;?>');
		return false;		
	}


	function show_set_config(set_option,pid){
		var point=Get_mouse_position('loc');
		var xmlhttp=InitAjax();
		xmlhttp.open("GET","?app=poll_show_config&set_option="+set_option+"&pid="+pid);
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4&&xmlhttp.status==200){				
				document.getElementById("set_config").style.display="";
				document.getElementById("set_config").style.top=point[1]-20+"px";
				document.getElementById("set_config").style.left=point[0]-170+"px";
	  	  var return_str=xmlhttp.responseText;
		    var	return_text=return_str.replace(/[\n\r]/g,"");
		    document.getElementById("set_config").innerHTML=return_text;
			}
		}
		xmlhttp.send(null);		
	}
	
	function action_set_config(set_option,pid){
		var xmlhttp=InitAjax();
		xmlhttp.open("POST","do.php?act=poll_set_config&set_option="+set_option+"&pid="+pid);
		xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4&&xmlhttp.status==200){
	  	  var return_str=xmlhttp.responseText;
		    var	return_text=return_str.replace(/[\n\r]/g,"");
		    if(return_text=='success'){
			    cancel_window();
					window.location.reload();
		    }else{
		    	parent.Dialog.alert(return_text);
		    }
			}
		}
		var send_str=null;
		switch(set_option){
			case "stop_award":
			send_str=null;
			break;
			
			case "add_award":
			var obj_num=document.getElementById("award_table").rows.length;
			if(obj_num==3){
				var add_award_sing=document.getElementById("add_award_sing").value;
				var add_award_sum=document.getElementById("add_award_sum").value;
				if(!isNaN(add_award_sum)||!isNaN(add_award_sing)){
					send_str="add_award_sum="+add_award_sum+"&add_award_sing="+add_award_sing;
				}
			}
			if(obj_num==2){
				var add_award_sum=document.getElementById("add_award_sum").value;
				if(!isNaN(add_award_sum)){
					send_str="add_award_sum="+add_award_sum;
				}
			}
			break;
						
			case "add_option":
			var add_new_option=document.getElementById("add_new_option").value;
				send_str="add_new_option="+add_new_option;
			break;
			
			case "del_poll":
			send_str=null;
			break;
			
			case "change_date":
			var expiration=document.getElementById("expiration").value;
			send_str="expiration="+expiration;
			break;
			
			case "add_summary":
			var add_summary=document.getElementById("add_summary").value;
				send_str="add_summary="+add_summary;
			break;
						
		}
		xmlhttp.send(send_str);
	}
	
	function cancel_window(){
		document.getElementById("set_config").style.display="none";
	}

</script>
</head>
<body>
  <div class="main_right_title">
     <span class="main_title_dot5"></span>
     <span class="main_title_txt"><?php echo $pol_langpackage->pol_title;?></span>
  </div>
	<!--按钮控制!-->
	<div id="tabsB" class="<?php echo $button_show;?>">
		<ul>
			<li><a href="?app=poll_list&m=new" title="<?php echo $pol_langpackage->pol_new;?>"<?php echo $n_l;?>><span <?php echo $n_r;?>><?php echo $pol_langpackage->pol_new;?></span></a></li>
			<li><a href="?app=poll_list&m=hot" title="<?php echo $pol_langpackage->pol_hot;?>"<?php echo $h_l;?>><span <?php echo $h_r;?>><?php echo $pol_langpackage->pol_hot;?></span></a></li>
			<li><a href="?app=poll_list&m=reward" title="<?php echo $pol_langpackage->pol_reward;?>"<?php echo $r_l;?>><span <?php echo $r_r;?>><?php echo $pol_langpackage->pol_reward;?></span></a></li>
			<li><a href="?app=poll_mine" title="<?php echo $pol_langpackage->pol_mine;?>"<?php echo $m_l;?>><span <?php echo $m_r;?>><?php echo $pol_langpackage->pol_mine;?></span></a></li>
		</ul>
			<div class="div_but" onclick="location.href='?app=poll_send'"><?php echo $pol_langpackage->pol_send;?></div>
	</div>	
	<!--按钮控制!-->
	<div class="iframe_contentbox">
		<div class="poll_initiator <?php echo $sendor_info;?>">
			<div class='poll_photo'>
				<a href="home.php?h=<?php echo $poll_row['user_id'];?>" target="_blank">
				<img src="<?php echo $poll_row['user_ico'];?>" onerror="parent.pic_error(this)" alt='<?php echo $poll_row['username'];?>' title='<?php echo $poll_row['username'];?>' height='43px' width='43px' /></a>
			</div>
			<div class="poll_userinfo">
				<h3><?php echo filt_word($poll_row['username']);?>发起的投票</h3>
				<p><a class="first" href='home.php?h=<?php echo $poll_row['user_id'];?>' target='_blank'><?php echo str_replace("{name}",filt_word($poll_row['username']),$pol_langpackage->pol_who_home);?></a><a href="">TA的投票</a><a href='javascript:window.history.go(-1);'><?php echo $pol_langpackage->pol_re_last;?></a></p>
			</div>
			<?php if($ses_uid){?>
			<span class="poll_share"><a href='javascript:void(0)' onclick="parent.show_share(4,<?php echo $poll_row['p_id'];?>,'<?php echo filt_word($poll_row['subject']);?>','','');" class='fenxiang <?php echo $show_share;?>'><?php echo $mn_langpackage->mn_share;?></a><a class="jubao" href="javascript:void(0);" onclick="parent.report(4,<?php echo $poll_row['user_id'];?>,<?php echo $poll_row['p_id'];?>);"><?php echo $mn_langpackage->mn_report;?></a></span>
			<?php }?>
		</div>
		<div class="clear"></div>
		<dl class="poll_info">
			<dd><?php echo $pol_langpackage->pol_send_date;?><span><?php echo $poll_row['dateline'];?></span></dd>
			<dd><?php echo $pol_langpackage->pol_stop_time;?><span><?php echo $poll_row['expiration'];?></span><dd>
			<dd><?php echo $pol_langpackage->pol_leave_int;?><span><?php echo $poll_row['credit'];?></span><dd>
			<dt><?php echo $pol_langpackage->pol_join_num;?><span><?php echo $poll_row['voternum'];?></span><dt>
		</dl>
		<?php if($poll_row['is_pass']==1 || $is_admin!='' && !empty($poll_row)){?>
			<?php if($ses_uid==$poll_row['user_id']){?>
			<ul class="poll_mag <?php echo $show_data;?>">
				<li><a href='javascript:void(0)' onclick='show_set_config("stop_award",<?php echo $poll_row["p_id"];?>);'><?php echo $pol_langpackage->pol_s_award;?></a></li>
				<li><a href='javascript:void(0)' onclick='show_set_config("add_award",<?php echo $poll_row["p_id"];?>);'><?php echo $pol_langpackage->pol_add_award;?></a></li>
				<li><a href='javascript:void(0)' onclick='show_set_config("add_option",<?php echo $poll_row["p_id"];?>);'><?php echo $pol_langpackage->pol_add_option;?></a></li>
				<li><a href='javascript:void(0)' onclick='show_set_config("del_poll",<?php echo $poll_row["p_id"];?>);'><?php echo $pol_langpackage->pol_del_poll;?></a></li>
				<li><a href='javascript:void(0)' onclick='show_set_config("change_date",<?php echo $poll_row["p_id"];?>);'><?php echo $pol_langpackage->pol_c_date;?></a></li>
				<li><a href='javascript:void(0)' onclick='show_set_config("add_summary",<?php echo $poll_row["p_id"];?>);'><?php echo $pol_langpackage->pol_write_sum;?></a></li>
			</ul>
			<?php }?>
		   <div id='set_config' style='display:none;' class='ajax_window'></div>
		   <div class="clear"></div>
		   <div class="poll_title"><span class="main_title_dot5"></span><?php echo filt_word($poll_row['subject']);?><span class="poll_choice"><?php echo str_replace("{s_num}",$poll_row['maxchoice'],$pol_langpackage->pol_s_num);?></span>
		   </div>
		   <div class='poll_credit <?php echo $show_award_int;?>'><?php echo str_replace("{int}",$poll_row['percredit'],$pol_langpackage->pol_award_int);?> <?php echo filt_word($poll_row['message']);?></div>

	<form action='<?php echo $action_URL;?>' method='post' onsubmit='return <?php echo $check_form;?>' style='margin-left:0px'>
		<input type='hidden' name='credit' value='<?php echo $poll_row['credit'];?>' />
		<input type='hidden' name='percredit' value='<?php echo $poll_row['percredit'];?>' />
		<input type='hidden' name='subject' value='<?php echo $poll_row['subject'];?>' />
	<?php $default_id=0;?>
	<?php foreach($p_result_rs as $rs){?>
	
		<div class="poll_area"><input type='<?php echo choo_type($poll_row['multiple']);?>' name='pol_cho[]' value="<?php echo $rs['oid'];?>" class='<?php echo $show_check;?> poll_selbt' />
			<div class="poll_option"><?php echo $rs['option'];?>：</div>
			<div class="poll_percent">
				<div id='poll_bg_<?php echo $default_id;?>' class="poll_init" style="width:1px;"></div>
			</div>&nbsp;<?php echo $rs['votenum'];?>&nbsp;(<?php echo option_per($rs['votenum'],$sum_poll_num['sum_votenum']);?>%)
		</div>
	<?php if(!empty($sum_poll_num['sum_votenum'])){?>
		<script type='text/javascript'>
			function incr(){
				var width_val=parseInt(document.getElementById("poll_bg_<?php echo $default_id;?>").style.width);		
				
				if(width_val>=140*<?php echo $rs['votenum']/$sum_poll_num['sum_votenum'];?>){
					window.clearInterval("padding_option_<?php echo $default_id;?>");
				}else{
					document.getElementById("poll_bg_<?php echo $default_id;?>").style.width=width_val+1+"px";
				}
			}
			var color_type=Array("b1.gif","b2.gif","b3.gif","b4.gif","b5.gif","b6.gif","b7.gif","b8.gif","b9.gif","b10.gif","b1.gif");
			var color_s=Math.round(Math.random()*10);
			var url = "url(skin/<?php echo $skinUrl;?>/images/vote/"
			document.getElementById("poll_bg_<?php echo $default_id;?>").style.backgroundImage = url + color_type[color_s] +')';			
			var padding_option_<?php echo $default_id;?>=window.setInterval(incr,30);
			
		</script>
	<?php }?>	
	<?php $default_id++;?>
	<?php }?>
	<div class="poll_button">
		<input type='submit' class='top_button' name='action' value='<?php echo $pol_langpackage->pol_title;?>' />&nbsp;&nbsp;<input type='checkbox' value='1' name='anonymity' /><?php echo $pol_langpackage->pol_anon;?>
	</div>	
	</form>
<div class="clear"></div>
<!--总结报告!-->
<div class='poll_summary <?php echo $show_sumary;?>'>
	<?php echo str_replace("{name}",filt_word($poll_row['username']),$pol_langpackage->pol_sumary);?>
	<div class='poll_summary_content'>
		<div class="left_g left"></div><div class="center_g left"><?php echo filt_word($poll_row['summary']);?></div><div class="right_g left"></div>
	</div>
</div>
</div>

<!--最新投票区!-->
<div class="container <?php echo $show_poll_info;?>">
	<div class="rs_head"><?php echo $pol_langpackage->pol_info;?></div>
</div>
<ul class="poll_list">
<?php foreach($p_put_info as $rs){?>
	<li class='poll_credit'><?php echo anon_poll($rs['anony'],$rs['uid'],$rs['username']);?> <?php echo str_replace(array("{date}","{option}"),array(format_datetime_txt($rs['dateline']),$rs['option']),$pol_langpackage->pol_input_info);?></li>
<?php }?>
</ul>

<div class="tleft ml20">
		<div class="replytip"></div>
		<div id='show_4_<?php echo $poll_row["p_id"];?>'>
			<?php echo get_restore($dbo,4,$poll_row["p_id"],0,20);?>
		</div>
		<?php if($ses_uid!=''){?>	
		<div class="reply <?php echo $show_i_com;?>">
			<img src='<?php echo get_sess_userico();?>' onerror="parent.pic_error(this)" />
			<textarea maxlength="160" onkeyup="return isMaxLen(this)" style="height:50px" id="reply_4_<?php echo $poll_row['p_id'];?>_input"></textarea>
			<div class="replybt">
				<input class="left button2" onclick="parent.restore_com(<?php echo $poll_row['user_id'];?>,4,<?php echo $poll_row['p_id'];?>);show('face_list_menu',200)" type="submit" name="button" id="button" value="<?php echo $pol_langpackage->pol_submit;?>" />
				<a id="reply_a_<?php echo $poll_row['p_id'];?>_input" class="right" href="javascript:void(0);" onclick=" showFace(this,'face_list_menu','reply_4_<?php echo $poll_row['p_id'];?>_input');"><?php echo $pol_langpackage->pol_face;?></a> 
			</div>
			<div class="clear"></div>
		</div>
		<?php }?>
		</div>
<?php }?>
	<!-- face begin -->
	<div id="face_list_menu" class="emBg" style="display:none;z-index:100;">
	</div>
	<!-- face end -->

<!--无数据-->
<div class="pageerr <?php echo $show_error;?>">
	<?php echo $error_str;?>
</div>

</body>
</html>
