Tfe

Ongi etorri tfe-ren webgunera...

Old stuff/old_sites/www/include/perso/pigeons.php

(Deskargatu)
<?
if (empty($_GET['article']))
{


    $start = (empty($_GET['start']) ? 0 : preg_replace("/\D/","",$_GET['start']));
    $order = ((strcmp($_GET['order'],"desc")==0) ? "desc" : "asc");
    $norder = ((strcmp($order,"asc") == 0) ? "desc" : "asc");
    if (
       $_GET['by'] == "id" or
       $_GET['by'] == "date" or
        $_GET['by'] == "bague" or
        $_GET['by'] == "pere" or	
        $_GET['by'] == "mere" or		
        $_GET['by'] == "distance" or			
        $_GET['by'] == "note") { $by = $_GET['by']; }
    else { $by = "bague"; }
        
    $query = "SELECT * FROM mp_pigeon WHERE pseudo='".$nick."' ORDER BY $by $order LIMIT $start,5";
    $result = mysql_query($query) or die(mysql_error()."<br>$query");
    
    echo "
    <p>Pour trier les pigeons par cat&eacute;gories, il vous suffit de cliquer sur la cat&eacute;gorie voulue.</p>
    <table border=\"1\" cellspacing=\"0\">
    <tr>
    <th>Image</th>\n
    ";
    
    foreach(array("date","bague","distance","note") as $key)
	{
	echo "
	    <th><a href=\"?page=perso&amp;start=$start&amp;id=pigeons&amp;by=$key&amp;order=";
	    echo  ((strcasecmp($by,$key) == 0) ? $norder."\" class=\"selected\" " : $order."\"");
	    echo ">".$key."</a></th>
	    ";
       }    
    echo "</tr>\n";
    if (mysql_num_rows($result) == 0) { echo "<tr><td colspan=\"7\">Aucun pigeon</td></tr>\n"; }
    while ($row = mysql_fetch_assoc($result))
    {
	$row{'date'} = preg_replace("/^([0-9]{4})([0-9]{2})([0-9]{2}).*/","$3/$2/$1",$row{'date'});
	echo "<tr>
	<td><a href=\"index.php?page=perso&amp;id=pigeons&amp;article=".$row{'id'}."\"><img src=\"http://$nick.monpigeonnier.be/pigeons/".$row{'bague'}.".jpeg\" alt=\"Image du pigeon ".$row{'bague'}.".jpeg\" /></a></td>\n
	";
        foreach(array("date","bague","distance","note") as $key)
	{
	echo "\t<td class=\"center\"><a href=\"index.php?page=perso&amp;id=pigeons&amp;article=".$row{'id'}."\">".$row{$key}."</a></td>\n"; 
	}
	echo "</tr>";
	    
    }	    
    echo "</table>";
    $query = "SELECT count(id) FROM mp_pigeon WHERE pseudo='".$nick."'";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    echo "<p>";


    if ($start-5 > -1)
    {
    echo "<a href=\"?page=perso&amp;id=pigeons&amp;by=$by&amp;order=$order&amp;start=".($start-5)."\">Les cinq pr&eacute;c&eacute;dents</a>";
    }
    if ($start+5 < $row{0})
    {
    echo "<a href=\"?page=perso&amp;id=pigeons&amp;by=$by&amp;order=$order&amp;start=".($start+5)."\">Les cinq suivants</a>";
    }
    echo "</p>";
    
}
else 
{
    $id = preg_replace("/\D/","",$_GET['article']);
    
    if (empty($_POST['bague']) or
        empty($_POST['date'])
    )
    {
    $query = "SELECT * FROM mp_pigeon WHERE pseudo='".$nick."' and id='".$id."' LIMIT 1";
    $result = mysql_query($query) or die(mysql_error()."<br>$query");
    $row = mysql_fetch_assoc($result);

    $row{'date'} = preg_replace("/^([0-9]{4})([0-9]{2})([0-9]{2}).*$/","$3/$2/$1",$row{'date'});
    echo "
    <div class=\"blog\">
    <form action=\"index.php?page=perso&amp;id=pigeons&amp;article=$id\" method=\"post\">
    <h4>Bague <input type=\"text\" name=\"bague\" value=\"".$row{'bague'}."\" /></h4>
    <p>Ce pigeon a &eacute;t&eacute; mis en libert&eacute; le <input type=\"text\" name=\"date\" value=\"".$row{'date'}."\" /></p>
    <dl>
    <dt>Descriptif du p&egrave;re</dt>
    <dd>
    <textarea name=\"pere\" rows=\"5\" cols=\"80\">";
    print $row{'pere'};
    print "
    </textarea>
    </dd>";
    echo "<dt>Descriptif de la  m&egrave;re</dt>
    <dd>  <textarea name=\"mere\" rows=\"5\" cols=\"80\">";
    print $row{'mere'};
    echo "</textarea></dd>
    <dt>Distance parcourue</dt>
    <dd><input type=\"text\" name=\"distance\" value=\"".$row{'distance'}."\" /> kms</dd>
    <dt>Note du propri&eacute;taire</dt>
    <dd><input type=\"text\" name=\"note\" value=\"".$row{'note'}."\" />/20</dd>
    <dt>Validation</dt>
    <dd><input type=\"submit\" name=\"action\" value=\"Editer\" /> <input type=\"submit\" name=\"action\" value=\"Supprimer\" /> </dd>
    </form>
    ";
    
    echo "</dl>
    </div>
    ";
    }
    elseif($_POST['action'] == "Supprimer") { $query = "DELETE FROM mp_pigeon WHERE pseudo='".$nick."' and id='".$id."'"; 
    mysql_query($query) or die(mysql_error()); 	echo "<p>Modifications effectu&eacute;es</p>";	
    }
    elseif (ereg("^([0-9]){2}\/([0-9]{2})\/([0-9]{4})$",$_POST['date'],$regs))
    {
	$query = "UPDATE mp_pigeon set date='".text2html($_POST['date'])."',
					pere='".text2html($_POST['pere'])."',
	                                mere='".text2html($_POST['mere'])."',
	                                bague='".text2html($_POST['bague'])."',					
	                                note='".text2html($_POST['note'])."',										
	                                distance='".text2html($_POST['distance'])."' WHERE pseudo='".$nick."' and id='".$id."'";
	mysql_query($query) ;
	if (mysql_affected_rows() == -1) {  echo "<p>erreur identifiant: la bague est d&eacute;j&agrave; port&eacute;e par quelqu' un d'autre !</p>"; }	
	echo "<p>Modifications effectu&eacute;es</p>";	
    }
    else
    {
	$query = "UPDATE mp_pigeon set
					pere='".text2html($_POST['pere'])."',
	                                mere='".text2html($_POST['mere'])."',
	                                bague='".text2html($_POST['bague'])."',					
	                                note='".text2html($_POST['note'])."',										
	                                distance='".text2html($_POST['distance'])."' WHERE pseudo='".$nick."' and id='".$id."'";
	echo "<p>Format de la date incorrect</p>"; 
	mysql_query($query) ;		
	if (mysql_affected_rows() == -1) {  echo "<p>erreur identifiant: la bague est d&eacute;j&agrave; port&eacute;e par quelqu' un d'autre !</p>"; }
	echo "<p>Modifications effectu&eacute;es</p>";
    }
}