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

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

$users = mysql_query("SELECT * FROM `pytox_community` ORDER BY `bruger` ASC"); 

if ($_COOKIE[pass] == $check_logon_com[kode] && $_COOKIE[com] == "1") {

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

//mysql forbindelser

$pmail_inbox = mysql_query("SELECT * FROM `pytox_post` WHERE `til` LIKE '$_COOKIE[user]' AND `show` LIKE '1' ORDER BY `id` DESC");
$pmail_sent = mysql_query("SELECT * FROM `pytox_post` WHERE `fra` LIKE '$_COOKIE[user]' AND `show` LIKE '1' ORDER BY `id` DESC");

//mysql forbindelser slut
?>
<a href="?site=Post">Indbakke</a> | <a href="?site=Post&choose=sent">Sendte beskeder</a> | <a href="?site=Pmail">Send en P-mail</a> | <a href="?site=Support&amp;support=pmail">Pmail?</a>
<br />
<br />
<?php
if ($_GET["choose"] == "thatmail" && isset($_GET[id])) {

//mysql forbindelser
$that_pmail = mysql_query("SELECT * FROM `pytox_post` WHERE `id` LIKE '{$_GET[id]}' LIMIT 1");
$that_sent = mysql_query("SELECT * FROM `pytox_post` WHERE `id` LIKE '{$_GET[id]}' LIMIT 1");
//mysql forbindelser slut

///////////////////////////////
if ($_GET["type"] == "sent") {



while ($pmail_showsent = mysql_fetch_array($that_sent)) {

if ($pmail_showsent[fra] == $check_logon_com[bruger]) {

?>
<strong>Til:</strong> <a href="?site=Com.users&user=<?php print $pmail_showsent[til];?>"><?php print $pmail_showsent[til];?></a>, <strong>Afsendelsestid:</strong> <?php print $pmail_showsent[tid];?>
<br />
<br />
<strong>Emne:</strong> <?php print $pmail_showsent[emne];?>
<br />
<br />
<br />
<?php
$admin[tjek2] = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$pmail_showsent[fra]}' LIMIT 1");
while($tjadmin = mysql_fetch_array($admin[tjek2])) {
	if ($tjadmin[admin] != "1") {
print strip_tags($pmail_showsent[besked], "<b><strong><u><i>");
	} else {
print $pmail_showsent[besked];
	}
}

} else {

print "Du kan kun læse din egen post!";

}

}//slutter while




} else {
while ($pmail_showthat = mysql_fetch_array($that_pmail)) {

if ($pmail_showthat[til] == $check_logon_com[bruger]) {

if ($pmail_showthat[show] == "1") {

$useridet = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$pmail_showthat[fra]}' LIMIT 1");

while ($idet = mysql_fetch_array($useridet)) {
?>
<strong><a href="?site=Pmail&amp;emne=<?php print $pmail_showthat[emne];?>&amp;touser=<?php print $idet[id];?>">Svar</a></strong>
<?php
}
?>
<br />
<br />
<?php
$userid = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$pmail_showthat[fra]}' LIMIT 1");

while ($id = mysql_fetch_array($userid)) {
?>
<strong>Fra:</strong> <a href="?site=Com.users&userid=<?=$id[id]?>"><?php print $pmail_showthat[fra];?></a>, <strong>Afsendelsestid:</strong> <?php print $pmail_showthat[tid];?>
<?php
}
?>
<br />
<br />
<strong>Emne:</strong> <?php print $pmail_showthat[emne];?>
<br />
<br />
<br />
<?php
$admin[tjek] = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$pmail_showthat[fra]}' LIMIT 1");
while($tadmin = mysql_fetch_array($admin[tjek])) {
	if ($tadmin[admin] != "1") {
print strip_tags($pmail_showthat[besked], "<b><strong><u><i>");
	} else {
print $pmail_showthat[besked];
	}
}

mysql_query("UPDATE `pytox_post` SET  `laest` = '1' WHERE `id` LIKE '{$_GET[id]}' LIMIT 1");

} else {

print "Denne besked er slettet, og den kan dermed ikke læses!<br />";

}

} else {

print "Du kan kun læse din egen post!";

}

}//slutter while

}
/////////////////////////

} else if ($_GET[choose] == "slet" && isset($_GET[id])) {
$del_pmail = mysql_query("SELECT * FROM `pytox_post` WHERE `id` LIKE '{$_GET[id]}' LIMIT 1");

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

mysql_query("UPDATE `pytox_post` SET  `show` = '0' WHERE `id` LIKE '{$_GET[id]}' LIMIT 1") or die(mysql_error());

print "Beskeden er nu slettet!";

} else {

///////////////////////////////
while ($pmail_showdel = mysql_fetch_array($del_pmail)) {
?>
Er du sikker på, at du vil fjerne følgende besked fra indbakken?: <a href="?site=Post&amp;choose=slet&amp;id=<?php print $_GET[id];?>&amp;del=true">Ja!</a> - <a href="?site=Post">Nej!</a>
<br />
<br />
<?php
if ($pmail_showdel[til] == $check_logon_com[bruger]) {

if ($pmail_showdel[show] == "1") {
?>
<strong>Fra:</strong> <a href="?site=Com.users&user=<?php print $pmail_showdel[fra];?>"><?php print $pmail_showdel[fra];?></a>, <strong>Afsendelsestid:</strong> <?php print $pmail_showdel[tid];?>
<br />
<br />
<strong>Emne:</strong> <?php print $pmail_showdel[emne];?>
<br />
<br />
<?php print $pmail_showdel[besked];?>
<?php
//mysql_query("UPDATE `pytox_post` SET  `laest` = '1' WHERE `id` LIKE '{$_GET[id]}' LIMIT 1");

} else {

print "Denne besked er slettet, og den kan dermed ikke slettes!<br />";

}

} else {

print "Du kan kun slette din egen post!";

}

}

}
/////////////////////////

} else if ($_GET["choose"] == "sent") {
////////////////
?>
<table style="width:650px;" cellpadding="2" cellspacing="0" class="blackborder">
 <tr>
  <td style="width:200px;background-color:#EEE;border-bottom:1px solid #000;">
<strong>Emne</strong>
  </td>
  <td style="width:150px;border-bottom:1px solid #000;">
<strong>Modtager</strong>
  </td>
  <td style="width:200px;background-color:#EEE;border-bottom:1px solid #000;">
<strong>Afsendelsestid</strong>
  </td>
  <td style="width:100px;background-color:#FFF;border-bottom:1px solid #000;">
<strong>Valg:</strong>
  </td>
 </tr>
<?php
if (mysql_num_rows($pmail_sent) == 0) {
?>
 <tr>
  <td style="width:200px;background-color:#EEE;">
ingen
  </td>
  <td style="width:150px;">
ingen
  </td>
  <td style="width:200px;background-color:#EEE;">
ingen
  </td>
  <td style="width:100px;background-color:#FFF;">
ingen
  </td>
 </tr>
<?php
} else {

while ($pmail_sent_show = mysql_fetch_array($pmail_sent)) {
?>
 <tr>
  <td style="width:200px;background-color:#EEE;">
<?php
if ($pmail_sent_show[laest] == "0") {
print "<strong>";
}
?>
<a href="?site=Post&amp;choose=thatmail&amp;type=sent&amp;id=<?php print $pmail_sent_show[id];?>"><?php print $pmail_sent_show[emne];?></a>
<?php
if ($pmail_sent_show[laest] == "0") {
print "</strong>";
}
?>
  </td>
  <td style="width:150px;">
<a href="?site=Com.users&amp;user=<?php print $pmail_sent_show[til];?>"><?php print $pmail_sent_show[til];?></a>
  </td>
  <td style="width:200px;background-color:#EEE;">
<?php print $pmail_sent_show[tid];?>
  </td>
  <td style="width:100px;background-color:#FFF;">
Ingen
  </td>
 </tr>
<?php
}
}
?>
</table>
<?php
////////////////
} else {
?>
<br />
<table style="width:650px;" cellpadding="2" cellspacing="0" class="blackborder">
 <tr>
  <td style="width:200px;background-color:#EEE;border-bottom:1px solid #000;">
<strong>Emne</strong>
  </td>
  <td style="width:150px;border-bottom:1px solid #000;">
<strong>Afsender</strong>
  </td>
  <td style="width:200px;background-color:#EEE;border-bottom:1px solid #000;">
<strong>Afsendelsestid</strong>
  </td>
  <td style="width:100px;background-color:#FFF;border-bottom:1px solid #000;">
<strong>Valg:</strong>
  </td>
 </tr>
<?php
if (mysql_num_rows($pmail_inbox) == 0) {
?>
 <tr>
  <td style="width:200px;background-color:#EEE;">
ingen
  </td>
  <td style="width:150px;">
ingen
  </td>
  <td style="width:200px;background-color:#EEE;">
ingen
  </td>
  <td style="width:100px;background-color:#FFF;">
  </td>
 </tr>
<?php
} else {

while ($pmail_show = mysql_fetch_array($pmail_inbox)) {
?>
 <tr>
  <td style="width:200px;background-color:#EEE;">
<?php
if ($pmail_show[laest] == "0") {
print "<strong>";
}
?>
<a href="?site=Post&amp;choose=thatmail&amp;id=<?php print $pmail_show[id];?>"><?php print $pmail_show[emne];?></a>
<?php
if ($pmail_show[laest] == "0") {
print "</strong>";
}
?>
  </td>
  <td style="width:150px;">
<?php
$useriid = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$pmail_show[fra]}' LIMIT 1");

while ($iid = mysql_fetch_array($useriid)) {
?>
<a href="?site=Com.users&amp;userid=<?=$iid[id]?>"><?php print $pmail_show[fra];?></a>
<?php
}
?>
  </td>
  <td style="width:200px;background-color:#EEE;">
<?php print $pmail_show[tid];?>
  </td>
  <td style="width:100px;background-color:#FFF;">
<?php
$useriid2 = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$pmail_show[fra]}' LIMIT 1");

while ($iid2 = mysql_fetch_array($useriid2)) {
?>
<a href="?site=Pmail&amp;emne=<?php print $pmail_show[emne];?>&amp;touser=<?php print $iid2[id];?>">Svar</a> - <a href="?site=Post&amp;choose=slet&amp;id=<?php print $pmail_show[id];?>">Slet</a>
<?php
}
?>
  </td>
 </tr>
<?php
}
}
?>
</table> 
<?php
}

	} else {//exist
	header("Location: index.php?message=failure&errorid=60065");
	}//exist
}//cookies
}//whilen
?>