function resetWorld($getPage_connection3)
{
    if ($_SESSION["admin"] == 1) {
        if (strlen($_SESSION["action"]) >= 1) {
            if ($_SESSION["action"] == "reset_world") {
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE agreements")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE claims")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE combatlog")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE continents")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE improvementsmap")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE nations")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE offers")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE organizations")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE production")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE rankings")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE resourcesmap")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE tilesmap")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE trade")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE transport")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE unitsmap")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE users")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("TRUNCATE TABLE mapmemory")) {
                    $stmt->execute();
                    $stmt->close();
                } else {
                }
                // else
                if ($stmt = $getPage_connection3->prepare("SELECT id FROM market ORDER BY id ASC")) {
                    $stmt->execute();
                    $stmt->store_result();
                    $stmt->bind_result($r_id);
                    while ($stmt->fetch()) {
                        $next_markets = $r_id;
                        $marketInfo1 = getMarketInfo($getPage_connection3, $next_markets);
                        setMarketInfo($getPage_connection3, $next_markets, $marketInfo1["name"], 100);
                    }
                    // while
                    $stmt->close();
                } else {
                }
                // else
                resetSession(false);
                // Create Admin Account, starter continent
                $new_salt = "";
                $new_username = "******";
                $new_avatar = "images/users/avatar.png";
                $allowed_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
                $chars_length = 63;
                for ($i = 0; $i < 51; $i++) {
                    $new_salt .= $allowed_chars[mt_rand(0, $chars_length)];
                }
                // for
                $new_date = date("Y-m-d H:i:s");
                $new_token = mt_rand(1000, 9999);
                $new_thread = mt_rand(100, 999);
                $final_salt = '$2y$09$' . $new_salt . '$';
                $created_password = crypt("qwertyuiop" . $new_salt, $final_salt);
                addUserInfo($getPage_connection3, $new_username, $new_avatar, $new_date, $new_date, $created_password, $new_salt, $new_token, $new_thread, 1);
                $new_userid = $getPage_connection3->insert_id;
                $new_name = "Administrator";
                $new_formal = "Administrator";
                addProductionInfo($getPage_connection3, $new_userid, 100, array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 2), array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 2));
                addRankingInfo($getPage_connection3, $new_userid, 999, 999, 999, 999, 999);
                $new_routes = array(0 => 0);
                $new_worth = array(0 => 0);
                $new_offers = array(0 => 0);
                addTradeInfo($getPage_connection3, $new_userid, $new_routes, 0);
                $capitalBuilt = false;
                $availableTiles = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
                $finalTiles = array(0 => 0, 1 => 0);
                $availableContinent = 0;
                if ($stmt = $getPage_connection3->prepare("SELECT id FROM continents ORDER BY id ASC")) {
                    $stmt->execute();
                    $stmt->store_result();
                    $stmt->bind_result($r_id);
                    while ($stmt->fetch()) {
                        $next_continents = $r_id;
                        $availableTiles = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
                        $next_tiles = 1;
                        $counter1 = 0;
                        if ($stmt2 = $getPage_connection3->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) {
                            $stmt2->execute();
                            $stmt2->store_result();
                            $stmt2->bind_result($r_id1);
                            while ($stmt2->fetch()) {
                                $next_tiles = $r_id1;
                                $tileInfoD = getTileInfoByID($getPage_connection3, $next_tiles);
                                if ($tileInfoD["continent"] == $next_continents && $tileInfoD["owner"] == 0 && $tileInfoD["terrain"] != 2) {
                                    $tileInfoDWest = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] - 1, $tileInfoD["ypos"]);
                                    $tileInfoDNorthWest = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] - 1, $tileInfoD["ypos"] - 1);
                                    $tileInfoDNorth = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] - 1, $tileInfoD["ypos"] - 1);
                                    $tileInfoDNorthEast = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] + 1, $tileInfoD["ypos"] - 1);
                                    $tileInfoDEast = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] + 1, $tileInfoD["ypos"]);
                                    $tileInfoDSouthEast = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] + 1, $tileInfoD["ypos"] + 1);
                                    $tileInfoDSouth = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"], $tileInfoD["ypos"] + 1);
                                    $tileInfoDSouthWest = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] - 1, $tileInfoD["ypos"] + 1);
                                    if ($tileInfoDWest["continent"] == $next_continents && $tileInfoDWest["owner"] == 0 && $tileInfoDWest["terrain"] != 2 || $tileInfoDNorthWest["continent"] == $next_continents && $tileInfoDNorthWest["owner"] == 0 && $tileInfoDNorthWest["terrain"] != 2 || $tileInfoDNorth["continent"] == $next_continents && $tileInfoDNorth["owner"] == 0 && $tileInfoDNorth["terrain"] != 2 || $tileInfoDNorthEast["continent"] == $next_continents && $tileInfoDNorthEast["owner"] == 0 && $tileInfoDNorthEast["terrain"] != 2 || $tileInfoDEast["continent"] == $next_continents && $tileInfoDEast["owner"] == 0 && $tileInfoDEast["terrain"] != 2 || $tileInfoDSouthEast["continent"] == $next_continents && $tileInfoDSouthEast["owner"] == 0 && $tileInfoDSouthEast["terrain"] != 2 || $tileInfoDSouth["continent"] == $next_continents && $tileInfoDSouth["owner"] == 0 && $tileInfoDSouth["terrain"] != 2 || $tileInfoDSouthWest["continent"] == $next_continents && $tileInfoDSouthWest["owner"] == 0 && $tileInfoDSouthWest["terrain"] != 2) {
                                        $availableTiles[$counter1] = $tileInfoD["id"];
                                        $counter1++;
                                    }
                                    // if
                                }
                                // if
                                if ($counter1 == 4) {
                                    $availableContinent = $next_continents;
                                }
                                // if
                            }
                            // while
                            $stmt2->close();
                        } else {
                        }
                        // else
                        if ($counter1 == 4) {
                            break;
                        }
                        // if
                    }
                    // while
                    $stmt->close();
                } else {
                    $next_continents = 0;
                }
                // else
                // get available tiles from newly created continent if no continent is available
                if ($availableContinent < 1) {
                    $continent1 = generateContinent($getPage_connection3);
                    $next_continents = $continent1;
                    $availableContinent = $next_continents;
                    $availableTiles = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
                    $counter1 = 0;
                    if ($stmt = $getPage_connection3->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) {
                        $stmt->execute();
                        $stmt->store_result();
                        $stmt->bind_result($r_result);
                        while ($stmt->fetch()) {
                            $next_tiles = $r_result;
                            $tileInfoD = getTileInfoByID($getPage_connection3, $next_tiles);
                            if ($tileInfoD["continent"] == $next_continents && $tileInfoD["owner"] == 0 && ($tileInfoD["terrain"] != 2 && $tileInfoD["terrain"] != 3)) {
                                $tileInfoDWest = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] - 1, $tileInfoD["ypos"]);
                                $tileInfoDNorthWest = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] - 1, $tileInfoD["ypos"] - 1);
                                $tileInfoDNorth = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] - 1, $tileInfoD["ypos"] - 1);
                                $tileInfoDNorthEast = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] + 1, $tileInfoD["ypos"] - 1);
                                $tileInfoDEast = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] + 1, $tileInfoD["ypos"]);
                                $tileInfoDSouthEast = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] + 1, $tileInfoD["ypos"] + 1);
                                $tileInfoDSouth = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"], $tileInfoD["ypos"] + 1);
                                $tileInfoDSouthWest = getTileInfo($getPage_connection3, $tileInfoD["continent"], $tileInfoD["xpos"] - 1, $tileInfoD["ypos"] + 1);
                                if ($tileInfoDWest["continent"] == $next_continents && $tileInfoDWest["owner"] == 0 && ($tileInfoDWest["terrain"] != 2 && $tileInfoDWest["terrain"] != 3) || $tileInfoDNorthWest["continent"] == $next_continents && $tileInfoDNorthWest["owner"] == 0 && ($tileInfoDNorthWest["terrain"] != 2 && $tileInfoDNorthWest["terrain"] != 3) || $tileInfoDNorth["continent"] == $next_continents && $tileInfoDNorth["owner"] == 0 && ($tileInfoDNorth["terrain"] != 2 && $tileInfoDNorth["terrain"] != 3) || $tileInfoDNorthEast["continent"] == $next_continents && $tileInfoDNorthEast["owner"] == 0 && ($tileInfoDNorthEast["terrain"] != 2 && $tileInfoDNorthEast["terrain"] != 3) || $tileInfoDEast["continent"] == $next_continents && $tileInfoDEast["owner"] == 0 && ($tileInfoDEast["terrain"] != 2 && $tileInfoDEast["terrain"] != 3) || $tileInfoDSouthEast["continent"] == $next_continents && $tileInfoDSouthEast["owner"] == 0 && ($tileInfoDSouthEast["terrain"] != 2 && $tileInfoDSouthEast["terrain"] != 3) || $tileInfoDSouth["continent"] == $next_continents && $tileInfoDSouth["owner"] == 0 && ($tileInfoDSouth["terrain"] != 2 && $tileInfoDSouth["terrain"] != 3) || $tileInfoDSouthWest["continent"] == $next_continents && $tileInfoDSouthWest["owner"] == 0 && ($tileInfoDSouthWest["terrain"] != 2 && $tileInfoDSouthWest["terrain"] != 3)) {
                                    $availableTiles[$counter1] = $tileInfoD["id"];
                                    $counter1++;
                                }
                                // if
                            }
                            // if
                        }
                        // while
                        $stmt->close();
                    } else {
                    }
                    // else
                }
                // if
                $sameTile = true;
                $randTiles = array(0 => 0, 1 => 0);
                while ($sameTile === true) {
                    $randTiles[0] = mt_rand(1, count($availableTiles) - 2);
                    $randDirection = mt_rand(1, 2);
                    if ($randDirection == 1) {
                        $randTiles[1] = $randTiles[0] - 1;
                    } else {
                        if ($randDirection == 2) {
                            $randTiles[1] = $randTiles[0] + 1;
                        }
                    }
                    // else if
                    if ($randTiles[0] == $randTiles[1]) {
                        $sameTile = true;
                    } else {
                        $sameTile = false;
                    }
                    // else
                }
                // while
                $finalTiles[0] = $availableTiles[$randTiles[0]];
                $finalTiles[1] = $availableTiles[$randTiles[1]];
                $claims = array(0 => 0);
                for ($c = 0; $c < 3; $c++) {
                    if (isset($finalTiles[$c])) {
                        if ($finalTiles[$c] > 0) {
                            addClaimInfo($getPage_connection3, 10, $new_userid, $finalTiles[$c]);
                        }
                        // if
                    }
                    // if
                }
                // for
                for ($j = 0; $j < 3; $j++) {
                    if (isset($finalTiles[$j])) {
                        if ($finalTiles[$j] > 0) {
                            $tileInfo2 = getTileInfoByID($getPage_connection3, $finalTiles[$j]);
                            setTileInfo($getPage_connection3, $tileInfo2["id"], $tileInfo2["continent"], $tileInfo2["xpos"], $tileInfo2["ypos"], $tileInfo2["terrain"], $tileInfo2["resources"], $tileInfo2["improvements"], $new_userid, $tileInfo2["claims"], $tileInfo2["population"]);
                            if ($capitalBuilt === false) {
                                addImprovementInfo($getPage_connection3, $tileInfo2["continent"], $tileInfo2["xpos"], $tileInfo2["ypos"], 1, 1, array(0 => 0), array(0 => $new_userid), "Capital City");
                                // add capital
                                addImprovementInfo($getPage_connection3, $tileInfo2["continent"], $tileInfo2["xpos"], $tileInfo2["ypos"], 4, 1, array(0 => 0), array(0 => $new_userid), "First Farm");
                                // add farm
                                $capitalBuilt = true;
                            }
                            // if
                        }
                        // if
                    }
                    // if
                }
                // for
                addNationInfo($getPage_connection3, $new_userid, $new_name, $availableContinent, $new_formal, "", 12, 5000, 0, 3, 2500, 5, 0, 5, 0, array(0 => 0), array(0 => 0), array(0 => 5, 1 => 0, 2 => 0, 3 => 5, 4 => 2, 5 => 5, 6 => 0, 7 => 5), array(0 => 5, 1 => 5, 2 => 5, 3 => 5), 2000, 0);
                // go through y positions
                for ($y = 1; $y < 21; $y++) {
                    // go through x positions
                    for ($x = 1; $x < 21; $x++) {
                        $mapContentString = "";
                        $mapContentToken = 0;
                        for ($qw = 0; $qw < 5; $qw++) {
                            if ($qw == 0) {
                                $_SESSION["overlay"] = "terrain";
                            } else {
                                if ($qw == 1) {
                                    $_SESSION["overlay"] = "control";
                                } else {
                                    if ($qw == 2) {
                                        $_SESSION["overlay"] = "claims";
                                    } else {
                                        if ($qw == 3) {
                                            $_SESSION["overlay"] = "units";
                                        } else {
                                            if ($qw == 4) {
                                                $_SESSION["overlay"] = "nations";
                                            }
                                        }
                                    }
                                }
                            }
                            // else if
                            $mapContent_generated = array("", 0);
                            $mapContent_generated = generateMapTile($getPage_connection3, $availableContinent, $x, $y);
                            $mapContentString = $mapContent_generated[0];
                            $mapContentToken = $mapContent_generated[1];
                            $_SESSION["terrainMapContentsTokens"] = array(0);
                            $_SESSION["terrainMapContents"] = array(0);
                            $_SESSION["controlMapContentsTokens"] = array(0);
                            $_SESSION["controlMapContents"] = array(0);
                            $_SESSION["claimsMapContentsTokens"] = array(0);
                            $_SESSION["claimsMapContents"] = array(0);
                            $_SESSION["unitsMapContentsTokens"] = array(0);
                            $_SESSION["unitsMapContents"] = array(0);
                            $_SESSION["nationsMapContentsTokens"] = array(0);
                            $_SESSION["nationsMapContents"] = array(0);
                            if ($_SESSION["overlay"] == "terrain") {
                                $_SESSION["terrainMapContentsTokens"][$y][$x] = $mapContentToken;
                                $_SESSION["terrainMapContents"][$y][$x] = $mapContentString;
                            } else {
                                if ($_SESSION["overlay"] == "control") {
                                    $_SESSION["controlMapContentsTokens"][$y][$x] = $mapContentToken;
                                    $_SESSION["controlMapContents"][$y][$x] = $mapContentString;
                                } else {
                                    if ($_SESSION["overlay"] == "claims") {
                                        $_SESSION["claimsMapContentsTokens"][$y][$x] = $mapContentToken;
                                        $_SESSION["claimsMapContents"][$y][$x] = $mapContentString;
                                    } else {
                                        if ($_SESSION["overlay"] == "units") {
                                            $_SESSION["unitsMapContentsTokens"][$y][$x] = $mapContentToken;
                                            $_SESSION["unitsMapContents"][$y][$x] = $mapContentString;
                                        } else {
                                            if ($_SESSION["overlay"] == "nations") {
                                                $_SESSION["nationsMapContentsTokens"][$y][$x] = $mapContentToken;
                                                $_SESSION["nationsMapContents"][$y][$x] = $mapContentString;
                                            } else {
                                                $_SESSION["nationsMapContentsTokens"][$y][$x] = $mapContentToken;
                                                $_SESSION["nationsMapContents"][$y][$x] = $mapContentString;
                                            }
                                        }
                                    }
                                }
                            }
                            // else
                        }
                        // for
                    }
                    // for
                }
                // for
                addMapMemoryInfo($getPage_connection3, $new_userid, $_SESSION["terrainMapContents"], $_SESSION["controlMapContents"], $_SESSION["claimsMapContents"], $_SESSION["unitsMapContents"], $_SESSION["nationsMapContents"], $_SESSION["terrainMapContentsTokens"], $_SESSION["controlMapContentsTokens"], $_SESSION["claimsMapContentsTokens"], $_SESSION["unitsMapContentsTokens"], $_SESSION["nationsMapContentsTokens"]);
                //
                $_SESSION["success_message"] = "World has been reset successfully!";
            } else {
                $_SESSION["warning_message"] = "Cannot complete action: action is not valid.";
            }
            // else
        } else {
            $_SESSION["warning_message"] = "Cannot complete action: action is not valid.";
        }
        // else
    } else {
        $_SESSION["warning_message"] = "Cannot complete action: not valid admin.";
    }
    // else
}
示例#2
0
function securities_user_main()
{
    global $fromDate, $toDate, $tmpFromDate, $tmpToDate, $maxTradingDate, $urlParam;
    $data['from_date'] = $fromDate;
    $data['to_date'] = $toDate;
    $data['url_param'] = $urlParam;
    $seId = 1;
    //{ Xu ly khung info
    $data['se'] = 'hose';
    //{{Cau hinh rieng cho san HOSE
    if (!empty($_GET['seid']) && $_GET['seid'] == 2) {
        $data['se'] = 'hase';
        $seId = $_GET['seid'];
    }
    //}}
    //}
    $view = 0;
    if (!empty($_GET['view'])) {
        $view = $_GET['view'];
    }
    $data['view'] = $view;
    //Khac giao dich trai phieu
    //{ Xu ly khung du lieu
    $data['type'] = '.';
    $symbol = '';
    $validSymbol = false;
    if (!empty($_GET['symbol'])) {
        $symbol = $_GET['symbol'];
        if ($view != 3) {
            $data['type'] = '.filter.';
            $data['se'] = 'company';
        }
        $data['url_param'] .= '&symbol=' . $symbol;
        $db1 = _db('stockbiz');
        $db1->query('SELECT c.Symbol, c.CompanyName, i.Name AS IndustryName,Bourse, i.IndustryId
        FROM _prefix_companyinfo c, _prefix_industry i 
        WHERE i.IndustryId = c.IndustryID AND Symbol="' . $symbol . '"');
        if ($info = $db1->fetch()) {
            $data['info'] = $info;
            if ($info['Bourse'] == 'HOSE') {
                $seId = 1;
            } else {
                $seId = 2;
            }
            $validSymbol = true;
            $data['symbol'] = $symbol;
        }
    }
    $data['seid'] = $seId;
    if ($seId == 1) {
        require 'hose.php';
    } else {
        require 'hase.php';
    }
    switch ($view) {
        case 0:
            //Khong co loc
            if ($symbol == '') {
                if ($seId == 1) {
                    $data['hose_current_security'] = get_hcm_security($toDate);
                } else {
                    $data['hase_current_security'] = get_hn_security($toDate);
                }
                //Co loc
            } else {
                if ($validSymbol) {
                    $data['current_security'] = get_hcm_security_filter($symbol, $fromDate, $toDate, $seId);
                }
            }
            break;
        case 1:
            if ($seId == 1) {
                $data['put_through'] = get_hcm_putthrough($symbol, $fromDate, $toDate);
                $data['put_through_info'] = getPutExecInfo_sum($symbol, $fromDate, $toDate);
            } else {
                if ($symbol == '') {
                    $data['put_through'] = get_hn_putthrough($toDate, $data['put_through_qty'], $data['put_through_val']);
                }
            }
            break;
        case 2:
            $result_per_page = 20;
            $data['fi_sum'] = getForeignInvestment_sum($symbol, $fromDate, $toDate, $seId);
            $data['fi_top5bvol'] = getTopFI5BVol($fromDate, $toDate, $seId);
            $data['fi_top5bval'] = getTopFI5BVal($fromDate, $toDate, $seId);
            $data['fi_top5svol'] = getTopFI5SVol($fromDate, $toDate, $seId);
            $data['fi_top5sval'] = getTopFI5SVal($fromDate, $toDate, $seId);
            $data['fi'] = getForeignInvestment($symbol, $fromDate, $toDate, $seId);
            $paging = new Paging('p', $result_per_page, 0, _display_page());
            $paging->sCurrentPageClass = 'current';
            $paging->sPageNextClass = 'next';
            $paging->sPostfix = '#detail';
            $paging->nTotalRow = count($data['fi']);
            $data['fi_offset'] = $paging->getResultRowStart();
            $data['fi_total'] = $data['fi_offset'] + $result_per_page;
            $data['fi_paging'] = $paging;
            /*if ($seId == 1) $data[] = '';
              else $data[] = '';*/
            break;
        case 3:
            //Su dung ham trong hose
            if ($seId == 2) {
                require 'hose.php';
            }
            $data['bond'] = get_hcm_putthrough($symbol, $fromDate, $toDate, 1);
            $data['bond_info'] = getPutExecInfo_sum($symbol, $fromDate, $toDate, 1);
            $data['se'] = 'hose';
            return $data;
            break;
        case 4:
            break;
    }
    if ($symbol == '') {
        $data['maxtradingdate'] = $toDate;
        getMarketInfo($toDate, $seId, $data);
        $data['chart_startdate'] = date("Y-m-d", mktime(0, 0, 0, date("m", strtotime($toDate)) - 6, date("d", strtotime($toDate)), date("Y", strtotime($toDate))));
        $data['chart_today'] = $toDate;
    }
    return $data;
}
function showTradeInfo($getPage_connection2)
{
    $nationInfo = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
    $tradeInfo = getTradeInfo($getPage_connection2, $_SESSION["nation_id"]);
    $authorityReport = getAuthorityReport($nationInfo["authority"]);
    $economyReport = getEconomyReport($nationInfo["economy"]);
    echo "        <div class=\"spacing-from-menu well well-lg standard-text\">\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View and reply to pending trade agreements.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Pending Agreements        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapsePendingAgreements\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapsePendingAgreements\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    $agreementsExist = false;
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM agreements ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_agreements = $r_result;
            $agreementInfo1 = getAgreementInfo($getPage_connection2, $next_agreements);
            if (($agreementInfo1["toNation"] == $_SESSION["nation_id"] || $agreementInfo1["fromNation"] == $_SESSION["nation_id"]) && $agreementInfo1["status"] == 0) {
                $agreementsExist = true;
                $toNationInfo = getNationInfo($getPage_connection2, $agreementInfo1["toNation"]);
                $fromNationInfo = getNationInfo($getPage_connection2, $agreementInfo1["fromNation"]);
                echo "                To: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $toNationInfo["id"] . "\">" . $toNationInfo["name"] . "</a>, From: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $fromNationInfo["id"] . "\">" . $fromNationInfo["name"] . "</a>\n                <br />\n";
                echo "                Agreement Policy: " . $agreementInfo1["policy"] . "\n                <br />\n";
                echo "                " . $agreementInfo1["turns"] . " turns \n";
                echo "                <br />\n";
                echo "                <form action=\"index.php?page=trade#collapsePendingAgreements\" method=\"post\">\n";
                echo "                  <div class=\"form-group form-group-xs\">\n";
                echo "                    <input type=\"hidden\" name=\"page\" value=\"trade\" />\n";
                echo "                    <input type=\"hidden\" name=\"actionid\" value=\"" . $agreementInfo1["id"] . "\" />\n";
                echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Accept trade agreement proposal.\" name=\"action\" value=\"accept_agreement\" id=\"accept_agreement-" . $agreementInfo1["id"] . "\" type=\"submit\" class=\"btn btn-sm btn-success\">Accept</button>\n";
                echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Decline trade agreement proposal.\" name=\"action\" value=\"decline_agreement\" id=\"decline_agreement-" . $agreementInfo1["id"] . "\" type=\"submit\" class=\"btn btn-sm btn-danger\">Decline</button>\n";
                echo "                  </div>\n";
                echo "                </form\">\n";
                echo "                ----\n                <br />\n";
            }
            // if
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    if ($agreementsExist === false) {
        echo "                 No agreements established.\n";
    }
    // if
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View and reply to pending offers.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Pending Offers        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapsePendingOffers\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapsePendingOffers\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    $offersExist = false;
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM offers ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_offers = $r_result;
            $offerInfo1 = getOfferInfo($getPage_connection2, $next_offers);
            if ($offerInfo1["toNation"] == $_SESSION["nation_id"] && $offerInfo1["status"] == 0) {
                if ($offerInfo1["givingItems"][0] > 0 || $offerInfo1["receivingItems"][0] > 0) {
                    $offersExist = true;
                    $toNationInfo = getNationInfo($getPage_connection2, $offerInfo1["toNation"]);
                    $fromNationInfo = getNationInfo($getPage_connection2, $offerInfo1["fromNation"]);
                    echo "                To: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $toNationInfo["id"] . "\">" . $toNationInfo["name"] . "</a>, From: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $fromNationInfo["id"] . "\">" . $fromNationInfo["name"] . "</a>\n                <br />\n";
                    if ($offerInfo1["givingItems"][0] > 0) {
                        echo "                Giving:\n                <br />\n";
                        for ($z = 0; $z < count($offerInfo1["givingItems"]); $z++) {
                            if ($offerInfo1["givingQuantities"][$z] > 0) {
                                if ($offerInfo1["givingTypes"][$z] == "goods") {
                                    $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                    $name1 = $itemInfo1["name"];
                                } else {
                                    if ($offerInfo1["givingTypes"][$z] == "resources") {
                                        $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                        $name1 = $itemInfo1["name"];
                                    } else {
                                        $name1 = "money";
                                    }
                                }
                                // else
                                echo "                " . $offerInfo1["givingQuantities"][$z] . " " . $name1 . "\n                <br />\n";
                            }
                            // if
                        }
                        // for
                    } else {
                        echo "                Giving:\n                <br />\n                Nothing.\n";
                    }
                    // else
                    if ($offerInfo1["receivingItems"][0] > 0) {
                        echo "                Receiving:\n                <br />\n";
                        for ($z = 0; $z < count($offerInfo1["receivingItems"]); $z++) {
                            if ($offerInfo1["receivingQuantities"][$z] > 0) {
                                if ($offerInfo1["receivingTypes"][$z] == "goods") {
                                    $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                    $name1 = $itemInfo1["name"];
                                } else {
                                    if ($offerInfo1["receivingTypes"][$z] == "resources") {
                                        $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                        $name1 = $itemInfo1["name"];
                                    } else {
                                        $name1 = "money";
                                    }
                                }
                                // else
                                echo "                " . $offerInfo1["receivingQuantities"][$z] . " " . $name1 . "\n                <br />\n";
                            }
                            // if
                        }
                        // for
                    } else {
                        echo "                Receiving:\n                <br />\n                Nothing.\n                <br />\n";
                    }
                    // else
                    echo "                " . $offerInfo1["turns"] . " turns \n";
                    echo "                <br />\n";
                    echo "                <form action=\"index.php?page=trade#collapsePendingOffers\" method=\"post\">\n";
                    echo "                  <div class=\"form-group form-group-xs\">\n";
                    echo "                    <input type=\"hidden\" name=\"page\" value=\"trade\" />\n";
                    echo "                    <input type=\"hidden\" name=\"actionid\" value=\"" . $offerInfo1["id"] . "\" />\n";
                    echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Accept offer.\" name=\"action\" value=\"accept_offer\" id=\"accept_offer-" . $offerInfo1["id"] . "\" type=\"submit\" class=\"btn btn-sm btn-success\">Accept</button>\n";
                    echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Decline offer.\" name=\"action\" value=\"decline_offer\" id=\"decline_offer-" . $offerInfo1["id"] . "\" type=\"submit\" class=\"btn btn-sm btn-danger\">Decline</button>\n";
                    echo "                  </div>\n";
                    echo "                </form\">\n";
                    echo "                ----\n                <br />\n";
                }
                // if
            }
            // if
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    if ($offersExist === false) {
        echo "                No offers established.\n";
    }
    // if
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Create new trade agreement proposal.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Make Trade Agreement        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseMakeAgreement\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseMakeAgreement\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    if ($tradeInfo["limit"] > count($tradeInfo["routes"])) {
        echo "                <form action=\"index.php?page=trade#collapseMakeAgreement\" method=\"post\">\n";
        echo "                  <input type=\"hidden\" name=\"page\" value=\"trade\" />\n";
        echo "                  <div class=\"form-group form-group-sm\">\n";
        echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify target nation.\" name=\"send_nation\" type=\"text\" class=\"form-control input-md\" id=\"send_nation\" placeholder=\"Name of Target Nation\" />\n";
        echo "                    <br />\n";
        echo "                    <label class=\"control-label\" for=\"slider-agreement\">Trade Policy:</label>\n";
        echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify trade agreement free trade policy arrangement.  A lower number means less state intervention, and a higher number means more.\" name=\"agreement\" id=\"slider-agreement\" type=\"range\" min=\"1\" max=\"10\" step=\"1\" value=\"1\" />\n";
        echo "                    <br />\n";
        echo "                    <label class=\"control-label\" for=\"set_turns_agreement\">Turns:</label>\n";
        echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify the duration of the deal.\" type=\"text\" name=\"turns\" id=\"set_turns_agreement\" class=\"form-control input-sm\" value=\"1\" placeholder=\"e.g. 1\" />\n";
        echo "                    <br />\n";
        echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Send deal to nation for consideration.\" value=\"send_agreement\" name=\"action\" id=\"send_agreement\" type=\"submit\" class=\"btn btn-md btn-success info_button\">Send</button>\n";
        echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Reset deal's contents to none.\" value=\"reset_agreement\" name=\"action\" id=\"reset_agreement\" type=\"submit\" class=\"btn btn-md btn-danger info_button\">Reset</button>\n";
        echo "                  </div>\n";
        echo "                </form>\n";
    } else {
        echo "              You have no trade routes available.\n";
    }
    // else
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Create new offer.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Make Offer        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseMakeOffer\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseMakeOffer\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    echo "                <form action=\"index.php?page=trade#collapseMakeOffer\" method=\"post\">\n";
    echo "                  <input type=\"hidden\" name=\"page\" value=\"trade\" />\n";
    echo "                  <div class=\"form-group form-group-sm\">\n";
    echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify target nation.\" name=\"send_nation\" type=\"text\" class=\"form-control input-md\" id=\"send_nation\" placeholder=\"Name of Target Nation\" />\n";
    echo "                    <div class=\"col-md-6\">\n";
    echo "                      <label for=\"add_offer\">Add Offer</label>\n";
    echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Add another offer (something the player's nation contributes).\" value=\"add_offer\" name=\"action\" id=\"add_offer\" type=\"submit\" class=\"btn btn-md btn-success\">Add</button>\n";
    echo "                      <br />\n";
    echo "                      <div id=\"offers\">\n";
    for ($ff = 0; $ff <= count($_SESSION["offers"]); $ff++) {
        if ($ff < count($_SESSION["offers"])) {
            echo "                        <input type=\"hidden\" name=\"offers[" . $ff . "]\" value=\"1\" />\n";
            echo "                        Offer <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify quantity of item.\" type=\"text\" name=\"offersQuantities[" . $ff . "]\" class=\"form-control input-sm\" placeholder=\"Quantity\" value=\"" . $_SESSION["offersQuantities"][$ff] . "\" />\n";
            echo "                        <select data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify item.\" name=\"offersItems[" . $ff . "]\" class=\"form-control input-sm\">\n";
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM resources ORDER BY id ASC")) {
                $stmt->execute();
                $stmt->store_result();
                $stmt->bind_result($r_result);
                while ($stmt->fetch()) {
                    $next_resources = $r_result;
                    $resourceTypeInfo1 = getResourceTypeInfo($getPage_connection2, $next_resources);
                    if ($_SESSION["offersItems"][$ff] == $resourceTypeInfo1["id"] && $_SESSION["offersTypes"][$ff] == "resources") {
                        echo "                          <option selected value=\"resources." . strtolower($resourceTypeInfo1["name"]) . "\">" . $resourceTypeInfo1["name"] . "</option>\n";
                    } else {
                        echo "                          <option value=\"resources." . strtolower($resourceTypeInfo1["name"]) . "\">" . $resourceTypeInfo1["name"] . "</option>\n";
                    }
                    // else
                }
                // while
                $stmt->close();
            } else {
            }
            // else
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM goods ORDER BY id ASC")) {
                $stmt->execute();
                $stmt->store_result();
                $stmt->bind_result($r_result);
                while ($stmt->fetch()) {
                    $next_goods = $r_result;
                    $goodsInfo1 = getGoodsInfo($getPage_connection2, $next_goods);
                    if ($_SESSION["offersItems"][$ff] == $goodsInfo1["id"] && $_SESSION["offersTypes"][$ff] == "goods") {
                        echo "                          <option selected value=\"goods." . strtolower($goodsInfo1["name"]) . "\">" . $goodsInfo1["name"] . "</option>\n";
                    } else {
                        echo "                          <option value=\"goods." . strtolower($goodsInfo1["name"]) . "\">" . $goodsInfo1["name"] . "</option>\n";
                    }
                    // else
                }
                // while
                $stmt->close();
            } else {
            }
            // else
            if ($_SESSION["offersTypes"][$ff] == "money") {
                echo "                          <option selected value=\"money.money\">Money</option>\n";
            } else {
                echo "                          <option value=\"money.money\">Money</option>\n";
            }
            // else
            if ($_SESSION["offersTypes"][$ff] == "food") {
                echo "                          <option selected value=\"food.food\">Food</option>\n";
            } else {
                echo "                          <option value=\"food.food\">Food</option>\n";
            }
            // else
            echo "                        </select>\n";
            echo "                        <br />\n";
        } else {
            echo "                        <input type=\"hidden\" name=\"offers[" . $ff . "]\" value=\"1\" />\n";
            echo "                        Offer <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify quantity of item.\" type=\"text\" name=\"offersQuantities[" . $ff . "]\" class=\"form-control input-sm\" placeholder=\"Quantity\" value=\"0\" />\n";
            echo "                        <select data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify item.\" name=\"offersItems[" . $ff . "]\" class=\"form-control input-sm\">\n";
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM resources ORDER BY id ASC")) {
                $stmt->execute();
                $stmt->store_result();
                $stmt->bind_result($r_result);
                while ($stmt->fetch()) {
                    $next_resources = $r_result;
                    $resourceTypeInfo1 = getResourceTypeInfo($getPage_connection2, $next_resources);
                    echo "                          <option value=\"resources." . strtolower($resourceTypeInfo1["name"]) . "\">" . $resourceTypeInfo1["name"] . "</option>\n";
                }
                // while
                $stmt->close();
            } else {
            }
            // else
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM goods ORDER BY id ASC")) {
                $stmt->execute();
                $stmt->store_result();
                $stmt->bind_result($r_result);
                while ($stmt->fetch()) {
                    $next_goods = $r_result;
                    $goodsInfo1 = getGoodsInfo($getPage_connection2, $next_goods);
                    echo "                          <option value=\"goods." . strtolower($goodsInfo1["name"]) . "\">" . $goodsInfo1["name"] . "</option>\n";
                }
                // while
                $stmt->close();
            } else {
            }
            // else
            echo "                          <option value=\"money.money\">Money</option>\n";
            echo "                          <option value=\"food.food\">Food</option>\n";
            echo "                        </select>\n";
            echo "                        <br />\n";
        }
        // else
    }
    // for
    echo "                      </div>\n";
    echo "                    </div>\n";
    echo "                    <div class=\"col-md-6\">\n";
    echo "                      <label for=\"add_demand\">Add Demand</label>\n";
    echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Add another demand (something the target nation contributes).\" value=\"add_demand\" name=\"action\" id=\"add_demand\" type=\"submit\" class=\"btn btn-md btn-success\">Add</button>\n";
    echo "                      <br />\n";
    echo "                      <div id=\"demands\">\n";
    for ($ff = 0; $ff <= count($_SESSION["demands"]); $ff++) {
        if ($ff < count($_SESSION["demands"])) {
            echo "                        <input type=\"hidden\" name=\"demands[" . $ff . "]\" value=\"1\" />\n";
            echo "                        Demand <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify quantity of item.\" type=\"text\" name=\"demandsQuantities[" . $ff . "]\" class=\"form-control input-sm\" placeholder=\"Quantity\" value=\"" . $_SESSION["demandsQuantities"][$ff] . "\" />\n";
            echo "                        <select data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify item.\" name=\"demandsItems[" . $ff . "]\" class=\"form-control input-sm\">\n";
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM resources ORDER BY id ASC")) {
                $stmt->execute();
                $stmt->store_result();
                $stmt->bind_result($r_result);
                while ($stmt->fetch()) {
                    $next_resources = $r_result;
                    $resourceTypeInfo1 = getResourceTypeInfo($getPage_connection2, $next_resources);
                    if ($_SESSION["demandsItems"][$ff] == $resourceTypeInfo1["id"] && $_SESSION["demandsTypes"][$ff] == "resources") {
                        echo "                          <option selected value=\"resources." . strtolower($resourceTypeInfo1["name"]) . "\">" . $resourceTypeInfo1["name"] . "</option>\n";
                    } else {
                        echo "                          <option value=\"resources." . strtolower($resourceTypeInfo1["name"]) . "\">" . $resourceTypeInfo1["name"] . "</option>\n";
                    }
                    // else
                }
                // while
                $stmt->close();
            } else {
            }
            // else
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM goods ORDER BY id ASC")) {
                $stmt->execute();
                $stmt->store_result();
                $stmt->bind_result($r_result);
                while ($stmt->fetch()) {
                    $next_goods = $r_result;
                    $goodsInfo1 = getGoodsInfo($getPage_connection2, $next_goods);
                    if ($_SESSION["demandsItems"][$ff] == $goodsInfo1["id"] && $_SESSION["demandsTypes"][$ff] == "goods") {
                        echo "                          <option selected value=\"goods." . strtolower($goodsInfo1["name"]) . "\">" . $goodsInfo1["name"] . "</option>\n";
                    } else {
                        echo "                          <option value=\"goods." . strtolower($goodsInfo1["name"]) . "\">" . $goodsInfo1["name"] . "</option>\n";
                    }
                    // else
                }
                // while
                $stmt->close();
            } else {
            }
            // else
            if ($_SESSION["demandsTypes"][$ff] == "money") {
                echo "                          <option selected value=\"money.money\">Money</option>\n";
            } else {
                echo "                          <option value=\"money.money\">Money</option>\n";
            }
            // else
            if ($_SESSION["demandsTypes"][$ff] == "food") {
                echo "                          <option selected value=\"food.food\">Food</option>\n";
            } else {
                echo "                          <option value=\"food.food\">Food</option>\n";
            }
            // else
            echo "                        </select>\n";
            echo "                        <br />\n";
        } else {
            echo "                        <input type=\"hidden\" name=\"demands[" . $ff . "]\" value=\"1\" />\n";
            echo "                        Demand <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify quantity of item.\" type=\"text\" name=\"demandsQuantities[" . $ff . "]\" class=\"form-control input-sm\" placeholder=\"Quantity\" value=\"0\" />\n";
            echo "                        <select data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify item.\" name=\"demandsItems[" . $ff . "]\" class=\"form-control input-sm\">\n";
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM resources ORDER BY id ASC")) {
                $stmt->execute();
                $stmt->store_result();
                $stmt->bind_result($r_result);
                while ($stmt->fetch()) {
                    $next_resources = $r_result;
                    $resourceTypeInfo1 = getResourceTypeInfo($getPage_connection2, $next_resources);
                    echo "                          <option value=\"resources." . strtolower($resourceTypeInfo1["name"]) . "\">" . $resourceTypeInfo1["name"] . "</option>\n";
                }
                // while
                $stmt->close();
            } else {
            }
            // else
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM goods ORDER BY id ASC")) {
                $stmt->execute();
                $stmt->store_result();
                $stmt->bind_result($r_result);
                while ($stmt->fetch()) {
                    $next_goods = $r_result;
                    $goodsInfo1 = getGoodsInfo($getPage_connection2, $next_goods);
                    echo "                          <option value=\"goods." . strtolower($goodsInfo1["name"]) . "\">" . $goodsInfo1["name"] . "</option>\n";
                }
                // while
                $stmt->close();
            } else {
            }
            // else
            echo "                          <option value=\"money.money\">Money</option>\n";
            echo "                          <option value=\"food.food\">Food</option>\n";
            echo "                        </select>\n";
            echo "                        <br />\n";
        }
        // else
    }
    // for
    echo "                      </div>\n";
    echo "                    </div>\n";
    echo "                    <br />\n";
    echo "                    <div class=\"col-md-12\">\n";
    echo "                      <label class=\"control-label\" for=\"set_turns\">Turns:</label>\n";
    echo "                      <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Specify the duration of the deal.\" type=\"text\" name=\"turns\" id=\"set_turns\" class=\"form-control input-sm\" value=\"1\" placeholder=\"e.g. 1\" />\n";
    echo "                    </div>\n";
    echo "                    <br />\n";
    echo "                    <div class=\"col-md-12\">\n";
    echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Send deal to nation for consideration.\" value=\"send_offer\" name=\"action\" id=\"send_offer\" type=\"submit\" class=\"btn btn-md btn-success info_button\">Send</button>\n";
    echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Reset deal's contents to none.\" value=\"reset_offer\" name=\"action\" id=\"reset_offer\" type=\"submit\" class=\"btn btn-md btn-danger info_button\">Reset</button>\n";
    echo "                    </div>\n";
    echo "                  </div>\n";
    echo "                </form>\n";
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View current market rates.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Current Market        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseMarket\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseMarket\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM market ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_market = $r_result;
            $marketInfo1 = getMarketInfo($getPage_connection2, $next_market);
            echo "                " . $marketInfo1["name"] . ": " . $marketInfo1["rate"] . "% value\n                <br />\n";
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View previously accepted trade agreements.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Accepted Agreements        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseAcceptedAgreements\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseAcceptedAgreements\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    $agreementsExist = false;
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM agreements ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_agreements = $r_result;
            $agreementInfo1 = getAgreementInfo($getPage_connection2, $next_agreements);
            if (($agreementInfo1["toNation"] == $_SESSION["nation_id"] || $agreementInfo1["fromNation"] == $_SESSION["nation_id"]) && $agreementInfo1["status"] == 1) {
                $agreementsExist = true;
                $toNationInfo = getNationInfo($getPage_connection2, $agreementInfo1["toNation"]);
                $fromNationInfo = getNationInfo($getPage_connection2, $agreementInfo1["fromNation"]);
                echo "                To: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $toNationInfo["id"] . "\">" . $toNationInfo["name"] . "</a>, From: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $fromNationInfo["id"] . "\">" . $fromNationInfo["name"] . "</a>\n                <br />\n";
                echo "                Agreement Policy: " . $agreementInfo1["policy"] . "\n                <br />\n";
                echo "                " . $agreementInfo1["counter"] . " / " . $agreementInfo1["turns"] . " turns \n";
                echo "                <br />\n";
                echo "                ----\n                <br />\n";
            }
            // if
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    if ($agreementsExist === false) {
        echo "                No agreements established.\n";
    }
    // if
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View previously accepted offers.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Accepted Offers        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseAcceptedOffers\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseAcceptedOffers\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    $offersExist = false;
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM offers ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_offers = $r_result;
            $offerInfo1 = getOfferInfo($getPage_connection2, $next_offers);
            if (($offerInfo1["toNation"] == $_SESSION["nation_id"] || $offerInfo1["fromNation"] == $_SESSION["nation_id"]) && $offerInfo1["status"] == 1) {
                if ($offerInfo1["givingItems"][0] > 0 || $offerInfo1["receivingItems"][0] > 0) {
                    $offersExist = true;
                    $toNationInfo = getNationInfo($getPage_connection2, $offerInfo1["toNation"]);
                    $fromNationInfo = getNationInfo($getPage_connection2, $offerInfo1["fromNation"]);
                    echo "                To: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $toNationInfo["id"] . "\">" . $toNationInfo["name"] . "</a>, From: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $fromNationInfo["id"] . "\">" . $fromNationInfo["name"] . "</a>\n                <br />\n";
                    if ($offerInfo1["givingItems"][0] > 0) {
                        echo "                Giving:\n                <br />\n";
                        for ($z = 0; $z < count($offerInfo1["givingItems"]); $z++) {
                            if ($offerInfo1["givingQuantities"][$z] > 0) {
                                if ($offerInfo1["givingTypes"][$z] == "goods") {
                                    $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                    $name1 = $itemInfo1["name"];
                                } else {
                                    if ($offerInfo1["givingTypes"][$z] == "resources") {
                                        $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                        $name1 = $itemInfo1["name"];
                                    } else {
                                        $name1 = "money";
                                    }
                                }
                                // else
                                echo "                " . $offerInfo1["givingQuantities"][$z] . " " . $name1 . "\n                <br />\n";
                            }
                            // if
                        }
                        // for
                    } else {
                        echo "                Giving:\n                <br />\n                Nothing.\n";
                    }
                    // else
                    if ($offerInfo1["receivingItems"][0] > 0) {
                        echo "                Receiving:\n                <br />\n";
                        for ($z = 0; $z < count($offerInfo1["receivingItems"]); $z++) {
                            if ($offerInfo1["receivingQuantities"][$z] > 0) {
                                if ($offerInfo1["receivingTypes"][$z] == "goods") {
                                    $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                    $name1 = $itemInfo1["name"];
                                } else {
                                    if ($offerInfo1["receivingTypes"][$z] == "resources") {
                                        $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                        $name1 = $itemInfo1["name"];
                                    } else {
                                        $name1 = "money";
                                    }
                                }
                                // else
                                echo "                " . $offerInfo1["receivingQuantities"][$z] . " " . $name1 . "\n                <br />\n";
                            }
                            // if
                        }
                        // for
                    } else {
                        echo "                Receiving:\n                <br />\n                Nothing.\n";
                    }
                    // else
                    echo "                <br />\n";
                    echo "                " . $offerInfo1["counter"] . " / " . $offerInfo1["turns"] . " turns \n";
                    echo "                <br />\n";
                    echo "                ----\n                <br />\n";
                }
                // if
            }
            // if
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    if ($offersExist === false) {
        echo "                No offers established.\n";
    }
    // if
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View previously declined trade agreements.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Declined Agreements        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseDeclinedAgreements\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseDeclinedAgreements\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    $agreementsExist = false;
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM agreements ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_agreements = $r_result;
            $agreementInfo1 = getAgreementInfo($getPage_connection2, $next_agreements);
            if (($agreementInfo1["toNation"] == $_SESSION["nation_id"] || $agreementInfo1["fromNation"] == $_SESSION["nation_id"]) && $agreementInfo1["status"] == 2) {
                $agreementsExist = true;
                $toNationInfo = getNationInfo($getPage_connection2, $agreementInfo1["toNation"]);
                $fromNationInfo = getNationInfo($getPage_connection2, $agreementInfo1["fromNation"]);
                echo "                To: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $toNationInfo["id"] . "\">" . $toNationInfo["name"] . "</a>, From: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $fromNationInfo["id"] . "\">" . $fromNationInfo["name"] . "</a>\n                <br />\n";
                echo "                Agreement Policy: " . $agreementInfo1["policy"] . "\n                <br />\n";
                echo "                <br />\n";
                echo "                " . $agreementInfo1["counter"] . " / " . $agreementInfo1["turns"] . " turns \n";
                echo "                <br />\n";
                echo "                ----\n                <br />\n";
            }
            // if
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    if ($agreementsExist === false) {
        echo "                 No declined agreements exist so far.\n";
    }
    // if
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View previously declined offers.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Declined Offers        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseDeclinedOffers\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseDeclinedOffers\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    $offersExist = false;
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM offers ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_offers = $r_result;
            $offerInfo1 = getOfferInfo($getPage_connection2, $next_offers);
            if (($offerInfo1["toNation"] == $_SESSION["nation_id"] || $offerInfo1["fromNation"] == $_SESSION["nation_id"]) && $offerInfo1["status"] == 2) {
                if ($offerInfo1["givingItems"][0] > 0 || $offerInfo1["receivingItems"][0] > 0) {
                    $offersExist = true;
                    $toNationInfo = getNationInfo($getPage_connection2, $offerInfo1["toNation"]);
                    $fromNationInfo = getNationInfo($getPage_connection2, $offerInfo1["fromNation"]);
                    echo "                To: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $toNationInfo["id"] . "\">" . $toNationInfo["name"] . "</a>, From: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $fromNationInfo["id"] . "\">" . $fromNationInfo["name"] . "</a>\n                <br />\n";
                    if ($offerInfo1["givingItems"][0] > 0) {
                        echo "                Giving:\n                <br />\n";
                        for ($z = 0; $z < count($offerInfo1["givingItems"]); $z++) {
                            if ($offerInfo1["givingQuantities"][$z] > 0) {
                                if ($offerInfo1["givingTypes"][$z] == "goods") {
                                    $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                    $name1 = $itemInfo1["name"];
                                } else {
                                    if ($offerInfo1["givingTypes"][$z] == "resources") {
                                        $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                        $name1 = $itemInfo1["name"];
                                    } else {
                                        $name1 = "money";
                                    }
                                }
                                // else
                                echo "                " . $offerInfo1["givingQuantities"][$z] . " " . $name1 . "\n                <br />\n";
                            }
                            // if
                        }
                        // for
                    } else {
                        echo "                Giving:\n                <br />\n                Nothing.\n";
                    }
                    // else
                    if ($offerInfo1["receivingItems"][0] > 0) {
                        echo "                Receiving:\n                <br />\n";
                        for ($z = 0; $z < count($offerInfo1["receivingItems"]); $z++) {
                            if ($offerInfo1["receivingQuantities"][$z] > 0) {
                                if ($offerInfo1["receivingTypes"][$z] == "goods") {
                                    $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                    $name1 = $itemInfo1["name"];
                                } else {
                                    if ($offerInfo1["receivingTypes"][$z] == "resources") {
                                        $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                        $name1 = $itemInfo1["name"];
                                    } else {
                                        $name1 = "money";
                                    }
                                }
                                // else
                                echo "                " . $offerInfo1["receivingQuantities"][$z] . " " . $name1 . "\n                <br />\n";
                            }
                            // if
                        }
                        // for
                    } else {
                        echo "                Receiving:\n                <br />\n                Nothing.\n";
                    }
                    // else
                    echo "                <br />\n";
                    echo "                " . $offerInfo1["counter"] . " / " . $offerInfo1["turns"] . " turns \n";
                    echo "                <br />\n";
                    echo "                ----\n                <br />\n";
                }
                // if
            }
            // if
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    if ($offersExist === false) {
        echo "                No declined offers exist so far.\n";
    }
    // if
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "        </div>\n";
}
示例#4
0
function updateGlobe($getPage_connection2)
{
    // change requirements of luxury and basic goods
    // set luxurygoods
    $goodsInfoW = getGoodsInfo($getPage_connection2, 5);
    if ($goodsInfoW["productionRequired"] - 2 > 1) {
        $new_productionRequired = mt_rand($goodsInfoW["productionRequired"] - 2, $goodsInfoW["productionRequired"] + 2);
    } else {
        $new_productionRequired = mt_rand(1, $goodsInfoW["productionRequired"] + 2);
    }
    // else
    if ($new_productionRequired < 1) {
        $new_productionRequired = 1;
    }
    // if
    $rand_metals = 2;
    $rand_wood = 1;
    $rand_metals = mt_rand(2, 10);
    $rand_wood = mt_rand(2, 10);
    $new_resourceTypesRequired = array(0 => 0);
    $new_resourceQuantitiesRequired = array(0 => 0);
    if ($rand_wood > 0) {
        $new_resourceTypesRequired[0] = 1;
        $new_resourceQuantitiesRequired[0] = $rand_wood;
    }
    // if
    if ($rand_metals > 0) {
        $new_resourceTypesRequired[1] = 2;
        $new_resourceQuantitiesRequired[1] = $rand_metals;
    }
    // if
    setGoodsInfo($getPage_connection2, $goodsInfoW["id"], $goodsInfoW["name"], $new_productionRequired, $goodsInfoW["foodRequired"], $new_resourceTypesRequired, $new_resourceQuantitiesRequired, $goodsInfoW["improvementTypesRequired"], $goodsInfoW["improvementQuantitiesRequired"], $goodsInfoW["improvementLevelRequired"], $goodsInfoW["buyStrength"], $goodsInfoW["sellStrength"]);
    // set basicgoods
    $goodsInfoW = getGoodsInfo($getPage_connection2, 6);
    if ($goodsInfoW["productionRequired"] - 2 > 1) {
        $new_productionRequired = mt_rand($goodsInfoW["productionRequired"] - 2, $goodsInfoW["productionRequired"] + 2);
    } else {
        $new_productionRequired = mt_rand(0, $goodsInfoW["productionRequired"] + 2);
    }
    // else
    if ($new_productionRequired < 1) {
        $new_productionRequired = 1;
    }
    // if
    $rand_metals = 1;
    $rand_wood = 1;
    $rand_metals = mt_rand(1, 8);
    $rand_wood = mt_rand(1, 8);
    $new_resourceTypesRequired = array(0 => 0);
    $new_resourceQuantitiesRequired = array(0 => 0);
    if ($rand_wood > 0) {
        $new_resourceTypesRequired[0] = 1;
        $new_resourceQuantitiesRequired[0] = $rand_wood;
    }
    // if
    if ($rand_metals > 0) {
        $new_resourceTypesRequired[1] = 2;
        $new_resourceQuantitiesRequired[1] = $rand_metals;
    }
    // if
    setGoodsInfo($getPage_connection2, $goodsInfoW["id"], $goodsInfoW["name"], $new_productionRequired, $goodsInfoW["foodRequired"], $new_resourceTypesRequired, $new_resourceQuantitiesRequired, $goodsInfoW["improvementTypesRequired"], $goodsInfoW["improvementQuantitiesRequired"], $goodsInfoW["improvementLevelRequired"], $goodsInfoW["buyStrength"], $goodsInfoW["sellStrength"]);
    // set new market rates
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM goods ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_goods = $r_result;
            $goodsInfoW = getGoodsInfo($getPage_connection2, $next_goods);
            $marketInfoW = getMarketInfo($getPage_connection2, $next_goods);
            $rate = 0;
            // if buy strength is more, increase rate, otherwise decrease or remain constant
            if ($goodsInfoW["buyStrength"] > $goodsInfoW["sellStrength"]) {
                $randRateBonus = mt_rand(1, 4);
                $rate = $marketInfoW["rate"] + $randRateBonus;
            } else {
                if ($goodsInfoW["buyStrength"] < $goodsInfoW["sellStrength"]) {
                    $randFlux = mt_rand(1, 4);
                    // random drop or rise (75% more likely drop)
                    if ($randFlux == 1) {
                        $randRateBonus = mt_rand(1, 2);
                        $rate = $marketInfoW["rate"] + $randRateBonus;
                    } else {
                        $randRateBonus = mt_rand(1, 4);
                        $rate = $marketInfoW["rate"] - $randRateBonus;
                    }
                    // else
                } else {
                    $randFlux = mt_rand(1, 2);
                    // random drop or rise (50/50)
                    if ($randFlux == 1) {
                        $randRateBonus = mt_rand(1, 2);
                        $rate = $marketInfoW["rate"] + $randRateBonus;
                    } else {
                        $randRateBonus = mt_rand(1, 2);
                        $rate = $marketInfoW["rate"] - $randRateBonus;
                    }
                    // else
                }
            }
            // else
            if ($rate >= 1) {
                setMarketInfo($getPage_connection2, $next_goods, $marketInfoW["name"], $rate);
            } else {
                setMarketInfo($getPage_connection2, $next_goods, $marketInfoW["name"], 0);
            }
            // else
            // reset strength of good for next turn (no reset for now)
            //setGoodsInfo($getPage_connection2,$goodsInfoW["id"],$goodsInfoW["name"],$goodsInfoW["productionRequired"],$goodsInfoW["foodRequired"],$goodsInfoW["resourceTypesRequired"],$goodsInfoW["resourceQuantitiesRequired"],$goodsInfoW["improvementTypesRequired"],$goodsInfoW["improvementQuantitiesRequired"],$goodsInfoW["improvementLevelRequired"],100,100);
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    // add to turn counter for trade offers
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM offers ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_offers = $r_result;
            $offerInfo1 = getOfferInfo($getPage_connection2, $next_offers);
            $new_counter = $offerInfo1["counter"] + 1;
            setOfferInfo($getPage_connection2, $offerInfo1["id"], $offerInfo1["fromNation"], $offerInfo1["toNation"], $offerInfo1["givingItems"], $offerInfo1["receivingItems"], $offerInfo1["givingQuantities"], $offerInfo1["receivingQuantities"], $offerInfo1["givingTypes"], $offerInfo1["receivingTypes"], $offerInfo1["turns"], $new_counter, $offerInfo1["status"]);
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    // remove empty organizations, automatically appoint new manager if there is no manager (new manager is the oldest joined member)
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM organizations ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_organizations = $r_result;
            $organizationInfo1 = getOrganizationInfo($getPage_connection2, $next_organizations);
            $new_managers = array(0 => 0);
            if (count($organizationInfo1["members"]) == 1) {
                if ($organizationInfo1["members"][0] == 0) {
                    deleteOrganizationInfo($getPage_connection2, $next_organizations);
                }
                // if
            } else {
                if (count($organizationInfo1["members"]) > 1) {
                    if (count($organizationInfo1["managers"]) == 1) {
                        if ($organizationInfo1["managers"][0] == 0) {
                            $new_managers[0] = $organizationInfo1["members"][0];
                            setOrganizationInfo($getPage_connection2, $next_organizations, $organizationInfo1["name"], $organizationInfo1["members"], $new_managers, $organizationInfo1["pending"], $organizationInfo1["ranking"]);
                        }
                        // if
                    } else {
                    }
                    // else
                } else {
                    deleteOrganizationInfo($getPage_connection2, $next_organizations);
                }
            }
            // else
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    // set rankings
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        $offset = 0;
        while ($stmt->fetch()) {
            $next_nations = $r_result;
            $rank = $offset + 1;
            // production
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY production DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_production_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET production=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_production_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            // money
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY money DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_money_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET money=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_money_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            // happiness
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY happiness DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_happiness_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET happiness=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_happiness_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            // food
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY food DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_food_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET food=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_food_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            // population
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY population DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_population_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET population=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_population_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            $offset++;
        }
        // while
        $stmt->close();
    } else {
        $next_offers = 0;
    }
    // else
}