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

$tid = date("H:i:s d/m - Y");

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

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

 if ($admin["admin"] == "1" || $admin["admin"] == "3" || $admin["admin"] == "2") {

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

?>
<div align="center"><div class="blackborder" align="center" style="background-color:#EEE;color:#000;width:500px;height:18px;"><a href="?site=Adkonkurrencer&amp;choose=new">Ny konkurrence</a> | <a href="?site=Adkonkurrencer&amp;choose=red">Rediger konkurrence</a> | <a href="?site=Adkonkurrencer&amp;choose=del">Slet konkurrence</a></div></div>
<br />
<br />
<?php
///////////////////////NY
if ($_GET['choose'] == "new") {
	if ($_GET['action'] == "true") {
		if ($_POST['overskrift'] == "" || $_POST['om'] == "" || $_POST['vind'] == "" || $_POST['henvend'] == "") {
		print "Én eller flere felter blev ikke udfyldt! (Fejlkode: 27173)";
		} else {
		
		$opret = mysql_query("INSERT INTO `pytox_konkurrencer` (`id`, `header`, `about`, `win`, `by`) VALUES ('', '{$_POST['overskrift']}', '{$_POST['om']}', '{$_POST['vind']}', '{$_POST['henvend']}')");
		
		if ($opret == "1") {
		print "Konkurrencen blev oprettet med succes!";
		} else {
		print "Der opstod en fejl!";
		}
		}
	} else {
?>
<form action="?site=Adkonkurrencer&amp;choose=new&amp;action=true" method="post">
<strong>Opret ny konkurrence</strong>
<br />
<br />
Overskrift: <input type="text" name="overskrift" />
<br />
<br />
Om konkurrencen:<br /><textarea cols="30" rows="15" style="display:block;" name="om"></textarea>
<br />
<br />
Man kan vinde: <input type="text" name="vind" />
<br />
<br />
Henvend dig til: <input type="text" name="henvend" />
<br />
<br />
<input type="submit" value="Opret" name="submit" class="submit" />
</form>
<?php
	}
	///////////////////////NY
} else if ($_GET['choose'] == "red") {
///////////////////////RED
if ($_GET['action'] == "true") {

 if ($_POST['overskrift'] == "" || $_POST['om'] == "" || $_POST['vind'] == "" || $_POST['henvend'] == "") {
 print "Én eller flere felter blev ikke udfyldt!";
 } else {
 $opdater = mysql_query("UPDATE `pytox_konkurrencer` SET `header` = '$_POST[overskrift]', `about` = '$_POST[om]', `win` = '$_POST[vind]', `by` = '$_POST[henvend]' WHERE `id` LIKE '{$_POST['id']}' LIMIT 1") or die(mysql_error());
 if ($opdater == "1") {
 print "Konkurrencen blev redigeret med succes!";
 } else {
 print "Der skete en fejl!";
 }
 }

} else {
	if ($_GET['id'] != "") {
	$getcon = mysql_query("SELECT * FROM `pytox_konkurrencer` WHERE `id` LIKE '{$_GET['id']}' LIMIT 1");
	while($con = mysql_fetch_array($getcon)) {
	?>
<form action="?site=Adkonkurrencer&amp;choose=red&amp;action=true" method="post">
<strong>Rediger konkurrence</strong>
<br />
<input type="hidden" value="<?=$con['id']?>" name="id" />
<br />
Overskrift: <input type="text" name="overskrift" value="<?=$con['header']?>" />
<br />
<br />
Om konkurrencen:<br /><textarea cols="30" rows="15" style="display:block;" name="om"><?=$con['about']?></textarea>
<br />
<br />
Man kan vinde: <input type="text" name="vind" value="<?=$con['win']?>" />
<br />
<br />
Henvend dig til: <input type="text" name="henvend" value="<?=$con['by']?>" />
<br />
<br />
<input type="submit" value="Rediger" name="submit" class="submit" />
</form>
	<?php
	}
	} else {

?>
<table style="width:700px;" class="blackborder" cellpadding="1" cellspacing="0">
 <tr>
  <td style="border-bottom:1px solid #000;background-color:#CEC;">
  <strong>Overskrift</strong>
  </td>
  <td style="border-bottom:1px solid #000;background-color:#CEC;">
  <strong>Præmie</strong>
  </td>
 </tr>
<?php
$getchallenges = mysql_query("SELECT * FROM `pytox_konkurrencer` ORDER BY `id` DESC");

while($challenge = mysql_fetch_array($getchallenges)) {
if ($color == "#FFF") {
$color = "#EEE";
} else {
$color = "#FFF";
}
?>
 <tr>
  <td style="background-color:<?=$color?>;">
  <a href="?site=Adkonkurrencer&amp;choose=red&amp;id=<?=$challenge['id']?>"><?=$challenge['header']?></a>
  </td>
  <td style="background-color:<?=$color?>;">
  <?=$challenge['by']?>
  </td>
 </tr>
<?php
}
?>
</table>
<?php
}
}
///////////////////////RED
} else if ($_GET['choose'] == "del") {
///////////////////////DEL

if ($_GET['action'] == "true" && $_GET['id'] != "") {
 if ($_GET['sure'] == "yes") {
 $drop = mysql_query("DELETE FROM `pytox_konkurrencer` WHERE `id` LIKE '{$_GET['id']}' LIMIT 1");
	if ($drop == "1") {
	print "Konkurrencen blev slettet med succes!";
	} else {
	print "Der skete en fejl!";
	}
 } else {
$getkon = mysql_query("SELECT * FROM `pytox_konkurrencer` WHERE `id` LIKE '{$_GET['id']}' LIMIT 1");
while($kon = mysql_fetch_array($getkon)) {
?>
<strong>Er du sikker på, at du vil slette denne konkurrence?:</strong> <a href="?site=Adkonkurrencer&amp;choose=del&amp;action=true&amp;id=<?=$kon['id'];?>&amp;sure=yes">Ja</a> - <a href="javascript:history.go(-1)">Nej</a>
<br />
<br />
<?php
print "<strong>".$kon['header']."</strong><br />";
print "<i>Du kan vinde ".$kon['win']."</i><br /><br />";
print $kon['about']."<br /><br />";
print "Hendvendelse: ".$kon['by'];

}
}
} else {
?>
<table style="width:700px;" class="blackborder" cellpadding="1" cellspacing="0">
 <tr>
  <td style="border-bottom:1px solid #000;background-color:#CEC;">
  <strong>Overskrift</strong>
  </td>
  <td style="border-bottom:1px solid #000;background-color:#CEC;">
  <strong>Præmie</strong>
  </td>
 </tr>
<?php
$getchallenges = mysql_query("SELECT * FROM `pytox_konkurrencer` ORDER BY `id` DESC");

while($challenge = mysql_fetch_array($getchallenges)) {
if ($color == "#FFF") {
$color = "#EEE";
} else {
$color = "#FFF";
}
?>
 <tr>
  <td style="background-color:<?=$color?>;">
  <a href="?site=Adkonkurrencer&amp;choose=del&amp;action=true&amp;id=<?=$challenge['id']?>"><?=$challenge['header']?></a>
  </td>
  <td style="background-color:<?=$color?>;">
  <?=$challenge['by']?>
  </td>
 </tr>
<?php
}
?>
</table>
<?php
}

///////////////////////DEL
} else {
print "Vælg en af ovenstående muligheder..";
}
?>
<?php

/////////////////////////
	} else {// $admin[exist]
	header("Location: index.php?message=failure&errorid=60065");
	}

 }

}

}
?>