function toggleCharity() { // Some globals required. global $DB; global $MySelf; // Sanitize! $ID = sanitize($_GET[id]); // Mining run still open? if (!miningRunOpen($ID)) { makeNotice("You can not set the charity flag on closed operations!", "warning", "Failed", "index.php?action=show&id={$ID}", "[Cancel]"); } // update the flags $DB->query("UPDATE joinups SET charity=1 XOR charity WHERE userid='" . $MySelf->getID() . "' AND parted IS NULL AND run='" . $_GET[id] . "' LIMIT 1"); // Check is we were successful. if ($DB->affectedRows() == 1) { // Load the new charity status. $newMode = $DB->getCol("SELECT charity FROM joinups WHERE userid='" . $MySelf->getID() . "' AND parted IS NULL AND run='" . $_GET[id] . "' LIMIT 1"); if ($newMode[0]) { // He is now a volunteer. makeNotice("You have volunteered to waive your payout, and dontate it to your corporation. Thank you!", "notice", "Charity accepted", "index.php?action=show&id=" . $_GET[id]); header("Location: index.php?action=show&id=" . $_GET[id]); } else { // He is no longer a volunteer. makeNotice("You have revoked your waiver, you will recieve ISK for this run again.", "notice", "Charity revokation accepted", "index.php?action=show&id=" . $_GET[id]); header("Location: index.php?action=show&id=" . $_GET[id]); } } else { // Something went wrong with the database! makeNotice("Unable to set the charity flag!", "error", "Internal Error", "index.php?action=show&id=" . $_GET[id]); } }
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}"); } }
function listRun() { /* * STEP ZERO: * Import variables, and define needed things. */ global $DB; // Database connection global $STATIC_DB; // static db name global $ORENAMES; // A list of all the orenames global $DBORE; // An array of db friendly orenames global $TIMEMARK; // The "current" timestamp global $MySelf; // Ourself, and along with that, the permissions. global $SHIPTYPES; // We dont want numbers to memorize. global $DBSHIP; // An array of db friendly shipnames global $MATERIALS; global $DBMAT; $userID = $MySelf->getID(); // Shortcut: Assign the UserID to userID. $common_mode = array("width" => "200"); // Default column mode here. /* * STEP ONE: * Load the database row into $row. This requires us to look up the minigrun ID * first. */ include './functions/runs/listRun_inc_step1.php'; /* * STEP TWO * Gather some vital information. */ include './functions/runs/listRun_inc_step2.php'; /* * STEP THREE * Create a table with the System Information. */ include './functions/runs/listRun_inc_step3.php'; /* * STEP FOUR * The Join and Part log. */ include './functions/runs/listRun_inc_step4.php'; /* * STEP FIVE * The Resources Information Table */ include './functions/runs/listRun_inc_step5.php'; /* * STEP SIX * Gather all cans that belong to this miningrun. */ include './functions/runs/listRun_inc_step6.php'; /* * STEP SEVEN * Show the transport manifest */ include './functions/runs/listRun_inc_step7.php'; /* * STEP EIGHT * Calculate the payout. */ include './functions/runs/listRun_inc_step8.php'; /* * STEP NINE * Calculate the Material Conversion from a Perfect Refine. */ //include ('./functions/runs/listRun_inc_step9.php'); /* * Assemble & Return the HTML */ $page = "<h2>Detailed mining run information</h2>"; $page .= $System_table; $isOpen = miningRunOpen($ID); if ($general_info->hasContent()) { $page .= $general_info->flush(); } if ($isOpen) { if ($gotActivePeople) { $page .= "<br>" . $join_info->flush(); } else { $page .= "<br><b><i>There are currently no active pilots.</i></b><br>"; } if ($gotShips) { $page .= "<br>" . $shiptype_info->flush(); } } if ($ISK != 0) { $page .= "<br>" . $payout_info->flush(); } if (isset($partlog_info) && $partlog_info->hasContent()) { $page .= "<br>" . $partlog_info->flush(); } else { $page .= "<b><i>No one ever joined or left this operation.</i></b><br>"; } if ($gotOre) { $page .= "<br>" . $ressources_info->flush(); } else { $page .= "<b><i>Nothing has been mined (and hauled) yet.</i></b><br>"; } /* if (isset ($conversion_info) && $conversion_info->hasContent()) { $page .= "<br>" . $conversion_info->flush(); } else { $page .= "<b><i>There are not records of any hauling.</i></b><br>"; } */ if (getConfig("cargocontainer")) { if ($isOpen) { if (isset($can_information) && $can_information->hasContent()) { $page .= "<br>" . $can_information->flush(); } else { $page .= "<b><i>There are no cans out there that belong to this mining operation.</i></b><br>"; } } } if (isset($hauled_information) && $hauled_information->hasContent()) { $page .= "<br>" . $hauled_information->flush(); } else { $page .= "<b><i>There are not records of any hauling.</i></b><br>"; } return $page; }
function addHaul() { // Globals. global $DB; global $DBORE; global $ORENAME_STR; global $TIMEMARK; global $MySelf; global $STATIC_DB; // Some more settings we need $userID = $MySelf->getID(); // is the POST[id] truly a number? numericCheck($_POST[id]); $ID = sanitize($_POST[id]); // Are we allowed to haul? if (!$MySelf->canAddHaul()) { makeNotice("You are not allowed to haul to runs!", "error", "forbidden"); } // Is the run still open? if (!miningRunOpen($ID)) { makeNotice("This mining operation has been closed!", "warning", "Can not join"); } // Is the user in the run? if (userInRun($MySelf->getUsername(), "{$ID}") == "none") { makeNotice("You need to join that run before you can haul to it!", "error", "Need to join", "index.php?action=show&id={$ID}"); } // Mr. Proper $location = sanitize($_POST[location]); $location2 = sanitize($_POST[location2]); // Use manual input, if given. if ($location2) { $location = $location2; } // We dont accept empty locations. if ($location == "") { makeNotice("You need to supply a target location!", "error", "Commit haul denied.", "index.php?action=addhaul", "[Cancel]"); } // Get the current ore amount for the selected run. $results = $DB->query("select * from runs where id='{$ID}' limit 1"); /* Even tho its only one row (result) we are going to loop * through it. Just to be on the safe side. While we are at it, * we add the submited ore amount to the already stored amount. * * Note: I explicitly *allow* negative amounts to be "added", in * case the hauler got destroyed on his way back. */ /* while ($row = $results->fetchRow()) { foreach ($DBORE as $ORE) { $newcount = $row[$ORE] + $_POST[$ORE]; $DB->query("update runs set $ORE = '" . $newcount . "' where id = '$ID'"); } } */ /* * But wait! There is more! * Someone hauled our ore, lets record that in the * hauled database, along with a timestamp and whatever * he hauled. */ // Lets create the raw entry fist. $OPTYPE = $DB->getCol("select optype from runs where id = {$ID}"); $OPTYPE = $OPTYPE[0]; // Now loop through all the ore-types. foreach ($_POST as $ORE => $QTY) { $oreResult = $DB->query("select count(typeName) as v from {$STATIC_DB}.invTypes where replace(replace(typeName,' ',''),'-','') = '{$ORE}'"); // Check the input, and insert it! $validOre = $oreResult->fetchRow(); if ($validOre[v] > 0 && !empty($QTY) && is_numeric($QTY) && $QTY > 0) { // Is that ore-type actually enabled? if (getOreSettings($ORE, $OPTYPE) == 0 && $OPTYPE != "Shopping") { makeNotice("Your corporation has globally disabled the mining and hauling of {$ORE}. Please ask your CEO to re-enable {$ORE} globally.", "error", "{$ORE} disabled!", "index.php?action=show&id={$ID}", "[back]"); } else { if ($OPTYPE == "Shopping") { $QTY = $QTY * -1; } } // Now insert the database. $DB->query("insert into hauled (miningrun, hauler, time, location, Item, Quantity) values (?,?,?,?,?,?)", array("{$ID}", "{$userID}", "{$TIMEMARK}", "{$location}", "{$ORE}", "{$QTY}")); //$DB->query("UPDATE hauled SET Item = '$ORE', Quantity = '$_POST[$ORE]' WHERE time ='$TIMEMARK' and hauler = '$userID'"); $changed = $changed + $DB->affectedRows(); } } // Delete the haul again if nothing (useful) was entered. if ($changed < 1) { makeNotice("No valid Ore information found in your query, aborted.", "warning", "Haul not accepted", "index.php?action=show&id={$ID}", "[cancel]"); } /* * All done. */ makeNotice("Your hauling information has been entered into the database.", "notice", "Hauling recorded.", "index.php?action=show&id={$ID}"); }
function endrun() { global $DB; global $TIMEMARK; global $MySelf; // Is $_GET[id] truly a number? numericCheck($_GET[id]); // Are we allowed to close runs? $supervisor = $DB->getCol("SELECT supervisor FROM runs WHERE id='" . $_GET[id] . "' LIMIT 1"); if (!$MySelf->canCloseRun() && $MySelf->getID() != $supervisor[0]) { makeNotice("You are not allowed to close runs!", "error", "forbidden"); } // We sure about this? confirm("Are you sure you want to close mining operation {$_GET['id']}? " . "This will remove any active pilots that are still on this" . " run, and close this run for good."); // Run already closed? if (!miningRunOpen($_GET[id])) { makeNotice("This mining operation has already been closed!", "warning", "Operation closed already", "index.php?action=show&id={$_GET['id']}"); } // Moved to the end of the payout to allow correct calculations // Update the database. //$DB->query("update runs set endtime = '$TIMEMARK' where id = '$_GET[id]' and endtime is NULL"); // now "eject" all members. //$DB->query("update joinups set parted = '$TIMEMARK' where parted is NULL and run = '$_GET[id]'"); // Calculate Payout, IF this is an official run. $ID = $_GET[id]; $OfficialRun = $DB->getCol("SELECT isOfficial FROM runs WHERE id='{$ID}'"); // calculate the total value of this op. $ISK = getTotalWorth($ID, true); if ($OfficialRun[0] && getTotalWorth($ID) != 0) { // Select all people, except banned ones. $joinedPeople = $DB->query("SELECT DISTINCT userid FROM joinups WHERE run ='{$ID}' AND status < 2"); // Also, create the charity array. $charityDB = $DB->query("SELECT userid, charity FROM joinups WHERE run ='{$ID}' AND status < 2"); while ($c = $charityDB->fetchRow()) { $charityArray[$c[userid]] = $c[charity]; } // get the payout array. Fun guaranteed. while ($peep = $joinedPeople->fetchRow()) { $payoutArray[$peep[userid]] = calcPayoutPercent($ID, $peep[userid]); } // Calulate the percent-modifier. $percentModifier = 100 / array_sum($payoutArray); // Apply the modifier to the percentage. $names = array_keys($payoutArray); // Add the credit. $supervisor = usernameToID(runSupervisor($_GET[id])); foreach ($names as $name) { $percent = $payoutArray[$name] * $percentModifier; $payout = $ISK / 100 * $percent; // You cannot loose isk from a mission. if ($payout != 0 && !$charityArray[$name]) { addCredit($name, $supervisor, $payout, $_GET[id]); $finalPercent[$name] = $payout; } } // Moved to the end of the payout to allow correct calculations // Update the database. $DB->query("update runs set endtime = '{$TIMEMARK}' where id = '{$ID}' and endtime is NULL"); // now "eject" all members. $DB->query("update joinups set parted = '{$TIMEMARK}' where parted is NULL and run = '{$ID}'"); // wrap things up. makeEmailReceipt($ID, $finalPercent); makeNotice("The mining operation has ended. All still active pilots have been removed from the run and each pilot has been credited his share of the net income.", "notice", "Mining Operation closed", "index.php?action=list", "[OK]"); } // Moved to the end of the payout to allow correct calculations // Update the database. $DB->query("update runs set endtime = '{$TIMEMARK}' where id = '{$ID}' and endtime is NULL"); // now "eject" all members. $DB->query("update joinups set parted = '{$TIMEMARK}' where parted is NULL and run = '{$ID}'"); // wrap things up. makeNotice("The mining operation has ended. All still active pilots have been removed from the run.", "notice", "Mining Operation closed", "index.php?action=list", "[OK]"); }