<?php
   $poll        
"poll.php"// The poll file.
   
$user        "Admin";    // Administrator user name
   
$pass        "Admin";    // Administrator password
   
$enable_demo 1;          // Enable demo account?  0 = no, 1 = yes.

   
echo "\n";
   if (((isset(
$_POST['username']) && isset($_POST['password'])) && ($_POST['username']==$user && $_POST['password']==$pass)) || (empty($enable_demo) ^ $_POST['username']=="demo" && $_POST['password']=="demo")) {
    include(
$poll);
    global 
$file$answers$question;
    
$i 0;
    
$demo "no";

    if (
$_POST['username']=="demo" && $_POST['password']=="demo") {
     echo 
"  <small>Using Demo account.</small><br /><br />\n";
     
$demo "yes";
    }
    if (isset(
$_POST['save']) && $demo=="no") {
     
$all $_POST['total'];

     
$edit fopen($file"w");
     for (
$a=0$a<$all$a++) {
      if (
$_POST["$a".'_vote']=="0" ^ !empty($_POST["$a".'_vote']) && !empty($_POST["$a".'_ip'])) {
       
$data .= $_POST["$a".'_vote'] ."|"$_POST["$a".'_ip'] ."\n";
      }
     }
     
fwrite($edit$data);
     
fclose($edit);
     echo 
"  Saved!<br /><br /><br />\n";
     echo 
"  <a href=\"./\">Poll</a> | <a href=\"./?results\">Results</a>\n"// Edit if needed.
    
} else {
     echo 
"  <div id=\"admin_results\">\n  "poll::results();

     echo 
"  </div>\n  <br /><br /><br />\n\n  <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n".
          
"   <div>\n".
          
"    <input type=\"hidden\" name=\"save\" value=\"1\" />\n".
          
"    <input type=\"hidden\" name=\"username\" value=\"".$_POST['username']."\" />\n".
          
"    <input type=\"hidden\" name=\"password\" value=\"".$_POST['password']."\" />\n\n";

     
$poll_file file($file);
     foreach (
$poll_file as $line) {
      
$count count($poll_file);
      
$del explode("\n"$line);
      
$val explode("|"$del[0]);
      if (isset(
$val[0]) && isset($val[1])) {
       echo 
"    <input type=\"text\" title=\"".$answers[$val[0]]."\" class=\"box\" id=\"".$i."_vote\" name=\"".$i."_vote\" value=\"".$val[0]."\" />\n".
            
"    <input type=\"text\" class=\"box\" id=\"".$i."_ip\" name=\"".$i."_ip\" value=\"".$val[1]."\" />\n".
            
"    <span title=\"Delete option; ".$answers[$val[0]]."\" onclick=\"javascript:document.getElementById('".$i."_vote').value='';document.getElementById('".$i."_ip').value='';\" style=\"cursor: pointer;font-family: Courier, Monospace, sans-serif;margin-top: 4px;\">[-]</span>\n".
            
"    <span title=\"Restore option: ".$answers[$val[0]]."\" onclick=\"javascript:document.getElementById('".$i."_vote').value='".$val[0]."';document.getElementById('".$i."_ip').value='".$val[1]."';\" style=\"cursor: pointer;font-family: Courier, Monospace, sans-serif;margin-top: 4px;\">[+]</span>\n".
            
"    <br />\n\n";
       
$i++;
      }
     }

     echo 
"    <input type=\"hidden\" name=\"total\" value=\"$count\" />\n".
          
"    <br /><input type=\"submit\" value=\"Save\" />\n".
          
"   </div>\n".
          
"  </form>\n";
    }
   } else {
    if (
$enable_demo) {
     
$demo_user "value=\"demo\" ";
     
$demo_pass "value=\"demo\" ";
    }
    if (isset(
$_POST['username']) && isset($_POST['password'])) echo "  Bad, bad, <strong>bad</strong>!<br /><br />\n";
    echo 
"  <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n".
         
"   <div>\n".
         
"    Username: <input type=\"text\" name=\"username\" $demo_user/><br />\n".
         
"    Password: <input type=\"password\" name=\"password\" $demo_pass/><br />\n".
         
"    <br /><input type=\"submit\" value=\"Log in\" />\n".
         
"   </div>\n".
         
"  </form>\n";
   }

  
?>