コード例 #1
0
function umc_usericon_get($users = false, $update = true)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_PATH_MC;
    $steve_head = '/home/minecraft/server/bin/data/steve.png';
    if (!$users) {
        $users = umc_get_active_members();
    } else {
        if (is_array($users) && count($users) == 0) {
            XMPP_ERROR_send_msg("umc_update_usericons got zero users!");
        } else {
            if (!is_array($users)) {
                $U = umc_uuid_getboth($users);
                $users = array($U['uuid'] => $U['username']);
            }
        }
    }
    $users_raw = array();
    foreach ($users as $uuid => $username) {
        $uuid_raw = str_replace("-", "", $uuid);
        $users_raw[$uuid] = $url = "https://sessionserver.mojang.com/session/minecraft/profile/{$uuid_raw}";
    }
    $no_skin = array();
    $failed_users = array();
    $skin_urls = array();
    $D = unc_serial_curl($users_raw, 0, 50, '/home/includes/unc_serial_curl/google.crt');
    foreach ($D as $uuid => $d) {
        // we only update the skin if it does not exist
        if (!$update && file_exists("{$UMC_PATH_MC}/server/bin/data/full_skins/{$uuid}.png")) {
            continue;
        }
        if ($uuid == 'abandone-0000-0000-0000-000000000000') {
            continue;
        }
        if ($d['response']['http_code'] !== 200) {
            $failed_users[] = array('uuid' => $uuid, 'url' => $d['response']['url'], 'reason' => 'Could not download user data');
        }
        $base64_texture = '';
        $d_arr = json_decode($d['content']);
        if (!$d_arr) {
            XMPP_ERROR_trigger("Failed to retrieve session profile for {$uuid}");
        }
        //object(stdClass)#2 (3) {
        //  ["id"]=>
        //  string(32) "ab3bc877443445a993bdbab6df41eabf"
        //  ["name"]=>
        //  string(8) "uncovery"
        //  ["properties"]=>
        //  array(1) {
        //    [0]=>
        //    object(stdClass)#3 (2) {
        //      ["name"]=>
        //      string(8) "textures"
        //      ["value"]=>
        //      string(308) "eyJ0aW1lc3RhbXAiOjE0NDA0NzUyOTQ2NDksInByb2ZpbGVJZCI6ImFiM2JjODc3NDQzNDQ1YTk5M2JkYmFiNmRmNDFlYWJmIiwicHJvZmlsZU5hbWUiOiJ1bmNvdmVyeSIsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9jYWVhMjljODY2ZDkyMTVhYWJjMTk5MDQyMTE1ZWMwNTUzMzJkNjZlMGI4ZWY2ZjkyNjNmZTRiMWZlNzZlIn19fQ=="
        //    }
        //  }
        //}
        if (!isset($d_arr->properties)) {
            XMPP_ERROR_trace("json", $d_arr);
            XMPP_ERROR_trigger("Failed to retrieve properties for {$uuid}");
        }
        $prop_count = count($d_arr->properties);
        for ($i = 0; $i < $prop_count; $i++) {
            if ($d_arr->properties[$i]->name == 'textures') {
                $base64_texture = $d_arr->properties[$i]->value;
            } else {
                echo "Wrong property: " . $d_arr->properties[$i]->name;
            }
        }
        $raw_texture = base64_decode($base64_texture);
        // {"timestamp":1440475294649,"profileId":"ab3bc877443445a993bdbab6df41eabf","profileName":"uncovery","textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/caea29c866d9215aabc199042115ec055332d66e0b8ef6f9263fe4b1fe76e"}}}
        $texture_arr = json_decode($raw_texture);
        if (!$texture_arr) {
            XMPP_ERROR_trigger("Failed to decode texture: {$raw_texture}");
        }
        $time_stamp = $texture_arr->timestamp;
        // check if the file on the drive is newer
        $current_file = "{$UMC_PATH_MC}/server/bin/data/full_skins/{$uuid}.png";
        if (!file_exists($current_file) || filemtime($current_file) > $time_stamp) {
            if (isset($texture_arr->textures->SKIN)) {
                // user did not set skin
                $skin_urls[$uuid] = $texture_arr->textures->SKIN->url;
                // echo $texture_arr->textures->SKIN->url . "<br>\n";
            } else {
                XMPP_ERROR_trace("{$uuid} does not have a skin: {$raw_texture}");
                $no_skin[] = $uuid;
            }
        }
    }
    $S = unc_serial_curl($skin_urls);
    foreach ($S as $uuid => $s) {
        $skin_file = "{$UMC_PATH_MC}/server/bin/data/full_skins/{$uuid}.png";
        $head_file = "{$UMC_PATH_MC}/server/bin/data/user_icons/{$uuid}.png";
        if ($s['response']['content_type'] !== 'image/png' && $s['response']['http_code'] !== 200) {
            $failed_users[] = array('uuid' => $uuid, 'url' => $s['response']['url'], 'reason' => 'Could not download image');
            continue;
        }
        $written = file_put_contents($skin_file, $s['content']);
        if (!$written) {
            $failed_users[] = array('uuid' => $uuid, 'url' => $s['response']['url'], 'reason' => "Could not save file to {$skin_file}");
            continue;
        }
        // convert to head icon, resize to 20x20
        $command = "convert -crop '8x8+8+8' -scale 20 \"{$skin_file}\" \"{$head_file}\"";
        exec($command);
    }
    // process users w/o skin
    foreach ($no_skin as $uuid) {
        $head_file = "{$UMC_PATH_MC}/server/bin/data/user_icons/{$uuid}.png";
        if (!file_exists($steve_head)) {
            XMPP_ERROR_trigger("Steve head icon not available");
        } else {
            $check = copy($steve_head, $head_file);
            if (!$check || !file_exists($head_file)) {
                XMPP_ERROR_trigger("Could not create steve head for file {$head_file}");
            } else {
                XMPP_ERROR_trace("used steve head for {$head_file}");
            }
        }
    }
    if (count($failed_users) > 0) {
        XMPP_ERROR_trace("failed users:", $failed_users);
        XMPP_ERROR_trigger("Users failed to get icon, see error report for details");
    }
}
コード例 #2
0
/**
 * Bans a user
 * can make the difference between UUID and username
 * can make the difference between websend and wordpress
 *
 * @param type $user
 */
