2011-03-28 14:21:28 +00:00
< ?
//******************************************************************************//
//--------------- Vote on a request --------------------------------------------//
//This page is ajax!
2013-04-21 08:00:52 +00:00
if ( ! check_perms ( 'site_vote' )) {
2011-03-28 14:21:28 +00:00
error ( 403 );
}
authorize ();
2013-04-21 08:00:52 +00:00
if ( empty ( $_GET [ 'id' ]) || ! is_number ( $_GET [ 'id' ])) {
2013-02-19 08:00:30 +00:00
error ( 0 );
2011-03-28 14:21:28 +00:00
}
$RequestID = $_GET [ 'id' ];
2013-04-21 08:00:52 +00:00
if ( empty ( $_GET [ 'amount' ]) || ! is_number ( $_GET [ 'amount' ]) || $_GET [ 'amount' ] < $MinimumVote ) {
2011-06-27 08:00:06 +00:00
$Amount = $MinimumVote ;
2011-03-28 14:21:28 +00:00
} else {
$Amount = $_GET [ 'amount' ];
}
$Bounty = ( $Amount * ( 1 - $RequestTax ));
2013-07-10 00:08:53 +00:00
$DB -> query ( "
SELECT TorrentID
FROM requests
WHERE ID = $RequestID " );
2011-03-28 14:21:28 +00:00
list ( $Filled ) = $DB -> next_record ();
2013-07-11 08:00:55 +00:00
if ( $LoggedUser [ 'BytesUploaded' ] >= $Amount && $Filled === '0' ) {
2013-02-19 08:00:30 +00:00
2011-03-28 14:21:28 +00:00
// Create vote!
2013-04-21 08:00:52 +00:00
$DB -> query ( "
INSERT IGNORE INTO requests_votes
( RequestID , UserID , Bounty )
VALUES
( $RequestID , " . $LoggedUser['ID'] . " , $Bounty ) " );
2013-02-19 08:00:30 +00:00
2013-04-21 08:00:52 +00:00
if ( $DB -> affected_rows () < 1 ) {
2011-03-28 14:21:28 +00:00
//Insert failed, probably a dupe vote, just increase their bounty.
2013-04-21 08:00:52 +00:00
$DB -> query ( "
UPDATE requests_votes
SET Bounty = ( Bounty + $Bounty )
WHERE UserID = " . $LoggedUser['ID'] . "
2013-07-10 00:08:53 +00:00
AND RequestID = $RequestID " );
2011-03-28 14:21:28 +00:00
echo 'dupe' ;
}
2013-04-21 08:00:52 +00:00
2011-03-28 14:21:28 +00:00
2013-07-10 00:08:53 +00:00
$DB -> query ( "
UPDATE requests
SET LastVote = NOW ()
WHERE ID = $RequestID " );
2013-02-19 08:00:30 +00:00
2013-07-10 00:08:53 +00:00
$Cache -> delete_value ( " request_ $RequestID " );
$Cache -> delete_value ( " request_votes_ $RequestID " );
2011-03-28 14:21:28 +00:00
2013-05-13 08:00:33 +00:00
$ArtistForm = Requests :: get_artists ( $RequestID );
2013-04-21 08:00:52 +00:00
foreach ( $ArtistForm as $Importance ) {
foreach ( $Importance as $Artist ) {
2011-03-28 14:21:28 +00:00
$Cache -> delete_value ( 'artists_requests_' . $Artist [ 'id' ]);
}
}
// Subtract amount from user
2013-07-10 00:08:53 +00:00
$DB -> query ( "
UPDATE users_main
SET Uploaded = ( Uploaded - $Amount )
WHERE ID = " . $LoggedUser['ID'] );
2011-03-28 14:21:28 +00:00
$Cache -> delete_value ( 'user_stats_' . $LoggedUser [ 'ID' ]);
2013-05-16 16:15:57 +00:00
2012-10-11 08:00:15 +00:00
Requests :: update_sphinx_requests ( $RequestID );
2011-06-27 08:00:06 +00:00
echo 'success' ;
2013-10-23 08:01:03 +00:00
$DB -> query ( "
SELECT UserID
FROM requests_votes
WHERE RequestID = '$RequestID'
AND UserID != '$LoggedUser[ID]' " );
2013-08-28 23:08:41 +00:00
$UserIDs = array ();
while ( list ( $UserID ) = $DB -> next_record ()) {
$UserIDs [] = $UserID ;
}
2013-09-13 08:00:53 +00:00
NotificationsManager :: notify_users ( $UserIDs , NotificationsManager :: REQUESTALERTS , Format :: get_size ( $Amount ) . " of bounty has been added to a request you've voted on! " , " requests.php?action=view&id= " . $RequestID );
2013-10-01 23:08:42 +00:00
2013-04-21 08:00:52 +00:00
} elseif ( $LoggedUser [ 'BytesUploaded' ] < $Amount ) {
2011-03-28 14:21:28 +00:00
echo 'bankrupt' ;
}
?>