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})) {
|
||||
$subdir=(GETPOST('printer', 'alpha')=='expedition'?'sending':'');
|
||||
$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');
|
||||
}
|
||||
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);
|
||||
$printed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($printed==0) setEventMessages($langs->trans("NoActivePrintingModuleFound"), null);
|
||||
if ($printed==0) setEventMessages($langs->trans("NoActivePrintingModuleFound"), null, 'warning');
|
||||
} else {
|
||||
setEventMessages($langs->trans("NoModuleFound"), null, 'warning');
|
||||
}
|
||||
|
||||
@ -42,6 +42,8 @@ class printing_printgcp extends PrintingDriver
|
||||
var $conf = array();
|
||||
var $google_id = '';
|
||||
var $google_secret = '';
|
||||
var $error;
|
||||
var $errors = array();
|
||||
var $db;
|
||||
|
||||
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 string html list of printers
|
||||
* @return int 0 if OK, >0 if KO
|
||||
*/
|
||||
function listAvailablePrinters()
|
||||
{
|
||||
global $bc, $conf, $langs;
|
||||
$error = 0;
|
||||
$langs->load('printing');
|
||||
$var=true;
|
||||
|
||||
@ -145,7 +148,7 @@ class printing_printgcp extends PrintingDriver
|
||||
$var = true;
|
||||
foreach ($list['available'] as $printer_det)
|
||||
{
|
||||
$var=!$var;
|
||||
$var = !$var;
|
||||
$html.= "<tr ".$bc[$var].">";
|
||||
$html.= '<td>'.$printer_det['name'].'</td>';
|
||||
$html.= '<td>'.$printer_det['displayName'].'</td>';
|
||||
@ -165,8 +168,8 @@ class printing_printgcp extends PrintingDriver
|
||||
$html.= '</td>';
|
||||
$html.= '</tr>'."\n";
|
||||
}
|
||||
|
||||
return $html;
|
||||
$this->resprint = $html;
|
||||
return $error;
|
||||
}
|
||||
|
||||
|
||||
@ -240,15 +243,19 @@ class printing_printgcp extends PrintingDriver
|
||||
* @param string $file file
|
||||
* @param string $module module
|
||||
* @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='')
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
global $conf, $user, $db;
|
||||
$error = 0;
|
||||
|
||||
$fileprint=$conf->{$module}->dir_output;
|
||||
if ($subdir!='') $fileprint.='/'.$subdir;
|
||||
$fileprint.='/'.$file;
|
||||
$mimetype = dol_mimetype($fileprint);
|
||||
// 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;
|
||||
$result = $db->query($sql);
|
||||
@ -267,18 +274,18 @@ class printing_printgcp extends PrintingDriver
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'NoDefaultPrinterDefined';
|
||||
$this->errors[] = 'NoDefaultPrinterDefined';
|
||||
$error++;
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else dol_print_error($db);
|
||||
|
||||
$ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, 'application/pdf');
|
||||
$this->error = 'PRINTGCP: '.$ret['errormessage'];
|
||||
if ($ret['status']==1)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
$ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, $mimetype);
|
||||
$this->errors = 'PRINTGCP: '.mb_convert_encoding($ret['errormessage'], "UTF-8");
|
||||
if ($ret['status']!=1) $error++;
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -41,6 +41,7 @@ class printing_printipp extends PrintingDriver
|
||||
var $user;
|
||||
var $password;
|
||||
var $error;
|
||||
var $errors = array();
|
||||
var $db;
|
||||
|
||||
|
||||
@ -72,11 +73,12 @@ class printing_printipp extends PrintingDriver
|
||||
* @param string $module module
|
||||
* @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='')
|
||||
{
|
||||
global $conf, $user, $db;
|
||||
$error = 0;
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
|
||||
|
||||
@ -108,8 +110,9 @@ class printing_printipp extends PrintingDriver
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = 'NoDefaultPrinterDefined';
|
||||
return -1;
|
||||
$this->errors[] = 'NoDefaultPrinterDefined';
|
||||
$error++;
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,19 +124,26 @@ class printing_printipp extends PrintingDriver
|
||||
if ($subdir!='') $fileprint.='/'.$subdir;
|
||||
$fileprint.='/'.$file;
|
||||
$ipp->setData($fileprint);
|
||||
$ipp->printJob();
|
||||
try {
|
||||
$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 string html list of printers
|
||||
* @return int 0 if OK, >0 if KO
|
||||
*/
|
||||
function listAvailablePrinters()
|
||||
{
|
||||
global $bc, $conf, $langs;
|
||||
$error = 0;
|
||||
$var=true;
|
||||
|
||||
$html = '<tr class="liste_titre">';
|
||||
@ -180,8 +190,8 @@ class printing_printipp extends PrintingDriver
|
||||
$html.= '</td>';
|
||||
$html.= '</tr>'."\n";
|
||||
}
|
||||
|
||||
return $html;
|
||||
$this->resprint = $html;
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -256,7 +256,11 @@ if ($mode == 'test' && $user->admin)
|
||||
$printer = new $classname($db);
|
||||
//print '<pre>'.print_r($printer, true).'</pre>';
|
||||
if (count($printer->getlist_available_printers())) {
|
||||
print $printer->listAvailablePrinters();
|
||||
if ($printer->listAvailablePrinters()==0) {
|
||||
print $printer->resprint;
|
||||
} else {
|
||||
setEventMessages($printer->error, $printer->errors, 'errors');
|
||||
}
|
||||
}
|
||||
else {
|
||||
print $langs->trans('PleaseConfigureDriverfromList');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user