Vergleich polls.php - 1.6.8 - 1.6.11

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * $Id: polls.php 5826 2012-05-04 10:30:10Z Tomm $

 * $Id$

 */

define("IN_MYBB", 1);
define('THIS_SCRIPT', 'polls.php');


 */

define("IN_MYBB", 1);
define('THIS_SCRIPT', 'polls.php');


$templatelist = "poll_newpoll,redirect_pollposted,redirect_pollupdated,redirect_votethanks";

$templatelist = "changeuserbox,loginbox,polls_newpoll_option,polls_newpoll,polls_editpoll_option,polls_editpoll,polls_showresults_resultbit,polls_showresults";

require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/class_parser.php";

require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/class_parser.php";

Zeile 50Zeile 50

$query = $db->simple_select("threads", "*", "tid='".intval($mybb->input['tid'])."'");
$thread = $db->fetch_array($query);


$query = $db->simple_select("threads", "*", "tid='".intval($mybb->input['tid'])."'");
$thread = $db->fetch_array($query);

	$fid = $thread['fid'];
$forumpermissions = forum_permissions($fid);

// Get forum info
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);
}






	if(!$thread['tid'])
{
error($lang->error_invalidthread);
}

$fid = $thread['fid'];
$forumpermissions = forum_permissions($fid);

// Get forum info
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);
}

	else

	else

	{

	{

		// Is our forum closed?

		// Is our forum closed?

		if ($forum['open'] == 0)

		if($forum['open'] == 0 && !is_moderator($fid, "caneditposts"))

		{
// Doesn't look like it is
error($lang->error_closedinvalidforum);
}

		{
// Doesn't look like it is
error($lang->error_closedinvalidforum);
}

	}

if(!$thread['tid'])
{
error($lang->error_invalidthread);

 
	}
// Make navigation
build_forum_breadcrumb($fid);

	}
// Make navigation
build_forum_breadcrumb($fid);

Zeile 85Zeile 85
	}

if($thread['poll'])

	}

if($thread['poll'])

	{
error($lang->error_pollalready);
}


	{
error($lang->error_pollalready);
}


	// Sanitize number of poll options
if($mybb->input['numpolloptions'] > 0)
{

	// Sanitize number of poll options
if($mybb->input['numpolloptions'] > 0)
{

Zeile 113Zeile 113
	if($postoptions['multiple'] == 1)
{
$postoptionschecked['multiple'] = 'checked="checked"';

	if($postoptions['multiple'] == 1)
{
$postoptionschecked['multiple'] = 'checked="checked"';

	}

	}

	if($postoptions['public'] == 1)
{
$postoptionschecked['public'] = 'checked="checked"';

	if($postoptions['public'] == 1)
{
$postoptionschecked['public'] = 'checked="checked"';

Zeile 151Zeile 151
	$plugins->run_hooks("polls_do_newpoll_start");

$query = $db->simple_select("threads", "*", "tid='".intval($mybb->input['tid'])."'");

	$plugins->run_hooks("polls_do_newpoll_start");

$query = $db->simple_select("threads", "*", "tid='".intval($mybb->input['tid'])."'");

	$thread = $db->fetch_array($query);
$fid = $thread['fid'];
$forumpermissions = forum_permissions($fid);

// Get forum info
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);
}
else
{
// Is our forum closed?
if ($forum['open'] == 0)
{
// Doesn't look like it is






	$thread = $db->fetch_array($query);
if(!$thread['tid'])
{
error($lang->error_invalidthread);
}

$fid = $thread['fid'];
$forumpermissions = forum_permissions($fid);

// Get forum info
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);
}
else
{
// Is our forum closed?
if($forum['open'] == 0 && !is_moderator($fid, "caneditposts"))
{
// Doesn't look like it is

			error($lang->error_closedinvalidforum);
}

			error($lang->error_closedinvalidforum);
}

	}

if(!$thread['tid'])
{
error($lang->error_invalidthread);

 
	}

// No permission if: Not thread author; not moderator; no forum perms to view, post threads, post polls
if(($thread['uid'] != $mybb->user['uid'] && !is_moderator($fid)) || ($forumpermissions['canview'] == 0 || $forumpermissions['canpostthreads'] == 0 || $forumpermissions['canpostpolls'] == 0))
{
error_no_permission();

	}

// No permission if: Not thread author; not moderator; no forum perms to view, post threads, post polls
if(($thread['uid'] != $mybb->user['uid'] && !is_moderator($fid)) || ($forumpermissions['canview'] == 0 || $forumpermissions['canpostthreads'] == 0 || $forumpermissions['canpostpolls'] == 0))
{
error_no_permission();

	}


	}


	if($thread['poll'])

	if($thread['poll'])

	{

	{

		error($lang->error_pollalready);

		error($lang->error_pollalready);

	}

	}


