<?php
include("sicherheit.php3");
include ("../dbdata.php3");


	$anzahl_pro_seite=30; 						// Wieviele Studenten auf der Seite angezeigt werden

	
	if ($zeigen_ab=="") 									// Falls die Seite ohne Parameter aufgerufen wird!
		{
		$zeigen_ab=0;
		}
	if ($order_by=="") 									// Falls die Seite ohne Parameter aufgerufen wird!
		{
		$order_by="friend_spitzname";
		}


?>
<link rel="stylesheet" href="style.css" type="text/css">
		<script type="text/javascript">
		<!--
			function r_u_sure(friend_id)
			{
			Check = confirm("Willst du deinen Freund wirklich aus der Datenbank löschen?");
				if(Check == true)
					{
					window.location.href = "command.php3?friend_id="+ friend_id +"&command=delete_friend";
					}
					esle	
					{
					// Do Nothing
					}
	
			}
//-->

</script>

<?
include("header.php3");
?> 

<div align="center">
        <p class="typobold">Freunde<P>

          <table width="450" border="0" cellspacing="0" cellpadding="0">
            <tr><td>
      	  <span class="typotext">
				Hier kannst du einen neuen Freund speichern. Du musst nur das folgende Formular ausfüllen und auf "Speichern" klicken. Wenn du einen gespeicherten Freund löschen willst, klicke auf "Löschen" neben den Eintrag des entsprechenden Freundes:
		<spam>
      	</td>
            </tr>
          </table>
              


<form name="new_friend_form" method="post" action="command.php3">
			<input type="hidden" name="command" value="new_friend">
    <table width="450" border="0" cellspacing="0" cellpadding="0" class="typotext">
      <tr> 
        <td class="typobold">Emailadresse</td>
        <td width="260" align=right> 
          <input type="text" name="friend_email" class=formtextfield>
        </td>
      </tr>
      <tr> </tr>
      <tr> 
        <td  class="typobold">Spitzname</td>
        <td width="260" align=right> 
          <input type="text" name="friend_spitzname" class=formtextfield >
        </td>
      </tr>
      <tr> 
        <td  class="typobold" height="39"></td>
        <td width="260" align=right height="46"> <a href="javascript:void(document.new_friend_form.submit())"><img src="speichern.jpg" width="109" height="24" border="0"></a></td>
      </tr>
    </table>
    <p>&nbsp;</p>
  </form>







<table border=0 cellspacing="0" cellpadding="0" class="typotext" width="450">
<tr class="typobold">
	<td>Freunde
	</td>
	<td>	
	</td>
	<td>
	</td>

</tr>

<tr>
      	<td background="grau.jpg" height="1"></td>
      	<td background="grau.jpg" height="1"></td>
      	<td background="grau.jpg" height="1"></td>
</tr>



<?
	$verbindung = mysql_connect("localhost", $dbuser, $dbpass);
	mysql_select_db($dbname, $verbindung);
	

	// Anzahl der Studenten

	$abfrage= "SELECT count(friend_id) FROM pm_friends WHERE friend_from='$user_login'";
	$erg = mysql_query ($abfrage, $verbindung); 
	$myrow = mysql_fetch_row($erg)	;
	$anzahl=$myrow[0];

	// Name aus DB holen!

	$abfrage= "SELECT friend_id, friend_email, friend_spitzname FROM pm_friends  WHERE  friend_from='$user_login' 
				ORDER BY $order_by LIMIT $zeigen_ab, $anzahl_pro_seite";

	$erg = mysql_query ($abfrage, $verbindung); 
	mysql_close($verbindung);

	
	
	// Das Zeigen der eigenlichen Datensätze
	$count=0;
	while ( $myrow = mysql_fetch_row($erg) ) {
	if ( ($count %2)==0)
		{ 
		print "<TR >";
		}
	else
		{
		print "<TR bgcolor=#C6D3E6>";
		}

	print "<TD >$myrow[1]</TD>";
	print "<TD >$myrow[2]</TD>";
	// print "<a href=command.php3?friend_id=$myrow[0]&command=delete_friend> Löschen</a>";
	print "<TD ><a href='javascript:r_u_sure($myrow[0]);'> Löschen</a></TD>";
	print "</TR>";
	$count++;
	} //while
?>
</table>


<p class="typotext">

<?
	if ($anzahl >1)
	
	{

		// Schreiben der Weiterbuttons
		$erg= (integer) ($anzahl / $anzahl_pro_seite);
		for ($count=0; $count<=$erg; $count++ )
			{
				$zeigen_ab=($count) * $anzahl_pro_seite;
				$hilfe = $count +1;
				print "<a href=freunde.php3?zeigen_ab=$zeigen_ab&order_by=$order_by>[$hilfe]</a> ";
			} // for
	} // if 

?>
</p>


</div>

<?php
include("fooder.php3");
?>