<?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 - jimro : 13 juin 2005
******************************************************************************************/

/*****************************************************************************************
 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
******************************************************************************************/

include("adminheader.php");

// Dictionnaire spécifique au module
include("../langages/$SESSION_LANGSKIN/admin_galerie.php");

// Données titre et description module
// -----------------------------------
$imgmodule = "artiphpgalerie.gif";
$titremodule = "$LG_MODUGALERIE";
$descriptionmodule = "$LG_MODUGALERIEDES";

// Autorisation d'ouverture de cette page uniquement aux statuts autorisés
// -----------------------------------------------------------------------
if ($_SESSION['SESSION_STATUT']!="artadmin") {
   header("Location: ../outils/erreur.php?ec=2");
   exit();
}

// Affichage des données à modifier
if ($_GET['mod']) {
   $mod = $_GET['mod'];
   $requete = "select * from ".$extension."galcategorie where id_catgal='$mod'";
   $result = mysql_query($requete, $link);
   $dossier = mysql_fetch_object($result);

   $nom = $nomcatinitial = stripslashes($dossier->nomCatgal);
   $description = stripslashes($dossier->descCatgal);
   $imagecatgal = $dossier->imgCatgal;
   $catparent = $dossier->id_parentcatgal;

   $modif = $LG_MODCATS." ".$nom." ";

} elseif ($_POST['id_catgal']) {
   $mod = $_POST['id_catgal'];
   $nom = $_POST['nom'];
   $nomcatinitial = stripslashes($_POST['nomcatinitial']);
   $description = $_POST['description'];
   $imagecatgal = $_POST['imagecatgal'];
   $catparent = $_POST['catparent'];

   $modif = $LG_MODCATS." ".$nomcatinitial." ";

} else {

   $imagecatgal = "";
   $modif = "$LG_AJCATS";

}

if ($imagecatgal != "") {
   $formphoto = $LG_IMGNOW."<br>";
   $formphoto .= "<img src=\"../images/galcat/".$imagecatgal."\"><br>";
   $formphoto .= "<input type=\"checkbox\" name=\"suppimage\" value=\"ok\"> $LG_SUPPRES<br>";
   $formphoto .= $LG_IMGCHANG."<br>";
}

// Ouverture FTP et changement de chmod du répertoire /images/galcat
if ($_FILES['image']['type']) {
   if ($ftp=='1') {
      $ftpcon = ftp_connect($ftp_host) or die('Erreur');
      $loginresult = ftp_login($ftpcon, $ftp_login, $ftp_mdp);

      $repertoire = $ftp_repertoire."images";

      // Emplacement du répertoire que vous voulez modifier
      ftp_chdir($ftpcon, $repertoire) or die('Erreur répertoire');

      // Changement de chmod via FTP
      $chmod_cmd = "CHMOD 0777 galcat";
      ftp_site($ftpcon, $chmod_cmd);
   }
}
//----------------------------------------------------------------

// Upload de l'image
// -----------------

if ($_FILES['image']['type']) {
   $img = $_FILES['image']['type'];
   $nomimage = $_FILES['image']['name'];
   $tmp_file = $_FILES['image']['tmp_name'];

   if (!is_uploaded_file($tmp_file)) {
      $meserreur2 ="<br><font color=red>$LG_UPNOFILE</font><br><br>";
   }

   $tabTypeImage = split ("/", $img);
   $typeImage = $tabTypeImage[1];

   if ($typeImage != "pjpeg" && $typeImage != "x-jpeg" && $typeImage != "jpeg" && $typeImage != "gif" && $typeImage != "x-png" && $typeImage != "png") {
      $meserreur2 ="<br><font color=red>$LG_UPNOFORM</font><br><br>";
   } else {
      $destination = "../images/galcat/".$nomimage."";

      if (! move_uploaded_file ($tmp_file, $destination)) {
         $meserreur2 ="<br><font color=red>$LG_UPNOTRANS</font><br><br>";
          $insertimage = "";
      } else {
          $insertimage = ", imgCatgal='$nomimage' ";
      }

   }

}

// --------------------------------
// Fermeture et remise du chmod FTP
if ($_FILES['image']['type']){
   if ($ftp=='1') {
      $chmod_cmd = "CHMOD 0755 galcat";
      ftp_site($ftpcon, $chmod_cmd);
      ftp_close($ftpcon);
   }
}
// --------------------------------