$polloptions = $mybb->input['polloptions'];
if($mybb->settings['maxpolloptions'] && $polloptions > $mybb->settings['maxpolloptions'])


$polloptions = $mybb->input['polloptions'];
if($mybb->settings['maxpolloptions'] && $polloptions > $mybb->settings['maxpolloptions'])

Zeile 195Zeile 195

$postoptions = $mybb->input['postoptions'];
if($postoptions['multiple'] != '1')


$postoptions = $mybb->input['postoptions'];
if($postoptions['multiple'] != '1')

	{

	{

		$postoptions['multiple'] = 0;

		$postoptions['multiple'] = 0;

	}

	}


if($postoptions['public'] != '1')
{
$postoptions['public'] = 0;


if($postoptions['public'] != '1')
{
$postoptions['public'] = 0;

	}


	}


	if($polloptions < 2)
{
$polloptions = "2";
}
$optioncount = "0";
$options = $mybb->input['options'];

	if($polloptions < 2)
{
$polloptions = "2";
}
$optioncount = "0";
$options = $mybb->input['options'];

	
for($i = 1; $i <= $polloptions; ++$i)


for($i = 1; $i <= $polloptions; ++$i)

	{
if(trim($options[$i]) != "")

	{
if(trim($options[$i]) != "")

		{

		{

			$optioncount++;

			$optioncount++;

		}


		}


		if(my_strlen($options[$i]) > $mybb->settings['polloptionlimit'] && $mybb->settings['polloptionlimit'] != 0)
{
$lengtherror = 1;
break;
}
}

		if(my_strlen($options[$i]) > $mybb->settings['polloptionlimit'] && $mybb->settings['polloptionlimit'] != 0)
{
$lengtherror = 1;
break;
}
}

	



	if($lengtherror)
{
error($lang->error_polloptiontoolong);
}

	if($lengtherror)
{
error($lang->error_polloptiontoolong);
}

	



	if(empty($mybb->input['question']) || $optioncount < 2)
{
error($lang->error_noquestionoptions);
}

	if(empty($mybb->input['question']) || $optioncount < 2)
{
error($lang->error_noquestionoptions);
}

	



	$optionslist = '';
$voteslist = '';

	$optionslist = '';
$voteslist = '';

	for($i = 1; $i <= $optioncount; ++$i)

	for($i = 1; $i <= $polloptions; ++$i)

	{
if(trim($options[$i]) != '')
{

	{
if(trim($options[$i]) != '')
{

			if($i > 1)

			if($optionslist != '')

			{
$optionslist .= '||~|~||';
$voteslist .= '||~|~||';
}

			{
$optionslist .= '||~|~||';
$voteslist .= '||~|~||';
}

			$optionslist .= $options[$i];

			$optionslist .= trim(utf8_handle_4byte_string($options[$i]));

			$voteslist .= '0';
}
}

			$voteslist .= '0';
}
}

	



	if($mybb->input['timeout'] > 0)

	if($mybb->input['timeout'] > 0)

	{

	{

		$timeout = intval($mybb->input['timeout']);

		$timeout = intval($mybb->input['timeout']);

	}

	}

	else
{
$timeout = 0;
}

	else
{
$timeout = 0;
}

	




$mybb->input['question'] = utf8_handle_4byte_string($mybb->input['question']);


	$newpoll = array(
"tid" => $thread['tid'],
"question" => $db->escape_string($mybb->input['question']),

	$newpoll = array(
"tid" => $thread['tid'],
"question" => $db->escape_string($mybb->input['question']),

Zeile 277Zeile 279
	$plugins->run_hooks("polls_do_newpoll_process");

$pid = $db->insert_query("polls", $newpoll);

	$plugins->run_hooks("polls_do_newpoll_process");

$pid = $db->insert_query("polls", $newpoll);





	$db->update_query("threads", array('poll' => $pid), "tid='".$thread['tid']."'");

	$db->update_query("threads", array('poll' => $pid), "tid='".$thread['tid']."'");





	$plugins->run_hooks("polls_do_newpoll_end");

	$plugins->run_hooks("polls_do_newpoll_end");





	if($thread['visible'] == 1)

	if($thread['visible'] == 1)

	{

	{

		redirect(get_thread_link($thread['tid']), $lang->redirect_pollposted);

		redirect(get_thread_link($thread['tid']), $lang->redirect_pollposted);

	}
else
{
redirect(get_forum_link($thread['fid']), $lang->redirect_pollpostedmoderated);
}
}


	}
else
{
redirect(get_forum_link($thread['fid']), $lang->redirect_pollpostedmoderated);
}
}


