2004-12-12 03:51:51 +00:00
|
|
|
<?php
|
2006-06-17 06:10:10 +00:00
|
|
|
require_once(BASE."include/util.php");
|
2004-12-28 00:01:21 +00:00
|
|
|
/* max votes per user */
|
|
|
|
|
define('MAX_VOTES',3);
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* count the number of votes for appId by userId
|
|
|
|
|
*/
|
|
|
|
|
function vote_count($appId, $userId = null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(!$userId)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
if($_SESSION['current']->isLoggedIn())
|
|
|
|
|
$userId = $_SESSION['current']->iUserId;
|
2004-12-12 03:51:51 +00:00
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2006-06-27 19:16:27 +00:00
|
|
|
$hResult = query_parameters("SELECT * FROM appVotes WHERE appId = '?' AND userId = '?'",
|
|
|
|
|
$appId, $userId);
|
2006-06-21 01:04:12 +00:00
|
|
|
return mysql_num_rows($hResult);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
|
|
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* total votes by userId
|
|
|
|
|
*/
|
|
|
|
|
function vote_count_user_total($userId = null)
|
|
|
|
|
{
|
|
|
|
|
if(!$userId)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
if($_SESSION['current']->isLoggedIn())
|
|
|
|
|
$userId = $_SESSION['current']->iUserId;
|
2004-12-12 03:51:51 +00:00
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2006-06-27 19:16:27 +00:00
|
|
|
$hResult = query_parameters("SELECT * FROM appVotes WHERE userId = '?'", $userId);
|
2006-06-21 01:04:12 +00:00
|
|
|
return mysql_num_rows($hResult);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
/*
|
|
|
|
|
* total votes for appId
|
|
|
|
|
*/
|
|
|
|
|
function vote_count_app_total($appId)
|
|
|
|
|
{
|
2006-06-27 19:16:27 +00:00
|
|
|
$hResult = query_parameters("SELECT * FROM appVotes WHERE appId = '?'", $appId);
|
2006-06-21 01:04:12 +00:00
|
|
|
return mysql_num_rows($hResult);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-03-15 16:22:00 +00:00
|
|
|
* add a vote for appId
|
|
|
|
|
*/
|
|
|
|
|
function vote_add($appId, $slot, $userId = null)
|
|
|
|
|
{
|
|
|
|
|
if(!$userId)
|
2005-05-11 03:08:07 +00:00
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
if($_SESSION['current']->isLoggedIn())
|
|
|
|
|
$userId = $_SESSION['current']->iUserId;
|
2005-05-11 03:08:07 +00:00
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-12-28 00:01:21 +00:00
|
|
|
if($slot > MAX_VOTES)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
vote_remove($slot, $userId);
|
2006-06-24 04:20:32 +00:00
|
|
|
|
|
|
|
|
query_parameters("INSERT INTO appVotes (id, time, appId, userId, slot)
|
|
|
|
|
VALUES (?, ?, '?', '?', '?')", "null", "null", $appId, $userId, $slot);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
/**
|
2004-12-28 00:01:21 +00:00
|
|
|
* remove vote for a slot
|
2004-03-15 16:22:00 +00:00
|
|
|
*/
|
2004-12-28 00:01:21 +00:00
|
|
|
function vote_remove($slot, $userId = null)
|
2004-03-15 16:22:00 +00:00
|
|
|
{
|
2004-12-10 01:07:45 +00:00
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
if(!$userId)
|
2005-05-11 03:08:07 +00:00
|
|
|
{
|
|
|
|
|
if($_SESSION['current']->isLoggedIn())
|
|
|
|
|
$userId = $_SESSION['current']->iUserId;
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-27 19:16:27 +00:00
|
|
|
$sQuery = "DELETE FROM appVotes WHERE userId = '?' AND slot = '?'";
|
|
|
|
|
query_parameters($sQuery, $userId, $slot);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
function vote_get_user_votes($userId = null)
|
|
|
|
|
{
|
|
|
|
|
if(!$userId)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
if($_SESSION['current']->isLoggedIn())
|
|
|
|
|
$userId = $_SESSION['current']->iUserId;
|
2004-12-12 03:51:51 +00:00
|
|
|
if(!$userId)
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2006-06-27 19:16:27 +00:00
|
|
|
$hResult = query_parameters("SELECT * FROM appVotes WHERE userId = '?'", $userId);
|
2006-06-21 01:04:12 +00:00
|
|
|
if(!$hResult)
|
2004-12-12 03:51:51 +00:00
|
|
|
return array();
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
$obs = array();
|
2006-06-21 01:04:12 +00:00
|
|
|
while($oRow = mysql_fetch_object($hResult))
|
|
|
|
|
$obs[$oRow->slot] = $oRow;
|
2004-03-15 16:22:00 +00:00
|
|
|
return $obs;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-12 03:51:51 +00:00
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
function vote_menu()
|
|
|
|
|
{
|
2006-06-17 06:10:10 +00:00
|
|
|
|
|
|
|
|
$aClean = array(); //array of filtered user input
|
2006-07-06 17:27:54 +00:00
|
|
|
$aClean['iAppId'] = makeSafe($_REQUEST['iAppId']);
|
2006-06-17 06:10:10 +00:00
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
$m = new htmlmenu("Votes","updatevote.php");
|
|
|
|
|
|
|
|
|
|
$votes = vote_get_user_votes();
|
|
|
|
|
|
2004-12-27 23:59:30 +00:00
|
|
|
for($i = 1;$i <= MAX_VOTES; $i++)
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2004-12-27 23:59:30 +00:00
|
|
|
if(isset($votes[$i]))
|
|
|
|
|
{
|
2006-06-29 16:07:19 +00:00
|
|
|
$sAppName = Application::lookup_name($votes[$i]->appId);
|
2006-07-06 17:27:54 +00:00
|
|
|
$str = "<a href='appview.php?iAppId=".$votes[$i]->appId."'> $sAppName</a>";
|
2004-12-27 23:59:30 +00:00
|
|
|
$m->add("<input type=radio name=slot value='$i'> ".$str);
|
|
|
|
|
}
|
|
|
|
|
else
|
2006-07-06 17:27:54 +00:00
|
|
|
$m->add("<input type=radio name=iSlot value='$i'> No App Selected");
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
$m->addmisc(" ");
|
|
|
|
|
|
2006-07-06 17:27:54 +00:00
|
|
|
$m->add("<input type=submit name=sClear value=' Clear Vote ' class=votebutton>");
|
|
|
|
|
$m->add("<input type=submit name=sVote value='Vote for App' class=votebutton>");
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2006-07-06 17:27:54 +00:00
|
|
|
$m->addmisc("<input type=hidden name=iAppId value={$aClean['iAppId']}>");
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-12-23 01:12:03 +00:00
|
|
|
$m->add("View Results", BASE."votestats.php");
|
2006-07-06 17:27:54 +00:00
|
|
|
$m->add("Voting Help", BASE."help/?sTopic=voting");
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
$m->done(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function vote_update($vars)
|
|
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
if(!$_SESSION['current']->isLoggedIn())
|
2006-07-06 18:44:56 +00:00
|
|
|
util_show_error_page_and_exit("You must be logged in to vote");
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2006-07-06 17:27:54 +00:00
|
|
|
if( !is_numeric($vars['iAppId']) OR !is_numeric($vars['iSlot']))
|
2004-12-27 05:16:33 +00:00
|
|
|
{
|
2006-07-06 17:27:54 +00:00
|
|
|
if(is_numeric($vars['iAppId']))
|
2006-07-06 18:44:56 +00:00
|
|
|
util_redirect_and_exit(apidb_fullurl("appview.php?iAppId=".$vars["iAppId"]));
|
2005-05-11 03:08:07 +00:00
|
|
|
else
|
2006-07-06 18:44:56 +00:00
|
|
|
util_redirect_and_exit(apidb_fullurl("index.php"));
|
2005-05-11 03:08:07 +00:00
|
|
|
|
2004-12-27 05:16:33 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-06 17:27:54 +00:00
|
|
|
if($vars["sVote"])
|
2005-05-11 03:08:07 +00:00
|
|
|
{
|
2006-07-06 17:27:54 +00:00
|
|
|
addmsg("Registered vote for App #".$vars["iAppId"], "green");
|
|
|
|
|
vote_add($vars["iAppId"], $vars["slot"]);
|
|
|
|
|
} else if($vars["sClear"])
|
2005-05-11 03:08:07 +00:00
|
|
|
{
|
|
|
|
|
/* 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 */
|
|
|
|
|
if(is_vote_in_slot($vars["slot"]))
|
|
|
|
|
{
|
2005-02-26 16:36:52 +00:00
|
|
|
vote_remove($vars["slot"]);
|
2006-07-06 17:27:54 +00:00
|
|
|
addmsg("Removed vote for App #".$vars["iAppId"], "green");
|
2005-05-11 03:08:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-06 18:44:56 +00:00
|
|
|
util_redirect_and_exit(apidb_fullurl("appview.php?iAppId=".$vars["iAppId"]));
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2005-05-11 03:08:07 +00:00
|
|
|
// tell us if there is a vote in a given slot so we don't
|
|
|
|
|
// display incorrect information to the user or go
|
|
|
|
|
// through the trouble of trying to remove a vote that doesn't exist
|
|
|
|
|
function is_vote_in_slot($slot, $userId = null)
|
|
|
|
|
{
|
|
|
|
|
if(!$userId)
|
|
|
|
|
{
|
|
|
|
|
if($_SESSION['current']->isLoggedIn())
|
|
|
|
|
$userId = $_SESSION['current']->iUserId;
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-27 19:16:27 +00:00
|
|
|
$sQuery = "SELECT COUNT(*) as count from appVotes WHERE userId = '?' AND slot = '?'";
|
|
|
|
|
if($hResult = query_parameters($sQuery, $userId, $slot))
|
2005-05-11 03:08:07 +00:00
|
|
|
{
|
|
|
|
|
$oRow = mysql_fetch_object($hResult);
|
|
|
|
|
if($oRow->count != 0)
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
?>
|