/* This page implements an opinion poll for a yes/no question
	One person one vote - attempt to enforce this with a cookie. 3 cases:
   1. New user, give a form (no cookie, no vote)
   2. Vote to be tallied    (no cookie, vote in Q.Str.) -- also give result
   3. Previously voted	    (cookie set)	just give current result
	Author: Lin Jensen, for csc103 class
	November 7, 2008
$ftnfile = 'tally.php';  // or 'tally-db.php';
error_reporting(E_ALL ^ E_NOTICE);
if ($_COOKIE['voted']!='true')
    if (!isset($_GET['vote']))
    {  // give the form			?>
	  <title>yes-no vote form</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
 form  {background-color:#c8f; padding-left:5em;} 
	</head><body onload="document.forms[0].reset()">
	<img src="http://cs-linux.ubishops.ca/%7Ejensen/coat-arm2.jpg
" align=left>
<p>Bishop's University has an official coat of arms, designed by the Canadian College of Heralds in 1993,
 for the Sesquicentennial.
Recently the logo on the BU website was changed to a design that is not acceptable to the college,
in that the Latin motto is removed, and the crest resembles more that of the Anglican Diocese of Ontario.
<p>Last spring, several petitions and representations were made by faculty and students, to the principal,
 calling for a return to the official crest, with the motto. The response so far has
been, don't expect us to throw away stationary already printed. 
However, to revert the website is a simple matter. 
So the question today is: </p>
<h1>Which logo do you prefer for the BU website?</h1>
	<p>Your opinion?</p>
function checkform(f) {
if (f.name.value=='')
{ alert("Type your name")
  return false
if (!(f.vote[0].checked || f.vote[1].checked)) 
{	alert('Make up your mind!'); 
	return false;
return true
	<form action=yesnovote.php method=get onsubmit="return checkform(this)">
		<br><input type=radio name=vote value=yes> <img src=
align=middle style="background:white">
		<input type=radio name=vote value=no> 
<img src="http://cs.ubishops.ca/images1/BU-logo-purple2.png"
Your name: <input name=name><br><br>
	<input type=submit
		value="Register my opinion"> <input type=reset>
	die("You will see the results so far after you have voted");
    {  // tally the vote
	$vote = $_GET['vote'];
	$name= $_GET['name'];
	tally($vote, $name);
	setcookie('voted','true', time()+3600*24*30);	// to prevent extra votes
// now give result
gettally($yes, $no);
$both = $yes+$no;
  <title>yes-no result</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<img src="http://cs-linux.ubishops.ca/%7Ejensen/coat-arm2.jpg
" align=left>
<?php if($vote) print "You just voted $vote<br>"; 
	if (!$both) die ("Nobody has voted yet... curious.");
	$yp=round($yes/$both*100);	// percentages
	print "<img src=\"bargraph.php?yes=$yp&no=$np&ylab=New&nlab=Old\" align=right>";
<h2>This week's question: Which logo do you prefer?</h2>
So far, here's what you are saying:
<table cellpadding=6 bgcolor=#aaff88 align=center>
<tr><td>New</td><td> <?php print $yes;?> </td><td> <?php print $yp=round($yes/$both*100).'%';?></td></tr>
<tr><td>Old</td><td> <?php print $no;?> </td><td> <?php print $np=round($no/$both*100).'%';?></td></tr>
<a href=index.html>Home</a>