PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/facture/document.php

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