document.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // Load Dolibarr environment
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. if (isModEnabled('project')) {
  35. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  36. }
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('propal', 'compta', 'other', 'companies'));
  39. $action = GETPOST('action', 'alpha');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $id = GETPOST('id', 'int');
  42. $ref = GETPOST('ref', 'alpha');
  43. // Get parameters
  44. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'aZ09comma');
  46. $sortorder = GETPOST('sortorder', 'aZ09comma');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page == -1) {
  49. $page = 0;
  50. } // If $page is not defined, or '' or -1
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (getDolGlobalString('MAIN_DOC_SORT_FIELD')) {
  55. $sortfield = $conf->global->MAIN_DOC_SORT_FIELD;
  56. }
  57. if (getDolGlobalString('MAIN_DOC_SORT_ORDER')) {
  58. $sortorder = $conf->global->MAIN_DOC_SORT_ORDER;
  59. }
  60. if (!$sortorder) {
  61. $sortorder = "ASC";
  62. }
  63. if (!$sortfield) {
  64. $sortfield = "name";
  65. }
  66. $object = new Propal($db);
  67. $object->fetch($id, $ref);
  68. $permissiontoadd = $user->rights->propal->creer;
  69. // Security check
  70. $socid = '';
  71. if (!empty($user->socid)) {
  72. $socid = $user->socid;
  73. }
  74. restrictedArea($user, 'propal', $object->id);
  75. $usercancreate = $user->hasRight("propal", "creer");
  76. /*
  77. * Actions
  78. */
  79. if ($object->id > 0) {
  80. $object->fetch_thirdparty();
  81. $upload_dir = $conf->propal->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  82. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  83. }
  84. /*
  85. * View
  86. */
  87. $title = $object->ref." - ".$langs->trans('Documents');
  88. $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos';
  89. llxHeader('', $title, $help_url);
  90. $form = new Form($db);
  91. if ($object->id > 0) {
  92. $upload_dir = $conf->propal->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  93. $head = propal_prepare_head($object);
  94. print dol_get_fiche_head($head, 'document', $langs->trans('Proposal'), -1, 'propal');
  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. // Proposal card
  102. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  103. $morehtmlref = '<div class="refidno">';
  104. // Ref customer
  105. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  106. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  107. // Thirdparty
  108. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
  109. // Project
  110. if (isModEnabled('project')) {
  111. $langs->load("projects");
  112. $morehtmlref .= '<br>';
  113. if (0) {
  114. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  115. if ($action != 'classify') {
  116. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  117. }
  118. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  119. } else {
  120. if (!empty($object->fk_project)) {
  121. $proj = new Project($db);
  122. $proj->fetch($object->fk_project);
  123. $morehtmlref .= $proj->getNomUrl(1);
  124. if ($proj->title) {
  125. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  126. }
  127. }
  128. }
  129. }
  130. $morehtmlref .= '</div>';
  131. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  132. print '<div class="fichecenter">';
  133. print '<div class="underbanner clearboth"></div>';
  134. print '<table class="border tableforfield centpercent">';
  135. // Files infos
  136. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
  137. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  138. print "</table>\n";
  139. print '</div>';
  140. print dol_get_fiche_end();
  141. $modulepart = 'propal';
  142. $permissiontoadd = $user->rights->propal->creer;
  143. $permtoedit = $user->rights->propal->creer;
  144. $param = '&id='.$object->id;
  145. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  146. } else {
  147. print $langs->trans("ErrorUnknown");
  148. }
  149. // End of page
  150. llxFooter();
  151. $db->close();