photos.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. /**
  23. * \file htdocs/categories/photos.php
  24. * \ingroup category
  25. * \brief Gestion des photos d'une categorie
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
  32. // Load translation files required by the page
  33. $langs->loadlangs(array('categories', 'bills'));
  34. $id=GETPOST('id','int');
  35. $ref=GETPOST('ref');
  36. $type=GETPOST('type');
  37. $action=GETPOST('action','aZ09');
  38. $confirm=GETPOST('confirm');
  39. if (is_numeric($type)) $type=Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
  40. if ($id == "")
  41. {
  42. dol_print_error('','Missing parameter id');
  43. exit();
  44. }
  45. // Security check
  46. $result = restrictedArea($user, 'categorie', $id, '&category');
  47. $object = new Categorie($db);
  48. if ($id > 0)
  49. {
  50. $result = $object->fetch($id);
  51. $upload_dir = $conf->categorie->multidir_output[$object->entity];
  52. }
  53. /*
  54. * Actions
  55. */
  56. if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  57. {
  58. if ($object->id) {
  59. $file = $_FILES['userfile'];
  60. if (is_array($file['name']) && count($file['name']) > 0)
  61. {
  62. foreach ($file['name'] as $i => $name)
  63. {
  64. if(empty($file['tmp_name'][$i]) || intval($conf->global->MAIN_UPLOAD_DOC) * 1000 <= filesize($file['tmp_name'][$i]) )
  65. {
  66. setEventMessage($file['name'][$i] .' : '. $langs->trans(empty($file['tmp_name'][$i])? 'ErrorFailedToSaveFile' : 'MaxSizeForUploadedFiles' ) );
  67. unset($file['name'][$i],$file['type'][$i],$file['tmp_name'][$i],$file['error'][$i],$file['size'][$i]);
  68. }
  69. }
  70. }
  71. if(!empty($file['tmp_name'])) {
  72. $object->add_photo($upload_dir, $file);
  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. if ($action == 'addthumb' && $_GET["file"])
  81. {
  82. $object->addThumbs($upload_dir."/".$_GET["file"]);
  83. }
  84. /*
  85. * View
  86. */
  87. llxHeader("","",$langs->trans("Categories"));
  88. $form = new Form($db);
  89. $formother = new FormOther($db);
  90. if ($object->id)
  91. {
  92. if ($type == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductsCategoryShort");
  93. elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCategoryShort");
  94. elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoryShort");
  95. elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort");
  96. elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort");
  97. elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort");
  98. elseif ($type == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectsCategoriesShort");
  99. elseif ($type == Categorie::TYPE_USER) $title=$langs->trans("UsersCategoriesShort");
  100. else $title=$langs->trans("Category");
  101. $head = categories_prepare_head($object,$type);
  102. dol_fiche_head($head, 'photos', $title, -1, 'category');
  103. $linkback = '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("BackToList").'</a>';
  104. $object->ref = $object->label;
  105. $morehtmlref='<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
  106. $ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
  107. foreach ($ways as $way)
  108. {
  109. $morehtmlref.=$way."<br>\n";
  110. }
  111. $morehtmlref.='</div>';
  112. dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  113. /*
  114. * Confirmation de la suppression de photo
  115. */
  116. if ($action == 'delete')
  117. {
  118. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
  119. }
  120. print '<br>';
  121. print '<div class="fichecenter">';
  122. print '<div class="underbanner clearboth"></div>';
  123. print '<table class="border" width="100%">';
  124. // Description
  125. print '<tr><td class="titlefield notopnoleft">';
  126. print $langs->trans("Description").'</td><td>';
  127. print dol_htmlentitiesbr($object->description);
  128. print '</td></tr>';
  129. // Color
  130. print '<tr><td class="notopnoleft">';
  131. print $langs->trans("Color").'</td><td>';
  132. print $formother->showColor($object->color);
  133. print '</td></tr>';
  134. print "</table>\n";
  135. print '</div>';
  136. print dol_fiche_end();
  137. /* ************************************************************************** */
  138. /* */
  139. /* Barre d'action */
  140. /* */
  141. /* ************************************************************************** */
  142. print '<div class="tabsAction">'."\n";
  143. if ($action != 'ajout_photo' && $user->rights->categorie->creer)
  144. {
  145. if (! empty($conf->global->MAIN_UPLOAD_DOC))
  146. {
  147. print '<a class="butAction hideonsmartphone" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
  148. print $langs->trans("AddPhoto").'</a>';
  149. }
  150. else
  151. {
  152. print '<a class="butActionRefused hideonsmartphone" href="#">';
  153. print $langs->trans("AddPhoto").'</a>';
  154. }
  155. }
  156. print '</div>'."\n";
  157. /*
  158. * Ajouter une photo
  159. */
  160. if ($action == 'ajout_photo' && $user->rights->categorie->creer && ! empty($conf->global->MAIN_UPLOAD_DOC))
  161. {
  162. // Affiche formulaire upload
  163. $formfile=new FormFile($db);
  164. $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);
  165. }
  166. // Affiche photos
  167. if ($action != 'ajout_photo')
  168. {
  169. $nbphoto=0;
  170. $nbbyrow=5;
  171. $maxWidth = 160;
  172. $maxHeight = 120;
  173. $pdir = get_exdir($object->id,2,0,0,$object,'category') . $object->id ."/photos/";
  174. $dir = $upload_dir.'/'.$pdir;
  175. print '<br>';
  176. print '<table width="100%" valign="top" align="center">';
  177. foreach ($object->liste_photos($dir) as $key => $obj)
  178. {
  179. $nbphoto++;
  180. if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>';
  181. if ($nbbyrow) print '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
  182. print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">';
  183. // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
  184. if ($obj['photo_vignette'])
  185. {
  186. $filename=$obj['photo_vignette'];
  187. }
  188. else
  189. {
  190. $filename=$obj['photo'];
  191. }
  192. // Nom affiche
  193. $viewfilename=$obj['photo'];
  194. // Taille de l'image
  195. $object->get_image_size($dir.$filename);
  196. $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
  197. $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
  198. print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename).'">';
  199. print '</a>';
  200. print '<br>'.$viewfilename;
  201. print '<br>';
  202. // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
  203. if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight))
  204. {
  205. 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>';
  206. }
  207. if ($user->rights->categorie->creer)
  208. {
  209. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">';
  210. print img_delete().'</a>';
  211. }
  212. if ($nbbyrow) print '</td>';
  213. if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '</tr>';
  214. }
  215. // Ferme tableau
  216. while ($nbphoto % $nbbyrow)
  217. {
  218. print '<td width="'.ceil(100/$nbbyrow).'%">&nbsp;</td>';
  219. $nbphoto++;
  220. }
  221. print '</table>';
  222. if ($nbphoto < 1)
  223. {
  224. print '<div class="opacitymedium">'.$langs->trans("NoPhotoYet")."</div>";
  225. }
  226. }
  227. }
  228. else
  229. {
  230. print $langs->trans("ErrorUnknown");
  231. }
  232. // End of page
  233. llxFooter();
  234. $db->close();