1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-19 04:41:53 +02:00

Fixes #1449 - Polls failing in PHP7 and Multiple options voting not functioning.

This commit is contained in:
Cameron
2016-03-23 16:43:41 -07:00
parent 1c16094dea
commit 8282802d5e
8 changed files with 399 additions and 233 deletions

View File

@@ -23,52 +23,46 @@ if (!e107::isInstalled('poll'))
require_once(HEADERF);
require_once(e_HANDLER."comment_class.php");
$cobj = new comment;
$gen = new convert;
if(!defined("USER_WIDTH")){ define("USER_WIDTH","width:95%"); }
if(!defined("USER_WIDTH") && !deftrue('BOOTSTRAP'))
{
define("USER_WIDTH","width:95%");
}
include_lan(e_PLUGIN."poll/languages/".e_LANGUAGE.".php");
if(e_QUERY)
{
require_once('poll_class.php');
$query = "SELECT p.*, u.user_id, u.user_name FROM #polls AS p
LEFT JOIN #user AS u ON p.poll_admin_id = u.user_id
WHERE p.poll_type=1 AND p.poll_id=".intval(e_QUERY);
if($sql->db_Select_gen($query))
if($sql->gen($query))
{
$pl = new poll;
$row = $sql ->fetch();
$row = $sql -> db_Fetch();
extract($row);
$start_datestamp = $tp->toDate($row['poll_datestamp'], "long");
$end_datestamp = $tp->toDate($row['poll_end_datestamp'], "long");
$uparams = array('id' => $row['user_id'], 'name' => $row['user_name']);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$row['user_name']."</a>";
$optionArray = explode(chr(1), $poll_options);
$optionArray = array_slice($optionArray, 0, -1);
$voteArray = explode(chr(1), $poll_votes);
$voteArray = array_slice($voteArray, 0, -1);
$voteTotal = array_sum($voteArray);
$percentage = array();
foreach($voteArray as $votes)
{
$percentage[] = round(($votes/$voteTotal) * 100, 2);
}
$text = $pl->render_poll($row, 'forum', 'oldpolls',true);
$start_datestamp = $gen->convert_date($poll_datestamp, "long");
$end_datestamp = $gen->convert_date($poll_end_datestamp, "long");
//<a href='".e_BASE."user.php?id.{$user_id}'>".$user_name."</a>
$uparams = array('id' => $user_id, 'name' => $user_name);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$user_name."</a>";
$text = "<table style='".USER_WIDTH."'>
<tr>
<td colspan='2' class='mediumtext' style='text-align:center'>
<b>".$tp -> toHTML($poll_title,TRUE,'TITLE')."</b>
<div class='smalltext'>".POLLAN_35." ".$userlink."<br /> ".POLLAN_37." ".$start_datestamp." ".POLLAN_38." ".$end_datestamp.".<br />".POLLAN_26.": {$voteTotal}</div>
<br />
</td>
</tr>";
$text .= "
<div class='smalltext text-right'>
<small>".POLLAN_35." ".$userlink."<br /> ".POLLAN_37." ".$start_datestamp." ".POLLAN_38." ".$end_datestamp."</small></div>
";
$count = 0;
/* $count = 0;
$barl = (file_exists(THEME."images/barl.png") ? THEME."images/barl.png" : e_PLUGIN."poll/images/barl.png");
$barr = (file_exists(THEME."images/barr.png") ? THEME."images/barr.png" : e_PLUGIN."poll/images/barr.png");
@@ -92,79 +86,90 @@ if(e_QUERY)
$count++;
}
*/
$query = "SELECT c.*, u.* FROM #comments AS c
LEFT JOIN #user AS u ON FLOOR(SUBSTR(c.comment_author,1,INSTR(c.comment_author,'.')-1))=u.user_id
WHERE comment_item_id=".intval($poll_id)." AND comment_type=4 ORDER BY comment_datestamp";
if ($comment_total = $sql->db_Select_gen($query) !== FALSE)
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id
WHERE comment_item_id=".intval($row['poll_id'])." AND comment_type='4' ORDER BY comment_datestamp";
if ($comment_total = $sql->gen($query))
{
$text .= "<tr><td colspan='2'><br /><br />";
while ($row = $sql->db_Fetch()) {
$text .= $cobj->render_comment($row);
$text .= "<hr /><div>";
while ($row2 = $sql->fetch())
{
$text .= e107::getComment()->render_comment($row2, 'poll', 'comment');
}
$text .= "</td></tr>";
$text .= "</div>";
}
$text .= "</table>";
$ns->tablerender(POLL_ADLAN01." #".$poll_id, $text);
// $text .= "</table>";
$ns->tablerender(LAN_PLUGIN_POLL_NAME." #".$row['poll_id'], $text);
echo "<hr />";
}
}
$query = "SELECT p.*, u.user_name FROM #polls AS p
LEFT JOIN #user AS u ON p.poll_admin_id = u.user_id
WHERE p.poll_type=1
ORDER BY p.poll_datestamp DESC";
if(!$sql->db_Select_gen($query))
{
$ns->tablerender(POLLAN_28, "<div style='text-align:center'>".POLLAN_33."</div>");
// Render List of Polls.
$query = "SELECT p.*, u.user_name FROM #polls AS p
LEFT JOIN #user AS u ON p.poll_admin_id = u.user_id
WHERE p.poll_type=1
ORDER BY p.poll_datestamp DESC";
if(!$array = $sql->retrieve($query,true))
{
$ns->tablerender(POLLAN_28, "<div style='text-align:center'>".POLLAN_33."</div>");
require_once(FOOTERF);
exit;
}
$array = array_slice($array, 1);
if(empty($array))
{
$ns->tablerender(POLLAN_28, "<div style='text-align:center'>".POLLAN_33."</div>");
require_once(FOOTERF);
exit;
}
$text = "<table class='table fborder' style='".USER_WIDTH."'>
<colgroup>
<col style='width: 55%;' />
<col style='width: 15%;' />
<col style='width: 30%;' />
<thead>
<tr>
<th class='fcaption'>".LAN_TITLE."</th>
<th class='fcaption'>".POLLAN_35."</th>
<th class='fcaption'>".POLLAN_36."</th>
</tr></thead><tbody>\n";
foreach($array as $row)
{
$from = $tp->toDate($row['poll_datestamp'], "short");
$to = $tp->toDate($row['poll_end_datestamp'], "short");
$poll_title = $tp->toHtml($row['poll_title'], true, 'TITLE');
$uparams = array('id' => $row['poll_admin_id'], 'name' => $row['user_name']);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$row['user_name']."</a>";
$text .= "<tr>
<td class='forumheader3' style='width: 55%;'><a href='".e_SELF."?".$row['poll_id']."'>{$poll_title}</a></td>
<td class='forumheader3' style='width: 15%;'>".$userlink."</td>
<td class='forumheader3' style='width: 30%;'>".$from." ".POLLAN_38." ".$to."</td>
</tr>\n";
}
$text .= "</tbody></table>";
e107::getRender()->tablerender(POLLAN_28, $text);
require_once(FOOTERF);
exit;
}
$array = $sql -> db_getList();
$oldpollArray = array_slice($array, 1);
if(!count($oldpollArray))
{
$ns->tablerender(POLLAN_28, "<div style='text-align:center'>".POLLAN_33."</div>");
require_once(FOOTERF);
exit;
}
$text = "<table class='fborder' style='".USER_WIDTH."'>
<tr>
<td class='fcaption' style='width: 55%;'>".POLLAN_34."</td>
<td class='fcaption' style='width: 15%;'>".POLLAN_35."</td>
<td class='fcaption' style='width: 30%;'>".POLLAN_36."</td>
</tr>\n";
if (!is_object($tp->e_bb))
{
require_once(e_HANDLER.'bbcode_handler.php');
$tp->e_bb = new e_bbcode;
}
foreach($oldpollArray as $oldpoll)
{
extract($oldpoll);
$from = $gen->convert_date($poll_datestamp, "short");
$to = $gen->convert_date($poll_end_datestamp, "short");
$poll_title = $tp->e_bb->parseBBCodes($poll_title, 0,TRUE,TRUE); // Strip bbcodes
//<a href='".e_BASE."user.php?id.{$poll_admin_id}'>{$user_name}</a>
$uparams = array('id' => $poll_admin_id, 'name' => $user_name);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$user_name."</a>";
$text .= "<tr>
<td class='forumheader3' style='width: 55%;'><a href='".e_SELF."?{$poll_id}'>{$poll_title}</a></td>
<td class='forumheader3' style='width: 15%;'>".$userlink."</td>
<td class='forumheader3' style='width: 30%;'>{$from} ".POLLAN_38." {$to}</td>
</tr>\n";
}
$text .= "</table>";
$ns->tablerender(POLLAN_28, $text);
require_once(FOOTERF);
?>