diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index 409f7329be2..99686eed40d 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -73,7 +73,7 @@ class Categorie
*/
function fetch($id)
{
- $sql = "SELECT rowid, label, description, fk_soc, visible, type";
+ $sql = "SELECT rowid, entity, label, description, fk_soc, visible, type";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE rowid = ".$id;
@@ -83,12 +83,13 @@ class Categorie
{
$res = $this->db->fetch_array($resql);
- $this->id = $res['rowid'];
- $this->label = $res['label'];
- $this->description = $res['description'];
- $this->socid = $res['fk_soc'];
- $this->visible = $res['visible'];
- $this->type = $res['type'];
+ $this->id = $res['rowid'];
+ $this->label = $res['label'];
+ $this->description = $res['description'];
+ $this->socid = $res['fk_soc'];
+ $this->visible = $res['visible'];
+ $this->type = $res['type'];
+ $this->entity = $res['entity'];
$this->db->free($resql);
}
@@ -1284,6 +1285,8 @@ class Categorie
*/
function liste_photos($dir,$nbmax=0)
{
+ include_once(DOL_DOCUMENT_ROOT ."/core/lib/files.lib.php");
+
$nbphoto=0;
$tabobj=array();
@@ -1296,7 +1299,7 @@ class Categorie
{
while (($file = readdir($handle)) != false)
{
- if (is_file($dir.$file))
+ if (dol_is_file($dir.$file) && preg_match('/(\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i',$dir.$file))
{
$nbphoto++;
$photo = $file;
diff --git a/htdocs/categories/photos.php b/htdocs/categories/photos.php
index 7730347f286..d25a5520e22 100644
--- a/htdocs/categories/photos.php
+++ b/htdocs/categories/photos.php
@@ -51,6 +51,13 @@ if ($id == "")
$result = restrictedArea($user, 'categorie', $id, '&category');
$object = new Categorie($db);
+if ($id > 0)
+{
+ $result = $object->fetch($id);
+
+ $upload_dir = $conf->categorie->multidir_output[$object->entity];
+}
+
/*
* Actions
@@ -58,22 +65,17 @@ $object = new Categorie($db);
if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- if ($id)
- {
- $result = $object->fetch($id);
-
- $result = $object->add_photo($conf->categorie->dir_output, $_FILES['userfile']);
- }
+ if ($object->id) $result = $object->add_photo($upload_dir, $_FILES['userfile']);
}
if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer)
{
- $object->delete_photo($conf->categorie->dir_output."/".$_GET["file"]);
+ $object->delete_photo($upload_dir."/".$_GET["file"]);
}
if ($action == 'addthumb' && $_GET["file"])
{
- $object->add_thumb($conf->categorie->dir_output."/".$_GET["file"]);
+ $object->add_thumb($upload_dir."/".$_GET["file"]);
}
@@ -85,215 +87,210 @@ llxHeader("","",$langs->trans("Categories"));
$form = new Form($db);
-if (!empty($id) || !empty($ref))
+if ($object->id)
{
- $result = $object->fetch($id);
-
- if ($result)
- {
- $title=$langs->trans("ProductsCategoryShort");
- if ($type == 0) $title=$langs->trans("ProductsCategoryShort");
- elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort");
- elseif ($type == 2) $title=$langs->trans("CustomersCategoryShort");
- elseif ($type == 3) $title=$langs->trans("MembersCategoryShort");
-
- $head = categories_prepare_head($object,$type);
- dol_fiche_head($head, 'photos', $title, 0, 'category');
-
- /*
- * Confirmation de la suppression de photo
- */
- if ($action == 'delete')
- {
- $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
- if ($ret == 'html') print '
';
- }
-
- print($mesg);
-
- print '
| '; - $ways = $object->print_all_ways(); - print $langs->trans("Ref").' | ';
- print ''.$langs->trans("Root").' >> ';
- foreach ($ways as $way)
- {
- print $way." \n"; - } - print ' |
| '; - print $langs->trans("Description").' | '; - print nl2br($object->description); - print ' |
| '; - print $langs->trans("AssignedToTheCustomer").' | '; - print $soc->getNomUrl(1); - print ' |
| '; - print $langs->trans("CategoryContents").' | '; - print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); - print ' |
| '; - print $langs->trans("CategoryContents").' | '; - print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); - print ' |
| '; - print $langs->trans("CategoryContents").' | '; - print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); - print ' |
| ';
-
- print '';
-
- // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
- if ($obj['photo_vignette'])
- {
- $filename='thumbs/'.$obj['photo_vignette'];
- }
- else
- {
- $filename=$obj['photo'];
- }
-
- // Nom affiche
- $viewfilename=$obj['photo'];
-
- // Taille de l'image
- $object->get_image_size($dir.$filename);
- $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
- $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
-
- print ' '.$viewfilename; - print ' '; - - // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites - if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) - { - print ''.img_picto($langs->trans('GenerateThumb'),'refresh').' '; - } - if ($user->rights->categorie->creer) - { - print ''; - print img_delete().''; - } - if ($nbbyrow) print ' | ';
- if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print ''; - $nbphoto++; - } - - if ($nbphoto < 1) - { - print ' |
| ';
- print " ".$langs->trans("NoPhotoYet")." "; - print ' |
| '; + $ways = $object->print_all_ways(); + print $langs->trans("Ref").' | ';
+ print ''.$langs->trans("Root").' >> ';
+ foreach ($ways as $way)
+ {
+ print $way." \n"; + } + print ' |
| '; + print $langs->trans("Description").' | '; + print nl2br($object->description); + print ' |
| '; + print $langs->trans("AssignedToTheCustomer").' | '; + print $soc->getNomUrl(1); + print ' |
| '; + print $langs->trans("CategoryContents").' | '; + print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print ' |
| '; + print $langs->trans("CategoryContents").' | '; + print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print ' |
| '; + print $langs->trans("CategoryContents").' | '; + print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print ' |
| ';
+
+ print '';
+
+ // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
+ if ($obj['photo_vignette'])
+ {
+ $filename='thumbs/'.$obj['photo_vignette'];
+ }
+ else
+ {
+ $filename=$obj['photo'];
+ }
+
+ // Nom affiche
+ $viewfilename=$obj['photo'];
+
+ // Taille de l'image
+ $object->get_image_size($dir.$filename);
+ $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
+ $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
+
+ print ' '.$viewfilename; + print ' '; + + // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites + if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) + { + print 'entity.'&action=addthumb&type='.$type.'&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' '; + } + if ($user->rights->categorie->creer) + { + print 'entity.'&action=delete&type='.$type.'&file='.urlencode($pdir.$viewfilename).'">'; + print img_delete().''; + } + if ($nbbyrow) print ' | ';
+ if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print ''; + $nbphoto++; + } + + if ($nbphoto < 1) + { + print ' |
| ';
+ print " ".$langs->trans("NoPhotoYet")." "; + print ' |