PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/fourn/product/photos.php

https://bitbucket.org/speedealing/speedealing
PHP | 216 lines | 126 code | 48 blank | 42 comment | 35 complexity | 7fa222f0196fadb39c80fabfe2b7aa22 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/fourn/product/photos.php
  20. * \ingroup product
  21. * \brief Page de la fiche produit
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  25. $id = GETPOST('id', 'int');
  26. if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbidden();
  27. $object = new Product($db);
  28. /*
  29. * View
  30. */
  31. if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  32. {
  33. if ($id)
  34. {
  35. $result = $object->fetch($id);
  36. $object->add_photo($conf->product->multidir_output[$object->entity], $_FILES['photofile']);
  37. }
  38. }
  39. /*
  40. *
  41. */
  42. llxHeader("","",$langs->trans("CardProduct0"));
  43. /*
  44. * Fiche produit
  45. */
  46. if ($id)
  47. {
  48. $result = $object->fetch($id);
  49. if ( $result )
  50. {
  51. /*
  52. * En mode visu
  53. */
  54. $h=0;
  55. $head[$h][0] = DOL_URL_ROOT."/fourn/product/fiche.php?id=".$object->id;
  56. $head[$h][1] = $langs->trans("Card");
  57. $h++;
  58. if (! empty($conf->stock->enabled))
  59. {
  60. $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$object->id;
  61. $head[$h][1] = $langs->trans("Stock");
  62. $h++;
  63. }
  64. $head[$h][0] = DOL_URL_ROOT."/fourn/product/photos.php?id=".$object->id;
  65. $head[$h][1] = $langs->trans("Photos");
  66. $hselected = $h;
  67. $h++;
  68. //Affichage onglet Categories
  69. if (! empty($conf->categorie->enabled)){
  70. $head[$h][0] = DOL_URL_ROOT."/fourn/product/categorie.php?id=".$object->id;
  71. $head[$h][1] = $langs->trans('Categories');
  72. $h++;
  73. }
  74. $head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$object->id;
  75. $head[$h][1] = $langs->trans("CommercialCard");
  76. $h++;
  77. dol_fiche_head($head, $hselected, $langs->trans("CardProduct".$object->type).' : '.$object->ref);
  78. print($mesg);
  79. print '<table class="border" width="100%">';
  80. print "<tr>";
  81. print '<td>'.$langs->trans("Ref").'</td><td>'.$object->ref.'</td>';
  82. print '<td colspan="2">';
  83. print $object->getLibStatut(2);
  84. print '</td></tr>';
  85. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->libelle.'</td>';
  86. print '<td>'.$langs->trans("SellingPrice").'</td><td>'.price($object->price).'</td></tr>';
  87. print "</table><br>\n";
  88. /*
  89. * Ajouter une photo
  90. *
  91. */
  92. if ($action == 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC))
  93. {
  94. print_titre($langs->trans("AddPhoto"));
  95. print '<form name="userfile" action="photos.php?id='.$object->id.'" enctype="multipart/form-data" METHOD="POST">';
  96. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  97. print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
  98. print '<table class="border" width="100%"><tr>';
  99. print '<td>'.$langs->trans("File").'</td>';
  100. print '<td><input type="file" name="photofile"></td></tr>';
  101. print '<tr><td colspan="4" align="center">';
  102. print '<input type="submit" name="sendit" value="'.$langs->trans("Save").'">&nbsp;';
  103. print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
  104. print '</table>';
  105. print '</form><br>';
  106. }
  107. // Affiche photos
  108. if ($action != 'ajout_photo')
  109. {
  110. $nbphoto=0;
  111. $nbbyrow=5;
  112. $pdir = get_exdir($object->id,2) . $object->id ."/photos/";
  113. $dir = $conf->product->multidir_output[$object->entity] . '/'. $pdir;
  114. print '<br><table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
  115. foreach ($object->liste_photos($dir) as $obj)
  116. {
  117. $nbphoto++;
  118. // if ($nbbyrow && $nbphoto == 1) print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
  119. if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>';
  120. if ($nbbyrow) print '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
  121. print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">';
  122. // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
  123. if ($obj['photo_vignette']) $filename=$obj['photo_vignette'];
  124. else $filename=$obj['photo'];
  125. print '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$filename).'">';
  126. print '</a>';
  127. print '<br>'.$langs->trans("File").': '.dol_trunc($filename,16);
  128. if ($user->rights->produit->creer || $user->rights->service->creer)
  129. {
  130. print '<br><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;file='.urlencode($pdir.$filename).'">'.img_delete().'</a>';
  131. }
  132. if ($nbbyrow) print '</td>';
  133. if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '</tr>';
  134. }
  135. // Ferme tableau
  136. while ($nbphoto % $nbbyrow)
  137. {
  138. print '<td width="'.ceil(100/$nbbyrow).'%">&nbsp;</td>';
  139. $nbphoto++;
  140. }
  141. if ($nbphoto < 1)
  142. {
  143. print '<tr align=center valign=middle border=1><td class="photo">';
  144. print "<br>".$langs->trans("NoPhotoYet")."<br><br>";
  145. print '</td></tr></table>';
  146. }
  147. print '</table>';
  148. }
  149. print "</div>\n";
  150. }
  151. print "\n<div class=\"tabsAction\">\n";
  152. if ($action == '')
  153. {
  154. if (($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC))
  155. {
  156. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=ajout_photo&amp;id='.$object->id.'">';
  157. print $langs->trans("AddPhoto").'</a>';
  158. }
  159. }
  160. print "\n</div>\n";
  161. }
  162. else
  163. {
  164. print $langs->trans("ErrorUnknown");
  165. }
  166. llxFooter();
  167. $db->close();
  168. ?>