actions_printing.inc.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* Copyright (C) 2014-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014 Frederic France <frederic.france@free.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' and $user->rights->printing->read)
  28. {
  29. $langs->load("printing");
  30. require_once DOL_DOCUMENT_ROOT . '/core/modules/printing/modules_printing.php';
  31. $objectprint = new PrintingDriver($db);
  32. $list = $objectprint->listDrivers($db, 10);
  33. if (! empty($list)) {
  34. $errorprint=0;
  35. $printerfound=0;
  36. foreach ($list as $driver) {
  37. require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
  38. $langs->load($driver);
  39. $classname = 'printing_'.$driver;
  40. $printer = new $classname($db);
  41. //print '<pre>'.print_r($printer, true).'</pre>';
  42. if (! empty($conf->global->{$printer->active}))
  43. {
  44. $printerfound++;
  45. $subdir=(GETPOST('printer', 'alpha')=='expedition'?'sending':'');
  46. $module = GETPOST('printer', 'alpha');
  47. if ($module =='commande_fournisseur') {
  48. $module = 'fournisseur';
  49. $subdir = 'commande';
  50. }
  51. try {
  52. $ret = $printer->print_file(GETPOST('file', 'alpha'), $module, $subdir);
  53. if ($ret > 0) {
  54. //print '<pre>'.print_r($printer->errors, true).'</pre>';
  55. setEventMessages($printer->error, $printer->errors, 'errors');
  56. }
  57. if ($ret==0)
  58. {
  59. //print '<pre>'.print_r($printer->errors, true).'</pre>';
  60. setEventMessages($printer->error, $printer->errors);
  61. setEventMessages($langs->trans("FileWasSentToPrinter", basename(GETPOST('file'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null);
  62. }
  63. }
  64. catch(Exception $e)
  65. {
  66. $ret = 1;
  67. setEventMessages($e->getMessage(), null, 'errors');
  68. }
  69. }
  70. }
  71. if ($printerfound==0) setEventMessages($langs->trans("NoActivePrintingModuleFound"), null, 'warnings');
  72. } else {
  73. setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
  74. }
  75. $action = '';
  76. }