⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 poll.inc.php

📁 还是WEB游戏源码 Darkstep 还是WEB游戏源码 Darkstep
💻 PHP
字号:
<?php
/*
晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻
WebmasterCity Poll V1.1
晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻晻
*/

class wmpoll {
	function wmpoll($bezoeker) {
		$this->bezoeker = $bezoeker;
	}

	function htmlparse($string){
		return htmlentities(trim($string), ENT_QUOTES);
	}

	function stem($vote) {
		if(is_numeric($vote) && $vote >= 1 && $vote <= 10) {
			$id = $this->list['id'];
			$gestemd = $this->list['gestemd']."(".$this->bezoeker.",".$vote.")";
			$sql = @mysql_query("UPDATE poll SET antwoord".$vote."=antwoord".$vote."+1, gestemd='".$gestemd."' WHERE id='$id'");
			if($sql) {
				$this->list["antwoord".$vote]++;
			}
		}
	}

	function archief($aantal=0) {
		GLOBAL $HTTP_SERVER_VARS;
		if($aantal != 0) {
			$limit = " LIMIT ".$aantal;
		} else {
			$limit = "";
		}
		$sql = @mysql_query("SELECT id, vraag FROM poll ORDER BY id DESC".$limit);
		echo "<select name=\"pollarchief\" onChange=\"window.location=('".$HTTP_SERVER_VARS['PHP_SELF']."?pollid='+this.options[this.selectedIndex].value)\">\n<option value=\"\">Archief</option>/n";
		while($list = @mysql_fetch_assoc($sql)) {
			echo "<option value=\"".$list['id']."\">".$this->htmlparse($list['vraag'])."</option>\n";
		}
		echo "</select>\n";
	}

	function toon($id=0, $magstemmen=1, $balkje=200, $kleur1="#A9A9A9", $kleur2="#FF9900") {
		GLOBAL $HTTP_POST_VARS, $HTTP_SERVER_VARS;
		if($id == 0) {
			$sql = @mysql_query("SELECT * FROM poll WHERE actief='1' ORDER BY id DESC LIMIT 1");
		} else {
			$id = addslashes($id);
			$sql = @mysql_query("SELECT * FROM poll WHERE id='$id'");
		}

		// bestaat poll?
		$bestaat = @mysql_num_rows($sql);
		if($bestaat == 0 && $id == 0) {
			echo "Error: there is atm no active poll!\n";
		} elseif($bestaat == 0) {
			echo "Error: the poll doesn't excist!\n";
		} else {

			$this->list = @mysql_fetch_assoc($sql);

			// mag de bezoeker stemmen?
			if($magstemmen == 0 || preg_match("/\(".$this->bezoeker.",/", $this->list['gestemd'])) {
				$magstemmen = 0;
			} else {
				$magstemmen = 1;
			}

			// poll type
			if($this->list['actief'] == 1) {
				$type = "Active";
			} else {
				$type = "Archief";
				$magstemmen = 0;
			}

			// stem opslaan
			if($magstemmen == 1 && isset($HTTP_POST_VARS['pollvote']) && isset($HTTP_POST_VARS['pollid']) && $HTTP_POST_VARS['pollid'] == $this->list['id']) {
				$this->stem($HTTP_POST_VARS['pollvote']);
				$magstemmen = 0;
			}

			// totaal aantal stemmen
			$totaal = 0;
			for($x=1; $x<=10; $x++) {
				$totaal = $totaal + $this->list["antwoord".$x];
			}

			// poll weergeven
			if($magstemmen == 1) {
				echo "<form action=\"".$HTTP_SERVER_VARS['REQUEST_URI']."\" method=\"POST\">\n<input type=\"hidden\" name=\"pollid\" value=\"".$this->list['id']."\">\n";
			}
			echo "<b>".$this->htmlparse($this->list['vraag'])."</b><br>\nVotes: ".$totaal."<br>\nDate: ".date("d-m-Y", $this->list['datum'])."<br>\nType: ".$type."<br><br>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";

			for($x=1; $x<=10; $x++) {
				if(!empty($this->list["keuze".$x])) {
					// resultaten berekenen
					if($totaal != 0) {
						$procent = round(($this->list["antwoord".$x]/$totaal)*100);
						$balk = ($this->list["antwoord".$x]/$totaal)*$balkje;
					} else {
						$procent = 0;
						$balk = 0;
					}

					echo "<tr>";
					if($magstemmen == 1) {
						echo "<td><input type=\"radio\" name=\"pollvote\" value=\"".$x."\"></td>";
					}
					echo "<td><b>".$this->htmlparse($this->list["keuze".$x])."</b>&nbsp;&nbsp;&nbsp;</td><td>".$procent." %&nbsp;&nbsp;&nbsp;</td><td>\n<table width=\"".$balkje."\" height=\"10\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"border: 1px solid ".$kleur1.";\"><tr><td width=\"".$balk."\" bgcolor=\"".$kleur2."\"></td><td width=\"".($balkje-$balk)."\"></td></tr></table>\n</td></tr>\n";
				}
			}

			echo "</table>\n";

			if($magstemmen == 1) {
				echo "<input type=\"submit\" name=\"submit\" value=\"Stem\">\n</form>\n";
			}
		}
	}
}
?>

⌨️ 快捷键说明

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