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

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

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

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

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

if ($admin["admin"] == "1" || $admin["admin"] == "2" || $admin["admin"] == "3") {
print "<a href=\"?site=Chat&amp;choose=admin\">Administrer tagwallen</a><br /><br />";
}


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

if ($_POST["message"] != "") {

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

mysql_query("INSERT INTO `pytox_chat` (`id`, `ip`, `show`, `user`, `message`, `time`) VALUES ('', '{$_SERVER[REMOTE_ADDR]}', '1', '{$_COOKIE[user]}', '{$replace[message]}', '{$tid}')") or die(mysql_error());

header("Location: index.php?site=Chat");

} else {
print "Du mangler at skrive en besked!";
}

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

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

mysql_query("UPDATE `pytox_chat` SET `show` = '0'");
header("Location: index.php?site=Chat");

  } else {
  print "<a href=\"?site=Chat&amp;choose=admin&amp;do=toem\">Tøm tagwallen</a>";
  }
 }

} else {

?>
<form action="?site=Chat&new=true" method="post">
Bruger: <input type="text" value="<?php print $_COOKIE["user"];?>" disabled="disabled" />
<br />
Besked: <textarea class="small" name="message" style="width:310px;height:15px;"></textarea>
<br />
<input type="submit" name="submit" value="Send besked" class="submit" />
</form>
<br />
<br />
<input type="button" name="Update" value="Opdater tagwall" onClick="document.location.reload();" class="submit" />
<br />
<br />
<table cellpadding="2" cellspacing="0" class="blackborder" style="width:480px;">
<?php
$chatten = mysql_query("SELECT * FROM `pytox_chat` WHERE `show` LIKE '1' ORDER BY `id` DESC");

while($chat = mysql_fetch_array($chatten)) {
?>
 <tr>
  <td style="border-bottom : 1px dashed #000;">
<a href="?site=Com.user&amp;user=<?php print $chat[user];?>"><?php print $chat[user];?></a> - <?php print $chat[time];?>
<br />
<?php print $chat[message];?>
  </td>
 </tr>
<?php
}
?>
</table>
<?php	
}

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

}//slutter cookie-tjek

}//slutter while
?>