aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/functions_posting.php19
-rw-r--r--phpBB/posting.php3
2 files changed, 16 insertions, 6 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
diff --git a/phpBB/posting.php b/phpBB/posting.php
index a03e4af4c6..eac41e993b 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -770,10 +770,11 @@ if ($submit || $preview || $refresh)
$post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
$post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
+ /* We reset votes, therefore also allow removing options
if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
{
$message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
- }
+ }*/
}
else
{