PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 165 lines | 90 code | 35 blank | 40 comment | 14 complexity | 77c0a084370dc475722448af742466f9 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/product/document.php
  23. * \ingroup product
  24. * \brief Page des documents joints sur les produits
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. $langs->load("other");
  33. $langs->load("products");
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $action=GETPOST('action','alpha');
  37. $confirm=GETPOST('confirm','alpha');
  38. // Security check
  39. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  40. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  41. if ($user->societe_id) $socid=$user->societe_id;
  42. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  43. // Get parameters
  44. $sortfield = GETPOST("sortfield",'alpha');
  45. $sortorder = GETPOST("sortorder",'alpha');
  46. $page = GETPOST("page",'int');
  47. if ($page == -1) { $page = 0; }
  48. $offset = $conf->liste_limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if (! $sortorder) $sortorder="ASC";
  52. if (! $sortfield) $sortfield="name";
  53. $object = new Product($db);
  54. if ($id > 0 || ! empty($ref))
  55. {
  56. $result = $object->fetch($id, $ref);
  57. if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  58. elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  59. }
  60. $modulepart='produit';
  61. /*
  62. * Action envoie fichier
  63. */
  64. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  65. {
  66. dol_add_file_process($upload_dir,0,1,'userfile');
  67. }
  68. // Delete
  69. if ($action=='delete')
  70. {
  71. $langs->load("other");
  72. $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  73. $ret=dol_delete_file($file,0,0,0,$object);
  74. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  75. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  76. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  77. exit;
  78. }
  79. /*
  80. * View
  81. */
  82. $form = new Form($db);
  83. llxHeader("","",$langs->trans("CardProduct".$object->type));
  84. if ($object->id)
  85. {
  86. $head=product_prepare_head($object, $user);
  87. $titre=$langs->trans("CardProduct".$object->type);
  88. $picto=($object->type==1?'service':'product');
  89. dol_fiche_head($head, 'documents', $titre, 0, $picto);
  90. // Construit liste des fichiers
  91. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  92. $totalsize=0;
  93. foreach($filearray as $key => $file)
  94. {
  95. $totalsize+=$file['size'];
  96. }
  97. print '<table class="border" width="100%">';
  98. // Ref
  99. print '<tr>';
  100. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  101. print $form->showrefnav($object,'ref','',1,'ref');
  102. print '</td>';
  103. print '</tr>';
  104. // Label
  105. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$object->libelle.'</td></tr>';
  106. // Status (to sell)
  107. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
  108. print $object->getLibStatut(2,0);
  109. print '</td></tr>';
  110. // Status (to buy)
  111. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
  112. print $object->getLibStatut(2,1);
  113. print '</td></tr>';
  114. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  115. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  116. print '</table>';
  117. print '</div>';
  118. // Affiche formulaire upload
  119. $formfile=new FormFile($db);
  120. $formfile->form_attach_new_file(DOL_URL_ROOT.'/product/document.php?id='.$object->id,'',0,0,($user->rights->produit->creer||$user->rights->service->creer),50,$object);
  121. // List of document
  122. $formfile->list_of_documents($filearray,$object,'produit');
  123. }
  124. else
  125. {
  126. print $langs->trans("UnkownError");
  127. }
  128. llxFooter();
  129. $db->close();
  130. ?>