dolibarr/htdocs/core/actions_printing.inc.php

92 lines
3.7 KiB
PHP
Raw Normal View History

2014-12-05 18:23:54 +01:00
<?php
/* Copyright (C) 2014-2016 Laurent Destailleur <eldy@users.sourceforge.net>
2018-08-17 11:21:02 +02:00
* Copyright (C) 2014-2018 Frederic France <frederic.france@netlogic.fr>
2014-12-05 18:23:54 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/actions_printing.inc.php
* \brief Code for actions print_file to print file with calling trigger
*/
// $action must be defined
// $db, $user, $conf, $langs must be defined
// Filename to print must be provided into 'file' parameter
// Print file
2018-09-13 11:13:32 +02:00
if ($action == 'print_file' && $user->rights->printing->read) {
2014-12-05 18:23:54 +01:00
$langs->load("printing");
2014-12-08 20:33:26 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/modules/printing/modules_printing.php';
$objectprint = new PrintingDriver($db);
$list = $objectprint->listDrivers($db, 10);
if (! empty($list)) {
$errorprint=0;
2017-04-12 13:01:41 +02:00
$printerfound=0;
2014-12-08 20:33:26 +01:00
foreach ($list as $driver) {
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
$langs->load($driver);
$classname = 'printing_'.$driver;
$printer = new $classname($db);
//print '<pre>'.print_r($printer, true).'</pre>';
2014-12-05 18:23:54 +01:00
if (! empty($conf->global->{$printer->active}))
{
2017-04-12 13:01:41 +02:00
$printerfound++;
$subdir='';
2015-10-29 19:07:00 +01:00
$module = GETPOST('printer', 'alpha');
switch ($module )
{
case 'livraison' :
$subdir = 'receipt';
$module = 'expedition';
break;
case 'expedition' :
$subdir = 'sending';
break;
case 'commande_fournisseur' :
$module = 'fournisseur';
$subdir = 'commande';
break;
2015-10-29 19:07:00 +01:00
}
2017-04-12 13:01:41 +02:00
try {
2018-09-13 11:13:32 +02:00
$ret = $printer->printFile(GETPOST('file', 'alpha'), $module, $subdir);
2017-04-12 13:01:41 +02:00
if ($ret > 0) {
//print '<pre>'.print_r($printer->errors, true).'</pre>';
setEventMessages($printer->error, $printer->errors, 'errors');
}
if ($ret==0)
2017-04-12 13:01:41 +02:00
{
//print '<pre>'.print_r($printer->errors, true).'</pre>';
setEventMessages($printer->error, $printer->errors);
setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null);
2017-04-12 13:01:41 +02:00
}
2015-10-21 18:23:35 +02:00
}
2017-04-12 13:01:41 +02:00
catch(Exception $e)
{
2017-04-12 13:01:41 +02:00
$ret = 1;
setEventMessages($e->getMessage(), null, 'errors');
2014-12-08 20:33:26 +01:00
}
}
}
if ($printerfound==0) setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings');
2014-12-08 20:33:26 +01:00
} else {
2015-11-02 09:46:21 +01:00
setEventMessages($langs->trans("NoModuleFound"), null, 'warnings');
2014-12-05 18:23:54 +01:00
}
$action = '';
}