document.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 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@inodbox.com>
  6. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  7. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/reception/document.php
  24. * \ingroup reception
  25. * \brief Management page of documents attached to an reception
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
  35. if (isModEnabled('project')) {
  36. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  37. }
  38. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
  40. // Load translation files required by the page
  41. $langs->loadLangs(array('receptions', 'companies', 'other'));
  42. $action = GETPOST('action', 'aZ09');
  43. $confirm = GETPOST('confirm');
  44. $id = GETPOST('id', 'int');
  45. $ref = GETPOST('ref');
  46. // Get parameters
  47. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  48. $sortfield = GETPOST('sortfield', 'aZ09comma');
  49. $sortorder = GETPOST('sortorder', 'aZ09comma');
  50. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  51. if (empty($page) || $page == -1) {
  52. $page = 0;
  53. } // If $page is not defined, or '' or -1
  54. $offset = $limit * $page;
  55. $pageprev = $page - 1;
  56. $pagenext = $page + 1;
  57. if (!$sortorder) {
  58. $sortorder = "ASC";
  59. }
  60. if (!$sortfield) {
  61. $sortfield = "name";
  62. }
  63. $object = new Reception($db);
  64. if ($id > 0 || !empty($ref)) {
  65. $object->fetch($id, $ref);
  66. $object->fetch_thirdparty();
  67. if (!empty($object->origin)) {
  68. $origin = $object->origin;
  69. $object->fetch_origin();
  70. $typeobject = $object->origin;
  71. }
  72. // Linked documents
  73. if ($origin == 'order_supplier' && $object->$typeobject->id && isModEnabled("supplier_order")) {
  74. $objectsrc = new CommandeFournisseur($db);
  75. $objectsrc->fetch($object->$typeobject->id);
  76. }
  77. $upload_dir = $conf->reception->dir_output."/".dol_sanitizeFileName($object->ref);
  78. }
  79. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  80. $hookmanager->initHooks(array('receptiondocument'));
  81. // Security check
  82. if ($user->socid > 0) {
  83. $socid = $user->socid;
  84. }
  85. $result = restrictedArea($user, 'reception', $object->id, '');
  86. if (isModEnabled("reception")) {
  87. $permissiontoread = $user->rights->reception->lire;
  88. $permissiontoadd = $user->rights->reception->creer;
  89. $permissiondellink = $user->rights->reception->creer; // Used by the include of actions_dellink.inc.php
  90. $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->reception->creer)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->reception->reception_advance->validate)));
  91. $permissiontodelete = $user->rights->reception->supprimer;
  92. } else {
  93. $permissiontoread = $user->rights->fournisseur->commande->receptionner;
  94. $permissiontoadd = $user->rights->fournisseur->commande->receptionner;
  95. $permissiondellink = $user->rights->fournisseur->commande->receptionner; // Used by the include of actions_dellink.inc.php
  96. $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->fournisseur->commande->receptionner)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->fournisseur->commande_advance->check)));
  97. $permissiontodelete = $user->rights->fournisseur->commande->receptionner;
  98. }
  99. /*
  100. * Actions
  101. */
  102. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  103. /*
  104. * View
  105. */
  106. llxHeader('', $langs->trans('Reception'), '');
  107. $form = new Form($db);
  108. if ($id > 0 || !empty($ref)) {
  109. if ($object->fetch($id, $ref)) {
  110. $object->fetch_thirdparty();
  111. $upload_dir = $conf->reception->dir_output.'/'.dol_sanitizeFileName($object->ref);
  112. $head = reception_prepare_head($object);
  113. print dol_get_fiche_head($head, 'documents', $langs->trans("Shipment"), -1, $object->picto);
  114. // Build file list
  115. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  116. $totalsize = 0;
  117. foreach ($filearray as $key => $file) {
  118. $totalsize += $file['size'];
  119. }
  120. // Shipment card
  121. $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  122. $morehtmlref = '<div class="refidno">';
  123. // Ref customer reception
  124. $morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', 0, 1);
  125. $morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', null, null, '', 1);
  126. // Thirdparty
  127. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  128. // Project
  129. if (isModEnabled('project')) {
  130. $langs->load("projects");
  131. $morehtmlref .= '<br>';
  132. if (0) { // Do not change on reception
  133. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  134. if ($action != 'classify' && $permissiontoadd) {
  135. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  136. }
  137. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  138. } else {
  139. if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
  140. $proj = new Project($db);
  141. $proj->fetch($objectsrc->fk_project);
  142. $morehtmlref .= $proj->getNomUrl(1);
  143. if ($proj->title) {
  144. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  145. }
  146. }
  147. }
  148. }
  149. $morehtmlref .= '</div>';
  150. // Order card
  151. $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  152. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  153. print '<div class="fichecenter">';
  154. print '<div class="underbanner clearboth"></div>';
  155. print '<table class="border tableforfield centpercent">';
  156. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  157. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  158. print "</table>\n";
  159. print "</div>\n";
  160. print dol_get_fiche_end();
  161. $modulepart = 'reception';
  162. $permissiontoadd = $user->rights->reception->creer;
  163. $permtoedit = $user->rights->reception->creer;
  164. $param = '&id='.$object->id;
  165. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  166. } else {
  167. dol_print_error($db);
  168. }
  169. } else {
  170. header('Location: index.php');
  171. exit;
  172. }
  173. // End of page
  174. llxFooter();
  175. $db->close();