Errors management
This commit is contained in:
parent
2b4224d4c4
commit
b9367bb196
@ -47,17 +47,19 @@ if ($action == 'print_file' and $user->rights->printing->read)
|
|||||||
if (! empty($conf->global->{$printer->active})) {
|
if (! empty($conf->global->{$printer->active})) {
|
||||||
$subdir=(GETPOST('printer', 'alpha')=='expedition'?'sending':'');
|
$subdir=(GETPOST('printer', 'alpha')=='expedition'?'sending':'');
|
||||||
$ret = $printer->print_file(GETPOST('file', 'alpha'), GETPOST('printer', 'alpha'), $subdir);
|
$ret = $printer->print_file(GETPOST('file', 'alpha'), GETPOST('printer', 'alpha'), $subdir);
|
||||||
if ($ret < 0) {
|
if ($ret > 0) {
|
||||||
|
//print '<pre>'.print_r($printer->errors, true).'</pre>';
|
||||||
setEventMessages($printer->error, $printer->errors, 'errors');
|
setEventMessages($printer->error, $printer->errors, 'errors');
|
||||||
}
|
}
|
||||||
if ($ret==0) {
|
if ($ret==0) {
|
||||||
setEventMessages($printer->error, $printer->errors, 'warning');
|
//print '<pre>'.print_r($printer->errors, true).'</pre>';
|
||||||
|
setEventMessages($printer->error, $printer->errors);
|
||||||
setEventMessages($langs->trans("FileWasSentToPrinter", basename(GETPOST('file'))).' '.$langs->trans("ViaModule").' '.$printer->name, null);
|
setEventMessages($langs->trans("FileWasSentToPrinter", basename(GETPOST('file'))).' '.$langs->trans("ViaModule").' '.$printer->name, null);
|
||||||
$printed++;
|
$printed++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($printed==0) setEventMessages($langs->trans("NoActivePrintingModuleFound"), null);
|
if ($printed==0) setEventMessages($langs->trans("NoActivePrintingModuleFound"), null, 'warning');
|
||||||
} else {
|
} else {
|
||||||
setEventMessages($langs->trans("NoModuleFound"), null, 'warning');
|
setEventMessages($langs->trans("NoModuleFound"), null, 'warning');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,8 @@ class printing_printgcp extends PrintingDriver
|
|||||||
var $conf = array();
|
var $conf = array();
|
||||||
var $google_id = '';
|
var $google_id = '';
|
||||||
var $google_secret = '';
|
var $google_secret = '';
|
||||||
|
var $error;
|
||||||
|
var $errors = array();
|
||||||
var $db;
|
var $db;
|
||||||
|
|
||||||
const LOGIN_URL = 'https://accounts.google.com/o/oauth2/token';
|
const LOGIN_URL = 'https://accounts.google.com/o/oauth2/token';
|
||||||
@ -122,11 +124,12 @@ class printing_printgcp extends PrintingDriver
|
|||||||
/**
|
/**
|
||||||
* Return list of available printers
|
* Return list of available printers
|
||||||
*
|
*
|
||||||
* @return string html list of printers
|
* @return int 0 if OK, >0 if KO
|
||||||
*/
|
*/
|
||||||
function listAvailablePrinters()
|
function listAvailablePrinters()
|
||||||
{
|
{
|
||||||
global $bc, $conf, $langs;
|
global $bc, $conf, $langs;
|
||||||
|
$error = 0;
|
||||||
$langs->load('printing');
|
$langs->load('printing');
|
||||||
$var=true;
|
$var=true;
|
||||||
|
|
||||||
@ -165,8 +168,8 @@ class printing_printgcp extends PrintingDriver
|
|||||||
$html.= '</td>';
|
$html.= '</td>';
|
||||||
$html.= '</tr>'."\n";
|
$html.= '</tr>'."\n";
|
||||||
}
|
}
|
||||||
|
$this->resprint = $html;
|
||||||
return $html;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -240,15 +243,19 @@ class printing_printgcp extends PrintingDriver
|
|||||||
* @param string $file file
|
* @param string $file file
|
||||||
* @param string $module module
|
* @param string $module module
|
||||||
* @param string $subdir subdir for file
|
* @param string $subdir subdir for file
|
||||||
* @return int 0 if OK, <0 if KO
|
* @return int 0 if OK, >0 if KO
|
||||||
*/
|
*/
|
||||||
function print_file($file, $module, $subdir='')
|
function print_file($file, $module, $subdir='')
|
||||||
{
|
{
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
|
||||||
global $conf, $user, $db;
|
global $conf, $user, $db;
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
$fileprint=$conf->{$module}->dir_output;
|
$fileprint=$conf->{$module}->dir_output;
|
||||||
if ($subdir!='') $fileprint.='/'.$subdir;
|
if ($subdir!='') $fileprint.='/'.$subdir;
|
||||||
$fileprint.='/'.$file;
|
$fileprint.='/'.$file;
|
||||||
|
$mimetype = dol_mimetype($fileprint);
|
||||||
// select printer uri for module order, propal,...
|
// select printer uri for module order, propal,...
|
||||||
$sql = "SELECT rowid, printer_id, copy FROM ".MAIN_DB_PREFIX."printing WHERE module='".$module."' AND driver='printgcp' AND userid=".$user->id;
|
$sql = "SELECT rowid, printer_id, copy FROM ".MAIN_DB_PREFIX."printing WHERE module='".$module."' AND driver='printgcp' AND userid=".$user->id;
|
||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
@ -267,18 +274,18 @@ class printing_printgcp extends PrintingDriver
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 'NoDefaultPrinterDefined';
|
$this->errors[] = 'NoDefaultPrinterDefined';
|
||||||
|
$error++;
|
||||||
|
return $error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else dol_print_error($db);
|
else dol_print_error($db);
|
||||||
|
|
||||||
$ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, 'application/pdf');
|
$ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, $mimetype);
|
||||||
$this->error = 'PRINTGCP: '.$ret['errormessage'];
|
$this->errors = 'PRINTGCP: '.mb_convert_encoding($ret['errormessage'], "UTF-8");
|
||||||
if ($ret['status']==1)
|
if ($ret['status']!=1) $error++;
|
||||||
return 0;
|
return $error;
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -41,6 +41,7 @@ class printing_printipp extends PrintingDriver
|
|||||||
var $user;
|
var $user;
|
||||||
var $password;
|
var $password;
|
||||||
var $error;
|
var $error;
|
||||||
|
var $errors = array();
|
||||||
var $db;
|
var $db;
|
||||||
|
|
||||||
|
|
||||||
@ -72,11 +73,12 @@ class printing_printipp extends PrintingDriver
|
|||||||
* @param string $module module
|
* @param string $module module
|
||||||
* @param string $subdir subdirectory of document like for expedition subdir is sendings
|
* @param string $subdir subdirectory of document like for expedition subdir is sendings
|
||||||
*
|
*
|
||||||
* @return int 0 if OK, <0 if KO
|
* @return int 0 if OK, >0 if KO
|
||||||
*/
|
*/
|
||||||
function print_file($file, $module, $subdir='')
|
function print_file($file, $module, $subdir='')
|
||||||
{
|
{
|
||||||
global $conf, $user, $db;
|
global $conf, $user, $db;
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
|
include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
|
||||||
|
|
||||||
@ -108,8 +110,9 @@ class printing_printipp extends PrintingDriver
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error = 'NoDefaultPrinterDefined';
|
$this->errors[] = 'NoDefaultPrinterDefined';
|
||||||
return -1;
|
$error++;
|
||||||
|
return $error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,19 +124,26 @@ class printing_printipp extends PrintingDriver
|
|||||||
if ($subdir!='') $fileprint.='/'.$subdir;
|
if ($subdir!='') $fileprint.='/'.$subdir;
|
||||||
$fileprint.='/'.$file;
|
$fileprint.='/'.$file;
|
||||||
$ipp->setData($fileprint);
|
$ipp->setData($fileprint);
|
||||||
|
try {
|
||||||
$ipp->printJob();
|
$ipp->printJob();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->errors[] = $e->getMessage();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
if ($error==0) $this->errors[] = 'PRINTIPP: Job added';
|
||||||
|
|
||||||
return 0;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of available printers
|
* Return list of available printers
|
||||||
*
|
*
|
||||||
* @return string html list of printers
|
* @return int 0 if OK, >0 if KO
|
||||||
*/
|
*/
|
||||||
function listAvailablePrinters()
|
function listAvailablePrinters()
|
||||||
{
|
{
|
||||||
global $bc, $conf, $langs;
|
global $bc, $conf, $langs;
|
||||||
|
$error = 0;
|
||||||
$var=true;
|
$var=true;
|
||||||
|
|
||||||
$html = '<tr class="liste_titre">';
|
$html = '<tr class="liste_titre">';
|
||||||
@ -180,8 +190,8 @@ class printing_printipp extends PrintingDriver
|
|||||||
$html.= '</td>';
|
$html.= '</td>';
|
||||||
$html.= '</tr>'."\n";
|
$html.= '</tr>'."\n";
|
||||||
}
|
}
|
||||||
|
$this->resprint = $html;
|
||||||
return $html;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -256,7 +256,11 @@ if ($mode == 'test' && $user->admin)
|
|||||||
$printer = new $classname($db);
|
$printer = new $classname($db);
|
||||||
//print '<pre>'.print_r($printer, true).'</pre>';
|
//print '<pre>'.print_r($printer, true).'</pre>';
|
||||||
if (count($printer->getlist_available_printers())) {
|
if (count($printer->getlist_available_printers())) {
|
||||||
print $printer->listAvailablePrinters();
|
if ($printer->listAvailablePrinters()==0) {
|
||||||
|
print $printer->resprint;
|
||||||
|
} else {
|
||||||
|
setEventMessages($printer->error, $printer->errors, 'errors');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print $langs->trans('PleaseConfigureDriverfromList');
|
print $langs->trans('PleaseConfigureDriverfromList');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user