document.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  9. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/fichinter/document.php
  26. * \ingroup fichinter
  27. * \brief Page des documents joints sur les contrats
  28. */
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.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/lib/fichinter.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. if (!empty($conf->project->enabled)) {
  36. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  37. }
  38. // Load translation files required by the page
  39. $langs->loadLangs(array('other', 'fichinter', 'companies', 'interventions'));
  40. $id = GETPOST('id', 'int');
  41. $ref = GETPOST('ref', 'alpha');
  42. $action = GETPOST('action', 'aZ09');
  43. $confirm = GETPOST('confirm', 'alpha');
  44. // Security check
  45. if ($user->socid) {
  46. $socid = $user->socid;
  47. }
  48. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  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 Fichinter($db);
  67. $object->fetch($id, $ref);
  68. $upload_dir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($object->ref);
  69. $modulepart = 'fichinter';
  70. $permissiontoadd = $user->rights->ficheinter->creer; // Used by the include of actions_setnotes.inc.php
  71. /*
  72. * Actions
  73. */
  74. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  75. /*
  76. * View
  77. */
  78. $form = new Form($db);
  79. llxHeader('', $langs->trans("Intervention"));
  80. if ($object->id) {
  81. $object->fetch_thirdparty();
  82. $head = fichinter_prepare_head($object);
  83. print dol_get_fiche_head($head, 'documents', $langs->trans("InterventionCard"), -1, 'intervention');
  84. // Build file list
  85. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  86. $totalsize = 0;
  87. foreach ($filearray as $key => $file) {
  88. $totalsize += $file['size'];
  89. }
  90. // Intervention card
  91. $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  92. $morehtmlref = '<div class="refidno">';
  93. // Ref customer
  94. //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  95. //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  96. // Thirdparty
  97. $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  98. // Project
  99. if (!empty($conf->project->enabled)) {
  100. $langs->load("projects");
  101. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  102. if ($user->rights->commande->creer) {
  103. if ($action != 'classify') {
  104. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  105. $morehtmlref .= ' : ';
  106. }
  107. if ($action == 'classify') {
  108. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  109. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  110. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  111. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  112. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  113. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  114. $morehtmlref .= '</form>';
  115. } else {
  116. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  117. }
  118. } else {
  119. if (!empty($object->fk_project)) {
  120. $proj = new Project($db);
  121. $proj->fetch($object->fk_project);
  122. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  123. if ($proj->title) {
  124. $morehtmlref .= ' - '.$proj->title;
  125. }
  126. } else {
  127. $morehtmlref .= '';
  128. }
  129. }
  130. }
  131. $morehtmlref .= '</div>';
  132. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  133. print '<div class="fichecenter">';
  134. print '<div class="underbanner clearboth"></div>';
  135. print '<table class="border tableforfield centpercent">';
  136. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  137. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  138. print '</table>';
  139. print '</div>';
  140. print dol_get_fiche_end();
  141. $modulepart = 'ficheinter';
  142. $permissiontoadd = $user->rights->ficheinter->creer;
  143. $permtoedit = $user->rights->ficheinter->creer;
  144. $param = '&id='.$object->id;
  145. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  146. } else {
  147. print $langs->trans("ErrorUnknown");
  148. }
  149. llxFooter();
  150. $db->close();