if($mybb->input['action'] == "editpoll")
{
$pid = intval($mybb->input['pid']);

$plugins->run_hooks("polls_editpoll_start");

if($mybb->input['action'] == "editpoll")
{
$pid = intval($mybb->input['pid']);

$plugins->run_hooks("polls_editpoll_start");





	$query = $db->simple_select("polls", "*", "pid='$pid'");
$poll = $db->fetch_array($query);

	$query = $db->simple_select("polls", "*", "pid='$pid'");
$poll = $db->fetch_array($query);









if(!$poll['pid'])
{
error($lang->error_invalidpoll);
}


	$query = $db->simple_select("threads", "*", "poll='$pid'");
$thread = $db->fetch_array($query);
$tid = $thread['tid'];

	$query = $db->simple_select("threads", "*", "poll='$pid'");
$thread = $db->fetch_array($query);
$tid = $thread['tid'];

 
	if(!$tid)
{
error($lang->error_invalidthread);
}


	$fid = $thread['fid'];

// Make navigation

	$fid = $thread['fid'];

// Make navigation

Zeile 312Zeile 324
	add_breadcrumb($lang->nav_editpoll);

$forumpermissions = forum_permissions($fid);

	add_breadcrumb($lang->nav_editpoll);

$forumpermissions = forum_permissions($fid);

	



	// Get forum info
$forum = get_forum($fid);
if(!$forum)

	// Get forum info
$forum = get_forum($fid);
if(!$forum)

Zeile 322Zeile 334
	else
{
// Is our forum closed?

	else
{
// Is our forum closed?

		if($forum['open'] == 0)

		if($forum['open'] == 0 && !is_moderator($fid, "caneditposts"))

		{
// Doesn't look like it is
error($lang->error_closedinvalidforum);
}
}


		{
// Doesn't look like it is
error($lang->error_closedinvalidforum);
}
}


	if(!$tid)
{
error($lang->error_invalidthread);
}


 
	if(!is_moderator($fid, "caneditposts"))
{
error_no_permission();

	if(!is_moderator($fid, "caneditposts"))
{
error_no_permission();

	}


	}


	$polldate = my_date($mybb->settings['dateformat'], $poll['dateline']);
if(!$mybb->input['preview'] && !$mybb->input['updateoptions'])
{
if($poll['closed'] == 1)
{
$postoptionschecked['closed'] = 'checked="checked"';

	$polldate = my_date($mybb->settings['dateformat'], $poll['dateline']);
if(!$mybb->input['preview'] && !$mybb->input['updateoptions'])
{
if($poll['closed'] == 1)
{
$postoptionschecked['closed'] = 'checked="checked"';

		}


		}


		if($poll['multiple'] == 1)
{
$postoptionschecked['multiple'] = 'checked="checked"';
}

		if($poll['multiple'] == 1)
{
$postoptionschecked['multiple'] = 'checked="checked"';
}

		



		if($poll['public'] == 1)

		if($poll['public'] == 1)

		{
$postoptionschecked['public'] = 'checked="checked"';
}


		{
$postoptionschecked['public'] = 'checked="checked"';
}


		$optionsarray = explode("||~|~||", $poll['options']);
$votesarray = explode("||~|~||", $poll['votes']);


		$optionsarray = explode("||~|~||", $poll['options']);
$votesarray = explode("||~|~||", $poll['votes']);


Zeile 365Zeile 372
		{
$poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1];
}

		{
$poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1];
}

		



		$question = htmlspecialchars_uni($poll['question']);
$numoptions = $poll['numoptions'];
$optionbits = "";
for($i = 0; $i < $numoptions; ++$i)

		$question = htmlspecialchars_uni($poll['question']);
$numoptions = $poll['numoptions'];
$optionbits = "";
for($i = 0; $i < $numoptions; ++$i)

		{

		{

			$counter = $i + 1;
$option = $optionsarray[$i];
$option = htmlspecialchars_uni($option);
$optionvotes = intval($votesarray[$i]);

			$counter = $i + 1;
$option = $optionsarray[$i];
$option = htmlspecialchars_uni($option);
$optionvotes = intval($votesarray[$i]);

			



			if(!$optionvotes)
{
$optionvotes = 0;
}

			if(!$optionvotes)
{
$optionvotes = 0;
}

			



			eval("\$optionbits .= \"".$templates->get("polls_editpoll_option")."\";");
$option = "";
$optionvotes = "";
}

			eval("\$optionbits .= \"".$templates->get("polls_editpoll_option")."\";");
$option = "";
$optionvotes = "";
}

		



		if(!$poll['timeout'])

		if(!$poll['timeout'])

		{

		{

			$timeout = 0;
}
else

			$timeout = 0;
}
else

Zeile 416Zeile 423
		{
$postoptionschecked['multiple'] = 'checked="checked"';
}

		{
$postoptionschecked['multiple'] = 'checked="checked"';
}

		



		if($postoptions['public'] == 1)
{
$postoptionschecked['public'] = 'checked="checked"';
}

		if($postoptions['public'] == 1)
{
$postoptionschecked['public'] = 'checked="checked"';
}

		



		if($postoptions['closed'] == 1)
{
$postoptionschecked['closed'] = 'checked="checked"';

		if($postoptions['closed'] == 1)
{
$postoptionschecked['closed'] = 'checked="checked"';

Zeile 436Zeile 443
			$option = $options[$i];
$option = htmlspecialchars_uni($option);
$optionvotes = $votes[$i];

			$option = $options[$i];
$option = htmlspecialchars_uni($option);
$optionvotes = $votes[$i];

			



			if(!$optionvotes)
{
$optionvotes = 0;
}

			if(!$optionvotes)
{
$optionvotes = 0;
}

			



			eval("\$optionbits .= \"".$templates->get("polls_editpoll_option")."\";");
$option = "";

			eval("\$optionbits .= \"".$templates->get("polls_editpoll_option")."\";");
$option = "";

		}

		}


if($mybb->input['timeout'] > 0)
{
$timeout = $mybb->input['timeout'];
}
else


if($mybb->input['timeout'] > 0)
{
$timeout = $mybb->input['timeout'];
}
else

		{

		{

			$timeout = 0;
}
}

			$timeout = 0;
}
}

