document.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/product/document.php
  25. * \ingroup product
  26. * \brief Page des documents joints sur les produits
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. $langs->load("other");
  35. $langs->load("products");
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $action=GETPOST('action','alpha');
  39. $confirm=GETPOST('confirm','alpha');
  40. // Security check
  41. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  42. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  43. if ($user->societe_id) $socid=$user->societe_id;
  44. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  45. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  46. $hookmanager->initHooks(array('productdocuments'));
  47. // Get parameters
  48. $sortfield = GETPOST("sortfield",'alpha');
  49. $sortorder = GETPOST("sortorder",'alpha');
  50. $page = GETPOST("page",'int');
  51. if ($page == -1) { $page = 0; }
  52. $offset = $conf->liste_limit * $page;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. if (! $sortorder) $sortorder="ASC";
  56. if (! $sortfield) $sortfield="name";
  57. $object = new Product($db);
  58. if ($id > 0 || ! empty($ref))
  59. {
  60. $result = $object->fetch($id, $ref);
  61. if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  62. elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  63. }
  64. $modulepart='produit';
  65. $parameters=array('id'=>$id);
  66. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  67. /*
  68. * Action envoie fichier
  69. */
  70. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
  71. /*
  72. * View
  73. */
  74. $form = new Form($db);
  75. llxHeader("","",$langs->trans("CardProduct".$object->type));
  76. if ($object->id)
  77. {
  78. $head=product_prepare_head($object, $user);
  79. $titre=$langs->trans("CardProduct".$object->type);
  80. $picto=($object->type==1?'service':'product');
  81. dol_fiche_head($head, 'documents', $titre, 0, $picto);
  82. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  83. // Construit liste des fichiers
  84. $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  85. $totalsize=0;
  86. foreach($filearray as $key => $file)
  87. {
  88. $totalsize+=$file['size'];
  89. }
  90. print '<table class="border" width="100%">';
  91. // Ref
  92. print '<tr>';
  93. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  94. print $form->showrefnav($object,'ref','',1,'ref');
  95. print '</td>';
  96. print '</tr>';
  97. // Label
  98. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$object->libelle.'</td></tr>';
  99. // Status (to sell)
  100. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
  101. print $object->getLibStatut(2,0);
  102. print '</td></tr>';
  103. // Status (to buy)
  104. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
  105. print $object->getLibStatut(2,1);
  106. print '</td></tr>';
  107. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  108. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  109. print '</table>';
  110. print '</div>';
  111. $modulepart = 'produit';
  112. $permission = $user->rights->produit->creer;
  113. $param = '&id=' . $object->id;
  114. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  115. }
  116. else
  117. {
  118. print $langs->trans("ErrorUnknown");
  119. }
  120. llxFooter();
  121. $db->close();