<?php
session_start();
error_reporting(0);

/*****************************************************************************************
                          Artiphp Velocity 3 - ArtiDownload
               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="Download";


// 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/download.php");


// autorisation
//--------------------
  $requete="select visumodule from ".$extension."module where nomModule='Download'";
  $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();
     }
   }

// presentation
  $downnn=$_SESSION['SESSION_PREDOWN'];

  $idcat=$_GET['idcat'];
  $page=$_GET['page'];
  $limit=$_GET['limit'];

  $idcat = intval($idcat);
  $page = intval($page);
  $limit = intval($limit);

//----------------------------------------------------------
//affichage des download par categorie (5 dossiers par page)
//----------------------------------------------------------

if ($idcat) {


  //pagination le limit défini le nombre d'enregistrement par page
  //---------------------------------------------------------------

  if (!($limit)) {
   $limit = 5;
  } 
  if (!($page)) {
   $page = 0;
  }

  // comptage des enregistrements
  $requete2="select id_download from ".$extension."download where id_cat='$idcat'";
  $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 id_categorie, id_parentcat, nomCategorie, descCat, verifsscat FROM ".$extension."categoriedown where id_categorie='$idcat'";
  $result2=mysql_query($requete2, $link);
  $defcat=mysql_fetch_object($result2);

  $defcat->nomCategorie = stripslashes($defcat->nomCategorie);

  $entete2 .="<font class=\"grandtitre\">&nbsp;".$defcat->nomCategorie."</font>";
  $entete2 .="<p>";

   // si la categorie est une souscategorie
   if ($defcat->id_parentcat) {
    $nomsscat = stripslashes($defcat->nomCategorie);
    $sscat="$defcat->id_categorie";
     $requete3="SELECT id_categorie, nomCategorie FROM ".$extension."categoriedown where id_categorie='$defcat->id_parentcat'";
     $result3=mysql_query($requete3, $link);
     $defcat1=mysql_fetch_object($result3);

      $nomcat = stripslashes($defcat1->nomCategorie);
      $cat="$defcat1->id_categorie";  

   // si la categorie n'est pas une souscategorie
   } else {
    $nomcat = stripslashes($defcat->nomCategorie);
    $cat="$defcat->id_categorie";

    if($defcat->verifsscat=='2') {
     $requete5="select id_categorie, nomCategorie from ".$extension."categoriedown where id_parentcat='$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->nomCategorie = stripslashes($sscatsuite->nomCategorie);
        $entete2 .="<a href=\"cat.php?idcat=".$sscatsuite->id_categorie."\" class=\"Dos_catphp_sscat\">".$sscatsuite->nomCategorie ."</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_DOWNTITLE</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_DOWNTITLE</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);
  $nCat2 = htmlspecialchars($nomsscat);
  $metatitle="".$nCat." - ".$nCat2."";
  $nCatDes = htmlspecialchars($defcat->descCat);
  $metaDescription="$nCatDes";
  //-------------------------------------------


/** AFFICHAGE DES RESULTATS **/

  $page = intval($page);
  $limit = intval($limit);

 $requete="SELECT * FROM ".$extension."download where id_cat='$idcat' order by dateDownload desc LIMIT $page, $limit";
 $result=mysql_query($requete, $link);
 $ix=0;

 $listedossiers="<div class=\"Dos_catphp_general\"><table width=\"100%\" class=\"Dos_catphp_general\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\">";

 while ($dossier=mysql_fetch_object($result)) {

  $dossier->titreDownload = stripslashes($dossier->titreDownload);
  $dossier->chapoDownload = stripslashes($dossier->chapoDownload);

/* ajout de tutosoft pour le poids du fichier */ 
  $poids = filesize("../download/down/".$dossier->lienDownload.""); 
  $po = $poids/1024 ; 
  $p = ceil($po) ;
/* ****************************************** */

    if ($dossier->imgDownload=="") {
     $photo="";
     } else {
     $photo="<img src=\"../images/".$dossier->imgDownload."\" align=\"left\">";
     }

  if ($downnn=="2") {

    // colonne de gauche                                                                     
    if ($ix % 2 == 0) { 
     $listedoss .= "<div class=\"Dos_catphp_titre\"><img src=\"../download/download.gif\" align=\"absmiddle\"> <a target=\"_blank\" href=\"redirec.php?id=".$dossier->id_download."\" class=\"titredos_catphp\">".$dossier->titreDownload."</a> <font class=\"datedos_catphp\">" .$dossier->dateDownvis."<br>".$LG_NBDOWNNB." ".$dossier->DnbSortie." ".$LG_DOSFOIS."  (".$p." Ko)</font></div>\n<br>".$dossier->chapoDownload;
// commenté par MDC
//     $listedoss .= "<div class=\"Dos_catphp_texte\">". $photo ."<font class=\"chapo_catphp\">" .$dossier->chapoDownload."</font></div>\n";
    // Colonne de droite                                                                     
    } else { 
     $listedoss2 .= "<div class=\"Dos_catphp_titre2\"><a target=\"_blank\" href=\"redirec.php?id=".$dossier->id_download."\" class=\"titredos_catphp\">".$dossier->titreDownload."</a> <font class=\"datedos_catphp\">" .$dossier->dateDownvis."<br>".$LG_NBDOWNNB." ".$dossier->DnbSortie." ".$LG_DOSFOIS."  (".$p." Ko)</font></div>\n<br>".$dossier->chapoDownload;
// commenté par MDC
//     $listedoss2 .= "<div class=\"Dos_catphp_texte2\">". $photo ."<font class=\"chapo_catphp\">" .$dossier->chapoDownload."</font></div>\n";
    }
    $ix++; 

  } else {

// modifié par MDC pour ajouter la description (chapoDownload)
    $listedossiers .= "<tr class=\"Dos_catphp\"><td class=\"Dos_catphp\"><div class=\"Dos_catphp_titre\"><img src=\"../download/download.gif\" align=\"right\"></td><td> <a target=\"_blank\" href=\"redirec.php?id=".$dossier->id_download."\" class=\"titredos_catphp\">".$dossier->titreDownload."</a> <font class=\"datedos_catphp\">" .$dossier->dateDownvis." - ".$LG_NBDOWNNB." ".$dossier->DnbSortie." ".$LG_DOSFOIS."  (".$p." Ko)</font></div>\n<br>".$dossier->chapoDownload."</td></tr>\n";
// commenté par MDC
//   $listedossiers .= "<div class=\"Dos_catphp_texte\">". $photo ." <font class=\"chapo_catphp\">" .$dossier->chapoDownload."</font></div></td></tr>\n";
  }
 }

  if ($downnn=="2") {
    $listedossiers .= "<tr class=\"Dos_catphp\"><td width=\"50%\" valign=\"top\" class=\"Dos_catphp\">$listedoss</td>\n";
    $listedossiers .= "<td width=\"50%\" valign=\"top\" class=\"Dos_catphp2\">$listedoss2</td></tr>\n";

  }

 $listedossiers .="</table></div><br>";


 //-----------------------------------------------------------------------
 // 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>";
 }
 //-------------------------------------------------------------------------




} 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/download.css\">\n";


//le template
//------------

 $SESSION_SKIN=$_SESSION['SESSION_SKIN'];
 include("../templates/temp$SESSION_SKIN/temp.html");
 echo $arti;
mysql_close();
?>
