<? //;
$page = "chandelles";
include "lib.php3";
include "entete.php3";
$num_candles = getNumberOfCandles();
print "$num_candles chandelles brillent maintenant pour Nadia!<BR>\n";
print "<BR>\n";
print "<CENTER>Un instant svp... le t&eacute;l&eacute;chargement des chandelles peut &ecirc;tre long!</CENTER>\n";
print "<BR>";
print "<A HREF=\"drapeaux.phtml\">Drapeaux</A><BR>\n";

if($start == "")
  $start = 1;
if($pagelength == "")
  $pagelength = 24;
if($rowlength == "")
  $rowlength = 8;
if($pagelength < $rowlength)
  $rowlength = $pagelength;

$Query = "SELECT c.Chandelle_id,c.Prenom,c.Nom_famille,p.nom,p.logo,c.logo as clogo,c.important 
	FROM Chandelles c, pays p
	WHERE p.pays_id=c.pays_id ";

if($pays_id != "")
    $Where[] = " c.pays_id=$pays_id ";
if($cree_le != "")
    $Where[] = " c.cree_le='$cree_le' ";
if($range_1 != "" && $range_2 != "")
    $Where[] = " c.cree_le>='$range_1' AND c.cree_le<='$range_2' ";
if($logo != "")
    $Where[] = " c.logo='$logo' ";

if($Where) {
    $Query .= " AND ".join(" AND ",$Where)." ";
}

$Query .= " order by c.Chandelle_id";
$sth = mysql_db_query($DBname,$Query);
if(!$sth) {
    print "Error querying DB (".mysql_error().")!<BR>";
} else {	
    $numrows = mysql_num_rows($sth);
    if(($start+$pagelength) > $numrows)	
	$end = $numrows;
    else 
	$end = (($start-1)+$pagelength);
    print "<TABLE BORDER=0>\n";
    print "<TR><TD ALIGN=CENTER COLSPAN=$rowlength>Chandelle #$start &agrave; #".$end." de $numrows</TD></TR>\n";
	$i = 0;
    while(($row = mysql_fetch_object($sth)) && ($i < $end)) {
	if($i < ($start-1)) {
	    $i++;
	    // if(($i+$rowlength) > ($start-1)) {
		// if($i % $rowlength == 0) {print "<TR>\n"; $started=1;}
		// else if($started) print "<TD>&nbsp;</TD>\n";
		// }
	    continue;
	    }
	if($showing % $rowlength == 0) {
	    print "<TR>\n";
	}
	print "<TD><CENTER><IMG SRC=\"images/".$row->clogo;
	print "\" BORDER=0 WIDTH=43 HEIGHT=80><BR>";
	if($row->important == 1)
	    print "<FONT SIZE=+1><B>";
	print $row->Prenom."<BR>".$row->Nom_famille;
	if($row->important == 1)
	    print "</FONT></B>";
	print "<BR>";
	print "<IMG SRC=\"images/".$row->logo."\" ALT=\"";
	print $row->nom."\" BORDER=0 WIDTH=42 HEIGHT=26></CENTER></TD>\n";
	if($showing % $rowlength == ($rowlength-1)) {
	    print "</TR>\n";
	}
	$i++;
	$showing++;
    }
    if($showing % $rowlength != 0) {
	for ($x = ($showing % $rowlength); $x <= ($rowlength-1); $x++) {
	    print "<TD>&nbsp;</TD>";
	}
	print "</TR>\n";
    }
    print "<TR><TD COLSPAN=$rowlength><TABLE WIDTH=100%<MTR><TD ALIGN=LEFT>";
    if($i-(($pagelength-($start-1))*2) >= 0) {
	if($i-($pagelength*2) < 0) $pi=($pagelength*2);
	else $pi = $i;
	print "<A HREF='chandelles.phtml?start=".($pi-($pagelength*2))."&pagelength=$pagelength";
	if($pays_id != "")
	    print "&pays_id=$pays_id";
	print "'>";
	print "Page pr&eacute;c&eacute;dente</A>";
    } else print "Page pr&eacute;c&eacute;dente";
    print "</TD>";
    print "<TD ALIGN=RIGHT>";
    $i++;
    if($i <= $numrows) {
	print "<A HREF='chandelles.phtml?start=$i&pagelength=$pagelength";
	if($pays_id != "")
	    print "&pays_id=$pays_id";
	print "'>";
	print "Page suivante</A>";
    } else print "Page suivante";
    print "</TD>";
    print "</TR></TABLE></TD></TR>";
    print "</TABLE>\n";
}
include "basdepage.php3";
?>
