dolibarr  13.0.2
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 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
34 
35 // Load translation files required by the page
36 $langs->loadlangs(array('categories', 'bills'));
37 
38 
39 $id = GETPOST('id', 'int');
40 $label = GETPOST('label', 'alpha');
41 $type = GETPOST('type');
42 $action = GETPOST('action', 'aZ09');
43 $confirm = GETPOST('confirm');
44 
45 if ($id == '' && $label == '')
46 {
47  dol_print_error('', 'Missing parameter id');
48  exit();
49 }
50 
51 // Security check
52 $result = restrictedArea($user, 'categorie', $id, '&category');
53 
54 $object = new Categorie($db);
55 $result = $object->fetch($id, $label, $type);
56 if ($result <= 0) {
57  dol_print_error($db, $object->error); exit;
58 }
59 $object->fetch_optionals();
60 if ($result <= 0) {
61  dol_print_error($db, $object->error); exit;
62 }
63 $upload_dir = $conf->categorie->multidir_output[$object->entity];
64 
65 if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
66 
67 /*
68  * Actions
69  */
70 
71 if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && $_POST["sendit"] && !empty($conf->global->MAIN_UPLOAD_DOC))
72 {
73  if ($object->id) {
74  $file = $_FILES['userfile'];
75  if (is_array($file['name']) && count($file['name']) > 0)
76  {
77  foreach ($file['name'] as $i => $name)
78  {
79  if (empty($file['tmp_name'][$i]) || intval($conf->global->MAIN_UPLOAD_DOC) * 1000 <= filesize($file['tmp_name'][$i]))
80  {
81  setEventMessage($file['name'][$i].' : '.$langs->trans(empty($file['tmp_name'][$i]) ? 'ErrorFailedToSaveFile' : 'MaxSizeForUploadedFiles'));
82  unset($file['name'][$i], $file['type'][$i], $file['tmp_name'][$i], $file['error'][$i], $file['size'][$i]);
83  }
84  }
85  }
86 
87  if (!empty($file['tmp_name'])) {
88  $object->add_photo($upload_dir, $file);
89  }
90  }
91 }
92 
93 if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer)
94 {
95  $object->delete_photo($upload_dir."/".$_GET["file"]);
96 }
97 
98 if ($action == 'addthumb' && $_GET["file"])
99 {
100  $object->addThumbs($upload_dir."/".$_GET["file"]);
101 }
102 
103 
104 /*
105  * View
106  */
107 
108 llxHeader("", "", $langs->trans("Categories"));
109 
110 $form = new Form($db);
111 $formother = new FormOther($db);
112 
113 if ($object->id)
114 {
115  $title = Categorie::$MAP_TYPE_TITLE_AREA[$type];
116 
117  $head = categories_prepare_head($object, $type);
118 
119 
120  print dol_get_fiche_head($head, 'photos', $langs->trans($title), -1, 'category');
121 
122  $linkback = '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("BackToList").'</a>';
123  $object->next_prev_filter = ' type = '.$object->type;
124  $object->ref = $object->label;
125  $morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
126  $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
127  foreach ($ways as $way)
128  {
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  {
140  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
141  }
142 
143  print '<br>';
144 
145  print '<div class="fichecenter">';
146  print '<div class="underbanner clearboth"></div>';
147  print '<table class="border centpercent tableforfield">';
148 
149  // Description
150  print '<tr><td class="titlefield notopnoleft">';
151  print $langs->trans("Description").'</td><td>';
152  print dol_htmlentitiesbr($object->description);
153  print '</td></tr>';
154 
155  // Color
156  print '<tr><td class="notopnoleft">';
157  print $langs->trans("Color").'</td><td>';
158  print $formother->showColor($object->color);
159  print '</td></tr>';
160 
161  print "</table>\n";
162  print '</div>';
163 
165 
166 
167 
168  /* ************************************************************************** */
169  /* */
170  /* Barre d'action */
171  /* */
172  /* ************************************************************************** */
173 
174  print '<div class="tabsAction">'."\n";
175 
176  if ($action != 'ajout_photo' && $user->rights->categorie->creer)
177  {
178  if (!empty($conf->global->MAIN_UPLOAD_DOC))
179  {
180  print '<a class="butAction hideonsmartphone" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
181  print $langs->trans("AddPhoto").'</a>';
182  } else {
183  print '<a class="butActionRefused classfortooltip hideonsmartphone" href="#">';
184  print $langs->trans("AddPhoto").'</a>';
185  }
186  }
187 
188  print '</div>'."\n";
189 
190  /*
191  * Ajouter une photo
192  */
193  if ($action == 'ajout_photo' && $user->rights->categorie->creer && !empty($conf->global->MAIN_UPLOAD_DOC))
194  {
195  // Affiche formulaire upload
196  $formfile = new FormFile($db);
197  $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);
198  }
199 
200  // Affiche photos
201  if ($action != 'ajout_photo')
202  {
203  $nbphoto = 0;
204  $nbbyrow = 5;
205 
206  $maxWidth = 160;
207  $maxHeight = 120;
208 
209  $pdir = get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/";
210  $dir = $upload_dir.'/'.$pdir;
211 
212  $listofphoto = $object->liste_photos($dir);
213 
214  if (is_array($listofphoto) && count($listofphoto))
215  {
216  print '<br>';
217  print '<table width="100%" valign="top" align="center">';
218 
219  foreach ($listofphoto as $key => $obj)
220  {
221  $nbphoto++;
222 
223  if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>';
224  if ($nbbyrow) print '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">';
225 
226  print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">';
227 
228  // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
229  if ($obj['photo_vignette'])
230  {
231  $filename = $obj['photo_vignette'];
232  } else {
233  $filename = $obj['photo'];
234  }
235 
236  // Nom affiche
237  $viewfilename = $obj['photo'];
238 
239  // Taille de l'image
240  $object->get_image_size($dir.$filename);
241  $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
242  $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
243 
244  print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename).'">';
245 
246  print '</a>';
247  print '<br>'.$viewfilename;
248  print '<br>';
249 
250  // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
251  if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i', $obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight))
252  {
253  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addthumb&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').'&nbsp;&nbsp;</a>';
254  }
255  if ($user->rights->categorie->creer)
256  {
257  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">';
258  print img_delete().'</a>';
259  }
260  if ($nbbyrow) print '</td>';
261  if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '</tr>';
262  }
263 
264  // Ferme tableau
265  while ($nbphoto % $nbbyrow)
266  {
267  print '<td width="'.ceil(100 / $nbbyrow).'%">&nbsp;</td>';
268  $nbphoto++;
269  }
270 
271  print '</table>';
272  }
273 
274  if ($nbphoto < 1)
275  {
276  print '<div class="opacitymedium">'.$langs->trans("NoPhotoYet")."</div>";
277  }
278  }
279 } else {
280  print $langs->trans("ErrorUnknown");
281 }
282 
283 // End of page
284 llxFooter();
285 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
categories_prepare_head(Categorie $object, $type)
Prepare array with list of tabs.
setEventMessage($mesgs, $style= 'mesgs')
Set event message 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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
Class to manage categories.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
Classe permettant la generation de composants html autre Only common components are here...
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, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.