1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-18 14:48:28 +01:00

Re-enabled polling ... includes option of multiple choice polling, indication of option voted for, etc. ... preliminary implementation, various things need finishing

git-svn-id: file:///svn/phpbb/trunk@3920 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-04-22 16:47:34 +00:00
parent 9cb38cc0f9
commit 899f7bc1d7
6 changed files with 111 additions and 47 deletions

View File

@ -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');

View File

@ -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;
}
}

View File

@ -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)
);
}

View File

@ -13,6 +13,10 @@
<td class="row1"><b class="gen">{L_POLL_OPTIONS}</b><br /><span class="gensmall">{L_POLL_OPTIONS_EXPLAIN}</span></td>
<td class="row2"><textarea style="width:450px" name="poll_option_text" rows="5" cols="35">{POLL_OPTIONS}</textarea></td>
</tr>
<tr>
<td class="row1"><b class="gen">{L_POLL_MAX_OPTIONS}</b><br /><span class="gensmall">{L_POLL_MAX_OPTIONS_EXPLAIN}</span></td>
<td class="row2"><input class="post" type="text" name="poll_max_options" size="3" maxlength="3" value="{POLL_MAX_OPTIONS}" /></td>
</tr>
<tr>
<td class="row1"><b class="gen">{L_POLL_FOR}</b></td>
<td class="row2"><input class="post" type="text" name="poll_length" size="3" maxlength="3" value="{POLL_LENGTH}" />&nbsp;<b class="gen">{L_DAYS}</b> <span class="gensmall">{L_POLL_FOR_EXPLAIN}</span></td>

View File

@ -31,13 +31,13 @@
<tr>
<td class="row2" colspan="2"><br clear="all" /><form method="post" action="{S_POLL_ACTION}"><table cellspacing="0" cellpadding="4" border="0" align="center">
<tr>
<td align="center"><span class="gen"><b>{POLL_QUESTION}</b></span></td>
<td align="center"><span class="gen"><b>{POLL_QUESTION}</b></span><br /><span class="gensmall">{L_MAX_VOTES}</span></td>
</tr>
<tr>
<td align="center"><table cellspacing="0" cellpadding="2" border="0">
<!-- BEGIN poll_option -->
<tr>
<td><input type="radio" name="vote_id" value="{poll_option.POLL_OPTION_ID}" />&nbsp;</td>
<td><!-- IF S_IS_MULTI_CHOICE --><input type="checkbox" name="vote_id[]" value="{poll_option.POLL_OPTION_ID}" /><!-- ELSE --><input type="radio" name="vote_id[]" value="{poll_option.POLL_OPTION_ID}" /><!-- ENDIF -->&nbsp;</td>
<td><span class="gen">{poll_option.POLL_OPTION_CAPTION}</span></td>
</tr>
<!-- END poll_option -->
@ -69,14 +69,17 @@
<td>{POLL_RIGHT_CAP_IMG}</td>
</tr>
</table></td>
<td align="center"><b><span class="gen">&nbsp;{poll_option.POLL_OPTION_PERCENT}&nbsp;</span></b></td>
<td align="center"><span class="gen">[ {poll_option.POLL_OPTION_RESULT} ]</span></td>
<td class="gen" align="center"><b>&nbsp;{poll_option.POLL_OPTION_PERCENT}&nbsp;</b></td>
<td class="gen" align="center">[ {poll_option.POLL_OPTION_RESULT} ]</td>
<!-- IF poll_option.POLL_OPTION_VOTED -->
<td class="gensmall" valign="top"><b title="{L_POLL_VOTED_OPTION}">x</b></td>
<!-- ENDIF -->
</tr>
<!-- END poll_option -->
</table></td>
</tr>
<tr>
<td colspan="4" align="center"><span class="gen"><b>{L_TOTAL_VOTES} : {TOTAL_VOTES}</b></span></td>
<td class="gensmall" colspan="4" align="center"><b>{L_TOTAL_VOTES} : {TOTAL_VOTES}</b></td>
</tr>
</table><br clear="all" /></td>
</tr>

View File

@ -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&amp;t=$topic_id&amp;sk=$sort_key&amp;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&amp;t=$topic_id&amp;sk=$sort_key&amp;sd=$sort_dir",
'U_VIEW_RESULTS' => "viewtopic.$phpEx$SID&amp;t=$topic_id&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir&amp;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&amp;p=" . $row['post_id'],
'U_MCP_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? "mcp.$phpEx$SID&amp;mode=post_details&amp;p=" . $row['post_id'] : '',
'POST_ICON' => (!empty($row['icon_id'])) ? '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />' : '',
'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&amp;mode=approve&amp;p=" . $row['post_id'],
'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_', $forum_id)) ? TRUE : FALSE,
'U_REPORT' => "report.$phpEx$SID&amp;p=" . $row['post_id'],
'U_MCP_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? "mcp.$phpEx$SID&amp;mode=post_details&amp;p=" . $row['post_id'] : '',
'U_MCP_APPROVE' => "mcp.$phpEx$SID&amp;mode=approve&amp;p=" . $row['post_id'],
'U_MINI_POST' => $mini_post_url,
'U_POST_ID' => $u_post_id)
);