Jump to content

christam1

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

christam1's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I've got this at the bottom right around where the results table gets called after someone has voted. // otherwise, add single vote else { addVote($request_pid, $request_vote); } I also have at the top $one_vote_per_user = 1; and around the middle // if user has already voted, display poll with error message if (($one_vote_per_user == 1) && isset($_COOKIE['xmlPoll_' . $request_pid])) { printResults($request_pid, "You voted on " . $_COOKIE['xmlPoll_' . $request_pid] . "."); } I'm actually so confused, this stuff is what the creator of the original script put in!
  2. Hi there, I've created this PHP voting script based on a template, but using XML with it as well as SWFs...and I'm wondering why anyone can vote more than once, it's really irritating me! If somebody could possibly have a look at this and tell me what might be wrong with the setcookie part of the script that would be great! The script is supposed to let any one user on a computer vote only once, not as many times as they like which is what it's currently doing!! You can see what it is currently doing here http://www.st-augustines.worcs.sch.uk/departments/music/ <title>-Pop Icons 2009-</title> <? // // SET VARIABLES // // name of XML file which contains your image data $xml_file = "poll.xml"; // path to header file $header_file = "poll_header.inc"; // path to footer file $footer_file = "poll_footer.inc"; // set to 0 for testing $one_vote_per_user = 1; // import request variables import_request_variables("gp", "request_"); // make "request_pid" an integer settype($request_pid, "integer"); // // DEFINE FUNCTIONS // // isClosed(): check whether poll is closed // if poll is closed, return closing date // if poll is not closed, return false function isClosed($pid) { // get "polls" object into this scope global $polls; // get closing date and split into three parts (year, month, and day) $closing_date = explode("-", $polls->poll[$pid]->closingdate); // if today's date is after closing date, then return closing date if (mktime() > mktime(0, 0, 0, $closing_date[1], $closing_date[2], $closing_date[0])) { $closing_date = date("l, F j, Y", mktime(0, 0, 0, $closing_date[1], $closing_date[2], $closing_date[0])); return $closing_date; } // if today's date is on or before closing date, return false else { return false; } } // printVotingForm(): print voting form function printVotingForm($pid) { // get these variables in this scope global $polls, $header_file, $footer_file; // include header file include($header_file); // print poll title and form echo "<h3 style=\"text-align: center\">" . $polls->poll[$pid]['title'] . "</h3>\n"; echo "<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">\n"; echo "<fieldset>\n"; echo "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />\n"; echo "<ul style=\"list-style-type: none\">\n"; echo "<table class=\"dark\" width=\"10%\" height=\"10\" cellspacing=\"12\" cellpadding=\"15\">\n"; // count number of answers $no_answers = count($polls->poll[$pid]->answers->answer); $flash = $polls->poll[$pid]->answers->answer[$i]->flash; // print each answer as a checkbox if ($polls->poll[$pid]->multipleanswers == "yes") { for ($i = 0; $i < 5; $i++) { echo "<li><input type=\"checkbox\" name=\"vote[]\" value=\"" . $polls->poll[$pid]->answers->answer[$i]->name . "\" />" . $polls->poll[$pid]->answers->answer[$i]->name . (isset($polls->poll[$pid]->answers->answer[$i]->image)? '<img src="' . $polls->poll[$pid]->answers->answer[$i]->image . '">' :''). "</li>\n"; } } // print each answer as a radio button else { for ($i = 0; $i < 3; $i++) { echo "<td>"; $name = $polls->poll[$pid]->answers->answer[$i]->name; $song = $polls->poll[$pid]->answers->answer[$i]->song; $image = $polls->poll[$pid]->answers->answer[$i]->image; $flash = $polls->poll[$pid]->answers->answer[$i]->flash; $embedImg = "<br /><img src='{$image}' />"; $embedFlash = "<br /><object width='100' height='30'> <param name='movie' value='{$flash}'> <embed src='{$flash}'></embed> <param name='SCALE' value='noborder' /> </object>"; echo "<input type='radio' name='vote' value='{$name}' /><br />" . "<strong>$name;</strong>"; echo "<br />" . $song; echo !empty($image) ? $embedImg : ''; echo !empty($flash) ? $embedFlash : ''; "\n"; } } echo "<tr>"; echo "<tr>"; echo "<tr>"; echo "<tr>"; echo "<tr>"; echo "<tr>"; echo "</table>"; echo "</ul>\n"; echo "<p style=\"text-align: center\"><input type=\"submit\" value=\"Vote\" /> or <a href=\"" . $_SERVER['PHP_SELF'] . "?pid=$pid&view_results=1\">View Results</a></p>\n"; echo "</fieldset>\n"; echo "</form>\n"; // include footer file include($footer_file); } // addVote(): add user's vote to XML file function addVote($pid, $vote) { // get variables into this scope global $polls, $xml_file; // update vote tally for ($i = 0; $i < count($polls->poll[$pid]->answers->answer); $i++) { if ($polls->poll[$pid]->answers->answer[$i]->name == $vote) { $polls->poll[$pid]->answers->answer[$i]->tally = $polls->poll[$pid]->answers->answer[$i]->tally + 1; break; } } // update XML file with new tally $fp_xml_file = fopen($xml_file, "w"); fwrite($fp_xml_file, $polls->asXML()); fclose($fp_xml_file); } // printResults(): display results with optional message function printResults($pid, $message = "") { // get variables into this scope global $polls, $header_file, $footer_file; // include header file include($header_file); // print header echo "<h3 style=\"text-align: center\">" . $polls->poll[$pid]['title'] . "</h3>\n"; // print optional message if ($message != "") { echo "<p style=\"text-align: center\">$message</p>\n"; } // count number of answers $no_answers = count($polls->poll[$pid]->answers->answer); // calculate total number of votes for ($i = 0; $i < $no_answers; $i++) { // add this vote subtotal to "grand_total" variable $grand_total += $polls->poll[$pid]->answers->answer[$i]->tally; } // begin printing results table echo "<table class=\"dark\" width=\"100%\">\n"; // print a table row for each answer for ($i = 0; $i < $no_answers; $i++) { // calculate this answer's percentage of total number of votes if ($grand_total == 0) { $percentage = 0; } else { $percentage = ($polls->poll[$pid]->answers->answer[$i]->tally / $grand_total) * 100; // round percentage to 1 decimal place $percentage = round($percentage, 1); } echo "<tr>\n"; echo "\t<th class=\"dark\">" . $polls->poll[$pid]->answers->answer[$i]->name . "</th>\n"; // if percentage is 0, do not print a bar if ($percentage == 0) { echo "\t<td></td>\n"; echo "\t<td>0%</td>\n"; } // otherwise, print a bar else { echo "\t<td><img src=\"poll.jpg\" alt=\"$percentage%\" height=\"15\" width=\"$percentage\" /></td>\n"; echo "\t<td>$percentage%</td>\n"; } // print vote subtotal for this answer if ($polls->poll[$pid]->answers->answer[$i]->tally == 0) { echo "\t<td>0 votes</td>\n"; } elseif ($polls->poll[$pid]->answers->answer[$i]->tally == 1) { echo "\t<td>1 vote</td>\n"; } else { echo "\t<td>" . $polls->poll[$pid]->answers->answer[$i]->tally . " votes</td>\n"; } echo "</tr>\n"; } // finish printing results table echo "</table>\n"; // print total number of votes echo "<p style=\"text-align: center\">Total Votes Cast: <b>$grand_total</b></p>\n"; // include footer file include($footer_file); } // // GET XML DATA // // create SimpleXML object from XML file $polls = simplexml_load_file($xml_file); // // PROGRAM CODE // // print results if ($view_results) { printResults($request_pid); } // if poll is closed, display poll with closing date elseif ($closing_date = isClosed($request_pid)) { printResults($request_pid, "The poll closed on $closing_date."); } // if poll is open, check whether user voted else { // if user has not voted, display voting form if (!isset($request_vote) && !isset($_COOKIE['xmlPoll_' . $request_pid])) { printVotingForm($request_pid); } // if user has voted, attempt to add his vote else { // if user has already voted, display poll with error message if (($one_vote_per_user == 1) && isset($_COOKIE['xmlPoll_' . $request_pid])) { printResults($request_pid, "You voted on " . $_COOKIE['xmlPoll_' . $request_pid] . "."); } // otherwise, add vote else { // if user cast multiple votes, add each vote if (is_array($request_vote)) { for ($i = 0; $i < count($request_vote); $i++) { addVote($request_pid, $request_vote[$i]); } } // otherwise, add single vote else { addVote($request_pid, $request_vote); } // add cookie to user's computer to prevent repeat voting setcookie("xmlPoll_$request_pid", date("l, F j, Y"), time()+60*60*24*90, "/", ".fromthedesk.com"); // then display poll printResults($request_pid); } } } ?> Thanks for your help Chris
  3. Hi there, I'm creating a voting system (which needs to be ready by this Thursday) with PHP, XML and Flash. The only thing that is puzzling me now is the fact that when I load in flash files into the PHP table (using XML in between), for some reason they are being blown up a lot bigger than they should be. The swfs are exported at 100W and 30H but are being expanded possibly to the dimensions of the table cell they are being put in - I have no idea how to sort this out!! You can see the site here http://www.st-augustines.worcs.sch.uk/departments/music/ Any ideas why this could be happening? I've tried a few different settings in Flash when outputting the swf but nothing seems to help! Here's my PHP: <? // // SET VARIABLES // // name of XML file which contains your image data $xml_file = "poll.xml"; // path to header file $header_file = "poll_header.inc"; // path to footer file $footer_file = "poll_footer.inc"; // set to 0 for testing $one_vote_per_user = 0; // import request variables import_request_variables("gp", "request_"); // make "request_pid" an integer settype($request_pid, "integer"); // // DEFINE FUNCTIONS // // isClosed(): check whether poll is closed // if poll is closed, return closing date // if poll is not closed, return false function isClosed($pid) { // get "polls" object into this scope global $polls; // get closing date and split into three parts (year, month, and day) $closing_date = explode("-", $polls->poll[$pid]->closingdate); // if today's date is after closing date, then return closing date if (mktime() > mktime(0, 0, 0, $closing_date[1], $closing_date[2], $closing_date[0])) { $closing_date = date("l, F j, Y", mktime(0, 0, 0, $closing_date[1], $closing_date[2], $closing_date[0])); return $closing_date; } // if today's date is on or before closing date, return false else { return false; } } // printVotingForm(): print voting form function printVotingForm($pid) { // get these variables in this scope global $polls, $header_file, $footer_file; // include header file include($header_file); // print poll title and form echo "<h3 style=\"text-align: center\">" . $polls->poll[$pid]['title'] . "</h3>\n"; echo "<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">\n"; echo "<fieldset>\n"; echo "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />\n"; echo "<ul style=\"list-style-type: none\">\n"; echo "<table class=\"dark\" width=\"100%\" cellspacing=\"2\" cellpadding=\"5\">\n"; // count number of answers $no_answers = count($polls->poll[$pid]->answers->answer); $flash = $polls->poll[$pid]->answers->answer[$i]->flash; // print each answer as a checkbox if ($polls->poll[$pid]->multipleanswers == "yes") { for ($i = 0; $i < 5; $i++) { echo "<li><input type=\"checkbox\" name=\"vote[]\" value=\"" . $polls->poll[$pid]->answers->answer[$i]->name . "\" />" . $polls->poll[$pid]->answers->answer[$i]->name . (isset($polls->poll[$pid]->answers->answer[$i]->image)? '<img src="' . $polls->poll[$pid]->answers->answer[$i]->image . '">' :''). "</li>\n"; } } // print each answer as a radio button else { for ($i = 0; $i < 3; $i++) { echo "<td>"; $name = $polls->poll[$pid]->answers->answer[$i]->name; $song = $polls->poll[$pid]->answers->answer[$i]->song; $image = $polls->poll[$pid]->answers->answer[$i]->image; $flash = $polls->poll[$pid]->answers->answer[$i]->flash; $embedImg = "<br /><img src='{$image}' />"; $embedFlash = "<br /><object width='100' height='30'> <param name='movie' value='{$flash}'> <embed src='{$flash}'></embed> </object>"; echo "<input type='radio' name='vote' value='{$name}' /><br />" . "<strong>$name;</strong>"; echo "<br />" . $song; echo !empty($image) ? $embedImg : ''; echo !empty($flash) ? $embedFlash : ''; "\n"; } } and my XML from which the PHP file is looking for swfs from! <?xml version="1.0"?> <polls> <poll title="Who do you think should win Pop Icons 2009?"> <answers> <answer> <name>Axelle:</name> <song>Killing Me Softly</song> <tally>0</tally> <image>images/1.jpg</image> <flash>songs/1.swf</flash> </answer> <answer> <name>Bethanie:</name> <song>I Think We're Alone Now</song> <tally>0</tally> <image>images/2.jpg</image> <flash>songs/2.swf</flash> </answer> <answer> <name>Ciara:</name> <song>Serious</song> <tally>0</tally> <image>images/3.jpg</image> <flash>songs/3.swf</flash> </answer> </answers> <multipleanswers>no</multipleanswers> <closingdate>31-01-2009</closingdate> </poll> </polls> If someone could look through it for me that would be fab - if you have any ideas they would be greatly appreciated!! Cheers Chris
  4. Hi there, I'm creating a PHP/XML-based voting system. There are 24 options for a user to vote from, and ideally I'd like the user to see a picture of each person they vote for. So far, I've managed to list all the names of people up for voting from a "poll.xml" file in my "poll.php" file which is what web users will go to in order to vote. It also correctly updates the tally in the XML file when a person is voted for. The only thing that doesn't work now is trying to get an image to display next to each person's name...any ideas? Or would I have to learn XSLT to do this? (I have none currently, just a plain XML file and PHP file). Thanks for your time! Appropriate sections of each file are below POLL.PHP function printVotingForm($pid) { // get these variables in this scope global $polls, $header_file, $footer_file; // include header file include($header_file); // print poll title and form echo "<h3 style=\"text-align: center\">" . $polls->poll[$pid]['title'] . "</h3>\n"; echo "<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">\n"; echo "<fieldset>\n"; echo "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />\n"; echo "<ul style=\"list-style-type: none\">\n"; // count number of answers $no_answers = count($polls->poll[$pid]->answers->answer); // print each answer as a checkbox if ($polls->poll[$pid]->multipleanswers == "yes") { for ($i = 0; $i < $no_answers; $i++) { echo "<li><input type=\"checkbox\" name=\"vote[]\" value=\"" . $polls->poll[$pid]->answers->answer[$i]->name . "\" />" . $polls->poll[$pid]->answers->answer[$i]->name . "</li>\n"; } } // print each answer as a radio button else { for ($i = 0; $i < $no_answers; $i++) { echo "<li><input type=\"radio\" name=\"vote\" value=\"" . $polls->poll[$pid]->answers->answer[$i]->name . "\" />" . $polls->poll[$pid]->answers->answer[$i]->name . "</li>\n"; } } echo "</ul>\n"; echo "<p style=\"text-align: center\"><input type=\"submit\" value=\"Vote\" /> or <a href=\"" . $_SERVER['PHP_SELF'] . "?pid=$pid&view_results=1\">View Results</a></p>\n"; echo "</fieldset>\n"; echo "</form>\n"; // include footer file include($footer_file); POLL.XML <?xml version="1.0"?> <polls> <poll title="Who do you think should win the vote this year?"> <answers> <answer> <name>Michael</name> <tally>0</tally> <image>src_here.gif</image> </answer> <answer> <name>Sophie</name> <tally>0</tally> </answer> </answers> </poll> </polls>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.