dolibarr 20.0.0
photos.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2014 Jean-François Ferry <jfefe@aternatik.fr>
7 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
36
37// Load translation files required by the page
38$langs->loadlangs(array('categories', 'bills'));
39
40
41$id = GETPOSTINT('id');
42$label = GETPOST('label', 'alpha');
43$action = GETPOST('action', 'aZ09');
44$confirm = GETPOST('confirm');
45
46if ($id == '' && $label == '') {
47 dol_print_error(null, 'Missing parameter id');
48 exit();
49}
50
51$object = new Categorie($db);
52$result = $object->fetch($id, $label);
53if ($result <= 0) {
54 dol_print_error($db, $object->error);
55 exit;
56}
57
58$type = $object->type;
59if (is_numeric($type)) {
60 $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
61}
62
63$upload_dir = $conf->categorie->multidir_output[$object->entity];
64
65$hookmanager->initHooks(array('categorycard'));
66
67// Security check
68$result = restrictedArea($user, 'categorie', $id, '&category');
69
70$permissiontoadd = $user->hasRight('categorie', 'creer');
71
72
73/*
74 * Actions
75 */
76
77$parameters = array('id' => $id, 'label' => $label, 'confirm' => $confirm, 'type' => $type, 'uploaddir' => $upload_dir, 'sendfile' => (GETPOST("sendit") ? true : false));
78// Note that $action and $object may be modified by some hooks
79$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
80if ($reshook < 0) {
81 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
82}
83
84if (empty($reshook)) {
85 if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && GETPOST("sendit") && getDolGlobalString('MAIN_UPLOAD_DOC')) {
86 if ($object->id) {
87 $file = $_FILES['userfile'];
88 if (is_array($file['name']) && count($file['name']) > 0) {
89 foreach ($file['name'] as $i => $name) {
90 if (empty($file['tmp_name'][$i]) || (getDolGlobalInt('MAIN_UPLOAD_DOC') * 1000) <= filesize($file['tmp_name'][$i])) {
91 setEventMessage($file['name'][$i].' : '.$langs->trans(empty($file['tmp_name'][$i]) ? 'ErrorFailedToSaveFile' : 'MaxSizeForUploadedFiles'), 'errors');
92 unset($file['name'][$i], $file['type'][$i], $file['tmp_name'][$i], $file['error'][$i], $file['size'][$i]);
93 }
94 }
95 }
96
97 if (!empty($file['tmp_name'])) {
98 $object->add_photo($upload_dir, $file);
99 }
100 }
101 }
102
103 if ($action == 'confirm_delete' && GETPOST("file") && $confirm == 'yes' && $permissiontoadd) {
104 $object->delete_photo($upload_dir."/".GETPOST("file"));
105 }
106
107 if ($action == 'addthumb' && GETPOST("file") && $permissiontoadd) {
108 $object->addThumbs($upload_dir."/".GETPOST("file"));
109 }
110}
111
112/*
113 * View
114 */
115
116llxHeader("", "", $langs->trans("Categories"));
117
118$form = new Form($db);
119$formother = new FormOther($db);
120
121if ($object->id) {
122 $title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
123
124 $head = categories_prepare_head($object, $type);
125 print dol_get_fiche_head($head, 'photos', $langs->trans($title), -1, 'category');
126
127 $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
128 $linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
129 $object->next_prev_filter = 'type = '.((int) $object->type);
130 $object->ref = $object->label;
131 $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
132 $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
133 foreach ($ways as $way) {
134 $morehtmlref .= $way."<br>\n";
135 }
136 $morehtmlref .= '</div>';
137
138 dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
139
140 /*
141 * Confirmation deletion of picture
142 */
143 if ($action == 'delete') {
144 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.urlencode($type).'&file='.urlencode(GETPOST("file")), $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
145 }
146
147 print '<br>';
148
149 print '<div class="fichecenter">';
150 print '<div class="underbanner clearboth"></div>';
151 print '<table class="border centpercent tableforfield">';
152
153 // Description
154 print '<tr><td class="titlefield notopnoleft">';
155 print $langs->trans("Description").'</td><td>';
156 print dol_htmlentitiesbr($object->description);
157 print '</td></tr>';
158
159 // Color
160 print '<tr><td class="notopnoleft">';
161 print $langs->trans("Color").'</td><td>';
162 print $formother->showColor($object->color);
163 print '</td></tr>';
164
165 print "</table>\n";
166 print '</div>';
167
168 print dol_get_fiche_end();
169
170
171
172 /*
173 * Action bar
174 */
175 print '<div class="tabsAction">'."\n";
176
177 if ($action != 'ajout_photo' && $user->hasRight('categorie', 'creer')) {
178 if (getDolGlobalString('MAIN_UPLOAD_DOC')) {
179 print '<a class="butAction hideonsmartphone" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
180 print $langs->trans("AddPhoto").'</a>';
181 } else {
182 print '<a class="butActionRefused classfortooltip hideonsmartphone" href="#">';
183 print $langs->trans("AddPhoto").'</a>';
184 }
185 }
186
187 print '</div>'."\n";
188
189 /*
190 * Ajouter une photo
191 */
192 if ($action == 'ajout_photo' && $user->hasRight('categorie', 'creer') && getDolGlobalString('MAIN_UPLOAD_DOC')) {
193 // Affiche formulaire upload
194 $formfile = new FormFile($db);
195 $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;type='.$type, $langs->trans("AddPhoto"), 1, '', $user->hasRight('categorie', 'creer'), 50, $object, '', false, '', 0);
196 }
197
198 // Affiche photos
199 if ($action != 'ajout_photo') {
200 $nbphoto = 0;
201 $nbbyrow = 5;
202
203 $maxWidth = 160;
204 $maxHeight = 120;
205
206 $pdir = get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/";
207 $dir = $upload_dir.'/'.$pdir;
208
209 $listofphoto = $object->liste_photos($dir);
210
211 if (is_array($listofphoto) && count($listofphoto)) {
212 print '<br>';
213 print '<table width="100%" valign="top" class="center centpercent">';
214
215 foreach ($listofphoto as $key => $obj) {
216 $nbphoto++;
217
218 if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) {
219 print '<tr class"center valignmiddle" border="1">';
220 }
221 if ($nbbyrow) {
222 print '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">';
223 }
224
225 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">';
226
227 // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
228 if ($obj['photo_vignette']) {
229 $filename = $obj['photo_vignette'];
230 } else {
231 $filename = $obj['photo'];
232 }
233
234 // Nom affiche
235 $viewfilename = $obj['photo'];
236
237 // Taille de l'image
238 $object->get_image_size($dir.$filename);
239 $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
240 $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
241
242 print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename).'">';
243
244 print '</a>';
245 print '<br>'.$viewfilename;
246 print '<br>';
247
248 // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
249 if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i', $obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) {
250 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>';
251 }
252 if ($user->hasRight('categorie', 'creer')) {
253 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&type='.$type.'&file='.urlencode($pdir.$viewfilename).'">';
254 print img_delete().'</a>';
255 }
256 if ($nbbyrow) {
257 print '</td>';
258 }
259 if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) {
260 print '</tr>';
261 }
262 }
263
264 // Ferme tableau
265 while ($nbphoto % $nbbyrow) {
266 print '<td width="'.ceil(100 / $nbbyrow).'%">&nbsp;</td>';
267 $nbphoto++;
268 }
269
270 print '</table>';
271 }
272
273 if ($nbphoto < 1) {
274 print '<div class="opacitymedium">'.$langs->trans("NoPhotoYet")."</div>";
275 }
276 }
277} else {
278 print $langs->trans("ErrorUnknown");
279}
280
281// End of page
282llxFooter();
283$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
categories_prepare_head(Categorie $object, $type)
Prepare array with list of tabs.
Class to manage categories.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.