<?php
session_start();
error_reporting(0);

/*****************************************************************************************
                        Artiphp Velocity 3.0.2 - ArtiGalerie
               copyright : Ronald Guérin - webmaster@artiloo.com
                             http://www.artiloo.com
                       Dernière mise à jour : 20 octobre 2004
******************************************************************************************/

/*****************************************************************************************
 Artiphp, portail CMS pour la création de sites dynamiques 

 Copyright (C) 2003 Ronald Guérin - webmaster@artiloo.com 

 Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier 
 conformément aux dispositions de la Licence Publique Générale GNU, telle que publiée 
 par la Free Software Foundation ; version 2 de la licence, ou encore (à votre choix) 
 toute version ultérieure. 

 Ce programme est distribué dans l'espoir qu'il sera utile, mais SANS AUCUNE GARANTIE ; 
 sans même la garantie implicite de COMMERCIALISATION ou D'ADAPTATION A UN OBJET PARTICULIER. 
 Pour plus de détail, voir la Licence Publique Générale GNU . 

 Vous devez avoir reçu un exemplaire de la Licence Publique Générale GNU en même temps que 
 ce programme ; si ce n'est pas le cas, écrivez à la Free Software Foundation Inc., 
 675 Mass Ave, Cambridge, MA 02139, Etats-Unis. 

 Pour plus d'informations sur Artiphp :
 http://www.artiloo.com - webmaster@artiloo.com
******************************************************************************************/

//connection à la base
//--------------------
  include("../artzone/connect.php");
  include("../outils/identification2.php");   //  zone membre
  include("../outils/identimprime.php");

//Définition module
//-----------------
  $mod_present="Galerie";


// langue
//--------------------
  if ($_SESSION['SESSION_IDSKIN']) {
  } else {
  include("../outils/donneeSkin.php"); 
  }
  $SESSION_LANGSKIN=$_SESSION['SESSION_LANGSKIN'];
  include("../langages/$SESSION_LANGSKIN/index.php");


//dictionnaire specifique au module
  include("../langages/$SESSION_LANGSKIN/galerie.php");


// autorisation
//--------------------
  $requete="select visumodule from ".$extension."module where nomModule='Galerie'";
  $result=mysql_query($requete, $link);
   $autorisation=mysql_fetch_object($result);

  $SESSION_STATUT=$_SESSION['SESSION_STATUT'];

   if ($autorisation->visumodule=='1') {
     if ($SESSION_STATUT!="artadmin" && $SESSION_STATUT!="auteurqal" && $SESSION_STATUT!="auteur" && $SESSION_STATUT!="inscrit") {  
     header("Location: ../outils/erreur.php?ec=2");
     exit();
     }
   } elseif ($autorisation->visumodule=='2') {
     if ($SESSION_STATUT!="artadmin" && $SESSION_STATUT!="auteurqal" && $SESSION_STATUT!="auteur") {  
     header("Location: ../outils/erreur.php?ec=2");
     exit();
     }
   } elseif ($autorisation->visumodule=='3') {
     if ($SESSION_STATUT!="artadmin" && $SESSION_STATUT!="auteurqal") {  
     header("Location: ../outils/erreur.php?ec=2");
     exit();
     }
   } elseif ($autorisation->visumodule=='4') {
     if ($SESSION_STATUT!="artadmin") {  
     header("Location: ../outils/erreur.php?ec=2");
     exit();
     }
   }



  $idcat=$_GET['idcat'];
  $page=$_GET['page'];
  $limit=$_GET['limit'];

  $idcat = intval($idcat);
  $page = intval($page);
  $limit = intval($limit);

/***************************************************/
/* affichage de 8 images miniatures par categorie */
/***************************************************/

