dolibarr 19.0.3
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 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
35
36// Load translation files required by the page
37$langs->loadlangs(array('categories', 'bills'));
38
39
40$id = GETPOST('id', 'int');
41$label = GETPOST('label', 'alpha');
42$action = GETPOST('action', 'aZ09');
43$confirm = GETPOST('confirm');
44
45if ($id == '' && $label == '') {
46 dol_print_error('', 'Missing parameter id');
47 exit();
48}
49
50// Security check
51$result = restrictedArea($user, 'categorie', $id, '&category');
52
53$object = new Categorie($db);
54$result = $object->fetch($id, $label);
55if ($result <= 0) {
56 dol_print_error($db, $object->error);
57 exit;
58}
59
60$type = $object->type;
61if (is_numeric($type)) {
62 $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
63}
64
65$upload_dir = $conf->categorie->multidir_output[$object->entity];
66
67$hookmanager->initHooks(array('categorycard'));
68
69/*
70 * Actions
71 */
72$parameters = array('id' => $id, 'label' => $label, 'confirm' => $confirm, 'type' => $type, 'uploaddir' => $upload_dir, 'sendfile' => (GETPOST("sendit") ? true : false));
73// Note that $action and $object may be modified by some hooks
74$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
75if ($reshook < 0) {
76 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
77}
78
79if (empty($reshook)) {
80 if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && GETPOST("sendit") && getDolGlobalString('MAIN_UPLOAD_DOC')) {
81 if ($object->id) {
82 $file = $_FILES['userfile'];
83 if (is_array($file['name']) && count($file['name']) > 0) {
84 foreach ($file['name'] as $i => $name) {
85 if (empty($file['tmp_name'][$i]) || intval($conf->global->MAIN_UPLOAD_DOC) * 1000 <= filesize($file['tmp_name'][$i])) {
86 setEventMessage($file['name'][$i].' : '.$langs->trans(empty($file['tmp_name'][$i]) ? 'ErrorFailedToSaveFile' : 'MaxSizeForUploadedFiles'));
87 unset($file['name'][$i], $file['type'][$i], $file['tmp_name'][$i], $file['error'][$i], $file['size'][$i]);
88 }
89 }
90 }
91
92 if (!empty($file['tmp_name'])) {
93 $object->add_photo($upload_dir, $file);
94 }
95 }
96 }
97
98 if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->hasRight('categorie', 'creer')) {
99 $object->delete_photo($upload_dir."/".$_GET["file"]);
100 }
101
102 if ($action == 'addthumb' && $_GET["file"]) {
103 $object->addThumbs($upload_dir."/".$_GET["file"]);
104 }
105}
106
107/*
108 * View
109 */
110
111llxHeader("", "", $langs->trans("Categories"));
112
113$form = new Form($db);
114$formother = new FormOther($db);
115
116if ($object->id) {
117 $title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
118
119 $head = categories_prepare_head($object, $type);
120 print dol_get_fiche_head($head, 'photos', $langs->trans($title), -1, 'category');
121
122 $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
123 $linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
124 $object->next_prev_filter = 'type = '.((int) $object->type);
125 $object->ref = $object->label;
126 $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
127 $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
128 foreach ($ways as $way) {
129 $morehtmlref .= $way."<br>\n";
130 }
131 $morehtmlref .= '</div>';
132
133 dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
134
135 /*
136 * Confirmation de la suppression de photo
137 */
138 if ($action == 'delete') {
139 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
140 }
141
142 print '<br>';
143
144 print '<div class="fichecenter">';
145 print '<div class="underbanner clearboth"></div>';
146 print '<table class="border centpercent tableforfield">';
147
148 // Description
149 print '<tr><td class="titlefield notopnoleft">';
150 print $langs->trans("Description").'</td><td>';
151 print dol_htmlentitiesbr($object->description);
152 print '</td></tr>';
153
154 // Color
155 print '<tr><td class="notopnoleft">';
156 print $langs->trans("Color").'</td><td>';
157 print $formother->showColor($object->color);
158 print '</td></tr>';
159
160 print "</table>\n";
161 print '</div>';
162
163 print dol_get_fiche_end();
164
165
166
167 /*
168 * Action bar
169 */
170 print '<div class="tabsAction">'."\n";
171
172 if ($action != 'ajout_photo' && $user->hasRight('categorie', 'creer')) {
173 if (getDolGlobalString('MAIN_UPLOAD_DOC')) {
174 print '<a class="butAction hideonsmartphone" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
175 print $langs->trans("AddPhoto").'</a>';
176 } else {
177 print '<a class="butActionRefused classfortooltip hideonsmartphone" href="#">';
178 print $langs->trans("AddPhoto").'</a>';
179 }
180 }
181
182 print '</div>'."\n";
183
184 /*
185 * Ajouter une photo
186 */
187 if ($action == 'ajout_photo' && $user->hasRight('categorie', 'creer') && getDolGlobalString('MAIN_UPLOAD_DOC')) {
188 // Affiche formulaire upload
189 $formfile = new FormFile($db);
190 $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);
191 }
192
193 // Affiche photos
194 if ($action != 'ajout_photo') {
195 $nbphoto = 0;
196 $nbbyrow = 5;
197
198 $maxWidth = 160;
199 $maxHeight = 120;
200
201 $pdir = get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/";
202 $dir = $upload_dir.'/'.$pdir;
203
204 $listofphoto = $object->liste_photos($dir);
205
206 if (is_array($listofphoto) && count($listofphoto)) {
207 print '<br>';
208 print '<table width="100%" valign="top" class="center centpercent">';
209
210 foreach ($listofphoto as $key => $obj) {
211 $nbphoto++;
212
213 if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) {
214 print '<tr class"center valignmiddle" border="1">';
215 }
216 if ($nbbyrow) {
217 print '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">';
218 }
219
220 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">';
221
222 // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
223 if ($obj['photo_vignette']) {
224 $filename = $obj['photo_vignette'];
225 } else {
226 $filename = $obj['photo'];
227 }
228
229 // Nom affiche
230 $viewfilename = $obj['photo'];
231
232 // Taille de l'image
233 $object->get_image_size($dir.$filename);
234 $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
235 $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
236
237 print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename).'">';
238
239 print '</a>';
240 print '<br>'.$viewfilename;
241 print '<br>';
242
243 // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
244 if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i', $obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) {
245 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>';
246 }
247 if ($user->hasRight('categorie', 'creer')) {
248 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&type='.$type.'&file='.urlencode($pdir.$viewfilename).'">';
249 print img_delete().'</a>';
250 }
251 if ($nbbyrow) {
252 print '</td>';
253 }
254 if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) {
255 print '</tr>';
256 }
257 }
258
259 // Ferme tableau
260 while ($nbphoto % $nbbyrow) {
261 print '<td width="'.ceil(100 / $nbbyrow).'%">&nbsp;</td>';
262 $nbphoto++;
263 }
264
265 print '</table>';
266 }
267
268 if ($nbphoto < 1) {
269 print '<div class="opacitymedium">'.$langs->trans("NoPhotoYet")."</div>";
270 }
271 }
272} else {
273 print $langs->trans("ErrorUnknown");
274}
275
276// End of page
277llxFooter();
278$db->close();
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.
Classe permettant la generation de composants html autre Only common components are here.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_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.