Location: PHPKode > projects > Bugdar > upload/vote.php
<?php
/*=====================================================================*\
|| ###################################################################
|| # Bugdar
|| # Copyright ©2002-2007 Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
|| # the Free Software Foundation; version 2 of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/

define('SVN', '$Id$');

$focus['showreport'] = 'focus';

require_once('./global.php');

// ###################################################################

if (empty($_REQUEST['do']))
{
	$message->error(L_INVALID_ID);
}

// ###################################################################

if ($_REQUEST['do'] == 'vote')
{
	$bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $bugsys->input_clean('bugid', TYPE_UINT));
	$vote =  $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
	
	if (!check_bug_permissions($bug))
	{
		$message->errorPermission();
	}
	
	if (!can_perform('canvote', $bug['product']))
	{
		$message->errorPermission();
	}
	
	if (!$bug)
	{
		$message->error(L_INVALID_ID);
	}
	
	if ($vote['uservote'])
	{
		$message->error(T('You have already voted on this bug.'));
	}
	
	// handle userids
	$userids = $vote['userids'];
	if ($bugsys->userinfo['userid'])
	{
		if (trim($vote['userids']))
		{
			$userids .= ',' . $bugsys->userinfo['userid'];
		}
		else
		{
			$userids = $bugsys->userinfo['userid'];
		}
	}
	
	$uservote = $bugsys->input_clean('vote', TYPE_INT);
	
	$votefor = $vote['votefor'];
	$voteagainst = $vote['voteagainst'];
	
	if ($uservote > 0)
	{
		$votefor++;
	}
	else if ($uservote < 0)
	{
		$voteagainst++;
	}
	else
	{
		$message->error(T('You need to specify whether you want to vote for or against this bug.'));
	}
	
	$db->query("UPDATE " . TABLE_PREFIX . "vote SET userids = '$userids', votefor = $votefor, voteagainst = $voteagainst WHERE bugid = $bug[bugid]");

	$message->redirect(T('Your vote has been added.'), "showreport.php?bugid=$bug[bugid]");
}

/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>
Return current item: Bugdar