Zeile 471Zeile 478

$query = $db->simple_select("polls", "*", "pid='".intval($mybb->input['pid'])."'");
$poll = $db->fetch_array($query);


$query = $db->simple_select("polls", "*", "pid='".intval($mybb->input['pid'])."'");
$poll = $db->fetch_array($query);

 

if(!$poll['pid'])
{
error($lang->error_invalidpoll);
}


$query = $db->simple_select("threads", "*", "poll='".intval($mybb->input['pid'])."'");
$thread = $db->fetch_array($query);


$query = $db->simple_select("threads", "*", "poll='".intval($mybb->input['pid'])."'");
$thread = $db->fetch_array($query);







	if(!$thread['tid'])
{
error($lang->error_invalidthread);
}


	$forumpermissions = forum_permissions($thread['fid']);

	$forumpermissions = forum_permissions($thread['fid']);

	



	// Get forum info
$forum = get_forum($thread['fid']);
if(!$forum)

	// Get forum info
$forum = get_forum($thread['fid']);
if(!$forum)

	{

	{

		error($lang->error_invalidforum);

		error($lang->error_invalidforum);

	}

	}

	else

	else

	{

	{

		// Is our forum closed?

		// Is our forum closed?

		if($forum['open'] == 0)

		if($forum['open'] == 0 && !is_moderator($fid, "caneditposts"))

		{
// Doesn't look like it is
error($lang->error_closedinvalidforum);
}

		{
// Doesn't look like it is
error($lang->error_closedinvalidforum);
}

	}

if($thread['visible'] == 0 || !$thread['tid'])
{
error($lang->error_invalidthread);
}


	}







	if(!is_moderator($thread['fid'], "caneditposts"))
{
error_no_permission();

	if(!is_moderator($thread['fid'], "caneditposts"))
{
error_no_permission();

Zeile 521Zeile 532
	{
$postoptions['multiple'] = 0;
}

	{
$postoptions['multiple'] = 0;
}

	



	if($postoptions['public'] != '1')
{
$postoptions['public'] = 0;
}

	if($postoptions['public'] != '1')
{
$postoptions['public'] = 0;
}

	



	if($postoptions['closed'] != '1')
{
$postoptions['closed'] = 0;

	if($postoptions['closed'] != '1')
{
$postoptions['closed'] = 0;

Zeile 539Zeile 550
		if(trim($options[$i]) != '')
{
$optioncount++;

		if(trim($options[$i]) != '')
{
$optioncount++;

		}

if(my_strlen($options[$i]) > $mybb->settings['polloptionlimit'] && $mybb->settings['polloptionlimit'] != 0)

		}

if(my_strlen($options[$i]) > $mybb->settings['polloptionlimit'] && $mybb->settings['polloptionlimit'] != 0)

		{
$lengtherror = 1;
break;
}
}

		{
$lengtherror = 1;
break;
}
}

	



	if($lengtherror)

	if($lengtherror)

	{

	{

		error($lang->error_polloptiontoolong);

		error($lang->error_polloptiontoolong);

	}

	}


if(trim($mybb->input['question']) == '' || $optioncount < 2)
{
error($lang->error_noquestionoptions);
}


if(trim($mybb->input['question']) == '' || $optioncount < 2)
{
error($lang->error_noquestionoptions);
}

	



	$optionslist = '';
$voteslist = '';
$numvotes = '';
$votes = $mybb->input['votes'];

	$optionslist = '';
$voteslist = '';
$numvotes = '';
$votes = $mybb->input['votes'];

	for($i = 1; $i <= $optioncount; ++$i)

	for($i = 1; $i <= $numoptions; ++$i)

	{
if(trim($options[$i]) != '')
{

	{
if(trim($options[$i]) != '')
{

			if($i > 1)

			if($optionslist != '')

			{
$optionslist .= "||~|~||";
$voteslist .= "||~|~||";
}

			{
$optionslist .= "||~|~||";
$voteslist .= "||~|~||";
}

			
$optionslist .= $options[$i];


$optionslist .= trim(utf8_handle_4byte_string($options[$i]));

			if(intval($votes[$i]) <= 0)
{
$votes[$i] = "0";

			if(intval($votes[$i]) <= 0)
{
$votes[$i] = "0";

Zeile 581Zeile 592
			$numvotes = $numvotes + $votes[$i];
}
}

			$numvotes = $numvotes + $votes[$i];
}
}

	



	if($mybb->input['timeout'] > 0)

	if($mybb->input['timeout'] > 0)

	{

	{

		$timeout = intval($mybb->input['timeout']);

		$timeout = intval($mybb->input['timeout']);

	}

	}

	else
{
$timeout = 0;
}

	else
{
$timeout = 0;
}

	




$mybb->input['question'] = utf8_handle_4byte_string($mybb->input['question']);


	$updatedpoll = array(
"question" => $db->escape_string($mybb->input['question']),
"options" => $db->escape_string($optionslist),
"votes" => $db->escape_string($voteslist),

	$updatedpoll = array(
"question" => $db->escape_string($mybb->input['question']),
"options" => $db->escape_string($optionslist),
"votes" => $db->escape_string($voteslist),

		"numoptions" => intval($numoptions),

		"numoptions" => intval($optioncount),

		"numvotes" => $numvotes,
"timeout" => $timeout,
"closed" => $postoptions['closed'],

		"numvotes" => $numvotes,
"timeout" => $timeout,
"closed" => $postoptions['closed'],

Zeile 608Zeile 621
	$db->update_query("polls", $updatedpoll, "pid='".intval($mybb->input['pid'])."'");

$plugins->run_hooks("polls_do_editpoll_end");

	$db->update_query("polls", $updatedpoll, "pid='".intval($mybb->input['pid'])."'");

$plugins->run_hooks("polls_do_editpoll_end");

	



	$modlogdata['fid'] = $thread['fid'];
$modlogdata['tid'] = $thread['tid'];
log_moderator_action($modlogdata, $lang->poll_edited);

	$modlogdata['fid'] = $thread['fid'];
$modlogdata['tid'] = $thread['tid'];
log_moderator_action($modlogdata, $lang->poll_edited);





	redirect(get_thread_link($thread['tid']), $lang->redirect_pollupdated);
}

	redirect(get_thread_link($thread['tid']), $lang->redirect_pollupdated);
}





if($mybb->input['action'] == "showresults")
{
$query = $db->simple_select("polls", "*", "pid='".intval($mybb->input['pid'])."'");
$poll = $db->fetch_array($query);

if($mybb->input['action'] == "showresults")
{
$query = $db->simple_select("polls", "*", "pid='".intval($mybb->input['pid'])."'");
$poll = $db->fetch_array($query);

 

if(!$poll['pid'])
{
error($lang->error_invalidpoll);
}


	$tid = $poll['tid'];
$query = $db->simple_select("threads", "*", "tid='$tid'");
$thread = $db->fetch_array($query);

	$tid = $poll['tid'];
$query = $db->simple_select("threads", "*", "tid='$tid'");
$thread = $db->fetch_array($query);

 
	if(!$thread['tid'])
{
error($lang->error_invalidthread);
}


	$fid = $thread['fid'];

// Get forum info

	$fid = $thread['fid'];

// Get forum info

Zeile 635Zeile 659
	$forumpermissions = forum_permissions($forum['fid']);

$plugins->run_hooks("polls_showresults_start");

	$forumpermissions = forum_permissions($forum['fid']);

$plugins->run_hooks("polls_showresults_start");


if($forumpermissions['canviewthreads'] == 0 || $forumpermissions['canview'] == 0)
{
error($lang->error_pollpermissions);
}

if(!$poll['pid'])
{
error($lang->error_invalidpoll);
}

if(!$thread['tid'])


if($forumpermissions['canviewthreads'] == 0 || $forumpermissions['canview'] == 0 || ($forumpermissions['canonlyviewownthreads'] != 0 && $thread['uid'] != $mybb->user['uid']))











	{

	{

		error($lang->error_invalidthread);

		error_no_permission();

	}

	}





	// Make navigation
build_forum_breadcrumb($fid);
add_breadcrumb(htmlspecialchars_uni($thread['subject']), get_thread_link($thread['tid']));
add_breadcrumb($lang->nav_pollresults);

	// Make navigation
build_forum_breadcrumb($fid);
add_breadcrumb(htmlspecialchars_uni($thread['subject']), get_thread_link($thread['tid']));
add_breadcrumb($lang->nav_pollresults);





	$voters = array();

// Calculate votes
$query = $db->query("

	$voters = array();

// Calculate votes
$query = $db->query("

		SELECT v.*, u.username 
FROM ".TABLE_PREFIX."pollvotes v
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=v.uid)
WHERE v.pid='{$poll['pid']}'

		SELECT v.*, u.username
FROM ".TABLE_PREFIX."pollvotes v
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=v.uid)
WHERE v.pid='{$poll['pid']}'

		ORDER BY u.username
");
while($voter = $db->fetch_array($query))

		ORDER BY u.username
");
while($voter = $db->fetch_array($query))

Zeile 672Zeile 686
		if($mybb->user['uid'] == $voter['uid'] && $mybb->user['uid'])
{
$votedfor[$voter['voteoption']] = 1;

		if($mybb->user['uid'] == $voter['uid'] && $mybb->user['uid'])
{
$votedfor[$voter['voteoption']] = 1;

		}


		}


		// Count number of guests and users without a username (assumes they've been deleted)
if($voter['uid'] == 0 || $voter['username'] == '')
{
// Add one to the number of voters for guests
++$guest_voters[$voter['voteoption']];

		// Count number of guests and users without a username (assumes they've been deleted)
if($voter['uid'] == 0 || $voter['username'] == '')
{
// Add one to the number of voters for guests
++$guest_voters[$voter['voteoption']];

		}

		}

		else
{
$voters[$voter['voteoption']][$voter['uid']] = $voter['username'];
}
}

		else
{
$voters[$voter['voteoption']][$voter['uid']] = $voter['username'];
}
}

	



	$optionsarray = explode("||~|~||", $poll['options']);
$votesarray = explode("||~|~||", $poll['votes']);

	$optionsarray = explode("||~|~||", $poll['options']);
$votesarray = explode("||~|~||", $poll['votes']);

	for($i = 1; $i <= $poll['numoptions']; ++$i)
{

	for($i = 1; $i <= $poll['numoptions']; ++$i)
{

		$poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1];
}

		$poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1];
}

	



	$polloptions = '';
for($i = 1; $i <= $poll['numoptions']; ++$i)
{

	$polloptions = '';
for($i = 1; $i <= $poll['numoptions']; ++$i)
{

Zeile 719Zeile 733
			$optionbg = 'trow1';
$votestar = '';
}

			$optionbg = 'trow1';
$votestar = '';
}

		



		if($votes == '0')
{
$percent = '0';

		if($votes == '0')
{
$percent = '0';

Zeile 728Zeile 742
		{
$percent = number_format($votes / $poll['totvotes'] * 100, 2);
}

		{
$percent = number_format($votes / $poll['totvotes'] * 100, 2);
}

		



		$imagewidth = round($percent/3) * 5;
$comma = '';
$guest_comma = '';

		$imagewidth = round($percent/3) * 5;
$comma = '';
$guest_comma = '';

Zeile 759Zeile 773
		}
eval("\$polloptions .= \"".$templates->get("polls_showresults_resultbit")."\";");
}

		}
eval("\$polloptions .= \"".$templates->get("polls_showresults_resultbit")."\";");
}

	



	if($poll['totvotes'])
{
$totpercent = '100%';
}
else

	if($poll['totvotes'])
{
$totpercent = '100%';
}
else

	{

	{

		$totpercent = '0%';
}

$plugins->run_hooks("polls_showresults_end");

		$totpercent = '0%';
}

