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égories, il vous suffit de cliquer sur la caté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&start=$start&id=pigeons&by=$key&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&id=pigeons&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&id=pigeons&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&id=pigeons&by=$by&order=$order&start=".($start-5)."\">Les cinq précédents</a>";
}
if ($start+5 < $row{0})
{
echo "<a href=\"?page=perso&id=pigeons&by=$by&order=$order&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&id=pigeons&article=$id\" method=\"post\">
<h4>Bague <input type=\"text\" name=\"bague\" value=\"".$row{'bague'}."\" /></h4>
<p>Ce pigeon a été mis en liberté le <input type=\"text\" name=\"date\" value=\"".$row{'date'}."\" /></p>
<dl>
<dt>Descriptif du père</dt>
<dd>
<textarea name=\"pere\" rows=\"5\" cols=\"80\">";
print $row{'pere'};
print "
</textarea>
</dd>";
echo "<dt>Descriptif de la mè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é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é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éjà portée par quelqu' un d'autre !</p>"; }
echo "<p>Modifications effectué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éjà portée par quelqu' un d'autre !</p>"; }
echo "<p>Modifications effectuées</p>";
}
}