document.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/loan/document.php
  20. * \ingroup loan
  21. * \brief Page with attached files on loan
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. if (isModEnabled('project')) {
  31. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  32. }
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("other", "companies", "compta", "bills", "loan"));
  35. $id = GETPOST('id', 'int');
  36. $action = GETPOST('action', 'aZ09');
  37. $confirm = GETPOST('confirm', 'alpha');
  38. // Security check
  39. if ($user->socid) {
  40. $socid = $user->socid;
  41. }
  42. $result = restrictedArea($user, 'loan', $id, '', '');
  43. // Get parameters
  44. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'aZ09comma');
  46. $sortorder = GETPOST('sortorder', 'aZ09comma');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page == -1) {
  49. $page = 0;
  50. }
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (!$sortorder) {
  55. $sortorder = "ASC";
  56. }
  57. if (!$sortfield) {
  58. $sortfield = "name";
  59. }
  60. $object = new Loan($db);
  61. if ($id > 0) {
  62. $object->fetch($id);
  63. }
  64. $upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref);
  65. $modulepart = 'loan';
  66. $permissiontoadd = $user->rights->loan->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
  67. /*
  68. * Actions
  69. */
  70. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  71. /*
  72. * View
  73. */
  74. $form = new Form($db);
  75. $title = $langs->trans("Loan").' - '.$langs->trans("Documents");
  76. $help_url = 'EN:Module_Loan|FR:Module_Emprunt';
  77. llxHeader("", $title, $help_url);
  78. if ($object->id) {
  79. $totalpaid = $object->getSumPayment();
  80. $head = loan_prepare_head($object);
  81. print dol_get_fiche_head($head, 'documents', $langs->trans("Loan"), -1, 'bill');
  82. $morehtmlref = '<div class="refidno">';
  83. // Ref loan
  84. $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, 0, 'string', '', 0, 1);
  85. $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, 0, 'string', '', null, null, '', 1);
  86. // Project
  87. if (isModEnabled('project')) {
  88. $langs->load("projects");
  89. $morehtmlref .= '<br>'.$langs->trans('Project').' : ';
  90. if ($user->rights->loan->write) {
  91. //if ($action != 'classify')
  92. // $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  93. if ($action == 'classify') {
  94. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  95. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  96. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  97. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  98. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  99. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  100. $morehtmlref .= '</form>';
  101. } else {
  102. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
  103. }
  104. } else {
  105. if (!empty($object->fk_project)) {
  106. $proj = new Project($db);
  107. $proj->fetch($object->fk_project);
  108. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  109. if ($proj->title) {
  110. $morehtmlref .= ' - '.$proj->title;
  111. }
  112. } else {
  113. $morehtmlref .= '';
  114. }
  115. }
  116. }
  117. $morehtmlref .= '</div>';
  118. $linkback = '<a href="'.DOL_URL_ROOT.'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  119. $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  120. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
  121. print '<div class="fichecenter">';
  122. print '<div class="underbanner clearboth"></div>';
  123. // Build file list
  124. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  125. $totalsize = 0;
  126. foreach ($filearray as $key => $file) {
  127. $totalsize += $file['size'];
  128. }
  129. print '<table class="border tableforfield centpercent">';
  130. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
  131. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  132. print "</table>\n";
  133. print "</div>\n";
  134. print dol_get_fiche_end();
  135. $modulepart = 'loan';
  136. $permissiontoadd = $user->rights->loan->write;
  137. $permtoedit = $user->rights->loan->write;
  138. $param = '&id='.$object->id;
  139. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  140. } else {
  141. print $langs->trans("ErrorUnknown");
  142. }
  143. // End of page
  144. llxFooter();
  145. $db->close();