PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/photos.php

https://bitbucket.org/speedealing/speedealing
PHP | 197 lines | 108 code | 39 blank | 50 comment | 36 complexity | 76f286603c90d953b7817c47fb81fcc5 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 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. *
  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 3 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/product/photos.php
  22. * \ingroup product
  23. * \brief Onglet photos de la fiche produit
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29. $langs->load("products");
  30. $langs->load("bills");
  31. $id = GETPOST('id', 'int');
  32. $ref = GETPOST('ref', 'alpha');
  33. $action = GETPOST('action', 'alpha');
  34. $confirm = GETPOST('confirm', 'alpha');
  35. // Security check
  36. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  37. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  38. if ($user->societe_id) $socid=$user->societe_id;
  39. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  40. $mesg = '';
  41. $object = new Product($db);
  42. if ($id > 0 || ! empty($ref))
  43. {
  44. $result = $object->fetch($id, $ref);
  45. $dir = (! empty($conf->product->multidir_output[$object->entity])?$conf->product->multidir_output[$object->entity]:$conf->service->multidir_output[$object->entity]);
  46. }
  47. /*
  48. * Actions
  49. */
  50. if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  51. {
  52. if ($object->id) $result = $object->add_photo($dir, $_FILES['userfile']);
  53. }
  54. if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer))
  55. {
  56. $object->delete_photo($dir."/".$_GET["file"]);
  57. }
  58. if ($action == 'addthumb' && $_GET["file"])
  59. {
  60. $object->add_thumb($dir."/".$_GET["file"]);
  61. }
  62. /*
  63. * View
  64. */
  65. $form = new Form($db);
  66. if ($object->id)
  67. {
  68. llxHeader("","",$langs->trans("CardProduct".$object->type));
  69. /*
  70. * En mode visu
  71. */
  72. $head=product_prepare_head($object, $user);
  73. $titre=$langs->trans("CardProduct".$object->type);
  74. $picto=($object->type==1?'service':'product');
  75. dol_fiche_head($head, 'photos', $titre, 0, $picto);
  76. /*
  77. * Confirmation de la suppression de photo
  78. */
  79. if ($action == 'delete')
  80. {
  81. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
  82. if ($ret == 'html') print '<br>';
  83. }
  84. print($mesg);
  85. print '<table class="border" width="100%">';
  86. // Reference
  87. print '<tr>';
  88. print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="2">';
  89. print $form->showrefnav($object,'ref','',1,'ref');
  90. print '</td>';
  91. print '</tr>';
  92. // Libelle
  93. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$object->libelle.'</td>';
  94. print '</tr>';
  95. // Status (to sell)
  96. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
  97. print $object->getLibStatut(2,0);
  98. print '</td></tr>';
  99. // Status (to buy)
  100. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
  101. print $object->getLibStatut(2,1);
  102. print '</td></tr>';
  103. print "</table>\n";
  104. print "</div>\n";
  105. /* ************************************************************************** */
  106. /* */
  107. /* Barre d'action */
  108. /* */
  109. /* ************************************************************************** */
  110. print "\n<div class=\"tabsAction\">\n";
  111. if ($action != 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer))
  112. {
  113. if (! empty($conf->global->MAIN_UPLOAD_DOC))
  114. {
  115. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=ajout_photo&amp;id='.$object->id.'">';
  116. print $langs->trans("AddPhoto").'</a>';
  117. }
  118. else
  119. {
  120. print '<a class="butActionRefused" href="#">e';
  121. print $langs->trans("AddPhoto").'</a>';
  122. }
  123. }
  124. print "\n</div>\n";
  125. /*
  126. * Add a photo
  127. */
  128. if ($action == 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC))
  129. {
  130. // Affiche formulaire upload
  131. $formfile=new FormFile($db);
  132. $formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans("AddPhoto"),1);
  133. }
  134. // Affiche photos
  135. if ($action != 'ajout_photo')
  136. {
  137. $nbphoto=0;
  138. $nbbyrow=5;
  139. $maxWidth = 160;
  140. $maxHeight = 120;
  141. print $object->show_photos($dir,1,1000,$nbbyrow,1,1);
  142. if ($object->nbphoto < 1)
  143. {
  144. print '<br>';
  145. print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; print '<tr align=center valign=middle border=1><td class="photo">';
  146. print "<br>".$langs->trans("NoPhotoYet")."<br><br>";
  147. print '</td></tr>';
  148. print '</table>';
  149. }
  150. }
  151. }
  152. else
  153. {
  154. print $langs->trans("ErrorUnknown");
  155. }
  156. llxFooter();
  157. $db->close();
  158. ?>