Esempio n. 1
0
function ShowAccountEditorPage()
{
    global $LNG, $reslist, $resource;
    $template = new template();
    switch ($_GET['edit']) {
        case 'resources':
            $id = HTTP::_GP('id', 0);
            $id_dark = HTTP::_GP('id_dark', 0);
            $metal = max(0, round(HTTP::_GP('metal', 0.0)));
            $cristal = max(0, round(HTTP::_GP('cristal', 0.0)));
            $deut = max(0, round(HTTP::_GP('deut', 0.0)));
            $dark = HTTP::_GP('dark', 0);
            if ($_POST) {
                if (!empty($id)) {
                    $before = $GLOBALS['DATABASE']->getFirstRow("SELECT `metal`,`crystal`,`deuterium`,`universe`  FROM " . PLANETS . " WHERE `id` = '" . $id . "';");
                }
                if (!empty($id_dark)) {
                    $before_dm = $GLOBALS['DATABASE']->getFirstRow("SELECT `darkmatter` FROM " . USERS . " WHERE `id` = '" . $id_dark . "';");
                }
                if ($_POST['add']) {
                    if (!empty($id)) {
                        $SQL = "UPDATE " . PLANETS . " SET ";
                        $SQL .= "`metal` = `metal` + '" . $metal . "', ";
                        $SQL .= "`crystal` = `crystal` + '" . $cristal . "', ";
                        $SQL .= "`deuterium` = `deuterium` + '" . $deut . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';";
                        $GLOBALS['DATABASE']->query($SQL);
                        $after = array('metal' => $before['metal'] + $metal, 'crystal' => $before['crystal'] + $cristal, 'deuterium' => $before['deuterium'] + $deut);
                    }
                    if (!empty($id_dark)) {
                        $SQL = "UPDATE " . USERS . " SET ";
                        $SQL .= "`darkmatter` = `darkmatter` + '" . $dark . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id_dark . "' AND `universe` = '" . Universe::getEmulated() . "' ";
                        $GLOBALS['DATABASE']->query($SQL);
                        $after_dm = array('darkmatter' => $before_dm['darkmatter'] + $dark);
                    }
                } elseif ($_POST['delete']) {
                    if (!empty($id)) {
                        $SQL = "UPDATE " . PLANETS . " SET ";
                        $SQL .= "`metal` = `metal` - '" . $metal . "', ";
                        $SQL .= "`crystal` = `crystal` - '" . $cristal . "', ";
                        $SQL .= "`deuterium` = `deuterium` - '" . $deut . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';";
                        $GLOBALS['DATABASE']->query($SQL);
                        $after = array('metal' => $before['metal'] - $metal, 'crystal' => $before['crystal'] - $cristal, 'deuterium' => $before['deuterium'] - $deut);
                    }
                    if (!empty($id_dark)) {
                        $SQL = "UPDATE " . USERS . " SET ";
                        $SQL .= "`darkmatter` = `darkmatter` - '" . $dark . "' ";
                        $SQL .= "WHERE ";
                        $SQL .= "`id` = '" . $id_dark . "';";
                        $GLOBALS['DATABASE']->query($SQL);
                        $after_dm = array('darkmatter' => $before_dm['darkmatter'] - $dark);
                    }
                }
                if (!empty($id)) {
                    $LOG = new Log(2);
                    $LOG->target = $id;
                    $LOG->universe = $before_dm['universe'];
                    $LOG->old = $before;
                    $LOG->new = $after;
                    $LOG->save();
                }
                if (!empty($id_dark)) {
                    $LOG = new Log(1);
                    $LOG->target = $id_dark;
                    $LOG->universe = $before_dm['universe'];
                    $LOG->old = $before_dm;
                    $LOG->new = $after_dm;
                    $LOG->save();
                }
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_res_sucess'], '?page=accounteditor&edit=resources');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_res_sucess'], '?page=accounteditor&edit=resources');
                    }
                }
                exit;
            }
            $template->show('AccountEditorPageResources.tpl');
            break;
        case 'ships':
            if ($_POST) {
                $before1 = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $before = array();
                $after = array();
                foreach ($reslist['fleet'] as $ID) {
                    $before[$ID] = $before1[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`eco_hash` = '', ";
                    foreach ($reslist['fleet'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = $before[$ID] + max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`eco_hash` = '', ";
                    foreach ($reslist['fleet'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = max($before[$ID] - max(0, round(HTTP::_GP($resource[$ID], 0.0))), 0);
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                }
                $LOG = new Log(2);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = $before1['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_ships_sucess'], '?page=accounteditor&edit=ships');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_ships_sucess'], '?page=accounteditor&edit=ships');
                    }
                }
                exit;
            }
            $parse['ships'] = "";
            foreach ($reslist['fleet'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageShips.tpl');
            break;
        case 'defenses':
            if ($_POST) {
                $before1 = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $before = array();
                $after = array();
                foreach ($reslist['defense'] as $ID) {
                    $before[$ID] = $before1[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['defense'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = $before[$ID] + max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    foreach ($reslist['defense'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = max($before[$ID] - max(0, round(HTTP::_GP($resource[$ID], 0.0))), 0);
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                    $Name = $LNG['log_nomoree'];
                }
                $LOG = new Log(2);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = $before1['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_defenses_success'], '?page=accounteditor&edit=defenses');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_defenses_success'], '?page=accounteditor&edit=defenses');
                    }
                }
                exit;
            }
            foreach ($reslist['defense'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageDefenses.tpl');
            break;
            break;
        case 'buildings':
            if ($_POST) {
                $PlanetData = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . PLANETS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                if (!isset($PlanetData)) {
                    $template->message($LNG['ad_add_not_exist'], '?page=accounteditor&edit=buildings');
                }
                $before = array();
                $after = array();
                foreach ($reslist['allow'][$PlanetData['planet_type']] as $ID) {
                    $before[$ID] = $PlanetData[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $Fields = 0;
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`eco_hash` = '', ";
                    foreach ($reslist['allow'][$PlanetData['planet_type']] as $ID) {
                        $Count = max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . $Count . "'";
                        $after[$ID] = $before[$ID] + $Count;
                        $Fields += $Count;
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= ", `field_current` = `field_current` + '" . $Fields . "'";
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $Fields = 0;
                    $QryUpdate = array();
                    $SQL = "UPDATE " . PLANETS . " SET ";
                    $SQL .= "`eco_hash` = '', ";
                    foreach ($reslist['allow'][$PlanetData['planet_type']] as $ID) {
                        $Count = max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . $Count . "'";
                        $after[$ID] = max($before[$ID] - $Count, 0);
                        $Fields += $Count;
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= ", `field_current` = `field_current` - '" . $Fields . "'";
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                }
                $LOG = new Log(2);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = Universe::getEmulated();
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_build_success'], '?page=accounteditor&edit=buildings');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_build_success'], '?page=accounteditor&edit=buildings');
                    }
                }
                exit;
            }
            foreach ($reslist['build'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageBuilds.tpl');
            break;
        case 'researchs':
            if ($_POST) {
                $before1 = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $before = array();
                $after = array();
                foreach ($reslist['tech'] as $ID) {
                    $before[$ID] = $before1[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['tech'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = $before[$ID] + max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['tech'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = max($before[$ID] - max(0, round(HTTP::_GP($resource[$ID], 0.0))), 0);
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                }
                $LOG = new Log(1);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = $before1['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_tech_success'], '?page=accounteditor&edit=researchs');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_tech_success'], '?page=accounteditor&edit=researchs');
                    }
                }
                exit;
            }
            foreach ($reslist['tech'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageResearch.tpl');
            break;
        case 'personal':
            if ($_POST) {
                $id = HTTP::_GP('id', 0);
                $username = HTTP::_GP('username', '', UTF8_SUPPORT);
                $password = HTTP::_GP('password', '', true);
                $email = HTTP::_GP('email', '');
                $email_2 = HTTP::_GP('email_2', '');
                $vacation = HTTP::_GP('vacation', '');
                $before = $GLOBALS['DATABASE']->getFirstRow("SELECT `username`,`email`,`email_2`,`password`,`urlaubs_modus`,`urlaubs_until` FROM " . USERS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $after = array();
                $PersonalQuery = "UPDATE " . USERS . " SET ";
                if (!empty($username) && $id != ROOT_USER) {
                    $PersonalQuery .= "`username` = '" . $GLOBALS['DATABASE']->sql_escape($username) . "', ";
                    $after['username'] = $username;
                }
                if (!empty($email) && $id != ROOT_USER) {
                    $PersonalQuery .= "`email` = '" . $GLOBALS['DATABASE']->sql_escape($email) . "', ";
                    $after['email'] = $email;
                }
                if (!empty($email_2) && $id != ROOT_USER) {
                    $PersonalQuery .= "`email_2` = '" . $GLOBALS['DATABASE']->sql_escape($email_2) . "', ";
                    $after['email_2'] = $email_2;
                }
                if (!empty($password) && $id != ROOT_USER) {
                    $PersonalQuery .= "`password` = '" . $GLOBALS['DATABASE']->sql_escape(cryptPassword($password)) . "', ";
                    $after['password'] = cryptPassword($password) != $before['password'] ? 'CHANGED' : '';
                }
                $before['password'] = '';
                $Answer = 0;
                $TimeAns = 0;
                if ($vacation == 'yes') {
                    $Answer = 1;
                    $after['urlaubs_modus'] = 1;
                    $TimeAns = TIMESTAMP + $_POST['d'] * 86400 + $_POST['h'] * 3600 + $_POST['m'] * 60 + $_POST['s'];
                    $after['urlaubs_until'] = $TimeAns;
                }
                $PersonalQuery .= "`urlaubs_modus` = '" . $Answer . "', `urlaubs_until` = '" . $TimeAns . "' ";
                $PersonalQuery .= "WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "'";
                $GLOBALS['DATABASE']->query($PersonalQuery);
                $LOG = new Log(1);
                $LOG->target = $id;
                $LOG->universe = $before['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                $template->message($LNG['ad_personal_succes'], '?page=accounteditor&edit=personal');
                exit;
            }
            $template->assign_vars(array('Selector' => array('' => $LNG['select_option'], 'yes' => $LNG['one_is_yes'][1], 'no' => $LNG['one_is_yes'][0])));
            $template->show('AccountEditorPagePersonal.tpl');
            break;
        case 'officiers':
            if ($_POST) {
                $before1 = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE `id` = '" . HTTP::_GP('id', 0) . "';");
                $before = array();
                $after = array();
                foreach ($reslist['officier'] as $ID) {
                    $before[$ID] = $before1[$resource[$ID]];
                }
                if ($_POST['add']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['officier'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` + '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = $before[$ID] + max(0, round(HTTP::_GP($resource[$ID], 0.0)));
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                } elseif ($_POST['delete']) {
                    $SQL = "UPDATE " . USERS . " SET ";
                    foreach ($reslist['officier'] as $ID) {
                        $QryUpdate[] = "`" . $resource[$ID] . "` = `" . $resource[$ID] . "` - '" . max(0, round(HTTP::_GP($resource[$ID], 0.0))) . "'";
                        $after[$ID] = max($before[$ID] - max(0, round(HTTP::_GP($resource[$ID], 0.0))), 0);
                    }
                    $SQL .= implode(", ", $QryUpdate);
                    $SQL .= "WHERE ";
                    $SQL .= "`id` = '" . HTTP::_GP('id', 0) . "' AND `universe` = '" . Universe::getEmulated() . "';";
                    $GLOBALS['DATABASE']->query($SQL);
                }
                $LOG = new Log(1);
                $LOG->target = HTTP::_GP('id', 0);
                $LOG->universe = $before1['universe'];
                $LOG->old = $before;
                $LOG->new = $after;
                $LOG->save();
                if ($_POST['add']) {
                    $template->message($LNG['ad_add_offi_success'], '?page=accounteditor&edit=officiers');
                } else {
                    if ($_POST['delete']) {
                        $template->message($LNG['ad_delete_offi_success'], '?page=accounteditor&edit=officiers');
                    }
                }
                exit;
            }
            foreach ($reslist['officier'] as $ID) {
                $INPUT[$ID] = array('type' => $resource[$ID]);
            }
            $template->assign_vars(array('inputlist' => $INPUT));
            $template->show('AccountEditorPageOfficiers.tpl');
            break;
        case 'planets':
            if ($_POST) {
                $id = HTTP::_GP('id', 0);
                $name = HTTP::_GP('name', '', UTF8_SUPPORT);
                $diameter = HTTP::_GP('diameter', 0);
                $fields = HTTP::_GP('fields', 0);
                $buildings = HTTP::_GP('0_buildings', '');
                $ships = HTTP::_GP('0_ships', '');
                $defenses = HTTP::_GP('0_defenses', '');
                $c_hangar = HTTP::_GP('0_c_hangar', '');
                $c_buildings = HTTP::_GP('0_c_buildings', '');
                $change_pos = HTTP::_GP('change_position', '');
                $galaxy = HTTP::_GP('g', 0);
                $system = HTTP::_GP('s', 0);
                $planet = HTTP::_GP('p', 0);
                if (!empty($name)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `name` = '" . $GLOBALS['DATABASE']->sql_escape($name) . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($buildings == 'on') {
                    foreach ($reslist['build'] as $ID) {
                        $BUILD[] = "`" . $resource[$ID] . "` = '0'";
                    }
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET " . implode(', ', $BUILD) . " WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($ships == 'on') {
                    foreach ($reslist['fleet'] as $ID) {
                        $SHIPS[] = "`" . $resource[$ID] . "` = '0'";
                    }
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET " . implode(', ', $SHIPS) . " WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($defenses == 'on') {
                    foreach ($reslist['defense'] as $ID) {
                        $DEFS[] = "`" . $resource[$ID] . "` = '0'";
                    }
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET " . implode(', ', $DEFS) . " WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($c_hangar == 'on') {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `b_hangar` = '0', `b_hangar_plus` = '0', `b_hangar_id` = '' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($c_buildings == 'on') {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `b_building` = '0', `b_building_id` = '' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($diameter)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `diameter` = '" . $diameter . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($fields)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `field_max` = '" . $fields . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                }
                if ($change_pos == 'on' && $galaxy > 0 && $system > 0 && $planet > 0 && $galaxy <= Config::get(Universe::getEmulated())->max_galaxy && $system <= Config::get(Universe::getEmulated())->max_system && $planet <= Config::get(Universe::getEmulated())->max_planets) {
                    $P = $GLOBALS['DATABASE']->getFirstRow("SELECT galaxy,system,planet,planet_type FROM " . PLANETS . " WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                    if ($P['planet_type'] == '1') {
                        if (PlayerUtil::checkPosition(Universe::getEmulated(), $galaxy, $system, $planet, $P['planet_type'])) {
                            $template->message($LNG['ad_pla_error_planets3'], '?page=accounteditor&edit=planets');
                            exit;
                        }
                        $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `galaxy` = '" . $galaxy . "', `system` = '" . $system . "', `planet` = '" . $planet . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                    } else {
                        if (PlayerUtil::checkPosition(Universe::getEmulated(), $galaxy, $system, $planet, $P['planet_type'])) {
                            $template->message($LNG['ad_pla_error_planets5'], '?page=accounteditor&edit=planets');
                            exit;
                        }
                        $Target = $GLOBALS['DATABASE']->getFirstRow("SELECT id_luna FROM " . PLANETS . " WHERE `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "' AND `planet_type` = '1';");
                        if ($Target['id_luna'] != '0') {
                            $template->message($LNG['ad_pla_error_planets4'], '?page=accounteditor&edit=planets');
                            exit;
                        }
                        $GLOBALS['DATABASE']->multi_query("UPDATE " . PLANETS . " SET `id_luna` = '0' WHERE `galaxy` = '" . $P['galaxy'] . "' AND `system` = '" . $P['system'] . "' AND `planet` = '" . $P['planet'] . "' AND `planet_type` = '1';UPDATE " . PLANETS . " SET `id_luna` = '" . $id . "'  WHERE `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "' AND planet_type = '1';UPDATE " . PLANETS . " SET `galaxy` = '" . $galaxy . "', `system` = '" . $system . "', `planet` = '" . $planet . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "';");
                        $QMOON2 = $GLOBALS['DATABASE']->getFirstRow("SELECT id_owner FROM " . PLANETS . " WHERE `galaxy` = '" . $galaxy . "' AND `system` = '" . $system . "' AND `planet` = '" . $planet . "';");
                        $GLOBALS['DATABASE']->query("UPDATE " . PLANETS . " SET `galaxy` = '" . $galaxy . "', `system` = '" . $system . "', `planet` = '" . $planet . "', `id_owner` = '" . $QMOON2['id_owner'] . "' WHERE `id` = '" . $id . "' AND `universe` = '" . Universe::getEmulated() . "' AND `planet_type` = '3';");
                    }
                }
                $template->message($LNG['ad_pla_succes'], '?page=accounteditor&edit=planets');
                exit;
            }
            $template->show('AccountEditorPagePlanets.tpl');
            break;
        case 'alliances':
            if ($_POST) {
                $id = HTTP::_GP('id', 0);
                $name = HTTP::_GP('name', '', UTF8_SUPPORT);
                $changeleader = HTTP::_GP('changeleader', 0);
                $tag = HTTP::_GP('tag', '', UTF8_SUPPORT);
                $externo = HTTP::_GP('externo', '', true);
                $interno = HTTP::_GP('interno', '', true);
                $solicitud = HTTP::_GP('solicitud', '', true);
                $delete = HTTP::_GP('delete', '');
                $delete_u = HTTP::_GP('delete_u', '');
                $QueryF = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . ALLIANCE . " WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                if (!empty($name)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_name` = '" . $name . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($tag)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_tag` = '" . $tag . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                $QueryF2 = $GLOBALS['DATABASE']->getFirstRow("SELECT ally_id FROM " . USERS . " WHERE `id` = '" . $changeleader . "';");
                $GLOBALS['DATABASE']->multi_query("UPDATE " . ALLIANCE . " SET `ally_owner` = '" . $changeleader . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';UPDATE " . USERS . " SET `ally_rank_id` = '0' WHERE `id` = '" . $changeleader . "';");
                if (!empty($externo)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_description` = '" . $externo . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($interno)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_text` = '" . $interno . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                if (!empty($solicitud)) {
                    $GLOBALS['DATABASE']->query("UPDATE " . ALLIANCE . " SET `ally_request` = '" . $solicitud . "' WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';");
                }
                if ($delete == 'on') {
                    $GLOBALS['DATABASE']->multi_query("DELETE FROM " . ALLIANCE . " WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';UPDATE " . USERS . " SET `ally_id` = '0', `ally_rank_id` = '0', `ally_register_time` = '0' WHERE `ally_id` = '" . $id . "';");
                }
                if (!empty($delete_u)) {
                    $GLOBALS['DATABASE']->multi_query("UPDATE " . ALLIANCE . " SET `ally_members` = ally_members - 1 WHERE `id` = '" . $id . "' AND `ally_universe` = '" . Universe::getEmulated() . "';UPDATE " . USERS . " SET `ally_id` = '0', `ally_rank_id` = '0', `ally_register_time` = '0' WHERE `id` = '" . $delete_u . "' AND `ally_id` = '" . $id . "';");
                }
                $template->message($LNG['ad_ally_succes'], '?page=accounteditor&edit=alliances');
                exit;
            }
            $template->show('AccountEditorPageAlliance.tpl');
            break;
        default:
            $template->show('AccountEditorPageMenu.tpl');
            break;
    }
}
Esempio n. 2
0
function ShowCreatorPage()
{
    global $LNG, $USER;
    $template = new template();
    switch ($_GET['mode']) {
        case 'user':
            $LNG->includeData(array('PUBLIC'));
            if ($_POST) {
                $UserName = HTTP::_GP('name', '', UTF8_SUPPORT);
                $UserPass = HTTP::_GP('password', '');
                $UserPass2 = HTTP::_GP('password2', '');
                $UserMail = HTTP::_GP('email', '');
                $UserMail2 = HTTP::_GP('email2', '');
                $UserAuth = HTTP::_GP('authlevel', 0);
                $Galaxy = HTTP::_GP('galaxy', 0);
                $System = HTTP::_GP('system', 0);
                $Planet = HTTP::_GP('planet', 0);
                $Language = HTTP::_GP('lang', '');
                $ExistsUser = $GLOBALS['DATABASE']->getFirstCell("SELECT (SELECT COUNT(*) FROM " . USERS . " WHERE universe = " . Universe::getEmulated() . " AND username = '******'DATABASE']->sql_escape($UserName) . "') + (SELECT COUNT(*) FROM " . USERS_VALID . " WHERE universe = " . Universe::getEmulated() . " AND username = '******'DATABASE']->sql_escape($UserName) . "')");
                $ExistsMails = $GLOBALS['DATABASE']->getFirstCell("SELECT (SELECT COUNT(*) FROM " . USERS . " WHERE universe = " . Universe::getEmulated() . " AND (email = '" . $GLOBALS['DATABASE']->sql_escape($UserMail) . "' OR email_2 = '" . $GLOBALS['DATABASE']->sql_escape($UserMail) . "')) + (SELECT COUNT(*) FROM " . USERS_VALID . " WHERE universe = " . Universe::getEmulated() . " AND email = '" . $GLOBALS['DATABASE']->sql_escape($UserMail) . "')");
                $errors = "";
                $config = Config::get(Universe::getEmulated());
                if (!PlayerUtil::isMailValid($UserMail)) {
                    $errors .= $LNG['invalid_mail_adress'];
                }
                if (empty($UserName)) {
                    $errors .= $LNG['empty_user_field'];
                }
                if (strlen($UserPass) < 6) {
                    $errors .= $LNG['password_lenght_error'];
                }
                if ($UserPass != $UserPass2) {
                    $errors .= $LNG['different_passwords'];
                }
                if ($UserMail != $UserMail2) {
                    $errors .= $LNG['different_mails'];
                }
                if (!PlayerUtil::isNameValid($UserName)) {
                    $errors .= $LNG['user_field_specialchar'];
                }
                if ($ExistsUser != 0) {
                    $errors .= $LNG['user_already_exists'];
                }
                if ($ExistsMails != 0) {
                    $errors .= $LNG['mail_already_exists'];
                }
                if (!PlayerUtil::isPositionFree(Universe::getEmulated(), $Galaxy, $System, $Planet)) {
                    $errors .= $LNG['planet_already_exists'];
                }
                if ($Galaxy > $config->max_galaxy || $System > $config->max_system || $Planet > $config->max_planets) {
                    $errors .= $LNG['po_complete_all2'];
                }
                if (!empty($errors)) {
                    $template->message($errors, '?page=create&mode=user', 10, true);
                    exit;
                }
                $Language = array_key_exists($Language, $LNG->getAllowedLangs(false)) ? $Language : $config->lang;
                PlayerUtil::createPlayer(Universe::getEmulated(), $UserName, PlayerUtil::cryptPassword($UserPass), $UserMail, $Language, $Galaxy, $System, $Planet, $LNG['fcm_planet'], $UserAuth);
                $template->message($LNG['new_user_success'], '?page=create&mode=user', 5, true);
                exit;
            }
            $AUTH = array();
            $AUTH[AUTH_USR] = $LNG['user_level'][AUTH_USR];
            if ($USER['authlevel'] >= AUTH_OPS) {
                $AUTH[AUTH_OPS] = $LNG['user_level'][AUTH_OPS];
            }
            if ($USER['authlevel'] >= AUTH_MOD) {
                $AUTH[AUTH_MOD] = $LNG['user_level'][AUTH_MOD];
            }
            if ($USER['authlevel'] >= AUTH_ADM) {
                $AUTH[AUTH_ADM] = $LNG['user_level'][AUTH_ADM];
            }
            $template->assign_vars(array('admin_auth' => $USER['authlevel'], 'new_add_user' => $LNG['new_add_user'], 'new_creator_refresh' => $LNG['new_creator_refresh'], 'new_creator_go_back' => $LNG['new_creator_go_back'], 'universe' => $LNG['mu_universe'], 'user_reg' => $LNG['user_reg'], 'pass_reg' => $LNG['pass_reg'], 'pass2_reg' => $LNG['pass2_reg'], 'email_reg' => $LNG['email_reg'], 'email2_reg' => $LNG['email2_reg'], 'new_coord' => $LNG['new_coord'], 'new_range' => $LNG['new_range'], 'lang_reg' => $LNG['lang_reg'], 'new_title' => $LNG['new_title'], 'Selector' => array('auth' => $AUTH, 'lang' => $LNG->getAllowedLangs(false))));
            $template->show('CreatePageUser.tpl');
            break;
        case 'moon':
            if ($_POST) {
                $PlanetID = HTTP::_GP('add_moon', 0);
                $MoonName = HTTP::_GP('name', '', UTF8_SUPPORT);
                $Diameter = HTTP::_GP('diameter', 0);
                $MoonPlanet = $GLOBALS['DATABASE']->getFirstRow("SELECT temp_max, temp_min, id_luna, galaxy, system, planet, planet_type, destruyed, id_owner FROM " . PLANETS . " WHERE id = '" . $PlanetID . "' AND universe = '" . Universe::getEmulated() . "' AND planet_type = '1' AND destruyed = '0';");
                if (!isset($MoonPlanet)) {
                    $template->message($LNG['mo_planet_doesnt_exist'], '?page=create&mode=moon', 3, true);
                    exit;
                }
                $moonId = PlayerUtil::createMoon(Universe::getEmulated(), $MoonPlanet['galaxy'], $MoonPlanet['system'], $MoonPlanet['planet'], $MoonPlanet['id_owner'], 20, $_POST['diameter_check'] == 'on' ? NULL : $Diameter, $MoonName);
                if ($moonId !== false) {
                    $template->message($LNG['mo_moon_added'], '?page=create&mode=moon', 3, true);
                } else {
                    $template->message($LNG['mo_moon_unavaible'], '?page=create&mode=moon', 3, true);
                }
                exit;
            }
            $template->assign_vars(array('admin_auth' => $USER['authlevel'], 'universum' => $LNG['mu_universe'], 'po_add_moon' => $LNG['po_add_moon'], 'input_id_planet' => $LNG['input_id_planet'], 'mo_moon_name' => $LNG['mo_moon_name'], 'mo_diameter' => $LNG['mo_diameter'], 'mo_temperature' => $LNG['mo_temperature'], 'mo_fields_avaibles' => $LNG['mo_fields_avaibles'], 'button_add' => $LNG['button_add'], 'new_creator_refresh' => $LNG['new_creator_refresh'], 'mo_moon' => $LNG['fcm_moon'], 'new_creator_go_back' => $LNG['new_creator_go_back']));
            $template->show('CreatePageMoon.tpl');
            break;
        case 'planet':
            if ($_POST) {
                $id = HTTP::_GP('id', 0);
                $Galaxy = HTTP::_GP('galaxy', 0);
                $System = HTTP::_GP('system', 0);
                $Planet = HTTP::_GP('planet', 0);
                $name = HTTP::_GP('name', '', UTF8_SUPPORT);
                $field_max = HTTP::_GP('field_max', 0);
                $config = Config::get(Universe::getEmulated());
                if ($Galaxy > $config->max_galaxy || $System > $config->max_system || $Planet > $config->max_planets) {
                    $template->message($LNG['po_complete_all2'], '?page=create&mode=planet', 3, true);
                    exit;
                }
                $ISUser = $GLOBALS['DATABASE']->getFirstRow("SELECT id, authlevel FROM " . USERS . " WHERE id = '" . $id . "' AND universe = '" . Universe::getEmulated() . "';");
                if (!PlayerUtil::checkPosition(Universe::getEmulated(), $Galaxy, $System, $Planet) || !isset($ISUser)) {
                    $template->message($LNG['po_complete_all'], '?page=create&mode=planet', 3, true);
                    exit;
                }
                $planetId = PlayerUtil::createPlanet($Galaxy, $System, $Planet, Universe::getEmulated(), $id, NULL, false, $ISUser['authlevel']);
                $SQL = "UPDATE " . PLANETS . " SET ";
                if ($_POST['diameter_check'] != 'on' || $field_max > 0) {
                    $SQL .= "field_max = '" . $field_max . "' ";
                }
                if (!empty($name)) {
                    $SQL .= ", name = '" . $GLOBALS['DATABASE']->sql_escape($name) . "' ";
                }
                $SQL .= "WHERE ";
                $SQL .= "id = '" . $planetId . "'";
                $GLOBALS['DATABASE']->query($SQL);
                $template->message($LNG['po_complete_succes'], '?page=create&mode=planet', 3, true);
                exit;
            }
            $template->assign_vars(array('admin_auth' => $USER['authlevel'], 'po_add_planet' => $LNG['po_add_planet'], 'po_galaxy' => $LNG['po_galaxy'], 'po_system' => $LNG['po_system'], 'po_planet' => $LNG['po_planet'], 'input_id_user' => $LNG['input_id_user'], 'new_creator_coor' => $LNG['new_creator_coor'], 'po_name_planet' => $LNG['po_name_planet'], 'po_fields_max' => $LNG['po_fields_max'], 'button_add' => $LNG['button_add'], 'po_colony' => $LNG['fcp_colony'], 'new_creator_refresh' => $LNG['new_creator_refresh'], 'new_creator_go_back' => $LNG['new_creator_go_back']));
            $template->show('CreatePagePlanet.tpl');
            break;
        default:
            $template->assign_vars(array('new_creator_title_u' => $LNG['new_creator_title_u'], 'new_creator_title_p' => $LNG['new_creator_title_p'], 'new_creator_title_l' => $LNG['new_creator_title_l'], 'new_creator_title' => $LNG['new_creator_title']));
            $template->show('CreatePage.tpl');
            break;
    }
}
    function TargetEvent()
    {
        $db = Database::get();
        $sql = 'SELECT * FROM %%USERS%% WHERE `id` = :userId;';
        $senderUser = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner']));
        $senderUser['factor'] = getFactors($senderUser, 'basic', $this->_fleet['fleet_start_time']);
        $LNG = $this->getLanguage($senderUser['lang']);
        $checkPosition = PlayerUtil::checkPosition($this->_fleet['fleet_universe'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']);
        $isPositionFree = PlayerUtil::isPositionFree($this->_fleet['fleet_universe'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']);
        if (!$isPositionFree || !$checkPosition) {
            $message = sprintf($LNG['sys_colo_notfree'], GetTargetAddressLink($this->_fleet, ''));
        } else {
            $allowPlanetPosition = PlayerUtil::allowPlanetPosition($this->_fleet['fleet_end_planet'], $senderUser);
            if (!$allowPlanetPosition) {
                $message = sprintf($LNG['sys_colo_notech'], GetTargetAddressLink($this->_fleet, ''));
            } else {
                $sql = 'SELECT COUNT(*) as state
				FROM %%PLANETS%%
				WHERE `id_owner`	= :userId
				AND `planet_type`	= :type
				AND `destruyed`		= :destroyed;';
                $currentPlanetCount = $db->selectSingle($sql, array(':userId' => $this->_fleet['fleet_owner'], ':type' => 1, ':destroyed' => 0), 'state');
                $maxPlanetCount = PlayerUtil::maxPlanetCount($senderUser);
                if ($currentPlanetCount >= $maxPlanetCount) {
                    $message = sprintf($LNG['sys_colo_maxcolo'], GetTargetAddressLink($this->_fleet, ''), $maxPlanetCount);
                } else {
                    $NewOwnerPlanet = PlayerUtil::createPlanet($this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet'], $this->_fleet['fleet_universe'], $this->_fleet['fleet_owner'], $LNG['fcp_colony'], false, $senderUser['authlevel']);
                    if ($NewOwnerPlanet === false) {
                        $message = sprintf($LNG['sys_colo_badpos'], GetTargetAddressLink($this->_fleet, ''));
                        $this->setState(FLEET_RETURN);
                    } else {
                        $this->_fleet['fleet_end_id'] = $NewOwnerPlanet;
                        $message = sprintf($LNG['sys_colo_allisok'], GetTargetAddressLink($this->_fleet, ''));
                        $this->StoreGoodsToPlanet();
                        if ($this->_fleet['fleet_amount'] == 1) {
                            $this->KillFleet();
                        } else {
                            $CurrentFleet = explode(";", $this->_fleet['fleet_array']);
                            $NewFleet = '';
                            foreach ($CurrentFleet as $Group) {
                                if (empty($Group)) {
                                    continue;
                                }
                                $Class = explode(",", $Group);
                                if ($Class[0] == 208 && $Class[1] > 1) {
                                    $NewFleet .= $Class[0] . "," . ($Class[1] - 1) . ";";
                                } elseif ($Class[0] != 208 && $Class[1] > 0) {
                                    $NewFleet .= $Class[0] . "," . $Class[1] . ";";
                                }
                            }
                            $this->UpdateFleet('fleet_array', $NewFleet);
                            $this->UpdateFleet('fleet_amount', $this->_fleet['fleet_amount'] - 1);
                            $this->UpdateFleet('fleet_resource_metal', 0);
                            $this->UpdateFleet('fleet_resource_crystal', 0);
                            $this->UpdateFleet('fleet_resource_deuterium', 0);
                        }
                    }
                }
            }
        }
        PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_colo_mess_from'], 4, $LNG['sys_colo_mess_report'], $message, $this->_fleet['fleet_start_time'], NULL, 1, $this->_fleet['fleet_universe']);
        $this->setState(FLEET_RETURN);
        $this->SaveFleet();
    }