aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_posting.php
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2007-04-02 16:05:48 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2007-04-02 16:05:48 +0000
commit9fcbcb626562eca16e2f2be1303f4a6cad8345a2 (patch)
treef291e03cfc5d95bdadb06b8fbf6c37131bb4ece0 /phpBB/includes/functions_posting.php
parent1d1b5e6446667cc03cb765c789e269b4efa7e3a8 (diff)
downloadforums-9fcbcb626562eca16e2f2be1303f4a6cad8345a2.tar
forums-9fcbcb626562eca16e2f2be1303f4a6cad8345a2.tar.gz
forums-9fcbcb626562eca16e2f2be1303f4a6cad8345a2.tar.bz2
forums-9fcbcb626562eca16e2f2be1303f4a6cad8345a2.tar.xz
forums-9fcbcb626562eca16e2f2be1303f4a6cad8345a2.zip
#5163
git-svn-id: file:///svn/phpbb/trunk@7267 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_posting.php')
-rw-r--r--phpBB/includes/functions_posting.php19
1 files changed, 14 insertions, 5 deletions
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index b7ac1b3ac3..9e4a5c0843 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -1731,7 +1731,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
if ($poll['poll_start'] && $mode == 'edit')
{
- $sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . '
+ $sql = 'SELECT *
+ FROM ' . POLL_OPTIONS_TABLE . '
WHERE topic_id = ' . $data['topic_id'] . '
ORDER BY poll_option_id';
$result = $db->sql_query($sql);
@@ -1751,18 +1752,19 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
{
if (empty($cur_poll_options[$i]))
{
+ // If we add options we need to put them to the end to be able to preserve votes...
$sql_insert_ary[] = array(
- 'poll_option_id' => (int) $i,
+ 'poll_option_id' => (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary),
'topic_id' => (int) $data['topic_id'],
'poll_option_text' => (string) $poll['poll_options'][$i]
);
}
else if ($poll['poll_options'][$i] != $cur_poll_options[$i])
{
- $sql = "UPDATE " . POLL_OPTIONS_TABLE . "
+ $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . "
SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "'
- WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . "
- AND topic_id = " . $data['topic_id'];
+ WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . '
+ AND topic_id = ' . $data['topic_id'];
$db->sql_query($sql);
}
}
@@ -1777,6 +1779,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
AND topic_id = ' . $data['topic_id'];
$db->sql_query($sql);
}
+
+ // If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option
+ if ($mode == 'edit' && sizeof($poll['poll_options']) != sizeof($cur_poll_options))
+ {
+ $db->sql_query('DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data['topic_id']);
+ $db->sql_query('UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data['topic_id']);
+ }
}
// Submit Attachments