git-svn-id: file:///svn/phpbb/trunk@7267 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2007-04-02 16:05:48 +00:00
parent 1d1b5e6446
commit 9fcbcb6265
2 changed files with 16 additions and 6 deletions

View file

@ -1731,7 +1731,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
if ($poll['poll_start'] && $mode == 'edit') if ($poll['poll_start'] && $mode == 'edit')
{ {
$sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . ' $sql = 'SELECT *
FROM ' . POLL_OPTIONS_TABLE . '
WHERE topic_id = ' . $data['topic_id'] . ' WHERE topic_id = ' . $data['topic_id'] . '
ORDER BY poll_option_id'; ORDER BY poll_option_id';
$result = $db->sql_query($sql); $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 (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( $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'], 'topic_id' => (int) $data['topic_id'],
'poll_option_text' => (string) $poll['poll_options'][$i] 'poll_option_text' => (string) $poll['poll_options'][$i]
); );
} }
else if ($poll['poll_options'][$i] != $cur_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]) . "' SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "'
WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . " WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . '
AND topic_id = " . $data['topic_id']; AND topic_id = ' . $data['topic_id'];
$db->sql_query($sql); $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']; AND topic_id = ' . $data['topic_id'];
$db->sql_query($sql); $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 // Submit Attachments

View file

@ -770,10 +770,11 @@ if ($submit || $preview || $refresh)
$post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : ''; $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
$post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : ''; $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)) if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
{ {
$message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS']; $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
} }*/
} }
else else
{ {