function Buildings()
 {
     data::initialize();
     $this->planet_id = current_planet();
     $this->building_id = isset($_REQUEST['building_id']) ? (int) $_REQUEST['building_id'] : NULL;
     permissions_check(PERMISSION_PLANET, $this->planet_id, array('build', 'commission'));
     $this->data->updater->update(0, $this->planet_id);
     $this->quiet = false;
 }
 function Research_Interface(&$data, &$smarty)
 {
     $this->data =& $data;
     $this->smarty =& $smarty;
     $this->sql = new SQL_Generator();
     $this->planet_id = current_planet();
     $this->concept_id = (int) request_variable('concept_id');
     permissions_check(PERMISSION_PLANET, $this->planet_id, array('build', 'commission'));
     $this->data->updater->update($_SESSION['kingdom_id']);
 }
 function Units(&$data, &$smarty)
 {
     $this->data =& $data;
     $this->smarty =& $smarty;
     $this->sql = new SQL_Generator();
     $this->planet_id = current_planet();
     $this->unit_type = request_variable('unit_type', NULL, 'army');
     $this->unit_id = request_variable('unit_id');
     if (!in_array($this->unit_type, array('army', 'navy'))) {
         error(__FILE__, __LINE__, 'DATA', 'Invalid unit type.');
     }
     if (!empty($this->unit_id)) {
         permissions_check(PERMISSION_PLANET, $this->planet_id, 'commission');
     }
     $this->smarty->assign('unit_type', $this->unit_type);
     $this->smarty->assign('unit_id', $this->unit_id);
     $this->data->updater->update(0, $this->planet_id);
 }
<?php

define('IK_AUTHORIZED', true);
require_once dirname(__FILE__) . '/includes/init.php';
// ###############################################
// Prisoner filter
prisoner_filter($_SESSION['player_id']);
// ###############################################
// Validate Function
$valid_functions = array('default' => 'planet_extraction', 'planet_extraction_set', 'planet_permissions', 'planet_permissions_set', 'planet_settings', 'planet_settings_set', 'planet_massmanage', 'planet_massmanage_set');
$fn = validate_fn($valid_functions, __FILE__, __LINE__);
if (!in_array($fn, array('planet_massmanage', 'planet_massmanage_set'))) {
    $planet_id = current_planet();
    permissions_check(PERMISSION_PLANET, $planet_id, 'owner');
}
$updater->update(0, 0, $_SESSION['player_id']);
$fn();
function planet_massmanage()
{
    global $smarty, $sql, $data;
    // get all planets owned by this player
    // picture, name, food storage & rate, worker storage & rate, energy storage & rate, mineral storage & rate,
    // [ ] The Past	  1.2K  +8   1.1K  +40   872  +48   0  0   Derrick   1h, 38m
    $available_planning = $available_cranes = 0;
    // Retrieve all of the player's planets
    $player = $data->player($_SESSION['player_id']);
    $planet_ids = $player['planets'];
    $planet_ids = array_keys($planet_ids);
    $planets = $data->planet($planet_ids);
    if (!empty($planets)) {
        $db_query = "\n\t\t\t\tSELECT \n\t\t\t\t\tt.`planet_id`, \n\t\t\t\t\tb.`name`, \n\t\t\t\t\tMIN(t.`completion`) as 'completion' \n\t\t\t\tFROM \n\t\t\t\t\t`tasks` t, \n\t\t\t\t\t`buildings` b \n\t\t\t\tWHERE \n\t\t\t\t\tt.`planet_id` IN ('" . implode("', '", array_keys($planets)) . "') AND \n\t\t\t\t\tb.`building_id` = t.`building_id` \n\t\t\t\tGROUP BY t.`planet_id` \n\t\t\t\tLIMIT " . count($planets);
function starsystem()
{
    global $smarty;
    // $starsystem[x][y]['exists']
    // $starsystem[x][y]['kingdom']
    // $starsystem[x][y]['target']
    if (isset($_REQUEST['starsystem_id'])) {
        $starsystem_id = (int) $_REQUEST['starsystem_id'];
        $db_query = "SELECT `starsystem_id` FROM `starsystems` WHERE `round_id` = '" . $_SESSION['round_id'] . "' AND `starsystem_id` = '" . $starsystem_id . "'";
        $db_result = mysql_query($db_query);
        if (mysql_num_rows($db_result) == 0) {
            unset($starsystem_id);
        }
    }
    if (!isset($starsystem_id)) {
        $planet_id = current_planet();
        $db_query = "SELECT `starsystem_id` FROM `planets` WHERE `planet_id` = '" . $planet_id . "'";
        $db_result = mysql_query($db_query);
        $db_row = mysql_fetch_array($db_result, MYSQL_ASSOC);
        $starsystem_id = $db_row['starsystem_id'];
    }
    if (!empty($_REQUEST['target_id'])) {
        $target_id = abs((int) $_REQUEST['target_id']);
    }
    $db_query = "SELECT `planet_id`, `kingdom_id`, `type`, `x`, `y`, `name` FROM `planets` WHERE `round_id` = '" . $_SESSION['round_id'] . "' AND `starsystem_id` = '" . $starsystem_id . "' AND `status` = '" . PLANETSTATUS_OCCUPIED . "'";
    $db_result = mysql_query($db_query);
    $starsystem = array();
    while ($db_row = mysql_fetch_array($db_result, MYSQL_ASSOC)) {
        if (empty($db_row['type'])) {
            $db_row['type'] = '';
        }
        $starsystem[$db_row['x']][$db_row['y']]['type'] = $db_row['type'];
        $starsystem[$db_row['x']][$db_row['y']]['planet_id'] = $db_row['planet_id'];
        $starsystem[$db_row['x']][$db_row['y']]['planet_name'] = $db_row['name'];
        $starsystem[$db_row['x']][$db_row['y']]['exists'] = true;
        if ($db_row['kingdom_id'] == $_SESSION['kingdom_id']) {
            $starsystem[$db_row['x']][$db_row['y']]['kingdom'] = true;
        } elseif (isset($target_id) && $db_row['kingdom_id'] == $target_id) {
            $starsystem[$db_row['x']][$db_row['y']]['target'] = true;
        }
    }
    $smarty->assign('starsystem', $starsystem);
    $smarty->display('map_starsystem.tpl');
}
function current_planet()
{
    global $data, $smarty, $sql;
    if (!empty($_REQUEST['planet_id'])) {
        $planet_id = abs((int) $_REQUEST['planet_id']);
    } elseif (!empty($_SESSION['planet_id'])) {
        $planet_id = $_SESSION['planet_id'];
    } else {
        $player = $data->player($_SESSION['player_id']);
        if (empty($player['planet_current'])) {
            $player =& $data->player($_SESSION['player_id']);
            $player['planet_current'] = array_rand($player['planets']);
            $data->save();
        }
        $_SESSION['planet_id'] = $planet_id = $player['planet_current'];
    }
    $planet = $data->planet($planet_id);
    if (empty($planet) || $planet['kingdom_id'] != $_SESSION['kingdom_id']) {
        if (!empty($_REQUEST['planet_id'])) {
            unset($_REQUEST['planet_id']);
        } elseif (!empty($_SESSION['planet_id'])) {
            unset($_SESSION['planet_id']);
        } else {
            error(__FILE__, __LINE__, 'INVALID_PLANET_ID', 'Invalid planet id specified or returned');
        }
        $planet_id = current_planet();
    }
    $smarty->assign('planet_id', $planet['planet_id']);
    $smarty->assign('planet_name', htmlentities($planet['name']));
    return $planet_id;
}