<?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"] == "2") {

	if ($admin["exist"] == "1") {
$eradmin = 1;
	}
 }
}
}
if ($_GET[opret] == "true") {

if ($_POST["besked"] != "" && $_POST["submit"] == "Skriv!" && isset($_COOKIE[user])) {

 if ($_POST["validate"] != $_SESSION[tjekcode]) {
print "<div style=\"color:#F00;\">Valideringskoden er ugyldig!</div>";
 } else {

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

$userrights = mysql_query("SELECT * FROM `pytox_community`  WHERE `bruger` LIKE '{$_COOKIE[user]}' LIMIT 1");
while ($rights = mysql_fetch_array($userrights)) {
if ($rights[admin] != "1") {
$replace["besked"] = strip_tags($replace["besked"], "<b><u><i><strong>");
}
}

mysql_query("INSERT INTO `pytox_tagwall` (`id`, `ip`, `user`, `message`, `time`) VALUES ('', '$_SERVER[REMOTE_ADDR]', '$_COOKIE[user]', '$replace[besked]', '$tid')");


header("Location: index.php?site=Tagwall&message=newtagcorrect");

 }

} else {
header("Location: index.php?message=failure&errorid=27173");
}
} else if ($_GET['choose'] == "del" && $_GET['id'] != "") {
$deleting = mysql_query("DELETE FROM `pytox_tagwall` WHERE `id` LIKE '{$_GET['id']}' LIMIT 1");

if ($deleting == "1") {
header("Location: index.php?site=Tagwall");
} else {
print "Der opstod en fejl, tag'et blev ikke slettet!";
}
} else {
?>
<?php

while($check_logon_com = mysql_fetch_array($db_community)) {

if ($_COOKIE[pass] == $check_logon_com[kode] && $_COOKIE[com] == "1") {
?>
<br />
<center><form action="?site=Tagwall&opret=true" method="post">
Besked:
<br />
<textarea cols="30" rows="10" name="besked"></textarea>
<br />
<input type="submit" name="submit" value="Skriv!" class="submit" />
</form>
<?php
} else if (mysql_num_rows($db_community) == 0) {
print "Du skal være logget på, før du kan se communityet!";
} else {
print "Du skal være logget på, før du kan se communityet!";
}
}
?><center>
  <td>
<br />
<?php
}
?>
<?php
/* APOLTIX CODE */
$query['tagwall_numbers'] = mysql_query("SELECT * FROM `pytox_tagwall` ORDER BY `id` DESC");
$query['tagwall_numbers_show'] = mysql_query("SELECT * FROM `pytox_tagwall` WHERE `user` NOT LIKE 'Pytox - bot' ORDER BY `id` DESC");

$pgLimit = 20;


if ( empty($_GET["start"]) || !is_numeric($_GET["start"]) ) {
	$check["limit"] = "LIMIT " . $pgLimit;
} elseif ( is_numeric($_GET["start"]) ) {
	if ( $_GET["start"] < mysql_num_rows($query["tagwall_numbers"]) && $_GET["start"] > 1 ) {
		$start = $pgLimit * $_GET["start"] - $pgLimit;
		$check["limit"] = "LIMIT " . $start . " , " . $pgLimit;
	} else {
		$check["limit"] = "LIMIT " . $pgLimit;
	}
}
$articles_on_page = 0;

$query['tagwall'] = mysql_query("SELECT * FROM `pytox_tagwall` ORDER BY `id` DESC {$check['limit']}");
/* END APOLTIX CODE */

if (mysql_num_rows($query['tagwall_numbers_show']) == 0) {
$antal = "ingen";
$text = "beskeder";
} else if (mysql_num_rows($query['tagwall_numbers_show']) == 1) {
$antal = mysql_num_rows($query['tagwall_numbers_show']);
$text = "besked";
} else if (mysql_num_rows($query['tagwall_numbers_show']) > 1) {
$antal = mysql_num_rows($query['tagwall_numbers_show']);
$text = "beskeder";
}

print "<div class=\"small\" style=\"font-weight:bold;display:inline;\">Der er i øjeblikket ".$antal." ".$text." i tagwallen. <i>(Beskeder fra Pytox-botten medtælles ikke!)</i></div><br /><i>(".mysql_num_rows($query['tagwall_numbers'])." med Pytox-botten)</i><br />";
?>
<br />
<br />

<?php
/* APOLTIX CODE */
?>
<div style="text-align:center;">
Side <?php
$chooseno_of_pg = mysql_num_rows($query['tagwall_numbers']);
$no_of_pages = ceil($chooseno_of_pg / $pgLimit);
$currentPage = is_numeric($_GET["start"]) ? $_GET["start"] : "1";
print $currentPage . " af " . $no_of_pages . "<br />";
$page_select_nr = 1;
while($page_select_nr <= $no_of_pages) {
	if ( $_GET["start"] == $page_select_nr || ( empty($_GET["start"]) && $page_select_nr == 1 ) ) {
		print "<strong>";
	} else {
		$thelink = $_SERVER["PHP_SELF"];//preg_replace("/(\?|\&)start=([0-9]{0-100}|[A-Z]|[a-z]|[0-9])/", "", $_SERVER["REQUEST_URI"]);
		print "<a href=\"{$thelink}?site=Tagwall&amp;start={$page_select_nr}\">";
	}
	print $page_select_nr;
	if ( $_GET["start"] == $page_select_nr || ( empty($_GET["start"]) && $page_select_nr == 1 ) ) {
		print "</strong>";
	} else {
		print "</a>";
	}
	print " ";
	$page_select_nr++;
} // Ends while
?>
</div>
<?php
/* END APOLTIX CODE */
?>
<br />
<input type="button" name="Update" value="Opdater tagwall" onClick="document.location.reload();" class="submit" />
<br />
<br />
<?php

