libvote.php

来自「linux/unix环境下的建站系统」· PHP 代码 · 共 809 行 · 第 1/2 页

PHP
809
字号
</center><?php			}		function svCreateVoteStepThree()	{		global $currentuser,$sysVoteConfig;		$this->user = $currentuser;?><center><p align=center><strong>创建系统投票</strong></p><form action="<?php echo $_SERVER["PHP_SELF"]; ?>?act=create&step=4" name="svs3" id="svs3" method="post"><table cellspacing=0 cellpadding=5 class=t1 border=0 width=90%>	<tr><td colspan=2 class=t2>第三步:设定投票选项</td></tr>	<input type="hidden" name="svsubject" value="<?php echo $_POST["svsubject"]; ?>">	<input type="hidden" name="svdesc" value="<?php echo $_POST["svdesc"]; ?>">	<input type="hidden" name="svannouce" value="<?php echo (int)($_POST["svannouce"]); ?>">	<input type="hidden" name="svtimelong" value="<?php echo (int)($_POST["svtimelong"]); ?>">	<input type="hidden" name="svanonymous" value="<?php echo (int)($_POST["svanonymous"]); ?>">	<input type="hidden" name="svvotesperip" value="<?php echo (int)($_POST["svvotesperip"]); ?>">	<input type="hidden" name="svprobnum"" value="<?php echo (int)($_POST["svprobnum"]); ?>"><?php	for($i = 0 ; $i< (int)($_POST["svprobnum"]) ; $i ++)	{?>		<input type="hidden" name="svprob<?php echo $i + 1; ?>" value="<?php echo $_POST["svprob".($i + 1)]; ?>">	<input type="hidden" name="svprobtype<?php echo $i + 1 ;?>" value="<?php echo (int)($_POST["svprobtype".($i+1)]); ?>">	<input type="hidden" name="svprobetem<?php echo $i + 1 ;?>" value="<?php echo $_POST["svprobetem".($i+1)]; ?>"><?php		}	for($i = 0 ; $i< (int)($_POST["svprobnum"]) ; $i ++)	{?>		<tr>		<td class=t2></strong>问题<font color=#FF0000><?php echo $i + 1; ?></font>:</strong></td>		<td class=t5><input type="text" name="svprob<?php echo $i+1; ?>" size=100 class=b9 value="<?php echo $_POST["svprob".($i + 1)]; ?>"></td>	</tr>	<tr>		<td class=t3>类型</td>		<td class=t5>			<input type="radio" class=b9 name="svprobtype<?php echo $i + 1; ?>" value=0 <?php echo ((int)($_POST["svprobtype".($i+1)])==0)?"checked":""; ?>>单选			<input type="radio" class=b9 name="svprobtype<?php echo $i + 1; ?>" value=1 <?php echo ((int)($_POST["svprobtype".($i+1)])==1)?"checked":""; ?>>多选			<input type="radio" class=b9 name="svprobtype<?php echo $i + 1; ?>" value=2 <?php echo ((int)($_POST["svprobtype".($i+1)])==2)?"checked":""; ?>>单选带问答			<input type="radio" class=b9 name="svprobtype<?php echo $i + 1; ?>" value=3 <?php echo ((int)($_POST["svprobtype".($i+1)])==3)?"checked":""; ?>>多选带问答			<input type="radio" class=b9 name="svprobtype<?php echo $i + 1; ?>" value=4 <?php echo ((int)($_POST["svprobtype".($i+1)])==4)?"checked":""; ?>>问答		</td>	</tr>	<tr>		<td class=t3>选项</td>		<td class=t5>		<textarea name="svprobetem<?php echo $i + 1; ?>" class=b9 cols=80 rows=3><?php echo $_POST["svprobetem".($i+1)]; ?></textarea>		<br />(请用"|"符号隔开选择性问题的多个选项,问答题直接输入题目.)		</td>	</tr><?php	}?>	<tr>		<td class=t2 colspan=2>		<input type="button" value="<<上一步" class="b9" onclick="document.svs3.action='<?php echo $_SERVER["PHP_SELF"]; ?>?act=create&step=2';document.svs3.submit();">		<input type="submit" value="下一步>>" class="b9">		</td>	</tr></table></form></center><?php			}	function svCreateVoteStepFour()	{		global $currentuser,$sysVoteConfig;		$this->user = $currentuser;?><center><p align=center><strong>创建系统投票</strong></p><form action="<?php echo $_SERVER["PHP_SELF"]; ?>?act=create&step=5" name="svs3" id="svs3" method="post"><table cellspacing=0 cellpadding=5 class=t1 border=0 width=90%>	<tr><td colspan=2 class=t2>第四步:确认投票选项</td></tr>	<input type="hidden" name="svsubject" value="<?php echo $_POST["svsubject"]; ?>">	<input type="hidden" name="svdesc" value="<?php echo $_POST["svdesc"]; ?>">	<input type="hidden" name="svannouce" value="<?php echo (int)($_POST["svannouce"]); ?>">	<input type="hidden" name="svtimelong" value="<?php echo (int)($_POST["svtimelong"]); ?>">	<input type="hidden" name="svanonymous" value="<?php echo (int)($_POST["svanonymous"]); ?>">	<input type="hidden" name="svvotesperip" value="<?php echo (int)($_POST["svvotesperip"]); ?>">	<input type="hidden" name="svprobnum"" value="<?php echo (int)($_POST["svprobnum"]); ?>"><?php	for($i = 0 ; $i< (int)($_POST["svprobnum"]) ; $i ++)	{?>		<input type="hidden" name="svprob<?php echo $i + 1; ?>" value="<?php echo $_POST["svprob".($i + 1)]; ?>">	<input type="hidden" name="svprobtype<?php echo $i + 1 ;?>" value="<?php echo (int)($_POST["svprobtype".($i+1)]); ?>">	<input type="hidden" name="svprobetem<?php echo $i + 1 ;?>" value="<?php echo $_POST["svprobetem".($i+1)]; ?>">	<tr>		<td class=t2 width=120></strong>问题<font color=#FF0000><?php echo $i + 1; ?></font>:</strong></td>		<td class=t5><?php echo html_format($_POST["svprob".($i + 1)],TRUE,FALSE); ?>&nbsp;</td>	</tr>	<tr>		<td class=t3>类型</td>		<td class=t5>		<?php			switch((int)($_POST["svprobtype".($i+1)]))			{				case 0:					echo "单选";					break;				case 1:					echo "多选";					break;				case 2:					echo "单选带问答";					break;				case 3:					echo "多选带问答";					break;				case 4:					echo "问答";					break;				default:			}		?>		</td>	</tr>	<tr>		<td class=t3>选项</td>		<td class=t5>		<?php			$etems = svGetProbEtems($_POST["svprobetem".($i+1)],(int)($_POST["svprobtype".($i+1)]));			for($j = 0 ; $j < count($etems) ; $j ++ )			{				echo "<strong>选项<font color=#FF0000>".($j + 1)."</font></strong>\n&nbsp;".html_format($etems[$j],TRUE,FALSE)."<br />";			}		?>		</td>	</tr><?php	}?>	<tr>		<td class=t2 colspan=2>		<input type="button" value="<<上一步" class="b9" onclick="document.svs3.action='<?php echo $_SERVER["PHP_SELF"]; ?>?act=create&step=3';document.svs3.submit();">		<input type="submit" value="开启系统投票" class="b9">		</td>	</tr></table></form></center><?php			}	function svCreateVoteStepFive($link)	{		global $currentuser,$sysVoteConfig;		$this->user = $currentuser;		$svInfor = array(				"subject" => $_POST["svsubject"],				"desc" => $_POST["svdesc"],				"annouce" => (int)($_POST["svannouce"]),				"timelong" => (int)($_POST["svtimelong"]),				"anonymous" => (int)($_POST["svanonymous"]),				"votesperip" => (int)($_POST["svvotesperip"]),				"probnum" => (int)($_POST["svprobnum"]),				"created" => time()					);		$etems = "";		for($i = 0 ; $i < (int)($_POST["svprobnum"]) ; $i ++ )		{			 if($etems!="") $etems .= "|";			 $etems .= base64_encode($_POST["svprob".($i + 1)])."&".(int)($_POST["svprobtype".($i+1)])."&".base64_encode($_POST["svprobetem".($i+1)]); 		}		$svInfor[etems] = $etems;				$svInfor[logs] = addslashes("管理员 ".$this->user["userid"]." 于 ".date("Y-m-d H:i:s")." 自 ".$_SERVER["REMOTE_ADDR"]." 创建本次投票;");		$query = "INSERT INTO `sysvote_votes` ( `svid` , `active` , `subject` , `description` , `changed` , `created` , `annouce` , `probs` , `timelong` , `anonymousvote` , `votesperip` , `votecount` , `logs` , `results` ) ".			"VALUES ('', '1', '".addslashes($svInfor[subject])."', '".addslashes($svInfor[desc])."', '".date("YmdHis")."' , '".date("YmdHis")."', '".$svInfor[annouce]."', '".addslashes($svInfor[etems])."', '".$svInfor[timelong]."', '".$svInfor[anonymous]."', '".$svInfor[votesperip]."', '0', '".$svInfor[logs]."', '');";		mysql_query($query,$link);				if($svInfor[annouce] == 2 )			svPostAnnouce($sysVoteConfig["BOARD"],$svInfor);		if($svInfor[annouce] == 1)			svPostAnnouce("vote",$svInfor);					//生成html文档供mainpage使用		$query = "SELECT svid FROM sysvote_votes WHERE subject = '".addslashes($svInfor[subject])."' AND probs = '".addslashes($svInfor[etems])."' ORDER BY svid DESC LIMIT 0,1";		$result = mysql_query($query,$link);		$rows = mysql_fetch_array($result);		$newSvid = $rows[svid];		$htmlFile = "<form action=\"/bbssysvote.php?svid=".$newSvid."&sv=sv\" method=\"post\"><table width=\"100%\" height=\"18\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"helpert\">".				"<tr><td width=\"16\" background=\"images/lt.gif\">&nbsp;</td><td width=\"66\" bgcolor=\"#0066CC\">系统投票</td><td width=\"16\" background=\"images/rt.gif\"></td>".				"<td>&nbsp;</td></tr></table><table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\" class=\"helper\">".				"<tr><td width=\"100%\" class=\"MainContentText\">".				sysvote_display_probs(sysvote_get_probs($svInfor[etems])).				"<p align=center><input type=submit class=button value=\"投票\">".				"<input type=button class=button value=\"查看\" onclick=\"window.location.href='/bbssysvote.php';\">".				"</p></td></tr></table></form>";		$fp = fopen(BBS_HOME . "/vote/sysvote.html" , "w");		fputs($fp,$htmlFile,strlen($htmlFile));		fclose($fp);?><br /><br /><br /><p align=center><strong>系统投票创建成功!</strong></p><p align=center>[<a href="/bbssysvote.php">点击返回</a>]</p><?php	}}function sysvote_get_etems($etem,$type){	$etems = array();	if($type==4)		$etems[0] = $etem;	else		$etems = explode("|",$etem);	return $etems;}function sysvote_get_probs($probs){	$prob = array();	$probarr = explode("|",$probs);	for($i = 0 ; $i < count($probarr) ; $i ++)	{		if($probdept[1]==4)	$probdept[0]=$probs;		$probdept = explode("&",$probarr[$i]);		$prob[$i] = array(				"prob" => base64_decode($probdept[0]),				"type" => (int)($probdept[1]),				"etems" => sysvote_get_etems(base64_decode($probdept[2]),base64_decode($probdept[1]))				);	}	return $prob;}function sysvote_display_probs($probs){	for($i = 0 ; $i < count($probs) ; $i ++)	{		$output = html_format($probs[$i][prob],TRUE,FALSE)."\n<br />";			switch($probs[$i][type])		{			case 0:				for($j = 0 ; $j < count($probs[$i][etems]) ; $j ++ )					$output .=  "<input type=\"radio\" name=\"ans".$i."\" value=\"".($j + 1)."\">\n<font color=#FF0000><strong>".($j+1)."</strong></font>. ".html_format($probs[$i][etems][$j],TRUE,FALSE)."\n<br />";				break;				case 1:				for($j = 0 ; $j < count($probs[$i][etems]) ; $j ++ )					$output .=  "<input type=\"checkbox\" name=\"ans".$i."e".$j."\" value=\"1\">\n<font color=#FF0000><strong>".($j+1)."</strong></font>. ".html_format($probs[$i][etems][$j],TRUE,FALSE)."\n<br />";				break;				case 2:				for($j = 0 ; $j < count($probs[$i][etems]) ; $j ++ )					$output .=  "<input type=\"radio\" name=\"ans".$i."\" value=\"".($j + 1)."\">\n<font color=#FF0000><strong>".($j+1)."</strong></font>. ".html_format($probs[$i][etems][$j],TRUE,FALSE)."\n<br />";				$output .= "<textarea class=b9 cols=50 rows=5 name=\"ans".$i."p\"></textarea>\n<br />";				break;				case 3:				for($j = 0 ; $j < count($probs[$i][etems]) ; $j ++ )					$output .=  "<input type=\"checkbox\" name=\"ans".$i."e".$j."\" value=\"1\">\n<font color=#FF0000><strong>".($j+1)."</strong></font>. ".html_format($probs[$i][etems][$j],TRUE,FALSE)."\n<br />";				$output .= "<textarea class=b9 cols=50 rows=5 name=\"ans".$i."p\"></textarea>\n<br />";				break;				case 4:				$output .= html_format($probs[$i][etems][0],TRUE,FALSE)."<br /><textarea class=b9 cols=50 rows=5 name=\"ans".$i."\"></textarea>\n<br />";			default:			}		$output .=  "<br />";		return $output;	}}function sysvote_load_votes($link,$start=1,$all=FALSE){	global $sysVoteConfig;		$start = (int)($start);	if($start < 1) $start = 1;	$query = "SELECT * FROM sysvote_votes ORDER BY active DESC , svid DESC LIMIT ".(($start - 1)*$sysVoteConfig["PAGESIZE"])." , ".$sysVoteConfig["PAGESIZE"]." ;";	$result = mysql_query($query,$link);	$votesNum = mysql_num_rows($result);	$votes = array();	for($i = 0 ; $i < $votesNum ; $i ++ )	{		$rows = mysql_fetch_array($result);		$votes[$i] = array(				"svid" => $rows[svid],				"active" => $rows[active],				"subject" => html_format($rows[subject]),				"desc" => html_format($rows[description],TRUE),				"changed" => time_format($rows[changed]),				"created" => time_format($rows[created]),				"annouce" => $rows[annouce],				"probs" => sysvote_get_probs(stripslashes($rows[probs])),				"timelong" => $rows[timelong],				"anonymous" => $rows[anonymousvote],				"votesperip" => $rows[votesperip],				"votecount" => $rows[votecount],				"logs" => $rows[logs]				);	}	return $votes;}function sysvote_load_vote_infor($link,$svid){	global $sysVoteConfig;		$query = "SELECT * FROM sysvote_votes WHERE  svid = ".(int)($svid).";";	$result = mysql_query($query,$link);	$rows = mysql_fetch_array($result);	if(!$rows)		return FALSE;	$vote = array(			"svid" => $rows[svid],			"active" => $rows[active],			"subject" => html_format($rows[subject]),			"desc" => html_format($rows[description],TRUE),			"changed" => time_format($rows[changed]),			"created" => time_format($rows[created]),			"annouce" => $rows[annouce],			"probs" => sysvote_get_probs(stripslashes($rows[probs])),			"timelong" => $rows[timelong],			"anonymous" => $rows[anonymousvote],			"votesperip" => $rows[votesperip],			"votecount" => $rows[votecount],			"logs" => $rows[logs],			"ori" => $rows,			"res" => $rows[results]			);	return $vote;}function sysvote_user_can_vote($link,$vote,$currentuser){	if($vote[anonymous]==0 && ($currentuser[userid]=="guest"||!$currentuser))		return -1;//匿名用户	$query = "SELECT userid FROM sysvote_users WHERE svid = '".$vote[svid]."' AND ( userid = '".$currentuser[userid]."' OR votehost = '".$currentuser[lasthost]."' )";	$result = mysql_query($query,$link);	$i = 0 ;	while($rows=mysql_fetch_array($result))	{		if(strtolower($rows[userid])==strtolower($currentuser[userid]) && $currentuser[userid]!="guest")			return -2;//该ID已投票			$i ++;	}	if($vote[votesperip]!=0 && $i >= $vote[votesperip])		return -3; //该IP已达到最大投票数	return 0;//可以投票}function sysvote_user_vote($link,$vote,$currentuser,$ans){	$query = "INSERT INTO `sysvote_users` ( `suid` , `svid` , `userid` , `votehost` , `votetime` , `voteinfo` ) ".		"VALUES ('', '".$vote[svid]."', '".$currentuser[userid]."', '".$currentuser[lasthost]."', '".date("YmdHis")."', '".$ans."');";	mysql_query($query,$link);	$voteLogs = $vote[logs]."\n用户 ".$currentuser[userid]." 于 ".date("Y-m-d H:i:s")." 自 ".$_SERVER["REMOTE_ADDR"]." 进行投票;";	$query = "UPDATE sysvote_votes SET votecount = votecount + 1 , logs = '".$voteLogs."' WHERE svid = '".$vote[svid]."';";	mysql_query($query,$link);}function sysvote_display_result($vote){	$res = explode("|",$vote[res]);	$voteUserNum = max(1,$res[0]);	$probType = array("单项选择","多项选择","单项选择(可发表意见)","多项选择(可发表意见)","问答");	for($i = 0 ; $i < count($vote[probs]) ; $i ++)	{?><table cellspacing=0 cellpadding=5 width=100% border=0 class=t1>	<tr>		<td colspan=2 class=t3><strong><?php echo $i+1; ?></strong></td>	</tr>	<tr>		<td class=t3 width=200>问题</td>		<td class=t7><?php echo html_format($vote[probs][$i][prob],TRUE,FALSE); ?></td>	</tr>	<tr>		<td class=t3>类型</td>		<td class=t7><?php echo $probType[$vote[probs][$i][type]]; ?></td>	</tr><?php	if($vote[probs][$i][type]==4)		echo "<tr><td class=t3>网友建议</td><td class=t7>".html_format(base64_decode($res[$i+1]),TRUE,FALSE)."</td></tr>";	else	{		$etemcount = explode(",",$res[$i+1]);		for($j = 0 ;$j < count($vote[probs][$i][etems])	; $j ++)		{			$etemcount1 = ((int)(($etemcount[$j]*1000 )/ $voteUserNum)) / 10;			echo "<tr><td class=t3><span title=\"".html_format($vote[probs][$i][etems][$j],FALSE,FALSE)."\">";			echo html_format(substr($vote[probs][$i][etems][$j],0,24),FALSE,FALSE);			if(strlen($vote[probs][$i][etems][$j])>24) echo " ... \n";			echo "</span></td><td class=t7>";			echo "<img src=\"images/bar".($j%10 + 1).".gif\" width=\"".($etemcount1*0.8)."%\" height=10 alt=\"票数:".$etemcount[$j]."  比例:".$etemcount1."\" border=0>";			echo "&nbsp;".$etemcount1."%";			echo "</td></tr>";		}	}	if($vote[probs][$i][type]==2 || $vote[probs][$i][type]==3)		echo "<tr><td class=t3>网友建议</td><td class=t7>".html_format(base64_decode($etemcount[count($vote[probs][$i][etems])]),TRUE,FALSE)."</td></tr>";	?>	</table><?php	}// i 循环  题目}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?