<?php
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright (c) 2005 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------*/
require_once "../../maincore.php";
require_once THEMES."templates/header.php";

include INFUSIONS."ip_poll_panel/infusion_db.php";

if (file_exists(INFUSIONS."ip_poll_panel/locale/".$settings['locale'].".php")) {
	include INFUSIONS."ip_poll_panel/locale/".$settings['locale'].".php";
} else {
	include INFUSIONS."ip_poll_panel/locale/English.php";
}

$result = dbquery("SELECT * FROM ".DB_IP_POLLS." WHERE poll_ended!='0' ORDER BY poll_id DESC");
if (dbrows($result) != 0) {
	$view_list = "";
	while ($data = dbarray($result)) {
		$view_list .= "<option value='".$data['poll_id']."'>".$data['poll_title']."</option>\n";
	}
	opentable($locale['PLAN_107']);
	echo "<form name='pollsform' method='post' action='".FUSION_SELF."'>
<center>
".$locale['PLAN_108']."<br>
<select name='oldpoll_id' class='textbox'>
$view_list</select>
<input type='submit' name='view' value='".$locale['PLAN_109']."' class='button'>
</center>
</form>\n";
	closetable();
}
if (isset($_POST['oldpoll_id'])) {
	$data = dbarray(dbquery("SELECT * FROM ".DB_IP_POLLS." WHERE poll_id='".$_POST['oldpoll_id']."' AND poll_ended!='0'"));
	$oldpoll_votes = 0;
	for ($i=0; $i<=9; $i++) {
		if ($data["poll_opt_".$i]) $oldpoll_option[$i] = $data["poll_opt_".$i];
		$oldpoll_votes = $oldpoll_votes + $data["poll_votes_".$i];
	}
	$poll_archive = ""; $i = 0;
	while ($i < count($oldpoll_option)) {
		$oldnum_votes = $data["poll_votes_".$i];
		$oldopt_votes = ($oldpoll_votes ? number_format(100 / $oldpoll_votes * $oldnum_votes) : 0);
		$poll_archive .= $oldpoll_option[$i]."<br>
<img src='".THEME."images/pollbar.gif' alt='".$oldpoll_option[$i]."' height='12' width='$oldopt_votes%' class='poll'><br>
".$oldopt_votes."% [".$oldnum_votes." ".($oldnum_votes == 1 ? $locale['PLAN_102'] : $locale['PLAN_103'])."]<br>\n";
		$i++;
	}
	tablebreak();
	opentable($locale['PLAN_110']);
	echo "<table align='center' width='200' cellspacing='0' cellpadding='0' class='tbl'>
<tr>
<td>".$data['poll_title']."
<hr>
$poll_archive
<center><br>
".$locale['PLAN_104'].$oldpoll_votes."<br>
".$locale['PLAN_105'].showdate("shortdate", $data['poll_started'])."<br>
".$locale['PLAN_106'].showdate("shortdate", $data['poll_ended'])."
</center>
</td>
</td>
</table>\n";
	closetable();
}

require_once THEMES."templates/footer.php";
?>