$plugins->run_hooks("polls_showresults_end");





	$poll['question'] = htmlspecialchars_uni($poll['question']);
eval("\$showresults = \"".$templates->get("polls_showresults")."\";");
output_page($showresults);

	$poll['question'] = htmlspecialchars_uni($poll['question']);
eval("\$showresults = \"".$templates->get("polls_showresults")."\";");
output_page($showresults);

Zeile 779Zeile 793
{
// Verify incoming POST request
verify_post_check($mybb->input['my_post_key']);

{
// Verify incoming POST request
verify_post_check($mybb->input['my_post_key']);

	



	$query = $db->simple_select("polls", "*", "pid='".intval($mybb->input['pid'])."'");
$poll = $db->fetch_array($query);
$poll['timeout'] = $poll['timeout']*60*60*24;

	$query = $db->simple_select("polls", "*", "pid='".intval($mybb->input['pid'])."'");
$poll = $db->fetch_array($query);
$poll['timeout'] = $poll['timeout']*60*60*24;

Zeile 792Zeile 806
	}

$query = $db->simple_select("threads", "*", "poll='".$poll['pid']."'");

	}

$query = $db->simple_select("threads", "*", "poll='".$poll['pid']."'");

	$thread = $db->fetch_array($query);

if(!$thread['tid'])

	$thread = $db->fetch_array($query);

