document.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 <http://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. // Security check
  44. if ($user->societe_id)
  45. {
  46. $socid = $user->societe_id;
  47. }
  48. $result=restrictedArea($user,'expedition',$id,'');
  49. // Get parameters
  50. $sortfield = GETPOST("sortfield",'alpha');
  51. $sortorder = GETPOST("sortorder",'alpha');
  52. $page = GETPOST("page",'int');
  53. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  54. $offset = $conf->liste_limit * $page;
  55. $pageprev = $page - 1;
  56. $pagenext = $page + 1;
  57. if (! $sortorder) $sortorder="ASC";
  58. if (! $sortfield) $sortfield="name";
  59. $object = new Expedition($db);
  60. /*
  61. * Actions
  62. */
  63. if ($object->fetch($id))
  64. {
  65. $object->fetch_thirdparty();
  66. $upload_dir = $conf->expedition->dir_output . "/sending/" . dol_sanitizeFileName($object->ref);
  67. }
  68. include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
  69. /*
  70. * View
  71. */
  72. llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
  73. $form = new Form($db);
  74. if ($id > 0 || ! empty($ref)){
  75. if ($object->fetch($id, $ref)){
  76. $object->fetch_thirdparty();
  77. $upload_dir = $conf->expedition->dir_output.'/sending/'.dol_sanitizeFileName($object->ref);
  78. $head = shipping_prepare_head($object);
  79. dol_fiche_head($head, 'documents', $langs->trans("Shipment"), -1, 'sending');
  80. // Build file list
  81. $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  82. $totalsize=0;
  83. foreach($filearray as $key => $file){
  84. $totalsize+=$file['size'];
  85. }
  86. // Shipment card
  87. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
  88. $morehtmlref='<div class="refidno">';
  89. // Ref customer
  90. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  91. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  92. // Thirdparty
  93. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  94. // Project
  95. if (! empty($conf->projet->enabled)) {
  96. $langs->load("projects");
  97. $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
  98. if (0) { // Do not change on shipment
  99. if ($action != 'classify') {
  100. $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  101. }
  102. if ($action == 'classify') {
  103. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  104. $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
  105. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  106. $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  107. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  108. $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
  109. $morehtmlref .= '</form>';
  110. } else {
  111. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  112. }
  113. } else {
  114. // We don't have project on shipment, so we will use the project or source object instead
  115. // TODO Add project on shipment
  116. $morehtmlref .= ' : ';
  117. if (! empty($objectsrc->fk_project)) {
  118. $proj = new Project($db);
  119. $proj->fetch($objectsrc->fk_project);
  120. $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  121. $morehtmlref .= $proj->ref;
  122. $morehtmlref .= '</a>';
  123. } else {
  124. $morehtmlref .= '';
  125. }
  126. }
  127. }
  128. $morehtmlref.='</div>';
  129. // Order card
  130. $linkback = '<a href="' . DOL_URL_ROOT . '/expedition/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  131. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  132. print '<div class="fichecenter">';
  133. print '<div class="underbanner clearboth"></div>';
  134. print '<table class="border" width="100%">';
  135. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  136. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>';
  137. print "</table>\n";
  138. print "</div>\n";
  139. print dol_fiche_end();
  140. $modulepart = 'expedition';
  141. $permission = $user->rights->expedition->creer;
  142. $permtoedit = $user->rights->expedition->creer;
  143. $param = '&id=' . $object->id;
  144. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  145. }
  146. else{
  147. dol_print_error($db);
  148. }
  149. }
  150. else{
  151. header('Location: index.php');
  152. exit;
  153. }
  154. // End of page
  155. llxFooter();
  156. $db->close();