Ejemplo n.º 1
0
function showHierarchy()
{
    // Globals!
    global $DB;
    // Get all sorted ranks.
    $Ranks = $DB->query("SELECT DISTINCT name, rankid, rankOrder FROM ranks ORDER by rankOrder ASC");
    while ($rank = $Ranks->fetchRow()) {
        // Get all the users in the current rank.
        $peopleInRank = $DB->query("SELECT DISTINCT username, rank FROM users WHERE rank='{$rank['rankid']}' AND deleted='0' AND canLogin='******' ORDER BY username");
        // Are there people in this rank?
        if ($peopleInRank->numRows() > 0) {
            // Create a temp. table.
            $table = new table(1, true);
            $table->addHeader(">> " . $rank[name]);
            while ($peep = $peopleInRank->fetchRow()) {
                $table->addRow();
                $table->addCol("<a href=\"index.php?action=profile&id=" . usernameToID($peep[username]) . "\">" . ucfirst($peep[username]) . "</a>");
            }
            $html .= $table->flush() . "<br>";
            unset($table);
        }
    }
    $header = "<h2>" . getConfig("sitename") . " - Hierarchy</h2>";
    return $header . $html;
}
Ejemplo n.º 2
0
function userInRun($username, $run = "check")
{
    // Get / Set important variables.
    global $DB;
    // If username is given, convert to ID.
    if (!is_numeric($username)) {
        $userID = usernameToID($username, "userInRun");
    } else {
        $userID = $username;
    }
    // Is $run truly an integer?
    if ($run != "check") {
        // We want to know wether user is in run X.
        numericCheck($run);
    } else {
        // We want to know if user is in any run, and if so, in which one.
        $results = $DB->getCol("select run from joinups where userid = '{$userID}' and parted is NULL limit 1");
        // Return false if in no run, else ID of runNr.
        if ($results == null) {
            return false;
        } else {
            return $results[0];
        }
    }
    // Query the database and return wether he is in run X or not.
    $results = $DB->query("select joined from joinups where userid in (select id from users where authID in (select distinct authID from users where id = '{$userID}')) and run = '{$run}' and parted is NULL limit 1");
    if ($results->numRows() == 0) {
        return "none";
    } else {
        while ($row = $results->fetchRow()) {
            return $row[joined];
        }
    }
}
Ejemplo n.º 3
0
function addRun()
{
    // We need some more globals.
    global $DB;
    global $ORENAMES;
    global $DBORE;
    global $ORENAMES_STR;
    global $MySelf;
    global $TIMEMARK;
    // Set the userID
    $userID = $MySelf->getID();
    // Are we permitted to create a new run?
    if (!$MySelf->canCreateRun()) {
        makeNotice("You are not allowed to create a mining op!", "error", "forbidden");
    }
    if ($_POST[startnow]) {
        $starttime = $TIMEMARK;
    } else {
        // Startting time goodness.
        $myTime = array("day" => "{$_POST['ST_day']}", "month" => "{$_POST['ST_month']}", "year" => "{$_POST['ST_year']}", "hour" => "{$_POST['ST_hour']}", "minute" => "{$_POST['ST_minute']}");
        $starttime = humanTime("toUnix", $myTime);
    }
    // Having fun with checkboxes, yet again.
    if ($_POST[isOfficial] == "on") {
        $official = true;
    } else {
        $official = false;
    }
    // We using either predefined locations.
    if (empty($_POST[location])) {
        $location = $_POST[locations];
    } else {
        $location = $_POST[location];
    }
    if (empty($location)) {
        makeNotice("You need to specify the location of the Mining Operation!", "notice", "Where again?", "index.php?action=newrun", "[Cancel]");
    }
    // Supervisor
    if ($MySelf->isOfficial()) {
        if (empty($_POST[supervisor])) {
            // Is official, but no one named!
            makeNotice("You need to name someone as the supervisor for this run!", "warning", "Missing Information", "index.php?action=newrun", "[Cancel]");
        } else {
            // Grab ID of named supervisor.
            $supervisor = usernameToID(sanitize($_POST[supervisor]));
        }
    } else {
        // Non official, use own ID
        $supervisor = $MySelf->getID();
    }
    // Corp tax
    if ($MySelf->isOfficial()) {
        if ($_POST[corpkeeps] > 100 || $_POST[corpkeeps] < 0 || !numericCheckBool($_POST[corpkeeps])) {
            makeNotice("The corporation can not keep more than 100% and most certainly wont pay out more than the gross worth (values below 0%). A value of " . $_POST[corpkeeps] . " is really not valid.", "warning", "Out of range", "index.php?action=newrun", "[Cancel]");
        } else {
            $tax = $_POST[corpkeeps];
        }
    } else {
        $tax = "0";
    }
    /*
    // Get the current ore-values.
    $oreValue = $DB->getCol("SELECT max(time) FROM orevalues");
    $oreValue = $oreValue[0];
    */
    //Edit Starts Here
    $shipValue = $DB->getCol("SELECT max(id) FROM shipvalues");
    $shipValue = $shipValue[0];
    $optype = $_REQUEST[optype];
    //Edit Ends Here
    $DB->query("insert into runs (location, starttime, supervisor, corpkeeps, isOfficial, oreGlue, shipGlue,optype) " . "values (?,?,?,?,?,?,?,?)", array("{$location}", "{$starttime}", "{$supervisor}", $tax, $official, "{$TIMEMARK}", $shipValue, "{$optype}"));
    // Check for success.
    if ($DB->affectedRows() != 1) {
        makeNotice("DB Error: Could not add run to database!", "error", "DB Error");
    }
    // Now update the "required" ore values.
    foreach ($DBORE as $ORE) {
        // But the ore needs to be set, valid (numeric) and must be activated.
        if (isset($_POST[$ORE]) && is_numeric($_POST[$ORE]) && getOreSettings($ORE) == true && $_POST[$ORE] > 0) {
            $DB->query("UPDATE runs SET " . $ORE . "Wanted='" . $_POST[$ORE] . "' WHERE {$starttime}='{$starttime}'");
        }
    }
    // And return the user to the run-list overview page.
    makeNotice("The new Mining Operation has been created in the database.", "notice", "Mining Operation created", "index.php?action=list", "[OK]");
}
Ejemplo n.º 4
0
    $payout_info->addRow("060622");
    $payout_info->addCol("Pilot", array("bold" => true));
    $payout_info->addCol("Percent of Net", array("bold" => true));
    $payout_info->addCol("Payout", array("bold" => true));
    // get the payout array. Fun guaranteed.
    while ($peep = $joinedPeople->fetchRow()) {
        $payoutArray[idToUsername($peep[userid])] = calcPayoutPercent($ID, $peep[userid]);
    }
    // Calulate the percent-modifier.
    $percentModifier = 100 / array_sum($payoutArray);
    // Apply the modifier to the percentage.
    $names = array_keys($payoutArray);
    foreach ($names as $name) {
        $percent = $payoutArray[$name] * $percentModifier;
        $payout = $ISK / 100 * $percent;
        $payout_info->addRow();
        $payout_info->addCol(makeProfileLink(usernameToID($name)));
        $payout_info->addCol(number_format($percent, 2) . "%");
        if ($MySelf->isAccountant()) {
            $payout_info->addCol("<a href=\"index.php?action=showTransactions&id=" . usernameToID($name) . "\">" . number_format($payout, 2) . " ISK</a>");
        } else {
            $payout_info->addCol(number_format($payout, 2) . " ISK");
        }
        $totalPayout = $totalPayout + $payout;
        $totalPercent = $totalPercent + $percent;
    }
    $payout_info->addRow("060622");
    $payout_info->addCol("TOTAL", array("bold" => true));
    $payout_info->addCol(number_format($totalPercent, 2) . "%");
    $payout_info->addCol(number_format($totalPayout, 2) . " ISK");
}
Ejemplo n.º 5
0
function showFailedLogins($limit, $user = false)
{
    global $DB;
    $user = sanitize(stripslashes($user));
    // Specify a user, if given.
    if ($user) {
        $addQuery = "WHERE username = '******'";
    } else {
        $addQuery = "";
    }
    // Set the default results (10)
    if ($limit < 1) {
        $limit = 10;
    }
    // Ask the oracle.
    $FailedDB = $DB->query("SELECT * FROM failed_logins {$addQuery} order by incident desc LIMIT {$limit} ");
    // Check for results.
    if ($FailedDB->numRows() > 0) {
        // We have failed logins.
        $table = new table(5, true);
        // Add a table header accordingly.
        if ($user) {
            $table->addHeader("Failed logins for user " . ucfirst(stripslashes($user)) . ".");
        } else {
            $table->addHeader("Failed logins");
        }
        // Add Table Description
        $table->addRow();
        $table->addCol("Incident");
        $table->addCol("Occurance");
        $table->addCol("IP");
        $table->addCol("Username");
        $table->addCol("Valid Username");
        // 		$table->addCol("Agent");
        // Add the data-rows.
        while ($log = $FailedDB->fetchRow()) {
            $table->addRow();
            $table->addCol(str_pad($log['incident'], 4, "0", STR_PAD_LEFT));
            $table->addCol(date("d.m.y h:i:s", $log['time']));
            $table->addCol($log['ip']);
            if ($log['username_valid']) {
                $userID = usernameToID(stripslashes(sanitize($log['username'])), "Failed_Login");
                if ($userID == -1) {
                    $link = ucfirst(stripslashes(sanitize($log['username'])));
                } else {
                    $link = "<a href=\"index.php?action=edituser&id={$userID}\">" . ucfirst(stripslashes(sanitize($log['username']))) . "</a>";
                }
                $table->addCol($link);
            } else {
                $table->addCol(ucfirst(sanitize($log['username'])));
            }
            $table->addCol(yesno($log['username_valid']));
            // 			$table->addCol($log['agent']);
        }
        $table->addHeaderCentered("Securing your system is your responsibility!");
        return "<br>" . $table->flush();
    } else {
        // No failed logins.
        return false;
    }
}
Ejemplo n.º 6
0
function globalStatistics()
{
    // We need some stuff.
    global $DB;
    global $MySelf;
    /*
     * Global Information
     */
    // Create the header of the table
    $stat_table = new table(2, true);
    $stat_table->addHeader(">> Global Information for " . getConfig("sitename"));
    // Total Users
    $temp = $DB->getCol("SELECT COUNT(id) FROM users WHERE deleted='0'");
    $totalUsers = $temp[0];
    $stat_table->addRow();
    $stat_table->addCol("Total user accounts:");
    $stat_table->addCol(number_format($totalUsers, 0));
    // Total Logins
    $temp = $DB->getCol("SELECT COUNT(authkey) FROM auth");
    $temp = $temp[0];
    $stat_table->addRow();
    $stat_table->addCol("Total logins:");
    $stat_table->addCol(number_format($temp, 0));
    // Total failed logins
    $temp = $DB->getCol("SELECT COUNT(incident) FROM failed_logins");
    $temp = $temp[0];
    $stat_table->addRow();
    $stat_table->addCol("Total failed logins:");
    $stat_table->addCol(number_format($temp, 0));
    // Total API keys
    $temp = $DB->getCol("SELECT COUNT(userid) FROM api_keys");
    $totalApiKeys = $temp[0];
    if ($totalApiKeys > 0) {
        $stat_table->addRow();
        $stat_table->addCol("Total API keys stored:");
        $stat_table->addCol(number_format($totalApiKeys, 0));
        // Total API keys
        $temp = $DB->getCol("SELECT COUNT(userid) FROM api_keys WHERE api_valid=1");
        $totalValidApiKeys = $temp[0];
        $stat_table->addRow();
        $stat_table->addCol("Total API keys validated:");
        $stat_table->addCol(number_format($totalValidApiKeys, 0));
        // Total API keys percentage
        $stat_table->addRow();
        $stat_table->addCol("Percent of stored keys valid:");
        $stat_table->addCol(number_format($totalValidApiKeys * 100 / $totalApiKeys, 2) . "%");
        // Total API keys percentage (over all users)
        $stat_table->addRow();
        $stat_table->addCol("Percent of pilots submited API keys:");
        $stat_table->addCol(number_format($totalApiKeys * 100 / $totalUsers, 2) . "%");
    }
    /*
     * Mining Information
     */
    // Create the header of the table
    $mining_table = new table(2, true);
    $mining_table->addHeader(">> Mining Information for " . getConfig("sitename"));
    // Total Mining Operations
    $temp = $DB->getCol("SELECT COUNT(id) FROM runs WHERE isOfficial = 1");
    $totalMiningOps = $temp[0];
    $mining_table->addRow();
    $mining_table->addCol("Total Mining Operations:");
    $mining_table->addCol(number_format($totalMiningOps, 0));
    // Total Number of Joins
    $temp = $DB->getCol("SELECT COUNT( uJoinups ) FROM (SELECT COUNT( id ) AS uJoinups FROM joinups GROUP BY `run`,`userid`) AS suJoinups");
    $totalJoinUps = $temp[0];
    $mining_table->addRow();
    $mining_table->addCol("Total joinups:");
    $mining_table->addCol(number_format($totalJoinUps, 0));
    // Total Hauling Runs
    $temp = $DB->getCol("SELECT COUNT(id) FROM hauled");
    $totalHaulingRuns = $temp[0];
    $mining_table->addRow();
    $mining_table->addCol("Total Hauling Runs:");
    $mining_table->addCol(number_format($totalHaulingRuns, 0));
    // Total ISK Mined
    $mining_table->addRow();
    $mining_table->addCol("Total ISK mined:");
    $totalIskMined = calculateTotalIskMined();
    $mining_table->addCol(number_format($totalIskMined) . " ISK");
    // Average TMEC
    $aTMEC = $DB->getCol("SELECT AVG(tmec) FROM runs WHERE isOfficial = 1");
    $aTMEC = $aTMEC[0];
    $mining_table->addRow();
    $mining_table->addCol("Average TMEC:");
    if ($aTMEC <= 0) {
        $aTMEC = 0;
    }
    $mining_table->addCol(number_format($aTMEC, 3));
    // Total time spent mining
    $temp = $DB->getCol("SELECT SUM(endtime-starttime) AS time FROM runs WHERE endtime >0 AND isOfficial = 1");
    $time = $temp[0];
    if ($time > 0) {
        $totalTimeSpentMining = $time;
        $string = numberToString($time);
    } else {
        $string = "Never mined at all!";
    }
    $mining_table->addRow();
    $mining_table->addCol("Total time spent mining:");
    $mining_table->addCol($string);
    // Total pilot time
    $time = $DB->getCol("select SUM(parted-joined) as time from joinups WHERE parted >0");
    $time = $time[0];
    $mining_table->addRow();
    $mining_table->addCol("Total time combined from all pilots:");
    if ($time > 0) {
        $totalPilotTime = $time;
        $string = numberToString($time);
    } else {
        $string = "Never mined at all!";
    }
    $mining_table->addCol($string);
    /*
     * Money Stuff
     */
    $trans_Count = $DB->getCol("SELECT COUNT(id) FROM transactions");
    $trans_Count = $trans_Count[0];
    if ($trans_Count > 0) {
        $trans = new table(2, true);
        $trans->addHeader(">> Financial Statistics");
        $trans->addRow();
        $trans->addCol("Total Transactions made:");
        $trans->addCol(number_format($trans_Count, 0));
        $tmw = $DB->getCol("SELECT SUM(amount) FROM transactions WHERE type ='1'");
        $tmd = $DB->getCol("SELECT SUM(amount) FROM transactions WHERE type ='0'");
        $tmw = $tmw[0];
        $tmd = $tmd[0];
        $trans->addRow();
        $trans->addCol("Total Money withdrawn:");
        $trans->addCol(number_format($tmw * -1, 2) . " ISK");
        $trans->addRow();
        $trans->addCol("Total Money deposited:");
        $trans->addCol(number_format($tmd, 2) . " ISK");
        $trans->addRow();
        $trans->addCol("Difference:");
        $trans->addCol(number_format($tmd + $tmw, 2) . " ISK");
        /*
         * Abbreviations:
         * por - PayOutRequests
         * pord - PayOutRequests Done
         * port - PayOutRequests Total
         * portd - PayOutRequests Total Done
         */
        $por = $DB->getCol("SELECT COUNT(request) FROM payoutRequests");
        $port = $DB->getCol("SELECT SUM(amount) FROM payoutRequests");
        $portd = $DB->getCol("SELECT SUM(amount) FROM payoutRequests WHERE payoutTime is NULL");
        $pord = $DB->getCol("SELECT COUNT(request) FROM payoutRequests WHERE payoutTime is NULL");
        $por = $por[0];
        $pord = $pord[0];
        $port = $port[0];
        $portd = $portd[0];
        $trans->addRow();
        $trans->addCol("Total payout requests:");
        $trans->addCol(number_format($por, 0));
        $trans->addRow();
        $trans->addCol("Payout requests fullfilled:");
        $trans->addCol(number_format($por - $pord, 0));
        $trans->addRow();
        $trans->addCol("Payout requests pending:");
        $trans->addCol(number_format($pord, 0));
        $trans->addRow();
        $trans->addCol("Total payout requested:");
        $trans->addCol(number_format($port, 2) . " ISK");
        $trans->addRow();
        $trans->addCol("Total requested paid:");
        $trans->addCol(number_format($port - $portd, 2) . " ISK");
        $trans->addRow();
        $trans->addCol("Total requested open:");
        $trans->addCol(number_format($portd, 2) . " ISK");
        $trans->addHeader("A positive difference means the Corp owes the players, a negative difference means the player owes the Corp.");
        $trans_r = "<br>" . $trans->flush();
    }
    /*
     * Mining Statistics
     */
    // Create the header of the table
    $miningStats_table = new table(2, true);
    $miningStats_table->addHeader(">> Mining Statistics for " . getConfig("sitename"));
    // Average ISK / OP
    $miningStats_table->addRow();
    $miningStats_table->addCol("Average ISK per Op:");
    $miningStats_table->addCol(number_format($totalIskMined / $totalMiningOps, 2) . " ISK");
    // Average ISK/ Hour
    $miningStats_table->addRow();
    $miningStats_table->addCol("Average ISK per hour:");
    $miningStats_table->addCol(number_format($totalIskMined / ceil($totalTimeSpentMining / 3600), 2) . " ISK");
    // Average joinups / Op
    $miningStats_table->addRow();
    $miningStats_table->addCol("Average Joinups per Op:");
    $miningStats_table->addCol(number_format($totalJoinUps / $totalMiningOps, 2));
    // Average hauls per OP:
    $miningStats_table->addRow();
    $miningStats_table->addCol("Average hauls per Op:");
    $miningStats_table->addCol(number_format($totalHaulingRuns / $totalMiningOps, 2));
    /*
     * Hauler statistics
     */
    $haulers = $DB->query("SELECT DISTINCT hauler, COUNT(miningrun) AS runs FROM hauled GROUP BY hauler ORDER BY runs DESC LIMIT 15");
    if ($haulers->numRows() > 0) {
        $hauler_stats = new table(2, true);
        $hauler_stats->addHeader("Most hauling trips");
        while ($h = $haulers->fetchRow()) {
            // place counter.
            $place++;
            $hauler_stats->addRow();
            $hauler_stats->addCol("Place #" . $place . ":");
            $hauler_stats->addCol(makeProfileLink($h[hauler]) . " with " . number_format($h[runs]) . " runs!");
        }
        $hauler_stats_table = "<br>" . $hauler_stats->flush();
    }
    /*
     * Most frequent joiners
     */
    $MFJDB = $DB->query("SELECT COUNT(userid) AS count, userid FROM (SELECT * FROM joinups GROUP BY userid,run) AS ujoinups GROUP BY userid ORDER BY count DESC LIMIT 15");
    if ($MFJDB->numRows() > 0) {
        // Create the header of the table
        $frequentJoiners_table = new table(2, true);
        $frequentJoiners_table->addHeader(">> Most frequent joiners for " . getConfig("sitename"));
        $place = "1";
        while ($FJ = $MFJDB->fetchRow()) {
            $frequentJoiners_table->addRow();
            $frequentJoiners_table->addCol("Place #" . $place . ":");
            $frequentJoiners_table->addCol(makeProfileLink($FJ[userid]) . " with " . $FJ[count] . " joinups!");
            $place++;
        }
        $MFJ_r = "<br>" . $frequentJoiners_table->flush();
    }
    /*
     * Pilot record with mining time
     */
    $PMT = $DB->query("select SUM(parted-joined) AS totaltime, userid from joinups WHERE parted >0 GROUP BY userid ORDER BY totaltime DESC LIMIT 15");
    if ($PMT->numRows() > 0) {
        // Create the header of the table
        $mostOnline_table = new table(2, true);
        $mostOnline_table->addHeader(">> Most time spent mining");
        $place = 1;
        while ($P = $PMT->fetchRow()) {
            $time = $P[totaltime];
            if ($time > 0) {
                $string = numberToString($time);
                $mostOnline_table->addRow();
                $mostOnline_table->addCol("Place #" . $place . ":");
                $mostOnline_table->addCol(makeProfileLink($P[userid]) . " with " . $string);
                $place++;
            }
        }
        $MO_r = "<br>" . $mostOnline_table->flush();
    }
    /*
     * Longest OPS
     */
    $LOPS = $DB->query("select SUM(endtime-starttime) AS totaltime, id, location FROM runs WHERE endtime > 0 AND isOfficial = 1 GROUP BY id ORDER BY totaltime DESC LIMIT 15");
    if ($LOPS->numRows() > 0) {
        // Create the header of the table
        $lops_table = new table(2, true);
        $lops_table->addHeader(">> Longest Ops for " . getConfig("SITENAME"));
        $place = 1;
        while ($OP = $LOPS->fetchRow()) {
            $time = $OP[totaltime];
            if ($time > 0) {
                $string = numberToString($time);
                // Make system clickable.
                $system = new solarSystem($OP[location]);
                $loc = $system->makeFancyLink();
                $lops_table->addRow();
                $lops_table->addCol("Place #" . $place . ": Operation <a href=\"index.php?action=show&id=" . $OP[id] . "\">#" . str_pad($OP[id], 4, "0", STR_PAD_LEFT) . "</a> in " . $loc . ":");
                $lops_table->addCol($string);
                $place++;
            }
        }
        $LOPS_r = "<br>" . $lops_table->flush();
    }
    /*
     * Highest TMEC runs
     */
    // Load the top runs out of the database.
    $TMECDB = $DB->query("SELECT * FROM runs WHERE isOfficial = 1 AND endtime > 0 ORDER BY tmec DESC LIMIT 15");
    // Check that we have any!
    if ($TMECDB->numRows() > 0) {
        // Create table header for tmec.
        $TMEC = new table(3, true);
        $TMEC->addHeader(">> Highest rated TMEC Ops");
        // Reset first place again.
        $place = 1;
        // Now loop through the winners.
        while ($r = $TMECDB->fetchRow()) {
            // Calculate TMEC
            $thisTMEC = calcTMEC($r[id]);
            // This this is TMEC is zero or below.
            if ($thisTMEC <= 0) {
                break;
            }
            // If TMEC > 0, add it.
            $TMEC->addRow();
            // Load the solarsystem its in.
            $system = new solarSystem($r[location]);
            $location = $system->makeFancyLink();
            // Add tmec stuff.
            $TMEC->addCol("Place #" . $place . ":");
            $TMEC->addCol("Op #<a href=\"index.php?action=show&id=" . $r[id] . "\">" . str_pad($r[id], 4, "0", STR_PAD_LEFT) . "</a> in " . $location);
            $TMEC->addCol("Scored a TMEC of " . $thisTMEC . "!");
            // Increase place by one.
            $place++;
        }
        // Render the table.
        $TMEC_r = "<br>" . $TMEC->flush();
    }
    /* 
     * Total mined ore
     */
    /*
     * Assemble the heavy-duty SQL query.
     * It is dynamic because this way we can easily add ores from 
     * config-system.php to the system without code rewrite.
     */
    global $DBORE;
    global $ORENAMES;
    foreach ($DBORE as $ORE) {
        $new = $ORE;
        if ($last) {
            $SQLADD .= "(select coalesce(SUM(Quantity),0) from hauled where Item = '" . $last . "') AS total" . $last . ", ";
        }
        $last = $new;
    }
    $SQLADD .= "(select coalesce(SUM(Quantity),0) from hauled where Item = '" . $last . "') AS total" . $last . " ";
    $SQL = "SELECT " . $SQLADD;
    //$SQL = "select Item, coalesce(SUM(Quantity),0) as total from hauled group by Item";
    // Now query it.
    $totalOREDB = $DB->query("{$SQL}");
    // Create table.
    $totalOre_table = new table(2, true);
    $totalOre_table->addHeader(">> Total ore mined for " . getConfig("SITENAME"));
    // Loop through the result (single result!)
    if ($totalOREDB->numRows() > 0) {
        echo "<!-- Got rows for ore stats -->";
        while ($totalORE = $totalOREDB->fetchRow()) {
            // Now check each ore type.
            foreach ($ORENAMES as $ORE) {
                // And ignore never-hauled ore
                if ($totalORE[total . $DBORE[$ORE]] > 0) {
                    // We got some ore!
                    $totalOre_table->addRow();
                    $totalOre_table->addCol("<img width=\"20\" height=\"20\" src=\"./images/ores/" . $ORE . ".png\">Total " . $ORE . ":");
                    $totalOre_table->addCol(number_format($totalORE[total . $DBORE[$ORE]]));
                    $gotOre = true;
                }
            }
        }
        if ($gotOre) {
            $oretable_r = "<br>" . $totalOre_table->flush();
        }
    }
    /*
     * Assemble the heavy-duty SQL query.
     * It is dynamic because this way we can easily add ships from 
     * config-system.php to the system without code rewrite.
     */
    global $DBSHIP;
    global $SHIPNAMES;
    foreach ($DBSHIP as $SHIP) {
        $new = $SHIP;
    }
    /*
     * Most beloved Systems
     */
    $MBS = $DB->query("select SUM(endtime-starttime) as timespent, location FROM runs WHERE endtime > 0 AND isOfficial = 1 GROUP BY location ORDER BY timespent DESC LIMIT 10");
    if ($MBS->numRows() > 0) {
        $MBST = new table(2, true);
        $MBST->addHeader(">> Most loved locations");
        while ($LOC = $MBS->fetchRow()) {
            if ($LOC[timespent] > 0) {
                $MBST->addRow();
                $system = new solarSystem($LOC[location]);
                $MBST->addCol($system->makeFancyLink());
                $MBST->addCol(numberToString($LOC[timespent]));
            }
        }
        $MBST_r = "<br>" . $MBST->flush();
    }
    /*
     * Most charitable folks
     */
    $charity = $DB->query("SELECT users.username, COUNT(uJoinups.charity) as NOBLE FROM (SELECT * FROM joinups GROUP BY userid,run) as uJoinups, users WHERE users.id = uJoinups.userid AND uJoinups.charity=1 GROUP BY users.username ORDER BY NOBLE DESC, username ASC LIMIT 15");
    if ($charity->numRows() > 0) {
        $charity_table = new table(2, true);
        $charity_table->addHeader(">> Most charitable pilots");
        unset($j);
        while ($c = $charity->fetchRow()) {
            $j++;
            $charity_table->addRow();
            $charity_table->addCol("Place #" . $j . ":");
            $charity_table->addCol(makeProfileLink(usernameToID($c[username])) . " with " . $c[NOBLE] . " charitable acts!");
            $charityCount = $charityCount + $c[NOBLE];
        }
        $charity_table->addHeader("A total of {$charityCount} charitable actions have been recorded.");
        $charity_table = "<br>" . $charity_table->flush();
    }
    $page = "<h2>Global statistics</h2>" . $stat_table->flush() . $trans_r . "<br>" . $mining_table->flush() . "<br>" . $miningStats_table->flush() . $hauler_stats_table . $MFJ_r . $MO_r . $charity_table . $LOPS_r . $TMEC_r . $oretable_r . $MBST_r;
    return $page;
}
Ejemplo n.º 7
0
function onlineTime()
{
    // We need funky globals!
    global $DB;
    global $MySelf;
    global $TIMEMARK;
    /*
     * The change form.
     */
    $MySetting = $DB->query("SELECT * FROM onlinetime WHERE userid='" . $MySelf->getID() . "'");
    $MySetting = $MySetting->numRows();
    if ($MySetting == 0 || $_GET[edit]) {
        $setTable = new table(3, true);
        $setTable->addHeader(">> Set your online time");
        // Fetch el grande saved array. Ole!
        $myOnlineTime = $DB->getAssoc("SELECT * FROM onlinetime WHERE userid='" . $MySelf->getID() . "' LIMIT 1");
        $myOnlineTime = $myOnlineTime[$MySelf->getID()];
        // Loop through the hours.
        $j = 0;
        for ($i = 0; $i <= 23; $i++) {
            // Add a new row every 3rd time we are here, startign with first.
            if ($j == 0) {
                $setTable->addRow();
                $j = 3;
            }
            // 01-02, 02-03.. etc
            $p = str_pad($i, 2, "0", STR_PAD_LEFT) . "-" . str_pad($i + 1, 2, "0", STR_PAD_LEFT);
            // Wow this is ugly. Pre-select all values that are stored in the db.
            $ppdv0 = "<option value=\"0\">0</option>";
            $ppdv1 = "<option value=\"1\">1</option>";
            $ppdv2 = "<option value=\"2\">2</option>";
            $ppdv3 = "<option value=\"3\">3</option>";
            $column = "h" . str_pad($i, 2, "0", STR_PAD_LEFT);
            switch ($myOnlineTime[$column]) {
                case "0":
                    $ppdv0 = "<option selected value=\"0\">0</option>";
                    break;
                case "01":
                    $ppdv1 = "<option selected value=\"1\">1</option>";
                    break;
                case "2":
                    $ppdv2 = "<option selected value=\"2\">2</option>";
                    break;
                case "3":
                    $ppdv3 = "<option selected value=\"3\">3</option>";
                    break;
            }
            $ppd = $ppdv0 . $ppdv1 . $ppdv2 . $ppdv3;
            $s = "<select name=\"{$i}\">";
            $setTable->addCol($p . $s . $ppd . "</select>");
            // Substract one.
            $j--;
        }
        // explain:
        $setTable->addRow();
        $setTable->addCol("Code 0: You cant play at all. (sleep, work)", array("colspan" => 3));
        $setTable->addRow();
        $setTable->addCol("Code 1: You could, but normaly wouldnt, except for extreme cases.", array("colspan" => 3));
        $setTable->addRow();
        $setTable->addCol("Code 2: You can easily be online, but normaly are not.", array("colspan" => 3));
        $setTable->addRow();
        $setTable->addCol("Code 3: Your preffered online time.", array("colspan" => 3));
        $submitbutton = "<input type=\"hidden\" name=\"check\" value=\"true\">" . "<input type=\"hidden\" value=\"modonlinetime\" name=\"action\">" . "<input type=\"submit\" value=\"Update your OnlineTime\" name=\"submit\">";
        $setTable->addHeaderCentered("All times are EvE time!");
        $setTable->addHeaderCentered($submitbutton);
        $form .= "<form action=\"index.php\" method=\"POST\">";
        $form .= $setTable->flush();
        $form .= "</form>";
    } else {
        $editLink = "<br>[<a href=\"index.php?action=onlinetime&edit=true\">Edit your times</a>]";
    }
    $page = "<h2>Online Time</h2>" . $form;
    /*
     * Okay pheew. That was the table to set your own time. Now lets create
     * a table to show everyones online time.
     */
    $onlineTime = new table(25, true);
    $onlineTime->addHeader(">> Online Time of your corporation");
    $onlineTime->addRow("#060622");
    $onlineTime->addCol("Member");
    $onlineTime->addCol("00");
    $onlineTime->addCol("01");
    $onlineTime->addCol("02");
    $onlineTime->addCol("03");
    $onlineTime->addCol("04");
    $onlineTime->addCol("05");
    $onlineTime->addCol("06");
    $onlineTime->addCol("07");
    $onlineTime->addCol("08");
    $onlineTime->addCol("09");
    $onlineTime->addCol("10");
    $onlineTime->addCol("11");
    $onlineTime->addCol("12");
    $onlineTime->addCol("13");
    $onlineTime->addCol("14");
    $onlineTime->addCol("15");
    $onlineTime->addCol("16");
    $onlineTime->addCol("17");
    $onlineTime->addCol("18");
    $onlineTime->addCol("19");
    $onlineTime->addCol("20");
    $onlineTime->addCol("21");
    $onlineTime->addCol("22");
    $onlineTime->addCol("23");
    // Ask the oracle.
    $cutOff = $TIMEMARK - 2592000;
    // 30 days.
    $OT = $DB->getCol("select distinct id from users where canLogin='******' and lastlogin >= '{$cutOff}'  AND deleted='0'");
    // Pilots names are not store in the onlinetable. So we have to translate.
    foreach ($OT as $pilotID) {
        $pilots[] = idToUsername($pilotID);
    }
    // Anyone published his online time yet?
    if (count($pilots) >= 1) {
        $haveOnlineTime = true;
    }
    // Sort the pilots by name.
    asort($pilots);
    // Create a row for each pilot.
    foreach ($pilots as $pilot) {
        // Get the pilots online times.
        $id = usernameToID($pilot);
        $ot = $DB->query("SELECT * FROM onlinetime WHERE userid='" . $id . "'");
        // break off here if the user has not publishes his online time yet.
        if ($ot->numRows() == 0) {
            continue;
        }
        $ot = $ot->fetchRow();
        $onlineTime->addRow();
        // Pilot name
        $onlineTime->addCol(ucfirst($pilot));
        // And go through each hour, creating a nice coloured box.
        for ($i = 0; $i <= 23; $i++) {
            $column = "h" . str_pad($i, 2, "0", STR_PAD_LEFT);
            // #222733  |  #4f646e  |  #c2c957  |  #e6f137
            switch ($ot[$column]) {
                case "0":
                    $onlineTime->addCol(" ", array("bgcolor" => "#222733"));
                    break;
                case "01":
                    $onlineTime->addCol(" ", array("bgcolor" => "#4f646e"));
                    break;
                case "2":
                    $onlineTime->addCol(" ", array("bgcolor" => "#c2c957"));
                    break;
                case "3":
                    $onlineTime->addCol(" ", array("bgcolor" => "#e6f137"));
                    break;
            }
        }
    }
    // Return the hard labor.
    /* Return the Online Table, or, If no one published his online time yet,
     * print a message saying just that. */
    if ($haveOnlineTime) {
        // We have at least one person who sent in his times.
        return $page . $onlineTime->flush() . $editLink;
    } else {
        // No one ever sent in his times.
        return $page . "<b>No one sent in his/her onlinetimes yet. But you can be the first! :)</b><br>" . $editLink;
    }
}
Ejemplo n.º 8
0
function endrun()
{
    global $DB;
    global $TIMEMARK;
    global $MySelf;
    // Is $_GET[id] truly a number?
    numericCheck($_GET[id]);
    // Are we allowed to close runs?
    $supervisor = $DB->getCol("SELECT supervisor FROM runs WHERE id='" . $_GET[id] . "' LIMIT 1");
    if (!$MySelf->canCloseRun() && $MySelf->getID() != $supervisor[0]) {
        makeNotice("You are not allowed to close runs!", "error", "forbidden");
    }
    // We sure about this?
    confirm("Are you sure you want to close mining operation {$_GET['id']}? " . "This will remove any active pilots that are still on this" . " run, and close this run for good.");
    // Run already closed?
    if (!miningRunOpen($_GET[id])) {
        makeNotice("This mining operation has already been closed!", "warning", "Operation closed already", "index.php?action=show&id={$_GET['id']}");
    }
    // Moved to the end of the payout to allow correct calculations
    // Update the database.
    //$DB->query("update runs set endtime = '$TIMEMARK' where id = '$_GET[id]' and endtime is NULL");
    // now "eject" all members.
    //$DB->query("update joinups set parted = '$TIMEMARK' where parted is NULL and run = '$_GET[id]'");
    // Calculate Payout, IF this is an official run.
    $ID = $_GET[id];
    $OfficialRun = $DB->getCol("SELECT isOfficial FROM runs WHERE id='{$ID}'");
    // calculate the total value of this op.
    $ISK = getTotalWorth($ID, true);
    if ($OfficialRun[0] && getTotalWorth($ID) != 0) {
        // Select all people, except banned ones.
        $joinedPeople = $DB->query("SELECT DISTINCT userid FROM joinups WHERE run ='{$ID}' AND status < 2");
        // Also, create the charity array.
        $charityDB = $DB->query("SELECT userid, charity FROM joinups WHERE run ='{$ID}' AND status < 2");
        while ($c = $charityDB->fetchRow()) {
            $charityArray[$c[userid]] = $c[charity];
        }
        // get the payout array. Fun guaranteed.
        while ($peep = $joinedPeople->fetchRow()) {
            $payoutArray[$peep[userid]] = calcPayoutPercent($ID, $peep[userid]);
        }
        // Calulate the percent-modifier.
        $percentModifier = 100 / array_sum($payoutArray);
        // Apply the modifier to the percentage.
        $names = array_keys($payoutArray);
        // Add the credit.
        $supervisor = usernameToID(runSupervisor($_GET[id]));
        foreach ($names as $name) {
            $percent = $payoutArray[$name] * $percentModifier;
            $payout = $ISK / 100 * $percent;
            // You cannot loose isk from a mission.
            if ($payout != 0 && !$charityArray[$name]) {
                addCredit($name, $supervisor, $payout, $_GET[id]);
                $finalPercent[$name] = $payout;
            }
        }
        // Moved to the end of the payout to allow correct calculations
        // Update the database.
        $DB->query("update runs set endtime = '{$TIMEMARK}' where id = '{$ID}' and endtime is NULL");
        // now "eject" all members.
        $DB->query("update joinups set parted = '{$TIMEMARK}' where parted is NULL and run = '{$ID}'");
        // wrap things up.
        makeEmailReceipt($ID, $finalPercent);
        makeNotice("The mining operation has ended. All still active pilots have been removed from the run and each pilot has been credited his share of the net income.", "notice", "Mining Operation closed", "index.php?action=list", "[OK]");
    }
    // Moved to the end of the payout to allow correct calculations
    // Update the database.
    $DB->query("update runs set endtime = '{$TIMEMARK}' where id = '{$ID}' and endtime is NULL");
    // now "eject" all members.
    $DB->query("update joinups set parted = '{$TIMEMARK}' where parted is NULL and run = '{$ID}'");
    // wrap things up.
    makeNotice("The mining operation has ended. All still active pilots have been removed from the run.", "notice", "Mining Operation closed", "index.php?action=list", "[OK]");
}