Example #1
0
function q17($from, $to)
{
    $length = 0;
    for ($i = $from; $i <= $to; ++$i) {
        $numberString = numberToString($i);
        //		echo $i . ': ' .  . PHP_EOL;
        $numberString = str_replace(' ', '', $numberString);
        $length += strlen($numberString);
    }
    return $length;
}
Example #2
0
function checkBan()
{
    // We need the database and the current time.
    global $DB;
    global $TIMEMARK;
    // Get the ban time, the maximum attempts etc..
    $maxAllowedPerIP = getConfig("banAttempts");
    $banTime = getConfig("banTime") * 60;
    $timeFrame = 1800;
    $targetTimeStamp = $TIMEMARK - $timeFrame;
    // Enforce minimal settings.
    if ($maxAllowedPerIP < 5) {
        setConfig("banAttempts", "5");
        $maxAllowedPerIP = 5;
    }
    if ($banTime < 60) {
        setConfig("banTime", "1");
        $banTime = 60;
    }
    // Wash the username and IP.
    $username = strtolower(sanitize($_POST[username]));
    $ip = $_SERVER[REMOTE_ADDR];
    // Load counts from database.
    $attemptsIP = $DB->getCol("SELECT COUNT(incident) FROM failed_logins WHERE ip='" . $ip . "' AND failed_logins.time > " . $targetTimeStamp);
    $attemptsUsername = $DB->getCol("SELECT COUNT(incident) FROM failed_logins WHERE username='******' AND failed_logins.time > " . $targetTimeStamp);
    // Deny access if limits reached.
    if ($attemptsIP[0] > $maxAllowedPerIP || $attemptsUsername[0] > $maxAllowedPerIP) {
        // Get the time of the latest attempt.
        $latestAttempt = $DB->getCol("SELECT time FROM failed_logins WHERE ip='" . $ip . "' OR username='******' ORDER BY time DESC LIMIT 1");
        // Lets check if that is still in the baaaaad area.
        if ($latestAttempt[0] + $banTime > $TIMEMARK) {
            // Still banned.
            $remain = numberToString($latestAttempt[0] + $banTime - $TIMEMARK);
            makeNotice("You have reached the maximum number of login attempts. You are temporarily banned for " . number_format($banTime / 60, 0) . " minutes. Time left on ban: " . $remain, "error", "Banned");
        }
    }
    // If we get here, all is good.
}
Example #3
0
function browser()
{
    // Wash the incoming.
    numericCheck(sanitize($_GET[mode]));
    numericCheck(sanitize($_GET[id]));
    $id = $_GET[id];
    $mode = $_GET[mode];
    global $DB;
    // We differ between 0 = system (detailed), 1 = constellation and 2 = region.
    switch ($_GET[mode]) {
        case "0":
            $solar = new solarSystem($id);
            $table = $solar->makeInfoTable();
            //Current Runs in System
            $openRuns = $DB->query("SELECT * FROM runs WHERE location = '" . $solar->getName() . "' AND endtime IS NULL ORDER BY id");
            if ($openRuns->numRows() > 0) {
                $openRunsTable = new table(2, true);
                $openRunsTable->addHeader(">> Current runs in " . $solar->getName());
                // We need this for a new table line.
                $newline = true;
                // Loop through all solarsystems.
                while ($openRun = $openRuns->fetchRow()) {
                    // If this is a new table row, add one.
                    if ($newline) {
                        $openRunsTable->addRow();
                        $newline = false;
                    } else {
                        $newline = true;
                    }
                    // Add the information.
                    $openRunsTable->addCol("<a href=\"index.php?action=show&id=" . $openRun[id] . "\">#" . str_pad($openRun[id], 4, "0", STR_PAD_LEFT . "</a>"));
                }
                if (!$newline) {
                    $openRunsTable->addCol();
                }
                $openRunsStuff = $openRunsTable->flush();
            }
            //Past Runs in System
            $Runs = $DB->query("SELECT * FROM runs WHERE location = '" . $solar->getName() . "' AND endtime > 0 ORDER BY id");
            if ($Runs->numRows() > 0) {
                $RunsTable = new table(2, true);
                $RunsTable->addHeader(">> Past runs in " . $solar->getName());
                // We need this for a new table line.
                $newline = true;
                // Loop through all solarsystems.
                while ($Run = $Runs->fetchRow()) {
                    // If this is a new table row, add one.
                    if ($newline) {
                        $RunsTable->addRow();
                        $newline = false;
                    } else {
                        $newline = true;
                    }
                    // Add the information.
                    $RunsTable->addCol("<a href=\"index.php?action=show&id=" . $Run[id] . "\">#" . str_pad($Run[id], 4, "0", STR_PAD_LEFT . "</a>"));
                }
                if (!$newline) {
                    $RunsTable->addCol();
                }
                // Get the total time spent in this System.
                $time = $DB->getCol("SELECT SUM(endtime - starttime) FROM runs WHERE location='" . $solar->getName() . "'");
                $time = numberToString($time[0]);
                $RunsTable->addHeaderCentered("Time spent in " . $solar->makeFancyLink() . ": " . $time);
                $RunsStuff = $RunsTable->flush();
            }
            $solarStuff = $solar->makeConstellationTable();
            break;
    }
    return "<h2>Solar System Information</h2>" . $table . "<br>" . $solarStuff . "<br>" . $openRunsStuff . "<br>" . $RunsStuff;
}
Example #4
0
function profile()
{
    // The usual suspects.
    global $MySelf;
    global $DB;
    // Set the ID.
    $ID = sanitize($_GET[id]);
    numericCheck($_GET[id], 0);
    // Load the profile.
    $profile = new profile($ID);
    $username = ucfirst(idToUsername($ID));
    // Cache our permissions.
    $canSeeUsers = $MySelf->canSeeUsers();
    // Need the api.
    $api = new api($ID);
    // Create table header.
    $table = new table(2, true);
    $table->addHeader(">> About " . $username);
    $table->addRow();
    $table->addCol("Current rank:");
    $table->addCol(getRank($ID));
    $table->addRow();
    $table->addCol("Last login:"******"SELECT lastlogin FROM users WHERE id='" . $ID . "' AND deleted='0' LIMIT 1");
    $table->addCol(date("d.m.y. H:i:s", $lastLog[0]));
    $table->addRow();
    $table->addCol("Total logins:");
    $lastLog = $DB->getCol("SELECT COUNT(authkey) FROM auth WHERE user='******' LIMIT 1");
    $table->addCol(number_format($lastLog[0], 0));
    $table->addRow();
    $table->addCol("Valid api-key on file:");
    $table->addCol(yesno($api->valid(), true));
    $table->addRow();
    $table->addCol("Is available for mining:");
    if ($profile->isOwn()) {
        if ($profile->MinerFlag()) {
            $temp = " [<a href=\"index.php?action=modprofile&id=" . $ID . "&mining=false\">set not available</a>]";
        } else {
            $temp = " [<a href=\"index.php?action=modprofile&id=" . $ID . "&mining=true\">set available</a>]";
        }
    }
    $table->addCol(yesno($profile->MinerFlag(), true) . $temp);
    $table->addRow();
    $table->addCol("Is available for hauling:");
    if ($profile->isOwn()) {
        if ($profile->HaulerFlag()) {
            $temp = " [<a href=\"index.php?action=modprofile&id=" . $ID . "&hauling=false\">set not available</a>]";
        } else {
            $temp = " [<a href=\"index.php?action=modprofile&id=" . $ID . "&hauling=true\">set available</a>]";
        }
    }
    $table->addCol(yesno($profile->HaulerFlag(), true) . $temp);
    $table->addRow();
    $table->addCol("Is available for fighting:");
    if ($profile->isOwn()) {
        if ($profile->FighterFlag()) {
            $temp = " [<a href=\"index.php?action=modprofile&id=" . $ID . "&fighting=false\">set not available</a>]";
        } else {
            $temp = " [<a href=\"index.php?action=modprofile&id=" . $ID . "&fighting=true\">set available</a>]";
        }
    }
    $table->addCol(yesno($profile->FighterFlag(), true) . $temp);
    if ($profile->emailVisible() || $profile->isOwn()) {
        if ($profile->isOwn()) {
            if ($profile->emailVisible()) {
                $temp = " (public) [<a href=\"index.php?action=modprofile&id=" . $ID . "&email=hide\">hide from public</a>]";
            } else {
                $temp = " (hidden) [<a href=\"index.php?action=modprofile&id=" . $ID . "&email=show\">make public</a>]";
            }
        }
        $table->addRow();
        $table->addCol("Email address:");
        $email = $DB->getCol("SELECT email FROM users WHERE id='" . $ID . "' LIMIT 1");
        $table->addCol($email[0] . $temp);
    }
    // Statistics.
    $stats = new table(2, true);
    $stats->addHeader(">> Statistical breakdown");
    $miningRunsJoined = $DB->getCol("SELECT COUNT(id) FROM joinups WHERE userid='" . $ID . "'");
    $miningRunsJoined = $miningRunsJoined[0];
    $OpjoinUps = $DB->getCol("SELECT COUNT(id) FROM joinups WHERE userid='" . $ID . "'");
    $OpjoinUps = $OpjoinUps[0];
    $joinUps = $DB->getCol("SELECT COUNT(id) FROM (SELECT * from joinups WHERE userid='" . $ID . "' GROUP BY run) as uJoinups");
    $joinUps = $joinUps[0];
    $haulingRuns = $DB->getCol("SELECT COUNT(id) FROM hauled WHERE hauler='" . $ID . "'");
    $haulingRuns = $haulingRuns[0];
    $timeMining = $DB->getCol("SELECT SUM(parted - joined) FROM joinups WHERE userid='" . $ID . "' AND parted >1");
    $timeMining = $timeMining[0];
    $timesKicked = $DB->getCol("SELECT COUNT(id) FROM joinups WHERE userid='" . $ID . "' AND status='1'");
    $timesKicked = $timesKicked[0];
    $timesRemoved = $DB->getCol("SELECT COUNT(id) FROM joinups WHERE userid='" . $ID . "' AND status='2'");
    $timesRemoved = $timesRemoved[0];
    $timesBanned = $DB->getCol("SELECT COUNT(id) FROM joinups WHERE userid='" . $ID . "' AND status='3'");
    $timesBanned = $timesBanned[0];
    $timesCharity = $DB->getCol("SELECT COUNT(id) FROM (SELECT * from joinups WHERE userid='" . $ID . "' GROUP BY run) as uJoinups WHERE userid='" . $ID . "' AND charity='1'");
    $timesCharity = $timesCharity[0];
    $tmec = $DB->getCol("SELECT AVG(tmec) FROM runs WHERE isOfficial = 1");
    $tmecJoined = $DB->getCol("SELECT AVG(runs.tmec) FROM joinups, runs WHERE joinups.userid='" . $ID . "' AND joinups.run = runs.id AND runs.endtime > 0 AND runs.isOfficial = 1");
    $tmecNotJoined = $DB->getCol("SELECT AVG(runs.tmec) FROM joinups, runs WHERE joinups.userid='" . $ID . "' AND joinups.run <> runs.id AND runs.endtime > 0 AND runs.isOfficial = 1");
    $tmecDiff = $tmecJoined[0] - $tmecNotJoined[0];
    $stats->addRow();
    $stats->addCol("Mining operations joined:");
    if ($miningRunsJoined > 0) {
        $stats->addCol(number_format($joinUps, 0));
    } else {
        $stats->addCol("never joined.");
    }
    $stats->addRow();
    $stats->addCol("Total operations joinups:");
    if ($OpjoinUps > 0) {
        $stats->addCol(number_format($OpjoinUps, 0));
    } else {
        $stats->addCol("never joined.");
    }
    $stats->addRow();
    $stats->addCol("Hauling runs:");
    if ($haulingRuns > 0) {
        $stats->addCol(number_format($haulingRuns, 0));
    } else {
        $stats->addCol("never hauled.");
    }
    $stats->addRow();
    $stats->addCol("Time spent mining:");
    if ($timeMining > 0) {
        $stats->addCol(numberToString($timeMining));
    } else {
        $stats->addCol("never mined.");
    }
    $stats->addRow();
    $stats->addCol("Average TMEC:");
    $stats->addCol(number_format($tmec[0], 3));
    $stats->addRow();
    $stats->addCol("Average TMEC on Ops <b>with</b> " . $username . ":");
    $stats->addCol(number_format($tmecJoined[0], 3));
    $stats->addRow();
    $stats->addCol("Average TMEC on Ops <b>without</b> " . $username . ":");
    $stats->addCol(number_format($tmecNotJoined[0], 3));
    $stats->addRow();
    $stats->addCol("TMEC difference:");
    if ($tmecDiff >= 0) {
        $stats->addCol("<font color=\"#00ff00\">" . number_format($tmecDiff, 3), true . "</font>");
    } else {
        $stats->addCol("<font color=\"#ff0000\">" . number_format($tmecDiff, 3), true . "</font>");
    }
    $stats->addRow();
    $stats->addCol("Times removed from OP:");
    $stats->addCol(number_format($timesRemoved, 0));
    $stats->addRow();
    $stats->addCol("Times kicked from OP:");
    $stats->addCol(number_format($timesKicked, 0));
    $stats->addRow();
    $stats->addCol("Times banned from OP:");
    $stats->addCol(number_format($timesBanned, 0));
    $stats->addRow();
    $stats->addCol("Times declared charity:");
    $stats->addCol(number_format($timesCharity, 0));
    /*
     * 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 .= "SUM(" . $last . ") AS total" . $last . ", ";
    		}
    		$last = $new;
    	}
    	$SQLADD .= "SUM(" . $last . ") AS total" . $last . " ";
    	$SQL = "SELECT " . $SQLADD . " FROM hauled WHERE hauler='" . $ID . "'";
    
    	// Now query it.
    	$totalOREDB = $DB->query("$SQL");
    	
    
    if (DB::isError($totalOREDB)) {
        *
         * This is not what you would really want to do in
         * your program.  It merely demonstrates what kinds
         * of data you can get back from error objects.
         *
        echo 'Standard Message: ' . $totalOREDB->getMessage() . "\n";
        echo '\n ';
        echo 'Standard Code: ' . $totalOREDB->getCode() . "\n";
        echo '\n ';
        echo 'DBMS/User Message: ' . $totalOREDB->getUserInfo() . "\n";
        echo '\n ';
        echo 'DBMS/Debug Message: ' . $totalOREDB->getDebugInfo() . "\n";
        echo '\n ';
        exit;
    }
    
    	// Create table.
    	$totalOre_table = new table(2, true);
    	$totalOre_table->addHeader(">> Total ore hauled");
    
    	// Loop through the result (single result!)
    	if ($totalOREDB->numRows() > 0) {
    		while ($totalORE = $totalOREDB->fetchRow()) {
    			// Now check each ore type.
    			foreach ($ORENAMES as $ORE) {
    				// And ignore never-hauled ore
    				if ($totalORE[total . $ORE] > 0) {
    					// We got some ore!
    					$totalOre_table->addRow();
    					$totalOre_table->addCol("<img width=\"20\" height=\"20\" src=\"./images/ores/" . $ORE . ".png\">Total " . $ORE . " hauled:");
    					$totalOre_table->addCol(number_format($totalORE[total . $ORE]));
    					$gotOre = true;
    				}
    			}
    		}
    		if ($gotOre) {
    			$oretable_r = "<br>" . $totalOre_table->flush();
    		}
    	}
    */
    // Image thingy.
    // We serve small images IGB.
    global $IGB;
    global $IGB_VISUAL;
    if ($IGB && $IGB_VISUAL) {
        $image = "<img src=\"portrait:" . $api->getCharacterID() . "\" SIZE=\"128\">";
    } else {
        $image = $profile->getImage("large");
    }
    $picTable = new table(true, 1);
    $picTable->addHeader(">> Picture of " . $username);
    $picTable->addRow();
    $picTable->addCol($image);
    $imageTable = $picTable->flush();
    // About
    if ($profile->GetAbout() && !$profile->isOwn()) {
        $aboutTable = new table(1, true);
        $aboutTable->addHeader(">> " . $username . " says...");
        $aboutTable->addRow();
        $aboutTable->addCol(nl2br($profile->GetAbout()));
        $aboutTable = "<br>" . $aboutTable->flush();
    }
    if ($profile->isOwn()) {
        $aboutTable = new table(1, true);
        $aboutTable->addHeader(">> Enter a public viewable text here");
        $aboutTable->addRow();
        $form = "<form action=\"index.php\" method=\"POST\">";
        $form .= "<input type=\"hidden\" name=\"check\" value=\"true\">";
        $form .= "<input type=\"hidden\" name=\"action\" value=\"modprofile\">";
        $form .= "<input type=\"hidden\" name=\"id\" value=\"" . $ID . "\">";
        $aboutTable->addCol("<textarea rows=\"18\" cols=\"80\" name=\"about\">" . $profile->GetAbout() . "</textarea>");
        $aboutTable->addHeaderCentered("<input type=\"submit\" name=\"submit\" value=\"Update about\">");
        $aboutTable = "<br>" . $form . $aboutTable->flush() . "</form>";
    }
    // quick "jump to" -thingy.
    $peeps = $DB->query("SELECT DISTINCT username,id FROM users WHERE deleted = 0 AND canLogin = 1 ORDER BY username ASC");
    if ($peeps->numRows() > 0) {
        while ($p = $peeps->fetchRow()) {
            if ($ID == $p[id]) {
                $pdm .= "<option SELECTED value=\"" . $p[id] . "\">" . ucfirst($p[username]) . " (current)</option>";
            } else {
                $pdm .= "<option value=\"" . $p[id] . "\">" . ucfirst($p[username]) . "</option>";
            }
        }
        $pdm = "<select name=\"id\">" . $pdm . "</select></form>";
        $quickChooser = new table(1, true);
        $quickChooser->addHeader(">> Quick jump to profile");
        $quickChooser->addRow();
        $quickChooser->addCol($pdm);
        $quickChooser->addHeaderCentered("<input type=\"submit\" name=\"submit\" value=\"Switch\">");
        $quickChooser = "<form action=\"index.php\" method=\"GET\"><input type=\"hidden\" name=\"action\" value=\"profile\">" . $quickChooser->flush() . "</form>";
    }
    $page = "<h2>View profile</h2>" . $quickChooser . $imageTable . "<br>" . $table->flush() . "<br>" . $stats->flush() . $oretable_r . $aboutTable;
    return $page;
}
Example #5
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;
}
Example #6
0
function makeCanPage()
{
    // Defining some globals.
    global $DB;
    global $TIMEMARK;
    global $MySelf;
    global $PREFS;
    $USERNAME = $MySelf->getUsername();
    $USERID = $MySelf->getID();
    $TTL = getConfig("canLifeTime") * 60;
    // is the cargo module active?
    if (!getConfig("cargocontainer")) {
        makeNotice("The admin has deactivated the events module.", "warning", "Module not active");
    }
    // Get all current locations.
    $locations = $DB->getCol("SELECT DISTINCT location FROM runs ORDER BY location");
    // Get all current cans.
    $cans = $DB->getAssoc("SELECT * from cans");
    // Get last can-nr.
    $canNaming = $PREFS->getPref("CanNaming");
    // Query the database accordingly.
    if ($canNaming == 1) {
        $maxCan = $DB->getCol("SELECT MAX(name) as max FROM cans WHERE pilot = '{$USERID}'");
    } else {
        $maxCan = $DB->getCol("SELECT MAX(name) as max FROM cans");
    }
    // For can-naming: Increment the number.
    if ($maxCan[0] == "") {
        // No can jettisoned yet.
        $canname = "001";
    } else {
        if (is_numeric($maxCan[0])) {
            // Can ejected, and it is numeric, we can increase that number.
            $canname = str_pad($maxCan[0] + 1, "3", "0", STR_PAD_LEFT);
        } else {
            // User entered some non-numerical stuff, can not increase.
            unset($canname);
        }
    }
    // Get the system the users mining operation takes place in, if any.
    $myRun = userInRun($USERNAME);
    if ($myRun != false) {
        $myLocation = $DB->getCol("SELECT location FROM runs WHERE id='{$myRun}'");
        $myLocation = $myLocation[0];
    }
    // Assemble the locations dropdown menu.
    if (!empty($locations)) {
        // Loop through all the locations.
        foreach ($locations as $location) {
            // And preselect the location the users miningrun takes place, if any.
            if ("{$location}" == "{$myLocation}") {
                $ddm .= "<option selected value=\"{$location}\">{$location}</option>";
            } else {
                $ddm .= "<option value=\"{$location}\">{$location}</option>";
            }
        }
    }
    // Select all current cans owned by the pilot.
    $CansDS = $DB->query("SELECT location, droptime, name, id, isFull, miningrun FROM cans WHERE pilot = '{$USERID}' ORDER BY droptime ASC");
    if ($CansDS->numRows() > 0) {
        // We have at least one can out there, lets do this.
        $myCans = new table(7, true);
        $myCans->addHeader(">> My cargo containers in space");
        $mode = array("bold" => true);
        $myCans->addRow("#060622");
        $myCans->addCol("Name", $mode);
        $myCans->addCol("Location", $mode);
        $myCans->addCol("Self or Run", $mode);
        $myCans->addCol("Droptime", $mode);
        $myCans->addCol("est. Poptime", $mode);
        $myCans->addCol("Time Left", $mode);
        $myCans->addCol("Can is full", $mode);
        while ($can = $CansDS->fetchRow()) {
            $candroptime = $can[droptime];
            // Time of can drop.
            $poptime = $candroptime + $TTL;
            // Extimated pop time (droptime + 1h)
            $timeleft = $candroptime + $TTL - $TIMEMARK;
            // Time left (poptime - current time)
            $minsleft = str_pad(number_format(($timeleft - 60) / 60, 0), "2", "0", STR_PAD_LEFT);
            $secsleft = str_pad($timeleft % 60, "2", "0", STR_PAD_LEFT);
            if ($secsleft < 1) {
                // We want all negative amounts to read "00".
                $secsleft = "00";
            }
            // Colorize the remaining time
            if ($minsleft >= 30) {
                // More or equal 30 mins: Green. We are cool.
                $color = "#88ff88";
            } elseif ($minsleft <= 29 && $minsleft >= 15) {
                // Less or equal 29 mins: Yellow, keep an eye out.
                $color = "#FFFF00";
            } elseif ($minsleft < 15) {
                // Less than 15 minutes: Ayee! RED! Refresh!s
                $color = "#FF0000";
            }
            $myCans->addRow();
            $myCans->addCol("<a href=\"index.php?action=popcan&id={$can['id']}\"><b>{$can['name']}</b></a>");
            $system = new solarSystem($can[location]);
            $myCans->addCol($system->makeFancyLink());
            // Can for self or mining run?
            if ($can[miningrun] >= 0) {
                $myCans->addCol("<a href=\"index.php?action=show&id={$can['miningrun']}\">" . str_pad($can[miningrun], "5", "0", STR_PAD_LEFT) . "</a>");
            } else {
                $myCans->addCol("(for self)");
            }
            $myCans->addCol(date("H:i:s", $can[droptime]));
            $myCans->addCol(date("H:i:s", $poptime));
            // Can popped already?
            if ($minsleft > 0) {
                $myCans->addCol("<font color=\"{$color}\">" . numberToString($timeleft) . "</font>");
            } else {
                $myCans->addCol("<font color=\"{$color}\">POPPED</font>");
            }
            // Can full?
            if ($can[isFull]) {
                $myCans->addCol("<a href=\"index.php?action=togglecan&canid={$can['id']}\"><font color=\"#00ff00\">YES</font></a>");
            } else {
                $myCans->addCol("<a href=\"index.php?action=togglecan&canid={$can['id']}\">No</a>");
            }
        }
        // The delete all button.
        $myCans->addHeaderCentered("[<a href=\"index.php?action=popcan&id=all\">pop all cans</a>]");
        $MyCansExist = true;
    }
    // Select all current cans, belonging to the mining run.
    $MiningRun = userInRun($MySelf->getUsername());
    if ($MiningRun) {
        $CansDS = $DB->query("SELECT location, droptime, name, pilot, isFull, miningrun FROM cans WHERE miningrun='{$MiningRun}' ORDER BY droptime ASC");
        if ($CansDS->numRows() > 0) {
            // We got one or more can floating around that belong to our mining run.
            $runCans = new table(7, true);
            $runCans->addHeader(">> My operations's cargo containers in space");
            $runCans->addRow("#060622");
            $runCans->addCol("Name", $mode);
            $runCans->addCol("Owner", $mode);
            $runCans->addCol("Location", $mode);
            $runCans->addCol("Droptime", $mode);
            $runCans->addCol("est. Poptime", $mode);
            $runCans->addCol("time remaining", $mode);
            $runCans->addCol("is full", $mode);
            while ($can = $CansDS->fetchRow()) {
                // Same as above.
                $candroptime = $can[droptime];
                $timeleft = $candroptime + $TTL - $TIMEMARK;
                $minsleft = str_pad(number_format(($timeleft - 60) / 60, 0), "2", "0", STR_PAD_LEFT);
                $secsleft = str_pad($timeleft % 60, "2", "0", STR_PAD_LEFT);
                $poptime = $candroptime + $TTL;
                // No negative minutes..
                if ($secsleft < 1) {
                    $secsleft = "00";
                }
                // Colorize..
                if ($minsleft >= 30) {
                    $color = "#88ff88";
                } elseif ($minsleft < 29 && $minsleft >= 15) {
                    $color = "#FFFF00";
                } elseif ($minsleft < 15) {
                    $color = "#FF0000";
                }
                // Build table..
                $runCans->addRow();
                $runCans->addCol($can[name]);
                $runCans->addCol(idToUsername($can[pilot]));
                $system = new solarSystem($can[location]);
                $runCans->addCol($system->makeFancyLink());
                $runCans->addCol(date("H:i:s", $can[droptime]));
                $runCans->addCol(date("H:i:s", $poptime));
                // Can popped already?
                if ($minsleft > 0) {
                    $runCans->addCol("<font color=\"{$color}\">" . numberToString($timeleft) . "</font>");
                } else {
                    $runCans->addCol("<font color=\"{$color}\">POPPED</font>");
                }
                // Can full?
                if ($can[isFull]) {
                    $runCans->addCol("<font color=\"#00ff00\">YES</font>");
                } else {
                    $runCans->addCol("No");
                }
            }
            $runCansExists = true;
        }
    }
    // Select all current cans, regardless
    $CansDS = $DB->query("SELECT location, droptime, name, pilot, isFull FROM cans WHERE pilot <> '{$USERID}' ORDER BY droptime ASC");
    if ($CansDS->numRows() > 0) {
        // There is at least.. yeah..
        $allCans = new table(7, true);
        $allCans->addHeader(">> All containers floating in space");
        $allCans->addRow("#060622");
        $allCans->addCol("Name", $mode);
        $allCans->addCol("Owner", $mode);
        $allCans->addCol("Location", $mode);
        $allCans->addCol("Droptime", $mode);
        $allCans->addCol("est. Poptime", $mode);
        $allCans->addCol("time remaining", $mode);
        $allCans->addCol("is full", $mode);
        while ($can = $CansDS->fetchRow()) {
            // Time-stuff, yet again.
            $candroptime = $can[droptime];
            $timeleft = $candroptime + $TTL - $TIMEMARK;
            $minsleft = str_pad(number_format(($timeleft - 60) / 60, 0), "2", "0", STR_PAD_LEFT);
            $secsleft = str_pad($timeleft % 60, "2", "0", STR_PAD_LEFT);
            $poptime = $candroptime + $TTL;
            // no neg mins..
            if ($secsleft < 1) {
                $secsleft = "00";
            }
            // color..
            if ($minsleft >= 30) {
                $color = "#88ff88";
            } elseif ($minsleft < 29 && $minsleft >= 15) {
                $color = "#FFFF00";
            } elseif ($minsleft < 15) {
                $color = "#FF0000";
            }
            $allCans->addRow();
            $allCans->addCol($can[name]);
            $allCans->addCol(idToUsername($can[pilot]));
            $system = new solarSystem($can[location]);
            $allCans->addCol($system->makeFancyLink());
            $allCans->addCol(date("H:i:s", $can[droptime]));
            $allCans->addCol(date("H:i:s", $poptime));
            // Can popped already?
            if ($minsleft > 0) {
                $allCans->addCol("<font color=\"{$color}\">" . numberToString($timeleft) . "</font>");
            } else {
                $allCans->addCol("<font color=\"{$color}\">POPPED</font>");
            }
            // Can full?
            if ($can[isFull]) {
                $allCans->addCol("<font color=\"#00ff00\">YES</font>");
            } else {
                $CANS_other .= "<td align=\"center\">No</td>";
                $allCans->addCol("No");
            }
        }
        $allCansExists = true;
    }
    // Lets get down to html buisiness.
    // Show only what the man wants. Eh, Tony?
    global $PREFS;
    if ($PREFS->getPref("CanAddCans")) {
        // Create a new add-can table.
        $addFormTable = new table(2, true);
        $addFormTable->addHeader(">> Register a new cargo container");
        // Row: Name
        $addFormTable->addRow();
        $addFormTable->addCol("Container name:", $mode);
        $addFormTable->addCol("<input type=\"text\" name=\"cantag\" value=\"" . $canname . "\" maxlength=\"100\" size=\"20\">");
        // Row: Naming preferences
        $addFormTable->addRow();
        $addFormTable->addCol("Naming&nbsp;preferences:", $mode);
        // Pre-select the current preferences.
        switch ($canNaming) {
            case "0":
                $c1 = "selected";
                break;
            case "1":
                $c2 = "selected";
                break;
            case "2":
                $c3 = "selected";
                break;
        }
        $canNamingPDM = "<select name=\"canprefs\">" . "<option " . $c1 . " value=\"0\">Do not suggest names</option>" . "<option " . $c2 . " value=\"1\">Numbers - select your highest can-number</option>" . "<option " . $c3 . " value=\"2\">Numbers - select overall highest can-number</option>" . "</select>";
        $addFormTable->addCol($canNamingPDM);
        // Row: Location
        $addFormTable->addRow();
        $addFormTable->addCol("Location:", $mode);
        $addFormTable->addCol("<select name=\"location\">" . $ddm . "</select>");
        // Row: System
        $addFormTable->addRow();
        $addFormTable->addCol("<b>-or-</b> System name:", $mode);
        $addFormTable->addCol("<input type=\"text\" name=\"location2\">");
        // Row: Time of Launch
        $addFormTable->addRow();
        $addFormTable->addCol("Time of launch:", $mode);
        // Get a time-array and do the human friendly part.
        // Funnies: We always want to use "00" as the minute, and always at the start of the
        // NEXT hour.
        $times = humanTime("toHuman", $TIMEMARK);
        $timefield = "<input type=\"text\" name=\"ST_day\"    size=\"2\" maxlength=\"4\" value=\"" . $times[day] . "\">." . "<input type=\"text\" name=\"ST_month\"  size=\"2\" maxlength=\"4\" value=\"" . $times[month] . "\">." . "<input type=\"text\" name=\"ST_year\"   size=\"4\" maxlength=\"6\" value=\"" . $times[year] . "\">" . "&nbsp;&nbsp;" . "<input type=\"text\" name=\"ST_hour\"   size=\"2\" maxlength=\"4\" value=\"" . $times[hour] . "\">:" . "<input type=\"text\" name=\"ST_minute\" size=\"2\" maxlength=\"4\" value=\"" . $times[minute] . "\">";
        $addFormTable->addCol($timefield . " <i>(d:m:y, h:m)</i>");
        // Row: Belongs to run
        $addFormTable->addRow();
        $addFormTable->addCol("For mining op:", $mode);
        if ($PREFS->getPref("CanForRun")) {
            $addFormTable->addCol("<input type=\"checkbox\" CHECKED name=\"forRun\" value=\"true\"> Tick this if the can(s) you are dropping are part of your mining run, if any.");
        } else {
            $addFormTable->addCol("<input type=\"checkbox\" CHECKED name=\"forRun\" value=\"true\"> Tick this if the can(s) you are dropping are part of your mining run, if any.");
        }
        // Row: Submit button.
        $addFormTable->addHeaderCentered("<input type=\"submit\" name=\"create\" value=\"Register can in Database\">" . "<input type=\"hidden\" name=\"action\" value=\"addcan\">" . "<input type=\"hidden\" name=\"check\" value=\"true\">");
    }
    $html = "<h2>Cargo container chronograph</h2>";
    if ($PREFS->getPref("CanAddCans")) {
        $html .= "<form action=\"index.php\" method=\"post\">" . $addFormTable->flush();
    }
    if ($PREFS->getPref("CanMyCans") && $MyCansExist) {
        $html .= "<br>" . $myCans->flush();
    }
    if ($PREFS->getPref("CanRunCans") && $runCansExists) {
        $html .= "<br>" . $runCans->flush();
    }
    if ($PREFS->getPref("CanAllCans") && $allCansExists) {
        $html .= "<br>" . $allCans->flush();
    }
    return $html . "</form>";
}
Example #7
0
    $refresh_button = " [<a href=\"index.php?action=show&id={$row['id']}\">Reload page</a>]";
    $general_info->addCol($join . $addHaul . $add2 . $lock . $add . $charity . $refresh_button);
} else {
    // Mining run ended.
    // Row: Ended
    $general_info->addRow();
    $general_info->addCol("Ended on:", $common_mode);
    $general_info->addCol(date("d.m.y H:i", $row['endtime']));
    $ranForSecs = $row['endtime'] - $row['starttime'];
    // Duration
    $general_info->addRow();
    $general_info->addCol("Duration:", $common_mode);
    if ($ranForSecs < 0) {
        $general_info->addCol("Event was canceled before starttime.");
    } else {
        $general_info->addCol(numberToString($ranForSecs));
    }
    // Set flag for later that we dont generate active ship data.
    $DontShips = true;
    // Current TMEC
    $general_info->addRow();
    $general_info->addCol("TMEC reached:");
    $general_info->addCol(calcTMEC($row['id']), true);
}
// We have to check for "0" - archiac runs that have no ore values glued to them
if ($row['oreGlue'] > 0) {
    $general_info->addRow();
    $general_info->addCol("Ore Quotes:", $common_mode);
    // Is this the current ore quote?
    $cur = $DB->getCol("SELECT time FROM orevalues ORDER BY time DESC LIMIT 1");
    if ($cur[0] <= $row['oreGlue']) {
Example #8
0
function showEvent()
{
    // Lets import some globals, shall we?
    global $MySelf;
    global $DB;
    global $TIMEMARK;
    $ID = $MySelf->getID();
    // is the events module active?
    if (!getConfig("events")) {
        makeNotice("The admin has deactivated the events module.", "warning", "Module not active");
    }
    // Are we allowed to be here?
    if (!$MySelf->canSeeEvents()) {
        makeNotice("You are not allowed to do this!", "error", "Forbidden");
    }
    // Is the ID safe?
    if (!is_numeric($_GET[id]) || $_GET[id] < 0) {
        makeNotice("Invalid ID given!", "error", "Invalid Data");
    }
    // Load the event.
    $EVENTS = $DB->getRow("SELECT * FROM events WHERE id='{$_GET['id']}'");
    $mission = new table(2, true);
    $mission->addHeader(">> Mission information");
    $mission->addRow();
    $mission->addCol("Mission ID:");
    $mission->addCol(str_pad("{$EVENTS['id']}", 5, "0", STR_RIGHT_PAD));
    $mission->addRow();
    $mission->addCol("Mission Type:");
    $mission->addCol($EVENTS[type]);
    $mission->addRow();
    $mission->addCol("Executing Officer:");
    // In case of a numeric value we have to translate that into plain english.
    if (is_numeric($EVENTS[officer])) {
        $officer = idToUsername($EVENTS[officer]);
    } else {
        $officer = $EVENTS[officer];
    }
    $mission->addCol(ucfirst($officer));
    $mission->addRow();
    $mission->addCol("System:");
    $mission->addCol(ucfirst($EVENTS[system]));
    $mission->addRow();
    $mission->addCol("Security:");
    $mission->addCol($EVENTS[security]);
    // Has the event started yet?
    $delta = $TIMEMARK - $EVENTS[starttime];
    if ($delta > 0) {
        // Yep!
        $mission->addRow();
        $mission->addCol("Mission underway for:");
        $mission->addCol(numberToString($delta));
    } else {
        // Nope!
        $delta = $delta * -1;
        $mission->addRow();
        $mission->addCol("Mission will start in:");
        $mission->addCol(numberToString($delta));
    }
    $mission->addRow();
    $mission->addCol("Est. Duration:");
    $mission->addCol($EVENTS[duration]);
    // How difficult is it?
    $mission->addRow();
    $mission->addCol("Difficulty:");
    switch ($EVENTS[difficulty]) {
        case 0:
            $mission->addCol("No risk involved");
            break;
        case 1:
            $mission->addCol("Inferior forces");
            break;
        case 2:
            $mission->addCol("Adequate forces");
            break;
        case 3:
            $mission->addCol("Major forces expected");
            break;
        case 4:
            $mission->addCol("Superior forces expected");
            break;
        case 5:
            $mission->addCol("Suicide Mission");
            break;
    }
    $mission->addRow();
    $mission->addCol("Payment:");
    $mission->addCol($EVENTS[payment]);
    $mission->addRow();
    $mission->addCol("Collateral:");
    $mission->addCol(number_format($EVENTS[collateral]));
    $mission->addRow();
    $mission->addCol("Notes:");
    $mission->addCol(nl2br($EVENTS[notes]));
    $shipsTable = new table(3, true);
    $shipsTable->addHeader(">> Shiptypes and Joinups");
    // Compute the wanted Ships.
    $ships = unserialize($EVENTS[ships]);
    $SHIPTYPES = array("shuttles", "frigates", "destroyers", "cruisers", "bcruiser", "scruiser", "bship", "dread", "carrier", "titan", "barges", "indies", "freighter", "jfreighter", "exhumer");
    $TRANSLATE = array("shuttles" => "Shuttle", "frigates" => "Frigate", "destroyers" => "Destroyer", "cruisers" => "Cruiser", "bcruiser" => "Battlecruiser", "scruiser" => "Strategic Cruiser", "bship" => "Battleship", "dread" => "Dreadnought", "carrier" => "Carrier", "titan" => "Titan", "barges" => "Mining Barge", "indies" => "Industrial Ship", "freighter" => "Freighter", "jfreighter" => "Jump Freighter", "exhumer" => "Exhumer");
    $shipsTable->addRow("#060622");
    $shipsTable->addCol("Ship class");
    $shipsTable->addCol("Signed up");
    $shipsTable->addCol("Join up");
    // Ugh. ugly hack. Easier way?
    $JOINUPS_DS = $DB->getCol("SELECT signups FROM events WHERE id = '{$_GET['id']}'");
    $JOINUPS = unserialize($JOINUPS_DS[0]);
    unset($JOINUPS_DS);
    $JOINUPS_SHIPS = array_count_values($JOINUPS);
    // Translate the ships.
    foreach ($SHIPTYPES as $type) {
        if (in_array($type, $ships)) {
            $shipsTable->addRow();
            $shipsTable->addCol($TRANSLATE[$type] . "s");
            // Print how many ships are coming.
            if ($JOINUPS_SHIPS[$type] != "") {
                $shipsTable->addCol("{$JOINUPS_SHIPS[$type]}");
            } else {
                $shipsTable->addCol("none");
            }
            // Okay this is fun. First lets see if the user is already in this event.
            if ($JOINUPS[$ID] != "") {
                // User in Event. Lets see if the current shiptype is the shiptype hes joined up with.
                if ($JOINUPS[$ID] != $type) {
                    // Its not. Offer to switch.
                    $shipsTable->addCol("<a href=\"index.php?action=joinevent&id={$EVENTS['id']}&type={$type}\">Switch to " . $TRANSLATE[$type] . " class</a>");
                } else {
                    // It is. Renember him.
                    $shipsTable->addCol("You are signed up as " . $TRANSLATE[$type]);
                }
            } else {
                // User is not in event, offer to joinup.
                $shipsTable->addCol("<a href=\"index.php?action=joinevent&id={$EVENTS['id']}&type={$type}\">Join as " . $TRANSLATE[$type] . "</a>");
            }
        }
    }
    // Offer to quit Event.
    if ($JOINUPS[$ID] != "") {
        $shipsTable->addHeaderCentered("<a href=\"index.php?action=joinevent&id={$EVENTS['id']}&type=quit\">Cancel my signup for this event.</a>");
    }
    // Pilot overview.
    $pilotTable = new table(1, true);
    $pilotTable->addHeader(">> Current event roster");
    $keys = array_keys($JOINUPS);
    foreach ($keys as $key) {
        $pilotTable->addRow();
        $pilotTable->addCol(ucfirst(idToUsername($key)) . " has joined as a " . $TRANSLATE[$JOINUPS[$key]]);
    }
    // Return what we got.
    $html = "<h2>Detailed Mission Information</h2>" . $mission->flush();
    $html .= "<br>[<a href=\"index.php?action=showevents\">Back to overview</a>]<br>";
    $html .= "<br>" . $shipsTable->flush();
    $html .= "<br>" . $pilotTable->flush();
    return $html;
}
Example #9
0
/**
 * converts a number into its english written equivilent
 *
 * @param int $num 
 * @param int $tri 
 * @return string
 * @author Craig Ulliott
*/
function numberToString($num, $tri = 0)
{
    $ones = array("", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen");
    $tens = array("", "", " twenty", " thirty", " forty", " fifty", " sixty", " seventy", " eighty", " ninety");
    $triplets = array("", " thousand", " million", " billion", " trillion", " quadrillion", " quintillion", " sextillion", " septillion", " octillion", " nonillion");
    // chunk the number, ...rxyy
    $r = (int) ($num / 1000);
    $x = $num / 100 % 10;
    $y = $num % 100;
    // init the output string
    $str = "";
    // do hundreds
    if ($x > 0) {
        $str = $ones[$x] . " hundred";
    }
    // do ones and tens
    if ($y < 20) {
        $str .= $ones[$y];
    } else {
        $str .= $tens[(int) ($y / 10)] . $ones[$y % 10];
    }
    // add triplet modifier only if there
    // is some output to be modified...
    if ($str != "") {
        $str .= $triplets[$tri];
    }
    // continue recursing?
    if ($r > 0) {
        return numberToString($r, $tri + 1) . $str;
    } else {
        return $str;
    }
}
Example #10
0
function showEvents()
{
    // Lets import some globals, shall we?
    global $MySelf;
    global $DB;
    global $TIMEMARK;
    $delta = $TIMEMARK - 259200;
    // is the events module active?
    if (!getConfig("events")) {
        makeNotice("The admin has deactivated the events module.", "warning", "Module not active");
    }
    // Load all events.
    $EVENTS_DS = $DB->query("SELECT * FROM events WHERE starttime >= '" . $delta . "' ORDER BY starttime ASC");
    // .. right?
    if ($EVENTS_DS->numRows() >= 1) {
        // Lets keep in mind: We have events.
        $haveEvents = true;
        while ($event = $EVENTS_DS->fetchRow()) {
            // get the date.
            $date = date("d.m.y", $event[starttime]);
            // open up a new table for each day.
            if ($date != $previousdate) {
                $workday = date("l", $event[starttime]);
                if ($beenhere) {
                    $html .= $temp->flush();
                    $html .= "<br>";
                }
                $beenhere = true;
                // We need an additional row if we are allowed to delete events.
                if ($MySelf->canDeleteEvents()) {
                    $temp = new table(8, true);
                } else {
                    $temp = new table(7, true);
                }
                $temp->addHeader(">> Events for " . $workday . ", the " . $date);
                $previousdate = $date;
                $temp->addRow("#060622");
                $temp->addCol("ID");
                $temp->addCol("Starttime");
                $temp->addCol("Starts in / Runs for");
                $temp->addCol("Mission Type");
                $temp->addCol("Short Description");
                $temp->addCol("System");
                $temp->addCol("Security");
                if ($MySelf->canDeleteEvents()) {
                    $temp->addCol("Delete");
                }
            }
            // Add Event to the current database.
            $temp->addRow();
            $temp->addCol("<a href=\"index.php?action=showevent&id=" . $event[id] . "\">" . str_pad($event[id], 4, "0", STR_PAD_LEFT) . "</a>");
            $temp->addCol(date("d.m.y H:i", $event[starttime]));
            $delta = $TIMEMARK - $event[starttime];
            if ($TIMEMARK > $event[starttime]) {
                // Event underway.
                $temp->addCol("<font color=\"#00ff00\">" . numberToString($delta) . "</font>");
            } else {
                // Event not started yet.
                $delta = $delta * -1;
                $temp->addCol("<font color=\"#ffff00\">" . numberToString($delta) . "</font>");
            }
            $temp->addCol($event[type]);
            $temp->addCol($event[sdesc]);
            $temp->addCol($event[system]);
            $temp->addCol($event[security]);
            if ($MySelf->canDeleteEvents()) {
                $temp->addCol("<a href=\"index.php?action=deleteevent&id={$event['id']}\">delete event</a>");
            }
        }
    }
    // Lets recall, did we have events scheduled?
    if ($haveEvents) {
        // We do!
        $html = "<h2>Scheduled Events</h2>" . $html . $temp->flush();
    } else {
        // We dont!
        $html = "<h2>Scheduled Events</h2><b>There are currently no scheduled events in the database.</b>";
    }
    // Return what we got.
    return $html;
}
Example #11
0
 $partlog_info->addCol("Active Time", array("bold" => true));
 $partlog_info->addCol("State", array("bold" => true));
 $partlog_info->addCol("Shiptype", array("bold" => true));
 $partlog_info->addCol("Notes", array("bold" => true));
 while ($join = $joinlog->fetchRow()) {
     $partlog_info->addRow();
     $partlog_info->addCol(makeProfileLink($join[userid]));
     if ($TIMEMARK >= $join[joined]) {
         $partlog_info->addCol(date("H:i:s", $join[joined]));
         if ("{$join['parted']}" != "") {
             $partlog_info->addCol(date("H:i:s", $join[parted]));
             $partlog_info->addCol(numberToString($join[parted] - $join[joined]));
             $partlog_info->addCol("<font color=\"#ff0000\">INACTIVE</font>");
         } else {
             $partlog_info->addCol("<i>soon(tm)</i>");
             $partlog_info->addCol(numberToString($TIMEMARK - $join[joined]));
             $partlog_info->addCol("<font color=\"#00ff00\">ACTIVE</font>");
         }
         $partlog_info->addCol(joinAs($join[shiptype]));
     } else {
         $partlog_info->addCol("request pending");
         $partlog_info->addCol("request pending");
         $partlog_info->addCol("request pending");
         $partlog_info->addCol("request pending");
         $partlog_info->addCol(joinAs($join[shiptype]));
     }
     // Get the removal reason.
     switch ($join[status]) {
         default:
         case "0":
             $reason = " ";