<?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["kodeord"]) {

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

	if ($admin["exist"] == "1") {
/////////////////////////
?>
<strong>Ting-administration:</strong> <a href="?site=Ting&amp;choose=add">Tilføj en ting</a> - <a href="?site=Ting&amp;choose=edit">Ret en ting</a> - <a href="?site=Ting&amp;choose=del">Slet en ting</a>
<br />
<br />
<?php
if ($_GET["choose"] == "add") {

?>
Tilføj er valgt
<br />
<br />
<?php
if ($_GET["new"] == "true") {

if ($_POST["navn"] == "" || $_POST["pris"] == "" || $_POST["level"] == "" || $_POST["lager"] == "" || $_POST["billedsti"] == "") {
print "Én eller flere felter blev ikke udfyldt!<br /><br />";
} else {
mysql_query("INSERT INTO `pytox_tingdb` (`id`, `name`, `price`, `level`, `image`, `instore`) VALUES ('', '{$_POST['navn']}', '{$_POST['pris']}', '{$_POST['level']}', '{$_POST['billedsti']}', '{$_POST['lager']}')") or die(mysql_error());
print "Tingen blev oprettet, og er nu på markedet.<br /><br />";
}

}
?>
<form action="?site=Ting&amp;choose=add&amp;new=true" method="post">
<i><strong>OBS:</strong>Alle felter skal udfyldes!</i>
<br />
<table class="blackborder" cellpadding="0" cellspacing="0" style="width:500px;">
 <tr>
  <td style="width:200px;" align="left">
Navn på ting:
  </td>
  <td style="width:300px;" align="left">
<input type="text" name="navn" />
  </td>
 </tr>
 <tr>
  <td style="width:200px;" align="left">
Pris:
  </td>
  <td style="width:300px;" align="left">
<input type="text" name="pris" />
  </td>
 </tr>
 <tr>
  <td style="width:200px;" align="left">
Krævede level:
  </td>
  <td style="width:300px;" align="left">
<input type="text" name="level" />
  </td>
 </tr>
 <tr>
  <td style="width:200px;" align="left">
På lager:
  </td>
  <td style="width:300px;" align="left">
<input type="text" name="lager" />
  </td>
 </tr>
 <tr>
  <td style="width:200px;" align="left" valign="top">
Billedesti:
  </td>
  <td style="width:300px;" align="left">
<input id="billedsti" type="text" name="billedsti" onMouseover="if(this.value == '') {document.Eksempel.src = '../gfx/eksempel_billedsti.jpg';} else {document.Eksempel.src = document.getElementById('billedsti').value;}" onMouseout="if(this.value == '') {document.Eksempel.src = '../gfx/eksempel_billedsti.jpg';} else {document.Eksempel.src = document.getElementById('billedsti').value;}"/><div style="display:block;" class="copy">Bevæg musen henover, eller væk fra feltet, hvis et eksempel ønskes</div>
  </td>
 </tr>
</table>
<br />
<br/>
<img id="Eksempel" name="Eksempel" src="../gfx/eksempel_billedsti.jpg" alt="Billedet eksisterer ikke!" title="Eksempel på billedsti vises her" />
<br />
<br />
<input type="submit" value="Opret ting!" class="submit" />
</form>
<?php

} else if ($_GET["choose"] == "edit") {

?>
Ret er valgt
<br />
<br />
<?php
if ($_GET["ret"] == true && isset($_GET[retid])) {
////////////////////////////////////////////////////
$getret = mysql_query("SELECT * FROM `pytox_tingdb` WHERE `id` LIKE '{$_GET[retid]}' LIMIT 1") or die(mysql_error());

while ($ret = mysql_fetch_array($getret)) {
?>
<form action="?site=Ting&amp;choose=edit&amp;ret=true&amp;retid=<?=$ret[id]?>&amp;check=true" method="post">
<i><strong>OBS:</strong>Alle felter skal udfyldes!</i>
<br />
<table class="blackborder" cellpadding="0" cellspacing="0" style="width:500px;">
 <tr>
  <td style="width:200px;" align="left">
Navn på ting:
  </td>
  <td style="width:300px;" align="left">
<input type="text" name="navn" value="<?=$ret[name]?>" />
  </td>
 </tr>
 <tr>
  <td style="width:200px;" align="left">
Pris:
  </td>
  <td style="width:300px;" align="left">
<input type="text" name="pris" value="<?=$ret[price]?>" />
  </td>
 </tr>
 <tr>
  <td style="width:200px;" align="left">
Krævede level:
  </td>
  <td style="width:300px;" align="left">
<input type="text" name="level" value="<?=$ret[level]?>" />
  </td>
 </tr>
 <tr>
  <td style="width:200px;" align="left">
På lager:
  </td>
  <td style="width:300px;" align="left">
<input type="text" name="lager" value="<?=$ret[instore]?>" />
  </td>
 </tr>
 <tr>
  <td style="width:200px;" align="left" valign="top">
Billedesti:
  </td>
  <td style="width:300px;" align="left">
<input id="billedsti" value="<?=$ret[image]?>" type="text" name="billedsti" onMouseover="if(this.value == '') {document.Eksempel.src = '<?=$ret[image]?>';} else {document.Eksempel.src = document.getElementById('billedsti').value;}" onMouseout="if(this.value == '') {document.Eksempel.src = '<?=$ret[image]?>';} else {document.Eksempel.src = document.getElementById('billedsti').value;}"/><div style="display:block;" class="copy">Bevæg musen henover, eller væk fra feltet, hvis et eksempel ønskes</div>
  </td>
 </tr>
</table>
<br />
<br/>
<img id="Eksempel" name="Eksempel" src="<?=$ret[image]?>" alt="Billedet eksisterer ikke!" title="Eksempel på billedsti vises her" />
<br />
<br />
<input type="submit" value="Ret ting!" class="submit" />
</form>
<?php
}
////////////////////////////////////////////////////
} else {


$allret = mysql_query("SELECT * FROM `pytox_tingdb`");
$perlinjen = 8;

	for ($i = 0;$i <= mysql_num_rows($allret);$i = $i+$perlinjen) {

$query = "SELECT * FROM `pytox_tingdb` ORDER BY `name` ASC LIMIT ".$i.", ".$perlinjen;
$retall = mysql_query($query) or die(mysql_error());

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

 
if ($o == 0) {
$o = 1;
$bgcoloren = "#CCC";
} else if ($o == 1) {
$o = 0;
$bgcoloren = "#FFF";
} else {
$o = 1;
$bgcoloren = "#CCC";
}

?>
<div style="display:inline;background-color:<?=$bgcoloren?>;"><a href="?site=Ting&amp;choose=edit&amp;ret=true&amp;choose=ret&amp;retid=<?=$ret[id]?>"><?=$ret[name]?></a></div>, 
<?php
}
print "<br /><br />";
}
?>
<?php

} else if ($_GET["choose"] == "del") {

?>
Slet er valgt
<br />
<br />
<i><strong>OBS:</strong> Tryk for at slette!</i>
<br />
<br />
<?php
if ($_GET["delete"] == "true" && isset($_GET["delid"])) {

if ($_GET["check"] == "true") {

mysql_query("DELETE FROM `pytox_tingdb` WHERE `id` LIKE '{$_GET['delid']}' LIMIT 1") or die(mysql_error());

print "Tingen blev slettet!<br /><br />";

} else {

$getthingdel = mysql_query("SELECT * FROM `pytox_tingdb` WHERE `id` LIKE '{$_GET[delid]}' LIMIT 1") or die(mysql_error());

 while ($suredel = mysql_fetch_array($getthingdel)) {
?>
Er du SIKKER på, at du vil slette tingen '<?=$suredel[name]?>'?
<br />
<br />
<a href="?site=Ting&amp;choose=del&amp;delete=true&amp;delid=<?=$_GET[delid]?>&amp;check=true">Ja!</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="?site=Ting&amp;choose=del">Nej!</a>
<br />
<br />
<?php
 }
}

}


$all = mysql_query("SELECT * FROM `pytox_tingdb`");
$perlinje = 8;

	for ($i = 0;$i <= mysql_num_rows($all);$i = $i+$perlinje) {

$query = "SELECT * FROM `pytox_tingdb` ORDER BY `name` ASC LIMIT ".$i.", ".$perlinje;
$delall = mysql_query($query) or die(mysql_error());

while ($del = mysql_fetch_array($delall)) {

if ($u == 0) {
$u = 1;
$bgcolor = "#CCC";
} else if ($u == 1) {
$u = 0;
$bgcolor = "#FFF";
} else {
$u = 1;
$bgcolor = "#CCC";
}

?>
<div style="display:inline;background-color:<?=$bgcolor?>;"><a href="?site=Ting&amp;choose=del&amp;delete=true&amp;delid=<?=$del[id]?>"><?=$del[name]?></a></div>, 
<?php
}
print "<br /><br />";
}
?>
<?php

} else {

print "V&aelig;lg en mulighed øverst";

}

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

 }

}

}
?>