Esempio n. 1
0
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}");
    }
}
Esempio n. 2
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;
}