示例#1
0
function include_vote2_text()
{
    $objSrcUser =& $GLOBALS["objSrcUser"];
    // if this user voted
    if (isset($_POST['votefor'])) {
        $iVotedFor = intval($_POST['votefor']);
        include 'inc/functions/vote.php';
        // Save this persons vote
        $iAllianceId = $objSrcUser->get_stat(ALLIANCE);
        $objSrcUser->set_stat(VOTE, $iVotedFor);
        // When voter == elder, allow updating coelders
        if ($objSrcUser->get_stat(TYPE) == 'elder') {
            if (isset($_POST['voteforcoelder'])) {
                $arrCoelderVotes = $_POST['voteforcoelder'];
                // dirty input (ES)
            }
            unset_coelders($iAllianceId);
            //fixed some possibly nasty issues if less than 2 coelders are selected - AI 17/11/06
            for ($i = 0; $i < 2 && !empty($arrCoelderVotes[$i]); $i++) {
                $coelderId = $arrCoelderVotes[$i];
                set_coelder($iAllianceId, $coelderId);
            }
        }
        unset_external_votes($iAllianceId);
        count_votes($iAllianceId);
        header('location: main.php?cat=game&page=vote');
    }
}
示例#2
0
function count_votes($i_intAlliance)
{
    $strSQL = "SELECT COUNT(id) AS playercount " .
              "  FROM stats " .
              " WHERE kingdom = '$i_intAlliance' " .
              "   AND vote != 0";

    $result = mysql_query ($strSQL) or die("include_vote_text3:" . mysql_error());

    $intPlayerCount = 100; // fail-safe number, if we don't get the no. of the tribes

    if (mysql_num_rows($result) == 1)
    {
        $intPlayerCount = mysql_result ($result, 0, "playercount");
    }

    // this is a such a cool query. in 1 query I find the person with the max
    // votes in an alliance
    $strSQL = "SELECT vote, COUNT(vote) AS votecount " .
              "  FROM stats " .
              " WHERE kingdom = $i_intAlliance " .
              "   AND vote > 0 " .
              " GROUP BY vote" .
              " ORDER BY votecount DESC, id ASC " .
              " LIMIT 1";

    $result = mysql_query ($strSQL) or die("include_vote_text4:" . mysql_error());

    if (mysql_num_rows($result) == 1)
    {
        $intNewElder = mysql_result ($result, 0, "vote");
        $intVoteCount = mysql_result ($result, 0, "votecount");

        // set the current elder to a player
        $strSQL = "UPDATE stats " .
                  "   SET type = 'player' " .
                  " WHERE kingdom = '$i_intAlliance' " .
                  "   AND type = 'elder'";
        $result = mysql_query ($strSQL) or die("include_vote_text5:" . mysql_error());
        $strSQL = "UPDATE rankings_personal " .
                  "   SET player_type = 'player' " .
                  " WHERE alli_id = '$i_intAlliance' " .
                  "   AND player_type = 'elder'";
        $result = mysql_query ($strSQL) or die("include_vote_text_rank:" . mysql_error());

        // set the new elder
        if ($intVoteCount > floor((double) $intPlayerCount * 0.6))
        {
            $strSQL = "UPDATE stats " .
                      "   SET type = 'elder' " .
                      " WHERE id = '$intNewElder' ";
                    $result = mysql_query ($strSQL) or die("include_vote_text6:" . mysql_error());
            $strSQL = "UPDATE rankings_personal " .
                      "   SET player_type = 'elder' " .
                      " WHERE id = '$intNewElder' ";
            $result = mysql_query ($strSQL) or die("include_vote_text_ranking:" . mysql_error());
        }
    }
    else
    {
        // set the current elder to a player
        $strSQL = "UPDATE stats " .
                  "   SET type = 'player' " .
                  " WHERE kingdom = '$i_intAlliance' " .
                  "   AND type = 'elder'";
        $result = mysql_query ($strSQL) or die("include_vote_text:" . mysql_error());
        $strSQL = "UPDATE rankings_personal " .
                  "   SET player_type = 'player' " .
                  " WHERE alli_id = '$i_intAlliance' " .
                  "   AND player_type = 'elder'";
        $result = mysql_query ($strSQL) or die("include_vote_text_rank:" . mysql_error());

        // set the current co-elders to players
        unset_coelders($i_intAlliance);
    }
}