/** * List jobs print * * @param string $module module * * @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 $ipp->setHost($this->host); $ipp->setPort($this->port); $ipp->setUserName($this->userid); if (!empty($this->user)) { $ipp->setAuthentication($this->user, $this->password); } // select printer uri for module order, propal,... $sql = 'SELECT rowid,printer_uri,printer_name FROM ' . MAIN_DB_PREFIX . 'printer_ipp WHERE module="' . $module . '"'; $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); if ($obj) { $ipp->setPrinterURI($obj->printer_uri); } else { // All printers $ipp->setPrinterURI("ipp://localhost:631/printers/"); } } // Getting Jobs 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; //$html .= '<pre>'.print_r($jobs,true).'</pre>'; foreach ($jobs as $value) { $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>'; } $html .= "</table>"; $this->resprint = $html; return $error; }
/** * List jobs print * * @param string $module module * * @return void */ function list_jobs($module) { global $conf, $db, $bc, $langs; include_once DOL_DOCUMENT_ROOT . '/includes/printipp/CupsPrintIPP.php'; $ipp = new CupsPrintIPP(); $ipp->setLog(DOL_DATA_ROOT . '/printipp.log', 'file', 3); // logging very verbose $ipp->setHost($this->host); $ipp->setPort($this->port); $ipp->setUserName($this->userid); if (!empty($this->user)) { $ipp->setAuthentication($this->user, $this->password); } // select printer uri for module order, propal,... $sql = 'SELECT rowid,printer_uri,printer_name FROM ' . MAIN_DB_PREFIX . 'printer_ipp WHERE module="' . $module . '"'; $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); if ($obj) { $ipp->setPrinterURI($obj->printer_uri); } else { // All printers $ipp->setPrinterURI("ipp://localhost:631/printers/"); } } // Getting Jobs try { $ipp->getJobs(false, 0, 'completed', false); // May return errors if setup not correct } catch (Exception $e) { setEventMessage('[printipp] ' . $langs->trans('CoreErrorMessage'), 'errors'); dol_syslog($e->getMessage(), LOG_ERR); } 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"; $jobs = $ipp->jobs_attributes; $var = true; //print '<pre>'.print_r($jobs,true).'</pre>'; if (is_array($jobs)) { 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>'; } } print "</table>"; }
$ipp->setDocumentName("testfile with UTF-8 characters"); $ipp->setData("./test-utf8.txt");//Path to file echo "Printing testfile with UTF-8 characters: ".$ipp->printJob()."<br />"; $ipp->unsetAttribute('orientation-requested'); /* printing a gzipped file */ echo "<br /><br /><br /> TEST 7<br />"; echo "OPERATION " . $j++ . "<br />"; $ipp->setAttribute('compression', 'gzip'); $ipp->setData("./test-utf8-compressed.txt.gz"); //Path to file. echo "Printing testfile with UTF-8 characters, gzipped: " . $ipp->printJob() . "<br />"; $ipp->unsetAttribute('compression'); /* getting not-completed jobs */ echo "<br /><br /><br /> TEST 8<br />"; echo "OPERATION " . $j++ . "<br />"; echo "Getting NOT PROCESSED Jobs: " . $ipp->getJobs(true, 0, "") . "<br />"; // defaults to $my_jobs=true,$limit=0 (no limit),$which_jobs=not-completed,$subset=false echo "Job 0 state: " . $ipp->jobs_attributes->job_0->job_state->_value0 . "<br />"; echo "Job 0 state-reasons: " . $ipp->jobs_attributes->job_0->job_state_reasons->_value0 . "<br />"; echo "<pre>"; print_r($ipp->jobs_attributes); echo "</pre>"; /* getting all jobs (subset of attributes) */ echo "<br /><br /><br /> TEST 9<br />"; echo "OPERATION " . $j++ . "<br />"; #echo "Getting ALL Jobs: ".$ipp->getJobs(true,0,"completed",true)."<br />"; echo "Getting ALL Jobs: " . $ipp->getJobs(true) . "<br />"; echo "Job 0 state: " . $ipp->jobs_attributes->job_0->job_state->_value0 . "<br />"; echo "Job 0 state-reasons: " . $ipp->jobs_attributes->job_0->job_state_reasons->_value0 . "<br />"; echo "<pre>"; print_r($ipp->jobs_attributes);
public function connect(Application $app) { $controllers = $app['controllers_factory']; /** * Gets all pending print jobs for the current user. */ $controllers->get('/jobs', function (Request $request) use($app) { $Username = User::GetUsernameFromRequest($request); /* @var $cups CupsPrintIPP */ $cups = new \CupsPrintIPP(); if (!empty($app['config']) && !empty($app['config']['cups']) && !empty($app['config']['cups']['host'])) { $cups->setHost($app['config']['cups']['host']); } else { throw new \Exception("Cups is not configured."); } if (!empty($app['config']) && !empty($app['config']['cups']) && !empty($app['config']['cups']['catchall_printer'])) { $cups->setPrinterURI($app['config']['cups']['catchall_printer']); } else { throw new \Exception("Printer is not configured."); } $cups->setUserName($Username); // setting user name for server //$cups->debug_level = 3; // Debugging very verbose //$cups->setLog('/tmp/printipp','file',3); // logging very verbose if (($error = $cups->getJobs(true)) === "successfull-ok") { $jobs_attributes = []; for ($count = 0; !empty($cups->jobs_attributes->{"job_" . $count}) && is_object($cups->jobs_attributes->{"job_" . $count}); $count++) { $jobs_attributes["job_" . $count] = $cups->jobs_attributes->{"job_" . $count}; } if (!empty($jobs_attributes)) { return $app->json($jobs_attributes); } else { return $app->json(new \stdClass()); } } return $app->json($error, 500); })->before('PrintApp\\Controllers\\Shared::EnsureAuthenticatedGETJSON'); /** * Gets a list of all known beacons and the printers they are near. */ $controllers->get('/beaconMap', function (Request $request) use($app) { $all_beacons = $app['db']->fetchAll("SELECT * FROM vw_beacons_printers"); if (!empty($all_beacons)) { $beacon_map = []; foreach ($all_beacons as $beacon) { $beacon_map[$beacon["beacon_identifier"]] = $beacon['printer_name']; } return $app->json($beacon_map); } else { return $app->json([]); } })->before('PrintApp\\Controllers\\Shared::EnsureAuthenticatedGETJSON'); /** * Release all print jobs for the current user to the printer provided in * the POST data */ $controllers->post('/releaseAll', function (Request $request) use($app) { $Username = User::GetUsernameFromRequest($request); $Printer = $request->request->get('printer'); if (empty($Printer)) { throw new \Exception("Must provider a printer to print to."); } /* @var $cups CupsPrintIPP */ $cups = new \CupsPrintIPP(); if (!empty($app['config']) && !empty($app['config']['cups']) && !empty($app['config']['cups']['host'])) { $cups->setHost($app['config']['cups']['host']); } else { throw new \Exception("Cups is not configured."); } if (!empty($app['config']) && !empty($app['config']['cups']) && !empty($app['config']['cups']['catchall_printer'])) { $cups->setPrinterURI($app['config']['cups']['catchall_printer']); } else { throw new \Exception("Printer is not configured."); } $cups->setUserName($Username); $cups->debug_level = 3; // Debugging very verbose $cups->setLog('/tmp/printipp', 'file', 3); // logging very verbose if (($error = $cups->getJobs(false)) === "successfull-ok") { $jobs_attributes = []; for ($count = 0; !empty($cups->jobs_attributes->{"job_" . $count}) && is_object($cups->jobs_attributes->{"job_" . $count}); $count++) { $jobs_attributes["job_" . $count] = $cups->jobs_attributes->{"job_" . $count}; } foreach ($jobs_attributes as $v) { $job_uri = $v->job_uri->_value0; $job_id = $v->job_id->_value0; exec("/usr/sbin/lpmove " . escapeshellarg($job_id) . " " . escapeshellarg($Printer)); if (!empty($job_uri) && ($releaseJobsError = $cups->releaseJob($job_uri)) !== "successfull-ok") { return $app->json($releaseJobsError, 500); } } return $app->json(["isSuccessful" => true]); } return $app->json($error, 500); })->before('PrintApp\\Controllers\\Shared::EnsureAuthenticatedGETJSON'); return $controllers; }