dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("categories");
36 $langs->load("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  $object->add_photo($upload_dir, $_FILES['userfile']);
73  }
74 }
75 
76 if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer)
77 {
78  $object->delete_photo($upload_dir."/".$_GET["file"]);
79 }
80 
81 if ($action == 'addthumb' && $_GET["file"])
82 {
83  $object->addThumbs($upload_dir."/".$_GET["file"]);
84 }
85 
86 
87 /*
88  * View
89  */
90 
91 llxHeader("","",$langs->trans("Categories"));
92 
93 $form = new Form($db);
94 $formother = new FormOther($db);
95 
96 if ($object->id)
97 {
98  if ($type == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductsCategoryShort");
99  elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCategoryShort");
100  elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoryShort");
101  elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort");
102  elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort");
103  elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort");
104  elseif ($type == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectsCategoriesShort");
105  elseif ($type == Categorie::TYPE_USER) $title=$langs->trans("UsersCategoriesShort");
106  else $title=$langs->trans("Category");
107 
108  $head = categories_prepare_head($object,$type);
109 
110 
111  dol_fiche_head($head, 'photos', $title, -1, 'category');
112 
113  $linkback = '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("BackToList").'</a>';
114 
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  {
120  $morehtmlref.=$way."<br>\n";
121  }
122  $morehtmlref.='</div>';
123 
124  dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
125 
126  /*
127  * Confirmation de la suppression de photo
128  */
129  if ($action == 'delete')
130  {
131  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
132  }
133 
134  print '<br>';
135 
136  print '<div class="fichecenter">';
137  print '<div class="underbanner clearboth"></div>';
138  print '<table class="border" width="100%">';
139 
140  // Description
141  print '<tr><td class="titlefield notopnoleft">';
142  print $langs->trans("Description").'</td><td>';
143  print dol_htmlentitiesbr($object->description);
144  print '</td></tr>';
145 
146  // Color
147  print '<tr><td class="notopnoleft">';
148  print $langs->trans("Color").'</td><td>';
149  print $formother->showColor($object->color);
150  print '</td></tr>';
151 
152  print "</table>\n";
153  print '</div>';
154 
156 
157 
158 
159  /* ************************************************************************** */
160  /* */
161  /* Barre d'action */
162  /* */
163  /* ************************************************************************** */
164 
165  print '<div class="tabsAction">'."\n";
166 
167  if ($action != 'ajout_photo' && $user->rights->categorie->creer)
168  {
169  if (! empty($conf->global->MAIN_UPLOAD_DOC))
170  {
171  print '<a class="butAction hideonsmartphone" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
172  print $langs->trans("AddPhoto").'</a>';
173  }
174  else
175  {
176  print '<a class="butActionRefused hideonsmartphone" href="#">';
177  print $langs->trans("AddPhoto").'</a>';
178  }
179  }
180 
181  print '</div>'."\n";
182 
183  /*
184  * Ajouter une photo
185  */
186  if ($action == 'ajout_photo' && $user->rights->categorie->creer && ! empty($conf->global->MAIN_UPLOAD_DOC))
187  {
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->rights->categorie->creer, 50, $object, '', false, '', 0);
191  }
192 
193  // Affiche photos
194  if ($action != 'ajout_photo')
195  {
196  $nbphoto=0;
197  $nbbyrow=5;
198 
199  $maxWidth = 160;
200  $maxHeight = 120;
201 
202  $pdir = get_exdir($object->id,2,0,0,$object,'category') . $object->id ."/photos/";
203  $dir = $upload_dir.'/'.$pdir;
204 
205  print '<br>';
206  print '<table width="100%" valign="top" align="center">';
207 
208  foreach ($object->liste_photos($dir) as $key => $obj)
209  {
210  $nbphoto++;
211 
212 
213  if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>';
214  if ($nbbyrow) print '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
215 
216  print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">';
217 
218  // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
219  if ($obj['photo_vignette'])
220  {
221  $filename=$obj['photo_vignette'];
222  }
223  else
224  {
225  $filename=$obj['photo'];
226  }
227 
228  // Nom affiche
229  $viewfilename=$obj['photo'];
230 
231  // Taille de l'image
232  $object->get_image_size($dir.$filename);
233  $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
234  $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
235 
236  print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename).'">';
237 
238  print '</a>';
239  print '<br>'.$viewfilename;
240  print '<br>';
241 
242  // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
243  if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight))
244  {
245  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>';
246  }
247  if ($user->rights->categorie->creer)
248  {
249  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">';
250  print img_delete().'</a>';
251  }
252  if ($nbbyrow) print '</td>';
253  if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '</tr>';
254  }
255 
256  // Ferme tableau
257  while ($nbphoto % $nbbyrow)
258  {
259  print '<td width="'.ceil(100/$nbbyrow).'%">&nbsp;</td>';
260  $nbphoto++;
261  }
262 
263  print '</table>';
264 
265  if ($nbphoto < 1)
266  {
267  print '<div class="opacitymedium">'.$langs->trans("NoPhotoYet")."</div>";
268  }
269  }
270 }
271 else
272 {
273  print $langs->trans("ErrorUnknown");
274 }
275 
276 
277 llxFooter();
278 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
if(!GETPOST('transkey')&&!GETPOST('transphrase')) else
View.
Definition: notice.php:43
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
Class to manage categories.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
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:46
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
Class to offer components to list and upload files.
print
Draft customers invoices.
Definition: index.php:91
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.
type
Definition: viewcat.php:283
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.