// Formulaire de saisie
// --------------------

/* si un champ n'est pas renseigné, message d'erreur */
if (! $_POST['nom'] || ! $_POST['description']) {
   $meserreur="<font style=\"color:red\"><br>$LG_FORMERROR</font>";

   if (!$_GET['mod']) {
      $nom = stripslashes($nom);
      $description = stripslashes($description);
   }

/* si on récupère id_catgal, c'est une mise à jour */
} elseif ($_POST['id_catgal'] && $_POST['nom'] && $_POST['description']) {

   $nom = addslashes($nom);
   $description = addslashes($description);
   $catparent = $_POST['catparent'];
   $id_catgal = $_POST['id_catgal'];

   if ($_POST['suppimage']) {
      $insertimage = ", imgCatgal='' ";
   }

   $requete = "UPDATE ".$extension."galcategorie SET nomCatgal='$nom', descCatgal='$description', id_parentcatgal='$catparent' $insertimage WHERE id_catgal='$id_catgal'";
   $result = mysql_query($requete, $link);

   // Mise à jour de l'index
   include("galerie_donnees.php");

   header ("Location:galerieindex.php");
   exit();

/* sinon, c'est un ajout */
} else {

   $nom = addslashes($_POST['nom']);
   $description = addslashes($_POST['description']);
   $catparent = $_POST['catparent'];

   $requete = "INSERT into ".$extension."galcategorie SET nomCatgal='$nom', descCatgal='$description', id_parentcatgal='$catparent'$insertimage";
   $result = mysql_query($requete, $link);

   // Mise à jour de l'index
   include("galerie_donnees.php");

   header ("Location: galerieindex.php");
   exit();

}

// Champ catégorie
$catselect[$catparent] = "selected";
$listecat = "<select name=\"catparent\" size=\"1\">\n";
$listecat .= "<option value=\"0\">$LG_NEWCATS</option>\n";
// Exclusion de la catégorie en cours de la liste
$requete = "SELECT nomCatgal, id_catgal, id_parentcatgal FROM ".$extension."galcategorie WHERE id_catgal<>'$mod' AND id_parentcatgal='0'";
$result = mysql_query($requete, $link);
while ($cat=mysql_fetch_object($result)) {
   $cat->nomCatgal = stripslashes($cat->nomCatgal);
   $listecat .= "<option value=\"".$cat->id_catgal."\" ".$catselect[$cat->id_catgal].">".$LG_SSDECATS." ".$cat->nomCatgal."</option>\n";
}
$listecat .= "</select></p>\n";

mysql_free_result($result);
// ------------------------

// Présentation
// ------------

include("header.php");
include("menumod.php");

?>

<div align="center"><center>
   <table width="95%" border="0" cellspacing="5" cellpadding="5">
      <tr>
         <form NAME="form" method="POST" action="galeriecat.php" enctype="multipart/form-data">
         <td>
            <p><img src="imgadmin/cat.gif" align="absmiddle" border="0">&nbsp;
            <strong><?php echo $modif; ?></strong>
            <?php echo $meserreur; ?>
         </td>
      </tr>
      <tr>
         <td valign="top" bgcolor="#CCCCFF" style="BORDER:#000000 1px dashed">
            <b><?php echo $LG_NOM; ?> *</b><br>
            <input type="text" name="nom" value="<?php echo $nom; ?>" size="50"></p><p>
            <b><?php echo $LG_DESCRIPTION; ?> *</b><br>
            <textarea rows="5" name="description" cols="50"><?php echo $description; ?></textarea></p>
            <p><b><?php echo $LG_GALTYPECAT; ?></b><br><?php echo $listecat; ?></p>
            <p><b><?php echo $LG_IMGPRES; ?></b><br><?php echo $formphoto; ?>
            <input type="hidden" name="MAX_FILE_SIZE" value="15000">
            <input name="image" type="file" size="50" value=""><br><br>
            <input type="hidden" name="id_catgal" value="<?php echo $mod; ?>">
            <input type="hidden" name="nomcatinitial" value="<?php echo $nomcatinitial; ?>">
            <input type="hidden" name="imagecatgal" value="<?php echo $imagecatgal; ?>">
            <input type="submit" value="<?php echo $LG_ENVOI; ?>" name="B1"></p>
         </td>
         </form>
      </tr>
   </table>
</center></div>
<p></p>

<?php
include("menumod2.php");
include("footer.php");
mysql_close();
?>