actions_printing.inc.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /* Copyright (C) 2014-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014-2018 Frederic France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/actions_printing.inc.php
  21. * \brief Code for actions print_file to print file with calling trigger
  22. */
  23. // $action must be defined
  24. // $db, $user, $conf, $langs must be defined
  25. // Filename to print must be provided into 'file' parameter
  26. // Print file
  27. if ($action == 'print_file' && $user->rights->printing->read) {
  28. $langs->load("printing");
  29. require_once DOL_DOCUMENT_ROOT . '/core/modules/printing/modules_printing.php';
  30. $objectprint = new PrintingDriver($db);
  31. $list = $objectprint->listDrivers($db, 10);
  32. if (! empty($list)) {
  33. $errorprint=0;
  34. $printerfound=0;
  35. foreach ($list as $driver) {
  36. require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
  37. $langs->load($driver);
  38. $classname = 'printing_'.$driver;
  39. $printer = new $classname($db);
  40. //print '<pre>'.print_r($printer, true).'</pre>';
  41. if (! empty($conf->global->{$printer->active}))
  42. {
  43. $printerfound++;
  44. $subdir='';
  45. $module = GETPOST('printer', 'alpha');
  46. switch ($module )
  47. {
  48. case 'livraison' :
  49. $subdir = 'receipt';
  50. $module = 'expedition';
  51. break;
  52. case 'expedition' :
  53. $subdir = 'sending';
  54. break;
  55. case 'commande_fournisseur' :
  56. $module = 'fournisseur';
  57. $subdir = 'commande';
  58. break;
  59. }
  60. try {
  61. $ret = $printer->printFile(GETPOST('file', 'alpha'), $module, $subdir);
  62. if ($ret > 0) {
  63. //print '<pre>'.print_r($printer->errors, true).'</pre>';
  64. setEventMessages($printer->error, $printer->errors, 'errors');
  65. }
  66. if ($ret==0)
  67. {
  68. //print '<pre>'.print_r($printer->errors, true).'</pre>';
  69. setEventMessages($printer->error, $printer->errors);
  70. setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null);
  71. }
  72. }
  73. catch(Exception $e)
  74. {
  75. $ret = 1;
  76. setEventMessages($e->getMessage(), null, 'errors');
  77. }
  78. }
  79. }
  80. if ($printerfound==0) setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings');
  81. } else {
  82. setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
  83. }
  84. $action = '';
  85. }