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