actions_printing.inc.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <https://www.gnu.org/licenses/>.
  17. * or see https://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. $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
  33. if (!empty($list)) {
  34. $errorprint = 0;
  35. $printerfound = 0;
  36. foreach ($list as $driver) {
  37. foreach ($dirmodels as $dir) {
  38. if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) {
  39. $classfile = dol_buildpath($dir, 0).$driver.'.modules.php';
  40. break;
  41. }
  42. }
  43. require_once $classfile;
  44. $classname = 'printing_'.$driver;
  45. $printer = new $classname($db);
  46. $langs->load($printer::LANGFILE);
  47. //print '<pre>'.print_r($printer, true).'</pre>';
  48. if (!empty($conf->global->{$printer->active})) {
  49. $printerfound++;
  50. $subdir = '';
  51. $module = GETPOST('printer', 'alpha');
  52. switch ($module) {
  53. case 'livraison':
  54. $subdir = 'receipt';
  55. $module = 'expedition';
  56. break;
  57. case 'expedition':
  58. $subdir = 'sending';
  59. break;
  60. case 'commande_fournisseur':
  61. $module = 'fournisseur';
  62. $subdir = 'commande';
  63. break;
  64. }
  65. try {
  66. $ret = $printer->printFile(GETPOST('file', 'alpha'), $module, $subdir);
  67. if ($ret > 0) {
  68. //print '<pre>'.print_r($printer->errors, true).'</pre>';
  69. setEventMessages($printer->error, $printer->errors, 'errors');
  70. }
  71. if ($ret == 0) {
  72. //print '<pre>'.print_r($printer->errors, true).'</pre>';
  73. setEventMessages($printer->error, $printer->errors);
  74. setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null);
  75. }
  76. } catch (Exception $e) {
  77. $ret = 1;
  78. setEventMessages($e->getMessage(), null, 'errors');
  79. }
  80. }
  81. }
  82. if ($printerfound == 0) {
  83. setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings');
  84. }
  85. } else {
  86. setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
  87. }
  88. $action = '';
  89. }