PageRenderTime 45ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/categories/photos.php

https://github.com/asterix14/dolibarr
PHP | 308 lines | 158 code | 57 blank | 93 comment | 53 complexity | ac20a985d9700416042926149ba7d18d MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/categories/photos.php
  22. * \ingroup category
  23. * \brief Gestion des photos d'une categorie
  24. */
  25. require("../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/categories.lib.php");
  29. $langs->load("categories");
  30. $langs->load("bills");
  31. $mesg = '';
  32. $id=GETPOST('id');
  33. $ref=GETPOST('ref');
  34. $type=GETPOST('type');
  35. $action=GETPOST('action');
  36. $confirm=GETPOST('confirm');
  37. if ($id == "")
  38. {
  39. dol_print_error('','Missing parameter id');
  40. exit();
  41. }
  42. // Security check
  43. $result = restrictedArea($user, 'categorie', $id);
  44. $object = new Categorie($db);
  45. /*
  46. * Actions
  47. */
  48. if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  49. {
  50. if ($id)
  51. {
  52. $result = $object->fetch($id);
  53. $result = $object->add_photo($conf->categorie->dir_output, $_FILES['userfile']);
  54. }
  55. }
  56. if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer)
  57. {
  58. $object->delete_photo($conf->categorie->dir_output."/".$_GET["file"]);
  59. }
  60. if ($action == 'addthumb' && $_GET["file"])
  61. {
  62. $object->add_thumb($conf->categorie->dir_output."/".$_GET["file"]);
  63. }
  64. /*
  65. * View
  66. */
  67. llxHeader("","",$langs->trans("Categories"));
  68. $form = new Form($db);
  69. if (!empty($id) || !empty($ref))
  70. {
  71. $result = $object->fetch($id);
  72. if ($result)
  73. {
  74. $title=$langs->trans("ProductsCategoryShort");
  75. if ($type == 0) $title=$langs->trans("ProductsCategoryShort");
  76. elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort");
  77. elseif ($type == 2) $title=$langs->trans("CustomersCategoryShort");
  78. elseif ($type == 3) $title=$langs->trans("MembersCategoryShort");
  79. $head = categories_prepare_head($object,$type);
  80. dol_fiche_head($head, 'photos', $title, 0, 'category');
  81. /*
  82. * Confirmation de la suppression de photo
  83. */
  84. if ($action == 'delete')
  85. {
  86. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
  87. if ($ret == 'html') print '<br>';
  88. }
  89. print($mesg);
  90. print '<table class="border" width="100%">';
  91. // Path of category
  92. print '<tr><td width="20%" class="notopnoleft">';
  93. $ways = $object->print_all_ways();
  94. print $langs->trans("Ref").'</td><td>';
  95. print '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
  96. foreach ($ways as $way)
  97. {
  98. print $way."<br>\n";
  99. }
  100. print '</td></tr>';
  101. // Description
  102. print '<tr><td width="20%" class="notopnoleft">';
  103. print $langs->trans("Description").'</td><td>';
  104. print nl2br($object->description);
  105. print '</td></tr>';
  106. // Visibility
  107. /* if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)
  108. {
  109. if ($object->socid)
  110. {
  111. $soc = new Societe($db);
  112. $soc->fetch($object->socid);
  113. print '<tr><td width="20%" class="notopnoleft">';
  114. print $langs->trans("AssignedToTheCustomer").'</td><td>';
  115. print $soc->getNomUrl(1);
  116. print '</td></tr>';
  117. $catsMeres = $object->get_meres ();
  118. if ($catsMeres < 0)
  119. {
  120. dol_print_error();
  121. }
  122. else if (count($catsMeres) > 0)
  123. {
  124. print '<tr><td width="20%" class="notopnoleft">';
  125. print $langs->trans("CategoryContents").'</td><td>';
  126. print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible"));
  127. print '</td></tr>';
  128. }
  129. }
  130. else
  131. {
  132. print '<tr><td width="20%" class="notopnoleft">';
  133. print $langs->trans("CategoryContents").'</td><td>';
  134. print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible"));
  135. print '</td></tr>';
  136. }
  137. }
  138. else
  139. {
  140. print '<tr><td width="20%" class="notopnoleft">';
  141. print $langs->trans("CategoryContents").'</td><td>';
  142. print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible"));
  143. print '</td></tr>';
  144. }
  145. */
  146. print "</table>\n";
  147. print "</div>\n";
  148. /* ************************************************************************** */
  149. /* */
  150. /* Barre d'action */
  151. /* */
  152. /* ************************************************************************** */
  153. print "\n<div class=\"tabsAction\">\n";
  154. if ($action != 'ajout_photo' && $user->rights->produit->creer)
  155. {
  156. if (! empty($conf->global->MAIN_UPLOAD_DOC))
  157. {
  158. print '<a class="butAction" href="'.DOL_URL_ROOT.'/categories/photos.php?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
  159. print $langs->trans("AddPhoto").'</a>';
  160. }
  161. else
  162. {
  163. print '<a class="butActionRefused" href="#">';
  164. print $langs->trans("AddPhoto").'</a>';
  165. }
  166. }
  167. print "\n</div>\n";
  168. /*
  169. * Ajouter une photo
  170. */
  171. if ($action == 'ajout_photo' && $user->rights->categorie->creer && ! empty($conf->global->MAIN_UPLOAD_DOC))
  172. {
  173. // Affiche formulaire upload
  174. $formfile=new FormFile($db);
  175. $formfile->form_attach_new_file(DOL_URL_ROOT.'/categories/photos.php?id='.$object->id.'&amp;type='.$type,$langs->trans("AddPhoto"),1);
  176. }
  177. // Affiche photos
  178. if ($action != 'ajout_photo')
  179. {
  180. $nbphoto=0;
  181. $nbbyrow=5;
  182. $maxWidth = 160;
  183. $maxHeight = 120;
  184. $pdir = get_exdir($object->id,2) . $object->id ."/photos/";
  185. $dir = $conf->categorie->dir_output.'/'.$pdir;
  186. print '<br>';
  187. print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
  188. foreach ($object->liste_photos($dir) as $key => $obj)
  189. {
  190. $nbphoto++;
  191. if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>';
  192. if ($nbbyrow) print '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
  193. print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=categorie&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">';
  194. // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
  195. if ($obj['photo_vignette'])
  196. {
  197. $filename='thumbs/'.$obj['photo_vignette'];
  198. }
  199. else
  200. {
  201. $filename=$obj['photo'];
  202. }
  203. // Nom affiche
  204. $viewfilename=$obj['photo'];
  205. // Taille de l'image
  206. $object->get_image_size($dir.$filename);
  207. $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
  208. $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
  209. print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=categorie&file='.urlencode($pdir.$filename).'">';
  210. print '</a>';
  211. print '<br>'.$viewfilename;
  212. print '<br>';
  213. // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
  214. if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight))
  215. {
  216. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=addthumb&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').'&nbsp;&nbsp;</a>';
  217. }
  218. if ($user->rights->categorie->creer)
  219. {
  220. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=delete&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">';
  221. print img_delete().'</a>';
  222. }
  223. if ($nbbyrow) print '</td>';
  224. if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '</tr>';
  225. }
  226. // Ferme tableau
  227. while ($nbphoto % $nbbyrow)
  228. {
  229. print '<td width="'.ceil(100/$nbbyrow).'%">&nbsp;</td>';
  230. $nbphoto++;
  231. }
  232. if ($nbphoto < 1)
  233. {
  234. print '<tr align=center valign=middle border=1><td class="photo">';
  235. print "<br>".$langs->trans("NoPhotoYet")."<br><br>";
  236. print '</td></tr>';
  237. }
  238. print '</table>';
  239. }
  240. }
  241. }
  242. else
  243. {
  244. print $langs->trans("ErrorUnknown");
  245. }
  246. $db->close();
  247. llxFooter();
  248. ?>