document.php 5.7 KB

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