document.php 6.4 KB

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