Example #1
0
function makeOreWorth()
{
    // Get the globals.
    global $TIMEMARK;
    global $ORENAMES;
    global $DBORE;
    global $DB;
    global $OTYPENAME;
    global $PRICECRITERIA;
    // Where do I get Ore Values?
    $Market = getConfig("useMarket");
    if ($Market) {
        // Update prices from Eve-Central and store.
        if ($Market == "eve-central") {
            $CURRENTTIME = date(U) - getConfig("timeOffset") * 60 * 60;
            $itemListDB = $DB->query("SELECT * FROM `itemList` ORDER BY `itemName` DESC");
            $orderType = $OTYPENAME[getConfig("orderType")];
            $priceCrit = $PRICECRITERIA[getConfig("priceCriteria")];
            for ($i = 0; $i <= $itemListDB->numRows(); $i++) {
                $itemInfo = $itemListDB->fetchRow();
                $quoteAge = $CURRENTTIME - $itemInfo['updateTime'];
                if ($quoteAge >= 3600) {
                    $currentPrice = getMarketPrice($itemInfo['itemID'], $orderType, $priceCrit);
                    $DB->query("UPDATE itemList SET `updateTime` = {$CURRENTTIME}, `value` = {$currentPrice} WHERE `itemID` = " . $itemInfo['itemID']);
                }
            }
        } else {
            if ($Market == "eve-marketdata") {
            } else {
                if ($Market == "eve-marketeer") {
                    $regionID = getConfig("useRegion");
                    $url = "http://www.evemarketeer.com/api/info/{$itemID}/xml/{$regionID}/buy_highest5";
                    $xml = getXMLobj($url);
                    echo $xml[row][buy_highest5];
                }
            }
        }
    } else {
        // load the values.
        $orevaluesDS = $DB->query("select a.item, a.Worth, a.time, a.modifier from orevalues a where time = (select max(time) from orevalues b where a.item = b.item) group by item ORDER BY time DESC");
        while ($row = $orevaluesDS->fetchRow()) {
            $orevalues[$row[item]] = $row;
        }
    }
    if ($Market) {
        $headerText = ">> Manage ore values<br><font color=\"#ff0000\"><b>Ore values are current market values.</b></font>";
    } else {
        $headerText = ">> Manage ore values";
    }
    // Create the table.
    $table = new table(8, true);
    $table->addHeader($headerText, array("bold" => true, "colspan" => 8));
    $OPTYPE = isset($_REQUEST[optype]) ? $_REQUEST[optype] : "";
    $table->addRow();
    $table->addCol("Op Type:");
    $ops = $DB->getAll("select opName from opTypes;");
    if ($DB->isError($ops)) {
        die($ops->getMessage());
    }
    $opSelect = "<select name='optype' onChange='window.location = \"?action=changeow&optype=\"+this.value'>\n";
    $opSelect .= "<option value=''>Standard</option>\n";
    foreach ($ops as $op) {
        $default = $op[opName] == $OPTYPE ? "selected" : "";
        $opSelect .= "<option {$default} value='" . $op[opName] . "'>" . $op[opName] . "</option>\n";
    }
    $opSelect .= "</select>";
    $table->addCol($opSelect, array("colspan" => 7));
    $table->addRow();
    $table->addCol("Ore Name", array("colspan" => 2, "bold" => true));
    $table->addCol("Enabled", array("bold" => true));
    $table->addCol("Value", array("bold" => true));
    $table->addCol("Ore Name", array("colspan" => 2, "bold" => true));
    $table->addCol("Enabled", array("bold" => true));
    $table->addCol("Value", array("bold" => true));
    // How many ores are there in total? Ie, how long has the table to be?
    $tableLength = ceil(count($ORENAMES) / 2) - 1;
    for ($i = 0; $i <= $tableLength; $i++) {
        $right = 0;
        $table->addRow();
        for ($side = 0; $side <= 1; $side++) {
            $ORE = $ORENAMES[$i + ($tableLength + 1) * $side];
            // Fetch the right image for the ore.
            $ri_words = str_word_count($ORE, 1);
            $ri_max = count($ri_words);
            $ri = strtolower($ri_words[$ri_max - 1]);
            if ($ORE != "") {
                $table->addCol("<img width=\"32\" height=\"32\" src=\"./images/ores/" . $ORE . ".png\">");
                $table->addCol($ORE);
                if (getOreSettings($DBORE[$ORE], $OPTYPE)) {
                    $table->addCol("<input name=\"" . $DBORE[$ORE] . "Enabled\" value=\"true\" type=\"checkbox\" checked=\"checked\">");
                } else {
                    $table->addCol("<input name=\"" . $DBORE[$ORE] . "Enabled\" value=\"true\" type=\"checkbox\">");
                }
                if ($Market == 1) {
                    $thisPrice = getPriceCache($ORE);
                    $table->addCol("<input type=\"text\" style=\"text-align: right\" name=\"{$DBORE[$ORE]}\"" . "size=\"10\" value=\"" . $thisPrice . "\">");
                } else {
                    $table->addCol("<input type=\"text\" style=\"text-align: right\" name=\"{$DBORE[$ORE]}\"" . "size=\"10\" value=\"" . $orevalues[$DBORE[$ORE]][Worth] . "\">");
                }
            } else {
                $table->addCol("");
                $table->addCol("");
                $table->addCol("");
                $table->addCol("");
            }
        }
    }
    $form .= "<input type=\"hidden\" name=\"action\" value=\"changeore\">";
    $form .= "<input type=\"hidden\" name=\"check\" value=\"check\">";
    $form .= "<input type=\"hidden\" name=\"optype\" value=\"{$OPTYPE}\">";
    $form .= "<input type=\"submit\" name=\"change\" value=\"Modify ore settings\">";
    $table->addHeaderCentered($form, array("colspan" => 8, "align" => "center"));
    // return the page
    return "<h2>Modify ore settings</h2><form action=\"index.php\"method=\"post\">" . $table->flush();
}
Example #2
0
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}");
}
Example #3
0
function addRun()
{
    // We need some more globals.
    global $DB;
    global $ORENAMES;
    global $DBORE;
    global $ORENAMES_STR;
    global $MySelf;
    global $TIMEMARK;
    // Set the userID
    $userID = $MySelf->getID();
    // Are we permitted to create a new run?
    if (!$MySelf->canCreateRun()) {
        makeNotice("You are not allowed to create a mining op!", "error", "forbidden");
    }
    if ($_POST[startnow]) {
        $starttime = $TIMEMARK;
    } else {
        // Startting time goodness.
        $myTime = array("day" => "{$_POST['ST_day']}", "month" => "{$_POST['ST_month']}", "year" => "{$_POST['ST_year']}", "hour" => "{$_POST['ST_hour']}", "minute" => "{$_POST['ST_minute']}");
        $starttime = humanTime("toUnix", $myTime);
    }
    // Having fun with checkboxes, yet again.
    if ($_POST[isOfficial] == "on") {
        $official = true;
    } else {
        $official = false;
    }
    // We using either predefined locations.
    if (empty($_POST[location])) {
        $location = $_POST[locations];
    } else {
        $location = $_POST[location];
    }
    if (empty($location)) {
        makeNotice("You need to specify the location of the Mining Operation!", "notice", "Where again?", "index.php?action=newrun", "[Cancel]");
    }
    // Supervisor
    if ($MySelf->isOfficial()) {
        if (empty($_POST[supervisor])) {
            // Is official, but no one named!
            makeNotice("You need to name someone as the supervisor for this run!", "warning", "Missing Information", "index.php?action=newrun", "[Cancel]");
        } else {
            // Grab ID of named supervisor.
            $supervisor = usernameToID(sanitize($_POST[supervisor]));
        }
    } else {
        // Non official, use own ID
        $supervisor = $MySelf->getID();
    }
    // Corp tax
    if ($MySelf->isOfficial()) {
        if ($_POST[corpkeeps] > 100 || $_POST[corpkeeps] < 0 || !numericCheckBool($_POST[corpkeeps])) {
            makeNotice("The corporation can not keep more than 100% and most certainly wont pay out more than the gross worth (values below 0%). A value of " . $_POST[corpkeeps] . " is really not valid.", "warning", "Out of range", "index.php?action=newrun", "[Cancel]");
        } else {
            $tax = $_POST[corpkeeps];
        }
    } else {
        $tax = "0";
    }
    /*
    // Get the current ore-values.
    $oreValue = $DB->getCol("SELECT max(time) FROM orevalues");
    $oreValue = $oreValue[0];
    */
    //Edit Starts Here
    $shipValue = $DB->getCol("SELECT max(id) FROM shipvalues");
    $shipValue = $shipValue[0];
    $optype = $_REQUEST[optype];
    //Edit Ends Here
    $DB->query("insert into runs (location, starttime, supervisor, corpkeeps, isOfficial, oreGlue, shipGlue,optype) " . "values (?,?,?,?,?,?,?,?)", array("{$location}", "{$starttime}", "{$supervisor}", $tax, $official, "{$TIMEMARK}", $shipValue, "{$optype}"));
    // Check for success.
    if ($DB->affectedRows() != 1) {
        makeNotice("DB Error: Could not add run to database!", "error", "DB Error");
    }
    // Now update the "required" ore values.
    foreach ($DBORE as $ORE) {
        // But the ore needs to be set, valid (numeric) and must be activated.
        if (isset($_POST[$ORE]) && is_numeric($_POST[$ORE]) && getOreSettings($ORE) == true && $_POST[$ORE] > 0) {
            $DB->query("UPDATE runs SET " . $ORE . "Wanted='" . $_POST[$ORE] . "' WHERE {$starttime}='{$starttime}'");
        }
    }
    // And return the user to the run-list overview page.
    makeNotice("The new Mining Operation has been created in the database.", "notice", "Mining Operation created", "index.php?action=list", "[OK]");
}
Example #4
0
function addhaulpage()
{
    // Needed globals
    global $DB;
    global $ORENAMES;
    global $DBORE;
    global $MySelf;
    // Some needed variables
    $USER = $MySelf->getID();
    $ORESETTINGS = getOreSettings();
    // Get the run the user is on.
    if (!empty($_GET[id])) {
        // We supplied our own ID.
        $ID = sanitize((int) $_GET[id]);
        numericCheck($_GET[id], 0);
    } else {
        // No idd supplied, get our own :P
        $ID = userInRun($MySelf->getID());
    }
    //   No ID found.
    if (!$ID) {
        makeNotice("Either you have selected an invalid run, you have not joined that run or it is no longer open.", "warning", "Unable to register your haul");
    }
    $OPTYPE = $DB->getCol("select optype from runs where id = {$ID}");
    $OPTYPE = $OPTYPE[0];
    // Create the table!
    $haulpage = new table(2, true);
    $mode = array("bold" => true, "align" => "right");
    $haulpage->addHeader(">> Register new Hauling");
    $haulpage->addRow();
    if ($OPTYPE == "Shopping") {
        $haulpage->addCol("Shopping for Op: #<a href=\"index.php?action=show&id={$ID}\">" . str_pad($ID, 5, "0", STR_PAD_LEFT) . "</a> Add *positive* values for purchases", array("align" => "left"));
    } else {
        $haulpage->addCol("Hauling for Op: #<a href=\"index.php?action=show&id={$ID}\">" . str_pad($ID, 5, "0", STR_PAD_LEFT) . "</a>", array("align" => "left"));
    }
    // fetch the system the haul is taking place in..
    //	$location = $DB->getCol("select location from runs where endtime is NULL and id='$ID' order by id desc limit 1");
    //	$runLocation = $location[0];
    $runLocation = getLocationOfRun($ID);
    // make the targeted system click-able.
    $sytem = new solarSystem($runLocation);
    // Assemble a PDM with all the destinations for the current run.
    $locations = $DB->query("SELECT location FROM hauled WHERE miningrun='{$ID}' ORDER BY location ASC");
    if ($locations->numRows()) {
        while ($loc = $locations->fetchRow()) {
            if ($loc[location] != "") {
                $pdmSystems[] = $loc[location];
            }
        }
    }
    // Get the location the last haul was brought to at.
    $lastHaulLocation = $DB->getCol("SELECT location FROM hauled WHERE miningrun='{$ID}' AND hauler='" . $MySelf->getID() . "' ORDER BY time DESC LIMIT 1");
    $lastHaulLocation = $lastHaulLocation[0];
    // Get a list of neighbouring systems.
    $neighbouringSystems = $sytem->getNeighbouringSystems();
    // Lets pick the right system.
    if ($lastHaulLocation) {
        // Use the last system stuff was hauled to.
        $location = $lastHaulLocation;
    } else {
        // Or, if thats empty, the system the op is in.
        $location = $runLocation;
    }
    if (is_array($pdmSystems)) {
        $Systems = array_merge($neighbouringSystems, $pdmSystems);
    } else {
        $Systems = $neighbouringSystems;
    }
    sort($Systems);
    //	unset($pdmSystems);
    //	unset($neighbouringSystems);
    //	unset($loc);
    //	unset($locations);
    foreach ($Systems as $s) {
        if ($s == $location) {
            $pdm .= "<option value=\"" . strtolower($s) . "\" SELECTED>" . ucfirst($s) . "</option>";
        } else {
            $pdm .= "<option value=\"" . strtolower($s) . "\">" . ucfirst($s) . "</option>";
        }
    }
    $pdm = "<select name=\"location\">" . $pdm . "</select>";
    $haulpage->addCol("System hauling to: " . $pdm . " -or- <input type=\"text\" name=\"location2\" value=\"\">", array("align" => "right"));
    $haulpage->addRow();
    $haulpage->addCol("<hr>", array("colspan" => "2"));
    // Now we need the sum of all ores.
    $totalOres = count($ORENAMES);
    /*
    // And the sum of all ENABLED ores.
    $totalEnabledOres = $DB->getCol("select count(name) as active from config where name LIKE '%Enabled' AND value='1'");
    $totalEnabledOres = $totalEnabledOres[0];
    */
    /*
     * This is evil. We have to create an array that we fill up sorted.
     * It aint cheap. First, we loop through all the ore values.
     */
    for ($p = 0; $p < $totalOres; $p++) {
        // Then we check each ore if it is enabled.
        $ORE = $DBORE[$ORENAMES[$p]];
        if (getOreSettings($ORE, $OPTYPE)) {
            // If the ore is enabled, add it to the array.
            $left[] = $ORE;
        } else {
            // add to disabled-array.
            $disabledOres[] = $ORE;
        }
    }
    $totalEnabledOres = count($left);
    // No ores enabled?
    if ($totalEnabledOres == 0 && $OPTYPE != "Shopping") {
        makeNotice("Your CEO has disabled *all* the Oretypes. Please ask your CEO to reactivate at leat one Oretype.", "error", "No valid Oretypes!");
    }
    $ajaxHaul = isset($_GET[ajaxHaul]);
    if ($ajaxHaul || $OPTYPE == "Shopping") {
        $haulpage->addRow();
        $script = "<script>\nvar selectedItems = \"\";\nvar currentQuery;\nvar int;\nfunction lookForItem(txt){\n\tcurrentQuery = txt;\n\tclearInterval(int);\n\tif(txt.value.length>2){\n\t\tvar int=self.setInterval('execQuery()',2000);\n\t}\n}";
        $script .= "\nfunction execQuery(){\n\tclearInterval(int);\n\tvar txt = currentQuery;\n\t\$.ajax({\n\t\turl: 'index.php?action=getItemList&ajax&q=' + txt.value,\n\t\tsuccess: function(data){\$('#ajaxItemList').html(data);}\n\t});\n\t\n}";
        $script .= "\nfunction addItem(selection){\n\t//\$(selection).animate({background-color:yellow;});\n\tvar item = selection.innerHTML;\n\tvar dbore = selection.name;\n\t//\$(selection).animate({background-color:none;});\n\tif(selectedItems.split(',').indexOf(item) == -1 ){\n\t\tvar print = \$('#selectedItemList').html() + '<div>Add <input type=\"text\" size=\"5\" name=\"' + dbore + '\" value=\"0\">' + item + '</div>';\n\t\t\$('#selectedItemList').html(print);\n\t\tif(selectedItems.length == 0){\n\t\t\tselectedItems = item;\n\t\t} else {\n\t\t\tselectedItems += ',' + item;\n\t\t}\n\t}\n}\n</script> ";
        $haulpage->addCol("Search for an item:<input name='itemSearch' onkeyup='lookForItem(this)' />, then click the item name below.", array("colspan" => 2));
        $haulpage->addRow();
        $haulpage->addCol("<div id='selectedItemList'></div>", array("colspan" => 2));
        $haulpage->addRow();
        $haulpage->addCol("<div id='ajaxItemList'></div>", array("colspan" => 2));
    } else {
        // The table is, rounded up, exactly half the size of all enabled ores.
        $tableLength = ceil($totalEnabledOres / 2);
        // Now, copy the lower second half into a new array.
        $right = array_slice($left, $tableLength);
        /*
         * So now we have an array of all the enabled ores. All we
         * need to do now, is create a nice, handsome table of it.
         * Loop through this array.
         */
        for ($i = 0; $i < $tableLength; $i++) {
            // Fetch the right image for the ore.
            $ri_words = str_word_count(array_search($left[$i], $DBORE), 1);
            $ri_max = count($ri_words);
            $ri = strtolower($ri_words[$ri_max - 1]);
            // Add a row.
            $haulpage->addRow();
            // left side.
            $haulpage->addCol("<img width=\"20\" height=\"20\" src=\"./images/ores/" . array_search($left[$i], $DBORE) . ".png\">" . "Add <input type=\"text\" size=\"5\" name=\"{$left[$i]}\" value=\"0\"> " . array_search($left[$i], $DBORE));
            // We need an ore type (just in case of odd ore numbers)
            if ($right[$i] != "") {
                // right side.
                // Fetch the right image for the ore.
                $ri_words = str_word_count(array_search($right[$i], $DBORE), 1);
                $ri_max = count($ri_words);
                $ri = strtolower($ri_words[$ri_max - 1]);
                // Add the column.
                $haulpage->addCol("<img width=\"20\" height=\"20\" src=\"./images/ores/" . array_search($right[$i], $DBORE) . ".png\">" . "Add <input type=\"text\" size=\"5\" name=\"" . $right[$i] . "\" value=\"0\"> " . array_search($right[$i], $DBORE));
            } else {
                // We have an odd number of ores: add empty cell.
                $haulpage->addCol("");
            }
        }
    }
    /*
    // Print out all disabled ore types:
    $disabledOreCount = count($disabledOres);
    
    // add the "," between words, but not before the first one, and an "and" between the last one.
    for ($i = 0; $i < $disabledOreCount; $i++) {
    	if ($disabledOreCount == $i +1) {
    		$disabledOresText .= " and " . array_search($disabledOres[$i], $DBORE);
    	} else
    		if (empty ($disabledOresText)) {
    			$disabledOresText = array_search($disabledOres[$i], $DBORE);
    		} else {
    			$disabledOresText .= ", " . array_search($disabledOres[$i], $DBORE);
    		}
    }
    
    // Display the ore-disables-disclaimer. (Only if there are disabled oretypes.)
    if (!empty ($disabledOresText)) {
    	$disabledOresText = "The following Oretypes has been disabled by the CEO: $disabledOresText.";
    }
    */
    $haulpage->addRow();
    $haulpage->addCol("<hr>", array("colspan" => "2"));
    $haulpage->addHeaderCentered("<input type=\"submit\" name=\"haul\" value=\"Commit haul to database\">");
    // Render the page...
    $form_stuff .= "<input type=\"hidden\" value=\"check\" name=\"check\">";
    $form_stuff .= "<input type=\"hidden\" value=\"addhaul\" name=\"action\">";
    $form_stuff .= "<input type=\"hidden\" value=\"" . $ID . "\" name=\"id\">";
    $form_stuff .= "</form>";
    $html = "<h2>Submit new transport manifest (<a href='?" . $_SERVER['QUERY_STRING'] . "&ajaxHaul'>ajax</a>)</h2><form action=\"index.php\" method=\"post\">" . $haulpage->flush() . $form_stuff;
    /*
    	// print out all the disabled oretypes.
    	if (!empty ($disabledOresText)) {
    		$page .= "<br><i>" . $disabledOresText . "</i>";
    	}*/
    // Return the page
    return $script . $html . $page;
}