if ($idcat) {

  //pagination le limit défini le nombre d'enregistrement par page
  //---------------------------------------------------------------

  if (!($limit)) {
   $limit = 8;
  } 
  if (!($page)) {
   $page = 0;
  }

  // comptage des enregistrements
  $requete2="select id_img from ".$extension."galerie where id_catgalerie='$idcat' and pubimg='1'";
  $results=mysql_query($requete2, $link);
  $rows=mysql_num_rows($results);

  if ($rows == 0){
    $listenews .="<p><strong><font color=\"#FF0000\" size=\"2\">$LG_NORESULT</font></strong>\n";
  }

  $pages = intval($rows/$limit); 

  if ($rows%$limit) { $pages++;} 

  $current = ($page/$limit) + 1; 

  if (($pages < 1) || ($pages == 0)) { $total = 1;} else { $total = $pages;} 

  $first = $page + 1; 

  if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) { $last = $page + $limit;} else{ $last = $rows; } 


  mysql_free_result($results);
  //--------------------------



  /** DEFINITION DE LA CATEGORIE **/

  // la catégorie
  $requete2="SELECT * FROM ".$extension."galcategorie where id_catgal='$idcat'";
  $result2=mysql_query($requete2, $link);
  $defcat=mysql_fetch_object($result2);

  $defcat->nomCatgal = stripslashes($defcat->nomCatgal);

  $entete2="<br><font class=\"grandtitre\">&nbsp;".$defcat->nomCatgal."</font>";
  $entete2 .="<p>";

   // si la categorie est une souscategorie
   if ($defcat->id_parentcatgal) {
    $nomsscat = $defcat->nomCatgal;
    $sscat="$defcat->id_catgal";
     $requete3="SELECT id_catgal, nomCatgal FROM ".$extension."galcategorie where id_catgal='$defcat->id_parentcatgal'";
     $result3=mysql_query($requete3, $link);
     $defcat1=mysql_fetch_object($result3);
      $nomcat = stripslashes($defcat1->nomCatgal);
      $cat="$defcat1->id_catgal";  

   // si la categorie n'est pas une souscategorie 
   } else { 
    $nomcat = $defcat->nomCatgal; 
    if ($defcat->verifsscat=='2') { 
      $cat="$defcat->id_catgal"; 
      $requete5="select id_catgal, nomCatgal from ".$extension."galcategorie where id_parentcatgal='$idcat'"; 
      $result5=mysql_query($requete5, $link);
 
      $entete2 .="<div class=\"Dos_catphp_sscat\">";
      $entete2 .="<font class=\"Dos_catphp_sscat\">$LG_SSCAT</font><br>";

       while ($sscatsuite=mysql_fetch_object($result5)) {

        $sscatsuite->nomCatgal = stripslashes($sscatsuite->nomCatgal);
        $entete2 .="<a href=\"cat.php?idcat=".$sscatsuite->id_catgal."\" class=\"Dos_catphp_sscat\">".$sscatsuite->nomCatgal."</a><br>\n";
       }
       $entete2 .="</div><br>";
     }
    }

/** ENTETE DE PAGE **/

  if ($sscat) {
   $entete= "<font class=\"entete\"><a href=\"../welcome/index.php\" class=\"entete\">$LG_ACCUEIL</a>/<a href=\"index.php\" class=\"entete\">$LG_GALERIE</a>/<a href=\"cat.php?idcat=$cat\" class=\"entete\">" .$nomcat."</a>/". $nomsscat."</font>\n";
  } else {
   $entete= "<font class=\"entete\"><a href=\"../welcome/index.php\" class=\"entete\">$LG_ACCUEIL</a>/<a href=\"index.php\" class=\"entete\">$LG_GALERIE</a>/" .$nomcat."</font>\n";
  }

  //----------------------------------------
  $entetepage= "<p align=\"right\"><font class=\"entetepage\">$LG_RESULPERPG \n";
  $entetepage .= "<a href=\"".$PHP_SELF."?idcat=".$idcat."&page=".$page."&limit=5\" class=\"entetepage\">5</a> | \n";
  $entetepage .= "<a href=\"".$PHP_SELF."?idcat=".$idcat."&page=".$page."&limit=10\" class=\"entetepage\">10</a> | \n";
  $entetepage .= "<a href=\"".$PHP_SELF."?idcat=".$idcat."&page=".$page."&limit=20\" class=\"entetepage\">20</a> | \n";
  $entetepage .= "<a href=\"".$PHP_SELF."?idcat=".$idcat."&page=".$page."&limit=50\" class=\"entetepage\">50</a>&nbsp;&nbsp;</font>\n";
  //-----------------------------------------

  // metatags --------------------------------
  $nCat = htmlspecialchars($nomcat);
