dolibarr 18.0.6
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); exit;
57}
58
59$type = $object->type;
60if (is_numeric($type)) {
61 $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
62}
63
64$upload_dir = $conf->categorie->multidir_output[$object->entity];
65
66/*
67 * Actions
68 */
69
70if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && GETPOST("sendit") && !empty($conf->global->MAIN_UPLOAD_DOC)) {
71 if ($object->id) {
72 $file = $_FILES['userfile'];
73 if (is_array($file['name']) && count($file['name']) > 0) {
74 foreach ($file['name'] as $i => $name) {
75 if (empty($file['tmp_name'][$i]) || intval($conf->global->MAIN_UPLOAD_DOC) * 1000 <= filesize($file['tmp_name'][$i])) {
76 setEventMessage($file['name'][$i].' : '.$langs->trans(empty($file['tmp_name'][$i]) ? 'ErrorFailedToSaveFile' : 'MaxSizeForUploadedFiles'));
77 unset($file['name'][$i], $file['type'][$i], $file['tmp_name'][$i], $file['error'][$i], $file['size'][$i]);
78 }
79 }
80 }
81
82 if (!empty($file['tmp_name'])) {
83 $object->add_photo($upload_dir, $file);
84 }
85 }
86}
87
88if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer) {
89 $object->delete_photo($upload_dir."/".$_GET["file"]);
90}
91
92if ($action == 'addthumb' && $_GET["file"]) {
93 $object->addThumbs($upload_dir."/".$_GET["file"]);
94}
95
96
97/*
98 * View
99 */
100
101llxHeader("", "", $langs->trans("Categories"));
102
103$form = new Form($db);
104$formother = new FormOther($db);
105
106if ($object->id) {
107 $title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
108
109 $head = categories_prepare_head($object, $type);
110 print dol_get_fiche_head($head, 'photos', $langs->trans($title), -1, 'category');
111
112 $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.urlencode($type));
113 $linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
114 $object->next_prev_filter = 'type = '.((int) $object->type);
115 $object->ref = $object->label;
116 $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
117 $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
118 foreach ($ways as $way) {
119 $morehtmlref .= $way."<br>\n";
120 }
121 $morehtmlref .= '</div>';
122
123 dol_banner_tab($object, 'label', $linkback, ($user->socid ? 0 : 1), 'label', 'label', $morehtmlref, '&type='.$type, 0, '', '', 1);
124
125 /*
126 * Confirmation de la suppression de photo
127 */
128 if ($action == 'delete') {
129 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
130 }
131
132 print '<br>';
133
134 print '<div class="fichecenter">';
135 print '<div class="underbanner clearboth"></div>';
136 print '<table class="border centpercent tableforfield">';
137
138 // Description
139 print '<tr><td class="titlefield notopnoleft">';
140 print $langs->trans("Description").'</td><td>';
141 print dol_htmlentitiesbr($object->description);
142 print '</td></tr>';
143
144 // Color
145 print '<tr><td class="notopnoleft">';
146 print $langs->trans("Color").'</td><td>';
147 print $formother->showColor($object->color);
148 print '</td></tr>';
149
150 print "</table>\n";
151 print '</div>';
152
153 print dol_get_fiche_end();
154
155
156
157 /*
158 * Action bar
159 */
160 print '<div class="tabsAction">'."\n";
161
162 if ($action != 'ajout_photo' && $user->rights->categorie->creer) {
163 if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
164 print '<a class="butAction hideonsmartphone" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
165 print $langs->trans("AddPhoto").'</a>';
166 } else {
167 print '<a class="butActionRefused classfortooltip hideonsmartphone" href="#">';
168 print $langs->trans("AddPhoto").'</a>';
169 }
170 }
171
172 print '</div>'."\n";
173
174 /*
175 * Ajouter une photo
176 */
177 if ($action == 'ajout_photo' && $user->rights->categorie->creer && !empty($conf->global->MAIN_UPLOAD_DOC)) {
178 // Affiche formulaire upload
179 $formfile = new FormFile($db);
180 $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);
181 }
182
183 // Affiche photos
184 if ($action != 'ajout_photo') {
185 $nbphoto = 0;
186 $nbbyrow = 5;
187
188 $maxWidth = 160;
189 $maxHeight = 120;
190
191 $pdir = get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/";
192 $dir = $upload_dir.'/'.$pdir;
193
194 $listofphoto = $object->liste_photos($dir);
195
196 if (is_array($listofphoto) && count($listofphoto)) {
197 print '<br>';
198 print '<table width="100%" valign="top" class="center centpercent">';
199
200 foreach ($listofphoto as $key => $obj) {
201 $nbphoto++;
202
203 if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) {
204 print '<tr class"center valignmiddle" border="1">';
205 }
206 if ($nbbyrow) {
207 print '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">';
208 }
209
210 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">';
211
212 // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
213 if ($obj['photo_vignette']) {
214 $filename = $obj['photo_vignette'];
215 } else {
216 $filename = $obj['photo'];
217 }
218
219 // Nom affiche
220 $viewfilename = $obj['photo'];
221
222 // Taille de l'image
223 $object->get_image_size($dir.$filename);
224 $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
225 $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
226
227 print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename).'">';
228
229 print '</a>';
230 print '<br>'.$viewfilename;
231 print '<br>';
232
233 // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
234 if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i', $obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) {
235 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>';
236 }
237 if ($user->rights->categorie->creer) {
238 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&type='.$type.'&file='.urlencode($pdir.$viewfilename).'">';
239 print img_delete().'</a>';
240 }
241 if ($nbbyrow) {
242 print '</td>';
243 }
244 if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) {
245 print '</tr>';
246 }
247 }
248
249 // Ferme tableau
250 while ($nbphoto % $nbbyrow) {
251 print '<td width="'.ceil(100 / $nbbyrow).'%">&nbsp;</td>';
252 $nbphoto++;
253 }
254
255 print '</table>';
256 }
257
258 if ($nbphoto < 1) {
259 print '<div class="opacitymedium">'.$langs->trans("NoPhotoYet")."</div>";
260 }
261 }
262} else {
263 print $langs->trans("ErrorUnknown");
264}
265
266// End of page
267llxFooter();
268$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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.
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...
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.