<?
###############################################################################
# Copyright (C) 2000 Derek Leung
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# You may modify your copy or copies of this Program or any portion of it,
# but you must cause the modified files to carry prominent notices stating
# that you changed the files and the date of any change. And you are required
# to keep a copy of this License along with this Program.
#
# You are not required to accept this License, since you have not signed it.
# However, nothing else grants you permission to modify or distribute this
# Program or its derivative works. These actions are prohibited by law if
# you do not accept this License. Therefore, by modifying or distributing
# this Program (or any work based on this Program), you indicate your
# acceptance of this License to do so, and all its terms and conditions
# for copying, distributing or modifying this Program or works based on it.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# See the GNU General Public License for more details.
# http://www.opensource.org/licenses/gpl-license.html
###############################################################################
global $config;
// kick out anyone try to access this file directly
if (eregi("admin/", $PHP_SELF)) {
die ("Access Deny!");
}
/*********************************************************/
/* poll functions */
/*********************************************************/
function poll_createPoll($pollTitle, $topic, $optionText) {
// function to create a poll
global $config;
// we have right to do this?
$rightArray = getAdminRights();
if (!in_array("7",$rightArray)) {
errorPage("Access Deny!",$config[def_theme]);
}
if ($pollTitle !="" || $topic != "" || $optionText !="") {
$timeStamp = time();
$pollTitle = check_html(FixQuotes($pollTitle));
$pollTitle = check_words($pollTitle);
if(!mysql_query("INSERT INTO ps_poll_desc VALUES (NULL, '$pollTitle', '$timeStamp', 0, '$topic')")) {
echo mysql_errno(). ": ".mysql_error(). "<br>";
return;
}
$object = mysql_fetch_object(mysql_query("SELECT pollID FROM ps_poll_desc WHERE pollTitle='$pollTitle'"));
$id = $object->pollID;
for($i = 1; $i <= sizeof($optionText); $i++) {
if($optionText[$i] != "") {
$optionText[$i] = FixQuotes($optionText[$i]);
if(!mysql_query("INSERT INTO ps_poll_data (pollID, optionText, optionCount, voteID) VALUES ($id, '$optionText[$i]', 0, $i)")) {
echo mysql_errno(). ": ".mysql_error(). "<br>";
return;
}
}
}
$mesg = translate("Poll+is+created!");
header("Location: admin.php?mesg=$mesg");
} else {
ps_header("");
$topics = getTopicRights2();
?>
<h3><?php echo translate("Create new poll"); ?></h3>
<form action="admin.php" method="post">
<input type="hidden" name="op" value="createPoll">
<p><b><?php echo translate("Polltitle"); ?>:</b> <input type=text name="pollTitle" size=50 maxlength=100></p>
<p><b><?php echo translate("Topics"); ?>:</b>
<select name=topic>
<? foreach ($topics as $topic) {
echo "<option value=\"$topic\">$topic<br>";
}
echo "</select>";
echo "<br><br>";
echo "<table>";
for($i = 1; $i <= $config[maxOptions]; $i++) {
echo "<tr>";
echo "<td><b>".translate("Option")." $i:</b></td><td><input type=text name=\"optionText[$i]\" size=50 maxlength=150></td>";
echo "</tr>";
}
echo "</tr>";
echo "</table>";
echo "<input type=\"submit\" value=\"".translate("Create")."\">";
echo "</form>";
ps_footer("");
}
}
function poll_removePoll($pollID) {
// remove a poll
global $config;
// we have right to do this?
$rightArray = getAdminRights();
if (!in_array("7",$rightArray)) {
errorPage("Access Deny!",$config[def_theme]);
}
if ($pollID=="") {
ps_header("");
?>
<h3><?php echo translate("Remove an existing poll"); ?></h3>
<h3><?php echo translate("WARNING: The chosen poll will be removed IMMEDIATELY from the database!"); ?></h3>
<p><?php echo translate("Please choose a poll from the list below."); ?></p>
<form action="admin.php" method="post">
<input type="hidden" name="op" value="removePoll">
<table>
<?
$result = mysql_query("SELECT pollID, pollTitle, timeStamp ,topic FROM ps_poll_desc ORDER BY topic,timeStamp");
if(!$result) {
echo mysql_errno(). ": ".mysql_error(). "<br>";
return;
}
// cycle through the descriptions until everyone has been fetched
$topics = getTopicRights();
while($object = mysql_fetch_object($result)) {
if (in_array($object->topic,$topics)) {
echo "<tr><td><input type=\"radio\" name=\"pollID\" value=\"".$object->pollID."\">".$object->pollTitle."</td><td>[$object->topic]</td></tr>";
}
}
echo "</table>";
echo "<input type=\"submit\" value=\"".translate("Remove")."\">";
echo "</form>";
ps_footer("");
} else {
mysql_query("DELETE FROM ps_poll_desc WHERE pollID=$pollID");
mysql_query("DELETE FROM ps_poll_data WHERE pollID=$pollID");
$mesg = translate("Poll+is+deleted!");
Header("Location: admin.php?mesg=$mesg");
}
}
function poll_viewPoll($pollID, $topic) {
// view a poll
global $config;
// we have right to do this?
$rightArray = getAdminRights();
if (!in_array("7",$rightArray)) {
errorPage("Access Deny!",$config[def_theme]);
}
if ($pollID =="" || $topic == "") {
ps_header("");
echo "<h3>".translate("View poll results")."</h3>";
echo "<p>";
// select all descriptions
$result = mysql_query("SELECT pollID, pollTitle, timeStamp, topic FROM ps_poll_desc ORDER BY topic,timeStamp");
if(!$result) {
echo mysql_errno(). ": ".mysql_error(). "<br>";
ps_footer("");
return;
}
echo "<form action=\"".basename($GLOBALS[PHP_SELF])."\" method=\"post\">";
echo "<input type=\"hidden\" name=\"op\" value=\"viewPoll\">";
echo "<table>";
// cycle through the descriptions until everyone has been fetched
while($object = mysql_fetch_object($result)) {
echo "<tr><td><input type=\"radio\" name=\"pollID\" value=\"".$object->pollID."\"><b>".$object->pollTitle." </b></td><td>[$object->topic]</td></tr>";
echo "<input type=hidden name=\"topic[$object->pollID]\" value=\"$object->topic\">";
}
echo "</table>";
echo "<input type=\"submit\" value=\"".translate("View")."\">";
echo "</form>";
ps_footer("");
} else {
header("Location: pollBooth.php?op=results&pollID=$pollID&myTopic=$topic[$pollID]");
}
}
?>