function toggleLogin() { global $DB; global $MySelf; global $IS_DEMO; if ($IS_DEMO) { makeNotice("The user would have been changed. (Operation canceled due to demo site restrictions.)", "notice", "Password change confirmed"); } // Are we allowed to Manage Users? if (!$MySelf->canManageUser()) { makeNotice("You are not allowed to edit Users!", "error", "forbidden"); } if ($MySelf->getID() == $_GET[id]) { makeNotice("You are not allowed to block yourself!", "error", "forbidden"); } // Wash ID. numericCheck($_GET[id]); $ID = sanitize($_GET[id]); // update login capability. $DB->query("UPDATE users SET canLogin=1 XOR canLogin WHERE id='" . $ID . "' LIMIT 1"); $username = idToUsername("{$ID}"); $p = substr($username, 0, 1); // Return. header("Location: index.php?action=editusers&l={$p}"); }
function lotto_checkRatio($drawing) { // We need some globals. global $DB; global $MySelf; $LOTTO_MAX_PERCENT = getConfig("lottoPercent"); if (!getConfig("lotto")) { makeNotice("Your CEO disabled the Lotto module, request denied.", "warning", "Lotto Module Offline"); } // Drawing ID valid? numericCheck($drawing); // Get current occupied tickets in the playa's name. $totalPlayerOwned = $DB->getCol("SELECT COUNT(id) FROM lotteryTickets WHERE owner='" . $MySelf->getID() . "' AND drawing='" . $drawing . "'"); $totalPlayerOwned = $totalPlayerOwned[0]; // Get total number of tickets. $totalTickets = $DB->getCol("SELECT COUNT(id) FROM lotteryTickets WHERE drawing='" . $drawing . "'"); $totalTickets = $totalTickets[0]; // Is there actually a limit requested? if (!$LOTTO_MAX_PERCENT) { // The sky is the limit! $allowedTickets = $totalTickets; } else { // Calculate max allowed tickets per person, ceil it. $allowedTickets = ceil($totalTickets * $LOTTO_MAX_PERCENT / 100); } // return allowed tickets. return $allowedTickets - $totalPlayerOwned; }
function getCredits($id) { numericCheck($id, -1); global $DB; $credits = $DB->getCol("SELECT SUM(amount) FROM transactions WHERE owner='{$id}' LIMIT 1"); return $credits[0]; }
function editRanks() { // Doh, globals! global $MySelf; global $DB; // Are we allowed to do this? if (!$MySelf->canEditRank()) { makeNotice("You do not have sufficient rights to access this page.", "warning", "Access denied"); } // Get all unique rank IDS. $ranks = $DB->query("SELECT DISTINCT rankid FROM ranks"); // Edit each one at a time. while ($rankID = $ranks->fetchRow()) { $ID = $rankID[rankid]; if (isset($_POST["title_" . $ID . "_name"])) { // Cleanup $name = sanitize($_POST["title_" . $ID . "_name"]); numericCheck($_POST["order_" . $ID], 0); $order = $_POST["order_" . $ID]; // Update the Database. $DB->query("UPDATE ranks SET name='" . $name . "', rankOrder='" . $order . "' WHERE rankid='" . $ID . "' LIMIT 1"); } } header("Location: index.php?action=showranks"); }
function leaveRun() { // Access the globals. global $DB; global $TIMEMARK; global $MySelf; $runid = $_GET[id]; $userid = $MySelf->getID(); // Are we actually still in this run? if (userInRun($userid, $runid) == "none") { makeNotice("You can not leave a run you are currently not a part of.", "warning", "Not you run.", "index.php?action=show&id={$runid}", "[cancel]"); } // Is $runid truly an integer? numericCheck($runid); // Oh yeah? if (runIsLocked($runid)) { confirm("Do you really want to leave mining operation #{$runid} ?<br><br>Careful: This operation has been locked by " . runSupervisor($runid, true) . ". You can not rejoin the operation unless its unlocked again."); } else { confirm("Do you really want to leave mining operation #{$runid} ?"); } // Did the run start yet? If not, delete the request. $runStart = $DB->getCol("SELECT starttime FROM runs WHERE id='{$runid}' LIMIT 1"); if ($TIMEMARK < $runStart[0]) { // Event not started yet. Delete. $DB->query("DELETE FROM joinups WHERE run='{$runid}' AND userid='{$userid}'"); } else { // Event started, just mark inactive. $DB->query("update joinups set parted = '{$TIMEMARK}' where run = '{$runid}' and userid = '{$userid}' and parted IS NULL"); } makeNotice("You have left the run.", "notice", "You left the Op.", "index.php?action=show&id={$runid}", "[OK]"); }
function idToUsername($id, $authID = false) { // Need to access some globals. global $DB; // $id must be numeric. numericCheck("{$id}"); // Is it -1 ? (Self-added) if ("{$id}" == "-1") { return "-self-"; } // Ask the oracle. if (!$authID) { $results = $DB->query("select username from users where id='{$id}' limit 1"); } else { $results = $DB->query("select username from users where authID='{$id}' order by authPrimary desc, id desc limit 1"); } // Valid user? if ($results->numRows() == 0) { return "no one"; makeNotice("Internal Error: Invalid User at idToUsername", "error"); } // return the username. while ($row = $results->fetchRow()) { return $row['username']; } }
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]; } } }
public function __construct($ID) { // Link the DB. global $DB; $this->DB =& $DB; // Link the MySelf object. global $MySelf; $this->MySelf =& $MySelf; // Set the ID. $this->ID = sanitize($ID); numericCheck($this->ID, 0); // Set the picture links. $this->setImageLinks(); // Load the profile. $this->getProfileDB(); // is it out own profile? if ($MySelf->getID() == $this->ID) { $this->isOwn = true; } // Set some vars. $this->minerFlag = $this->profileDB[isMiner]; $this->haulerFlag = $this->profileDB[isHauler]; $this->fighterFlag = $this->profileDB[isFighter]; $this->emailVisible = $this->profileDB[emailVisible]; $this->about = $this->profileDB[about]; }
function getTotalHaulRuns($run) { global $DB; // Is $run truly an integer? numericCheck($run); // Query the oracle. $result = $DB->query("select * from hauled where miningrun = '{$run}'"); // Now return the results. return $result->numRows(); }
function lotto_claimTicket() { global $DB; global $MySelf; $LOTTO_MAX_PERCENT = getConfig("lottoPercent"); if (!getConfig("lotto")) { makeNotice("Your CEO disabled the Lotto module, request denied.", "warning", "Lotto Module Offline"); } // Only people with parents consent may play! if (!$MySelf->canPlayLotto()) { makeNotice("Im sorry, but you are not allowed to play Lotto. " . "Ask your CEO or a friendly Director to enable this for you.", "warning", "Unable to play :("); } // Ticket ID sane? numericCheck($_GET[ticket], 0); $ticket = $_GET[ticket]; // Get the drawing ID. $drawing = lotto_getOpenDrawing(); // Get my credits $MyStuff = $DB->getRow("SELECT lottoCredit, lottoCreditsSpent FROM users WHERE id='" . $MySelf->getID() . "'"); $Credits = $MyStuff[lottoCredit]; $CreditsSpent = $MyStuff[lottoCreditsSpent]; // Are we broke? if ($Credits < 1) { makeNotice("You can not afford the ticket, go get more credits!", "warning", "You're broke!'", "index.php?action=lotto", "[ashamed]"); } // Now check if we bust it. $myTickets = lotto_checkRatio($drawing); if ($myTickets <= 0) { makeNotice("You are already owning the maximum allowed tickets!", "warning", "Exceeded ticket ratio!", "index.php?action=lotto", "[Cancel]"); } // Deduct credit from account. $newcount = $Credits - 1; $DB->query("UPDATE users SET lottoCredit='{$newcount}' WHERE id='" . $MySelf->getID() . "' LIMIT 1"); if ($DB->affectedRows() != 1) { makeNotice("Internal Error: Problem with your bank account... :(", "error", "Internal Error", "index.php?action=lotto", "[Cancel]"); } // Add to "Spent". $spent = $CreditsSpent + 1; $DB->query("UPDATE users SET lottoCreditsSpent='{$spent}' WHERE id='" . $MySelf->getID() . "' LIMIT 1"); if ($DB->affectedRows() != 1) { makeNotice("Internal Error: Problem with your bank account... :(", "error", "Internal Error", "index.php?action=lotto", "[Cancel]"); } // Lets check that the ticket is still unclaimed. $Ticket = $DB->getCol("SELECT owner FROM lotteryTickets WHERE ticket='{$ticket}' AND drawing='{$drawing}'"); if ($Ticket[0] >= 0) { makeNotice("Im sorry, but someone else was faster that you and already claimed that ticket.", "warning", "Its gone, Jim!", "index.php?action=lotto", "[Damn!]"); } // Give him the ticket. $DB->query("UPDATE lotteryTickets SET owner='" . $MySelf->getID() . "' WHERE ticket='{$ticket}' AND drawing='{$drawing}' LIMIT 1"); if ($DB->affectedRows() == 1) { Header("Location: index.php?action=lotto"); } else { makeNotice("Internal Error: Could not grant you the ticket :(", "error", "Internal Error", "index.php?action=lotto", "[Cancel]"); } }
function calcTMEC($runID, $force = false) { // We need the database. global $DB; // Check RunID for validity. numericCheck($runID, "0"); if (!$force) { // Try to load a current TMEC. $TMEC = $DB->getCol("SELECT tmec FROM runs WHERE id='" . $runID . "'"); $TMEC = $TMEC[0]; // Got one, return that. if ($TMEC > 0) { return $TMEC; } } // Calculate how long the op lasted. $times = $DB->query("SELECT * FROM runs WHERE id=" . $runID . " LIMIT 1"); // Check that the run exists. if ($times->numRows() != 1) { // Doesnt. good thing we checked. return "0"; } $run = $times->fetchRow(); if ($run['optype'] == "PI") { return "0"; } // check that the endtime is valid. if ($run['endtime'] == 0) { // Run still ongoing, pretent it ends now. global $TIMEMARK; $endtime = $TIMEMARK; } else { // Use real endtime. $endtime = $run['endtime']; } // Calculate how many seconds the run lasted. $lasted = $endtime - $run['starttime']; // Get the total ISK mined by the run. $ISK = getTotalWorth($runID); // Load PlayerCount. $playerCount = $DB->getCol("SELECT COUNT(DISTINCT userid) FROM joinups WHERE run='" . $runID . "'"); $playerCount = $playerCount[0]; // Calculate the TMEC. $TMEC = $ISK / ($lasted / 60 / 60) / $playerCount / 1000000; // Only positive TMECS if ($TMEC < 0) { $TMEC = 0; } if (!$force) { // Store the TMEC in the database. $DB->query("UPDATE runs SET tmec ='" . $TMEC . "' WHERE id='" . $runID . "' LIMIT 1"); } return number_format($TMEC, 3); }
function getTotalRuntime($runid) { // Get the globals, query the DB. global $DB; // Is $run truly an integer? numericCheck($runid); $result = $DB->query("select starttime, endtime from runs where id = '{$runid}'"); // Return total run-seconds. while ($row = $result->fetchRow()) { return $row[endtime] - $row[starttime]; } }
function editTemplate() { global $DB; global $MySelf; // Are we allowed to? if (!$MySelf->isAdmin()) { makeNotice("Only an Administator can edit the sites templates.", "warning", "Access denied"); } // No Identifier, no service if ($_POST[check]) { // We got the returning form, edit it. numericCheck($_POST[id], 0); $ID = $_POST[id]; // Fetch the current template, see that its there. $test = $DB->query("SELECT identifier FROM templates WHERE id='{$ID}' LIMIT 1"); if ($test->numRows() == 1) { // We got the template $template = sanitize($_POST[template]); $DB->query("UPDATE templates SET template='" . $template . "' WHERE id='{$ID}' LIMIT 1"); // Check for success if ($DB->affectedRows() == 1) { // Success! header("Location: index.php?action=edittemplate&id={$ID}"); } else { // Fail! makeNotice("There was a problem updating the template in the database!", "error", "Internal Error", "index.php?action=edittemplate&id={$ID}", "Cancel"); } } else { // There is no such template makeNotice("There is no such template in the database!", "error", "Invalid Template!", "index.php?action=edittemplate&id={$ID}", "Cancel"); } } elseif (empty($_GET[id])) { // No returning form, no identifier. header("Location: index.php?action=configuration"); } else { $ID = $_GET[id]; } // numericheck! numericCheck($ID, 0); $temp = $DB->getCol("SELECT template FROM templates WHERE id='{$ID}' LIMIT 1"); $table = new table(1, true); $table->addHeader(">> Edit template"); $table->addRow(); $table->addCol("<center><textarea name=\"template\" rows=\"30\" cols=\"60\">" . $temp[0] . "</textarea></center>"); $table->addHeaderCentered("<input type=\"submit\" name=\"submit\" value=\"Edit Template\">"); $form1 = "<form action=\"index.php\" method=\"POST\">"; $form2 = "<input type=\"hidden\" name=\"check\" value=\"true\">"; $form2 .= "<input type=\"hidden\" name=\"action\" value=\"editTemplate\">"; $form2 .= "<input type=\"hidden\" name=\"id\" value=\"" . $ID . "\">"; $form2 .= "</form>"; $backlink = "<br><a href=\"index.php?action=configuration\">Back to configuration</a>"; return "<h2>Edit the template</h2>" . $form1 . $table->flush() . $form2 . $backlink; }
function getRank($ID) { global $DB; numericCheck($ID, 0); $rankID = $DB->getCol("SELECT rank FROM users WHERE id='" . $ID . "' AND deleted='0'"); if (is_numeric($rankID[0])) { $rank = resolveRankID($rankID[0]); return $rank; } else { return "No rank."; } }
function deleteAPIKey() { global $MySelf; global $DB; if ($MySelf->canManageUser()) { numericCheck($_GET[id]); $api = new api($_GET[id]); $api->deleteApiKey(); makeNotice("Api key for user " . ucfirst(idToUsername($_GET[id])) . " has been deleted from the database", "notice", "API deleted.", "index.php?action=edituser&id=" . $_GET[id], "[OK]"); } makeNotice("You do not have permission to modify users.", "warning", "Access denied."); }
function resolveRankID($ID) { global $DB; numericCheck($ID); $resolved = $DB->getCol("SELECT name FROM ranks WHERE rankid='{$ID}' LIMIT 1"); $resolved = $resolved[0]; if ($resolved == "") { return "-invalid rank-"; } else { return $resolved; } }
function miningRunOpen($run) { global $DB; // Is $run truly an integer? numericCheck($run); // Query the oracle. $result = $DB->query("select id from runs where endtime is NULL and id = '{$run}' limit 1"); if ($result->numRows() > 0) { return true; } else { return false; } }
function getLocationOfRun($id) { // We need the database access. global $DB; // Is the ID a number and greater (or euqal) zero? numericCheck($id, 0); // if (!numericCheck($id, 0)) { // makeNotice("Internal Error: getLocationOfRun called with negative ID.", "error", "Internal Error"); // } // Compact: Query, sort and return. $loc = $DB->getCol("SELECT location FROM runs WHERE id = '{$id}'"); return $loc[0]; }
function createTransaction() { // We need globals. global $DB; global $MySelf; global $TIMEMARK; // Are we allowed to poke in here? if (!$MySelf->isAccountant()) { makeNotice("Umm, you are not allowed to do this. Really. You are not.", "warning", "You are not supposed to be here"); } // Check the ints. numericCheck($_POST[wod], 0, 1); numericCheck($_POST[amount], 0); numericCheck($_POST[id], 0); // Its easier on the eyes. $type = $_POST[wod]; $amount = $_POST[amount]; $id = $_POST[id]; $username = idToUsername($id); // invert the amount if we have a withdrawal. if ($_POST[wod] == 1) { $dir = "withdrawed"; $dir2 = "from"; $hisMoney = getCredits($id); if ($hisMoney < $amount) { $ayee = $hisMoney - $amount; confirm("WARNING:<br>{$username} can NOT afford this withdrawal. If you choose to " . "authorize this transaction anyway his account will be at " . number_format($ayee, 2) . " ISK."); } } else { $amount = $_POST[amount]; $dir = "deposited"; $dir2 = "into"; } // We use custom reason, if set. if ($_POST[reason2] != "") { $reason = sanitize($_POST[reason2]); } else { $reason = sanitize($_POST[reason1]); } // Create transaction. $transaction = new transaction($id, $type, $amount); $transaction->setReason($reason); // Success? if (!$transaction->commit()) { // Nope :( makeNotice("Unable to create transaction. Danger, Will Robinson, DANGER!", "error", "Internal Error", "index.php?action=edituser&id={$id}", "[Back]"); } else { // Success ! makeNotice("You successfully {$dir} {$amount} ISK {$dir2} " . $username . "'s account.", "notice", "Transaction complete", "index.php?action=edituser&id={$id}", "[Ok]"); } }
function quickConfirm() { global $DB; global $MySelf; if ($MySelf->canManageUser() == false) { makeNotice("You are not allowed to do this!", "error", "Forbidden"); } $ID = sanitize($_GET[id]); numericCheck($ID); $DB->query("UPDATE users SET confirmed='1' WHERE id='" . $ID . "'"); $userDS = $DB->query("SELECT * FROM users WHERE id='{$ID}' LIMIT 1"); $user = $userDS->fetchRow(); lostPassword($user[username]); header("Location: index.php?action=editusers&newusers=true"); die; }
function runSupervisor($id, $capped = false) { // ID valid? numericCheck($id, 0); // if (!numericCheck($id, 0)) { // makeNotice("Internal Error: Invalid RUN selected for runSupervisor."); // } // Query the database. global $DB; $DS = $DB->getCol("SELECT supervisor FROM runs WHERE id='{$id}'"); // Return the supervisor. if ($capped) { return ucfirst(idToUsername($DS[0])); } else { return idToUsername($DS[0]); } }
function modOnlineTime() { // globals. global $DB; global $MySelf; $id = $MySelf->getID(); // Create empty dataset, if it doesnt exist. $check = $DB->query("SELECT * FROM onlinetime WHERE userid='" . $id . "'"); if ($check->numRows() == 0) { $check = $DB->query("INSERT INTO onlinetime (userid) VALUES (?)", array($id)); } for ($i = 0; $i <= 23; $i++) { numericCheck($_POST[$i], 0, 3); $column = "h" . str_pad($i, 2, "0", STR_PAD_LEFT); $DB->query("UPDATE onlinetime SET {$column}='" . $_POST[$i] . "' WHERE userid='{$id}' LIMIT 1"); } header("Location: index.php?action=onlinetime"); }
public function __construct($to, $type, $amount) { // We need some more globals at this stage global $MySelf; // Check for validity.. numericCheck($to); numericCheck($amount, 1); numericCheck($type, 0, 1); // .. and set the variables. $this->to = $to; $this->type = $type; // In case of a withdrawal, -*1 the amount. if ($type == 1) { $this->amount = $amount * -1; } else { $this->amount = $amount; } // Define standard content for remaining variables. $this->isTransfer = false; $this->from = $MySelf->getID(); }
function humanTime($mode, $playdoo = false) { /* * Mode is either toUnix or toHuman. * toUnix converts the given array to an UNIX timestamp,. * toHuman returns an array with split up time. */ switch ($mode) { case "toUnix": // To convert something back, we need an array. if (!is_array($playdoo)) { makeNotice("Internal Error: given argument is not an array in humanTime.", "error", "Internal Error"); } // Check for validity. numericCheck($playdoo[day]); numericCheck($playdoo[month]); numericCheck($playdoo[year]); numericCheck($playdoo[hour]); numericCheck($playdoo[minute]); // Assemble the time. $humantime = $playdoo[day] . "." . $playdoo[month] . "." . $playdoo[year] . " " . $playdoo[hour] . ":" . $playdoo[minute]; // Convert it. $timestamp = date("U", strtotime($humantime)); // Check and return. if ($timestamp >= 0) { // Its greater of equal zero, so we were successful. return $timestamp; } else { // Ugh, something did not go right. False, FALSE! return false; } break; case "toHuman": // We need a VALID timestamp. numericCheck($playdoo, 0); // Assemble and return. return array("day" => date("d", $playdoo), "month" => date("m", $playdoo), "year" => date("Y", $playdoo), "hour" => date("H", $playdoo), "minute" => date("i", $playdoo)); break; } }
function runIsLocked($id) { // ID is valid? numericCheck($id, 0); // if (!numericCheck($id, 0)) { // makeNotice("Internal error: Invalid run id for runIsLocked!", "error", "Internal Error"); // } // Ask the database global $DB; $DS = $DB->query("SELECT isLocked FROM runs WHERE id='{$id}' LIMIT 1"); // Do we have the runID? if ($DS->numRows() != 1) { makeNotice("Internal error: Run not found!", "error", "Internal Error"); } // Return the bool. $DS = $DS->fetchRow(); if ($DS[isLocked] == true) { return true; } else { return false; } }
function delRank() { // Doh, globals! global $MySelf; global $DB; // Are we allowed to do this? if (!$MySelf->canEditRank()) { makeNotice("You do not have sufficient rights to access this page.", "warning", "Access denied"); } // Verify it. numericCheck($_GET[id], 0); // Confirm it. confirm("Do you really want to permanently delete rank #" . str_pad($_GET[id], 3, "0", STR_LEFT_PAD) . "?"); // Insert Rank into Database $DB->query("DELETE FROM ranks WHERE rankid='" . $_GET[id] . "' LIMIT 1"); // Check for success if ($DB->affectedRows() == 1) { header("Location: index.php?action=showranks"); } else { makeNotice("Unable to add the rank into the database!", "warning", "Database Error!"); } }
function showTransactions() { // Global Fun! global $DB; global $MySelf; // Are we allowed to do this? if (!$MySelf->isAccountant()) { makeNotice("You are not an accountant to your corporation. Access denied.", "error", "Access denied"); } if (isset($_GET['auth'])) { $auth = true; } else { $auth = false; } // Sanity check. numericCheck($_GET['id'], 0); $username = idToUsername($_GET['id']); $id = $_GET['id']; // Load the transaction log. $account = $auth ? "'s TEST Auth" : ""; $page = "<h2>Transaction log for " . ucfirst($username) . "{$account}</h2>"; $users = $DB->query("select id, username from users where ((authID in (select authID from users where id = '{$id}') and '{$auth}' = 1) or id = '{$id}')"); while ($user = $users->fetchRow()) { $userid = $user['id']; $username = $user['username']; $trans = getTransactions($userid); if (!$trans) { $page .= "<b>There are no transactions for {$username}.</b>"; } else { $page .= $trans; } $page .= "<br>"; } // Add the backlink. $page .= "<br><a href=\"index.php?action=payout\">Back to Payouts</a>"; // Return the page. return $page; }
function addCredit($userID, $banker, $credit, $runID) { // Sane? numericCheck($userID, 0); numericCheck(abs($credit), 0); numericCheck($banker, 0); // Globals, YAY! global $DB; global $TIMEMARK; // Create a transaction. if ($credit >= 0) { $transaction = new transaction($userID, 0, $credit); $transaction->setReason("operation #" . str_pad($runID, 5, "0", STR_PAD_LEFT) . " payout"); } else { $transaction = new transaction($userID, 1, abs($credit)); $transaction->setReason("operation #" . str_pad($runID, 5, "0", STR_PAD_LEFT) . " charge"); } $state = $transaction->commit(); if ($state) { return true; } else { makeNotice("Unable to grant money to user #{$userID}!", "error", "Unable to comply!"); } }
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; }
function joinRun() { // Access the globals. global $DB; global $TIMEMARK; global $MySelf; $runid = (int) $_GET[id]; $userid = $MySelf->GetID(); // Are we allowed to join runs? if (!$MySelf->canJoinRun()) { makeNotice("You are not allowed to join mining operations. Please ask your CEO to unblock your account.", "error", "Forbidden"); } // Is $runid truly an integer? numericCheck($runid); // Is the run still open? if (!miningRunOpen($runid)) { makeNotice("This mining operation has been closed!", "warning", "Can not join", "index.php?action=show&id={$runid}"); } // Are we banned from the run? $State = $DB->getCol("SELECT status FROM joinups WHERE run='{$runid}' and userid='" . $MySelf->getID() . "'ORDER BY id DESC LIMIT 1"); $State = $State[0]; switch ($State) { case "2": // We have been kicked. $kicked = true; break; case "3": // We have been banned! if (runSupervisor($runid) == $MySelf->getUsername() || $MySelf->isOfficial()) { $banned = "You have been banned from this operation but your rank overrides this block."; } else { makeNotice("You have been banned from this operation. You can not rejoin it.", "warning", "You are banned.", "index.php?action=list", "[cancel]"); } break; } // Is the run locked? if (runIsLocked($runid)) { makeNotice("You can not join this run as this run has been locked by " . runSupervisor($runid) . ".", "notice", "Mining operation locked", "index.php?action=show&id={$runid}", "[Cancel]"); } // Join with shiptype. if (!$_GET['confirmed-ship']) { $table = new table(1, true); $table->addHeader(">> Join an Operation"); // If we have been kicked, inform the user. if ($kicked) { $table->addRow("#880000"); $table->addCol("Warning: You have been recently kicked. Please check if you are allowed to rejoin to avoid a ban."); } // If we are banned by an official, inform the user. if ($banned) { $table->addRow("#880000"); $table->addCol($banned); } $table->addRow(); $table->addCol($form . "Join the Operation in " . ucfirst(getLocationOfRun($runid)) . "."); $table->addRow(); $table->addCol("You have requested to join mining operation #{$runid}. Please choose the shipclass " . "you are going to join up with."); $table->addRow(); $table->addCol("Shiptype: " . $hiddenstuff . joinAs(), array("align" => "center")); $table->addRow("#444455"); $table->addCol("<input type=\"submit\" name=\"submit\" value=\"Join mining operation\">" . $form_end, array("align" => "center")); $page = "<h2>Join an Operation.</h2>"; $page .= "<form action=\"index.php\" method=\"GET\">"; $page .= "<input type=\"hidden\" name=\"id\" value=\"{$runid}\">"; $page .= "<input type=\"hidden\" name=\"confirmed-ship\" value=\"true\">"; $page .= "<input type=\"hidden\" name=\"confirmed\" value=\"true\">"; $page .= "<input type=\"hidden\" name=\"multiple\" value=\"true\">"; $page .= "<input type=\"hidden\" name=\"action\" value=\"joinrun\">"; $page .= $table->flush(); $page .= "</form>"; return $page; } // Sanitize the Shiptype. global $SHIPTYPES; $ShiptypesCount = count($SHIPTYPES); if (!numericCheck($_GET[shiptype], 0, $ShiptypesCount)) { makeNotice("The shiptype you tried to join up with is invalid, please go back, and try again.", "warning", "Shiptype invalid!", "index.php?action=show&id={$_GET['id']}"); } else { $shiptype = $_GET[shiptype]; } // Warn the user if he is already in another run. $joinedothers = $DB->query("select run from joinups where userid='{$userid}' and parted IS NULL order by run"); // And check for that just now. if ($joinedothers->numRows() > 0) { confirm("You joined another mining operation already!<br>Are you sure you want to join multiple runs at the same time?"); } // Get the correct time to join (in case event hasnt started yet) $startOfRun = $DB->getCol("SELECT starttime FROM runs WHERE id='{$runid}' LIMIT 1"); if ($startOfRun[0] > $TIMEMARK) { $time = $startOfRun[0]; } else { $time = $TIMEMARK; } // Dont allow him to join the same mining run twice. if (userInRun($MySelf->getID(), "{$runid}") == "none") { // Mark user as joined. $DB->query("insert into joinups (userid, run, joined, shiptype) values (?,?,?,?)", array("{$userid}", "{$runid}", "{$time}", "{$shiptype}")); // Forward user to his joined run. makeNotice("You have joined the Mining Operation.", "notice", "Joining confirmed", "index.php?action=show&id={$id}"); } else { // Hes already in that run. makeNotice("You are already in that mining run!", "notice", "Joinup not confirmed", "index.php?action=show&id={$id}"); } }