2004-12-12 03:51:51 +00:00
|
|
|
<?php
|
2004-03-15 16:22:00 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2005-01-08 18:24:55 +00:00
|
|
|
$result = query_appdb("SELECT * FROM appVotes WHERE appId = $appId AND userId = $userId");
|
2004-03-15 16:22:00 +00:00
|
|
|
return mysql_num_rows($result);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2005-01-08 18:24:55 +00:00
|
|
|
$result = query_appdb("SELECT * FROM appVotes WHERE userId = $userId");
|
2004-03-15 16:22:00 +00:00
|
|
|
return mysql_num_rows($result);
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2005-01-08 18:24:55 +00:00
|
|
|
$result = query_appdb("SELECT * FROM appVotes WHERE appId = $appId");
|
2004-03-15 16:22:00 +00:00
|
|
|
return mysql_num_rows($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-01-30 23:12:48 +00:00
|
|
|
if($_SESSION['current']->isLoggedIn())
|
|
|
|
|
$userId = $_SESSION['current']->iUserId;
|
2004-03-15 16:22:00 +00:00
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-28 00:01:21 +00:00
|
|
|
if($slot > MAX_VOTES)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
vote_remove($slot, $userId);
|
2005-01-08 18:24:55 +00:00
|
|
|
query_appdb("INSERT INTO appVotes 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-01-30 23:12:48 +00:00
|
|
|
if($_SESSION['current']->isLoggedIn())
|
|
|
|
|
$userId = $_SESSION['current']->iUserId;
|
2004-03-15 16:22:00 +00:00
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-01-08 18:24:55 +00:00
|
|
|
query_appdb("DELETE FROM appVotes WHERE userId = $userId AND slot = $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();
|
|
|
|
|
}
|
2005-01-08 18:24:55 +00:00
|
|
|
$result = query_appdb("SELECT * FROM appVotes WHERE userId = $userId");
|
2004-03-15 16:22:00 +00:00
|
|
|
if(!$result)
|
2004-12-12 03:51:51 +00:00
|
|
|
return array();
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
$obs = array();
|
|
|
|
|
while($ob = mysql_fetch_object($result))
|
2004-12-12 03:51:51 +00:00
|
|
|
$obs[$ob->slot] = $ob;
|
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()
|
|
|
|
|
{
|
|
|
|
|
$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]))
|
|
|
|
|
{
|
2005-02-04 02:59:05 +00:00
|
|
|
$appName = lookup_app_name($votes[$i]->appId);
|
2004-12-27 23:59:30 +00:00
|
|
|
$str = "<a href='appview.php?appId=".$votes[$i]->appId."'> $appName</a>";
|
|
|
|
|
$m->add("<input type=radio name=slot value='$i'> ".$str);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
$m->add("<input type=radio name=slot value='$i'> No App Selected");
|
2004-12-12 03:51:51 +00:00
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
$m->addmisc(" ");
|
|
|
|
|
|
|
|
|
|
$m->add("<input type=submit name=clear value=' Clear Vote ' class=votebutton>");
|
|
|
|
|
$m->add("<input type=submit name=vote value='Vote for App' class=votebutton>");
|
|
|
|
|
|
2004-12-27 05:16:33 +00:00
|
|
|
$m->addmisc("<input type=hidden name=appId value={$_REQUEST['appId']}>");
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-12-23 01:12:03 +00:00
|
|
|
$m->add("View Results", BASE."votestats.php");
|
|
|
|
|
$m->add("Voting Help", BASE."help/?topic=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())
|
2004-12-12 03:51:51 +00:00
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
errorpage("You must be logged in to vote");
|
2004-12-12 03:51:51 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-12-27 05:16:33 +00:00
|
|
|
if( !is_numeric($vars['appId']) OR !is_numeric($vars['slot']))
|
|
|
|
|
{
|
|
|
|
|
addmsg("No application or vote slot selected", "red");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-15 16:22:00 +00:00
|
|
|
if($vars["vote"])
|
|
|
|
|
{
|
|
|
|
|
addmsg("Registered vote for App #".$vars["appId"], "green");
|
|
|
|
|
vote_add($vars["appId"], $vars["slot"]);
|
2005-02-26 16:36:52 +00:00
|
|
|
redirect(apidb_fullurl("appview.php?appId=".$vars["appId"]));
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if($vars["clear"])
|
|
|
|
|
{
|
|
|
|
|
addmsg("Removed vote for App #".$vars["appId"], "green");
|
2005-02-26 16:36:52 +00:00
|
|
|
vote_remove($vars["slot"]);
|
|
|
|
|
redirect(apidb_fullurl("appview.php?appId=".$vars["appId"]));
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|