diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index d17a75b63e5..8eca3b5adab 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1645,6 +1645,36 @@ class Categorie extends CommonObject } } + /** + * Return if at least one photo is available + * + * @param string $sdir Directory to scan + * @return boolean True if at least one photo is available, False if not + */ + public function isAnyPhotoAvailable($sdir) + { + include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php'; + + $sdir .= '/' . get_exdir($this->id, 2, 0, 0, $this, 'category') . $this->id . "/photos/"; + + $dir_osencoded = dol_osencode($sdir); + if (file_exists($dir_osencoded)) { + $handle = opendir($dir_osencoded); + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + if (!utf8_check($file)) { + $file = mb_convert_encoding($file, 'UTF-8', 'ISO-8859-1'); // To be sure data is stored in UTF8 in memory + } + if (dol_is_file($sdir . $file) && image_format_supported($file) >= 0) { + return true; + } + } + } + } + return false; + } + /** * getTooltipContentArray * @param array $params params to construct tooltip data @@ -1755,7 +1785,7 @@ class Categorie extends CommonObject if (file_exists($dir)) { if (is_array($file['name']) && count($file['name']) > 0) { $nbfile = count($file['name']); - for ($i = 0; $i <= $nbfile; $i++) { + for ($i = 0; $i < $nbfile; $i++) { $originImage = $dir.$file['name'][$i]; // Cree fichier en taille origine diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 36a84e840bb..5eaa20bc1fa 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9051,7 +9051,8 @@ abstract class CommonObject { global $conf; - $file = ''; $originalfile = ''; + $file = ''; + $originalfile = ''; $newmodulepart = $modulepart; if ($modulepart == 'unknown' && !empty($this->module)) { $newmodulepart = $this->module; @@ -9124,6 +9125,10 @@ abstract class CommonObject $pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; } } + if ($modulepart == 'category') { + $dir = $sdir.'/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; + $pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; + } // Defined relative dir to DOL_DATA_ROOT $relativedir = ''; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f9e551644f6..95cf0b9dbff 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2414,6 +2414,26 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi $morehtmlleft .= '
transnoentitiesnoconv("Documents"))).'" alt="No photo"'.($width ? ' style="width: '.$width.'px"' : '').' src="'.DOL_URL_ROOT.$nophoto.'">
'; } } + } elseif ($object->element == 'category') { + /** @var Categorie $object */ + $width = 80; + $cssclass = 'photowithmargin photoref'; + $showimage = $object->isAnyPhotoAvailable($conf->categorie->multidir_output[$entity]); + $maxvisiblephotos = getDolGlobalInt('CATEGORY_MAX_VISIBLE_PHOTO', 5); + if ($conf->browser->layout == 'phone') { + $maxvisiblephotos = 1; + } + if ($showimage) { + $morehtmlleft .= '
'.$object->show_photos('category', $conf->categorie->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, 0, $width, 0, '').'
'; + } else { + if (getDolGlobalString('CATEGORY_NODISPLAYIFNOPHOTO')) { + $nophoto = ''; + $morehtmlleft .= '
'; + } else { // Show no photo link + $nophoto = '/public/theme/common/nophoto.png'; + $morehtmlleft .= '
transnoentitiesnoconv("Documents"))).'" alt="No photo"'.($width ? ' style="width: '.$width.'px"' : '').' src="'.DOL_URL_ROOT.$nophoto.'">
'; + } + } } elseif ($object->element == 'bom') { /** @var Bom $object */ $width = 80; @@ -2437,6 +2457,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi } elseif ($object->element == 'ticket') { $width = 80; $cssclass = 'photoref'; + /** @var Ticket $object */ $showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].'/'.$object->ref); $maxvisiblephotos = getDolGlobalInt('TICKET_MAX_VISIBLE_PHOTO', 2); if ($conf->browser->layout == 'phone') {