Location: PHPKode > projects > DoubleSpeak > igloo-0.1/html/admin/add_poll.php
<?

/*
 | This file is part of the Igloo Weblog system.
 | Igloo is available under the GNU General Public
 | License.  For details on the GNU General Public
 | License, read the COPYING or the LICENSE file
 | that you received with this distribution.  If
 | you did not receive one of these files with the
 | distribution, you can find more information at
 | http://www.gnu.org.
 |
 | Igloo is the creation of Brad Johnson.  It is not
 | based on any other works.  Brad Johnson is the
 | sole owner of the copyright, but he welcomes all
 | to take the software, use it, modify it, change
 | it, or to do whatever they can do with it under
 | the provisions of the GNU General Public License.
 |
 | This software is provided as-is, with no warranty
 | whatsoever.  The author is not responsible for
 | anything that may happen as a result of your
 | using this software unless you have purchased an
 | extended warranty.  If you would like to
 | purchase an extended warranty, please contact
 | Brad Johnson via e-mail at hide@address.com
 |
 | This software may destroy your system, date your
 | sister, drink your beer, eat the last of the
 | potato chips, cause Democrats to get elected,
 | kick your dog, burn your house, wreck your car,
 | cause nuclear war, force you to kiss your
 | grandmother, or make you eat brussel sprouts.
 | You have been warned.
 |
 | If it breaks, you may feel free to keep both
 | pieces.
 */

  require "../config.inc";
  require "$config[private]/local.inc";

  common_header();

  if ($preview) {

    print "                <tr>\n";
    print "                  <th colspan=\"2\">\n";
    print "                    This is what your poll will look like in it's own little box!\n";
    print "                  </th>\n";
    print "                </tr>\n";
    print "                <tr>\n";
    print "                  <td width=\"30%\">\n";
    print "                     <table width=\"100%\" border=\"1\">\n";
    print "                     <tr>\n";
    print "                       <th class=\"c\">\n";
    print "                         Previewing Your Poll\n";
    print "                       </th>\n";
    print "                     </tr>\n";
    print "                     <form action=\"/dev/null\" method=\"post\">\n";
    print "                     <tr>\n";
    print "                       <td>\n";
    print "                         <font size=\"2\">\n";
    print "                           <b>$poll_title</b><br>\n";
    if ($choice_one) {
      print "                           <input type=\"radio\" value=\"1\" name=\"poll_option\">$choice_one<br>\n";
    }
    if ($choice_two) {
      print "                           <input type=\"radio\" value=\"2\" name=\"poll_option\">$choice_two<br>\n";
    }
    if ($choice_three) {
      print "                           <input type=\"radio\" value=\"3\" name=\"poll_option\">$choice_three<br>\n";
    }
    if ($choice_four) {
      print "                           <input type=\"radio\" value=\"4\" name=\"poll_option\">$choice_four<br>\n";
    }
    if ($choice_five) {
      print "                           <input type=\"radio\" value=\"5\" name=\"poll_option\">$choice_five<br>\n";
    }
    print "                        </font>\n";
    print "                      </td>\n";
    print "                    </tr>\n";
    print "                    </form>\n";
    print "                    </table>\n";
    print "                  </td>\n";
    print "                  <td>\n";
    print "                    &nbsp;\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                <tr>\n";
    print "                  <td>\n";
    print "                    Review the poll for mistakes, and if you see any, click the \"Back\" button on your\n";
    print "                    browser so you can change them.  When you are satisfied, click the button that says\n";
    print "                    \"Publish Poll\"\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                <form action=\"/admin/add_poll.php\" method=\"post\">\n";
    print "                <input type=\"hidden\" name=\"poll_title\" value=\"$poll_title\">\n";
    if ($choice_one) {
      print "                <input type=\"hidden\" name=\"choice_one\" value=\"$choice_one\">\n";
    }
    if ($choice_two) {
      print "                <input type=\"hidden\" name=\"choice_two\" value=\"$choice_two\">\n";
    }
    if ($choice_three) {
      print "                <input type=\"hidden\" name=\"choice_three\" value=\"$choice_three\">\n";
    }
    if ($choice_four) {
      print "                <input type=\"hidden\" name=\"choice_four\" value=\"$choice_four\">\n";
    }
    if ($choice_five) {
      print "                <input type=\"hidden\" name=\"choice_five\" value=\"$choice_five\">\n";
    }
    print "                <tr>\n";
    print "                  <td>\n";
    print "                    <input type=\"submit\" name=\"submit\" value=\"Publish Poll\">\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                </form>\n";

  } elseif ($submit) {

    $Results = do_mysql_query("SELECT * FROM polls WHERE poll_title='$poll_title'")
      or die("I could not SELECT FROM the database\n");
    $Row = mysql_fetch_array($Results);
    if ($Row) {
      mysql_free_result($Results);
      print "                <tr>\n";
      print "                  <th>\n";
      print "                    Error in creating poll!\n";
      print "                  </th>\n";
      print "                </tr>\n";
      print "                <tr>\n";
      print "                  <td>\n";
      print "                    A poll with the title that you have chosen, \"$poll_title\" has already been\n";
      print "                    created.  Please modify your poll to have a different title\n";
      print "                  </td>\n";
      print "                </tr>\n";
    } else {
      $Results = do_mysql_query("INSERT INTO polls (poll_title) VALUES ('$poll_title')")
        or die("I could not INSERT INTO the database\n");
      $Results = do_mysql_query("SELECT id FROM polls WHERE poll_title='$poll_title'")
        or die("I could not SELECT FROM the database\n");
      $Row = mysql_fetch_array($Results);
      mysql_free_result($Results);
      $pid = $Row[id];
      $number_of_choices = 0;
      if ($choice_one) {
        $Results = do_mysql_query("INSERT INTO poll_choices (pid, choice_number, choice) VALUES ('$pid', 1, '$choice_one')")
          or die("I could not INSERT INTO the database\n");
        $number_of_choices++;
      }
      if ($choice_two) {
        $Results = do_mysql_query("INSERT INTO poll_choices (pid, choice_number, choice) VALUES ('$pid', 2, '$choice_two')")
          or die("I could not INSERT INTO the database\n");
        $number_of_choices++;
      }
      if ($choice_three) {
        $Results = do_mysql_query("INSERT INTO poll_choices (pid, choice_number, choice) VALUES ('$pid', 3, '$choice_three')")
          or die("I could not INSERT INTO the database\n");
        $number_of_choices++;
      }
      if ($choice_four) {
        $Results = do_mysql_query("INSERT INTO poll_choices (pid, choice_number, choice) VALUES ('$pid', 4, '$choice_four')")
          or die("I could not INSERT INTO the database\n");
        $number_of_choices++;
      }
      if ($choice_five) {
        $Results = do_mysql_query("INSERT INTO poll_choices (pid, choice_number, choice) VALUES ('$pid', 5, '$choice_five')")
          or die("I could not INSERT INTO the database\n");
        $number_of_choices++;
      }

      $Results = do_mysql_query("UPDATE polls SET number_choices='$number_of_choices' WHERE id='$pid'")
        or die("I could not UPDATE the database\n");

      print "                <tr>\n";
      print "                  <th>\n";
      print "                    Poll Creation Successful!\n";
      print "                  </th>\n";
      print "                </tr>\n";
      print "                <tr>\n";
      print "                  <td>\n";
      print "                    Your poll has been successfully created.\n";
      print "                  </td>\n";
      print "                </tr>\n";

    }

  } else {

    print "                <tr>\n";
    print "                  <th colspan=\"2\">\n";
    print "                    Adding a poll\n";
    print "                  </th>\n";
    print "                </tr>\n";
    print "                <tr>\n";
    print "                  <td colspan=\"2\">\n";
    print "                    You can use this handy-dandy form to add a poll to the site.\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                <form action=\"/admin/add_poll.php\">\n";
    print "                <tr>\n";
    print "                  <td>\n";
    print "                    Poll Title:\n";
    print "                  </td>\n";
    print "					 <td>\n";
    print "                    <input type=\"text\" name=\"poll_title\">\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                <tr>\n";
    print "                  <td>\n";
    print "                    Choice One:\n";
    print "                  </td>\n";
    print "                  <td>\n";
    print "                    <input type=\"text\" name=\"choice_one\">\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                <tr>\n";
    print "                  <td>\n";
    print "                    Choice Two:\n";
    print "                  </td>\n";
    print "                  <td>\n";
    print "                    <input type=\"text\" name=\"choice_two\">\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                <tr>\n";
    print "                  <td>\n";
    print "                    Choice Three:\n";
    print "                  </td>\n";
    print "                  <td>\n";
    print "                    <input type=\"text\" name=\"choice_three\">\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                <tr>\n";
    print "                  <td>\n";
    print "                    Choice Four:\n";
    print "                  </td>\n";
    print "                  <td>\n";
    print "                    <input type=\"text\" name=\"choice_four\">\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                <tr>\n";
    print "                  <td>\n";
    print "                    Choice Five:\n";
    print "                  </td>\n";
    print "                  <td>\n";
    print "                    <input type=\"text\" name=\"choice_five\">\n";
    print "                  </td>\n";
    print "                </tr>\n";
    print "                <tr>\n";
    print "                  <td>\n";
    print "                    &nbsp;\n";
    print "                  </td>\n";
    print "                  <td>\n";
    print "                    <input type=\"submit\" name=\"preview\" value=\"Preview Poll\">\n";
    print "                  </td>\n";
    print "                </tr>\n";

  }

  common_footer();

?>
Return current item: DoubleSpeak