dolibarr/htdocs/categories/photos.php

268 lines
9.0 KiB
PHP
Raw Normal View History

<?php
2015-05-23 18:52:31 +02:00
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
2015-05-23 18:52:31 +02:00
* Copyright (C) 2014 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/categories/photos.php
* \ingroup category
* \brief Gestion des photos d'une categorie
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
2016-05-21 15:03:02 +02:00
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
2018-05-27 09:58:23 +02:00
// Load translation files required by the page
$langs->loadlangs(array('categories', 'bills'));
2020-03-20 15:40:46 +01:00
$id = GETPOST('id', 'int');
$label = GETPOST('label', 'alpha');
2021-02-23 18:04:37 +01:00
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm');
2021-02-23 18:04:37 +01:00
if ($id == '' && $label == '') {
dol_print_error('', 'Missing parameter id');
exit();
}
// Security check
2012-03-20 15:45:15 +01:00
$result = restrictedArea($user, 'categorie', $id, '&category');
$object = new Categorie($db);
$result = $object->fetch($id, $label);
2020-03-20 15:40:46 +01:00
if ($result <= 0) {
dol_print_error($db, $object->error); exit;
}
$type = $object->type;
2021-02-23 18:04:37 +01:00
if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
}
$upload_dir = $conf->categorie->multidir_output[$object->entity];
/*
* Actions
*/
2021-03-25 16:59:47 +01:00
if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && GETPOST("sendit") && !empty($conf->global->MAIN_UPLOAD_DOC)) {
if ($object->id) {
$file = $_FILES['userfile'];
2021-02-23 18:04:37 +01:00
if (is_array($file['name']) && count($file['name']) > 0) {
foreach ($file['name'] as $i => $name) {
if (empty($file['tmp_name'][$i]) || intval($conf->global->MAIN_UPLOAD_DOC) * 1000 <= filesize($file['tmp_name'][$i])) {
setEventMessage($file['name'][$i].' : '.$langs->trans(empty($file['tmp_name'][$i]) ? 'ErrorFailedToSaveFile' : 'MaxSizeForUploadedFiles'));
unset($file['name'][$i], $file['type'][$i], $file['tmp_name'][$i], $file['error'][$i], $file['size'][$i]);
}
}
}
if (!empty($file['tmp_name'])) {
$object->add_photo($upload_dir, $file);
}
}
}
2021-02-23 18:04:37 +01:00
if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer) {
$object->delete_photo($upload_dir."/".$_GET["file"]);
}
2021-02-23 18:04:37 +01:00
if ($action == 'addthumb' && $_GET["file"]) {
$object->addThumbs($upload_dir."/".$_GET["file"]);
}
/*
* View
*/
llxHeader("", "", $langs->trans("Categories"));
$form = new Form($db);
2016-05-21 15:03:02 +02:00
$formother = new FormOther($db);
2021-02-23 18:04:37 +01:00
if ($object->id) {
2020-04-12 00:37:05 +02:00
$title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
2012-07-28 11:28:37 +02:00
$head = categories_prepare_head($object, $type);
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, 'photos', $langs->trans($title), -1, 'category');
2017-07-25 19:57:51 +02:00
2021-03-14 15:06:40 +01:00
$backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
$linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
$object->next_prev_filter = ' type = '.$object->type;
2017-01-22 12:13:32 +01:00
$object->ref = $object->label;
$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
2017-01-22 12:13:32 +01:00
$ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
2021-02-23 18:04:37 +01:00
foreach ($ways as $way) {
$morehtmlref .= $way."<br>\n";
2017-01-22 12:13:32 +01:00
}
$morehtmlref .= '</div>';
2017-07-25 19:57:51 +02:00
dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
2017-07-25 19:57:51 +02:00
2012-07-02 19:30:37 +02:00
/*
* Confirmation de la suppression de photo
*/
2021-02-23 18:04:37 +01:00
if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
2012-07-02 19:30:37 +02:00
}
2012-07-28 11:28:37 +02:00
2017-01-22 12:13:32 +01:00
print '<br>';
2017-07-25 19:57:51 +02:00
2017-04-05 14:48:24 +02:00
print '<div class="fichecenter">';
2017-01-22 12:13:32 +01:00
print '<div class="underbanner clearboth"></div>';
2020-05-26 14:43:50 +02:00
print '<table class="border centpercent tableforfield">';
2012-07-28 11:28:37 +02:00
2012-07-02 19:30:37 +02:00
// Description
2017-01-22 12:13:32 +01:00
print '<tr><td class="titlefield notopnoleft">';
2012-07-02 19:30:37 +02:00
print $langs->trans("Description").'</td><td>';
2015-05-14 20:49:22 +02:00
print dol_htmlentitiesbr($object->description);
2012-07-02 19:30:37 +02:00
print '</td></tr>';
2012-07-28 11:28:37 +02:00
2016-05-21 15:03:02 +02:00
// Color
print '<tr><td class="notopnoleft">';
print $langs->trans("Color").'</td><td>';
print $formother->showColor($object->color);
2012-07-02 19:30:37 +02:00
print '</td></tr>';
2016-08-29 10:32:00 +02:00
2012-07-02 19:30:37 +02:00
print "</table>\n";
print '</div>';
2017-07-25 19:57:51 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2012-07-28 11:28:37 +02:00
2021-03-16 04:22:43 +01:00
/*
* Action bar
*/
print '<div class="tabsAction">'."\n";
2012-07-28 11:28:37 +02:00
2021-02-23 18:04:37 +01:00
if ($action != 'ajout_photo' && $user->rights->categorie->creer) {
if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
print '<a class="butAction hideonsmartphone" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
2012-07-02 19:30:37 +02:00
print $langs->trans("AddPhoto").'</a>';
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip hideonsmartphone" href="#">';
2012-07-02 19:30:37 +02:00
print $langs->trans("AddPhoto").'</a>';
}
}
2012-07-28 11:28:37 +02:00
print '</div>'."\n";
2012-07-28 11:28:37 +02:00
2012-07-02 19:30:37 +02:00
/*
* Ajouter une photo
*/
2021-02-23 18:04:37 +01:00
if ($action == 'ajout_photo' && $user->rights->categorie->creer && !empty($conf->global->MAIN_UPLOAD_DOC)) {
2012-07-02 19:30:37 +02:00
// Affiche formulaire upload
$formfile = new FormFile($db);
$formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;type='.$type, $langs->trans("AddPhoto"), 1, '', $user->rights->categorie->creer, 50, $object, '', false, '', 0);
2012-07-02 19:30:37 +02:00
}
2012-07-28 11:28:37 +02:00
2012-07-02 19:30:37 +02:00
// Affiche photos
2021-02-23 18:04:37 +01:00
if ($action != 'ajout_photo') {
$nbphoto = 0;
$nbbyrow = 5;
2012-07-28 11:28:37 +02:00
2012-07-02 19:30:37 +02:00
$maxWidth = 160;
$maxHeight = 120;
2012-07-28 11:28:37 +02:00
$pdir = get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/";
2012-07-02 19:30:37 +02:00
$dir = $upload_dir.'/'.$pdir;
2012-07-28 11:28:37 +02:00
2019-03-15 10:48:10 +01:00
$listofphoto = $object->liste_photos($dir);
2012-07-02 19:30:37 +02:00
2021-02-23 18:04:37 +01:00
if (is_array($listofphoto) && count($listofphoto)) {
print '<br>';
2021-11-22 02:35:55 +01:00
print '<table width="100%" valign="top" class="center centpercent">';
2021-02-23 18:04:37 +01:00
foreach ($listofphoto as $key => $obj) {
$nbphoto++;
2021-02-23 18:04:37 +01:00
if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) {
2021-11-22 02:35:55 +01:00
print '<tr class"center valignmiddle" border="1">';
2021-02-23 18:04:37 +01:00
}
if ($nbbyrow) {
print '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">';
}
2021-11-22 02:35:55 +01:00
print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$obj['photo']).'" alt="Original size" target="_blank" rel="noopener noreferrer">';
// Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
2021-02-23 18:04:37 +01:00
if ($obj['photo_vignette']) {
$filename = $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 '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename).'">';
print '</a>';
print '<br>'.$viewfilename;
print '<br>';
// On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
2021-02-23 18:04:37 +01:00
if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i', $obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) {
2021-10-02 12:58:15 +02:00
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&token='.newToken().'&action=addthumb&type='.$type.'&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').'&nbsp;&nbsp;</a>';
}
2021-02-23 18:04:37 +01:00
if ($user->rights->categorie->creer) {
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&type='.$type.'&file='.urlencode($pdir.$viewfilename).'">';
print img_delete().'</a>';
}
2021-02-23 18:04:37 +01:00
if ($nbbyrow) {
print '</td>';
}
if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) {
print '</tr>';
}
}
// Ferme tableau
2021-02-23 18:04:37 +01:00
while ($nbphoto % $nbbyrow) {
print '<td width="'.ceil(100 / $nbbyrow).'%">&nbsp;</td>';
$nbphoto++;
}
print '</table>';
2012-07-02 19:30:37 +02:00
}
2012-07-28 11:28:37 +02:00
2021-02-23 18:04:37 +01:00
if ($nbphoto < 1) {
2017-04-05 14:48:24 +02:00
print '<div class="opacitymedium">'.$langs->trans("NoPhotoYet")."</div>";
2012-07-02 19:30:37 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
print $langs->trans("ErrorUnknown");
}
2018-07-29 13:40:35 +02:00
// End of page
llxFooter();
$db->close();