Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: larik000 on March 04, 2008, 10:05:03 AM

Title: Voting the guests
Post by: larik000 on March 04, 2008, 10:05:03 AM
That possible to do to possible was participate in questioning guest. I so has understood that on most forum this function beside guests inaccessible. Can it is necessary somehow to change the code or already there is lifelengths?
Title: Re: Voting the guests
Post by: capabmx on March 04, 2008, 10:13:28 AM
Go to Admin > Permissions > Guests - Modify > View Polls, I believe.
Title: Re: Voting the guests
Post by: larik000 on March 05, 2008, 01:36:40 AM
This does not approach. This gives him possibility to examine questioning, rather then vote in him. Beside guests no in rights of the point of the possibility to vote, as beside the other groups.
Title: Re: Voting the guests
Post by: capabmx on March 05, 2008, 07:07:32 AM
Try Checking off the permission to post polls, that should give them the right to vote in them, and as long as you don't check off add polls to topics, or something I don't think you'll have to worry about them making their own polls.
Title: Re: Voting the guests
Post by: codenaught on March 05, 2008, 08:25:04 AM
Guests cannot vote in polls in SMF 1.1. However as a new feature in 2.0, it is possible to allow them to in SMF 2.0 (which has not been released to the public yet).
Title: Re: Voting the guests
Post by: capabmx on March 05, 2008, 08:27:41 AM
@ akabugeyes,
hmmm, I guess my question is if I wanted to allow them to, where should I start looking, such as to start editing files hehe. I'll look into it later, I need some experience :].
Title: Re: Voting the guests
Post by: larik000 on March 10, 2008, 09:34:59 AM
I so understand this function to have charge of voting only users. From file Poll.php



function Vote()
{
global $topic, $txt, $db_prefix, $ID_MEMBER, $user_info;

// Make sure you can vote.
isAllowedTo('poll_vote');

// Even with poll_vote permission we would never be able to register you.
if ($user_info['is_guest'])
fatal_lang_error('cannot_poll_vote'); 

loadLanguage('Post');

// Check if they have already voted, or voting is locked.
$request = db_query("
SELECT IFNULL(lp.ID_CHOICE, -1) AS selected, p.votingLocked, p.ID_POLL, p.expireTime, p.maxVotes, p.changeVote
FROM ({$db_prefix}polls AS p, {$db_prefix}topics AS t)
LEFT JOIN {$db_prefix}log_polls AS lp ON (p.ID_POLL = lp.ID_POLL AND lp.ID_MEMBER = $ID_MEMBER)
WHERE p.ID_POLL = t.ID_POLL
AND t.ID_TOPIC = $topic
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) == 0)
fatal_lang_error('smf27', false);
$row = mysql_fetch_assoc($request);
mysql_free_result($request);                   


// Is voting locked or has it expired?
if (!empty($row['votingLocked']) || (!empty($row['expireTime']) && time() > $row['expireTime']))
fatal_lang_error('smf27', false);

// If they have already voted and aren't allowed to change their vote - hence they are outta here!
if ($row['selected'] != -1 && empty($row['changeVote']))
fatal_lang_error('smf27', false);
// Otherwise if they can change their vote yet they haven't sent any options... remove their vote and redirect.
elseif (!empty($row['changeVote']))
{
$pollOptions = array();                 

// Find out what they voted for before.
$request = db_query("
SELECT ID_CHOICE
FROM {$db_prefix}log_polls
WHERE ID_MEMBER = $ID_MEMBER
AND ID_POLL = $row[ID_POLL]", __FILE__, __LINE__);
while ($choice = mysql_fetch_row($request))
$pollOptions[] = $choice[0];
mysql_free_result($request);

// Just skip it if they had voted for nothing before.
if (!empty($pollOptions))
{
// Update the poll totals.
db_query("
UPDATE {$db_prefix}poll_choices
SET votes = votes - 1
WHERE ID_POLL = $row[ID_POLL]
AND ID_CHOICE IN (" . implode(', ', $pollOptions) . ")
AND votes > 0
LIMIT " . count($pollOptions), __FILE__, __LINE__);

// Delete off the log.
db_query("
DELETE FROM {$db_prefix}log_polls
WHERE ID_MEMBER = $ID_MEMBER
AND ID_POLL = $row[ID_POLL]", __FILE__, __LINE__);
}

// Redirect back to the topic so the user can vote again!
if (empty($_POST['options']))
redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
}

// Make sure the option(s) are valid.
if (empty($_POST['options']))
fatal_lang_error('smf26', false);

// Too many options checked!
if (count($_REQUEST['options']) > $row['maxVotes'])
fatal_lang_error('poll_error1', false, array($row['maxVotes']));

$pollOptions = array();
$setString = '';
foreach ($_REQUEST['options'] as $id)
{
$id = (int) $id;

$pollOptions[] = $id;
$setString .= "
($row[ID_POLL], $ID_MEMBER, $id),";
}
$setString = substr($setString, 0, -1);

// Add their vote to the tally.
db_query("
INSERT IGNORE INTO {$db_prefix}log_polls
(ID_POLL, ID_MEMBER, ID_CHOICE)
VALUES $setString", __FILE__, __LINE__);   
if (db_affected_rows() != 0)
db_query("
UPDATE {$db_prefix}poll_choices
SET votes = votes + 1
WHERE ID_POLL = $row[ID_POLL]
AND ID_CHOICE IN (" . implode(', ', $pollOptions) . ")
LIMIT " . count($pollOptions), __FILE__, __LINE__);

// Return to the post...
redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
}



You will Not prompt that here possible to take away to remove this restriction. To beside guests too was a possibility to vote.