List Jobs

This commit is contained in:
frederic34 2015-11-01 10:10:14 +01:00
parent bb06a55844
commit 2b4224d4c4
3 changed files with 66 additions and 47 deletions

View File

@ -352,11 +352,13 @@ class printing_printgcp extends PrintingDriver
/** /**
* List jobs print * List jobs print
* *
* @return void * @return int 0 if OK, >0 if KO
*/ */
function list_jobs() function list_jobs()
{ {
global $conf, $db, $bc; global $conf, $db, $bc;
$error = 0;
$html = '';
// Token storage // Token storage
$storage = new DoliStorage($this->db, $this->conf); $storage = new DoliStorage($this->db, $this->conf);
// Setup the credentials for the requests // Setup the credentials for the requests
@ -374,6 +376,7 @@ class printing_printgcp extends PrintingDriver
} catch (Exception $e) { } catch (Exception $e) {
$this->errors[] = $e->getMessage(); $this->errors[] = $e->getMessage();
$token_ok = false; $token_ok = false;
$error++;
} }
$expire = false; $expire = false;
// Is token expired or will token expire in the next 30 seconds // 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); $storage->storeAccessToken('Google', $token);
} catch (Exception $e) { } catch (Exception $e) {
$this->errors[] = $e->getMessage(); $this->errors[] = $e->getMessage();
$error++;
} }
} }
// Getting Jobs // Getting Jobs
@ -399,35 +403,37 @@ class printing_printgcp extends PrintingDriver
$response = $apiService->request(self::PRINTERS_GET_JOBS); $response = $apiService->request(self::PRINTERS_GET_JOBS);
} catch (Exception $e) { } catch (Exception $e) {
$this->errors[] = $e->getMessage(); $this->errors[] = $e->getMessage();
print '<pre>'.print_r($e->getMessage(),true).'</pre>'; $error++;
} }
$responsedata = json_decode($response, true); $responsedata = json_decode($response, true);
//print '<pre>'.print_r($responsedata,true).'</pre>'; //$html .= '<pre>'.print_r($responsedata,true).'</pre>';
print '<table width="100%" class="noborder">'; $html .= '<table width="100%" class="noborder">';
print '<tr class="liste_titre">'; $html .= '<tr class="liste_titre">';
print "<td>Id</td>"; $html .= "<td>Id</td>";
print "<td>Owner</td>"; $html .= "<td>Owner</td>";
print "<td>Printer</td>"; $html .= '<td>Printer</td>';
print "<td>File</td>"; $html .= '<td>File</td>';
print "<td>Status</td>"; $html .= '<td>Status</td>';
print "<td>Cancel</td>"; $html .= '<td>Cancel</td>';
print "</tr>\n"; $html .= '</tr>'."\n";
$var = True; $var = True;
$jobs = $responsedata['jobs']; $jobs = $responsedata['jobs'];
//print '<pre>'.print_r($jobs['0'],true).'</pre>'; //$html .= '<pre>'.print_r($jobs['0'],true).'</pre>';
foreach ($jobs as $value ) foreach ($jobs as $value )
{ {
$var=!$var; $var = !$var;
print "<tr ".$bc[$var].">"; $html .= '<tr '.$bc[$var].'>';
print '<td>'.$value['id'].'</td>'; $html .= '<td>'.$value['id'].'</td>';
print '<td>'.$value['ownerId'].'</td>'; $html .= '<td>'.$value['ownerId'].'</td>';
print '<td>'.$value['printerName'].'</td>'; $html .= '<td>'.$value['printerName'].'</td>';
print '<td>'.$value['title'].'</td>'; $html .= '<td>'.$value['title'].'</td>';
print '<td>'.$value['status'].'</td>'; $html .= '<td>'.$value['status'].'</td>';
print '<td>&nbsp;</td>'; $html .= '<td>&nbsp;</td>';
print '</tr>'; $html .= '</tr>';
} }
print "</table>"; $html .= '</table>';
$this->resprint = $html;
return $error;
} }
} }

View File

@ -228,13 +228,15 @@ class printing_printipp extends PrintingDriver
/** /**
* List jobs print * 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) function list_jobs($module)
{ {
global $conf, $db, $bc; global $conf, $db, $bc;
$error = 0;
$html = '';
include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php'; include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
$ipp = new CupsPrintIPP(); $ipp = new CupsPrintIPP();
$ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose
@ -259,32 +261,39 @@ class printing_printipp extends PrintingDriver
} }
} }
// Getting Jobs // Getting Jobs
$ipp->getJobs(false,0,'completed',false); try {
print '<table width="100%" class="noborder">'; $ipp->getJobs(false,0,'completed',false);
print '<tr class="liste_titre">'; } catch (Exception $e) {
print "<td>Id</td>"; $this->errors[] = $e->getMessage();
print "<td>Owner</td>"; $error++;
print "<td>Printer</td>"; }
print "<td>File</td>"; $html .= '<table width="100%" class="noborder">';
print "<td>Status</td>"; $html .= '<tr class="liste_titre">';
print "<td>Cancel</td>"; $html .= '<td>Id</td>';
print "</tr>\n"; $html .= '<td>Owner</td>';
$html .= '<td>Printer</td>';
$html .= '<td>File</td>';
$html .= '<td>Status</td>';
$html .= '<td>Cancel</td>';
$html .= '</tr>'."\n";
$jobs = $ipp->jobs_attributes; $jobs = $ipp->jobs_attributes;
$var = True; $var = True;
//print '<pre>'.print_r($jobs,true).'</pre>'; //$html .= '<pre>'.print_r($jobs,true).'</pre>';
foreach ($jobs as $value ) foreach ($jobs as $value )
{ {
$var=!$var; $var = !$var;
print "<tr ".$bc[$var].">"; $html .= '<tr '.$bc[$var].'>';
print '<td>'.$value->job_id->_value0.'</td>'; $html .= '<td>'.$value->job_id->_value0.'</td>';
print '<td>'.$value->job_originating_user_name->_value0.'</td>'; $html .= '<td>'.$value->job_originating_user_name->_value0.'</td>';
print '<td>'.$value->printer_uri->_value0.'</td>'; $html .= '<td>'.$value->printer_uri->_value0.'</td>';
print '<td>'.$value->job_name->_value0.'</td>'; $html .= '<td>'.$value->job_name->_value0.'</td>';
print '<td>'.$value->job_state->_value0.'</td>'; $html .= '<td>'.$value->job_state->_value0.'</td>';
print '<td>'.$value->job_uri->_value0.'</td>'; $html .= '<td>'.$value->job_uri->_value0.'</td>';
print '</tr>'; $html .= '</tr>';
} }
print "</table>"; $html .= "</table>";
$this->resprint = $html;
return $error;
} }
} }

View File

@ -39,7 +39,11 @@ foreach ($result as $driver) {
$printer = new $classname($db); $printer = new $classname($db);
if ($conf->global->{$printer->active}) { if ($conf->global->{$printer->active}) {
//$printer->list_jobs('commande'); //$printer->list_jobs('commande');
$printer->list_jobs(); if ($printer->list_jobs()==0) {
print $printer->resprint;
} else {
setEventMessages($printer->error, $printer->errors, 'errors');
}
} }
} }