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

/htdocs/expedition/document.php

http://github.com/Dolibarr/dolibarr
PHP | 197 lines | 117 code | 36 blank | 44 comment | 25 complexity | a867be844b3b306504d34a10da15f57a MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  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/expedition/document.php
  24. * \ingroup expedition
  25. * \brief Management page of documents attached to an expedition
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.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/lib/sendings.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  34. if (!empty($conf->projet->enabled)) {
  35. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  36. }
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('companies', 'other'));
  39. $action = GETPOST('action', 'aZ09');
  40. $confirm = GETPOST('confirm');
  41. $id = GETPOST('id', 'int');
  42. $ref = GETPOST('ref');
  43. // Get parameters
  44. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST("sortfield", 'alpha');
  46. $sortorder = GETPOST("sortorder", 'alpha');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page == -1) {
  49. $page = 0;
  50. } // If $page is not defined, or '' or -1
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (!$sortorder) {
  55. $sortorder = "ASC";
  56. }
  57. if (!$sortfield) {
  58. $sortfield = "name";
  59. }
  60. $object = new Expedition($db);
  61. if ($object->fetch($id, $ref)) {
  62. $object->fetch_thirdparty();
  63. $upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($object->ref);
  64. }
  65. // Security check
  66. if ($user->socid) {
  67. $socid = $user->socid;
  68. }
  69. $result = restrictedArea($user, 'expedition', $object->id, '');
  70. $permissiontoadd = $user->rights->expedition->creer; // Used by the include of actions_dellink.inc.php
  71. /*
  72. * Actions
  73. */
  74. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  75. /*
  76. * View
  77. */
  78. llxHeader('', $langs->trans('Order'), 'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
  79. $form = new Form($db);
  80. if ($id > 0 || !empty($ref)) {
  81. if ($object->fetch($id, $ref)) {
  82. $object->fetch_thirdparty();
  83. $upload_dir = $conf->expedition->dir_output.'/sending/'.dol_sanitizeFileName($object->ref);
  84. $head = shipping_prepare_head($object);
  85. print dol_get_fiche_head($head, 'documents', $langs->trans("Shipment"), -1, $object->picto);
  86. // Build file list
  87. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  88. $totalsize = 0;
  89. foreach ($filearray as $key => $file) {
  90. $totalsize += $file['size'];
  91. }
  92. // Shipment card
  93. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  94. $morehtmlref = '<div class="refidno">';
  95. // Ref customer
  96. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  97. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  98. // Thirdparty
  99. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  100. // Project
  101. if (!empty($conf->projet->enabled)) {
  102. $langs->load("projects");
  103. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  104. if (0) { // Do not change on shipment
  105. if ($action != 'classify') {
  106. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  107. }
  108. if ($action == 'classify') {
  109. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  110. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  111. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  112. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  113. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  114. $morehtmlref .= '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
  115. $morehtmlref .= '</form>';
  116. } else {
  117. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  118. }
  119. } else {
  120. // We don't have project on shipment, so we will use the project or source object instead
  121. // TODO Add project on shipment
  122. $morehtmlref .= ' : ';
  123. if (!empty($objectsrc->fk_project)) {
  124. $proj = new Project($db);
  125. $proj->fetch($objectsrc->fk_project);
  126. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  127. if ($proj->title) {
  128. $morehtmlref .= ' - '.$proj->title;
  129. }
  130. } else {
  131. $morehtmlref .= '';
  132. }
  133. }
  134. }
  135. $morehtmlref .= '</div>';
  136. // Order card
  137. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  138. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  139. print '<div class="fichecenter">';
  140. print '<div class="underbanner clearboth"></div>';
  141. print '<table class="border tableforfield centpercent">';
  142. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  143. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  144. print "</table>\n";
  145. print "</div>\n";
  146. print dol_get_fiche_end();
  147. $modulepart = 'expedition';
  148. $permissiontoadd = $user->rights->expedition->creer;
  149. $permtoedit = $user->rights->expedition->creer;
  150. $param = '&id='.$object->id;
  151. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  152. } else {
  153. dol_print_error($db);
  154. }
  155. } else {
  156. header('Location: index.php');
  157. exit;
  158. }
  159. // End of page
  160. llxFooter();
  161. $db->close();