while($tagwall = mysql_fetch_array($query['tagwall'])) {
?>
<div class="tag">
<strong>
<?php
$tagwall[message] = str_replace(":S", "<img src=\"../gfx/smileys/S.GIF\" alt=\"S\" />", $tagwall[message]);
$tagwall[message] = str_replace(":D", "<img src=\"../gfx/smileys/D.gif\" alt=\"D\" />", $tagwall[message]);
$tagwall[message] = str_replace(":(", "<img src=\"../gfx/smileys/(.gif\" alt=\"(\" />", $tagwall[message]);
$tagwall[message] = str_replace(":)", "<img src=\"../gfx/smileys/).gif\" alt=\")\" />", $tagwall[message]);
$tagwall[message] = str_replace(":'(", "<img src=\"../gfx/smileys/'(.gif\" alt=\"'(\" />", $tagwall[message]);
$tagwall[message] = str_replace(":P", "<img src=\"../gfx/smileys/P.GIF\" alt=\"P\" />", $tagwall[message]);

$tagwall[message] = str_replace(":s", "<img src=\"../gfx/smileys/S.GIF\" alt=\"S\" />", $tagwall[message]);
$tagwall[message] = str_replace(":d", "<img src=\"../gfx/smileys/D.gif\" alt=\"D\" />", $tagwall[message]);
$tagwall[message] = str_replace(":(", "<img src=\"../gfx/smileys/(.gif\" alt=\"(\" />", $tagwall[message]);
$tagwall[message] = str_replace(":)", "<img src=\"../gfx/smileys/).gif\" alt=\")\" />", $tagwall[message]);
$tagwall[message] = str_replace(":'(", "<img src=\"../gfx/smileys/'(.gif\" alt=\"'(\" />", $tagwall[message]);
$tagwall[message] = str_replace(":p", "<img src=\"../gfx/smileys/P.GIF\" alt=\"P\" />", $tagwall[message]);

$prevelegier = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$tagwall[user]}' LIMIT 1");

while($tambu = mysql_fetch_array($prevelegier)) {

if ($tambu[admin] == "1") {
$style = "color:#123456;";
} else if ($tambu[crew] == "1") {
$style = "color:#FFF;";
} else {
$style = "color:#000;";
}
}

$userid = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$tagwall[user]}' LIMIT 1");

if ($tagwall[user] == "Pytox - bot") {
?>
<div style="color:#EEE;display:inline;">Pytox - bot</div>
<?php
} else {

while ($id = mysql_fetch_array($userid)) {

print "<a style=\"".$style."\" href=\"?site=Com.users&amp;userid=".$id[id]."\">".$tagwall[user]."</a> - ".$tagwall[time];
}
}
?>
</strong>
<br />
<?php
$bannede = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$tagwall[user]}' LIMIT 1");

if ($tagwall[user] == "Pytox - bot") {
$tag = $tagwall[message];
} else {
while($banned = mysql_fetch_array($bannede)) {

if ($banned["admin"] == "1") {
$tag = $tagwall[message];
} else if ($banned[exist] == "1") {

$tag = strip_tags($tagwall[message], "<b><strong><u><i><img>");

} else if ($banned[exist] == "0") {

$tag = "Denne bruger er blevet deaktiveret, og hans beskeder bliver ikke vist.";
}
$articles_on_page++; // APOLTIX CODE
} // slutter while
}

print $tag;

////////////////////
////////////////////
if ($eradmin == 1) {
?>
<br />
<i>- <a href="?site=Tagwall&amp;choose=del&amp;id=<?=$tagwall['id']?>">Slet tag!</a></i>
<?php
}
////////////////////
////////////////////
?>
</div>
<br />
<br />
<?php
}
?>
<?php
/* APOLTIX CODE */
?>
<div style="text-align:center;">
Side <?php
$no_of_pages = ceil($chooseno_of_pg / $pgLimit);
$currentPage = is_numeric($_GET["start"]) ? $_GET["start"] : "1";
print $currentPage . " af " . $no_of_pages . "<br />";
$page_select_nr = 1;
while($page_select_nr <= $no_of_pages) {
	if ( $_GET["start"] == $page_select_nr || ( empty($_GET["start"]) && $page_select_nr == 1 ) ) {
		print "<strong>";
	} else {
		$thelink = $_SERVER["PHP_SELF"];//preg_replace("/(\?|\&)start=([0-9]{0-100}|[A-Z]|[a-z]|[0-9])/", "", $_SERVER["REQUEST_URI"]);
		print "<a href=\"{$thelink}?site=Tagwall&amp;start={$page_select_nr}\">";
	}
	print $page_select_nr;
	if ( $_GET["start"] == $page_select_nr || ( empty($_GET["start"]) && $page_select_nr == 1 ) ) {
		print "</strong>";
	} else {
		print "</a>";
	}
	print " ";
	$page_select_nr++;
} // Ends while
?>
</div>
<?php
/* END APOLTIX CODE */
?>
<br />
<br />
<br />
<div align="center">
<i>Tak til <a href="?site=Redirect&amp;location=http://hdmedia.dk" target="_blank">Christian Rasmussen</a>, for sideskift</i>
</div>