document.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  7. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/comm/propal/document.php
  24. * \ingroup propal
  25. * \brief Management page of documents attached to a business proposal
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. if (!empty($conf->projet->enabled)) {
  34. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  35. }
  36. // Load translation files required by the page
  37. $langs->loadLangs(array('propal', 'compta', 'other', 'companies'));
  38. $action = GETPOST('action', 'alpha');
  39. $confirm = GETPOST('confirm', 'alpha');
  40. $id = GETPOST('id', 'int');
  41. $ref = GETPOST('ref', 'alpha');
  42. // Security check
  43. $socid = '';
  44. if (!empty($user->socid)) {
  45. $socid = $user->socid;
  46. }
  47. $result = restrictedArea($user, 'propal', $id);
  48. // Get parameters
  49. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  50. $sortfield = GETPOST('sortfield', 'aZ09comma');
  51. $sortorder = GETPOST('sortorder', 'aZ09comma');
  52. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  53. if (empty($page) || $page == -1) {
  54. $page = 0;
  55. } // If $page is not defined, or '' or -1
  56. $offset = $limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if (!empty($conf->global->MAIN_DOC_SORT_FIELD)) {
  60. $sortfield = $conf->global->MAIN_DOC_SORT_FIELD;
  61. }
  62. if (!empty($conf->global->MAIN_DOC_SORT_ORDER)) {
  63. $sortorder = $conf->global->MAIN_DOC_SORT_ORDER;
  64. }
  65. if (!$sortorder) {
  66. $sortorder = "ASC";
  67. }
  68. if (!$sortfield) {
  69. $sortfield = "name";
  70. }
  71. $object = new Propal($db);
  72. $object->fetch($id, $ref);
  73. $permissiontoadd = $user->rights->propale->creer;
  74. // Security check
  75. if (!empty($user->socid)) {
  76. $socid = $user->socid;
  77. $object->id = $user->socid;
  78. }
  79. restrictedArea($user, 'propal', $object->id);
  80. /*
  81. * Actions
  82. */
  83. if ($object->id > 0) {
  84. $object->fetch_thirdparty();
  85. $upload_dir = $conf->propal->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  86. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  87. }
  88. /*
  89. * View
  90. */
  91. $title = $langs->trans('Proposal')." - ".$langs->trans('Documents');
  92. $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos';
  93. llxHeader('', $title, $help_url);
  94. $form = new Form($db);
  95. if ($object->id > 0) {
  96. $upload_dir = $conf->propal->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  97. $head = propal_prepare_head($object);
  98. print dol_get_fiche_head($head, 'document', $langs->trans('Proposal'), -1, 'propal');
  99. // Build file list
  100. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  101. $totalsize = 0;
  102. foreach ($filearray as $key => $file) {
  103. $totalsize += $file['size'];
  104. }
  105. // Proposal card
  106. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  107. $morehtmlref = '<div class="refidno">';
  108. // Ref customer
  109. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  110. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  111. // Thirdparty
  112. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
  113. // Project
  114. if (!empty($conf->projet->enabled)) {
  115. $langs->load("projects");
  116. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  117. if ($user->rights->propal->creer) {
  118. if ($action != 'classify') {
  119. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
  120. $morehtmlref .= ' : ';
  121. }
  122. if ($action == 'classify') {
  123. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  124. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  125. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  126. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  127. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  128. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  129. $morehtmlref .= '</form>';
  130. } else {
  131. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  132. }
  133. } else {
  134. if (!empty($object->fk_project)) {
  135. $proj = new Project($db);
  136. $proj->fetch($object->fk_project);
  137. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  138. if ($proj->title) {
  139. $morehtmlref .= ' - '.$proj->title;
  140. }
  141. } else {
  142. $morehtmlref .= '';
  143. }
  144. }
  145. }
  146. $morehtmlref .= '</div>';
  147. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  148. print '<div class="fichecenter">';
  149. print '<div class="underbanner clearboth"></div>';
  150. print '<table class="border tableforfield centpercent">';
  151. // Files infos
  152. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
  153. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  154. print "</table>\n";
  155. print '</div>';
  156. print dol_get_fiche_end();
  157. $modulepart = 'propal';
  158. $permissiontoadd = $user->rights->propal->creer;
  159. $permtoedit = $user->rights->propal->creer;
  160. $param = '&id='.$object->id;
  161. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  162. } else {
  163. print $langs->trans("ErrorUnknown");
  164. }
  165. // End of page
  166. llxFooter();
  167. $db->close();