document.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /* Copyright (C) 2003-2007 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) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/contrat/document.php
  25. * \ingroup contrat
  26. * \brief Page des documents joints sur les contrats
  27. */
  28. require "../main.inc.php";
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.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('other', 'products', 'contracts'));
  39. $action = GETPOST('action', 'alpha');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $id = GETPOST('id', 'int');
  42. $ref = GETPOST('ref', 'alpha');
  43. // Security check
  44. if ($user->socid > 0) {
  45. unset($_GET["action"]);
  46. $action = '';
  47. $socid = $user->socid;
  48. }
  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 Contrat($db);
  67. $object->fetch($id, $ref);
  68. if ($object->id > 0) {
  69. $object->fetch_thirdparty();
  70. }
  71. $upload_dir = $conf->contrat->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  72. $modulepart = 'contract';
  73. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  74. $hookmanager->initHooks(array('contractcard', 'globalcard'));
  75. $permissiontoadd = $user->hasRight('contrat', 'creer'); // Used by the include of actions_dellink.inc.php
  76. $result = restrictedArea($user, 'contrat', $object->id);
  77. /*
  78. * Actions
  79. */
  80. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  81. /*
  82. *
  83. */
  84. $form = new Form($db);
  85. $title = $langs->trans("Contract");
  86. $help_url = 'EN:Module_Contracts|FR:Module_Contrat';
  87. llxHeader('', $title, $help_url);
  88. if ($object->id) {
  89. $head = contract_prepare_head($object);
  90. print dol_get_fiche_head($head, 'documents', $langs->trans("Contract"), -1, 'contract');
  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. // Contract card
  98. $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  99. $morehtmlref = '';
  100. //if (!empty($modCodeContract->code_auto)) {
  101. $morehtmlref .= $object->ref;
  102. /*} else {
  103. $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
  104. $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
  105. }*/
  106. $morehtmlref .= '<div class="refidno">';
  107. // Ref customer
  108. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
  109. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
  110. // Ref supplier
  111. $morehtmlref .= '<br>';
  112. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  113. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
  114. // Thirdparty
  115. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  116. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  117. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';
  118. }
  119. // Project
  120. if (isModEnabled('project')) {
  121. $langs->load("projects");
  122. $morehtmlref .= '<br>';
  123. if (0) {
  124. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  125. if ($action != 'classify') {
  126. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  127. }
  128. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  129. } else {
  130. if (!empty($object->fk_project)) {
  131. $proj = new Project($db);
  132. $proj->fetch($object->fk_project);
  133. $morehtmlref .= $proj->getNomUrl(1);
  134. if ($proj->title) {
  135. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  136. }
  137. }
  138. }
  139. }
  140. $morehtmlref .= '</div>';
  141. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
  142. print '<div class="fichecenter">';
  143. print '<div class="underbanner clearboth"></div>';
  144. print '<table class="border tableforfield centpercent">';
  145. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  146. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  147. print '</table>';
  148. print '</div>';
  149. print dol_get_fiche_end();
  150. $modulepart = 'contract';
  151. $permissiontoadd = $user->hasRight('contrat', 'creer');
  152. $permtoedit = $user->hasRight('contrat', 'creer');
  153. $param = '&id='.$object->id;
  154. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  155. } else {
  156. print $langs->trans("ErrorUnknown");
  157. }
  158. llxFooter();
  159. $db->close();