if(!$thread['tid'] || $thread['visible'] == 0)

	{
error($lang->error_invalidthread);
}

	{
error($lang->error_invalidthread);
}

	



	$fid = $thread['fid'];
$forumpermissions = forum_permissions($fid);
if($forumpermissions['canvotepolls'] == 0)
{
error_no_permission();
}

	$fid = $thread['fid'];
$forumpermissions = forum_permissions($fid);
if($forumpermissions['canvotepolls'] == 0)
{
error_no_permission();
}

	



	// Get forum info
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);

	// Get forum info
$forum = get_forum($fid);
if(!$forum)
{
error($lang->error_invalidforum);

	}

	}

	else
{
// Is our forum closed?

	else
{
// Is our forum closed?

Zeile 819Zeile 833
		{
// Doesn't look like it is
error($lang->error_closedinvalidforum);

		{
// Doesn't look like it is
error($lang->error_closedinvalidforum);

		}

		}

	}

$expiretime = $poll['dateline'] + $poll['timeout'];

	}

$expiretime = $poll['dateline'] + $poll['timeout'];

Zeile 828Zeile 842
	{
error($lang->error_pollclosed);
}

	{
error($lang->error_pollclosed);
}

	



	if(!isset($mybb->input['option']))
{
error($lang->error_nopolloptions);
}

	if(!isset($mybb->input['option']))
{
error($lang->error_nopolloptions);
}

	



	// Check if the user has voted before...
