PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/root/usr/share/nethesis/NethServer/Tool/phpprintipp/ExtendedPrintIPP.php

https://github.com/nethesis/nethserver-cups
PHP | 1441 lines | 986 code | 341 blank | 114 comment | 201 complexity | be99869545c50681a26075e8099eb7a0 MD5 | raw file
Possible License(s): GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
  3. /* @(#) $Header: /sources/phpprintipp/phpprintipp/php_classes/ExtendedPrintIPP.php,v 1.1 2008/06/21 00:30:57 harding Exp $
  4. *
  5. * Class PrintIPP - Send extended IPP requests.
  6. *
  7. * Copyright (C) 2005-2006 Thomas HARDING
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Library General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Library General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Library General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * mailto:thomas.harding@laposte.net
  24. * Thomas Harding, 56 rue de la bourie rouge, 45 000 ORLEANS -- FRANCE
  25. *
  26. */
  27. /*
  28. This class is intended to implement non required operations of
  29. Internet Printing Protocol on client side.
  30. References needed to debug / add functionnalities:
  31. - RFC 2910
  32. - RFC 2911
  33. - RFC 3380
  34. - RFC 3995
  35. - RFC 3996
  36. - RFC 3997
  37. - RFC 3998
  38. - ...
  39. */
  40. require_once("PrintIPP.php");
  41. class ExtendedPrintIPP extends PrintIPP {
  42. // {{{ constructor
  43. public function __construct() {
  44. parent::__construct();
  45. }
  46. // }}}
  47. /******************
  48. *
  49. * PUBLIC FUNCTIONS
  50. *
  51. *******************/
  52. // OPERATIONS
  53. // {{{ printURI ($uri)
  54. public function printURI ($uri) {
  55. self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
  56. if (!empty($uri)) {
  57. $this->document_uri = $uri;
  58. $this->setup->uri = 1;
  59. }
  60. if(!$this->_stringUri())
  61. return FALSE;
  62. $this->output = $this->stringjob;
  63. $post_values = array( "Content-Type" => "application/ipp",
  64. "Data" => $this->output);
  65. if (self::_sendHttp ($post_values,$this->paths['printers'])) {
  66. if(self::_parseServerOutput()) {
  67. $this->_parseJobAttributes();
  68. $this->_getJobId();
  69. //$this->_getPrinterUri();
  70. $this->_getJobUri();
  71. }
  72. }
  73. $this->attributes = &$this->job_attributes;
  74. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  75. $this->status = array_merge($this->status,array($this->serveroutput->status));
  76. if ($this->serveroutput->status == "successfull-ok")
  77. self::_errorLog(sprintf("printing uri %s, job %s: ",$uri,$this->last_job)
  78. .$this->serveroutput->status,3);
  79. else {
  80. $this->jobs = array_merge($this->jobs,array(""));
  81. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  82. self::_errorLog(sprintf("printing uri %s: ",$uri,$this->last_job)
  83. .$this->serveroutput->status,1);
  84. }
  85. return $this->serveroutput->status;
  86. }
  87. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  88. self::_errorLog("printing uri $uri : OPERATION FAILED",1);
  89. return false;
  90. }
  91. // }}}
  92. // {{{ purgeJobs()
  93. public function purgeJobs() {
  94. $this->jobs = array_merge($this->jobs,array(""));
  95. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  96. self::_setOperationId();
  97. $this->parsed = array();
  98. unset($this->printer_attributes);
  99. if (!isset($this->setup->uri)) {
  100. $this->getPrinters();
  101. unset($this->jobs[count($this->jobs) - 1]);
  102. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  103. unset($this->status[count($this->status) - 1]);
  104. if (array_key_exists(0,$this->available_printers))
  105. self::setPrinterURI($this->available_printers[0]);
  106. else {
  107. trigger_error(_("purgeJobs: Printer URI is not set: die"),E_USER_WARNING);
  108. self::_putDebug( _("purgeJobs: Printer URI is not set: die\n"));
  109. self::_errorLog("purgeJobs: Printer URI is not set, die",2);
  110. return FALSE;
  111. }
  112. }
  113. if (!isset($this->setup->charset))
  114. self::setCharset('us-ascii');
  115. if (!isset($this->setup->language))
  116. self::setLanguage('en_us');
  117. if (!isset($this->meta->username))
  118. self::setUserName();
  119. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  120. . chr(0x00) . chr (0x12) // purge-Jobs | operation-id
  121. . $this->meta->operation_id // request-id
  122. . chr(0x01) // start operation-attributes | operation-attributes-tag
  123. . $this->meta->charset
  124. . $this->meta->language
  125. . $this->meta->printer_uri
  126. . $this->meta->username
  127. . chr(0x22)
  128. . self::_giveMeStringLength("purge-jobs")
  129. . "purge-jobs"
  130. . self::_giveMeStringLength(chr(0x01))
  131. . chr(0x01)
  132. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  133. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  134. self::_putDebug(sprintf(_("purging jobs of %s\n"),$this->printer_uri));
  135. $this->output = $this->stringjob;
  136. $post_values = array( "Content-Type"=>"application/ipp",
  137. "Data"=>$this->output);
  138. if (self::_sendHttp ($post_values,$this->paths['admin'])) {
  139. self::_parseServerOutput();
  140. self::_parseAttributes();
  141. }
  142. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  143. $this->status = array_merge($this->status,array($this->serveroutput->status));
  144. if ($this->serveroutput->status == "successfull-ok")
  145. self::_errorLog(sprintf(_("purging jobs of %s: "),$this->printer_uri)
  146. .$this->serveroutput->status,3);
  147. else
  148. self::_errorLog(sprintf(_("purging jobs of %s: "),$this->printer_uri)
  149. .$this->serveroutput->status,1);
  150. return $this->serveroutput->status;
  151. }
  152. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  153. self::_errorLog(date("Y-m-d H:i:s : ")
  154. .basename($_SERVER['PHP_SELF'])
  155. .sprintf(_("purging jobs of %s : OPERATION FAILED"),
  156. $this->printer_uri),3);
  157. return false;
  158. }
  159. // }}}
  160. // {{{ createJob()
  161. public function createJob() {
  162. self::_setOperationId();
  163. $this->parsed = array();
  164. unset($this->printer_attributes);
  165. if (!isset($this->setup->uri)) {
  166. $this->getPrinters();
  167. unset($this->jobs[count($this->jobs) - 1]);
  168. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  169. unset($this->status[count($this->status) - 1]);
  170. if (array_key_exists(0,$this->available_printers))
  171. self::setPrinterURI($this->available_printers[0]);
  172. else {
  173. trigger_error(_("createJob: Printer URI is not set: die"),E_USER_WARNING);
  174. self::_putDebug( _("createJob: Printer URI is not set: die\n"));
  175. self::_errorLog("createJob: Printer URI is not set, die",2);
  176. return FALSE;
  177. }
  178. }
  179. if (!isset($this->setup->charset))
  180. self::setCharset('us-ascii');
  181. if (!isset($this->setup->language))
  182. self::setLanguage('en_us');
  183. if (!isset($this->meta->username))
  184. self::setUserName();
  185. if (!isset($this->setup->copies))
  186. self::setCopies(1);
  187. if (!isset($this->meta->fidelity))
  188. $this->meta->fidelity = '';
  189. if (!isset($this->meta->sides))
  190. $this->meta->sides = '';
  191. if (!isset($this->meta->page_ranges))
  192. $this->meta->page_ranges = '';
  193. if (!isset($this->setup->jobname))
  194. if (is_readable($this->data))
  195. self::setJobName(basename($this->data),true);
  196. else
  197. self::setJobName();
  198. unset($this->setup->jobname);
  199. if (!isset($this->timeout))
  200. $this->timeout = 60;
  201. $timeout = self::_integerBuild($this->timeout);
  202. $this->meta->timeout = chr(0x21) // integer
  203. . self::_giveMeStringLength("multiple-operation-time-out")
  204. . "multiple-operation-time-out"
  205. . self::_giveMeStringLength($timeout)
  206. . $timeout;
  207. $jobattributes = '';
  208. $operationattributes = '';
  209. $printerattributes = '';
  210. self::_buildValues($operationattributes,$jobattributes,$printerattributes);
  211. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  212. . chr(0x00) . chr (0x05) // Create-Job | operation-id
  213. . $this->meta->operation_id // request-id
  214. . chr(0x01) // start operation-attributes | operation-attributes-tag
  215. . $this->meta->charset
  216. . $this->meta->language
  217. . $this->meta->printer_uri
  218. . $this->meta->username
  219. . $this->meta->jobname
  220. . $this->meta->fidelity
  221. . $this->meta->timeout
  222. . $operationattributes
  223. . chr(0x02) // start job-attributes | job-attributes-tag
  224. . $this->meta->copies
  225. . $this->meta->sides
  226. . $this->meta->page_ranges
  227. . $jobattributes
  228. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  229. unset ($this->meta->copies,$this->meta->sides,$this->meta->page_ranges);
  230. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  231. self::_putDebug(sprintf(_("creating job %s, printer %s\n"),$this->last_job,$this->printer_uri));
  232. $this->output = $this->stringjob;
  233. $post_values = array( "Content-Type"=>"application/ipp",
  234. "Data"=>$this->output);
  235. if (self::_sendHttp ($post_values,$this->paths['printers']))
  236. if(self::_parseServerOutput()) {
  237. $this->_getJobId();
  238. $this->_getJobUri();
  239. $this->_parseJobAttributes();
  240. } else {
  241. $this->jobs = array_merge($this->jobs,array(''));
  242. $this->jobs_uri = array_merge($this->jobs_uri,array(''));
  243. }
  244. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  245. $this->status = array_merge($this->status,array($this->serveroutput->status));
  246. if ($this->serveroutput->status == "successfull-ok")
  247. self::_errorLog(sprintf(_("Create job: job %s"),$this->last_job)
  248. .$this->serveroutput->status,3);
  249. else {
  250. $this->jobs = array_merge($this->jobs,array(""));
  251. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  252. self::_errorLog(sprintf(_("Create-Job: %s"),$this->serveroutput->status),1);
  253. }
  254. return $this->serveroutput->status;
  255. }
  256. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  257. self::_errorLog(date("Y-m-d H:i:s : ")
  258. .basename($_SERVER['PHP_SELF'])
  259. .sprintf(_("Creating job on %s : OPERATION FAILED"),
  260. $this->printer_uri),3);
  261. $this->jobs = array_merge($this->jobs,array(""));
  262. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  263. return false;
  264. }
  265. // }}}
  266. // {{{ sendDocument($job)
  267. public function sendDocument($job,$is_last=false){
  268. self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
  269. if (!$this->_stringDocument($job,$is_last))
  270. return FALSE;
  271. if (is_readable($this->data)){
  272. self::_putDebug( _("sending Document\n"));
  273. $this->output = $this->stringjob;
  274. if ($this->setup->datatype == "TEXT")
  275. $this->output .= chr(0x16); // ASCII "SYN"
  276. $post_values = array( "Content-Type" => "application/ipp",
  277. "Data" => $this->output,
  278. "File" => $this->data);
  279. if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed))
  280. $post_values = array_merge($post_values,array("Filetype"=>"TEXT"));
  281. } else {
  282. self::_putDebug( _("sending DATA as document\n"));
  283. $this->output = $this->stringjob;
  284. $this->output .= $this->datahead;
  285. $this->output .= $this->data;
  286. $this->output .= $this->datatail;
  287. $post_values = array( "Content-Type" => "application/ipp",
  288. "Data" => $this->output);
  289. }
  290. if (self::_sendHttp ($post_values,$this->paths['printers'])) {
  291. if(self::_parseServerOutput()) {
  292. $this->_getJobId();
  293. //$this->_getPrinterUri();
  294. $this->_getJobUri();
  295. $this->_parseJobAttributes();
  296. } else {
  297. $this->jobs = array_merge($this->jobs,array($job));
  298. $this->jobs_uri = array_merge($this->jobs_uri,array($job));
  299. }
  300. }
  301. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  302. $this->status = array_merge($this->status,array($this->serveroutput->status));
  303. if ($this->serveroutput->status == "successfull-ok")
  304. self::_errorLog(sprintf("sending document, job %s: %s",$job,$this->serveroutput->status),3);
  305. else {
  306. $this->jobs = array_merge($this->jobs,array(""));
  307. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  308. self::_errorLog(sprintf("sending document, job %s: %s",$job,$this->serveroutput->status),1);
  309. }
  310. return $this->serveroutput->status;
  311. }
  312. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  313. $this->jobs = array_merge($this->jobs,array($job));
  314. $this->jobs_uri = array_merge($this->jobs_uri,array($job));
  315. self::_errorLog(sprintf("sending document, job %s : OPERATION FAILED",$job),1);
  316. return false;
  317. }
  318. // }}}
  319. // {{{ sendURI ($uri,$job,$is_last=false)
  320. public function sendURI ($uri,$job,$is_last=false){
  321. self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
  322. if (!$this->_stringSendUri($uri,$job,$is_last))
  323. return FALSE;
  324. self::_putDebug( _("sending URI $uri\n"));
  325. $this->output = $this->stringjob;
  326. $post_values = array( "Content-Type" => "application/ipp",
  327. "Data" => $this->output);
  328. if (self::_sendHttp ($post_values,$this->paths['printers'])) {
  329. if(self::_parseServerOutput()) {
  330. $this->_getJobId();
  331. //$this->_getPrinterUri();
  332. $this->_getJobUri();
  333. $this->_parseJobAttributes();
  334. } else {
  335. $this->jobs = array_merge($this->jobs,array($job));
  336. $this->jobs_uri = array_merge($this->jobs_uri,array($job));
  337. }
  338. }
  339. $this->attributes = &$this->job_attributes;
  340. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  341. $this->status = array_merge($this->status,array($this->serveroutput->status));
  342. if ($this->serveroutput->status == "successfull-ok")
  343. self::_errorLog(sprintf("sending uri %s, job %s: %s",$uri,$job,$this->serveroutput->status),3);
  344. else {
  345. $this->jobs = array_merge($this->jobs,array(""));
  346. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  347. self::_errorLog(sprintf("sending uri, job %s: %s",$uri,$job,$this->serveroutput->status),1);
  348. }
  349. return $this->serveroutput->status;
  350. }
  351. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  352. $this->jobs = array_merge($this->jobs,array($job));
  353. $this->jobs_uri = array_merge($this->jobs_uri,array($job));
  354. self::_errorLog(sprintf("sending uri %s, job %s : OPERATION FAILED",$uri,$job),1);
  355. return false;
  356. }
  357. // }}}
  358. // {{{ pausePrinter ()
  359. public function pausePrinter() {
  360. $this->jobs = array_merge($this->jobs,array(""));
  361. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  362. self::_setOperationId();
  363. $this->parsed = array();
  364. unset($this->printer_attributes);
  365. if (!isset($this->setup->uri)) {
  366. $this->getPrinters();
  367. unset($this->jobs[count($this->jobs) - 1]);
  368. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  369. unset($this->status[count($this->status) - 1]);
  370. if (array_key_exists(0,$this->available_printers))
  371. self::setPrinterURI($this->available_printers[0]);
  372. else {
  373. trigger_error(_("pausePrinter: Printer URI is not set: die"),E_USER_WARNING);
  374. self::_putDebug( _("pausePrinter: Printer URI is not set: die\n"));
  375. self::_errorLog("pausePrinter: Printer URI is not set, die",2);
  376. return FALSE;
  377. }
  378. }
  379. if (!isset($this->setup->charset))
  380. self::setCharset('us-ascii');
  381. if (!isset($this->setup->language))
  382. self::setLanguage('en_us');
  383. if (!isset($this->meta->username))
  384. self::setUserName();
  385. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  386. . chr(0x00) . chr (0x10) // Pause-Printer | operation-id
  387. . $this->meta->operation_id // request-id
  388. . chr(0x01) // start operation-attributes | operation-attributes-tag
  389. . $this->meta->charset
  390. . $this->meta->language
  391. . $this->meta->printer_uri
  392. . $this->meta->username
  393. /* . chr(0x22)
  394. . self::_giveMeStringLength("purge-jobs")
  395. . "purge-jobs"
  396. . self::_giveMeStringLength(chr(0x01))
  397. . chr(0x01) */
  398. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  399. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  400. self::_putDebug(sprintf(_("pause printer %s\n"),$this->printer_uri));
  401. $this->output = $this->stringjob;
  402. $post_values = array( "Content-Type"=>"application/ipp",
  403. "Data"=>$this->output);
  404. if (self::_sendHttp ($post_values,$this->paths['admin'])) {
  405. self::_parseServerOutput();
  406. self::_parseAttributes();
  407. }
  408. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  409. $this->status = array_merge($this->status,array($this->serveroutput->status));
  410. if ($this->serveroutput->status == "successfull-ok")
  411. self::_errorLog(sprintf(_("Pause printer %s: "),$this->printer_uri)
  412. .$this->serveroutput->status,3);
  413. else
  414. self::_errorLog(sprintf(_("pause printer %s: "),$this->printer_uri)
  415. .$this->serveroutput->status,1);
  416. return $this->serveroutput->status;
  417. }
  418. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  419. self::_errorLog(date("Y-m-d H:i:s : ")
  420. .basename($_SERVER['PHP_SELF'])
  421. .sprintf(_("pause printer %s : OPERATION FAILED"),
  422. $this->printer_uri),3);
  423. return false;
  424. }
  425. // }}}
  426. // {{{ resumePrinter ()
  427. public function resumePrinter() {
  428. $this->jobs = array_merge($this->jobs,array(""));
  429. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  430. self::_setOperationId();
  431. $this->parsed = array();
  432. unset($this->printer_attributes);
  433. if (!isset($this->setup->uri)) {
  434. $this->getPrinters();
  435. unset($this->jobs[count($this->jobs) - 1]);
  436. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  437. unset($this->status[count($this->status) - 1]);
  438. if (array_key_exists(0,$this->available_printers))
  439. self::setPrinterURI($this->available_printers[0]);
  440. else {
  441. trigger_error(_("resumePrinter: Printer URI is not set: die"),E_USER_WARNING);
  442. self::_putDebug( _("resumePrinter: Printer URI is not set: die\n"));
  443. self::_errorLog(" Printer URI is not set, die",2);
  444. return FALSE;
  445. }
  446. }
  447. if (!isset($this->setup->charset))
  448. self::setCharset('us-ascii');
  449. if (!isset($this->setup->language))
  450. self::setLanguage('en_us');
  451. if (!isset($this->meta->username))
  452. self::setUserName();
  453. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  454. . chr(0x00) . chr (0x11) // suse-Printer | operation-id
  455. . $this->meta->operation_id // request-id
  456. . chr(0x01) // start operation-attributes | operation-attributes-tag
  457. . $this->meta->charset
  458. . $this->meta->language
  459. . $this->meta->printer_uri
  460. . $this->meta->username
  461. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  462. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  463. self::_putDebug(sprintf(_("resume printer %s\n"),$this->printer_uri));
  464. $this->output = $this->stringjob;
  465. $post_values = array( "Content-Type"=>"application/ipp",
  466. "Data"=>$this->output);
  467. if (self::_sendHttp ($post_values,$this->paths['admin'])) {
  468. self::_parseServerOutput();
  469. self::_parseAttributes();
  470. }
  471. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  472. $this->status = array_merge($this->status,array($this->serveroutput->status));
  473. if ($this->serveroutput->status == "successfull-ok")
  474. self::_errorLog(sprintf(_("resume printer %s: "),$this->printer_uri)
  475. .$this->serveroutput->status,3);
  476. else
  477. self::_errorLog(sprintf(_("resume printer %s: "),$this->printer_uri)
  478. .$this->serveroutput->status,1);
  479. return $this->serveroutput->status;
  480. }
  481. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  482. self::_errorLog(date("Y-m-d H:i:s : ")
  483. .basename($_SERVER['PHP_SELF'])
  484. .sprintf(_("resume printer %s : OPERATION FAILED"),
  485. $this->printer_uri),3);
  486. return false;
  487. }
  488. // }}}
  489. // {{{ holdJob ($job_uri)
  490. public function holdJob ($job_uri,$until='indefinite') {
  491. $this->jobs = array_merge($this->jobs,array(""));
  492. $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri)));
  493. self::_setOperationId();
  494. $this->parsed = array();
  495. unset($this->printer_attributes);
  496. if (!isset($this->setup->charset))
  497. self::setCharset('us-ascii');
  498. if (!isset($this->setup->language))
  499. self::setLanguage('en_us');
  500. if (!isset($this->meta->username))
  501. self::setUserName();
  502. if (!isset($this->meta->message))
  503. $this->meta->message = '';
  504. self::_setJobUri($job_uri);
  505. $until_strings = array('no-hold','day-time','evening','night','weekend','second-shift','third-shift');
  506. if (in_array($until,$until_strings))
  507. true;
  508. else
  509. $until = 'indefinite';
  510. $this->meta->job_hold_until = chr(0x42) // keyword
  511. . self::_giveMeStringLength('job-hold-until')
  512. . 'job-hold-until'
  513. . self::_giveMeStringLength($until)
  514. . $until;
  515. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  516. . chr(0x00) . chr (0x0C) // Hold-Job | operation-id
  517. . $this->meta->operation_id // request-id
  518. . chr(0x01) // start operation-attributes | operation-attributes-tag
  519. . $this->meta->charset
  520. . $this->meta->language
  521. . $this->meta->username
  522. . $this->meta->job_uri
  523. . $this->meta->message
  524. . $this->meta->job_hold_until
  525. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  526. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  527. self::_putDebug(sprintf(_("hold job %s until %s\n"),$job_uri,$until));
  528. $this->output = $this->stringjob;
  529. $post_values = array( "Content-Type"=>"application/ipp",
  530. "Data"=>$this->output);
  531. if (self::_sendHttp ($post_values,$this->paths['jobs'])) {
  532. self::_parseServerOutput();
  533. self::_parseAttributes();
  534. }
  535. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  536. $this->status = array_merge($this->status,array($this->serveroutput->status));
  537. if ($this->serveroutput->status == "successfull-ok")
  538. self::_errorLog(sprintf(_("hold job %s until %s: "),$job_uri,$until)
  539. .$this->serveroutput->status,3);
  540. else
  541. self::_errorLog(sprintf(_("hold job %s until %s: "),$job_uri,$until)
  542. .$this->serveroutput->status,1);
  543. return $this->serveroutput->status;
  544. }
  545. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  546. self::_errorLog(date("Y-m-d H:i:s : ")
  547. .basename($_SERVER['PHP_SELF'])
  548. .sprintf(_("hold job %s until %s : OPERATION FAILED"),
  549. $job_uri,$until),3);
  550. return false;
  551. }
  552. // }}}
  553. // {{{ releaseJob ($job_uri)
  554. public function releaseJob ($job_uri) {
  555. $this->jobs = array_merge($this->jobs,array(""));
  556. $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri)));
  557. self::_setOperationId();
  558. $this->parsed = array();
  559. unset($this->printer_attributes);
  560. if (!isset($this->setup->charset))
  561. self::setCharset('us-ascii');
  562. if (!isset($this->setup->language))
  563. self::setLanguage('en_us');
  564. if (!isset($this->meta->username))
  565. self::setUserName();
  566. if (!isset($this->meta->message))
  567. $this->meta->message = '';
  568. self::_setJobUri($job_uri);
  569. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  570. . chr(0x00) . chr (0x0D) // Hold-Job | operation-id
  571. . $this->meta->operation_id // request-id
  572. . chr(0x01) // start operation-attributes | operation-attributes-tag
  573. . $this->meta->charset
  574. . $this->meta->language
  575. . $this->meta->job_uri
  576. . $this->meta->username
  577. . $this->meta->message
  578. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  579. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  580. self::_putDebug(sprintf(_("release job %s\n"),$job_uri));
  581. $this->output = $this->stringjob;
  582. $post_values = array( "Content-Type"=>"application/ipp",
  583. "Data"=>$this->output);
  584. if (self::_sendHttp ($post_values,$this->paths['jobs'])) {
  585. self::_parseServerOutput();
  586. self::_parseAttributes();
  587. }
  588. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  589. $this->status = array_merge($this->status,array($this->serveroutput->status));
  590. if ($this->serveroutput->status == "successfull-ok")
  591. self::_errorLog(sprintf(_("release job %s: "),$job_uri)
  592. .$this->serveroutput->status,3);
  593. else
  594. self::_errorLog(sprintf(_("release job %s: "),$job_uri)
  595. .$this->serveroutput->status,1);
  596. return $this->serveroutput->status;
  597. }
  598. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  599. self::_errorLog(date("Y-m-d H:i:s : ")
  600. .basename($_SERVER['PHP_SELF'])
  601. .sprintf(_("release job %s: OPERATION FAILED"),
  602. $job_uri),3);
  603. return false;
  604. }
  605. // }}}
  606. // {{{ restartJob ($job_uri)
  607. public function restartJob ($job_uri) {
  608. $this->jobs = array_merge($this->jobs,array(""));
  609. $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri)));
  610. self::_setOperationId();
  611. $this->parsed = array();
  612. unset($this->printer_attributes);
  613. if (!isset($this->setup->charset))
  614. self::setCharset('us-ascii');
  615. if (!isset($this->setup->language))
  616. self::setLanguage('en_us');
  617. if (!isset($this->meta->username))
  618. self::setUserName();
  619. if (!isset($this->meta->message))
  620. $this->meta->message = '';
  621. self::_setJobUri($job_uri);
  622. $jobattributes = '';
  623. $operationattributes = '';
  624. $printerattributes = '';
  625. self::_buildValues ($operationattributes,$jobattributes,$printerattributes);
  626. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  627. . chr(0x00) . chr (0x0E) // Hold-Job | operation-id
  628. . $this->meta->operation_id // request-id
  629. . chr(0x01) // start operation-attributes | operation-attributes-tag
  630. . $this->meta->charset
  631. . $this->meta->language
  632. . $this->meta->job_uri
  633. . $this->meta->username
  634. . $this->meta->message
  635. . $jobattributes // job-hold-until is set by setAttribute($attribute,$value)
  636. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  637. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  638. self::_putDebug(sprintf(_("release job %s\n"),$job_uri));
  639. $this->output = $this->stringjob;
  640. $post_values = array( "Content-Type"=>"application/ipp",
  641. "Data"=>$this->output);
  642. if (self::_sendHttp ($post_values,$this->paths['jobs'])) {
  643. self::_parseServerOutput();
  644. self::_parseAttributes();
  645. }
  646. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  647. $this->status = array_merge($this->status,array($this->serveroutput->status));
  648. if ($this->serveroutput->status == "successfull-ok")
  649. self::_errorLog(sprintf(_("release job %s: "),$job_uri)
  650. .$this->serveroutput->status,3);
  651. else
  652. self::_errorLog(sprintf(_("release job %s: "),$job_uri)
  653. .$this->serveroutput->status,1);
  654. return $this->serveroutput->status;
  655. }
  656. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  657. self::_errorLog(date("Y-m-d H:i:s : ")
  658. .basename($_SERVER['PHP_SELF'])
  659. .sprintf(_("release job %s: OPERATION FAILED"),
  660. $job_uri),3);
  661. return false;
  662. }
  663. // }}}
  664. // {{{ setJobAttributes ($job_uri,$deleted_attributes=array())
  665. public function setJobAttributes ($job_uri,$deleted_attributes=array()) {
  666. $this->jobs = array_merge($this->jobs,array(""));
  667. $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri)));
  668. self::_setOperationId();
  669. $this->parsed = array();
  670. unset ($this->attributes);
  671. if (!isset($this->setup->charset))
  672. self::setCharset('us-ascii');
  673. if (!isset($this->setup->language))
  674. self::setLanguage('en_us');
  675. if (!isset($this->meta->username))
  676. self::setUserName();
  677. if (!isset($this->meta->message))
  678. $this->meta->message = '';
  679. if (!isset($this->meta->copies))
  680. $this->meta->copies = '';
  681. if (!isset($this->meta->sides))
  682. $this->meta->sides = '';
  683. if (!isset($this->meta->page_ranges))
  684. $this->meta->page_ranges = '';
  685. self::_setJobUri($job_uri);
  686. $operationattributes = '';
  687. $jobattributes = '';
  688. $printerattributes = '';
  689. self::_buildValues ($operationattributes,$jobattributes,$printerattributes);
  690. $this->meta->deleted_attributes = "";
  691. for ($i = 0 ; $i < count($deleted_attributes) ; $i++)
  692. $this->meta->deleted_attributes .= chr(0x16) // out-of-band value
  693. . self::_giveMeStringLength($deleted_attributes[$i])
  694. . $deleted_attributes[$i]
  695. . chr(0x0).chr(0x0); // value-length = 0;
  696. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  697. . chr(0x00) . chr (0x14) // Set-Job-Attributes | operation-id
  698. . $this->meta->operation_id // request-id
  699. . chr(0x01) // start operation-attributes | operation-attributes-tag
  700. . $this->meta->charset
  701. . $this->meta->language
  702. . $this->meta->job_uri
  703. . $this->meta->username
  704. . $this->meta->message
  705. . chr(0x02) // start job-attributes
  706. . $jobattributes // setteds by setAttribute($attribute,$value)
  707. . $this->meta->copies
  708. . $this->meta->sides
  709. . $this->meta->page_ranges
  710. . $this->meta->deleted_attributes
  711. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  712. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  713. self::_putDebug(sprintf(_("set job attributes for job %s\n"),$job_uri));
  714. $this->output = $this->stringjob;
  715. $post_values = array( "Content-Type"=>"application/ipp",
  716. "Data"=>$this->output);
  717. if (self::_sendHttp ($post_values,$this->paths['jobs'])) {
  718. self::_parseServerOutput();
  719. self::_parseAttributes();
  720. }
  721. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  722. $this->status = array_merge($this->status,array($this->serveroutput->status));
  723. if ($this->serveroutput->status == "successfull-ok")
  724. self::_errorLog(sprintf(_("set job attributes for job %s: "),$job_uri)
  725. .$this->serveroutput->status,3);
  726. else
  727. self::_errorLog(sprintf(_("set job attributes for job %s: "),$job_uri)
  728. .$this->serveroutput->status,1);
  729. $this->last_job = $job_uri;
  730. $this->jobs_uri[count($this->jobs_uri) - 1] = $job_uri;
  731. return $this->serveroutput->status;
  732. }
  733. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  734. self::_errorLog(date("Y-m-d H:i:s : ")
  735. .basename($_SERVER['PHP_SELF'])
  736. .sprintf(_("set job attributes for job %s: OPERATION FAILED"),
  737. $job_uri),3);
  738. return false;
  739. }
  740. // }}}
  741. // {{{ setPrinterAttributes ()
  742. public function setPrinterAttributes ($document_format='',$deleted_attributes=array()) {
  743. /* $document_format (RFC 3380)
  744. If the client includes this attribute, the Printer MUST change
  745. the supplied attributes for the document format specified by
  746. this attribute. If a supplied attribute is a member of the
  747. "document-format-varying-attributes" (i.e., the attribute
  748. varies by document format, see section 6.3), the Printer MUST
  749. change the supplied attribute for the document format specified
  750. by this attribute, but not for other document formats. If a
  751. supplied attribute isn't a member of the "document-format-
  752. varying-attributes" (i.e., it doesn't vary by document format),
  753. the Printer MUST change the supplied attribute for all document
  754. formats.
  755. If the client omits this attribute, the Printer MUST change the
  756. supplied attributes for all document formats, whether or not
  757. they vary by document-format.
  758. */
  759. $this->jobs = array_merge($this->jobs,array(""));
  760. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  761. unset ($this->attributes);
  762. self::_setOperationId();
  763. $this->parsed = array();
  764. if (!isset($this->setup->charset))
  765. self::setCharset('us-ascii');
  766. if (!isset($this->setup->language))
  767. self::setLanguage('en_us');
  768. if (!isset($this->meta->username))
  769. self::setUserName();
  770. if (!isset($this->meta->message))
  771. $this->meta->message = '';
  772. if (!isset($this->meta->copies))
  773. $this->meta->copies = '';
  774. if (!isset($this->meta->sides))
  775. $this->meta->sides = '';
  776. if (!isset($this->meta->page_ranges))
  777. $this->meta->page_ranges = '';
  778. if ($document_format)
  779. $document_format = chr(0x49) // document-format tag
  780. . self::_giveMeStringLength('document-format')
  781. . 'document-format' //
  782. . self::_giveMeStringLength($document_format)
  783. . $document_format; // value
  784. $operationattributes = '';
  785. $jobattributes = '';
  786. $printerattributes = '';
  787. self::_buildValues ($operationattributes,$jobattributes,$printerattributes);
  788. $this->meta->deleted_attributes = "";
  789. for ($i = 0 ; $i < count($deleted_attributes) ; $i++)
  790. $this->meta->deleted_attributes .= chr(0x16) // out-of-band "deleted" value
  791. . self::_giveMeStringLength($deleted_attributes[$i])
  792. . $deleted_attributes[$i]
  793. . chr(0x0).chr(0x0); // value-length = 0;
  794. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  795. . chr(0x00) . chr (0x13) // Set-Printer-Attributes | operation-id
  796. . $this->meta->operation_id // request-id
  797. . chr(0x01) // start operation-attributes | operation-attributes-tag
  798. . $this->meta->charset
  799. . $this->meta->language
  800. . $this->meta->printer_uri
  801. . $this->meta->username
  802. . $this->meta->message
  803. . $operationattributes
  804. . chr(0x02) // start job-attributes
  805. . $jobattributes // setteds by setAttribute($attribute,$value)
  806. . $this->meta->copies
  807. . $this->meta->sides
  808. . $this->meta->page_ranges
  809. . $this->meta->deleted_attributes
  810. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  811. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  812. self::_putDebug(sprintf(_("set printer attributes for job %s\n"),$this->printer_uri));
  813. $this->output = $this->stringjob;
  814. $post_values = array( "Content-Type"=>"application/ipp",
  815. "Data"=>$this->output);
  816. if (self::_sendHttp ($post_values,$this->paths['printers'])) {
  817. self::_parseServerOutput();
  818. self::_parseAttributes();
  819. }
  820. if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
  821. $this->status = array_merge($this->status,array($this->serveroutput->status));
  822. if ($this->serveroutput->status == "successfull-ok")
  823. self::_errorLog(sprintf(_("set printer attributes for printer %s: "),$this->printer_uri)
  824. .$this->serveroutput->status,3);
  825. else
  826. self::_errorLog(sprintf(_("set printer attributes for printer %s: "),$this->printer_uri)
  827. .$this->serveroutput->status,1);
  828. return $this->serveroutput->status;
  829. }
  830. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  831. self::_errorLog(date("Y-m-d H:i:s : ")
  832. .basename($_SERVER['PHP_SELF'])
  833. .sprintf(_("set printer attributes for printer %s: OPERATION FAILED"),
  834. $this->printer_uri),1);
  835. return false;
  836. }
  837. // }}}
  838. // REQUEST BUILDING
  839. // {{{ _setDocumentUri ($job_uri)
  840. protected function _setDocumentUri () {
  841. $this->meta->document_uri = chr(0x45) // type uri
  842. . chr(0x00).chr(0x0c) // name-length
  843. . "document-uri"
  844. . self::_giveMeStringLength($this->document_uri)
  845. . $this->document_uri;
  846. self::_putDebug( "document uri is: ".$this->document_uri."\n");
  847. $this->setup->document_uri = 1;
  848. }
  849. // }}}
  850. // {{{ _stringUri ()
  851. protected function _stringUri () {
  852. self::_setDocumentUri();
  853. if (!isset($this->setup->document_uri)) {
  854. trigger_error(_("_stringUri: Document URI is not set: die"),E_USER_WARNING);
  855. self::_putDebug( _("_stringUri: Document URI is not set: die\n"));
  856. self::_errorLog("Document URI is not set, die",2);
  857. return FALSE;
  858. }
  859. unset ($this->setup->document_uri);
  860. if (!isset($this->setup->uri)) {
  861. $this->getPrinters();
  862. unset($this->jobs[count($this->jobs) - 1]);
  863. unset($this->jobs_uri[count($this->jobs) - 1]);
  864. unset($this->status[count($this->status) - 1]);
  865. if (array_key_exists(0,$this->available_printers))
  866. self::setPrinterURI($this->available_printers[0]);
  867. else {
  868. trigger_error(_("_stringUri: Printer URI is not set: die"),E_USER_WARNING);
  869. self::_putDebug( _("_stringUri: Printer URI is not set: die\n"));
  870. self::_errorLog("_stringUri: Printer URI is not set, die",2);
  871. return FALSE;
  872. }
  873. }
  874. if (!isset($this->setup->charset))
  875. $this->meta->charset = "";
  876. // self::setCharset('us-ascii');
  877. if (!isset($this->setup->datatype))
  878. self::setBinary();
  879. if (!isset($this->setup->uri)) {
  880. trigger_error(_("_stringUri: Printer URI is not set: die"),E_USER_WARNING);
  881. self::_putDebug( _("_stringUri: Printer URI is not set: die\n"));
  882. self::_errorLog("Printer URI is not set, die",2);
  883. return FALSE;
  884. }
  885. if (!isset($this->setup->copies))
  886. self::setCopies(1);
  887. if (!isset($this->setup->language))
  888. self::setLanguage('en_us');
  889. if (!isset($this->setup->mime_media_type))
  890. self::setMimeMediaType();
  891. unset ($this->setup->mime_media_type);
  892. if (!isset($this->setup->jobname))
  893. if (is_readable($this->data))
  894. self::setJobName(basename($this->data),true);
  895. else
  896. self::setJobName();
  897. unset($this->setup->jobname);
  898. if (!isset($this->meta->username))
  899. self::setUserName();
  900. if (!isset($this->meta->fidelity))
  901. $this->meta->fidelity = '';
  902. if (!isset($this->meta->document_name))
  903. $this->meta->document_name = '';
  904. if (!isset($this->meta->sides))
  905. $this->meta->sides = '';
  906. if (!isset($this->meta->page_ranges))
  907. $this->meta->page_ranges = '';
  908. $jobattributes = '';
  909. $operationattributes = '';
  910. $printerattributes = '';
  911. self::_buildValues($operationattributes,$jobattributes,$printerattributes);
  912. self::_setOperationId();
  913. if (!isset($this->error_generation->request_body_malformed))
  914. $this->error_generation->request_body_malformed = "";
  915. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  916. .

Large files files are truncated, but you can click here to view the full file