<?php
include("connect.php");
include("login_cookies.php");

while($admin = mysql_fetch_array($db_admin)) {

if ($_COOKIE["pass"] == $admin["kode"]) {

 if ($admin["admin"] == "1") {

	if ($admin["exist"] == "1") {

if ($_GET[ret] == "true" && isset($_GET[id])) {

$rettende = mysql_query("SELECT * FROM `pytox_nyheder` WHERE `id` LIKE '{$_GET[id]}' LIMIT 1");

while($ret = mysql_fetch_array($rettende)) {

?>
<form action="?site=Adminnews&retter=true&submit=true&id=<?php print $_GET[id];?>" method="post">
Overskrift: <input type="text" name="header" value="<?php print $ret[overskrift]; ?>" />
<br />
Nyheden:
<br />
<textarea name="nyheden" cols="35" rows="12"><?php print $ret[nyhed]; ?></textarea>
<br />
Forfatter: <input type="text" name="author" value="<?php print $ret[forfatter];?>" /> <i>MÅ IKKE RETTES!</i>
<br />
<br />
<input type="submit" name="submit" value="Ret!" class="submit" />
</form>
<?php
}

} else if ($_GET[retter] == "true" && $_GET[submit] == "true" && isset($_GET[id])) {

if ($_POST[header] == "" || $_POST[nyheden] == "" || $_POST[author] == "") {
header("Location: index.php?message=failure&errorid=27173");
} else {

$erstattes = array("Ø", "ø", "Å", "å", "Æ", "æ");

$replace["header"] = str_replace("Ø", "&Oslash;", $_POST["header"]);
$replace["header"] = str_replace("ø", "&oslash;", $replace["header"]);
$replace["header"] = str_replace("Å", "&Aring;", $replace["header"]);
$replace["header"] = str_replace("å", "&aring;", $replace["header"]);
$replace["header"] = str_replace("Æ", "&Aelig;", $replace["header"]);
$replace["header"] = str_replace("æ", "&aelig;", $replace["header"]);

$replace["nyheden"] = str_replace("Ø", "&Oslash;", $_POST["nyheden"]);
$replace["nyheden"] = str_replace("ø", "&oslash;", $replace["nyheden"]);
$replace["nyheden"] = str_replace("Å", "&Aring;", $replace["nyheden"]);
$replace["nyheden"] = str_replace("å", "&aring;", $replace["nyheden"]);
$replace["nyheden"] = str_replace("Æ", "&Aelig;", $replace["nyheden"]);
$replace["nyheden"] = str_replace("æ", "&aelig;", $replace["nyheden"]);

mysql_query("UPDATE `pytox_nyheder` SET `show` = '1', `udgivet` = '1', `overskrift` = '$replace[header]', `nyhed` = '$replace[nyheden]', `forfatter` = '$_POST[author]' WHERE `id` LIKE '{$_GET[id]}' LIMIT 1");

print "Nyheden er nu rettet!";

setcookie("test", $_POST[nyheden], time()+10000);


}

} else if ($_GET[choose] == "delete" && isset($_GET[delid])) {

mysql_query("UPDATE `pytox_nyheder` SET `show` = '0' WHERE `id` LIKE '{$_GET[delid]}' LIMIT 1");

header("Location: index.php?site=Adminnews&del=true&id=$_GET[delid]");

} else if ($_GET[del] == "true" && isset($_GET[id])) {

$tjek = mysql_query("SELECT * FROM `pytox_nyheder` WHERE `id` LIKE '{$_GET[id]}' LIMIT 1");

while($look = mysql_fetch_array($tjek)) { 

if ($look[show] == "0") {
header("Location: index.php?site=Admin&message=corretdelart");
} else if ($look[show] != "0") {
header("Location: index.php?site=Admin&message=failure&errorid=51546");
}

}


} else {

$db_nyhedadmin = mysql_query("SELECT * FROM `pytox_nyheder` WHERE `show` LIKE '1' ORDER BY `id` DESC") or die(mysql_error());

while($new = mysql_fetch_array($db_nyhedadmin)) {

if ($new[show] == true) {
?>
<strong><?php print $new[overskrift]; ?></strong> - <a href="?site=Adminnews&amp;choose=delete&amp;delid=<?php print $new[id];?>">Slet</a> - <a href="?site=Adminnews&ret=true&id=<?php print $new[id];?>">Ret</a>
<br />
<?php
}
}

}

	} else {
	header("Location: index.php?message=failure&errorid=60065");
	}

}

}
}
?>
<br />