if($mybb->user['uid'])

	// Check if the user has voted before...
if($mybb->user['uid'])

	{

	{

		$query = $db->simple_select("pollvotes", "*", "uid='".$mybb->user['uid']."' AND pid='".$poll['pid']."'");
$votecheck = $db->fetch_array($query);
}

		$query = $db->simple_select("pollvotes", "*", "uid='".$mybb->user['uid']."' AND pid='".$poll['pid']."'");
$votecheck = $db->fetch_array($query);
}

	



	if($votecheck['vid'] || (isset($mybb->cookies['pollvotes'][$poll['pid']]) && $mybb->cookies['pollvotes'][$poll['pid']] !== ""))
{
error($lang->error_alreadyvoted);

	if($votecheck['vid'] || (isset($mybb->cookies['pollvotes'][$poll['pid']]) && $mybb->cookies['pollvotes'][$poll['pid']] !== ""))
{
error($lang->error_alreadyvoted);

	}

	}

	elseif(!$mybb->user['uid'])
{
// Give a cookie to guests to inhibit revotes

	elseif(!$mybb->user['uid'])
{
// Give a cookie to guests to inhibit revotes

Zeile 852Zeile 866
		{
// We have multiple options here...
$votes_cookie = implode(',', array_keys($mybb->input['option']));

		{
// We have multiple options here...
$votes_cookie = implode(',', array_keys($mybb->input['option']));

		}

		}

		else
{
$votes_cookie = $mybb->input['option'];
}

		else
{
$votes_cookie = $mybb->input['option'];
}





		my_setcookie("pollvotes[{$poll['pid']}]", $votes_cookie);
}

		my_setcookie("pollvotes[{$poll['pid']}]", $votes_cookie);
}

	



	$votesql = '';
$now = TIME_NOW;
$votesarray = explode("||~|~||", $poll['votes']);
$option = $mybb->input['option'];

	$votesql = '';
$now = TIME_NOW;
$votesarray = explode("||~|~||", $poll['votes']);
$option = $mybb->input['option'];

	$numvotes = $poll['numvotes'];

	$numvotes = (int)$poll['numvotes'];

	if($poll['multiple'] == 1)
{
if(is_array($option))

	if($poll['multiple'] == 1)
{
if(is_array($option))

Zeile 902Zeile 916
	}

$db->write_query("

	}

$db->write_query("

		INSERT INTO 
".TABLE_PREFIX."pollvotes (pid,uid,voteoption,dateline)

		INSERT INTO
".TABLE_PREFIX."pollvotes (pid,uid,voteoption,dateline)

		VALUES $votesql
");
$voteslist = '';

		VALUES $votesql
");
$voteslist = '';

Zeile 932Zeile 946
if($mybb->input['action'] == "do_undovote")
{
verify_post_check($mybb->input['my_post_key']);

if($mybb->input['action'] == "do_undovote")
{
verify_post_check($mybb->input['my_post_key']);

	



	$plugins->run_hooks("polls_do_undovote_start");
if($mybb->usergroup['canundovotes'] != 1)

	$plugins->run_hooks("polls_do_undovote_start");
if($mybb->usergroup['canundovotes'] != 1)

	{

	{

		error_no_permission();

		error_no_permission();

	}


	}


	$query = $db->simple_select("polls", "*", "pid='".intval($mybb->input['pid'])."'");
$poll = $db->fetch_array($query);

	$query = $db->simple_select("polls", "*", "pid='".intval($mybb->input['pid'])."'");
$poll = $db->fetch_array($query);

	


	$poll['numvotes'] = (int)$poll['numvotes'];


	if(!$poll['pid'])
{
error($lang->error_invalidpoll);
}

	if(!$poll['pid'])
{
error($lang->error_invalidpoll);
}

	



	// We do not have $forum_cache available here since no forums permissions are checked in undo vote
// Get thread ID and then get forum info
$query = $db->simple_select("threads", "*", "tid='".intval($poll['tid'])."'");
$thread = $db->fetch_array($query);

	// We do not have $forum_cache available here since no forums permissions are checked in undo vote
// Get thread ID and then get forum info
$query = $db->simple_select("threads", "*", "tid='".intval($poll['tid'])."'");
$thread = $db->fetch_array($query);

 
	if(!$thread['tid'] || $thread['visible'] == 0)
{
error($lang->error_invalidthread);
}


	$fid = $thread['fid'];

	$fid = $thread['fid'];

	



	// Get forum info
$forum = get_forum($fid);
if(!$forum)

	// Get forum info
$forum = get_forum($fid);
if(!$forum)

Zeile 968Zeile 988
			error($lang->error_closedinvalidforum);
}
}

			error($lang->error_closedinvalidforum);
}
}

	



	$poll['timeout'] = $poll['timeout']*60*60*24;

	$poll['timeout'] = $poll['timeout']*60*60*24;

	




