Sometime back I got a paid hack which shows all polls on 1 single page.
the PHP copy is attached. Lately I have got wary of the mod, it has lost its attractiveness - since it uses no templates - it looks pretty bland on my forum.
PLUS instead of showing recent poll first.. it shows the oldest poll first and most recent right in the end.
Can someone out here suggest or better this mod in some way... will really appreciate your help in this.
thanks
PHP Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'polls');
define('POLLSPERPAGE', 3);
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array(
'polloptions_table',
'polloption',
'polloption_multiple',
'pollresults_table',
'pollresult',
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once('./includes/functions_bigthree.php');
require_once('./includes/functions_showthread.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
// check for vboption
//if (!isset($vboptions['pollsperpage']))
//{
// $DB_site->query("INSERT INTO " . TABLE_PREFIX . "phrase (phraseid, languageid, varname, text, phrasetypeid) VALUES (NULL, '0', 'setting_pollsperpage_title', '" . addslashes('Polls Per Page') ."', '5000')");
// $DB_site->query("INSERT INTO " . TABLE_PREFIX . "phrase (phraseid, languageid, varname, text, phrasetypeid) VALUES (NULL, '0', 'setting_pollsperpage_desc', '" . addslashes('The number of polls you would like displayed on the page that displays all polls.') ."', '5000')");
// $DB_site->query("INSERT INTO " . TABLE_PREFIX . "setting (varname, grouptitle, value, defaultvalue, displayorder, volatile) VALUES('pollsperpage', 'poll', 10, 10, 120, 1)");
// $vboptions['pollsperpage'] = '10';
//}
$threads = $DB_site->query("SELECT forumid, pollid, open, threadid FROM " . TABLE_PREFIX . "thread WHERE pollid > 0");
while($thread = $DB_site->fetch_array($threads))
{
$threadpollinfo[$thread['pollid']][] = $thread['forumid'];
$threadpollinfo[$thread['pollid']][] = $thread['open'];
$threadpollinfo[$thread['pollid']][] = $thread['threadid'];
}
if (empty($_REQUEST['start'])) $_REQUEST['start'] = 0;
$pollnum = 0;
$polls = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "poll");
$totalpolls = $DB_site->num_rows($polls);
// page number
if (empty($_REQUEST['page'])) $pagenumber = 1;
else $pagenumber = $_REQUEST['page'];
// page construction
$perpage = $vboptions['pollsperpage'];
$pagenav = construct_page_nav($totalpolls, "polls.php?$session[sessionurl]", "&pp=".$vboptions['pollsperpage']);
// start number
$prevpage = $pagenumber - 1;
$start = $perpage * $prevpage;
$polls = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "poll ORDER BY pollid LIMIT " . $start .", ". $perpage);
while($pollinfo = $DB_site->fetch_array($polls))
{
$pollbits = '';
$counter = 1;
$pollid = $pollinfo['pollid'];
$threadinfo['forumid'] = $threadpollinfo[$pollid]['0'];
$thread['open'] = $threadpollinfo[$pollid]['1'];
$show['editpoll'] = iif(can_moderate($threadinfo['forumid'], 'caneditpoll'), true, false);
$pollinfo['question'] = parse_bbcode(unhtmlspecialchars($pollinfo['question']));
$splitoptions = explode('|||', $pollinfo['options']);
$splitvotes = explode('|||', $pollinfo['votes']);
$showresults = 0;
$uservoted = 0;
$forumperms = fetch_permissions($threadinfo['forumid']);
if (!($forumperms & CANVOTE))
{
$nopermission = 1;
}
//if (!$pollinfo['active'] OR ($pollinfo['dateline'] + ($pollinfo['timeout'] * 86400) < TIMENOW AND $pollinfo['timeout'] != 0))
if (!$pollinfo['active'] OR !$thread['open'] OR ($pollinfo['dateline'] + ($pollinfo['timeout'] * 86400) < TIMENOW AND $pollinfo['timeout'] != 0) OR $nopermission)
{
// poll is closed, ie show results no matter what
$showresults = 1;
}
else
{
//get userid, check if user already voted
$voted = fetch_bbarray_cookie('poll_voted', $pollid);
if ($voted)
{
$uservoted = 1;
}
}
if ($pollinfo['timeout'] AND !$showresults)
{
$pollendtime = vbdate($vboptions['timeformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
$pollenddate = vbdate($vboptions['dateformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
$show['pollenddate'] = true;
}
else
{
$show['pollenddate'] = false;
}
$option['open'] = $stylevar['left'][0];
$option['close'] = $stylevar['right'][0];
foreach ($splitvotes AS $index => $value)
{
$pollinfo['numbervotes'] += $value;
}
if ($bbuserinfo['userid'] > 0 AND $pollinfo['numbervotes'] > 0)
{
$pollvotes = $DB_site->query("
SELECT voteoption
FROM " . TABLE_PREFIX . "pollvote
WHERE userid = $bbuserinfo[userid] AND pollid = $pollid
");
if ($DB_site->num_rows($pollvotes) > 0)
{
$uservoted = 1;
}
}
if ($showresults OR $uservoted)
{
if ($uservoted)
{
$uservote = array();
while ($pollvote = $DB_site->fetch_array($pollvotes))
{
$uservote["$pollvote[voteoption]"] = 1;
}
}
}
foreach ($splitvotes AS $index => $value)
{
$arrayindex = $index + 1;
$option['uservote'] = iif($uservote["$arrayindex"], true, false);
$option['question'] = parse_bbcode($splitoptions["$index"], $forum['forumid'], 1);
// public link
if ($pollinfo['public'] AND $value)
{
$option['votes'] = '<a href="poll.php?' . $session['sessionurl'] . 'do=showresults&pollid=' . $pollinfo['pollid'] . '">' . $value . '</a>';
}
else
{
$option['votes'] = $value; //get the vote count for the option
}
$option['number'] = $counter; //number of the option
//Now we check if the user has voted or not
if ($showresults OR $uservoted)
{ // user did vote or poll is closed
if ($value == 0)
{
$option['percent'] = 0;
}
else if ($pollinfo['multiple'])
{
$option['percent'] = vb_number_format($value / $pollinfo['voters'] * 100, 2);
$option['percent'] = vb_number_format(($value < $pollinfo['voters']) ? $value / $pollinfo['voters'] * 100 : 100, 2);
}
else
{
$option['percent'] = vb_number_format(($value < $pollinfo['numbervotes']) ? $value / $pollinfo['numbervotes'] * 100 : 100, 2);
}
$option['graphicnumber'] = $option['number'] % 6 + 1;
$option['barnumber'] = round($option['percent']) * 2;
// Phrase parts below
if ($nopermission)
{
$pollstatus = $vbphrase['you_may_not_vote_on_this_poll'];
}
else if ($showresults)
{
$pollstatus = $vbphrase['this_poll_is_closed'];
}
else if ($uservoted)
{
$pollstatus = $vbphrase['you_have_already_voted_on_this_poll'];
}
eval('$pollbits .= "' . fetch_template('pollresult') . '";');
}
else
{
if ($pollinfo['multiple'])
{
eval('$pollbits .= "' . fetch_template('polloption_multiple') . '";');
}
else
{
eval('$pollbits .= "' . fetch_template('polloption') . '";');
}
}
$counter++;
}
if ($pollinfo['multiple'])
{
$pollinfo['numbervotes'] = $pollinfo['voters'];
$show['multiple'] = true;
}
if ($pollinfo['public'])
{
$show['publicwarning'] = true;
}
else
{
$show['publicwarning'] = false;
}
// add thread link
eval('$poll.= "<table><tr><td><br><b>Login to cast your vote or click<a href=\"showthread.php?$session[sessionurl]t=".$threadpollinfo[$pollid][2]."\">here</a> to discuss this poll.</b><br></td></tr></table>";');
if ($showresults OR $uservoted)
{
eval('$poll .= "' . fetch_template('pollresults_table') . '";');
}
else
{
eval('$poll .= "' . fetch_template('polloptions_table') . '";');
}
}
eval('$HTML = "<div align=\"$stylevar[right]\">$pagenav</div>$poll<div align=\"$stylevar[right]\">$pagenav</div>";');
// #############################################################################
// draw navbar
$navbits = array();
$navbits[''] = 'Polls';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// #############################################################################
// output page
eval('print_output("' . fetch_template('GENERIC_SHELL') . '");');
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 17:11, Tue Jan 18th 2005
|| # CVS: $RCSfile: polls.php,v $ - $Revision: 1.454.2.7 $
|| ####################################################################
\*======================================================================*/
?>