document.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@zendsi.com>
  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 <http://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. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29. if (! empty($conf->projet->enabled)) {
  30. require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  31. }
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("other","companies","compta","bills","loan"));
  34. $id = GETPOST('id','int');
  35. $action = GETPOST('action','aZ09');
  36. $confirm = GETPOST('confirm', 'alpha');
  37. // Security check
  38. if ($user->societe_id) $socid=$user->societe_id;
  39. $result = restrictedArea($user, 'loan', $id, '','');
  40. // Get parameters
  41. $sortfield = GETPOST("sortfield",'alpha');
  42. $sortorder = GETPOST("sortorder",'alpha');
  43. $page = GETPOST("page",'int');
  44. if ($page == -1) {
  45. $page = 0;
  46. }
  47. $offset = $conf->liste_limit * $page;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. if (! $sortorder) $sortorder="ASC";
  51. if (! $sortfield) $sortfield="name";
  52. $object = new Loan($db);
  53. if ($id > 0) $object->fetch($id);
  54. $upload_dir = $conf->loan->dir_output.'/'.dol_sanitizeFileName($object->ref);
  55. $modulepart='loan';
  56. /*
  57. * Actions
  58. */
  59. include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
  60. /*
  61. * View
  62. */
  63. $form = new Form($db);
  64. $title = $langs->trans("Loan") . ' - ' . $langs->trans("Documents");
  65. $help_url = 'EN:Module_Loan|FR:Module_Emprunt';
  66. llxHeader("",$title,$help_url);
  67. if ($object->id)
  68. {
  69. $totalpaid=$object->getSumPayment();
  70. $head = loan_prepare_head($object);
  71. dol_fiche_head($head, 'documents', $langs->trans("Loan"), -1, 'bill');
  72. $morehtmlref='<div class="refidno">';
  73. // Ref loan
  74. $morehtmlref.=$form->editfieldkey("Label", 'label', $object->label, $object, 0, 'string', '', 0, 1);
  75. $morehtmlref.=$form->editfieldval("Label", 'label', $object->label, $object, 0, 'string', '', null, null, '', 1);
  76. // Project
  77. if (! empty($conf->projet->enabled)) {
  78. $langs->load("projects");
  79. $morehtmlref .= '<br>' . $langs->trans('Project') . ' : ';
  80. if ($user->rights->loan->write) {
  81. //if ($action != 'classify')
  82. // $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  83. if ($action == 'classify') {
  84. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  85. $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
  86. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  87. $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  88. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  89. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
  90. $morehtmlref .= '</form>';
  91. } else {
  92. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  93. }
  94. } else {
  95. if (! empty($object->fk_project)) {
  96. $proj = new Project($db);
  97. $proj->fetch($object->fk_project);
  98. $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  99. $morehtmlref .= $proj->ref;
  100. $morehtmlref .= '</a>';
  101. } else {
  102. $morehtmlref .= '';
  103. }
  104. }
  105. }
  106. $morehtmlref.='</div>';
  107. $linkback = '<a href="' . DOL_URL_ROOT . '/loan/list.php">' . $langs->trans("BackToList") . '</a>';
  108. $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  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. {
  117. $totalsize+=$file['size'];
  118. }
  119. print '<table class="border" width="100%">';
  120. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
  121. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize,1,1).'</td></tr>';
  122. print "</table>\n";
  123. print "</div>\n";
  124. dol_fiche_end();
  125. $modulepart = 'loan';
  126. $permission = $user->rights->loan->write;
  127. $permtoedit = $user->rights->loan->write;
  128. $param = '&id=' . $object->id;
  129. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  130. }
  131. else
  132. {
  133. print $langs->trans("ErrorUnknown");
  134. }
  135. // End of page
  136. llxFooter();
  137. $db->close();