PageRenderTime 33ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/facture/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 205 lines | 126 code | 37 blank | 42 comment | 24 complexity | 58ab97eb88245f9832a566758d3c9d5e MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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.houssin@capnetworks.com>
  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 3 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. $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
  37. $ref=GETPOST('ref','alpha');
  38. $socid=GETPOST('socid','int');
  39. $action=GETPOST('action','alpha');
  40. $confirm=GETPOST('confirm', 'alpha');
  41. // Security check
  42. if ($user->societe_id)
  43. {
  44. $action='';
  45. $socid = $user->societe_id;
  46. }
  47. $result=restrictedArea($user,'facture',$id,'');
  48. // Get parameters
  49. $sortfield = GETPOST("sortfield",'alpha');
  50. $sortorder = GETPOST("sortorder",'alpha');
  51. $page = GETPOST("page",'int');
  52. if ($page == -1) { $page = 0; }
  53. $offset = $conf->liste_limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. if (! $sortorder) $sortorder="ASC";
  57. if (! $sortfield) $sortfield="name";
  58. $object = new Facture($db);
  59. /*
  60. * Actions
  61. */
  62. // Envoi fichier
  63. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  64. {
  65. if ($object->fetch($id))
  66. {
  67. $object->fetch_thirdparty();
  68. $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
  69. dol_add_file_process($upload_dir,0,1,'userfile');
  70. }
  71. }
  72. // Delete
  73. if ($action == 'confirm_deletefile' && $confirm == 'yes')
  74. {
  75. if ($object->fetch($id))
  76. {
  77. $langs->load("other");
  78. $object->fetch_thirdparty();
  79. $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
  80. $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  81. $ret=dol_delete_file($file,0,0,0,$object);
  82. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  83. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  84. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  85. exit;
  86. }
  87. }
  88. /*
  89. * View
  90. */
  91. llxHeader();
  92. $form = new Form($db);
  93. if ($id > 0 || ! empty($ref))
  94. {
  95. if ($object->fetch($id,$ref) > 0)
  96. {
  97. $object->fetch_thirdparty();
  98. $upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($object->ref);
  99. $head = facture_prepare_head($object);
  100. dol_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), 0, 'bill');
  101. // Construit liste des fichiers
  102. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  103. $totalsize=0;
  104. foreach($filearray as $key => $file)
  105. {
  106. $totalsize+=$file['size'];
  107. }
  108. print '<table class="border" width="100%">';
  109. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  110. // Ref
  111. print '<tr><td width="30%">'.$langs->trans('Ref').'</td>';
  112. print '<td colspan="3">';
  113. $morehtmlref='';
  114. $discount=new DiscountAbsolute($db);
  115. $result=$discount->fetch(0,$object->id);
  116. if ($result > 0)
  117. {
  118. $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
  119. }
  120. if ($result < 0)
  121. {
  122. dol_print_error('',$discount->error);
  123. }
  124. print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref);
  125. print '</td></tr>';
  126. // Ref customer
  127. print '<tr><td width="20%">';
  128. print '<table class="nobordernopadding" width="100%"><tr><td>';
  129. print $langs->trans('RefCustomer');
  130. print '</td>';
  131. print '</tr></table>';
  132. print '</td>';
  133. print '<td colspan="5">';
  134. print $object->ref_client;
  135. print '</td></tr>';
  136. // Company
  137. print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
  138. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  139. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  140. print "</table>\n";
  141. print "</div>\n";
  142. /*
  143. * Confirmation suppression fichier
  144. */
  145. if ($action == 'delete')
  146. {
  147. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?facid='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  148. if ($ret == 'html') print '<br>';
  149. }
  150. // Affiche formulaire upload
  151. $formfile=new FormFile($db);
  152. $formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id,'',0,0,$user->rights->facture->creer,50,$object);
  153. // List of document
  154. $param='&facid='.$object->id;
  155. $formfile->list_of_documents($filearray,$object,'facture',$param);
  156. }
  157. else
  158. {
  159. dol_print_error($db);
  160. }
  161. }
  162. else
  163. {
  164. print $langs->trans("UnkownError");
  165. }
  166. $db->close();
  167. llxFooter();
  168. ?>