if ($nomsscat) {
  $nCat2 = " - " . htmlspecialchars($nomsscat);
}
  $metatitle = $nCat . $nCat2;
  $nCatDes = htmlspecialchars($defcat->descCatgal);
  $metaDescription="$nCatDes";
  //-------------------------------------------



/** AFFICHAGE DES RESULTATS **/

  $page = intval($page);
  $limit = intval($limit);

  $requete="SELECT * FROM ".$extension."galerie where id_catgalerie='$idcat' and pubimg='1' order by id_img desc LIMIT $page, $limit";
  $result=mysql_query($requete, $link);

    $i = 0;
    $listedossiers .="<div class=\"Dos_cat_general2\"><table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"Dos_cat_general2\">";
    $listedossiers .= "<tr class=\"Dos_cat2\">";

while ($dossier=mysql_fetch_object($result)) {

   $dossier->titreimg = stripslashes($dossier->titreimg); //***** MODIF jimro ***** 7/6/2005
   //transformation date
   //-------------------
   $month 	= substr($dossier->dateimg, 4 ,2);
   $day 		= substr($dossier->dateimg, 6, 2);
   $year		= substr($dossier->dateimg, 0 ,4);
   $datetable="".$day."/".$month."/".$year."";

   /* AFFICHAGE DES VIGNETTES */
   /***************************/

   if ($i%4==0) $listedossiers .= "</tr><tr class=\"Dos_cat3\">";
   $i++;
//***** MODIF jimro ***** ajout du titre de chaque vignette (27/5/2005)
   $listedossiers .= "<td align=\"center\" valign=\"bottom\" class=\"Dos_cat2\"><a href=\"oeuvre.php?id_img=".$dossier->id_img."\" class=\"imgmini\"><img src=\"../galerie/mini/".$dossier->imgchemin."\" border=\"0\" class=\"imgmini\"></a><br><p><font class=\"titre\">".$dossier->titreimg."</font></p></td>\n";

  /***************************/

}

$listedossiers .="</tr></table></div>";

 //-----------------------------------------------------------------------
 // Deuxieme partie du code de pagination
 // (à modifier si vous avez d'autres données à faire circuler dans l'URL)
 //-----------------------------------------------------------------------
 if ($page != 0) { 
   $back_page = $page - $limit;
   $pagination .= "<a href=\"$PHP_SELF?idcat=".$idcat."&page=$back_page&limit=$limit\"><<</a>\n";
 }

 for ($i=1; $i <= $pages; $i++) {
   $ppage = $limit*($i - 1);
     if ($ppage == $page){
       //------
         if ($total == 1) {
           $pagination .= "";
         } else { 
         $pagination .= "<b>$i</b> \n";
         }
       //-----
     } else {
         $pagination .= "<a href=\"$PHP_SELF?idcat=".$idcat."&page=$ppage&limit=$limit\">$i</a> \n";
     }
 }

 if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { 
     $next_page = $page + $limit;
     $pagination .= "<a href=\"$PHP_SELF?idcat=".$idcat."&page=$next_page&limit=$limit\">>></a>\n";
 }

 if (! $pagination) {
         $finpag .= "<br>";
 } else {
         $debutpag .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\" class=\"entete2\"><tr class=\"entete2\"><td>";
         $debutpag .= "&nbsp;$LG_ALPAGE ";
         $finpag .= "</td></tr></table><br>";
 }
 //-------------------------------------------------------------------------




/****************************/
/* affichage des categories */
/****************************/

} else {
     header("Location: index.php");
     exit();
}



mysql_free_result($result);
//---------------------------


//------------
//presentation
//------------


$milieu="$debutpag $pagination $finpag";
$milieu .="$entete2";
$milieu .="$listedossiers";
$milieu .="$debutpag $pagination $finpag";

//feuilles de style spécifique au module
//--------------------------------------

$css .="\n<LINK TITLE=\"style\" TYPE=\"text/CSS\" rel=\"stylesheet\" HREF=\"../templates/temp$SESSION_SKIN/galerie.css\">\n";


//le template
//------------

 $SESSION_SKIN=$_SESSION['SESSION_SKIN'];
 include("../templates/temp$SESSION_SKIN/temp.html");
 echo $arti;
mysql_close();
?>