PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/facture/document.php

https://github.com/zeert/dolibarr
PHP | 206 lines | 127 code | 37 blank | 42 comment | 24 complexity | 70a33604b7cc779c28f911927bdedad7 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/facture/document.php
  22. * \ingroup facture
  23. * \brief Page for attached files on invoices
  24. */
  25. require("../../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  27. require_once(DOL_DOCUMENT_ROOT.'/core/class/discount.class.php');
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/invoice.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('propal');
  33. $langs->load('compta');
  34. $langs->load('other');
  35. $langs->load("bills");
  36. $action = GETPOST('action');
  37. $confirm = GETPOST('confirm');
  38. $id = GETPOST('facid','int');
  39. $ref = GETPOST('ref');
  40. // Security check
  41. if ($user->societe_id)
  42. {
  43. $action='';
  44. $socid = $user->societe_id;
  45. }
  46. $result=restrictedArea($user,'facture',$id,'');
  47. // Get parameters
  48. $sortfield = GETPOST("sortfield",'alpha');
  49. $sortorder = GETPOST("sortorder",'alpha');
  50. $page = GETPOST("page",'int');
  51. if ($page == -1) { $page = 0; }
  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 Facture($db);
  58. /*
  59. * Actions
  60. */
  61. // Envoi fichier
  62. if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  63. {
  64. if ($object->fetch($id))
  65. {
  66. $object->fetch_thirdparty();
  67. $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
  68. dol_add_file_process($upload_dir,0,1,'userfile');
  69. }
  70. }
  71. // Delete
  72. if ($action == 'confirm_deletefile' && $confirm == 'yes')
  73. {
  74. if ($object->fetch($id))
  75. {
  76. $langs->load("other");
  77. $object->fetch_thirdparty();
  78. $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
  79. $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  80. $ret=dol_delete_file($file,0,0,0,$object);
  81. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  82. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  83. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  84. exit;
  85. }
  86. }
  87. /*
  88. * View
  89. */
  90. llxHeader();
  91. $form = new Form($db);
  92. $id = $_GET['facid']?$_GET['facid']:$_GET['id'];
  93. $ref= $_GET['ref'];
  94. if ($id > 0 || ! empty($ref))
  95. {
  96. if ($object->fetch($id,$ref) > 0)
  97. {
  98. $object->fetch_thirdparty();
  99. $upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($object->ref);
  100. $head = facture_prepare_head($object);
  101. dol_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), 0, 'bill');
  102. // Construit liste des fichiers
  103. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  104. $totalsize=0;
  105. foreach($filearray as $key => $file)
  106. {
  107. $totalsize+=$file['size'];
  108. }
  109. print '<table class="border" width="100%">';
  110. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  111. // Ref
  112. print '<tr><td width="30%">'.$langs->trans('Ref').'</td>';
  113. print '<td colspan="3">';
  114. $morehtmlref='';
  115. $discount=new DiscountAbsolute($db);
  116. $result=$discount->fetch(0,$object->id);
  117. if ($result > 0)
  118. {
  119. $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
  120. }
  121. if ($result < 0)
  122. {
  123. dol_print_error('',$discount->error);
  124. }
  125. print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref);
  126. print '</td></tr>';
  127. // Ref customer
  128. print '<tr><td width="20%">';
  129. print '<table class="nobordernopadding" width="100%"><tr><td>';
  130. print $langs->trans('RefCustomer');
  131. print '</td>';
  132. print '</tr></table>';
  133. print '</td>';
  134. print '<td colspan="5">';
  135. print $object->ref_client;
  136. print '</td></tr>';
  137. // Company
  138. print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
  139. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  140. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  141. print "</table>\n";
  142. print "</div>\n";
  143. /*
  144. * Confirmation suppression fichier
  145. */
  146. if ($action == 'delete')
  147. {
  148. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?facid='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  149. if ($ret == 'html') print '<br>';
  150. }
  151. // Affiche formulaire upload
  152. $formfile=new FormFile($db);
  153. $formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id,'',0,0,$user->rights->facture->creer,50,$object);
  154. // List of document
  155. $param='&facid='.$object->id;
  156. $formfile->list_of_documents($filearray,$object,'facture',$param);
  157. }
  158. else
  159. {
  160. dol_print_error($db);
  161. }
  162. }
  163. else
  164. {
  165. print $langs->trans("UnkownError");
  166. }
  167. $db->close();
  168. llxFooter();
  169. ?>