<?php
if(!defined('INDEX')) { header('Location: ../'); exit; }
$pagea = 'print';
$titre = 'Vérification planète';

	$template->assign('linkpage', 'vplanetes');

if (!empty($_GET['id']) && !empty($_GET['key']) && $_GET['key'] != 'id') {
	$pagea = 'print_key';
	$id_plan = $_GET['id'];
	$key = $_GET['key'];
	$chapeau->connexion();
	$chapeau->escape($id_plan);
	$chapeau->escape($key);
	$reqp = $chapeau->unique_query("SELECT * FROM $table_planete WHERE id = '$id_plan';");
	$req = $chapeau->unique_query("DESCRIBE $table_planete $key;");
	$chapeau->deconnexion();
	$template->assign('tableau', $reqp);
	$template->assign('type', explode('(', $req['Type']));
	$template->assign('idPlan', $id_plan);
	$template->assign('key', $_GET['key']);
}
elseif (!empty($_GET['id'])) {
	$id_plan = $_GET['id'];
	if (isset($_POST['key']) && isset($_POST['mod'])) {
		$key = $_POST['key'];
		$mod = $_POST['mod'];
		$chapeau->connexion();
		$chapeau->escape($mod);
		$chapeau->query("UPDATE $table_planete SET $key = '$mod' WHERE id = '$id_plan';");
		$chapeau->deconnexion();
	}
	$chapeau->connexion();
	$req = $chapeau->unique_query("SELECT * FROM $table_planete WHERE id = '$id_plan';");
	$chapeau->deconnexion();
	$template->assign('tableau', $req);
	$template->assign('idPlan', $id_plan);
}
elseif (isset($_GET['amas']) && isset($_GET['ss']) && !empty($_GET['pos'])) {
	$amas = $_GET['amas'];
	$ss = $_GET['ss'];
	$pos = $_GET['pos'];
	$chapeau->connexion();
	$chapeau->escape($amas);
	$chapeau->escape($ss);
	$chapeau->escape($pos);
	$req = $chapeau->unique_query("SELECT * FROM $table_planete WHERE galaxie = '$amas' AND ss = '$ss' AND position = '$pos';");
	$chapeau->deconnexion();
	header('Location: admin.php?p=vplanetes&id='.$req['id']);
	exit;
}
else {
	$pagea = 'print_choixP';
}
?>