Viewing file: booth.php (7.43 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
// make sure this is a first
if(isset($isinc_booth)) return;
$isinc_booth = TRUE;
// detect file extension
$dotloc = strrpos(__FILE__, ".");
$ext = substr(__FILE__, $dotloc+1, (strlen(__FILE__) - $dotloc));
// detect sympoll directory
$symphome = dirname(__FILE__);
if(ereg("[/]$", $symphome))
{$symphome = substr($symphome, 0, strlen($symphome)-1);}
// include files
include "${symphome}/common.${ext}";
include "${symphome}/classes/poll.${ext}";
# get the top of the booth/results table.
function spew_top($p) {
global $s_width, $s_bg, $s_bord, $s_txtface, $s_qtx, $s_qbg, $s_txtsize;
# sorry about the mess here... the lines are too long to make pretty anyway
$o = "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" width=\""."$s_width"."\" bgcolor=\""."$s_bg"."\">\n<tr><td width=\"100%\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\""."$s_bord"."\" width=\"100%\">\n<tr><td width=\"100%\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\""."$s_qbg"."\" width=\"100%\">\n<tr><td width=\"100%\" valign=\"middle\">\n<font color=\""."$s_qtx"."\" size=\""."$s_txtsize"."\" face=\""."$s_txtface"."\">\n<b>"."$p->question"."<br /></b></font>\n</td></tr></table>\n</td></tr></table>\n</td></tr><tr><td width=\"100%\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\""."$s_bord"."\" width=\"100%\">\n<tr><td width=\"100%\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\""."$s_bg"."\" width=\"100%\">\n";
return $o;
}
function boothUI($p, $rand) {
global $s_tx, $s_txtsize, $s_optsize;
global $s_txtface, $s_dirurl, $s_polllist, $ext;
global $symp_lang1, $symp_lang2, $symp_lang3;
global $QUERY_STRING, $SYMP_URL;
// handle results-only marker and random-poll markers
$vostr = "vo="."$p->pid";
$rdstr = "rd="."$p->pid";
$sympurl = $SYMP_URL;
if(isset($QUERY_STRING)) {
$QUERY_STRING = ereg_replace("[&]?vo=[0-9]+","","$QUERY_STRING");
if(substr("$QUERY_STRING", 0, 1) == "&")
{ $QUERY_STRING = substr($QUERY_STRING, 1); }
}
if($QUERY_STRING == "") {
if($rand == TRUE) {
$sympurl .= "?"."$rdstr";
$QUERY_STRING = "$rdstr";
$vostr = "&"."$vostr";
} else {
$vostr = "?"."$vostr";
}
} else {
if($rand == TRUE) {
$QUERY_STRING .= "&"."$rdstr";
}
$sympurl .= "?"."$QUERY_STRING";
$vostr = "&"."$vostr";
}
// spit out the html for the booth
$o = "<form method=\"post\" action=\""."$s_dirurl"."dovote."."$ext"."\">\n";
$o.= spew_top($p);
// various options
while(is_array($p->options) && list($k,$v) = each($p->options)) {
$o.= "<tr><td width=\"10\" valign=\"top\" align=\"left\">\n";
$o.= "<input type=\"radio\" name=\"cid\" value=\"$k\" /></td>\n";
$o.= "<td width=\"100%\" valign=\"middle\" align=\"left\">\n";
$o.= "<font color=\"$s_tx\" face=\"$s_txtface\" size=\"$s_optsize\">\n";
$o.= "${v}</font></td></tr>\n\n";
}
// poll table footer
$o.= "<tr><td width=\"100%\" colspan=\"2\">\n";
$o.= "<font color=\"#000000\" size=\"1\" face=\"$s_txtface\"> \n";
$o.= "<input type=\"submit\" value=\"$symp_lang1\" style=\"font-size: 10px\" />";
$o.= "\n</font>\n";
if($s_polllist == "0") {
$o.= "<font size =\"1\" face=\"$s_txtface\">\n";
$o.= " ";
$o.= "<a href=\""."$sympurl"."$vostr"."\">$symp_lang2</a></font>\n";
} else {
$o.= "<div align=\"center\">";
$o.= "<font size =\"1\" face=\"$s_txtface\"><br />\n";
$o.= "<a href=\""."$sympurl"."$vostr"."\">"."$symp_lang2"."</a>";
$o.= " ~ ";
$o.= "<a href=\""."$s_dirurl"."polllist."."$ext"."\">"."$symp_lang3"."</a></font>";
$o.= "</div>\n";
}
$o.= "</td></tr></table>\n</td></tr></table>\n</td></tr></table>\n";
$o.= "<input type=\"hidden\" name=\"pid\" value=\"$p->pid\" />\n";
$o.= "<input type=\"hidden\" name=\"ref\" value=\"$sympurl\" />\n";
$o.= "<input type=\"hidden\" name=\"vostr\" value=\""."$vostr"."\" />\n";
$o.= "</form>\n";
return $o;
}
function resultsUI($p, $cid) {
global $s_tx, $s_txtsize, $s_optsize, $s_width;
global $s_txtface, $s_barimg, $s_barhite, $ext, $s_showtotal;
global $s_dirurl, $s_polllist, $s_resultnums, $symp_lang3, $symp_lang6;
$o = spew_top($p);
$p->calc_pcts();
$offset = 1;
// print each result row
while(is_array($p->options) && list($k,$v) = each($p->options)) {
if($s_resultnums == "0") {
$rnum = $p->votepcts[$k]."%";
} else {
$rnum = $p->votes[$k];
}
if($p->highpct > 0) {
$imgsize = floor($p->votepcts[$k] * (($s_width-40) / $p->highpct) ) + $offset;
} else {
$imgsize = $offset;
}
if($s_polllist != "0" && $s_showtotal != "0") {
$o.= "<tr><td valign=\"top\" colspan=\"2\">";
} else {
$o.= "<tr><td valign=\"top\">";
}
$o.= "<font color=\"$s_tx\" face=\"$s_txtface\" size=\"$s_optsize\">\n";
// print option text
if($k == $cid) {
$o.= "<b>"."$v"."</b>\n";
} else {
$o.= "$v"."\n";
}
// print result and bars
$alt = "tally: $rnum";
$srcp = "$s_dirurl"."$s_barimg";
$o.= "<br /><font color=\"#000000\">";
$o.= "<img src=\"$srcp\" width=\"$imgsize\" height=\"$s_barhite\" alt=\"$alt\" border=\"1\" align=\"top\" />";
$o.= "</font>";
$o.= " "."$rnum"."<br />";
$o.= "</font></td></tr>\n";
}
if($s_showtotal != "0" || $s_polllist != "0") {
$o.= "<tr>";
if($s_showtotal != "0") {
$o.= "<td align=\"left\"><font color=\"$s_tx\" size=\"1\" face=\"$s_txtface\">\n";
$o.= "<i>"."$symp_lang6".": </i>"."$p->tvotes";
$o.= "\n</font></td>\n";
}
if($s_polllist != "0") {
if($s_showtotal != "0") {
$o.= "<td align=\"right\">";
} else {
$o.= "<td align=\"left\">";
}
$o.= "<font color=\"$s_tx\" size=\"1\" face=\"$s_txtface\">\n";
$o.= "<a href=\""."$s_dirurl"."polllist."."$ext"."\">"."$symp_lang3"."</a>";
$o.= "\n</font></td>\n";
}
$o.= "</tr>";
}
$o.= "</table>\n</td></tr></table>\n</td></tr></table>\n";
return $o;
}
function get_booth($pid) {
global $vo, $rd, $sympvotes, $symp_lang8, $s_iplog, $s_cookielog;
if(isset($rd) && $rd != "" && $pid == -1)
{ $pid = $rd; }
$p = new Poll($pid);
if ($p->pid < 0 || $p->status == 0)
{ return "<b>"."$symp_lang8"."</b>"; }
// keep track of random poll displayed
$rand = FALSE;
if($pid == -1)
{ $rand = TRUE; }
// do we have a cookie already for this poll?
$cookiename = 'symp'.$p->tstamp;
global $$cookiename;
if(isset($sympvotes[$cookiename])) {
$scookie1 = $sympvotes[$cookiename];
} elseif(isset($$cookiename)) { /* backwards compatibility */
$scookie1 = $$cookiename;
}
if($s_cookielog != "0" && isset($scookie1)) {
return resultsUI($p, $scookie1);
} elseif( (isset($vo) && $vo == $p->pid) ||
($s_iplog != "0" && $p->voted != 0) ) {
return resultsUI($p, -1);
} else {
return boothUI($p, $rand);
}
}
# for use with templates, you can optionally change the following
# three functions to use return instead of echo. this will return
# all the text instead of directly displaying it.
function display_booth($pid) { echo get_booth($pid); }
function random_booth() { echo get_booth(-1); }
function newest_booth() { echo get_booth(-2); }
?>
|