document.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 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) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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. * or see https://www.gnu.org/
  24. */
  25. /**
  26. * \file htdocs/don/document.php
  27. * \ingroup donation
  28. * \brief Page of linked files onto donation
  29. */
  30. // Load Dolibarr environment
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  36. if (isModEnabled('project')) {
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  39. }
  40. // Load translation files required by the page
  41. $langs->loadLangs(array('companies', 'other', 'donations'));
  42. $id = GETPOST('id', 'int');
  43. $ref = GETPOST('ref', 'alpha');
  44. $action = GETPOST('action', 'aZ09');
  45. $confirm = GETPOST('confirm', 'alpha');
  46. $projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0);
  47. // Get parameters
  48. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortfield = GETPOST('sortfield', 'aZ09comma');
  50. $sortorder = GETPOST('sortorder', 'aZ09comma');
  51. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  52. if (empty($page) || $page == -1) {
  53. $page = 0;
  54. } // If $page is not defined, or '' or -1
  55. $offset = $limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (!$sortorder) {
  59. $sortorder = "ASC";
  60. }
  61. if (!$sortfield) {
  62. $sortfield = "name";
  63. }
  64. $object = new Don($db);
  65. if ($id > 0 || !empty($ref)) {
  66. $object->fetch($id, $ref);
  67. }
  68. if ($id > 0 || !empty($ref)) {
  69. $upload_dir = $conf->don->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object);
  70. }
  71. $modulepart = 'don';
  72. // Security check
  73. if ($user->socid) {
  74. $socid = $user->socid;
  75. }
  76. $result = restrictedArea($user, 'don', $object->id);
  77. $permissiontoadd = $user->rights->don->creer; // Used by the include of actions_dellink.inc.php
  78. /*
  79. * Actions
  80. */
  81. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  82. if ($action == 'classin' && $user->hasRight('don', 'creer')) {
  83. $object->fetch($id);
  84. $object->setProject($projectid);
  85. }
  86. /*
  87. * View
  88. */
  89. $form = new Form($db);
  90. if (isModEnabled('project')) {
  91. $formproject = new FormProjets($db);
  92. }
  93. $title = $langs->trans('Donation')." - ".$langs->trans('Documents');
  94. $help_url = 'EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones|DE:Modul_Spenden';
  95. llxHeader('', $title, $help_url);
  96. if ($object->id) {
  97. $object->fetch_thirdparty();
  98. $head = donation_prepare_head($object);
  99. print dol_get_fiche_head($head, 'documents', $langs->trans("Donation"), -1, 'donation');
  100. // Build file list
  101. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  102. $totalsize = 0;
  103. foreach ($filearray as $key => $file) {
  104. $totalsize += $file['size'];
  105. }
  106. $linkback = '<a href="'.DOL_URL_ROOT.'/don/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  107. $morehtmlref = '<div class="refidno">';
  108. // Project
  109. if (isModEnabled('project')) {
  110. $langs->load("projects");
  111. $morehtmlref .= $langs->trans('Project').' ';
  112. if ($user->hasRight('don', 'creer')) {
  113. if ($action != 'classify') {
  114. // $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  115. }
  116. if ($action == 'classify') {
  117. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  118. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  119. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  120. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  121. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  122. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  123. $morehtmlref .= '</form>';
  124. } else {
  125. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
  126. }
  127. } else {
  128. if (!empty($object->fk_project)) {
  129. $proj = new Project($db);
  130. $proj->fetch($object->fk_project);
  131. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  132. if ($proj->title) {
  133. $morehtmlref .= ' - '.$proj->title;
  134. }
  135. } else {
  136. $morehtmlref .= '';
  137. }
  138. }
  139. }
  140. $morehtmlref .= '</div>';
  141. dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  142. print '<div class="fichecenter">';
  143. print '<div class="underbanner clearboth"></div>';
  144. print '<table class="border tableforfield centpercent">';
  145. // Ref
  146. /*
  147. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
  148. print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
  149. print '</td></tr>';
  150. */
  151. // Societe
  152. //print "<tr><td>".$langs->trans("Company")."</td><td>".$object->client->getNomUrl(1)."</td></tr>";
  153. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  154. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  155. print '</table>';
  156. print '</div>';
  157. print '<div class="clearboth"></div>';
  158. print dol_get_fiche_end();
  159. $modulepart = 'don';
  160. $permissiontoadd = $user->rights->don->creer;
  161. $permtoedit = $user->rights->don->creer;
  162. $param = '&id='.$object->id;
  163. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  164. } else {
  165. print $langs->trans("ErrorUnknown");
  166. }
  167. llxFooter();
  168. $db->close();