diff --git a/languages/de/mods/lang_portal.php b/languages/de/mods/lang_portal.php
index ef9b4a24..1d6395ca 100644
--- a/languages/de/mods/lang_portal.php
+++ b/languages/de/mods/lang_portal.php
@@ -163,8 +163,14 @@ $lang = array_merge($lang, array(
'POSTS_PER_TOPIC_OTHER' => 'Beiträge pro Thema: %d',
'POSTS_PER_TOPIC_ZERO' => 'Beiträge pro Thema: 0',
- // other
+ // Poll
'POLL' => 'Umfrage',
+ 'LATEST_POLLS' => 'Latest Polls',
+ 'NO_OPTIONS' => 'This poll has no available options.',
+ 'NO_POLL' => 'No polls available',
+ 'RETURN_PORTAL' => '%sReturn to the portal%s',
+
+ // other
'CLOCK' => 'Uhr',
'SPONSOR' => 'Sponsoren',
'PORTAL_COPY' => 'board3 Portal - based on phpBB3 Portal',
diff --git a/languages/de/mods/lang_portal_acp.php b/languages/de/mods/lang_portal_acp.php
index 6a34bdfa..f55bb772 100644
--- a/languages/de/mods/lang_portal_acp.php
+++ b/languages/de/mods/lang_portal_acp.php
@@ -157,8 +157,12 @@ $lang = array_merge($lang, array(
'ACP_PORTAL_POLLS_SETTINGS_EXPLAIN' => 'Hier kannst du die Einstellungen für Umfragen ändern.',
'PORTAL_POLL_TOPIC' => 'Umfragen Block anzeigen',
'PORTAL_POLL_TOPIC_EXPLAIN' => 'Diesen Block auf dem Portal anzeigen.',
- 'PORTAL_POLL_TOPIC_ID' => 'Umfragen Topic ID',
- 'PORTAL_POLL_TOPIC_ID_EXPLAIN' => 'Die Nummer des Themas, aus dem die Umfrage angezeigt werden soll. Nur eine Topic ID / Umfrage möglich.',
+ 'PORTAL_POLL_TOPIC_ID' => 'Poll forum id(s)',
+ 'PORTAL_POLL_TOPIC_ID_EXPLAIN' => 'The id(s) of the forums from which the polls should be displayed. Use a comma to separate multiple forums, or leave blank to use all available forums.',
+ 'PORTAL_POLL_LIMIT' => 'Poll display limit',
+ 'PORTAL_POLL_LIMIT_EXPLAIN' => 'The number of polls you would like to display on the portal page.',
+ 'PORTAL_POLL_ALLOW_VOTE' => 'Allow voting',
+ 'PORTAL_POLL_ALLOW_VOTE_EXPLAIN' => 'Allow users with the required permissions to vote from the portal page.',
// most poster
'ACP_PORTAL_MOST_POSTER_INFO' => 'Vielschreiber',
diff --git a/root/includes/acp/acp_portal.php b/root/includes/acp/acp_portal.php
index c78bdd90..e0a69e38 100644
--- a/root/includes/acp/acp_portal.php
+++ b/root/includes/acp/acp_portal.php
@@ -189,7 +189,9 @@ class acp_portal
'vars' => array(
'legend1' => 'ACP_PORTAL_POLLS_SETTINGS',
'portal_poll_topic' => array('lang' => 'PORTAL_POLL_TOPIC' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
- 'portal_poll_topic_id' => array('lang' => 'PORTAL_POLL_TOPIC_ID' , 'validate' => 'string', 'type' => 'text:10:200', 'explain' => true),
+ 'portal_poll_topic_id' => array('lang' => 'PORTAL_POLL_TOPIC_ID' , 'validate' => 'string', 'type' => 'text:10:200', 'explain' => true),
+ 'portal_poll_limit' => array('lang' => 'PORTAL_POLL_LIMIT' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
+ 'portal_poll_allow_vote' => array('lang' => 'PORTAL_POLL_ALLOW_VOTE' , 'validate' => 'ibool', 'type' => 'radio:yes_no', 'explain' => true),
)
);
break;
diff --git a/root/language/en/mods/lang_portal.php b/root/language/en/mods/lang_portal.php
index dbd0c8c5..668d5cb5 100644
--- a/root/language/en/mods/lang_portal.php
+++ b/root/language/en/mods/lang_portal.php
@@ -170,8 +170,14 @@ $lang = array_merge($lang, array(
'POSTS_PER_TOPIC_OTHER' => 'Posts per topic: %d',
'POSTS_PER_TOPIC_ZERO' => 'Posts per topic: 0',
+ // Poll
+ 'POLL' => 'Poll',
+ 'LATEST_POLLS' => 'Latest Polls',
+ 'NO_OPTIONS' => 'This poll has no available options.',
+ 'NO_POLL' => 'No polls available',
+ 'RETURN_PORTAL' => '%sReturn to the portal%s',
+
// other
- 'POLL' => 'Poll',
'CLOCK' => 'Clock',
'SPONSOR' => 'Sponsors',
diff --git a/root/language/en/mods/lang_portal_acp.php b/root/language/en/mods/lang_portal_acp.php
index e971f5f3..92eb195c 100644
--- a/root/language/en/mods/lang_portal_acp.php
+++ b/root/language/en/mods/lang_portal_acp.php
@@ -159,8 +159,12 @@ $lang = array_merge($lang, array(
'ACP_PORTAL_POLLS_SETTINGS_EXPLAIN' => 'Here you can change your poll information and certain specific options.',
'PORTAL_POLL_TOPIC' => 'Display poll blocks',
'PORTAL_POLL_TOPIC_EXPLAIN' => 'Display this block on portal.',
- 'PORTAL_POLL_TOPIC_ID' => 'Poll topic id',
- 'PORTAL_POLL_TOPIC_ID_EXPLAIN' => 'The id of the topic from wich the poll should be displayed. Only one ID number / poll is possible.',
+ 'PORTAL_POLL_TOPIC_ID' => 'Poll forum id(s)',
+ 'PORTAL_POLL_TOPIC_ID_EXPLAIN' => 'The id(s) of the forums from which the polls should be displayed. Use a comma to separate multiple forums, or leave blank to use all available forums.',
+ 'PORTAL_POLL_LIMIT' => 'Poll display limit',
+ 'PORTAL_POLL_LIMIT_EXPLAIN' => 'The number of polls you would like to display on the portal page.',
+ 'PORTAL_POLL_ALLOW_VOTE' => 'Allow voting',
+ 'PORTAL_POLL_ALLOW_VOTE_EXPLAIN' => 'Allow users with the required permissions to vote from the portal page.',
// most poster
'ACP_PORTAL_MOST_POSTER_INFO' => 'Most poster',
diff --git a/root/portal/block/poll.php b/root/portal/block/poll.php
index e33a61a4..58ebd9e4 100644
--- a/root/portal/block/poll.php
+++ b/root/portal/block/poll.php
@@ -1,6 +1,5 @@
0));
+$user->add_lang('viewtopic');
-$start = request_var('start', 0);
-$view = request_var('view', '');
+$view = request_var('view', '');
+$update = request_var('update', false);
+$poll_view = request_var('polls', '');
-$sort_days = request_var('st', ((!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0));
-$sort_key = request_var('sk', ((!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't'));
-$sort_dir = request_var('sd', ((!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a'));
+$poll_view_ar = ( strpos(urldecode($poll_view), ',') !== FALSE ) ? explode(',', urldecode($poll_view)) : (($poll_view != '') ? array($poll_view) : array());
-$update = request_var('update', false);
-
-// Do we have a topic or post id?
-if (!$topic_id && !$post_id)
+if ($update && $portal_config['portal_poll_allow_vote'])
{
- // trigger_error('NO_TOPIC');
- $portal_config['portal_poll_topic'] = false;
-}
-
-// Find topic id if user requested a newer or older topic
-if ($view && !$post_id)
-{
- if (!$forum_id)
- {
- $sql = 'SELECT forum_id
- FROM ' . TOPICS_TABLE . "
- WHERE topic_id = $topic_id";
- $result = $db->sql_query($sql);
- $forum_id = (int) $db->sql_fetchfield('forum_id');
- $db->sql_freeresult($result);
-
- if (!$forum_id)
- {
- trigger_error('NO_TOPIC');
- }
- }
-
- // Check for global announcement correctness?
- if ((!isset($row) || !$row['forum_id']) && !$forum_id)
- {
- //trigger_error('NO_TOPIC');
- $portal_config['portal_poll_topic'] = false;
- }
- else if (isset($row) && $row['forum_id'])
- {
- $forum_id = $row['forum_id'];
- }
-}
-
-// This rather complex gaggle of code handles querying for topics but
-// also allows for direct linking to a post (and the calculation of which
-// page the post is on and the correct display of viewtopic)
-$sql_array = array(
- 'SELECT' => 't.*, f.*',
-
- 'FROM' => array(
- FORUMS_TABLE => 'f',
- )
-);
-
-if ($user->data['is_registered'])
-{
- $sql_array['SELECT'] .= ', tw.notify_status';
- $sql_array['LEFT_JOIN'] = array();
-
- $sql_array['LEFT_JOIN'][] = array(
- 'FROM' => array(TOPICS_WATCH_TABLE => 'tw'),
- 'ON' => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id'
- );
-}
-
-if (!$post_id)
-{
- $sql_array['WHERE'] = "t.topic_id = $topic_id";
-}
-else
-{
- $sql_array['WHERE'] = "p.post_id = $post_id AND t.topic_id = p.topic_id" . ((!$auth->acl_get('m_approve', $forum_id)) ? ' AND p.post_approved = 1' : '');
- $sql_array['FROM'][POSTS_TABLE] = 'p';
-}
-
-$sql_array['WHERE'] .= ' AND (f.forum_id = t.forum_id';
-
-$sql_array['WHERE'] .= ')';
-$sql_array['FROM'][TOPICS_TABLE] = 't';
-
-// Join to forum table on topic forum_id unless topic forum_id is zero
-// whereupon we join on the forum_id passed as a parameter ... this
-// is done so navigation, forum name, etc. remain consistent with where
-// user clicked to view a global topic
-$sql = $db->sql_build_query('SELECT', $sql_array);
-$result = $db->sql_query($sql);
-$topic_data = $db->sql_fetchrow($result);
-$db->sql_freeresult($result);
-
-if (!$topic_data)
-{
- // If post_id was submitted, we try at least to display the topic as a last resort...
- if ($post_id && $forum_id && $topic_id)
- {
- redirect(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id"));
- }
-
- //trigger_error('NO_TOPIC');
- $portal_config['portal_poll_topic'] = false;
-}
-
-$forum_id = (int) $topic_data['forum_id'];
-$topic_id = (int) $topic_data['topic_id'];
-
-// Setup look and feel
-$user->setup('viewtopic', $topic_data['forum_style']);
-
-if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id))
-{
- //trigger_error('NO_TOPIC');
- $portal_config['portal_poll_topic'] = false;
-}
-
-// Start auth check
-if (!$auth->acl_get('f_read', $forum_id))
-{
- if ($user->data['user_id'] != ANONYMOUS)
- {
- //trigger_error('SORRY_AUTH_READ');
- $portal_config['portal_poll_topic'] = false;
- }
-
- //login_box('', $user->lang['LOGIN_VIEWFORUM']);
- $portal_config['portal_poll_topic'] = false;
-}
-
-// Forum is passworded ... check whether access has been granted to this
-// user this session, if not show login box
-if ($topic_data['forum_password'])
-{
- login_forum_box($topic_data);
-}
-
-// Post ordering options
-$limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
-
-$sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
-$sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.post_time', 's' => 'p.post_subject');
-
-$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
-gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
-
-// General Viewtopic URL for return links
-$viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&start=$start&$u_sort_param");
-
-// This is only used for print view so ...
-$server_path = (!$view) ? $phpbb_root_path : generate_board_url() . '/';
-
-// Does this topic contain a poll?
-if (!empty($topic_data['poll_start']))
-{
- $sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid
- FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p
- WHERE o.topic_id = $topic_id
- AND p.post_id = {$topic_data['topic_first_post_id']}
- AND p.topic_id = o.topic_id
- ORDER BY o.poll_option_id";
- $result = $db->sql_query($sql);
-
- $poll_info = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $poll_info[] = $row;
- }
- $db->sql_freeresult($result);
+ $up_topic_id = request_var('t', 0);
+ $up_forum_id = request_var('f', 0);
+ $voted_id = request_var('vote_id', array('' => 0));
$cur_voted_id = array();
if ($user->data['is_registered'])
{
$sql = 'SELECT poll_option_id
FROM ' . POLL_VOTES_TABLE . '
- WHERE topic_id = ' . $topic_id . '
+ WHERE topic_id = ' . $up_topic_id . '
AND vote_user_id = ' . $user->data['user_id'];
$result = $db->sql_query($sql);
@@ -219,60 +51,77 @@ if (!empty($topic_data['poll_start']))
// Cookie based guest tracking ... I don't like this but hum ho
// it's oft requested. This relies on "nice" users who don't feel
// the need to delete cookies to mess with results.
- if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
+ if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $up_topic_id]))
{
- $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]);
+ $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $up_topic_id]);
$cur_voted_id = array_map('intval', $cur_voted_id);
}
}
- $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) ||
- ($auth->acl_get('f_votechg', $forum_id) && $topic_data['poll_vote_change'])) &&
+ $sql = 'SELECT t.poll_length, t.poll_start, t.poll_vote_change, t.topic_status, f.forum_status, t.poll_max_options
+ FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
+ WHERE t.forum_id = f.forum_id AND t.topic_id = " . (int) $up_topic_id . " AND t.forum_id = " . (int) $up_forum_id;
+ $result = $db->sql_query_limit($sql, 1);
+ $topic_data = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ $s_can_up_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $up_forum_id)) ||
+ ($auth->acl_get('f_votechg', $up_forum_id) && $topic_data['poll_vote_change'])) &&
(($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) || $topic_data['poll_length'] == 0) &&
$topic_data['topic_status'] != ITEM_LOCKED &&
$topic_data['forum_status'] != ITEM_LOCKED) ? true : false;
- $s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || $view == 'viewpoll') ? true : false;
- if ($update && $s_can_vote)
+ if( $s_can_up_vote )
{
- if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'])
+ if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id))
{
- $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id");
-
+ $redirect_url = append_sid("./portal.$phpEx");
+
meta_refresh(5, $redirect_url);
-
- $message = (!sizeof($voted_id)) ? 'NO_VOTE_OPTION' : 'TOO_MANY_VOTE_OPTIONS';
- $message = $user->lang[$message] . '
' . sprintf($user->lang['RETURN_TOPIC'], '', '');
+ if (!sizeof($voted_id))
+ {
+ $message = 'NO_VOTE_OPTION';
+ }
+ else if (sizeof($voted_id) > $topic_data['poll_max_options'])
+ {
+ $message = 'TOO_MANY_VOTE_OPTIONS';
+ }
+ else
+ {
+ $message = 'VOTE_CONVERTED';
+ }
+
+ $message = $user->lang[$message] . '
' . sprintf($user->lang['RETURN_PORTAL'], '', '');
trigger_error($message);
}
-
+
foreach ($voted_id as $option)
{
if (in_array($option, $cur_voted_id))
{
continue;
}
-
+
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
SET poll_option_total = poll_option_total + 1
WHERE poll_option_id = ' . (int) $option . '
- AND topic_id = ' . (int) $topic_id;
+ AND topic_id = ' . (int) $up_topic_id;
$db->sql_query($sql);
-
+
if ($user->data['is_registered'])
{
$sql_ary = array(
- 'topic_id' => (int) $topic_id,
+ 'topic_id' => (int) $up_topic_id,
'poll_option_id' => (int) $option,
'vote_user_id' => (int) $user->data['user_id'],
'vote_user_ip' => (string) $user->ip,
);
-
- $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
+
+ $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
}
}
-
+
foreach ($cur_voted_id as $option)
{
if (!in_array($option, $voted_id))
@@ -280,116 +129,224 @@ if (!empty($topic_data['poll_start']))
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . '
SET poll_option_total = poll_option_total - 1
WHERE poll_option_id = ' . (int) $option . '
- AND topic_id = ' . (int) $topic_id;
+ AND topic_id = ' . (int) $up_topic_id;
$db->sql_query($sql);
-
+
if ($user->data['is_registered'])
{
$sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
- WHERE topic_id = ' . (int) $topic_id . '
+ WHERE topic_id = ' . (int) $up_topic_id . '
AND poll_option_id = ' . (int) $option . '
AND vote_user_id = ' . (int) $user->data['user_id'];
$db->sql_query($sql);
}
}
}
-
+
if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot'])
{
- $user->set_cookie('poll_' . $topic_id, implode(',', $voted_id), time() + 31536000);
+ $user->set_cookie('poll_' . $up_topic_id, implode(',', $voted_id), time() + 31536000);
}
-
+
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET poll_last_vote = ' . time() . "
- WHERE topic_id = $topic_id";
+ WHERE topic_id = $up_topic_id";
//, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
$db->sql_query($sql);
-
- $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id");
-
+
+ $redirect_url = append_sid("./portal.$phpEx");
+
meta_refresh(5, $redirect_url);
- trigger_error($user->lang['VOTE_SUBMITTED'] . '
' . sprintf($user->lang['RETURN_TOPIC'], '', ''));
+ trigger_error($user->lang['VOTE_SUBMITTED'] . '
' . sprintf($user->lang['RETURN_PORTAL'], '', ''));
}
-
- $poll_total = 0;
- foreach ($poll_info as $poll_option)
- {
- $poll_total += $poll_option['poll_option_total'];
- }
-
- if ($poll_info[0]['bbcode_bitfield'])
- {
- $poll_bbcode = new bbcode();
- }
- else
- {
- $poll_bbcode = false;
- }
-
- for ($i = 0, $size = sizeof($poll_info); $i < $size; $i++)
- {
- $poll_info[$i]['poll_option_text'] = censor_text($poll_info[$i]['poll_option_text']);
- $poll_info[$i]['poll_option_text'] = str_replace("\n", '
', $poll_info[$i]['poll_option_text']);
-
- if ($poll_bbcode !== false)
- {
- $poll_bbcode->bbcode_second_pass($poll_info[$i]['poll_option_text'], $poll_info[$i]['bbcode_uid'], $poll_option['bbcode_bitfield']);
- }
-
- $poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']);
- }
-
- $topic_data['poll_title'] = censor_text($topic_data['poll_title']);
- $topic_data['poll_title'] = str_replace("\n", '
', $topic_data['poll_title']);
-
- if ($poll_bbcode !== false)
- {
- $poll_bbcode->bbcode_second_pass($topic_data['poll_title'], $poll_info[0]['bbcode_uid'], $poll_info[0]['bbcode_bitfield']);
- }
- $topic_data['poll_title'] = smiley_text($topic_data['poll_title']);
-
- unset($poll_bbcode);
-
- foreach ($poll_info as $poll_option)
- {
- $option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0;
- $option_pct_txt = sprintf("%.1d%%", ($option_pct * 100));
-
- $template->assign_block_vars('poll_option', array(
- 'POLL_OPTION_ID' => $poll_option['poll_option_id'],
- 'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'],
- 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'],
- 'POLL_OPTION_PERCENT' => $option_pct_txt,
- 'POLL_OPTION_PCT' => round($option_pct * 100),
- 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 10)),
- 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false
- ));
- }
-
- $poll_end = $topic_data['poll_length'] + $topic_data['poll_start'];
-
- $template->assign_vars(array(
- 'POLL_QUESTION' => $topic_data['poll_title'],
- 'TOTAL_VOTES' => $poll_total,
- 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'),
- 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'),
-
- 'L_MAX_VOTES' => ($topic_data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $topic_data['poll_max_options']),
- 'L_POLL_LENGTH' => ($topic_data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
-
- 'S_HAS_POLL' => true,
- 'S_CAN_VOTE' => $s_can_vote,
- 'S_DISPLAY_RESULTS' => $s_display_results,
- 'S_IS_MULTI_CHOICE' => ($topic_data['poll_max_options'] > 1) ? true : false,
- 'S_POLL_ACTION' => $viewtopic_url,
-
- 'U_VIEW_RESULTS' => $viewtopic_url . '&view=viewpoll'
- ));
- unset($poll_end, $poll_info, $voted_id);
}
-$template->assign_vars(array(
- 'S_DISPLAY_POLL' => true
-));
+$where = '';
+$poll_forums = false;
+
+if( $portal_config['portal_poll_topic_id'] !== '' )
+{
+ $poll_forums_config = explode(',' ,$portal_config['portal_poll_topic_id']);
+ foreach($poll_forums_config as $poll_forum )
+ {
+ if ( is_numeric(trim($poll_forum)) === TRUE )
+ {
+ $poll_forum = (int) trim($poll_forum);
+ if( $auth->acl_get('f_read', $poll_forum) )
+ {
+ $poll_forums = true;
+ $where .= ($where == "") ? "t.forum_id = '{$poll_forum}'" : " OR t.forum_id = '{$poll_forum}'";
+ }
+ }
+ }
+}
+else
+{
+ $forum_list = $auth->acl_getf('f_read', true);
+
+ foreach($forum_list as $pf => $pf_data )
+ {
+ $pf = (int) trim($pf);
+ $poll_forums = true;
+ $where .= ($where == "") ? "t.forum_id = '{$pf}'" : " OR t.forum_id = '{$pf}'";
+ }
+}
+
+$where = ($where !== '') ? "AND ({$where})" : '';
+
+if( $poll_forums === TRUE )
+{
+
+ $sql = 'SELECT t.poll_title, t.poll_start, t.topic_id, t.forum_id, t.poll_length, t.poll_vote_change, t.poll_max_options, t.topic_status, f.forum_status
+ FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
+ WHERE t.forum_id = f.forum_id AND t.topic_approved = 1 AND t.poll_start > 0
+ {$where}
+ ORDER BY t.poll_start DESC";
+
+ $limit = ( isset($portal_config['portal_poll_limit']) ) ? $portal_config['portal_poll_limit'] : 3;
+
+ $result = $db->sql_query_limit($sql, $limit);
+
+ $has_poll = false;
+
+ if ($result)
+ {
+
+ while( $data = $db->sql_fetchrow($result) )
+ {
+ $has_poll = true;
+ $poll_has_options = false;
+
+ $topic_id = (int) $data['topic_id'];
+
+ $cur_voted_id = array();
+ if( $portal_config['portal_poll_allow_vote'] )
+ {
+ if ($user->data['is_registered'])
+ {
+ $vote_sql = 'SELECT poll_option_id
+ FROM ' . POLL_VOTES_TABLE . '
+ WHERE topic_id = ' . $topic_id . '
+ AND vote_user_id = ' . $user->data['user_id'];
+ $vote_result = $db->sql_query($vote_sql);
+
+ while ($row = $db->sql_fetchrow($vote_result))
+ {
+ $cur_voted_id[] = $row['poll_option_id'];
+ }
+ $db->sql_freeresult($vote_result);
+ }
+ else
+ {
+ // Cookie based guest tracking ... I don't like this but hum ho
+ // it's oft requested. This relies on "nice" users who don't feel
+ // the need to delete cookies to mess with results.
+ if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]))
+ {
+ $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]);
+ $cur_voted_id = array_map('intval', $cur_voted_id);
+ }
+ }
+
+ $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) ||
+ ($auth->acl_get('f_votechg', $forum_id) && $data['poll_vote_change'])) &&
+ (($data['poll_length'] != 0 && $data['poll_start'] + $data['poll_length'] > time()) || $data['poll_length'] == 0) &&
+ $data['topic_status'] != ITEM_LOCKED &&
+ $data['forum_status'] != ITEM_LOCKED) ? true : false;
+ } else {
+ $s_can_vote = false;
+ }
+
+ $s_display_results = ( !$s_can_vote || ( $s_can_vote && sizeof($cur_voted_id) ) || ( $view == 'viewpoll' && in_array($topic_id, $poll_view_ar) ) ) ? true : false;
+
+ $poll_sql = 'SELECT po.poll_option_id, po.poll_option_text, po.poll_option_total
+ FROM ' . POLL_OPTIONS_TABLE . " po
+ WHERE po.topic_id = {$topic_id}
+ ORDER BY po.poll_option_id";
+
+ $poll_result = $db->sql_query($poll_sql);
+
+ $poll_total_votes = 0;
+
+ $poll_data = array();
+
+ if ($poll_result)
+ {
+ while( $polls_data = $db->sql_fetchrow($poll_result) )
+ {
+ $poll_has_options = true;
+ $poll_data[] = $polls_data;
+ $poll_total_votes += $polls_data['poll_option_total'];
+ }
+ }
+
+ $db->sql_freeresult($poll_result);
+
+ $forum_id = (int) $data['forum_id'];
+
+ $make_poll_view = array();
+
+ if( in_array($topic_id, $poll_view_ar) === FALSE )
+ {
+ $make_poll_view[] = $topic_id;
+ $make_poll_view = array_merge($poll_view_ar, $make_poll_view);
+ }
+
+ $poll_view_str = urlencode( implode(',', $make_poll_view) );
+
+ $portalpoll_url= append_sid("./portal.$phpEx", "polls=$poll_view_str");
+ $portalvote_url= append_sid("./portal.$phpEx", "f=$forum_id&t=$topic_id");
+ $viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id");
+
+ $poll_end = $data['poll_length'] + $data['poll_start'];
+
+ $template->assign_block_vars('poll', array(
+ 'S_POLL_HAS_OPTIONS' => $poll_has_options,
+ 'POLL_QUESTION' => $data['poll_title'],
+ 'U_POLL_TOPIC' => append_sid($phpbb_root_path . 'viewtopic.' . $phpEx . '?t=' . $topic_id . '&f=' . $forum_id),
+ 'POLL_LENGTH' => $data['poll_length'],
+ 'TOPIC_ID' => $topic_id,
+
+ 'TOTAL_VOTES' => $poll_total_votes,
+
+ 'L_MAX_VOTES' => ($data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $data['poll_max_options']),
+ 'L_POLL_LENGTH' => ($data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
+
+ 'S_CAN_VOTE' => $s_can_vote,
+ 'S_DISPLAY_RESULTS' => $s_display_results,
+ 'S_IS_MULTI_CHOICE' => ($data['poll_max_options'] > 1) ? true : false,
+ 'S_POLL_ACTION' => $portalvote_url,
+
+ 'U_VIEW_RESULTS' => $portalpoll_url . '&view=viewpoll',
+ 'U_VIEW_TOPIC' => $viewtopic_url
+ ));
+
+ foreach($poll_data as $pd)
+ {
+ $option_pct = ($poll_total_votes > 0) ? $pd['poll_option_total'] / $poll_total_votes : 0;
+ $option_pct_txt = sprintf("%.1d%%", ($option_pct * 100));
+
+ $template->assign_block_vars('poll.poll_option', array(
+ 'POLL_OPTION_ID' => $pd['poll_option_id'],
+ 'POLL_OPTION_CAPTION' => $pd['poll_option_text'],
+ 'POLL_OPTION_RESULT' => $pd['poll_option_total'],
+ 'POLL_OPTION_PERCENT' => $option_pct_txt,
+ 'POLL_OPTION_PCT' => round($option_pct * 100),
+ 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)),
+ 'POLL_OPTION_VOTED' => (in_array($pd['poll_option_id'], $cur_voted_id)) ? true : false
+ ));
+ }
+ }
+ }
+
+ $db->sql_freeresult($result);
+
+ $template->assign_vars(array(
+ 'S_DISPLAY_POLL' => true,
+ 'S_HAS_POLL' => $has_poll,
+ 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'),
+ 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'),
+ ));
+}
?>
\ No newline at end of file
diff --git a/root/styles/prosilver/template/portal/block/poll.html b/root/styles/prosilver/template/portal/block/poll.html
index 1d6d39bf..da756160 100644
--- a/root/styles/prosilver/template/portal/block/poll.html
+++ b/root/styles/prosilver/template/portal/block/poll.html
@@ -2,46 +2,73 @@