diff --git a/htdocs/core/modules/printing/printgcp.modules.php b/htdocs/core/modules/printing/printgcp.modules.php
index e7d34f3666c..4ce1e18b390 100644
--- a/htdocs/core/modules/printing/printgcp.modules.php
+++ b/htdocs/core/modules/printing/printgcp.modules.php
@@ -352,11 +352,13 @@ class printing_printgcp extends PrintingDriver
/**
* List jobs print
*
- * @return void
+ * @return int 0 if OK, >0 if KO
*/
function list_jobs()
{
global $conf, $db, $bc;
+ $error = 0;
+ $html = '';
// Token storage
$storage = new DoliStorage($this->db, $this->conf);
// Setup the credentials for the requests
@@ -374,6 +376,7 @@ class printing_printgcp extends PrintingDriver
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
$token_ok = false;
+ $error++;
}
$expire = false;
// Is token expired or will token expire in the next 30 seconds
@@ -391,6 +394,7 @@ class printing_printgcp extends PrintingDriver
$storage->storeAccessToken('Google', $token);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
+ $error++;
}
}
// Getting Jobs
@@ -399,35 +403,37 @@ class printing_printgcp extends PrintingDriver
$response = $apiService->request(self::PRINTERS_GET_JOBS);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
- print '
'.print_r($e->getMessage(),true).'
';
+ $error++;
}
$responsedata = json_decode($response, true);
- //print ''.print_r($responsedata,true).'
';
- print '';
- print '';
- print "| Id | ";
- print "Owner | ";
- print "Printer | ";
- print "File | ";
- print "Status | ";
- print "Cancel | ";
- print "
\n";
+ //$html .= ''.print_r($responsedata,true).'
';
+ $html .= '';
+ $html .= '';
+ $html .= "| Id | ";
+ $html .= "Owner | ";
+ $html .= 'Printer | ';
+ $html .= 'File | ';
+ $html .= 'Status | ';
+ $html .= 'Cancel | ';
+ $html .= '
'."\n";
$var = True;
$jobs = $responsedata['jobs'];
- //print ''.print_r($jobs['0'],true).'
';
+ //$html .= ''.print_r($jobs['0'],true).'
';
foreach ($jobs as $value )
{
- $var=!$var;
- print "";
- print '| '.$value['id'].' | ';
- print ''.$value['ownerId'].' | ';
- print ''.$value['printerName'].' | ';
- print ''.$value['title'].' | ';
- print ''.$value['status'].' | ';
- print ' | ';
- print '
';
+ $var = !$var;
+ $html .= '';
+ $html .= '| '.$value['id'].' | ';
+ $html .= ''.$value['ownerId'].' | ';
+ $html .= ''.$value['printerName'].' | ';
+ $html .= ''.$value['title'].' | ';
+ $html .= ''.$value['status'].' | ';
+ $html .= ' | ';
+ $html .= '
';
}
- print "
";
+ $html .= '
';
+ $this->resprint = $html;
+ return $error;
}
}
diff --git a/htdocs/core/modules/printing/printipp.modules.php b/htdocs/core/modules/printing/printipp.modules.php
index 56cd4c3b2b6..6e8ad305339 100644
--- a/htdocs/core/modules/printing/printipp.modules.php
+++ b/htdocs/core/modules/printing/printipp.modules.php
@@ -228,13 +228,15 @@ class printing_printipp extends PrintingDriver
/**
* List jobs print
*
- * @param string $module module
+ * @param string $module module
*
- * @return void
+ * @return int 0 if OK, >0 if KO
*/
function list_jobs($module)
{
global $conf, $db, $bc;
+ $error = 0;
+ $html = '';
include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
$ipp = new CupsPrintIPP();
$ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose
@@ -259,32 +261,39 @@ class printing_printipp extends PrintingDriver
}
}
// Getting Jobs
- $ipp->getJobs(false,0,'completed',false);
- print '';
- print '';
- print "| Id | ";
- print "Owner | ";
- print "Printer | ";
- print "File | ";
- print "Status | ";
- print "Cancel | ";
- print "
\n";
+ try {
+ $ipp->getJobs(false,0,'completed',false);
+ } catch (Exception $e) {
+ $this->errors[] = $e->getMessage();
+ $error++;
+ }
+ $html .= '';
+ $html .= '';
+ $html .= '| Id | ';
+ $html .= 'Owner | ';
+ $html .= 'Printer | ';
+ $html .= 'File | ';
+ $html .= 'Status | ';
+ $html .= 'Cancel | ';
+ $html .= '
'."\n";
$jobs = $ipp->jobs_attributes;
$var = True;
- //print ''.print_r($jobs,true).'
';
+ //$html .= ''.print_r($jobs,true).'
';
foreach ($jobs as $value )
{
- $var=!$var;
- print "";
- print '| '.$value->job_id->_value0.' | ';
- print ''.$value->job_originating_user_name->_value0.' | ';
- print ''.$value->printer_uri->_value0.' | ';
- print ''.$value->job_name->_value0.' | ';
- print ''.$value->job_state->_value0.' | ';
- print ''.$value->job_uri->_value0.' | ';
- print '
';
+ $var = !$var;
+ $html .= '';
+ $html .= '| '.$value->job_id->_value0.' | ';
+ $html .= ''.$value->job_originating_user_name->_value0.' | ';
+ $html .= ''.$value->printer_uri->_value0.' | ';
+ $html .= ''.$value->job_name->_value0.' | ';
+ $html .= ''.$value->job_state->_value0.' | ';
+ $html .= ''.$value->job_uri->_value0.' | ';
+ $html .= '
';
}
- print "
";
+ $html .= "
";
+ $this->resprint = $html;
+ return $error;
}
}
diff --git a/htdocs/printing/index.php b/htdocs/printing/index.php
index 2bee135ca44..1a1b038d47f 100644
--- a/htdocs/printing/index.php
+++ b/htdocs/printing/index.php
@@ -39,7 +39,11 @@ foreach ($result as $driver) {
$printer = new $classname($db);
if ($conf->global->{$printer->active}) {
//$printer->list_jobs('commande');
- $printer->list_jobs();
+ if ($printer->list_jobs()==0) {
+ print $printer->resprint;
+ } else {
+ setEventMessages($printer->error, $printer->errors, 'errors');
+ }
}
}