Code: Alles auswählen
// Set the vote graphic length to 100
// Note: If the bars look too long at %100, (only 1 vote) set this value lower.
// Likewise, if it looks too short to you, increase it here.
$length = 100;
// Get the poll forum from EZportal config above
$poll_forum = $CFG['poll_forum'];
$sql = 'SELECT
t.*, vd.*
FROM
' . TOPICS_TABLE . ' AS t,
' . VOTE_DESC_TABLE . ' AS vd
WHERE
t.forum_id = ' . $poll_forum . ' AND
t.topic_status <> 1 AND
t.topic_status <> 2 AND
t.topic_vote = 1 AND
t.topic_id = vd.topic_id
ORDER BY
t.topic_time DESC
LIMIT
0,1';
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Couldn't obtain poll information.", "", __LINE__, __FILE__, $sql);
}
if(!$total_posts = $db->sql_numrows($result))
{
message_die(GENERAL_MESSAGE, $lang['No_posts_topic']);
}
$pollrow = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$topic_id = $pollrow[0]['topic_id'] ;
$sql = "SELECT pt.bbcode_uid FROM " . TOPICS_TABLE . " t, " . POSTS_TEXT_TABLE . " pt
WHERE t.topic_id = $topic_id
AND t.topic_first_post_id = pt.post_id
LIMIT 1";
if (!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Could not read bbcode for poll_options', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$bbcode_uid = $row['bbcode_uid'];
$db->sql_freeresult($result);
$sql = "SELECT vd.vote_id, vd.vote_text, vd.vote_start, vd.vote_length, vd.vote_max, vd.vote_voted, vd.vote_hide, vd.vote_tothide, vr.vote_option_id, vr.vote_option_text, vr.vote_result
FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
WHERE vd.topic_id = $topic_id
AND vr.vote_id = vd.vote_id
ORDER BY vr.vote_option_id ASC";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain vote data for this topic", "", __LINE__, __FILE__, $sql);
}
if( $vote_options = $db->sql_numrows($result) )
{
$vote_info = $db->sql_fetchrowset($result);
$poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;
if ( $poll_expired == 0 )
{
$vote_id = $vote_info[0]['vote_id'];
$vote_title = $vote_info[0]['vote_text'];
$max_vote = $vote_info[0]['vote_max'];
$voted_vote = $vote_info[0]['vote_voted'];
$hide_vote = $vote_info[0]['vote_hide'];
$tothide_vote = $vote_info[0]['vote_tothide'];
$sql = "SELECT vote_id
FROM " . VOTE_USERS_TABLE . "
WHERE vote_id = $vote_id
AND vote_user_id = " . $userdata['user_id'];
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain user vote data for this topic", "", __LINE__, __FILE__, $sql);
}
$user_voted = ( $db->sql_numrows($result) ) ? TRUE : 0;
if( isset($HTTP_GET_VARS['vote']) || isset($HTTP_POST_VARS['vote']) )
{
$view_result = ( ( ( isset($HTTP_GET_VARS['vote']) ) ? $HTTP_GET_VARS['vote'] : $HTTP_POST_VARS['vote'] ) == "viewresult" ) ? TRUE : 0;
}
else
{
$view_result = 0;
}
$poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;
if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
{
$template->set_filenames(array(
"pollbox" => "portal_poll_result.tpl")
);
$vote_results_sum = 0;
for($i = 0; $i < $vote_options; $i++)
{
$vote_results_sum += $vote_info[$i]['vote_result'];
}
$vote_graphic = 0;
$vote_graphic_max = count($images['voting_graphic']);
for($i = 0; $i < $vote_options; $i++)
{
$vote_percent = ( $vote_results_sum > 0 ) ? $vote_info[$i]['vote_result'] / $vote_results_sum : 0;
$vote_graphic_length = round($vote_percent * $board_config['vote_graphic_length']);
$vote_graphic_img = $images['voting_graphic'][$vote_graphic];
$vote_graphic = ($vote_graphic < $vote_graphic_max - 1) ? $vote_graphic + 1 : 0;
if ( count($orig_word) && ($forum_topic_data['disable_word_censor'] == 0) )
{
$vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
}
$hide_vote_bl = '';
$hide_vote_zr = '0';
$total_votes_1 = $lang['Total_votes'] ;
$total_votes_2 = $vote_results_sum ;
if ( ( $poll_expired == 0 ) && ( $hide_vote == 1 ) && ( $vote_info[0]['vote_length'] <> 0 ) )
{
if ( $tothide_vote == 1 )
{
$total_votes_1 = '' ;
$total_votes_2 = '' ;
}
$poll_expires_c = $lang['Results_after'];
$template->assign_block_vars("poll_option", array(
'POLL_OPTION_CAPTION' => $vote_info[$i]['vote_option_text'],
'POLL_OPTION_RESULT' => $hide_vote_bl,
'POLL_OPTION_PERCENT' => $hide_vote_bl,
'POLL_OPTION_IMG' => $vote_graphic_img,
'POLL_OPTION_IMG_WIDTH' => $hide_vote_zr)
);
}
else
{
$poll_expires_c = '';
$vote_caption_text = $vote_info[$i]['vote_option_text'];
$vote_caption_text = (!$board_config['allow_html']) ? preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $vote_caption_text) : $vote_caption_text;
$vote_caption_text = ($board_config['allow_bbcode'] && $bbcode_uid != '') ? bbencode_second_pass($vote_caption_text, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $vote_caption_text);
$vote_caption_text = make_clickable($vote_caption_text);
$vote_caption_text = ($board_config['allow_smilies']) ? smilies_pass($vote_caption_text) : $vote_caption_text;
$template->assign_block_vars("poll_option", array(
'POLL_OPTION_CAPTION' => $vote_caption_text,
'POLL_OPTION_RESULT' => $vote_info[$i]['vote_result'],
'POLL_OPTION_PERCENT' => sprintf("%.1d%%", ($vote_percent * 100)),
'POLL_OPTION_IMG' => $vote_graphic_img,
'POLL_OPTION_IMG_WIDTH' => $vote_graphic_length)
);
}
}
$template->assign_vars(array(
'L_TOTAL_VOTES' => $total_votes_1,
"TOTAL_VOTES" => $total_votes_2,
"L_VIEW_RESULTS" => $lang['View_results'],
"U_VIEW_RESULTS" => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order&vote=viewresult"))
);
}
else
{
$template->set_filenames(array(
"pollbox" => "portal_poll_ballot.tpl")
);
for($i = 0; $i < $vote_options; $i++)
{
if( count($orig_word) )
{
$vote_info[$i]['vote_option_text'] = preg_replace($orig_word, $replacement_word, $vote_info[$i]['vote_option_text']);
}
$vote_caption_text = $vote_info[$i]['vote_option_text'];
$vote_caption_text = (!$board_config['allow_html']) ? preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $vote_caption_text) : $vote_caption_text;
$vote_caption_text = ($board_config['allow_bbcode'] && $bbcode_uid != '') ? bbencode_second_pass($vote_caption_text, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $vote_caption_text);
$vote_caption_text = make_clickable($vote_caption_text);
$vote_caption_text = ($board_config['allow_smilies']) ? smilies_pass($vote_caption_text) : $vote_caption_text;
$template->assign_block_vars("poll_option", array(
"POLL_OPTION_ID" => $vote_info[$i]['vote_option_id'],
"POLL_OPTION_CAPTION" => $vote_caption_text)
);
}
$template->assign_vars(array(
"LOGIN_TO_VOTE" => '<b><a href="' . append_sid("login.$phpEx?redirect=portal.$phpEx") . '">' . $lang['Login_to_vote'] . '</a><b>')
);
$s_hidden_fields = '<input type="hidden" name="topic_id" value="' . $topic_id . '"><input type="hidden" name="mode" value="vote">';
}
if( count($orig_word) )
{
$vote_title = preg_replace($orig_word, $replacement_word, $vote_title);
}
$template->assign_vars(array(
"POLL_QUESTION" => $vote_title,
"L_SUBMIT_VOTE" => $lang['Submit_vote'],
"S_HIDDEN_FIELDS" => ( !empty($s_hidden_fields) ) ? $s_hidden_fields : "",
"S_POLL_ACTION" => append_sid("posting.$phpEx?" . POST_TOPIC_URL . "=$topic_id&mode=vote"))
);
$template->assign_var_from_handle("PORTAL_POLL", "pollbox");
}
}