Fix voting(again) by changing all variables to use the new naming scheme

This commit is contained in:
Chris Morgan
2006-07-19 00:11:40 +00:00
committed by WineHQ
parent 71f963b04c
commit 2ef31edf05

View File

@@ -7,18 +7,18 @@ define('MAX_VOTES',3);
/** /**
* count the number of votes for appId by userId * count the number of votes for appId by userId
*/ */
function vote_count($appId, $userId = null) function vote_count($iAppId, $iUserId = null)
{ {
if(!$userId) if(!$iUserId)
{ {
if($_SESSION['current']->isLoggedIn()) if($_SESSION['current']->isLoggedIn())
$userId = $_SESSION['current']->iUserId; $iUserId = $_SESSION['current']->iUserId;
else else
return 0; return 0;
} }
$hResult = query_parameters("SELECT * FROM appVotes WHERE appId = '?' AND userId = '?'", $hResult = query_parameters("SELECT * FROM appVotes WHERE appId = '?' AND userId = '?'",
$appId, $userId); $iAppId, $iUserId);
return mysql_num_rows($hResult); return mysql_num_rows($hResult);
} }
@@ -26,16 +26,16 @@ function vote_count($appId, $userId = null)
/** /**
* total votes by userId * total votes by userId
*/ */
function vote_count_user_total($userId = null) function vote_count_user_total($iUserId = null)
{ {
if(!$userId) if(!$iUserId)
{ {
if($_SESSION['current']->isLoggedIn()) if($_SESSION['current']->isLoggedIn())
$userId = $_SESSION['current']->iUserId; $iUserId = $_SESSION['current']->iUserId;
else else
return 0; return 0;
} }
$hResult = query_parameters("SELECT * FROM appVotes WHERE userId = '?'", $userId); $hResult = query_parameters("SELECT * FROM appVotes WHERE userId = '?'", $iUserId);
return mysql_num_rows($hResult); return mysql_num_rows($hResult);
} }
@@ -43,9 +43,9 @@ function vote_count_user_total($userId = null)
/* /*
* total votes for appId * total votes for appId
*/ */
function vote_count_app_total($appId) function vote_count_app_total($iAppId)
{ {
$hResult = query_parameters("SELECT * FROM appVotes WHERE appId = '?'", $appId); $hResult = query_parameters("SELECT * FROM appVotes WHERE appId = '?'", $iAppId);
return mysql_num_rows($hResult); return mysql_num_rows($hResult);
} }
@@ -53,55 +53,55 @@ function vote_count_app_total($appId)
/** /**
* add a vote for appId * add a vote for appId
*/ */
function vote_add($appId, $slot, $userId = null) function vote_add($iAppId, $iSlot, $iUserId = null)
{ {
if(!$userId) if(!$iUserId)
{ {
if($_SESSION['current']->isLoggedIn()) if($_SESSION['current']->isLoggedIn())
$userId = $_SESSION['current']->iUserId; $iUserId = $_SESSION['current']->iUserId;
else else
return; return;
} }
if($slot > MAX_VOTES) if($iSlot > MAX_VOTES)
return; return;
vote_remove($slot, $userId); vote_remove($iSlot, $iUserId);
query_parameters("INSERT INTO appVotes (id, time, appId, userId, slot) query_parameters("INSERT INTO appVotes (id, time, appId, userId, slot)
VALUES (?, ?, '?', '?', '?')", "null", "null", $appId, $userId, $slot); VALUES (?, ?, '?', '?', '?')", "null", "null", $iAppId, $iUserId, $iSlot);
} }
/** /**
* remove vote for a slot * remove vote for a slot
*/ */
function vote_remove($slot, $userId = null) function vote_remove($iSlot, $iUserId = null)
{ {
if(!$userId) if(!$iUserId)
{ {
if($_SESSION['current']->isLoggedIn()) if($_SESSION['current']->isLoggedIn())
$userId = $_SESSION['current']->iUserId; $iUserId = $_SESSION['current']->iUserId;
else else
return; return;
} }
$sQuery = "DELETE FROM appVotes WHERE userId = '?' AND slot = '?'"; $sQuery = "DELETE FROM appVotes WHERE userId = '?' AND slot = '?'";
query_parameters($sQuery, $userId, $slot); query_parameters($sQuery, $iUserId, $iSlot);
} }
function vote_get_user_votes($userId = null) function vote_get_user_votes($iUserId = null)
{ {
if(!$userId) if(!$iUserId)
{ {
if($_SESSION['current']->isLoggedIn()) if($_SESSION['current']->isLoggedIn())
$userId = $_SESSION['current']->iUserId; $iUserId = $_SESSION['current']->iUserId;
if(!$userId) if(!$iUserId)
return array(); return array();
} }
$hResult = query_parameters("SELECT * FROM appVotes WHERE userId = '?'", $userId); $hResult = query_parameters("SELECT * FROM appVotes WHERE userId = '?'", $iUserId);
if(!$hResult) if(!$hResult)
return array(); return array();
@@ -128,7 +128,7 @@ function vote_menu()
{ {
$sAppName = Application::lookup_name($votes[$i]->appId); $sAppName = Application::lookup_name($votes[$i]->appId);
$str = "<a href='appview.php?iAppId=".$votes[$i]->appId."'> $sAppName</a>"; $str = "<a href='appview.php?iAppId=".$votes[$i]->appId."'> $sAppName</a>";
$m->add("<input type=radio name=slot value='$i'> ".$str); $m->add("<input type=radio name=iSlot value='$i'> ".$str);
} }
else else
$m->add("<input type=radio name=iSlot value='$i'> No App Selected"); $m->add("<input type=radio name=iSlot value='$i'> No App Selected");
@@ -156,7 +156,7 @@ function vote_update($vars)
if( !is_numeric($vars['iAppId']) OR !is_numeric($vars['iSlot'])) if( !is_numeric($vars['iAppId']) OR !is_numeric($vars['iSlot']))
{ {
if(is_numeric($vars['iAppId'])) if(is_numeric($vars['iAppId']))
util_redirect_and_exit(apidb_fullurl("appview.php?iAppId=".$vars["iAppId"])); util_redirect_and_exit(apidb_fullurl("appview.php?iAppId=".$vars['iAppId']));
else else
util_redirect_and_exit(apidb_fullurl("index.php")); util_redirect_and_exit(apidb_fullurl("index.php"));
@@ -165,37 +165,37 @@ function vote_update($vars)
if($vars["sVote"]) if($vars["sVote"])
{ {
addmsg("Registered vote for App #".$vars["iAppId"], "green"); addmsg("Registered vote for App #".$vars['iAppId'], "green");
vote_add($vars["iAppId"], $vars["slot"]); vote_add($vars['iAppId'], $vars['iSlot']);
} else if($vars["sClear"]) } else if($vars['sClear'])
{ {
/* see if we have a vote in this slot, if we don't there is */ /* see if we have a vote in this slot, if we don't there is */
/* little reason to remove it or even mention that we did anything */ /* little reason to remove it or even mention that we did anything */
if(is_vote_in_slot($vars["slot"])) if(is_vote_in_slot($vars['iSlot']))
{ {
vote_remove($vars["slot"]); vote_remove($vars['iSlot']);
addmsg("Removed vote for App #".$vars["iAppId"], "green"); addmsg("Removed vote for App #".$vars['iAppId'], "green");
} }
} }
util_redirect_and_exit(apidb_fullurl("appview.php?iAppId=".$vars["iAppId"])); util_redirect_and_exit(apidb_fullurl("appview.php?iAppId=".$vars['iAppId']));
} }
// tell us if there is a vote in a given slot so we don't // tell us if there is a vote in a given slot so we don't
// display incorrect information to the user or go // display incorrect information to the user or go
// through the trouble of trying to remove a vote that doesn't exist // through the trouble of trying to remove a vote that doesn't exist
function is_vote_in_slot($slot, $userId = null) function is_vote_in_slot($iSlot, $iUserId = null)
{ {
if(!$userId) if(!$iUserId)
{ {
if($_SESSION['current']->isLoggedIn()) if($_SESSION['current']->isLoggedIn())
$userId = $_SESSION['current']->iUserId; $iUserId = $_SESSION['current']->iUserId;
else else
return; return;
} }
$sQuery = "SELECT COUNT(*) as count from appVotes WHERE userId = '?' AND slot = '?'"; $sQuery = "SELECT COUNT(*) as count from appVotes WHERE userId = '?' AND slot = '?'";
if($hResult = query_parameters($sQuery, $userId, $slot)) if($hResult = query_parameters($sQuery, $iUserId, $iSlot))
{ {
$oRow = mysql_fetch_object($hResult); $oRow = mysql_fetch_object($hResult);
if($oRow->count != 0) if($oRow->count != 0)