Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
function calculateTotalIskMined()
{
    global $DB;
    $allRuns = $DB->query("SELECT id FROM runs");
    if ($allRuns->numRows() > 0) {
        while ($ID = $allRuns->fetchRow()) {
            $ID = $ID[id];
            $ISK = $ISK + getTotalWorth($ID);
        }
    } else {
        $ISK = "0";
    }
    return $ISK;
}
Exemplo n.º 3
0
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 *  OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
// Calculate Payout:
$joinedPeople = $DB->query("SELECT DISTINCT userid FROM joinups WHERE run ='{$ID}' AND status < '2'");
$ISK = getTotalWorth($ID, true);
if ($ISK != 0) {
    $payout_info = new table(3, true);
    $payout_info->addHeader(">> Payout Information");
    $payout_info->addRow("060622");
    $payout_info->addCol("Pilot", array("bold" => true));
    $payout_info->addCol("Percent of Net", array("bold" => true));
    $payout_info->addCol("Payout", array("bold" => true));
    // get the payout array. Fun guaranteed.
    while ($peep = $joinedPeople->fetchRow()) {
        $payoutArray[idToUsername($peep[userid])] = calcPayoutPercent($ID, $peep[userid]);
    }
    // Calulate the percent-modifier.
    $percentModifier = 100 / array_sum($payoutArray);
    // Apply the modifier to the percentage.
    $names = array_keys($payoutArray);
Exemplo n.º 4
0
function makeEmailReceipt($runid, $array)
{
    // Set variables.
    global $DB;
    global $DBORE;
    global $ORENAMES;
    global $MB_EMAIL;
    //Edit Starts Here
    global $DBSHIP;
    global $SHIPNAMES;
    //Edit Ends Here
    global $VERSION;
    global $URL;
    // Load the run
    $RUN = $DB->query("SELECT * FROM runs WHERE id='{$runid}' LIMIT 2");
    if ($RUN->numRows() != 1) {
        // This run does not exist!
        return;
    } else {
        $RUN = $RUN->fetchRow();
    }
    // Load the ore values
    $oreValues = $DB->query("SELECT * FROM orevalues WHERE id='" . $RUN[oreGlue] . "' LIMIT 1");
    $oreValues = $oreValues->fetchRow();
    //Edit Starts Here
    // Load the ship values
    $shipValues = $DB->query("SELECT * FROM shipvalues WHERE id='" . $RUN[shipGlue] . "' LIMIT 1");
    $shipValues = $shipValues->fetchRow();
    //Edit Ends Here
    // Get total number of people who joined.
    $totalPeople = $DB->getCol("SELECT count(DISTINCT userid) FROM joinups WHERE run='{$runid}'");
    $totalPeople = $totalPeople[0];
    /*
     * Taxes, net value etc
     */
    $grossValue = getTotalWorth($runid);
    $corpTax = $DB->getCol("SELECT corpkeeps FROM runs WHERE id='{$runid}' LIMIT 1");
    $corpTax = $corpTax[0];
    $taxes = $grossValue * $corpTax / 100;
    $netValue = $grossValue - $taxes;
    $myShareGross = $grossValue / $totalPeople;
    // No ores mined. Bye-bye.
    if ($grossValue < 1) {
        return;
    }
    /*
     * Get the longest name of the ores.
     */
    foreach ($ORENAMES as $howlong) {
        $length = strlen($howlong);
        if ($length > $winner) {
            $winner = $length;
        }
    }
    /*
     * Get all the ores.
     */
    foreach ($DBORE as $ORE) {
        if ($RUN[$ORE] > 0) {
            $oreType = str_pad(array_search($ORE, $DBORE), $winner, " ");
            $oreAmount = str_pad(number_format($RUN[$ORE]), 11, " ");
            $ppu = $oreValues[$ORE . "Worth"];
            $oreValue = str_pad(number_format($ppu) . " ISK", 11, " ");
            $remainder = 70 - (strlen($oreType) + strlen($oreAmount) + strlen($oreValue));
            $oreTotalValue = str_pad(number_format($ppu * $RUN[$ORE]) . " ISK", $remainder, " ", STR_PAD_LEFT);
            $l1 = strlen($oreAmount);
            $l1 = strlen($oreValue);
            $l1 = strlen($oreTotalValue);
            if ($OreLine) {
                $OreLine .= "\n";
            }
            $OreLine .= $oreType . $oreAmount . $oreValue . $oreTotalValue;
        }
    }
    /*
     * Replace the placeholders
     */
    $email = new email("receipt");
    $temp = $email->getTemplate();
    $temp = str_replace("{{ID}}", str_pad($runid, 5, "0", STR_PAD_LEFT), $temp);
    $temp = str_replace("{{ORESMINED}}", $OreLine, $temp);
    $temp = str_replace("{{VALUE}}", number_format($grossValue) . " ISK", $temp);
    $temp = str_replace("{{CORPTAXES}}", number_format($taxes) . " ISK", $temp);
    $temp = str_replace("{{NETVALUE}}", number_format($netValue) . " ISK", $temp);
    $temp = str_replace("{{GROSSSHARE}}", number_format($myShareGross) . " ISK", $temp);
    $template = $temp;
    /*
     * This ends the part thats generic for everyone. Now the personalized stuff.
     */
    $Atendees = $DB->query("SELECT DISTINCT userid FROM joinups WHERE run='{$runid}'");
    while ($atendee = $Atendees->fetchRow()) {
        // Reset the email back to the template.
        $temp = $template;
        /*
         * PROBLEM
         * 
         * Template is changed in email class, further modding in this loop
         * would require rewrite of either email class or this function.
         * 
         */
        die("PROBLEM");
        // Do some personalized stuff.
        $pilot = idToUsername($atendee[userid]);
        $temp = str_replace("{{USERNAME}}", ucfirst($pilot), $temp);
        $temp = str_replace("{{ACCOUNTBALANCE}}", str_pad("BALANCE: " . number_format(getCredits($atendee[userid])), 66, " ", STR_PAD_LEFT) . " ISK", $temp);
        $myShare = $array[$atendee[userid]];
        $temp = str_replace("{{NETSHARE}}", number_format($myShare) . " ISK", $temp);
        /*
         * transactions
         */
        $transactions = $DB->query("SELECT * FROM transactions WHERE owner ='{$atendee['userid']}' ORDER BY id DESC LIMIT 10");
        if ($transactions->numRows() > 0) {
            while ($trans = $transactions->fetchRow()) {
                // time type amount reason
                $transLine .= date("m.d.y h:i:", $trans[time]);
                if ($trans[type]) {
                    $transLine .= " [W]";
                } else {
                    $transLine .= " [D]";
                }
                $transLine .= " \"" . substr($trans[reason], 0, 33) . "\"";
                $length = strlen($transLine);
                $remainder = 70 - $length;
                $transLine .= str_pad(number_format($trans[amount]) . " ISK", $remainder, " ", STR_PAD_LEFT);
                // Add the line to the block.
                if ($transBlock) {
                    $transBlock .= "\n";
                }
                $transBlock .= $transLine;
                unset($transLine);
            }
        } else {
            $transLine = "No recent transactions.";
        }
        $temp = str_replace("{{ACCOUNT}}", $transBlock, $temp);
        // Mail, if opt-in.
        $userInfo = $DB->query("SELECT username, id, optIn, email FROM users WHERE id='" . $atendee[userid] . "' AND deleted='0'");
        $userInfo = $userInfo->fetchRow();
        if ($userInfo[email] && $userInfo[optIn]) {
            $to = $userInfo[email];
            $subject = "MiningBuddy Payout";
            $message = $email;
            $DOMAIN = $_SERVER['HTTP_HOST'];
            $headers = "From:" . $MB_EMAIL;
            mail($to, $subject, $message, $headers);
        }
    }
}
Exemplo n.º 5
0
function listRuns()
{
    /* bgcolor and i are used to alternate the tablerow
     * background color.
     */
    $bgc = array("#222222", "#333333");
    $bgi = 0;
    // Our database.
    global $DB;
    global $MySelf;
    global $READONLY;
    global $PREFS;
    $sirstate = $PREFS->getPref("sirstate");
    /*
     * LIST OPEN RUNS
     */
    // Query it.
    $results = $DB->query("select * from runs where endtime IS NULL order by id");
    $mode = array("bold" => true);
    $table = new table(9, true);
    $table->addHeader(">> Currently active Operations");
    $table->addRow("#060622");
    $table->addCol("Run ID");
    $table->addCol("Supervisor");
    $table->addCol("Op Type");
    $table->addCol("Starttime");
    $table->addCol("Endtime");
    $table->addCol("Location");
    $table->addCol("Security");
    $table->addCol("Official run");
    $table->addCol("Locked");
    $runsExist = false;
    // Now we loop through each returned result.
    while ($row = $results->fetchRow()) {
        // Skip inofficial runs if user does not want to see them.
        if (!$sirstate && !$row['isOfficial'] && !($MySelf->getID() == $row['supervisor'])) {
            continue;
        }
        $table->addRow();
        $table->addCol("<a href=\"index.php?action=show&id={$row['id']}\">" . str_pad($row['id'], 5, "0", STR_PAD_LEFT) . "</a>");
        $table->addCol(makeProfileLink($row['supervisor']));
        $table->addCol($row['optype'] == "" ? "Standard" : $row['optype']);
        $table->addCol(date("d.m.y H:i", $row['starttime']));
        /* This handles the endtime. Prints endtime if it has already
         * ended, or "active" along with an "end run"-link if still open.
         */
        unset($tmp);
        if ($row['endtime'] == "") {
            $tmp = "<b>active</b>";
            // If access level is above or equal 3 give option to close run.
            if ($MySelf->canCloseRun()) {
                $tmp .= " (<a href=\"index.php?action=endrun&id={$row['id']}\">close run</a>)";
            }
        } else {
            $tmp = date("d.m.y H:i", $row['endtime']);
        }
        // Add the end-time to the table.
        $table->addCol($tmp);
        // Show the security status
        $System = new solarSystem($row['location']);
        if ($System->valid()) {
            $table->addCol($System->makeFancyLink());
            $table->addCol($System->getSecurity());
        } else {
            $table->addCol(ucfirst($row['location']));
            $table->addCol("?");
        }
        $table->addCol(yesno($row['isOfficial'], true));
        $table->addCol(yesno($row['isLocked'], true, true));
        $runsExist = true;
        // We wont print out table if there are no open runs.
    }
    /*
     *  LIST CLOSED RUNS
     */
    // Query it.
    if (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0) {
        $page = "LIMIT " . $_GET['page'] * 20 . ", 20";
    } elseif (isset($_GET['page']) && $_GET['page'] == "all") {
        $page = "";
    } else {
        $page = "LIMIT 20";
    }
    $results = $DB->query("SELECT * FROM runs WHERE endtime IS NOT NULL ORDER BY endtime DESC {$page}");
    // This is the table header.
    $table_closed = new table(11, true);
    $table_closed->addHeader(">> Archived Operations");
    $table_closed->addRow("#060622");
    $table_closed->addCol("Run ID");
    $table_closed->addCol("Supervisor");
    $table_closed->addCol("Op Type");
    $table_closed->addCol("Starttime");
    $table_closed->addCol("Endtime");
    $table_closed->addCol("Location");
    $table_closed->addCol("Security");
    $table_closed->addCol("Yield");
    $table_closed->addCol("TMEC(tm)");
    $table_closed->addCol("Was official");
    // Offer delete button.
    if ($MySelf->canDeleteRun() && !$READONLY) {
        $table_closed->addCol("Delete", $mode);
    } else {
        $table_closed->addCol("");
    }
    // Now we loop through each returned result.
    while ($row = $results->fetchRow()) {
        // Skip inofficial runs if user does not want to see them.
        if (!$sirstate && !$row['isOfficial'] && !($MySelf->getID() == $row['supervisor'])) {
            continue;
        }
        $table_closed->addRow();
        $table_closed->addCol("<a href=\"index.php?action=show&id={$row['id']}\">" . str_pad($row['id'], 5, "0", STR_PAD_LEFT) . "</a>");
        $table_closed->addCol(makeProfileLink($row['supervisor']));
        $table_closed->addCol($row['optype'] == "" ? "Standard" : $row['optype']);
        $table_closed->addCol(date("d.m.y H:i", $row['starttime']));
        /* This handles the endtime. Prints endtime if it has already
         * ended, or "active" along with an "end run"-link if still open.
         */
        unset($tmp);
        if ("{$row['endtime']}" == "") {
            $tmp = "<b>active</b>";
            // If access level is above or equal 3 give option to close run.
            if ($MySelf->canCloseRun()) {
                $tmp .= " (<a href=\"index.php?action=endrun&id={$row['id']}\">close run</a>)";
            }
        } else {
            $tmp = date("d.m.y H:i", $row['endtime']);
        }
        // Add the end-time to the table.
        $table_closed->addCol($tmp);
        // Show the security status
        $System = new solarSystem($row['location']);
        if ($System->valid()) {
            $table_closed->addCol($System->makeFancyLink());
            $table_closed->addCol($System->getSecurity());
        } else {
            $table_closed->addCol(ucfirst($row['location']));
            $table_closed->addCol("?");
        }
        // get the total ores gained.
        $totalIsk = getTotalWorth($row['id']);
        $table_closed->addCol(number_format($totalIsk, 2) . " ISK", array("style" => "text-align:right;"));
        // Add the TMEC
        if ($row['tmec'] == 0) {
            $TMEC = calcTMEC($row['id']);
        } else {
            $TMEC = $row['tmec'];
        }
        $table_closed->addCol($TMEC, array("style" => "text-align:right;"));
        // Add "run is official" bit.
        $table_closed->addCol(yesno($row['isOfficial'], true), array("style" => "text-align:right;"));
        $closedRunsExist = true;
        // We wont print out table if there are no open runs.
        // Add possible delete run button.
        if ($MySelf->canDeleteRun() && !$READONLY) {
            $table_closed->addCol("<a href=\"index.php?action=deleterun&id={$row['id']}\">delete</a>");
        } else {
            $table_closed->addCol("");
        }
    }
    // The "show this many ops"-part.
    $count = $DB->getCol("SELECT COUNT(id) FROM runs WHERE endtime > 0");
    $countSteps = floor($count[0] / 20);
    $showMore = "Switch to page >> ";
    for ($i = 1; $i <= $countSteps; $i++) {
        $thisStep = str_pad($i, 2, "0", STR_PAD_LEFT);
        $showMore .= "[<a href=\"index.php?action=list&page=" . $thisStep . "\">" . $thisStep . "</a>] ";
    }
    $showMore .= "[<a href=\"index.php?action=list&page=all\">All</a>] ";
    $table_closed->addHeader($showMore);
    // Fancy it up!
    $page = "<h2>Mining Operations</h2>";
    // Print the open runs table, IF there are open runs.
    if ($runsExist) {
        $page .= $table->flush() . "<br>";
    }
    // Print the closed runs table, IF there are closed runs.
    if ($closedRunsExist) {
        $page .= $table_closed->flush();
    } else {
        $page .= "<i>There are no (closed) mining operations in the database. Is this a fresh installation?</i>";
    }
    return $page;
}
Exemplo n.º 6
0
 $secRunTime = $TIMEMARK - $row['starttime'];
 if ($time) {
     $general_info->addCol("<font color=\"#00ff00\">ACTIVE for " . numberToString($secRunTime) . "</font>");
 } else {
     $general_info->addCol("Event has not started yet.");
 }
 // Row: Corporation keeps %
 $general_info->addRow();
 $general_info->addCol("Corporation keeps:", $common_mode);
 $general_info->addCol("{$row['corpkeeps']}% of gross value.");
 // Current TMEC
 $general_info->addRow();
 $general_info->addCol("Current TMEC:");
 $general_info->addCol(calcTMEC($row['id'], true));
 // Statistical breakdown
 $totalISK = getTotalWorth($ID);
 if ($totalISK > 0) {
     $closed = $DB->getCol("SELECT endtime FROM runs WHERE id='" . $ID . "' LIMIT 1");
     if ($closed[0] < 1) {
         $general_info->addRow();
         $general_info->addCol("Total ISK so far:");
         $general_info->addCol(number_format($totalISK, 2) . " ISK");
         $general_info->addRow();
         $general_info->addCol("ISK per hour:");
         $general_info->addCol(number_format($totalISK / ($secRunTime / 60) * 60) . " ISK");
     }
 }
 // Row: Actions
 $general_info->addRow();
 $general_info->addCol("Actions:", $common_mode);
 // Lets switch wether the user is currently in this run or not.
Exemplo n.º 7
0
function endrun()
{
    global $DB;
    global $TIMEMARK;
    global $MySelf;
    // Is $_GET[id] truly a number?
    numericCheck($_GET[id]);
    // Are we allowed to close runs?
    $supervisor = $DB->getCol("SELECT supervisor FROM runs WHERE id='" . $_GET[id] . "' LIMIT 1");
    if (!$MySelf->canCloseRun() && $MySelf->getID() != $supervisor[0]) {
        makeNotice("You are not allowed to close runs!", "error", "forbidden");
    }
    // We sure about this?
    confirm("Are you sure you want to close mining operation {$_GET['id']}? " . "This will remove any active pilots that are still on this" . " run, and close this run for good.");
    // Run already closed?
    if (!miningRunOpen($_GET[id])) {
        makeNotice("This mining operation has already been closed!", "warning", "Operation closed already", "index.php?action=show&id={$_GET['id']}");
    }
    // Moved to the end of the payout to allow correct calculations
    // Update the database.
    //$DB->query("update runs set endtime = '$TIMEMARK' where id = '$_GET[id]' and endtime is NULL");
    // now "eject" all members.
    //$DB->query("update joinups set parted = '$TIMEMARK' where parted is NULL and run = '$_GET[id]'");
    // Calculate Payout, IF this is an official run.
    $ID = $_GET[id];
    $OfficialRun = $DB->getCol("SELECT isOfficial FROM runs WHERE id='{$ID}'");
    // calculate the total value of this op.
    $ISK = getTotalWorth($ID, true);
    if ($OfficialRun[0] && getTotalWorth($ID) != 0) {
        // Select all people, except banned ones.
        $joinedPeople = $DB->query("SELECT DISTINCT userid FROM joinups WHERE run ='{$ID}' AND status < 2");
        // Also, create the charity array.
        $charityDB = $DB->query("SELECT userid, charity FROM joinups WHERE run ='{$ID}' AND status < 2");
        while ($c = $charityDB->fetchRow()) {
            $charityArray[$c[userid]] = $c[charity];
        }
        // get the payout array. Fun guaranteed.
        while ($peep = $joinedPeople->fetchRow()) {
            $payoutArray[$peep[userid]] = calcPayoutPercent($ID, $peep[userid]);
        }
        // Calulate the percent-modifier.
        $percentModifier = 100 / array_sum($payoutArray);
        // Apply the modifier to the percentage.
        $names = array_keys($payoutArray);
        // Add the credit.
        $supervisor = usernameToID(runSupervisor($_GET[id]));
        foreach ($names as $name) {
            $percent = $payoutArray[$name] * $percentModifier;
            $payout = $ISK / 100 * $percent;
            // You cannot loose isk from a mission.
            if ($payout != 0 && !$charityArray[$name]) {
                addCredit($name, $supervisor, $payout, $_GET[id]);
                $finalPercent[$name] = $payout;
            }
        }
        // Moved to the end of the payout to allow correct calculations
        // Update the database.
        $DB->query("update runs set endtime = '{$TIMEMARK}' where id = '{$ID}' and endtime is NULL");
        // now "eject" all members.
        $DB->query("update joinups set parted = '{$TIMEMARK}' where parted is NULL and run = '{$ID}'");
        // wrap things up.
        makeEmailReceipt($ID, $finalPercent);
        makeNotice("The mining operation has ended. All still active pilots have been removed from the run and each pilot has been credited his share of the net income.", "notice", "Mining Operation closed", "index.php?action=list", "[OK]");
    }
    // Moved to the end of the payout to allow correct calculations
    // Update the database.
    $DB->query("update runs set endtime = '{$TIMEMARK}' where id = '{$ID}' and endtime is NULL");
    // now "eject" all members.
    $DB->query("update joinups set parted = '{$TIMEMARK}' where parted is NULL and run = '{$ID}'");
    // wrap things up.
    makeNotice("The mining operation has ended. All still active pilots have been removed from the run.", "notice", "Mining Operation closed", "index.php?action=list", "[OK]");
}