* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing XNova.
*
*/
define('INSTALL' , false);
require_once dirname(__FILE__) .'/common.php';
$user = Legacies_Empire_Model_User::getSingleton();
$planet = $user->getCurrentPlanet();
$moon = $planet->getMoon();
$action = isset($_GET['action']) ? $_GET['action'] : null;
if (isset($_POST) && !empty($_POST)) {
$action = isset($_POST['action']) && !empty($_POST['action']) ? $_POST['action'] : $action;
$formKey = isset($_POST['form_key']) && !empty($_POST['form_key']) ? $_POST['form_key'] : null;
if ($formKey == Legacies::getSession('security')->getData('form_key')) {
if ($action == 'rename' && isset($_POST['name']) && !empty($_POST['name'])) {
$planet->setData('name', $_POST['name'])->save();
header('302 Found');
header('Location: ' . basename(__FILE__));
exit(0);
} else if ($action == 'destroy' && isset($_POST['password']) && !empty($_POST['password']) && isset($_POST['confirm'])) {
if (!$user->checkPassword($_POST['password'])) {
Legacies::getSession('user')
->addError(Legacies::__('Password was not correct.'));
header('302 Found');
header('Location: ' . basename(__FILE__));
exit(0);
}
try {
$user->getCurrentPlanet()->destroy();
Legacies::getSession('user')
->addSucces(Legacies::__('Planet has been successfully destroyed.'));
} catch (Legacies_Empire_Model_Planet_Exception $e) {
Legacies::getSession('user')
->addError($e->getMessage());
}
header('302 Found');
header('Location: ' . basename(__FILE__));
exit(0);
}
} else {
Legacies::getSession('user')
->addError(Legacies::__('Invalid security key.'));
}
} else if ($action == 'rename') {
$layout = new Legacies_Core_Layout();
$layout->load('overview.rename-planet');
echo $layout->render();
exit(0);
} else if ($action == 'destroy') {
$layout = new Legacies_Core_Layout();
$layout->load('overview.destroy-planet');
echo $layout->render();
exit(0);
} else {
includeLang('resources');
includeLang('overview');
if ($user->getId()) {
$planetCollection = $user->getPlanetCollection();
$planetBlock = new Legacies_Core_Block_Template();
$planetBlock->setTemplate('empire/overview/planet/view.phtml');
$planetList = new Legacies_Core_Block_Concat();
$planetBlock->planetList = $planetList;
foreach ($planetCollection as $userPlanet) {
if ($userPlanet->getId() == $planet->getId()) {
continue;
}
/*
* Update planet resources and constructions
*/
Legacies::dispatchEvent('planet.update', array(
'planet' => $userPlanet
));
$userPlanet->save();
if ($userPlanet->getId() != $user->getCurrentPlanet()->getId() && $userPlanet->isPlanet()) {
$block = new Legacies_Core_Block_Template();
$block->setTemplate('empire/overview/planet/list/item.phtml');
$block['planet'] = $userPlanet;
$buildingQueue = $userPlanet->getBuildingQueue();
$buildingQueue->rewind();
$currentItem = $buildingQueue->current();
$block['queue_item'] = $currentItem;
}
}
/**
* Missile attack management
* Refactoring needed
* {{{
*/
$iraks_query = doquery("SELECT * FROM {{table}} WHERE owner = '" . $user['id'] . "'", 'iraks');
$Record = 4000;
while ($irak = $iraks_query->fetch(PDO::FETCH_ASSOC)) {
$Record++;
$fpage[$irak['zeit']] = '';
if ($irak['zeit'] > time()) {
$time = $irak['zeit'] - time();
$fpage[$irak['zeit']] .= InsertJavaScriptChronoApplet ("fm", $Record, $time, true);
$planet_start = doquery("SELECT * FROM {{table}} WHERE
galaxy = '" . $irak['galaxy'] . "' AND
system = '" . $irak['system'] . "' AND
planet = '" . $irak['planet'] . "' AND
planet_type = '1'", 'planets');
$user_planet = doquery("SELECT * FROM {{table}} WHERE
galaxy = '" . $irak['galaxy_angreifer'] . "' AND
system = '" . $irak['system_angreifer'] . "' AND
planet = '" . $irak['planet_angreifer'] . "' AND
planet_type = '1'", 'planets', true);
if (mysql_num_rows($planet_start) == 1) {
$planet = mysql_fetch_array($planet_start);
}
$fpage[$irak['zeit']] .= "