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

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

$loggedony = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$_COOKIE[user]}' ORDER BY `id` ASC");
$yzx = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$_COOKIE[user]}' ORDER BY `id` ASC");
$adminlogon = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$_COOKIE[user]}' ORDER BY `id` ASC");
$whulla = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$_COOKIE[user]}' ORDER BY `id` ASC");

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

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

if ($admin["admin"] == "1" || $admin["admin"] == "2" || $admin["admin"] == "3") {
print "<a href=\"?site=Chat&amp;choose=admin\">Administrer chatten</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") {


while($mister = mysql_fetch_array($whulla)) {

 if ($mister["admin"] == "1" || $mister["admin"] == "2" || $mister["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>";
  print "<br /><br />";
  print "<a href=\"?site=Chat\">Fortryd (vend tilbage til chatten)</a>";
  }
 }
 
 }

 
 } else {

 //print "<i>Chatten indeholder potentielle fejl, da BASF retter på systemet!</i><br /><br />";
 
if (mysql_num_rows($loggedony) == "1") {
//print "1";
while ($onlog = mysql_fetch_assoc($yzx))
{
//print "2";
if ($_COOKIE['pass'] == $onlog['kode']) {
if ($onlog['exist'] == 1) {
?>
<form action="?site=Chat&new=true" method="post">
Bruger: <input type="text" value="<?php print $_COOKIE["user"];?>" disabled="disabled" />
<br />
Besked: <input class="small" name="message" style="width:310px;" />
<br />
<input type="submit" name="submit" value="Send besked" class="submit" />
</form>
<?php
	} else {
	header("Location: index.php?message=failure&errorid=60065");
	}//slutter exist-tjek
	} //cookie-tjek
}//while
} else {
print "<i>Du skal være logget ind, før du kan skrive beskeder i chatten!";
}
?>
<br />
<br />
<script type="text/javascript">
//getSite('chatcontent');
</script>
<input type="button" name="Update" value="Opdater tagwall" onClick="window.location.reload();" class="submit" />
<br />
<div id="loader"  style="float:left;display:none;"><img src="ajax-loader.gif" alt="Loading" /></div>
<br />
<!--<div id="chatcontent">
</div>-->
<?php
include("../../sites/chatcontent.php");
?>
<?php	
}
?>