$expiretime = $poll['dateline'] + $poll['timeout'];
if($poll['closed'] == 1 || $thread['closed'] == 1 || ($expiretime < TIME_NOW && $poll['timeout']))
{
error($lang->error_pollclosed);


$expiretime = $poll['dateline'] + $poll['timeout'];
if($poll['closed'] == 1 || $thread['closed'] == 1 || ($expiretime < TIME_NOW && $poll['timeout']))
{
error($lang->error_pollclosed);

	}


	}


	// Check if the user has voted before...
$vote_options = array();
if($mybb->user['uid'])

	// Check if the user has voted before...
$vote_options = array();
if($mybb->user['uid'])

Zeile 986Zeile 1006
		while($voteoption = $db->fetch_array($query))
{
$vote_options[$voteoption['vid']] = $voteoption['voteoption'];

		while($voteoption = $db->fetch_array($query))
{
$vote_options[$voteoption['vid']] = $voteoption['voteoption'];

		}
}
else
{

		}
}
else
{

		// for Guests, we simply see if they've got the cookie
$vote_options = explode(',', $mybb->cookies['pollvotes'][$poll['pid']]);

		// for Guests, we simply see if they've got the cookie
$vote_options = explode(',', $mybb->cookies['pollvotes'][$poll['pid']]);

	}

	}

	$votecheck = !empty($vote_options);

	$votecheck = !empty($vote_options);

	



	if(!$votecheck)

	if(!$votecheck)

	{

	{

		error($lang->error_notvoted);

		error($lang->error_notvoted);

	}

	}

	else if(!$mybb->user['uid'])
{
// clear cookie for Guests
my_setcookie("pollvotes[{$poll['pid']}]", "");

	else if(!$mybb->user['uid'])
{
// clear cookie for Guests
my_setcookie("pollvotes[{$poll['pid']}]", "");

	}	


	}


	// Note, this is not thread safe!
$votesarray = explode("||~|~||", $poll['votes']);
if(count($votesarray) > $poll['numoptions'])
{
$votesarray = array_slice(0, $poll['numoptions']);
}

	// Note, this is not thread safe!
$votesarray = explode("||~|~||", $poll['votes']);
if(count($votesarray) > $poll['numoptions'])
{
$votesarray = array_slice(0, $poll['numoptions']);
}

	



	if($poll['multiple'] == 1)
{
foreach($vote_options as $vote)

	if($poll['multiple'] == 1)
{
foreach($vote_options as $vote)

Zeile 1030Zeile 1050
		{
--$votesarray[$voteoption-1];
--$poll['numvotes'];

		{
--$votesarray[$voteoption-1];
--$poll['numvotes'];

		}
}


		}
}


	// check if anything < 0 - possible if Guest vote undoing is allowed (generally Guest unvoting should be disabled >_>)
if($poll['numvotes'] < 0)

	// check if anything < 0 - possible if Guest vote undoing is allowed (generally Guest unvoting should be disabled >_>)
if($poll['numvotes'] < 0)

	{

	{

		$poll['numvotes'] = 0;

		$poll['numvotes'] = 0;

	}


	}


	foreach($votesarray as $i => $votes)
{
if($votes < 0)

	foreach($votesarray as $i => $votes)
{
if($votes < 0)

Zeile 1046Zeile 1066
			$votesarray[$i] = 0;
}
}

			$votesarray[$i] = 0;
}
}

	



	$voteslist = implode("||~|~||", $votesarray);
$updatedpoll = array(
"votes" => $db->escape_string($voteslist),

	$voteslist = implode("||~|~||", $votesarray);
$updatedpoll = array(
"votes" => $db->escape_string($voteslist),