function umc_user_ban($user, $reason)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_ENV, $UMC_USER;
    $U = umc_uuid_getboth($user);
    $uuid = $U['uuid'];
    $username = $U['username'];
    $cmd = "ban {$username} {$reason}";
    if ($UMC_ENV == 'websend') {
        umc_ws_cmd($cmd, 'asConsole', false, false);
        $admin = $UMC_USER['username'];
    } else {
        umc_exec_command($cmd, 'asConsole', false);
        $admin = 'wordpress';
    }
    $sql = "INSERT INTO minecraft_srvr.`banned_users`(`username`, `reason`, `admin`, `uuid`) VALUES ('{$username}','{$reason}', '{$admin}', '{$uuid}');";
    umc_mysql_query($sql, true);
    // remove shop inventory
    umc_shop_cleanout_olduser($uuid);
    // remove from teamspeak
    umc_ts_clear_rights($uuid);
    umc_wp_ban_user($uuid);
    umc_log('mod', 'ban', "{$admin} banned {$username}/{$uuid} because of {$reason}");
    XMPP_ERROR_send_msg("{$admin} banned {$username} because of {$reason}");
}
コード例 #3
0
ファイル: donation.php プロジェクト: dani0010/uncovery_me
function umc_donation_level($user, $debug = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $U = umc_uuid_getboth($user);
    $uuid = $U['uuid'];
    $username = $U['username'];
    $debug_txt = '';
    global $UMC_SETTING;
    $date_now = new DateTime("now");
    $sql = "SELECT amount, date FROM minecraft_srvr.donations WHERE uuid='{$uuid}';";
    $level = umc_get_uuid_level($uuid);
    if ($level == 'Owner') {
        return false;
    }
    $D = umc_mysql_fetch_all($sql);
    // if there are 0 donations, user should not be changes
    if (count($D) == 0 && strstr($level, "Donator")) {
        XMPP_ERROR_trigger("User {$username} ({$uuid}) never donated but has a donator level ({$level})");
    } else {
        if (count($D) == 0) {
            $debug_txt .= "{$username} ({$uuid}) does not have any donations\n";
            return;
        }
    }
    $debug_txt .= "Checking donation upgrade of user {$username}, current UserLevel: {$level}\n";
    $donation_level = 0;
    // go through all donations and find out how much is still active
    foreach ($D as $row) {
        $date_donation = new DateTime($row['date']);
        $interval = $date_donation->diff($date_now);
        $years = $interval->format('%y');
        $months = $interval->format('%m');
        $donation_term = $years * 12 + $months;
        $donation_leftover = $row['amount'] - $donation_term;
        if ($donation_leftover < 0) {
            $donation_leftover = 0;
            // do not create negative carryforward
        }
        $donation_level = $donation_level + $donation_leftover;
        $debug_txt .= "Amount donated {$row['amount']} {$years} years {$months} m ago = {$donation_term} months ago, {$donation_leftover} leftover, level: {$donation_level}\n";
    }
    $donation_level_rounded = ceil($donation_level);
    // get userlevel and check if demotion / promotion is needed
    $debug_txt .= "user {$username} ({$uuid}) has donation level of {$donation_level_rounded}, now is {$level}\n";
    // current userlevel
    $ranks_lvl = array_flip($UMC_SETTING['ranks']);
    $cur_lvl = $ranks_lvl[$level];
    // get current promotion level
    if (strpos($level, 'DonatorPlus')) {
        $current = 2;
    } else {
        if (strpos($level, 'Donator')) {
            $current = 1;
        } else {
            $current = 0;
        }
    }
    // get future promotion level
    if (count($D) == 0) {
        // this never happens since it's excluded above
        $future = 0;
    } else {
        if ($donation_level_rounded >= 1) {
            $future = 2;
        } else {
            if ($donation_level_rounded < 1) {
                $future = 1;
            }
        }
    }
    $debug_txt .= "future = {$future}, current = {$current}\n";
    $change = $future - $current;
    if ($change == 0) {
        $debug_txt .= "User has right level, nothing to do\n";
        return false;
        // bail if no change needed
    } else {
        // we have a change in level, let's get an error report
        $debug = true;
    }
    $debug_txt .= "User will change {$change} levels\n";
    // get currect rank index
    $debug_txt .= "Current Rank index = {$cur_lvl}\n";
    // calculate base level
    $base_lvl = $cur_lvl - $current;
    $debug_txt .= "User base level = {$base_lvl}\n";
    $new_lvl = $base_lvl + $future;
    if ($new_lvl == $cur_lvl) {
        XMPP_ERROR_send_msg("Donations upgrade: Nothing to do, CHECK this should have bailed earlier!");
        return false;
    }
    $new_rank = $UMC_SETTING['ranks'][$new_lvl];
    $debug_txt .= "User {$username} upgraded from {$level} to {$new_rank}\n";
    umc_exec_command("pex user {$uuid} group set {$new_rank}");
    umc_log('Donations', 'User Level de/promotion', "User {$username} upgraded from {$level} to {$new_rank}");
    if ($debug) {
        XMPP_ERROR_send_msg($debug_txt);
    }
    return $donation_level_rounded;
    // . "($donation_level $current - $future - $change)";
}
コード例 #4
0
function umc_vote_web()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $vote_ranks, $UMC_DOMAIN, $UMC_USER;
    $lvl_percent = array('a' => 0.3, 'd' => 0.4, 'm' => 0.7, 'e' => 1);
    $out = umc_vote_stats();
    // return "<h1>Sorry, due to technical issues, voting is temporarily suspended</h1>";
    if (!$UMC_USER) {
        $out = "Please <a href=\"{$UMC_DOMAIN}/wp-login.php\">login</a> to vote!";
        return $out;
    } else {
        $out .= "<h2>Proposals & Votes</h2>";
        $username = $UMC_USER['username'];
        $uuid = $UMC_USER['uuid'];
        $user_lvl = $UMC_USER['userlevel'];
    }
    $user_lvl_id = $vote_ranks[$user_lvl]['lvl'];
    if ($user_lvl_id < 3) {
        // start voting only for designers
        return "Sorry, you need to be Designer or above to vote!";
    }
    // get user numbers for levels
    $lvl_str_arr = array('a' => "'Architect', 'ArchitectDonator', 'ArchitectDonatorPlus'", 'd' => "'Designer', 'DesignerDonator', 'DesignerDonatorPlus'", 'm' => "'Master', 'MasterDonator', 'MasterDonatorPlus'", 'e' => "'Elder', 'ElderDonator', 'ElderDonatorPlus'");
    $lvl_amounts = array('a' => 0, 'd' => 0, 'm' => 0, 'e' => 0);
    $lvl_min_req = array('a' => 0, 'd' => 0, 'm' => 0, 'e' => 0);
    foreach ($lvl_str_arr as $lvl_code => $lvl_str) {
        // This takes all lots where the owners are in one of the user 4 levels that can vote
        $sql = "SELECT user_id, UUID.UUID as uuid, username FROM `minecraft_worldguard`.`region_players`\r\n            LEFT JOIN minecraft_worldguard.user ON region_players.user_id=user.id\r\n            LEFT JOIN minecraft_srvr.UUID ON minecraft_worldguard.user.uuid=minecraft_srvr.UUID.UUID\r\n            LEFT JOIN minecraft_srvr.permissions_inheritance ON minecraft_srvr.UUID.UUID=minecraft_srvr.permissions_inheritance.child\r\n            WHERE parent IN ({$lvl_str}) AND type=1 AND owner=1 GROUP BY user_id;";
        $C = umc_mysql_fetch_all($sql);
        // count all the people in the userlevel to know how many votes are needed
        $lvl_amounts[$lvl_code] = count($C);
    }
    // calc needed votes
    $full_vote = $lvl_amounts['e'] * $vote_ranks['Elder']['vote'];
    foreach ($lvl_amounts as $lvl => $lvl_amount) {
        $lvl_min_req[$lvl] = round($full_vote * $lvl_percent[$lvl]);
    }
    // TODO insert here a cleanup process that deletes old votes of non-promoted users
    $proposed = filter_input(INPUT_POST, 'proposal', FILTER_SANITIZE_STRING);
    if (isset($proposed) && strlen($proposed) > 1) {
        $proposed = umc_check_user($proposed);
        if (!$proposed) {
            $out .= "Sorry {$username}, but you need to input an existing user to propose!";
        } else {
            $proposed_data = umc_uuid_getboth($proposed, 'username');
            $proposed_username = $proposed_data['username'];
            $proposed_uuid = $proposed_data['uuid'];
            // what user level is it?
            $prop_lvl = umc_get_uuid_level($proposed_uuid);
            $prop_lvl_id = $vote_ranks[$prop_lvl]['lvl'];
            // check if the user was recently promoted
            $sql = "SELECT UNIX_TIMESTAMP(`date`) as mysql_ts FROM minecraft_srvr.proposals  WHERE `uuid` LIKE '{$proposed_uuid}' ORDER BY `date` DESC;";
            $D = umc_mysql_fetch_all($sql);
            $row = array();
            if (count($D) > 0) {
                $row = $D[0];
                // get the first (latest) entry
            } else {
                $row['mysql_ts'] = 0;
            }
            if (time() - $row['mysql_ts'] < 5270400) {
                $out .= "<strong>Sorry {$username}, but {$proposed_username} was last proposed for promotion less than 2 months ago!</strong>";
            } else {
                if ($user_lvl_id < 6 && $user_lvl_id < $prop_lvl_id + 1) {
                    $out .= "<strong>Sorry {$username}, but you need to be at a higher level to propose {$proposed_username} for a higher rank!</strong>";
                } else {
                    if ($prop_lvl_id > 5) {
                        $out .= "<strong>Sorry {$username}, but {$proposed_username} has reached max level already!</strong>";
                    } else {
                        if (umc_user_countlots($proposed) < 1) {
                            // is this an active user?
                            $out .= "<strong>Sorry {$username}, but you can only propose users who have a lot!</strong>";
                        } else {
                            if ($prop_lvl_id < 2) {
                                $out .= "<strong>Sorry {$username}, but you can only propose users who are at least Citizen level!</strong>";
                            } else {
                                if ($username == $proposed) {
                                    $out .= "<strong>Sorry {$username}, but you cannot propose yourself!</strong>";
                                } else {
                                    // ok to be promoted
                                    $ins_proposal_sql = "INSERT INTO `minecraft_srvr`.`proposals` (`pr_id`, `uuid`, `proposer_uuid`, `date`, `status`)\r\n                    VALUES (NULL, '{$proposed_uuid}', '{$uuid}', NOW(), 'voting');";
                                    umc_mysql_query($ins_proposal_sql);
                                    $pr_id = umc_mysql_insert_id();
                                    $sql = "INSERT INTO minecraft_srvr.`proposals_votes` (`pr_id`, `voter_uuid`, `date`, `vote`) VALUES ({$pr_id}, '{$uuid}', NOW(), 1);";
                                    umc_mysql_query($sql, true);
                                    $out .= "Thanks {$username}, {$proposed_username} as been submitted for voting, and your vote has been set, too!";
                                    if ($prop_lvl_id == 5) {
                                        // we propose a Master for promotion, inform all elders
                                        $sql = "SELECT user_email, UUID, username FROM minecraft_srvr.`UUID`\r\n                        LEFT JOIN minecraft.wp_usermeta ON UUID.UUID=meta_value\r\n                        LEFT JOIN minecraft.wp_users ON user_id=ID\r\n                        WHERE `userlevel` LIKE 'Elder%' AND lot_count > 0";
                                        $D = umc_mysql_fetch_all($sql);
                                        $subject = "{$proposed} proposed for Elder, please vote!";
                                        $content = "Dear Elder, \r\n\r\nthe user {$proposed} has been proposed to be promoted to Elder. Please go to\r\n\r\n{$UMC_DOMAIN}/vote-for-users/\r\n\r\n" . "and vote on this proposal. Please either SUPPORT or VETO the proposal.\r\n" . "Please note that the vote will be closed as 'failed' unless all Elders cast a vote within the coming 2 months.\r\n" . "Thanks a lot for supporting Uncovery Minecraft!\r\n\r\nBest regards,\r\nUncovery";
                                        $headers = 'From:minecraft@uncovery.me' . "\r\nReply-To:minecraft@uncovery.me\r\n" . 'X-Mailer: PHP/' . phpversion();
                                        mail('*****@*****.**', $subject, $content, $headers);
                                        foreach ($D as $row) {
                                            mail($row['user_email'], '[Uncovery Minecraft] ' . $subject, $content, $headers);
                                            umc_mail_send_backend($row['UUID'], 'ab3bc877-4434-45a9-93bd-bab6df41eabf', $content, $subject, 'send');
                                            // send from uncovery's UUID
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // propose new person
    if ($user_lvl_id > 3) {
        $out .= "<form action=\"\" method=\"post\">\n" . "<span>Propose a person to be upgraded: <input type=\"text\" name=\"proposal\"> " . "<input type=\"submit\" name=\"proposebutton\" value=\"Propose user!\">" . "</span></form>";
    } else {
        $out .= "(Since your level is too low, you cannot propose users yet.)";
    }
    // close old proposals
    $upd_sql = "UPDATE minecraft_srvr.proposals SET `status`='failed' WHERE status = 'voting' AND date < NOW() - INTERVAL 2 month";
    umc_mysql_query($upd_sql, true);
    // list proposed people
    $sql = "SELECT UUID.username, status, pr_id, date, proposals.uuid FROM minecraft_srvr.proposals\r\n        LEFT JOIN minecraft_srvr.UUID ON proposals.uuid=UUID.UUID\r\n        WHERE status IN ('voting','closed') ORDER BY `date` ASC;";
    $D = umc_mysql_fetch_all($sql);
    $header = '';
    if ($username == 'uncovery') {
        $header = '<th>Score</th>';
    }
    $out .= "<br><form action=\"\" method=\"post\">\n<input type=\"hidden\" name=\"uuid\" value=\"{$uuid}\">\n<input type=\"hidden\" name=\"voting\" value=\"true\">\n<table>\n" . "<tr><th>Proposal</th><th>Date</th><th>Current Level</th><th>Your Vote</th><th>Vote date</th>{$header}</tr>\n";
    $proposals = 0;
    $upgraded_users = array();
    foreach ($D as $row) {
        $prop_lvl = umc_get_userlevel($row['username']);
        $prop_status = $row['status'];
        $prop_lvl_id = $vote_ranks[$prop_lvl]['lvl'];
        $proposed = $row['uuid'];
        $proposed_name = $row['username'];
        // check if user is allowed to vote for this person
        if ($user_lvl_id <= $prop_lvl_id) {
            continue;
        }
        $proposals++;
        $sel_support = $sel_veto = '';
        $sel_none = " selected=\"selected\"";
        $vote_date = "n/a";
        $pr_id = $row['pr_id'];
        // check if vote has been cast right now
        if (isset($_POST['voting']) && $_POST['uuid'] == $uuid) {
            if ($prop_status == 'closed' && $username == 'uncovery' && isset($_POST['CL_' . $pr_id]) && $_POST['CL_' . $pr_id] != 'closed') {
                $new_vote = filter_input(INPUT_POST, 'CL_' . $pr_id, FILTER_SANITIZE_STRING);
                // var_dump($_POST);
                $sql = "UPDATE minecraft_srvr.`proposals` SET `status` = '{$new_vote}' WHERE `proposals`.`pr_id`={$pr_id} LIMIT 1;";
                umc_mysql_query($sql);
                // echo $sql;
                if ($new_vote == 'success') {
                    $cmd = "pex promote {$proposed}";
                    umc_exec_command($cmd, 'asConsole', false);
                    umc_exec_command($cmd, 'asConsole', false);
                    umc_exec_command($cmd, 'asConsole', false);
                    $upgraded_users[$proposed_name] = $prop_lvl;
                    umc_log('voting', "promotion", "{$proposed_name} ({$proposed}) was promoted from {$prop_lvl} through votes");
                }
                continue;
            } else {
                if ($prop_status != 'closed') {
                    $new_vote = filter_input(INPUT_POST, 'PR_' . $pr_id, FILTER_SANITIZE_STRING);
                    $sel_support = $sel_veto = $sel_none = '';
                    // find existing votes
                    $sql = "SELECT * FROM minecraft_srvr.`proposals_votes` WHERE pr_id={$pr_id} and voter_uuid='{$uuid}';";
                    $C = umc_mysql_fetch_all($sql);
                    if (count($C) > 0) {
                        $row_check = $C[0];
                        $vote_id = $row_check['vote_id'];
                        if ($new_vote == 0) {
                            $sql = "DELETE FROM minecraft_srvr.`proposals_votes` WHERE pr_id={$pr_id} and voter_uuid='{$uuid}';";
                            umc_mysql_query($sql, true);
                        } else {
                            if ($row_check['vote'] != $new_vote) {
                                $sql = "REPLACE INTO minecraft_srvr.`proposals_votes` (`vote_id`, `pr_id`, `voter_uuid`, `date`, `vote`)\r\n\t\t\t    VALUES ({$vote_id}, {$pr_id}, '{$uuid}', NOW(), {$new_vote});";
                                umc_mysql_query($sql, true);
                            }
                        }
                    } else {
                        if ($new_vote != 0) {
                            $sql = "INSERT INTO minecraft_srvr.`proposals_votes` (`pr_id`, `voter_uuid`, `date`, `vote`)\r\n                        VALUES ({$pr_id}, '{$uuid}', NOW(), {$new_vote});";
                            umc_mysql_query($sql, true);
                        }
                    }
                } else {
                    if ($prop_status == 'closed') {
                        // a user tried to vote on a closed vote... what to do?
                    }
                }
            }
        }
        // load existing votes
        $total_score = 0;
        $sql = "SELECT date, voter_uuid, UUID.username, vote, date FROM minecraft_srvr.proposals_votes\r\n                LEFT JOIN minecraft_srvr.UUID ON voter_uuid=UUID.UUID\r\n                WHERE pr_id={$pr_id} AND vote <> 0 ORDER BY date DESC;";
        $R = umc_mysql_fetch_all($sql);
        $email_close = "{$UMC_DOMAIN}/vote-for-users/\n";
        foreach ($R as $row_calc) {
            $vote_date = $row_calc['date'];
            $voter_lvl = umc_get_uuid_level($row_calc['voter_uuid']);
            $voter_weight = $vote_ranks[$voter_lvl]['vote'];
            $voter_score = $voter_weight * $row_calc['vote'];
            $total_score = $total_score + $voter_score;
            if ($username == 'uncovery') {
                $out .= "<tr><td>Vote:</td><td>{$row_calc['username']}</td><td>{$voter_lvl}</td><td>{$row_calc['vote']}</td><td>{$row_calc['date']}</td><td>{$voter_score}</td></tr>\n";
                // prepare email to send if this will be closed
            }
            $email_close .= "Vote: {$row_calc['username']} ({$voter_lvl}) on {$row_calc['date']} gave points: {$voter_score}\n";
        }
        // close votes that have enough points
        $lvl_code = $vote_ranks[$prop_lvl]['code'];
        $min_req = $lvl_min_req[$lvl_code];
        if (abs($total_score) >= $min_req && $prop_status == 'voting') {
            // close vote
            $sql = "UPDATE minecraft_srvr.`proposals` SET `status` = 'closed' WHERE `proposals`.`pr_id`={$pr_id} LIMIT 1 ";
            umc_mysql_query($sql, true);
            // send email with status report
            $email_text = $email_close . "Total Score: {$total_score}\n\rRequired: " . abs($lvl_min_req[$lvl_code]);
            $headers = 'From:minecraft@uncovery.me' . "\r\nReply-To:minecraft@uncovery.me\r\n" . 'X-Mailer: PHP/' . phpversion();
            mail('*****@*****.**', "Voting closed for " . $row['username'], $email_text, $headers);
            $prop_status = 'closed';
        } else {
            if ($prop_status == 'closed' && $total_score < abs($lvl_min_req[$lvl_code])) {
                //$sql = "UPDATE minecraft_srvr.`proposals` SET `status` = 'voting' WHERE `proposals`.`pr_id`=$pr_id LIMIT 1 ";
                //mysql_query($sql);
            }
        }
        // show total score
        if ($username == 'uncovery') {
            $header = "<td><strong>{$total_score}</strong> (of {$min_req})</td>";
        }
        // load your own score
        $sql = "SELECT * FROM minecraft_srvr.proposals_votes WHERE voter_uuid = '{$uuid}' AND pr_id={$pr_id}";
        $D = umc_mysql_fetch_all($sql);
        $vote_date = "n/a";
        if (count($D) > 0) {
            $row_votes = $D[0];
            $vote_id = $row_votes['vote_id'];
            $your_vote = $row_votes['vote'];
            $vote_date = $row_votes['date'];
            // check if an alternative vote has been cast right now
            if ($your_vote == 1) {
                $sel_support = " selected=\"selected\"";
            } else {
                if ($your_vote == -1) {
                    $sel_veto = " selected=\"selected\"";
                }
            }
        }
        // show voting buttons
        $vote_close = '';
        $min_req = $lvl_min_req[$lvl_code];
        if ($prop_status == 'closed') {
            $vote = "Voting closed!<input type=\"hidden\" name=\"PR_{$pr_id}\" value=\"done\">";
            if ($username == 'uncovery') {
                $vote_date = "<select name=\"CL_{$pr_id}\"><option value=\"closed\">Voting closed</option><option value=\"success\">Upgrade</option><option value=\"failed\">Fail</option></select>";
            }
        } else {
            $vote = "<select name=\"PR_{$pr_id}\"><option value=\"0\" {$sel_none}>Abstain</option><option value=\"1\"{$sel_support}>Supported</option><option value=\"-1\"{$sel_veto}>Vetoed</option></select>";
        }
        $vote_lvl = umc_get_userlevel($row['username']);
        $out .= "<tr><td><strong><a href=\"{$UMC_DOMAIN}/users-2/?u={$row['username']}\">{$row['username']}</a></strong></td><td>{$row['date']}</td><td>{$prop_lvl}</td><td>{$vote}</td><td>{$vote_date}</td>{$header}</tr>\n";
    }
    if ($proposals == 0) {
        $out .= "<tr><td colspan=6>There are no proposals that you can vote for at the moment!</td><tr>\n";
    }
    $out .= "</table>\n<input type=\"submit\" name=\"votebutton\" value=\"Submit votes!\">\n</form><br>\n";
    // process successful votes, create post to blog
    if (count($upgraded_users) > 0) {
        $text = "Please see the latest upgrades from the voting system:<ul>";
        $userlist_arr = array();
        foreach ($upgraded_users as $upgraded_user => $userlvl) {
            $nextrank = $vote_ranks[$userlvl]['next'];
            $text .= "<li>{$upgraded_user} (from {$userlvl} to {$nextrank})</li>";
            $userlist_arr[] = $upgraded_user;
        }
        $userlist = implode(", ", $userlist_arr);
        $text .= "</ul>Congratz and thanks to all voters!";
        $post = array('comment_status' => 'open', 'ping_status' => 'closed', 'post_author' => 1, 'post_content' => $text, 'post_status' => 'publish', 'post_title' => "Today's upgrades: {$userlist}", 'post_type' => 'post');
        wp_insert_post($post);
    }
    return $out;
}