PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/don/document.php

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