document.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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@capnetworks.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.dolibarr@gmail.com>
  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 <http://www.gnu.org/licenses/>.
  23. * or see http://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. {
  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. $langs->load("other");
  41. $langs->load("donations");
  42. $langs->load("companies");
  43. $id = GETPOST('id','int');
  44. $ref = GETPOST('ref', 'alpha');
  45. $action = GETPOST('action','alpha');
  46. $confirm = GETPOST('confirm','alpha');
  47. $projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0);
  48. // Security check
  49. if ($user->societe_id) $socid=$user->societe_id;
  50. $result = restrictedArea($user, 'don', $id, '');
  51. // Get parameters
  52. $sortfield = GETPOST('sortfield','alpha');
  53. $sortorder = GETPOST('sortorder','alpha');
  54. $page = GETPOST('page','int');
  55. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  56. $offset = $conf->liste_limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if (! $sortorder) $sortorder="ASC";
  60. if (! $sortfield) $sortfield="name";
  61. $object = new Don($db);
  62. $object->fetch($id, $ref);
  63. $upload_dir = $conf->don->dir_output . '/' . get_exdir($filename,0,0,0,$object,'donation'). '/'. dol_sanitizeFileName($object->ref);
  64. $modulepart='don';
  65. /*
  66. * Actions
  67. */
  68. include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
  69. if ($action == 'classin' && $user->rights->don->creer)
  70. {
  71. $object->fetch($id);
  72. $object->setProject($projectid);
  73. }
  74. /*
  75. * View
  76. */
  77. $form = new Form($db);
  78. if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
  79. $title = $langs->trans('Donation') . " - " . $langs->trans('Documents');
  80. $helpurl = "";
  81. llxHeader('', $title, $helpurl);
  82. if ($object->id)
  83. {
  84. $object->fetch_thirdparty();
  85. $head=donation_prepare_head($object);
  86. dol_fiche_head($head, 'documents', $langs->trans("Donation"), 0, 'generic');
  87. // Construit liste des fichiers
  88. $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  89. $totalsize=0;
  90. foreach($filearray as $key => $file)
  91. {
  92. $totalsize+=$file['size'];
  93. }
  94. $linkback = '<a href="'.DOL_URL_ROOT.'/don/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  95. $morehtmlref='<div class="refidno">';
  96. // Project
  97. if (! empty($conf->projet->enabled))
  98. {
  99. $langs->load("projects");
  100. $morehtmlref.=$langs->trans('Project') . ' ';
  101. if ($user->rights->don->creer)
  102. {
  103. if ($action != 'classify')
  104. // $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  105. if ($action == 'classify') {
  106. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  107. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  108. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  109. $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  110. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  111. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  112. $morehtmlref.='</form>';
  113. } else {
  114. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  115. }
  116. } else {
  117. if (! empty($object->fk_project)) {
  118. $proj = new Project($db);
  119. $proj->fetch($object->fk_project);
  120. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  121. $morehtmlref.=$proj->ref;
  122. $morehtmlref.='</a>';
  123. } else {
  124. $morehtmlref.='';
  125. }
  126. }
  127. }
  128. $morehtmlref.='</div>';
  129. dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  130. print '<div class="fichecenter">';
  131. print '<div class="underbanner clearboth"></div>';
  132. print '<table class="border" width="100%">';
  133. // Ref
  134. /*
  135. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
  136. print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', '');
  137. print '</td></tr>';
  138. */
  139. // Societe
  140. //print "<tr><td>".$langs->trans("Company")."</td><td>".$object->client->getNomUrl(1)."</td></tr>";
  141. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  142. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  143. print '</table>';
  144. print '</div>';
  145. print '<div class="clearboth"></div>';
  146. dol_fiche_end();
  147. $modulepart = 'don';
  148. $permission = $user->rights->don->lire;
  149. $permtoedit = $user->rights->don->creer;
  150. $param = '&id=' . $object->id;
  151. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  152. }
  153. else
  154. {
  155. print $langs->trans("ErrorUnknown");
  156. }
  157. llxFooter();
  158. $db->close();