document.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 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/comm/propal/document.php
  24. * \ingroup propal
  25. * \brief Management page of documents attached to a business proposal
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/supplier_proposal.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. if (isModEnabled('project')) {
  35. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  36. }
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('compta', 'supplier_proposal', 'other'));
  39. $action = GETPOST('action', 'alpha');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $id = GETPOST('id', 'int');
  42. $ref = GETPOST('ref', 'alpha');
  43. // Security check
  44. $socid = '';
  45. if (!empty($user->socid)) {
  46. $socid = $user->socid;
  47. }
  48. $result = restrictedArea($user, 'supplier_proposal', $id);
  49. // Get parameters
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page == -1) {
  55. $page = 0;
  56. } // If $page is not defined, or '' or -1
  57. $offset = $limit * $page;
  58. $pageprev = $page - 1;
  59. $pagenext = $page + 1;
  60. if (!$sortorder) {
  61. $sortorder = "ASC";
  62. }
  63. if (!$sortfield) {
  64. $sortfield = "name";
  65. }
  66. $object = new SupplierProposal($db);
  67. $object->fetch($id, $ref);
  68. if ($object->id > 0) {
  69. $object->fetch_thirdparty();
  70. $upload_dir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($object->ref);
  71. }
  72. $permissiontoadd = $user->rights->supplier_proposal->creer;
  73. $usercancreate = $permissiontoadd;
  74. /*
  75. * Actions
  76. */
  77. if ($object->id > 0) {
  78. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  79. }
  80. /*
  81. * View
  82. */
  83. $title = $object->ref." - ".$langs->trans('Documents');
  84. $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
  85. llxHeader('', $title, $help_url);
  86. $form = new Form($db);
  87. if ($object->id > 0) {
  88. $upload_dir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($object->ref);
  89. $head = supplier_proposal_prepare_head($object);
  90. print dol_get_fiche_head($head, 'document', $langs->trans('CommRequest'), -1, 'supplier_proposal');
  91. // Build file list
  92. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  93. $totalsize = 0;
  94. foreach ($filearray as $key => $file) {
  95. $totalsize += $file['size'];
  96. }
  97. // Supplier proposal card
  98. $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  99. $morehtmlref = '<div class="refidno">';
  100. // Ref supplier
  101. //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', 0, 1);
  102. //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', null, null, '', 1);
  103. // Thirdparty
  104. $morehtmlref .= $object->thirdparty->getNomUrl(1);
  105. // Project
  106. if (isModEnabled('project')) {
  107. $langs->load("projects");
  108. $morehtmlref .= '<br>';
  109. if (0) {
  110. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  111. if ($action != 'classify') {
  112. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  113. }
  114. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  115. } else {
  116. if (!empty($object->fk_project)) {
  117. $proj = new Project($db);
  118. $proj->fetch($object->fk_project);
  119. $morehtmlref .= $proj->getNomUrl(1);
  120. if ($proj->title) {
  121. $morehtmlref .= ' - '.$proj->title;
  122. }
  123. }
  124. }
  125. }
  126. $morehtmlref .= '</div>';
  127. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  128. print '<div class="fichecenter">';
  129. print '<div class="underbanner clearboth"></div>';
  130. print '<table class="border tableforfield centpercent">';
  131. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
  132. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  133. print '</table>';
  134. print '</div>';
  135. print dol_get_fiche_end();
  136. $modulepart = 'supplier_proposal';
  137. $permissiontoadd = $user->rights->supplier_proposal->creer;
  138. $permtoedit = $user->rights->supplier_proposal->creer;
  139. $param = '&id='.$object->id;
  140. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  141. } else {
  142. print $langs->trans("ErrorUnknown");
  143. }
  144. // End of page
  145. llxFooter();
  146. $db->close();