diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 225b286b51..9cb2dabd02 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -949,7 +949,8 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
{
$topic_sql = array_merge($topic_sql, array(
'poll_title' => stripslashes($poll['poll_title']),
- 'poll_start' => ($poll['poll_start']) ? $poll['poll_start'] : $current_time,
+ 'poll_start' => ($poll['poll_start']) ? $poll['poll_start'] : $current_time,
+ 'poll_max_options' => $poll['poll_max_options'],
'poll_length' => $poll['poll_length'] * 3600)
);
}
@@ -1181,7 +1182,7 @@ function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_
}
// Mark this topic as read and posted to.
- $mark_mode = ($mode == 'reply' || $mode == 'quote') ? 'post' : 'topic';
+ $mark_mode = ($mode == 'post' || $mode == 'reply' || $mode == 'quote') ? 'post' : 'topic';
markread($mark_mode, $post_data['forum_id'], $post_data['topic_id'], $post_data['post_id']);
$db->sql_transaction('commit');
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index 729f712f84..24868b64be 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -652,7 +652,9 @@ class parse_message
$err_msg = '';
// Process poll options
- if (!empty($poll_data['poll_option_text']) && (($auth->acl_get('f_poll', $forum_id) && !$poll_data['poll_last_vote']) || $auth->acl_get('m_edit', $forum_id)))
+ if (!empty($poll_data['poll_option_text']) &&
+ (($auth->acl_get('f_poll', $forum_id) && !$poll_data['poll_last_vote']) ||
+ $auth->acl_get('m_edit', $forum_id)))
{
if (($result = $this->parse($poll_data['poll_option_text'], $poll_data['enable_html'], $poll_data['enable_bbcode'], $poll_data['bbcode_uid'], $poll_data['enable_urls'], $poll_data['enable_smilies'], false)) != '')
{
@@ -678,9 +680,11 @@ class parse_message
$poll['poll_title'] = (!empty($poll_data['poll_title'])) ? trim(htmlspecialchars(strip_tags($poll_data['poll_title']))) : '';
$poll['poll_length'] = (!empty($poll_data['poll_length'])) ? intval($poll_data['poll_length']) : 0;
}
- $poll['poll_start'] = $poll_data['poll_start'];
- return ($err_msg);
+ $poll['poll_start'] = $poll_data['poll_start'];
+ $poll['poll_max_options'] = ($poll_data['poll_max_options'] < 1) ? 1 : (($poll_data['poll_max_options'] > $config['max_poll_options']) ? $config['max_poll_options'] : $poll_data['poll_max_options']);
+
+ return $err_msg;
}
}
diff --git a/phpBB/posting.php b/phpBB/posting.php
index fed17c7e7b..a472cb3f55 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -79,7 +79,7 @@ $post_validate = false;
// Easier validation
$forum_fields = array('forum_name' => 's', 'parent_id' => 'i', 'forum_parents' => 's', 'forum_status' => 'i', 'forum_postable' => 'i', 'enable_icons' => 'i');
-$topic_fields = array('topic_status' => 'i', 'topic_first_post_id' => 'i', 'topic_last_post_id' => 'i', 'topic_type' => 'i', 'topic_title' => 's', 'poll_last_vote' => 'i', 'poll_start' => 'i', 'poll_title' => 's', 'poll_length' => 'i');
+$topic_fields = array('topic_status' => 'i', 'topic_first_post_id' => 'i', 'topic_last_post_id' => 'i', 'topic_type' => 'i', 'topic_title' => 's', 'poll_last_vote' => 'i', 'poll_start' => 'i', 'poll_title' => 's', 'poll_max_options' => 'i', 'poll_length' => 'i');
$post_fields = array('post_time' => 'i', 'poster_id' => 'i', 'post_username' => 's', 'post_text' => 's', 'post_subject' => 's', 'post_checksum' => 's', 'post_attachment' => 'i', 'bbcode_uid' => 's', 'enable_magic_url' => 'i', 'enable_sig' => 'i', 'enable_smilies' => 'i', 'enable_bbcode' => 'i', 'post_edit_locked' => 'i');
@@ -530,6 +530,7 @@ if (($submit) || ($preview) || ($refresh))
}
$message_parser->message = (!empty($_POST['message'])) ? trim(stripslashes($_POST['message'])) : '';
+
$username = (!empty($_POST['username'])) ? trim($_POST['username']) : '';
$topic_type = (!empty($_POST['topic_type'])) ? intval($_POST['topic_type']) : POST_NORMAL;
$icon_id = (!empty($_POST['icon'])) ? intval($_POST['icon']) : 0;
@@ -557,10 +558,11 @@ if (($submit) || ($preview) || ($refresh))
$db->sql_query($sql);
$topic_sql = array(
- 'poll_title' => '',
- 'poll_start' => 0,
- 'poll_length' => 0,
- 'poll_last_vote' => 0
+ 'poll_title' => '',
+ 'poll_start' => 0,
+ 'poll_length' => 0,
+ 'poll_last_vote' => 0,
+ 'poll_max_options' => 0
);
$sql = 'UPDATE ' . TOPICS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $topic_sql) . ' WHERE topic_id = ' . $topic_id;
@@ -569,12 +571,14 @@ if (($submit) || ($preview) || ($refresh))
$poll_title = '';
$poll_length = '';
$poll_option_text = '';
+ $poll_max_options = '';
}
else
{
$poll_title = (!empty($_POST['poll_title'])) ? trim($_POST['poll_title']) : '';
$poll_length = (!empty($_POST['poll_length'])) ? $_POST['poll_length'] : '';
$poll_option_text = (!empty($_POST['poll_option_text'])) ? $_POST['poll_option_text'] : '';
+ $poll_max_options = (!empty($_POST['poll_max_options'])) ? $_POST['poll_max_options'] : 1;
}
$err_msg = '';
@@ -714,6 +718,7 @@ if (($submit) || ($preview) || ($refresh))
$poll_data = array(
'poll_title' => $poll_title,
'poll_length' => $poll_length,
+ 'poll_max_options' => $poll_max_options,
'poll_option_text' => $poll_option_text,
'poll_start' => $poll_start,
'poll_last_vote' => $poll_last_vote,
@@ -1074,9 +1079,10 @@ if ( ( ($mode == 'post') || ( ($mode == 'edit') && ($post_id == $topic_first_pos
'L_POLL_OPTIONS_EXPLAIN'=> sprintf($user->lang['POLL_OPTIONS_EXPLAIN'], $config['max_poll_options']),
- 'POLL_TITLE' => $poll_title,
- 'POLL_OPTIONS' => (!empty($poll_options)) ? implode("\n", $poll_options) : '',
- 'POLL_LENGTH' => $poll_length)
+ 'POLL_TITLE' => $poll_title,
+ 'POLL_OPTIONS' => (!empty($poll_options)) ? implode("\n", $poll_options) : '',
+ 'POLL_MAX_OPTIONS' => (!empty($poll_max_options)) ? $poll_max_options : 1,
+ 'POLL_LENGTH' => $poll_length)
);
}
diff --git a/phpBB/templates/subSilver/posting_poll_body.html b/phpBB/templates/subSilver/posting_poll_body.html
index c0c8f8b315..a016a0162d 100644
--- a/phpBB/templates/subSilver/posting_poll_body.html
+++ b/phpBB/templates/subSilver/posting_poll_body.html
@@ -13,6 +13,10 @@
{L_POLL_OPTIONS} {L_POLL_OPTIONS_EXPLAIN} |
|
+
+ {L_POLL_MAX_OPTIONS} {L_POLL_MAX_OPTIONS_EXPLAIN} |
+ |
+
{L_POLL_FOR} |
{L_DAYS} {L_POLL_FOR_EXPLAIN} |
diff --git a/phpBB/templates/subSilver/viewtopic_body.html b/phpBB/templates/subSilver/viewtopic_body.html
index 1be6f029b2..6ba74bf43e 100644
--- a/phpBB/templates/subSilver/viewtopic_body.html
+++ b/phpBB/templates/subSilver/viewtopic_body.html
@@ -31,13 +31,13 @@
|
- {L_TOTAL_VOTES} : {TOTAL_VOTES} |
+ {L_TOTAL_VOTES} : {TOTAL_VOTES} |
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index c711d57b83..9d9068b72d 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -132,7 +132,7 @@ else
}
}
$extra_fields = (!$post_id) ? '' : ", COUNT(p2.post_id) AS prev_posts";
-$order_sql = (!$post_id) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_id, f.forum_style ORDER BY p.post_id ASC";
+$order_sql = (!$post_id) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.poll_max_options, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_id, f.forum_style ORDER BY p.post_id ASC";
if ($user->data['user_id'] != ANONYMOUS)
{
@@ -144,8 +144,8 @@ if ($user->data['user_id'] != ANONYMOUS)
default:
$extra_fields .= ', tw.notify_status';
- $join_sql_table .= ' LEFT JOIN ' . TOPICS_WATCH_TABLE . ' tw ON tw.user_id = ' . $user->data['user_id'] . '
- AND t.topic_id = tw.topic_id';
+ $join_sql_table .= ' LEFT JOIN ' . TOPICS_WATCH_TABLE . ' tw ON (tw.user_id = ' . $user->data['user_id'] . '
+ AND t.topic_id = tw.topic_id)';
}
}
@@ -160,7 +160,7 @@ if (!$forum_id)
{
$forum_id = 2;
}
-$sql = "SELECT t.topic_id, t.forum_id AS real_forum_id, t.topic_title, t.topic_attachment, t.topic_status, " . (($auth->acl_get('m_approve')) ? 't.topic_replies_real AS topic_replies' : 't.topic_replies') . ", t.topic_last_post_id, t.topic_time, t.topic_type, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_id, f.forum_style" . $extra_fields . "
+$sql = "SELECT t.topic_id, t.forum_id AS real_forum_id, t.topic_title, t.topic_attachment, t.topic_status, " . (($auth->acl_get('m_approve')) ? 't.topic_replies_real AS topic_replies' : 't.topic_replies') . ", t.topic_last_post_id, t.topic_time, t.topic_type, t.poll_max_options, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_id, f.forum_style" . $extra_fields . "
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
WHERE $join_sql
AND (f.forum_id = t.forum_id
@@ -453,10 +453,52 @@ if (!empty($poll_start))
AND vote_user_id = " . $user->data['user_id'];
$result = $db->sql_query($sql);
- $voted_id = ($row = $db->sql_fetchrow($result)) ? $row['poll_option_id'] : false;
+ $voted_id = array();
+ if ($row = $db->sql_fetchrow($result))
+ {
+ do
+ {
+ $voted_id[] = $row['poll_option_id'];
+ }
+ while ($row = $db->sql_fetchrow($result));
+ }
$db->sql_freeresult($result);
- $display_results = ($voted_id || ($poll_length != 0 && $poll_start + $poll_length < time()) || $_GET['vote'] == 'viewresult' || !$auth->acl_get('f_vote', 'a_', $forum_id) || $topic_status == ITEM_LOCKED || $forum_status == ITEM_LOCKED) ? true : false;
+ if (isset($_POST['castvote']))
+ {
+ if (sizeof($voted_id) == $poll_max_options && !$auth->acl_get('f_votechg', $forum_id))
+ {
+ trigger_error($user->lang['ALREADY_VOTED']);
+ }
+
+ $voted_id = array_map('intval', $_POST['vote_id']);
+
+ if (!sizeof($voted_id) || sizeof($voted_id) > $poll_max_options)
+ {
+ $message = (!sizeof($option_voted)) ? 'NO_VOTE_OPTION' : 'TOO_MANY_VOTE_OPTIONS';
+ trigger_error($user->lang[$message]);
+ }
+
+ foreach ($voted_id as $option)
+ {
+ $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . " (topic_id, poll_option_id, vote_user_id, vote_user_ip)
+ VALUES ($topic_id, $option, " . $user->data['user_id'] . ", '$user->ip')";
+ $db->sql_query($sql);
+
+ $sql = "UPDATE " . POLL_OPTIONS_TABLE . "
+ SET poll_option_total = poll_option_total + 1
+ WHERE poll_option_id = $option
+ AND topic_id = $topic_id";
+ $db->sql_query($sql);
+ }
+
+ $sql = "UPDATE " . TOPICS_TABLE . "
+ SET poll_last_vote = " . time() . "
+ WHERE topic_id = $topic_id";
+ $db->sql_query($sql);
+ }
+
+ $display_results = (sizeof($voted_id) || ($poll_length != 0 && $poll_start + $poll_length < time()) || $_GET['vote'] == 'viewresult' || !$auth->acl_get('f_vote', $forum_id) || $topic_status == ITEM_LOCKED || $forum_status == ITEM_LOCKED) ? true : false;
$poll_total = 0;
foreach ($poll_info as $poll_option)
@@ -475,25 +517,23 @@ if (!empty($poll_start))
'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'],
'POLL_OPTION_RESULT' => $poll_option['poll_option_total'],
'POLL_OPTION_PERCENT' => $vote_percent,
- 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * $user->theme['poll_length']), true))
+ 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * $user->theme['poll_length']), true),
+ 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $voted_id)) ? true : false)
);
}
- $poll_title = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $poll_title) : $poll_title;
-
$template->assign_vars(array(
- 'POLL_QUESTION' => $poll_title,
+ 'POLL_QUESTION' => (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $poll_title) : $poll_title,
'TOTAL_VOTES' => $poll_total,
'POLL_LEFT_CAP_IMG' => $user->img('poll_left'),
'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'),
- 'S_HAS_POLL_OPTIONS'=> !$display_results,
- 'S_HAS_POLL_DISPLAY'=> $display_results,
- 'S_POLL_ACTION' => "viewtopic.$phpEx$SID&t=$topic_id&sk=$sort_key&sd=$sort_dir",
+ 'L_MAX_VOTES' => ($poll_max_options == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $poll_max_options),
- 'L_SUBMIT_VOTE' => $user->lang['Submit_vote'],
- 'L_VIEW_RESULTS'=> $user->lang['View_results'],
- 'L_TOTAL_VOTES' => $user->lang['Total_votes'],
+ 'S_HAS_POLL_OPTIONS'=> !$display_results,
+ 'S_HAS_POLL_DISPLAY'=> $display_results,
+ 'S_IS_MULTI_CHOICE' => ($poll_max_options > 1) ? true : false,
+ 'S_POLL_ACTION' => "viewtopic.$phpEx$SID&t=$topic_id&sk=$sort_key&sd=$sort_dir",
'U_VIEW_RESULTS' => "viewtopic.$phpEx$SID&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir&vote=viewresult")
);
@@ -504,8 +544,7 @@ if (!empty($poll_start))
$user_cache = $attachments = $attach_list = $rowset = $update_count = array();
$has_attachments = FALSE;
$force_encoding = '';
-$bbcode_bitfield = 0;
-$i = 0;
+$bbcode_bitfield = $i = 0;
// Go ahead and pull all data for this topic
$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_karma, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, p.*
@@ -766,18 +805,27 @@ if (count($attach_list))
if (!$db->sql_fetchrow($result))
{
- $db->sql_query("UPDATE " . TOPICS_TABLE . " SET topic_attachment = 0 WHERE topic_id = $topic_id");
+ $sql = 'UPDATE ' . TOPICS_TABLE . "
+ SET topic_attachment = 0
+ WHERE topic_id = $topic_id";
+ $db->sql_query($sql);
}
}
else
{
- $db->sql_query("UPDATE " . TOPICS_TABLE . " SET topic_attachment = 0 WHERE topic_id = $topic_id");
+ $sql = 'UPDATE ' . TOPICS_TABLE . "
+ SET topic_attachment = 0
+ WHERE topic_id = $topic_id";
+ $db->sql_query($sql);
}
}
elseif ($has_attachments && !$topic_data['topic_attachment'])
{
// Topic has approved attachments but its flag is wrong
- $db->sql_query("UPDATE " . TOPICS_TABLE . " SET topic_attachment = 1 WHERE topic_id = $topic_id");
+ $sql = 'UPDATE ' . TOPICS_TABLE . "
+ SET topic_attachment = 1
+ WHERE topic_id = $topic_id";
+ $db->sql_query($sql);
}
}
@@ -962,8 +1010,8 @@ foreach ($rowset as $key => $row)
'POSTER_POSTS' => $user_cache[$poster_id]['posts'],
'POSTER_FROM' => $user_cache[$poster_id]['from'],
'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'],
- 'POST_DATE' => $user->format_date($row['post_time']),
+ 'POST_DATE' => $user->format_date($row['post_time']),
'POST_SUBJECT' => $row['post_subject'],
'MESSAGE' => $message,
'SIGNATURE' => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '',
@@ -1001,20 +1049,18 @@ foreach ($rowset as $key => $row)
'YIM_IMG' => $user_cache[$poster_id]['yim_img'],
'YIM' => $user_cache[$poster_id]['yim'],
- 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_', $forum_id)) ? TRUE : FALSE,
- 'U_REPORT' => "report.$phpEx$SID&p=" . $row['post_id'],
- 'U_MCP_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? "mcp.$phpEx$SID&mode=post_details&p=" . $row['post_id'] : '',
-
'POST_ICON' => (!empty($row['icon_id'])) ? '
' : '',
'L_MINI_POST_ALT' => $mini_post_alt,
- 'S_ROW_COUNT' => $i++,
-
+ 'S_ROW_COUNT' => $i++,
'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? TRUE : FALSE,
'S_POST_UNAPPROVED' => ($row['post_approved']) ? FALSE : TRUE,
- 'U_MCP_APPROVE' => "mcp.$phpEx$SID&mode=approve&p=" . $row['post_id'],
+ 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_', $forum_id)) ? TRUE : FALSE,
+ 'U_REPORT' => "report.$phpEx$SID&p=" . $row['post_id'],
+ 'U_MCP_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? "mcp.$phpEx$SID&mode=post_details&p=" . $row['post_id'] : '',
+ 'U_MCP_APPROVE' => "mcp.$phpEx$SID&mode=approve&p=" . $row['post_id'],
'U_MINI_POST' => $mini_post_url,
'U_POST_ID' => $u_post_id)
);