Esempio n. 1
0
<?php

authorize();
$GroupID = $_REQUEST['groupid'];
if (!is_number($GroupID)) {
    echo 'Invalid Group';
    die;
}
// What groups has this guy voted?
$UserVotes = Votes::get_user_votes($LoggedUser['ID']);
// What are the votes for this group?
$GroupVotes = Votes::get_group_votes($GroupID);
$UserID = $LoggedUser['ID'];
if ($_REQUEST['do'] == 'vote') {
    if (isset($UserVotes[$GroupID]) || !check_perms('site_album_votes')) {
        echo 'noaction';
        die;
    }
    if ($_REQUEST['vote'] != 'up' && $_REQUEST['vote'] != 'down') {
        echo 'badvote';
        die;
    }
    $Type = $_REQUEST['vote'] == 'up' ? 'Up' : 'Down';
    // Update the two votes tables if needed
    $DB->query("\n\t\tINSERT IGNORE INTO users_votes (UserID, GroupID, Type)\n\t\tVALUES ({$UserID}, {$GroupID}, '{$Type}')");
    if ($DB->affected_rows() == 0) {
        echo 'noaction';
        die;
    }
    // Update the group's cache key
    $GroupVotes['Total'] += 1;