<?php
session_start();
error_reporting(0);

/*****************************************************************************************
                          Artiphp Velocity 3 - ArtiPHPBB
               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="forumbb";

// 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/forumbb.php");

// autorisation
//--------------------
  $requete="select visumodule from ".$extension."module where nomModule='Forumbb'";
  $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();
     }
   }


  $SESSION_LASTVISIT = $_SESSION['SESSION_LASTVISIT'];


  $idcat=$_GET['idcat'];
  $page=$_GET['page'];
  $limit=$_GET['limit'];

  $idcat = intval($idcat);
  $page = intval($page);
  $limit = intval($limit);


//affichage des dossiers par categorie (5 dossiers par page)
//----------------------------------------------------------

 if ($idcat) {

  //pagination le limit défini le nombre d'enregistrement par page
  //---------------------------------------------------------------

  if (!($limit)) {
   $limit = 20;
  } 
  if (!($page)) {
   $page = 0;
  }

  // comptage des enregistrements
  $requete2="select topic_id from ".$extension2."topics where forum_id='$idcat'";
  $results=mysql_query($requete2, $link);
  $rows=mysql_num_rows($results);

  if ($rows == 0){
    $listedossiers="<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
  $requetcat="SELECT forum_name FROM ".$extension2."forums where forum_id=$idcat";
  $resultcat=mysql_query($requetcat, $link);
  $nom_cat=mysql_fetch_object($resultcat);
  


/** ENTETE DE PAGE **/
   $entete= "<font class=\"entete\"><a href=\"../welcome/index.php\" class=\"entete\">$LG_ACCUEIL</a>/<a href=\"index.php\" class=\"entete\">$LG_FORUMTITLE</a>/" .$nom_cat->forum_name."</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";
  //-----------------------------------------

  $entete2="<font class=\"grandtitre\">&nbsp;$nom_cat->forum_name</font><br><br>\n\n";
//----------------------------------------



  // metatags --------------------------------
  $nCat = htmlspecialchars($nomcat);
  $nCat2 = htmlspecialchars($nomsscat);
  $metatitle="".$nCat." - ".$nCat2."";
  $nCatDes = htmlspecialchars($defcat->descCat );
  $metaDescription="$nCatDes";
  //-------------------------------------------

