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
*
* @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 '<pre>'.print_r($e->getMessage(),true).'</pre>';
$error++;
}
$responsedata = json_decode($response, true);
//print '<pre>'.print_r($responsedata,true).'</pre>';
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print "<td>Id</td>";
print "<td>Owner</td>";
print "<td>Printer</td>";
print "<td>File</td>";
print "<td>Status</td>";
print "<td>Cancel</td>";
print "</tr>\n";
//$html .= '<pre>'.print_r($responsedata,true).'</pre>';
$html .= '<table width="100%" class="noborder">';
$html .= '<tr class="liste_titre">';
$html .= "<td>Id</td>";
$html .= "<td>Owner</td>";
$html .= '<td>Printer</td>';
$html .= '<td>File</td>';
$html .= '<td>Status</td>';
$html .= '<td>Cancel</td>';
$html .= '</tr>'."\n";
$var = True;
$jobs = $responsedata['jobs'];
//print '<pre>'.print_r($jobs['0'],true).'</pre>';
//$html .= '<pre>'.print_r($jobs['0'],true).'</pre>';
foreach ($jobs as $value )
{
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td>'.$value['id'].'</td>';
print '<td>'.$value['ownerId'].'</td>';
print '<td>'.$value['printerName'].'</td>';
print '<td>'.$value['title'].'</td>';
print '<td>'.$value['status'].'</td>';
print '<td>&nbsp;</td>';
print '</tr>';
$var = !$var;
$html .= '<tr '.$bc[$var].'>';
$html .= '<td>'.$value['id'].'</td>';
$html .= '<td>'.$value['ownerId'].'</td>';
$html .= '<td>'.$value['printerName'].'</td>';
$html .= '<td>'.$value['title'].'</td>';
$html .= '<td>'.$value['status'].'</td>';
$html .= '<td>&nbsp;</td>';
$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
*
* @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 '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print "<td>Id</td>";
print "<td>Owner</td>";
print "<td>Printer</td>";
print "<td>File</td>";
print "<td>Status</td>";
print "<td>Cancel</td>";
print "</tr>\n";
try {
$ipp->getJobs(false,0,'completed',false);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
$error++;
}
$html .= '<table width="100%" class="noborder">';
$html .= '<tr class="liste_titre">';
$html .= '<td>Id</td>';
$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;
$var = True;
//print '<pre>'.print_r($jobs,true).'</pre>';
//$html .= '<pre>'.print_r($jobs,true).'</pre>';
foreach ($jobs as $value )
{
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td>'.$value->job_id->_value0.'</td>';
print '<td>'.$value->job_originating_user_name->_value0.'</td>';
print '<td>'.$value->printer_uri->_value0.'</td>';
print '<td>'.$value->job_name->_value0.'</td>';
print '<td>'.$value->job_state->_value0.'</td>';
print '<td>'.$value->job_uri->_value0.'</td>';
print '</tr>';
$var = !$var;
$html .= '<tr '.$bc[$var].'>';
$html .= '<td>'.$value->job_id->_value0.'</td>';
$html .= '<td>'.$value->job_originating_user_name->_value0.'</td>';
$html .= '<td>'.$value->printer_uri->_value0.'</td>';
$html .= '<td>'.$value->job_name->_value0.'</td>';
$html .= '<td>'.$value->job_state->_value0.'</td>';
$html .= '<td>'.$value->job_uri->_value0.'</td>';
$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);
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');
}
}
}