PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/commande/document.php

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