/** AFFICHAGE DES TOPICS DU FORUM SPECIFIE **/

  $page = intval($page);
  $limit = intval($limit);

  $listedossiers="<div class=\"bouton\"><a href=\"#\" class=\"menu\" onClick=\"window.open('".$cheminphpBB."/posting.php?mode=newtopic&f=$idcat','','menubar=no,scrollbars=yes,toolbar=no,resizable=yes,width=610,height=500');\"><img src=\"images/post.gif\" border=\"0\"></a></div>\n";

  $listedossiers.="<div class=\"Dos_catphp_general\"><table width=\"100%\" class=\"Dos_catphp_general\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\">";
	//présentation

	$listedossiers .="<tr class=\"Dos_cat\"><td class=\"Dos_cat\">\n";
	$listedossiers .= "<font class=\"Dos_cat_titre\">$LG_BBSUJET2</font>\n";
	$listedossiers .= "</td><td class=\"Dos_cat\"><font class=\"Dos_cat_titre\">$LG_BBREPONSE</font>\n";
	$listedossiers .= "</td><td class=\"Dos_cat\"><font class=\"Dos_cat_titre\">$LG_BBAUTEUR</font>\n";
	$listedossiers .= "</td><td class=\"Dos_cat\"><font class=\"Dos_cat_titre\">$LG_BBVUS</font>\n";
	$listedossiers .= "</td><td class=\"Dos_cat\"><font class=\"Dos_cat_titre\">$LG_BBLASTMESS</font>\n";
	$listedossiers .= "</td></tr>\n";

  $requete="SELECT ".$extension2."topics.topic_id, ".$extension2."topics.topic_title, ".$extension2."topics.topic_type, ".$extension2."topics.topic_status, ".$extension2."posts.post_time, ".$extension2."topics.topic_views, ".$extension2."topics.topic_replies, ".$extension2."users.username FROM ".$extension2."topics, ".$extension2."posts, ".$extension2."users WHERE ".$extension2."topics.forum_id='$idcat'and ".$extension2."posts.forum_id=".$extension2."topics.forum_id and ".$extension2."topics.topic_last_post_id=".$extension2."posts.post_id and ".$extension2."users.user_id=".$extension2."topics.topic_poster order by ".$extension2."topics.topic_type desc, ".$extension2."posts.post_time desc LIMIT $page, $limit";
  $result=mysql_query($requete, $link);
  while ($d2=mysql_fetch_object($result)) {

  $datedernierpost = "$d2->post_time";

  // transformation date
  $d2->post_time=$d2->post_time-86400;
  $d2->post_time = date("d-m-Y à H:m:s",$d2->post_time+24*3600);
  //---------------------------

   if ($d2->username=='Anonymous') {
	$d2->username="$LG_BBINVITE";
   }


  //images
  if ($SESSION_LASTVISIT) {
   if ($d2->topic_type=="1") {
     if ($SESSION_LASTVISIT<=$datedernierpost) {
       $imgfor="folder_sticky_new.gif";
       $topictyp="$LG_BBPOSTIT";
     } else {
       $imgfor="folder_sticky.gif";
       $topictyp="$LG_BBPOSTIT";
     }
   } elseif ($d2->topic_type=="2") {
     if ($SESSION_LASTVISIT<=$datedernierpost) {
       $imgfor="folder_announce_new.gif";
       $topictyp="$LG_BBANNONCE";
     } else {
       $imgfor="folder_announce.gif";
       $topictyp="$LG_BBANNONCE";
     }
   } else {
     if ($d2->topic_status=='1') {
       if ($SESSION_LASTVISIT<=$datedernierpost) {
         $imgfor="folder_lock_new.gif";
       } else {
         $imgfor="folder_lock.gif";
       }
      $topictyp="";
     } else {
       if ($SESSION_LASTVISIT<=$datedernierpost) {
         $imgfor="folder_new.gif";
       } else {
         $imgfor="folder.gif";
       }
      $topictyp="";
     }
   }
  } else {
   if ($d2->topic_type=="1") {
       $imgfor="folder_sticky.gif";
       $topictyp="$LG_BBPOSTIT";
   } elseif ($d2->topic_type=="2") {
       $imgfor="folder_announce.gif";
       $topictyp="$LG_BBANNONCE";
   } else {
     if ($d2->topic_status=='1') {
      $imgfor="folder_lock.gif";
      $topictyp="";
     } else {
      $imgfor="folder.gif";
      $topictyp="";
     }
   }
  }


   $listedossiers .="<tr class=\"Dos_sscat\"><td class=\"Dos_sscat\">\n";
   $listedossiers .="<div class=\"Dos_sscat_titre\"><img src=\"images/".$imgfor."\" align=\"absmiddle\"> ".$topictyp." <a href=\"topic.php?t=".$d2->topic_id."\" class=\"Dos_sscat_titre\">".$d2->topic_title ."</a></div>\n";
   $listedossiers .= "</td><td class=\"Dos_sscat\"><font class=\"Dos_sscat_nb\">".$d2->topic_replies."</font>\n";
   $listedossiers .= "</td><td class=\"Dos_sscat\"><font class=\"Dos_sscat_posteur\">".$d2->username."</font>\n";
   $listedossiers .= "</td><td class=\"Dos_sscat\"><font class=\"Dos_sscat_nb\">".$d2->topic_views."</font>\n";
   $listedossiers .= "</td><td class=\"Dos_sscat\"><font class=\"Dos_sscat_date\">".$d2->post_time."</font>\n";
   $listedossiers .= "</td></tr>\n";
  }

  $listedossiers .="</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>";
 }
 //-------------------------------------------------------------------------



} 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/forumbb.css\">\n";


//le template
//------------

 $SESSION_SKIN=$_SESSION['SESSION_SKIN'];
 include("../templates/temp$SESSION_SKIN/temp.html");
 echo $arti;
mysql_close();
?>