ExtendedPrintIPP.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  1. <?php
  2. /* @(#) $Header: /sources/phpprintipp/phpprintipp/php_classes/ExtendedPrintIPP.php,v 1.1 2008/06/21 00:30:57 harding Exp $
  3. *
  4. * Class PrintIPP - Send extended IPP requests.
  5. *
  6. * Copyright (C) 2005-2006 Thomas HARDING
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * mailto:thomas.harding@laposte.net
  23. * Thomas Harding, 56 rue de la bourie rouge, 45 000 ORLEANS -- FRANCE
  24. *
  25. */
  26. /*
  27. This class is intended to implement non required operations of
  28. Internet Printing Protocol on client side.
  29. References needed to debug / add functionnalities:
  30. - RFC 2910
  31. - RFC 2911
  32. - RFC 3380
  33. - RFC 3995
  34. - RFC 3996
  35. - RFC 3997
  36. - RFC 3998
  37. - ...
  38. */
  39. require_once("PrintIPP.php");
  40. class ExtendedPrintIPP extends PrintIPP
  41. {
  42. public function __construct()
  43. {
  44. parent::__construct();
  45. }
  46. // OPERATIONS
  47. public function printURI ($uri)
  48. {
  49. self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
  50. if (!empty($uri))
  51. {
  52. $this->document_uri = $uri;
  53. $this->setup->uri = 1;
  54. }
  55. if(!$this->_stringUri())
  56. {
  57. return FALSE;
  58. }
  59. $this->output = $this->stringjob;
  60. $post_values = array( "Content-Type" => "application/ipp",
  61. "Data" => $this->output);
  62. if (self::_sendHttp ($post_values,$this->paths['printers']))
  63. {
  64. if(self::_parseServerOutput())
  65. {
  66. $this->_parseJobAttributes();
  67. $this->_getJobId();
  68. //$this->_getPrinterUri();
  69. $this->_getJobUri();
  70. }
  71. }
  72. $this->attributes = &$this->job_attributes;
  73. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  74. {
  75. $this->status = array_merge($this->status,array($this->serveroutput->status));
  76. if ($this->serveroutput->status == "successfull-ok")
  77. {
  78. self::_errorLog(sprintf("printing uri %s, job %s: ",$uri,$this->last_job)
  79. .$this->serveroutput->status,3);
  80. }
  81. else
  82. {
  83. $this->jobs = array_merge($this->jobs,array(""));
  84. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  85. self::_errorLog(sprintf("printing uri %s: ",$uri,$this->last_job)
  86. .$this->serveroutput->status,1);
  87. }
  88. return $this->serveroutput->status;
  89. }
  90. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  91. self::_errorLog("printing uri $uri : OPERATION FAILED",1);
  92. return false;
  93. }
  94. public function purgeJobs()
  95. {
  96. $this->jobs = array_merge($this->jobs,array(""));
  97. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  98. self::_setOperationId();
  99. $this->parsed = array();
  100. unset($this->printer_attributes);
  101. if (!isset($this->setup->uri))
  102. {
  103. $this->getPrinters();
  104. unset($this->jobs[count($this->jobs) - 1]);
  105. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  106. unset($this->status[count($this->status) - 1]);
  107. if (array_key_exists(0,$this->available_printers))
  108. {
  109. self::setPrinterURI($this->available_printers[0]);
  110. }
  111. else
  112. {
  113. trigger_error(_("purgeJobs: Printer URI is not set: die"),E_USER_WARNING);
  114. self::_putDebug( _("purgeJobs: Printer URI is not set: die\n"));
  115. self::_errorLog("purgeJobs: Printer URI is not set, die",2);
  116. return FALSE;
  117. }
  118. }
  119. if (!isset($this->setup->charset))
  120. {
  121. self::setCharset();
  122. }
  123. if (!isset($this->setup->language))
  124. {
  125. self::setLanguage('en_us');
  126. }
  127. if (!isset($this->meta->username))
  128. {
  129. self::setUserName();
  130. }
  131. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  132. . chr(0x00) . chr (0x12) // purge-Jobs | operation-id
  133. . $this->meta->operation_id // request-id
  134. . chr(0x01) // start operation-attributes | operation-attributes-tag
  135. . $this->meta->charset
  136. . $this->meta->language
  137. . $this->meta->printer_uri
  138. . $this->meta->username
  139. . chr(0x22)
  140. . self::_giveMeStringLength("purge-jobs")
  141. . "purge-jobs"
  142. . self::_giveMeStringLength(chr(0x01))
  143. . chr(0x01)
  144. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  145. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  146. self::_putDebug(sprintf(_("purging jobs of %s\n"),$this->printer_uri));
  147. $this->output = $this->stringjob;
  148. $post_values = array( "Content-Type"=>"application/ipp",
  149. "Data"=>$this->output);
  150. if (self::_sendHttp ($post_values,$this->paths['admin']))
  151. {
  152. self::_parseServerOutput();
  153. self::_parseAttributes();
  154. }
  155. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  156. {
  157. $this->status = array_merge($this->status,array($this->serveroutput->status));
  158. if ($this->serveroutput->status == "successfull-ok")
  159. {
  160. self::_errorLog(sprintf(_("purging jobs of %s: "),$this->printer_uri)
  161. .$this->serveroutput->status,3);
  162. }
  163. else
  164. {
  165. self::_errorLog(sprintf(_("purging jobs of %s: "),$this->printer_uri)
  166. .$this->serveroutput->status,1);
  167. }
  168. return $this->serveroutput->status;
  169. }
  170. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  171. self::_errorLog(date("Y-m-d H:i:s : ")
  172. .basename($_SERVER['PHP_SELF'])
  173. .sprintf(_("purging jobs of %s : OPERATION FAILED"),
  174. $this->printer_uri),3);
  175. return false;
  176. }
  177. public function createJob()
  178. {
  179. self::_setOperationId();
  180. $this->parsed = array();
  181. unset($this->printer_attributes);
  182. if (!isset($this->setup->uri))
  183. {
  184. $this->getPrinters();
  185. unset($this->jobs[count($this->jobs) - 1]);
  186. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  187. unset($this->status[count($this->status) - 1]);
  188. if (array_key_exists(0,$this->available_printers))
  189. {
  190. self::setPrinterURI($this->available_printers[0]);
  191. }
  192. else
  193. {
  194. trigger_error(_("createJob: Printer URI is not set: die"),E_USER_WARNING);
  195. self::_putDebug( _("createJob: Printer URI is not set: die\n"));
  196. self::_errorLog("createJob: Printer URI is not set, die",2);
  197. return FALSE;
  198. }
  199. }
  200. if (!isset($this->setup->charset))
  201. {
  202. self::setCharset();
  203. }
  204. if (!isset($this->setup->language))
  205. {
  206. self::setLanguage('en_us');
  207. }
  208. if (!isset($this->meta->username))
  209. {
  210. self::setUserName();
  211. }
  212. if (!isset($this->setup->copies))
  213. {
  214. self::setCopies(1);
  215. }
  216. if (!isset($this->meta->fidelity))
  217. {
  218. $this->meta->fidelity = '';
  219. }
  220. if (!isset($this->meta->sides))
  221. {
  222. $this->meta->sides = '';
  223. }
  224. if (!isset($this->meta->page_ranges))
  225. {
  226. $this->meta->page_ranges = '';
  227. }
  228. if (!isset($this->setup->jobname))
  229. {
  230. if (is_readable($this->data))
  231. {
  232. self::setJobName(basename($this->data),true);
  233. }
  234. else
  235. {
  236. self::setJobName();
  237. }
  238. }
  239. unset($this->setup->jobname);
  240. if (!isset($this->timeout))
  241. {
  242. $this->timeout = 60;
  243. }
  244. $timeout = self::_integerBuild($this->timeout);
  245. $this->meta->timeout = chr(0x21) // integer
  246. . self::_giveMeStringLength("multiple-operation-time-out")
  247. . "multiple-operation-time-out"
  248. . self::_giveMeStringLength($timeout)
  249. . $timeout;
  250. $jobattributes = '';
  251. $operationattributes = '';
  252. $printerattributes = '';
  253. self::_buildValues($operationattributes,$jobattributes,$printerattributes);
  254. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  255. . chr(0x00) . chr (0x05) // Create-Job | operation-id
  256. . $this->meta->operation_id // request-id
  257. . chr(0x01) // start operation-attributes | operation-attributes-tag
  258. . $this->meta->charset
  259. . $this->meta->language
  260. . $this->meta->printer_uri
  261. . $this->meta->username
  262. . $this->meta->jobname
  263. . $this->meta->fidelity
  264. . $this->meta->timeout
  265. . $operationattributes
  266. . chr(0x02) // start job-attributes | job-attributes-tag
  267. . $this->meta->copies
  268. . $this->meta->sides
  269. . $this->meta->page_ranges
  270. . $jobattributes
  271. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  272. unset ($this->meta->copies,$this->meta->sides,$this->meta->page_ranges);
  273. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  274. self::_putDebug(sprintf(_("creating job %s, printer %s\n"),$this->last_job,$this->printer_uri));
  275. $this->output = $this->stringjob;
  276. $post_values = array( "Content-Type"=>"application/ipp",
  277. "Data"=>$this->output);
  278. if (self::_sendHttp ($post_values,$this->paths['printers']))
  279. {
  280. if(self::_parseServerOutput())
  281. {
  282. $this->_getJobId();
  283. $this->_getJobUri();
  284. $this->_parseJobAttributes();
  285. }
  286. else
  287. {
  288. $this->jobs = array_merge($this->jobs,array(''));
  289. $this->jobs_uri = array_merge($this->jobs_uri,array(''));
  290. }
  291. }
  292. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  293. {
  294. $this->status = array_merge($this->status,array($this->serveroutput->status));
  295. if ($this->serveroutput->status == "successfull-ok")
  296. {
  297. self::_errorLog(sprintf(_("Create job: job %s"),$this->last_job)
  298. .$this->serveroutput->status,3);
  299. }
  300. else
  301. {
  302. $this->jobs = array_merge($this->jobs,array(""));
  303. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  304. self::_errorLog(sprintf(_("Create-Job: %s"),$this->serveroutput->status),1);
  305. }
  306. return $this->serveroutput->status;
  307. }
  308. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  309. self::_errorLog(date("Y-m-d H:i:s : ")
  310. .basename($_SERVER['PHP_SELF'])
  311. .sprintf(_("Creating job on %s : OPERATION FAILED"),
  312. $this->printer_uri),3);
  313. $this->jobs = array_merge($this->jobs,array(""));
  314. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  315. return false;
  316. }
  317. public function sendDocument($job,$is_last=false)
  318. {
  319. self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
  320. if (!$this->_stringDocument($job,$is_last))
  321. {
  322. return FALSE;
  323. }
  324. if (is_readable($this->data))
  325. {
  326. self::_putDebug( _("sending Document\n"));
  327. $this->output = $this->stringjob;
  328. if ($this->setup->datatype == "TEXT")
  329. {
  330. $this->output .= chr(0x16);
  331. } // ASCII "SYN"
  332. $post_values = array( "Content-Type" => "application/ipp",
  333. "Data" => $this->output,
  334. "File" => $this->data);
  335. if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed))
  336. {
  337. $post_values = array_merge($post_values,array("Filetype"=>"TEXT"));
  338. }
  339. }
  340. else
  341. {
  342. self::_putDebug( _("sending DATA as document\n"));
  343. $this->output = $this->stringjob;
  344. $this->output .= $this->datahead;
  345. $this->output .= $this->data;
  346. $this->output .= $this->datatail;
  347. $post_values = array( "Content-Type" => "application/ipp",
  348. "Data" => $this->output);
  349. }
  350. if (self::_sendHttp ($post_values,$this->paths['printers']))
  351. {
  352. if(self::_parseServerOutput())
  353. {
  354. $this->_getJobId();
  355. //$this->_getPrinterUri();
  356. $this->_getJobUri();
  357. $this->_parseJobAttributes();
  358. }
  359. else
  360. {
  361. $this->jobs = array_merge($this->jobs,array($job));
  362. $this->jobs_uri = array_merge($this->jobs_uri,array($job));
  363. }
  364. }
  365. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  366. {
  367. $this->status = array_merge($this->status,array($this->serveroutput->status));
  368. if ($this->serveroutput->status == "successfull-ok")
  369. {
  370. self::_errorLog(sprintf("sending document, job %s: %s",$job,$this->serveroutput->status),3);
  371. }
  372. else
  373. {
  374. $this->jobs = array_merge($this->jobs,array(""));
  375. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  376. self::_errorLog(sprintf("sending document, job %s: %s",$job,$this->serveroutput->status),1);
  377. }
  378. return $this->serveroutput->status;
  379. }
  380. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  381. $this->jobs = array_merge($this->jobs,array($job));
  382. $this->jobs_uri = array_merge($this->jobs_uri,array($job));
  383. self::_errorLog(sprintf("sending document, job %s : OPERATION FAILED",$job),1);
  384. return false;
  385. }
  386. public function sendURI ($uri,$job,$is_last=false)
  387. {
  388. self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
  389. if (!$this->_stringSendUri($uri,$job,$is_last))
  390. {
  391. return FALSE;
  392. }
  393. self::_putDebug( _("sending URI $uri\n"));
  394. $this->output = $this->stringjob;
  395. $post_values = array( "Content-Type" => "application/ipp",
  396. "Data" => $this->output);
  397. if (self::_sendHttp ($post_values,$this->paths['printers']))
  398. {
  399. if(self::_parseServerOutput())
  400. {
  401. $this->_getJobId();
  402. //$this->_getPrinterUri();
  403. $this->_getJobUri();
  404. $this->_parseJobAttributes();
  405. }
  406. else
  407. {
  408. $this->jobs = array_merge($this->jobs,array($job));
  409. $this->jobs_uri = array_merge($this->jobs_uri,array($job));
  410. }
  411. }
  412. $this->attributes = &$this->job_attributes;
  413. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  414. {
  415. $this->status = array_merge($this->status,array($this->serveroutput->status));
  416. if ($this->serveroutput->status == "successfull-ok")
  417. {
  418. self::_errorLog(sprintf("sending uri %s, job %s: %s",$uri,$job,$this->serveroutput->status),3);
  419. }
  420. else
  421. {
  422. $this->jobs = array_merge($this->jobs,array(""));
  423. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  424. self::_errorLog(sprintf("sending uri, job %s: %s",$uri,$job,$this->serveroutput->status),1);
  425. }
  426. return $this->serveroutput->status;
  427. }
  428. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  429. $this->jobs = array_merge($this->jobs,array($job));
  430. $this->jobs_uri = array_merge($this->jobs_uri,array($job));
  431. self::_errorLog(sprintf("sending uri %s, job %s : OPERATION FAILED",$uri,$job),1);
  432. return false;
  433. }
  434. public function pausePrinter()
  435. {
  436. $this->jobs = array_merge($this->jobs,array(""));
  437. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  438. self::_setOperationId();
  439. $this->parsed = array();
  440. unset($this->printer_attributes);
  441. if (!isset($this->setup->uri))
  442. {
  443. $this->getPrinters();
  444. unset($this->jobs[count($this->jobs) - 1]);
  445. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  446. unset($this->status[count($this->status) - 1]);
  447. if (array_key_exists(0,$this->available_printers))
  448. {
  449. self::setPrinterURI($this->available_printers[0]);
  450. }
  451. else
  452. {
  453. trigger_error(_("pausePrinter: Printer URI is not set: die"),E_USER_WARNING);
  454. self::_putDebug( _("pausePrinter: Printer URI is not set: die\n"));
  455. self::_errorLog("pausePrinter: Printer URI is not set, die",2);
  456. return FALSE;
  457. }
  458. }
  459. if (!isset($this->setup->charset))
  460. {
  461. self::setCharset();
  462. }
  463. if (!isset($this->setup->language))
  464. {
  465. self::setLanguage('en_us');
  466. }
  467. if (!isset($this->meta->username))
  468. {
  469. self::setUserName();
  470. }
  471. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  472. . chr(0x00) . chr (0x10) // Pause-Printer | operation-id
  473. . $this->meta->operation_id // request-id
  474. . chr(0x01) // start operation-attributes | operation-attributes-tag
  475. . $this->meta->charset
  476. . $this->meta->language
  477. . $this->meta->printer_uri
  478. . $this->meta->username
  479. /* . chr(0x22)
  480. . self::_giveMeStringLength("purge-jobs")
  481. . "purge-jobs"
  482. . self::_giveMeStringLength(chr(0x01))
  483. . chr(0x01) */
  484. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  485. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  486. self::_putDebug(sprintf(_("pause printer %s\n"),$this->printer_uri));
  487. $this->output = $this->stringjob;
  488. $post_values = array( "Content-Type"=>"application/ipp",
  489. "Data"=>$this->output);
  490. if (self::_sendHttp ($post_values,$this->paths['admin']))
  491. {
  492. self::_parseServerOutput();
  493. self::_parseAttributes();
  494. }
  495. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  496. {
  497. $this->status = array_merge($this->status,array($this->serveroutput->status));
  498. if ($this->serveroutput->status == "successfull-ok")
  499. {
  500. self::_errorLog(sprintf(_("Pause printer %s: "),$this->printer_uri)
  501. .$this->serveroutput->status,3);
  502. }
  503. else
  504. {
  505. self::_errorLog(sprintf(_("pause printer %s: "),$this->printer_uri)
  506. .$this->serveroutput->status,1);
  507. }
  508. return $this->serveroutput->status;
  509. }
  510. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  511. self::_errorLog(date("Y-m-d H:i:s : ")
  512. .basename($_SERVER['PHP_SELF'])
  513. .sprintf(_("pause printer %s : OPERATION FAILED"),
  514. $this->printer_uri),3);
  515. return false;
  516. }
  517. public function resumePrinter()
  518. {
  519. $this->jobs = array_merge($this->jobs,array(""));
  520. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  521. self::_setOperationId();
  522. $this->parsed = array();
  523. unset($this->printer_attributes);
  524. if (!isset($this->setup->uri))
  525. {
  526. $this->getPrinters();
  527. unset($this->jobs[count($this->jobs) - 1]);
  528. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  529. unset($this->status[count($this->status) - 1]);
  530. if (array_key_exists(0,$this->available_printers))
  531. {
  532. self::setPrinterURI($this->available_printers[0]);
  533. }
  534. else
  535. {
  536. trigger_error(_("resumePrinter: Printer URI is not set: die"),E_USER_WARNING);
  537. self::_putDebug( _("resumePrinter: Printer URI is not set: die\n"));
  538. self::_errorLog(" Printer URI is not set, die",2);
  539. return FALSE;
  540. }
  541. }
  542. if (!isset($this->setup->charset))
  543. {
  544. self::setCharset();
  545. }
  546. if (!isset($this->setup->language))
  547. {
  548. self::setLanguage('en_us');
  549. }
  550. if (!isset($this->meta->username))
  551. {
  552. self::setUserName();
  553. }
  554. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  555. . chr(0x00) . chr (0x11) // suse-Printer | operation-id
  556. . $this->meta->operation_id // request-id
  557. . chr(0x01) // start operation-attributes | operation-attributes-tag
  558. . $this->meta->charset
  559. . $this->meta->language
  560. . $this->meta->printer_uri
  561. . $this->meta->username
  562. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  563. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  564. self::_putDebug(sprintf(_("resume printer %s\n"),$this->printer_uri));
  565. $this->output = $this->stringjob;
  566. $post_values = array( "Content-Type"=>"application/ipp",
  567. "Data"=>$this->output);
  568. if (self::_sendHttp ($post_values,$this->paths['admin']))
  569. {
  570. self::_parseServerOutput();
  571. self::_parseAttributes();
  572. }
  573. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  574. {
  575. $this->status = array_merge($this->status,array($this->serveroutput->status));
  576. if ($this->serveroutput->status == "successfull-ok")
  577. {
  578. self::_errorLog(sprintf(_("resume printer %s: "),$this->printer_uri)
  579. .$this->serveroutput->status,3);
  580. }
  581. else
  582. {
  583. self::_errorLog(sprintf(_("resume printer %s: "),$this->printer_uri)
  584. .$this->serveroutput->status,1);
  585. }
  586. return $this->serveroutput->status;
  587. }
  588. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  589. self::_errorLog(date("Y-m-d H:i:s : ")
  590. .basename($_SERVER['PHP_SELF'])
  591. .sprintf(_("resume printer %s : OPERATION FAILED"),
  592. $this->printer_uri),3);
  593. return false;
  594. }
  595. public function holdJob ($job_uri,$until='indefinite')
  596. {
  597. $this->jobs = array_merge($this->jobs,array(""));
  598. $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri)));
  599. self::_setOperationId();
  600. $this->parsed = array();
  601. unset($this->printer_attributes);
  602. if (!isset($this->setup->charset))
  603. {
  604. self::setCharset();
  605. }
  606. if (!isset($this->setup->language))
  607. {
  608. self::setLanguage('en_us');
  609. }
  610. if (!isset($this->meta->username))
  611. {
  612. self::setUserName();
  613. }
  614. if (!isset($this->meta->message))
  615. {
  616. $this->meta->message = '';
  617. }
  618. self::_setJobUri($job_uri);
  619. $until_strings = array('no-hold','day-time','evening','night','weekend','second-shift','third-shift');
  620. if (in_array($until,$until_strings))
  621. {
  622. true;
  623. }
  624. else
  625. {
  626. $until = 'indefinite';
  627. }
  628. $this->meta->job_hold_until = chr(0x42) // keyword
  629. . self::_giveMeStringLength('job-hold-until')
  630. . 'job-hold-until'
  631. . self::_giveMeStringLength($until)
  632. . $until;
  633. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  634. . chr(0x00) . chr (0x0C) // Hold-Job | operation-id
  635. . $this->meta->operation_id // request-id
  636. . chr(0x01) // start operation-attributes | operation-attributes-tag
  637. . $this->meta->charset
  638. . $this->meta->language
  639. . $this->meta->username
  640. . $this->meta->job_uri
  641. . $this->meta->message
  642. . $this->meta->job_hold_until
  643. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  644. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  645. self::_putDebug(sprintf(_("hold job %s until %s\n"),$job_uri,$until));
  646. $this->output = $this->stringjob;
  647. $post_values = array( "Content-Type"=>"application/ipp",
  648. "Data"=>$this->output);
  649. if (self::_sendHttp ($post_values,$this->paths['jobs']))
  650. {
  651. self::_parseServerOutput();
  652. self::_parseAttributes();
  653. }
  654. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  655. {
  656. $this->status = array_merge($this->status,array($this->serveroutput->status));
  657. if ($this->serveroutput->status == "successfull-ok")
  658. {
  659. self::_errorLog(sprintf(_("hold job %s until %s: "),$job_uri,$until)
  660. .$this->serveroutput->status,3);
  661. }
  662. else
  663. {
  664. self::_errorLog(sprintf(_("hold job %s until %s: "),$job_uri,$until)
  665. .$this->serveroutput->status,1);
  666. }
  667. return $this->serveroutput->status;
  668. }
  669. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  670. self::_errorLog(date("Y-m-d H:i:s : ")
  671. .basename($_SERVER['PHP_SELF'])
  672. .sprintf(_("hold job %s until %s : OPERATION FAILED"),
  673. $job_uri,$until),3);
  674. return false;
  675. }
  676. public function releaseJob ($job_uri)
  677. {
  678. $this->jobs = array_merge($this->jobs,array(""));
  679. $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri)));
  680. self::_setOperationId();
  681. $this->parsed = array();
  682. unset($this->printer_attributes);
  683. if (!isset($this->setup->charset))
  684. {
  685. self::setCharset();
  686. }
  687. if (!isset($this->setup->language))
  688. {
  689. self::setLanguage('en_us');
  690. }
  691. if (!isset($this->meta->username))
  692. {
  693. self::setUserName();
  694. }
  695. if (!isset($this->meta->message))
  696. {
  697. $this->meta->message = '';
  698. }
  699. self::_setJobUri($job_uri);
  700. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  701. . chr(0x00) . chr (0x0D) // Hold-Job | operation-id
  702. . $this->meta->operation_id // request-id
  703. . chr(0x01) // start operation-attributes | operation-attributes-tag
  704. . $this->meta->charset
  705. . $this->meta->language
  706. . $this->meta->job_uri
  707. . $this->meta->username
  708. . $this->meta->message
  709. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  710. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  711. self::_putDebug(sprintf(_("release job %s\n"),$job_uri));
  712. $this->output = $this->stringjob;
  713. $post_values = array( "Content-Type"=>"application/ipp",
  714. "Data"=>$this->output);
  715. if (self::_sendHttp ($post_values,$this->paths['jobs']))
  716. {
  717. self::_parseServerOutput();
  718. self::_parseAttributes();
  719. }
  720. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  721. {
  722. $this->status = array_merge($this->status,array($this->serveroutput->status));
  723. if ($this->serveroutput->status == "successfull-ok")
  724. {
  725. self::_errorLog(sprintf(_("release job %s: "),$job_uri)
  726. .$this->serveroutput->status,3);
  727. }
  728. else
  729. {
  730. self::_errorLog(sprintf(_("release job %s: "),$job_uri)
  731. .$this->serveroutput->status,1);
  732. }
  733. return $this->serveroutput->status;
  734. }
  735. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  736. self::_errorLog(date("Y-m-d H:i:s : ")
  737. .basename($_SERVER['PHP_SELF'])
  738. .sprintf(_("release job %s: OPERATION FAILED"),
  739. $job_uri),3);
  740. return false;
  741. }
  742. public function restartJob ($job_uri)
  743. {
  744. $this->jobs = array_merge($this->jobs,array(""));
  745. $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri)));
  746. self::_setOperationId();
  747. $this->parsed = array();
  748. unset($this->printer_attributes);
  749. if (!isset($this->setup->charset))
  750. {
  751. self::setCharset();
  752. }
  753. if (!isset($this->setup->language))
  754. {
  755. self::setLanguage('en_us');
  756. }
  757. if (!isset($this->meta->username))
  758. {
  759. self::setUserName();
  760. }
  761. if (!isset($this->meta->message))
  762. {
  763. $this->meta->message = '';
  764. }
  765. self::_setJobUri($job_uri);
  766. $jobattributes = '';
  767. $operationattributes = '';
  768. $printerattributes = '';
  769. self::_buildValues ($operationattributes,$jobattributes,$printerattributes);
  770. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  771. . chr(0x00) . chr (0x0E) // Hold-Job | operation-id
  772. . $this->meta->operation_id // request-id
  773. . chr(0x01) // start operation-attributes | operation-attributes-tag
  774. . $this->meta->charset
  775. . $this->meta->language
  776. . $this->meta->job_uri
  777. . $this->meta->username
  778. . $this->meta->message
  779. . $jobattributes // job-hold-until is set by setAttribute($attribute,$value)
  780. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  781. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  782. self::_putDebug(sprintf(_("release job %s\n"),$job_uri));
  783. $this->output = $this->stringjob;
  784. $post_values = array( "Content-Type"=>"application/ipp",
  785. "Data"=>$this->output);
  786. if (self::_sendHttp ($post_values,$this->paths['jobs']))
  787. {
  788. self::_parseServerOutput();
  789. self::_parseAttributes();
  790. }
  791. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  792. {
  793. $this->status = array_merge($this->status,array($this->serveroutput->status));
  794. if ($this->serveroutput->status == "successfull-ok")
  795. {
  796. self::_errorLog(sprintf(_("release job %s: "),$job_uri)
  797. .$this->serveroutput->status,3);
  798. }
  799. else
  800. {
  801. self::_errorLog(sprintf(_("release job %s: "),$job_uri)
  802. .$this->serveroutput->status,1);
  803. }
  804. return $this->serveroutput->status;
  805. }
  806. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  807. self::_errorLog(date("Y-m-d H:i:s : ")
  808. .basename($_SERVER['PHP_SELF'])
  809. .sprintf(_("release job %s: OPERATION FAILED"),
  810. $job_uri),3);
  811. return false;
  812. }
  813. public function setJobAttributes ($job_uri,$deleted_attributes=array())
  814. {
  815. $this->jobs = array_merge($this->jobs,array(""));
  816. $this->jobs_uri = array_merge($this->jobs_uri,array(trim($job_uri)));
  817. self::_setOperationId();
  818. $this->parsed = array();
  819. unset ($this->attributes);
  820. if (!isset($this->setup->charset))
  821. {
  822. self::setCharset();
  823. }
  824. if (!isset($this->setup->language))
  825. {
  826. self::setLanguage('en_us');
  827. }
  828. if (!isset($this->meta->username))
  829. {
  830. self::setUserName();
  831. }
  832. if (!isset($this->meta->message))
  833. {
  834. $this->meta->message = '';
  835. }
  836. if (!isset($this->meta->copies))
  837. {
  838. $this->meta->copies = '';
  839. }
  840. if (!isset($this->meta->sides))
  841. {
  842. $this->meta->sides = '';
  843. }
  844. if (!isset($this->meta->page_ranges))
  845. {
  846. $this->meta->page_ranges = '';
  847. }
  848. self::_setJobUri($job_uri);
  849. $operationattributes = '';
  850. $jobattributes = '';
  851. $printerattributes = '';
  852. self::_buildValues ($operationattributes,$jobattributes,$printerattributes);
  853. $this->meta->deleted_attributes = "";
  854. for ($i = 0 ; $i < count($deleted_attributes) ; $i++)
  855. {
  856. $this->meta->deleted_attributes .= chr(0x16) // out-of-band value
  857. . self::_giveMeStringLength($deleted_attributes[$i])
  858. . $deleted_attributes[$i]
  859. . chr(0x0).chr(0x0);
  860. } // value-length = 0;
  861. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  862. . chr(0x00) . chr (0x14) // Set-Job-Attributes | operation-id
  863. . $this->meta->operation_id // request-id
  864. . chr(0x01) // start operation-attributes | operation-attributes-tag
  865. . $this->meta->charset
  866. . $this->meta->language
  867. . $this->meta->job_uri
  868. . $this->meta->username
  869. . $this->meta->message
  870. . chr(0x02) // start job-attributes
  871. . $jobattributes // setteds by setAttribute($attribute,$value)
  872. . $this->meta->copies
  873. . $this->meta->sides
  874. . $this->meta->page_ranges
  875. . $this->meta->deleted_attributes
  876. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  877. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  878. self::_putDebug(sprintf(_("set job attributes for job %s\n"),$job_uri));
  879. $this->output = $this->stringjob;
  880. $post_values = array( "Content-Type"=>"application/ipp",
  881. "Data"=>$this->output);
  882. if (self::_sendHttp ($post_values,$this->paths['jobs']))
  883. {
  884. self::_parseServerOutput();
  885. self::_parseAttributes();
  886. }
  887. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  888. {
  889. $this->status = array_merge($this->status,array($this->serveroutput->status));
  890. if ($this->serveroutput->status == "successfull-ok")
  891. {
  892. self::_errorLog(sprintf(_("set job attributes for job %s: "),$job_uri)
  893. .$this->serveroutput->status,3);
  894. }
  895. else
  896. {
  897. self::_errorLog(sprintf(_("set job attributes for job %s: "),$job_uri)
  898. .$this->serveroutput->status,1);
  899. }
  900. $this->last_job = $job_uri;
  901. $this->jobs_uri[count($this->jobs_uri) - 1] = $job_uri;
  902. return $this->serveroutput->status;
  903. }
  904. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  905. self::_errorLog(date("Y-m-d H:i:s : ")
  906. .basename($_SERVER['PHP_SELF'])
  907. .sprintf(_("set job attributes for job %s: OPERATION FAILED"),
  908. $job_uri),3);
  909. return false;
  910. }
  911. public function setPrinterAttributes ($document_format='',$deleted_attributes=array())
  912. {
  913. /* $document_format (RFC 3380)
  914. If the client includes this attribute, the Printer MUST change
  915. the supplied attributes for the document format specified by
  916. this attribute. If a supplied attribute is a member of the
  917. "document-format-varying-attributes" (i.e., the attribute
  918. varies by document format, see section 6.3), the Printer MUST
  919. change the supplied attribute for the document format specified
  920. by this attribute, but not for other document formats. If a
  921. supplied attribute isn't a member of the "document-format-
  922. varying-attributes" (i.e., it doesn't vary by document format),
  923. the Printer MUST change the supplied attribute for all document
  924. formats.
  925. If the client omits this attribute, the Printer MUST change the
  926. supplied attributes for all document formats, whether or not
  927. they vary by document-format.
  928. */
  929. $this->jobs = array_merge($this->jobs,array(""));
  930. $this->jobs_uri = array_merge($this->jobs_uri,array(""));
  931. unset ($this->attributes);
  932. self::_setOperationId();
  933. $this->parsed = array();
  934. if (!isset($this->setup->charset))
  935. {
  936. self::setCharset();
  937. }
  938. if (!isset($this->setup->language))
  939. {
  940. self::setLanguage('en_us');
  941. }
  942. if (!isset($this->meta->username))
  943. {
  944. self::setUserName();
  945. }
  946. if (!isset($this->meta->message))
  947. {
  948. $this->meta->message = '';
  949. }
  950. if (!isset($this->meta->copies))
  951. {
  952. $this->meta->copies = '';
  953. }
  954. if (!isset($this->meta->sides))
  955. {
  956. $this->meta->sides = '';
  957. }
  958. if (!isset($this->meta->page_ranges))
  959. {
  960. $this->meta->page_ranges = '';
  961. }
  962. if ($document_format)
  963. {
  964. $document_format = chr(0x49) // document-format tag
  965. . self::_giveMeStringLength('document-format')
  966. . 'document-format' //
  967. . self::_giveMeStringLength($document_format)
  968. . $document_format;
  969. } // value
  970. $operationattributes = '';
  971. $jobattributes = '';
  972. $printerattributes = '';
  973. self::_buildValues ($operationattributes,$jobattributes,$printerattributes);
  974. $this->meta->deleted_attributes = "";
  975. for ($i = 0 ; $i < count($deleted_attributes) ; $i++)
  976. {
  977. $this->meta->deleted_attributes .= chr(0x16) // out-of-band "deleted" value
  978. . self::_giveMeStringLength($deleted_attributes[$i])
  979. . $deleted_attributes[$i]
  980. . chr(0x0).chr(0x0);
  981. } // value-length = 0;
  982. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  983. . chr(0x00) . chr (0x13) // Set-Printer-Attributes | operation-id
  984. . $this->meta->operation_id // request-id
  985. . chr(0x01) // start operation-attributes | operation-attributes-tag
  986. . $this->meta->charset
  987. . $this->meta->language
  988. . $this->meta->printer_uri
  989. . $this->meta->username
  990. . $this->meta->message
  991. . $operationattributes
  992. . chr(0x02) // start job-attributes
  993. . $jobattributes // setteds by setAttribute($attribute,$value)
  994. . $this->meta->copies
  995. . $this->meta->sides
  996. . $this->meta->page_ranges
  997. . $this->meta->deleted_attributes
  998. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  999. self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  1000. self::_putDebug(sprintf(_("set printer attributes for job %s\n"),$this->printer_uri));
  1001. $this->output = $this->stringjob;
  1002. $post_values = array( "Content-Type"=>"application/ipp",
  1003. "Data"=>$this->output);
  1004. if (self::_sendHttp ($post_values,$this->paths['printers']))
  1005. {
  1006. self::_parseServerOutput();
  1007. self::_parseAttributes();
  1008. }
  1009. if (isset($this->serveroutput) && isset($this->serveroutput->status))
  1010. {
  1011. $this->status = array_merge($this->status,array($this->serveroutput->status));
  1012. if ($this->serveroutput->status == "successfull-ok")
  1013. {
  1014. self::_errorLog(sprintf(_("set printer attributes for printer %s: "),$this->printer_uri)
  1015. .$this->serveroutput->status,3);
  1016. }
  1017. else
  1018. {
  1019. self::_errorLog(sprintf(_("set printer attributes for printer %s: "),$this->printer_uri)
  1020. .$this->serveroutput->status,1);
  1021. }
  1022. return $this->serveroutput->status;
  1023. }
  1024. $this->status = array_merge($this->status,array("OPERATION FAILED"));
  1025. self::_errorLog(date("Y-m-d H:i:s : ")
  1026. .basename($_SERVER['PHP_SELF'])
  1027. .sprintf(_("set printer attributes for printer %s: OPERATION FAILED"),
  1028. $this->printer_uri),1);
  1029. return false;
  1030. }
  1031. // REQUEST BUILDING
  1032. protected function _setDocumentUri ()
  1033. {
  1034. $this->meta->document_uri = chr(0x45) // type uri
  1035. . chr(0x00).chr(0x0c) // name-length
  1036. . "document-uri"
  1037. . self::_giveMeStringLength($this->document_uri)
  1038. . $this->document_uri;
  1039. self::_putDebug( "document uri is: ".$this->document_uri."\n");
  1040. $this->setup->document_uri = 1;
  1041. }
  1042. protected function _stringUri ()
  1043. {
  1044. self::_setDocumentUri();
  1045. if (!isset($this->setup->document_uri))
  1046. {
  1047. trigger_error(_("_stringUri: Document URI is not set: die"),E_USER_WARNING);
  1048. self::_putDebug( _("_stringUri: Document URI is not set: die\n"));
  1049. self::_errorLog("Document URI is not set, die",2);
  1050. return FALSE;
  1051. }
  1052. unset ($this->setup->document_uri);
  1053. if (!isset($this->setup->uri))
  1054. {
  1055. $this->getPrinters();
  1056. unset($this->jobs[count($this->jobs) - 1]);
  1057. unset($this->jobs_uri[count($this->jobs) - 1]);
  1058. unset($this->status[count($this->status) - 1]);
  1059. if (array_key_exists(0,$this->available_printers))
  1060. {
  1061. self::setPrinterURI($this->available_printers[0]);
  1062. }
  1063. else
  1064. {
  1065. trigger_error(_("_stringUri: Printer URI is not set: die"),E_USER_WARNING);
  1066. self::_putDebug( _("_stringUri: Printer URI is not set: die\n"));
  1067. self::_errorLog("_stringUri: Printer URI is not set, die",2);
  1068. return FALSE;
  1069. }
  1070. }
  1071. if (!isset($this->setup->charset))
  1072. {
  1073. $this->meta->charset = "";
  1074. }
  1075. if (!isset($this->setup->datatype))
  1076. {
  1077. self::setBinary();
  1078. }
  1079. if (!isset($this->setup->uri))
  1080. {
  1081. trigger_error(_("_stringUri: Printer URI is not set: die"),E_USER_WARNING);
  1082. self::_putDebug( _("_stringUri: Printer URI is not set: die\n"));
  1083. self::_errorLog("Printer URI is not set, die",2);
  1084. return FALSE;
  1085. }
  1086. if (!isset($this->setup->copies))
  1087. {
  1088. self::setCopies(1);
  1089. }
  1090. if (!isset($this->setup->language))
  1091. {
  1092. self::setLanguage('en_us');
  1093. }
  1094. if (!isset($this->setup->mime_media_type))
  1095. {
  1096. self::setMimeMediaType();
  1097. }
  1098. unset ($this->setup->mime_media_type);
  1099. if (!isset($this->setup->jobname))
  1100. {
  1101. if (is_readable($this->data))
  1102. {
  1103. self::setJobName(basename($this->data),true);
  1104. }
  1105. else
  1106. {
  1107. self::setJobName();
  1108. }
  1109. }
  1110. unset($this->setup->jobname);
  1111. if (!isset($this->meta->username))
  1112. {
  1113. self::setUserName();
  1114. }
  1115. if (!isset($this->meta->fidelity))
  1116. {
  1117. $this->meta->fidelity = '';
  1118. }
  1119. if (!isset($this->meta->document_name))
  1120. {
  1121. $this->meta->document_name = '';
  1122. }
  1123. if (!isset($this->meta->sides))
  1124. {
  1125. $this->meta->sides = '';
  1126. }
  1127. if (!isset($this->meta->page_ranges))
  1128. {
  1129. $this->meta->page_ranges = '';
  1130. }
  1131. $jobattributes = '';
  1132. $operationattributes = '';
  1133. $printerattributes = '';
  1134. self::_buildValues($operationattributes,$jobattributes,$printerattributes);
  1135. self::_setOperationId();
  1136. if (!isset($this->error_generation->request_body_malformed))
  1137. {
  1138. $this->error_generation->request_body_malformed = "";
  1139. }
  1140. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  1141. . chr(0x00) . chr (0x03) // Print-URI | operation-id
  1142. . $this->meta->operation_id // request-id
  1143. . $this->error_generation->request_body_malformed
  1144. . chr(0x01) // start operation-attributes | operation-attributes-tag
  1145. . $this->meta->charset
  1146. . $this->meta->language
  1147. . $this->meta->printer_uri
  1148. . $this->meta->jobname
  1149. . $this->meta->username
  1150. . $this->meta->fidelity
  1151. . $this->meta->document_name
  1152. . $this->meta->document_uri
  1153. . $operationattributes
  1154. . chr(0x02) // start job-attributes | job-attributes-tag
  1155. . $this->meta->copies
  1156. . $this->meta->sides
  1157. . $this->meta->page_ranges
  1158. . $jobattributes
  1159. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  1160. self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  1161. return TRUE;
  1162. }
  1163. protected function _stringDocument ($job,$is_last)
  1164. {
  1165. if ($is_last == false)
  1166. {
  1167. $is_last = chr(0x00);
  1168. }
  1169. else
  1170. {
  1171. $is_last = chr(0x01);
  1172. }
  1173. if (!isset($this->setup->charset))
  1174. {
  1175. self::setCharset();
  1176. }
  1177. if (!isset($this->setup->datatype))
  1178. {
  1179. self::setBinary();
  1180. }
  1181. if (!isset($this->setup->uri))
  1182. {
  1183. $this->getPrinters();
  1184. unset($this->jobs[count($this->jobs) - 1]);
  1185. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  1186. unset($this->status[count($this->status) - 1]);
  1187. if (array_key_exists(0,$this->available_printers))
  1188. {
  1189. self::setPrinterURI($this->available_printers[0]);
  1190. }
  1191. else
  1192. {
  1193. trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING);
  1194. self::_putDebug( _("_stringJob: Printer URI is not set: die\n"));
  1195. self::_errorLog(" Printer URI is not set, die",2);
  1196. return FALSE;
  1197. }
  1198. }
  1199. if (!isset($this->setup->copies))
  1200. {
  1201. $this->meta->copies = "";
  1202. }
  1203. if (!isset($this->setup->language))
  1204. {
  1205. self::setLanguage('en_us');
  1206. }
  1207. if (!isset($this->setup->mime_media_type))
  1208. {
  1209. $this->meta->mime_media_type = "";
  1210. }
  1211. if ($this->setup->datatype != "TEXT")
  1212. {
  1213. unset ($this->setup->mime_media_type);
  1214. }
  1215. if (!isset($this->meta->fidelity))
  1216. {
  1217. $this->meta->fidelity = '';
  1218. }
  1219. if (!isset($this->meta->document_name))
  1220. {
  1221. $this->meta->document_name = '';
  1222. }
  1223. if (!isset($this->meta->sides))
  1224. {
  1225. $this->meta->sides = '';
  1226. }
  1227. if (!isset($this->meta->page_ranges))
  1228. {
  1229. $this->meta->page_ranges = '';
  1230. }
  1231. $operationattributes = '';
  1232. $jobattributes = '';
  1233. $printerattributes = '';
  1234. self::_buildValues($operationattributes,$jobattributes,$printerattributes);
  1235. self::_setOperationId();
  1236. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  1237. . chr(0x00) . chr (0x06) // Send-Document | operation-id
  1238. . $this->meta->operation_id // request-id
  1239. . chr(0x01) // start operation-attributes | operation-attributes-tag
  1240. . $this->meta->charset
  1241. . $this->meta->language
  1242. . chr(0x45) // attribute-type: uri
  1243. . self::_giveMeStringLength("job-uri")
  1244. . "job-uri"
  1245. . self::_giveMeStringLength($job)
  1246. . $job
  1247. . $this->meta->username
  1248. . $this->meta->document_name
  1249. . $this->meta->fidelity
  1250. . $this->meta->mime_media_type
  1251. . $operationattributes
  1252. . chr(0x22) // boolean
  1253. . self::_giveMeStringLength("last-document")
  1254. . "last-document"
  1255. . self::_giveMeStringLength($is_last)
  1256. . $is_last
  1257. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  1258. self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  1259. return TRUE;
  1260. }
  1261. protected function _stringSendUri ($uri,$job,$is_last)
  1262. {
  1263. $this->document_uri = $uri;
  1264. self::_setDocumentUri();
  1265. if (!isset($this->setup->document_uri))
  1266. {
  1267. trigger_error(_("_stringUri: Document URI is not set: die"),E_USER_WARNING);
  1268. self::_putDebug( _("_stringUri: Document URI is not set: die\n"));
  1269. self::_errorLog("Document URI is not set, die",2);
  1270. return FALSE;
  1271. }
  1272. unset ($this->setup->document_uri);
  1273. if ($is_last == false)
  1274. {
  1275. $is_last = chr(0x00);
  1276. }
  1277. else
  1278. {
  1279. $is_last = chr(0x01);
  1280. }
  1281. if (!isset($this->setup->charset))
  1282. {
  1283. self::setCharset();
  1284. }
  1285. if (!isset($this->setup->datatype))
  1286. {
  1287. self::setBinary();
  1288. }
  1289. if (!isset($this->setup->uri))
  1290. {
  1291. $this->getPrinters();
  1292. unset($this->jobs[count($this->jobs) - 1]);
  1293. unset($this->jobs_uri[count($this->jobs_uri) - 1]);
  1294. unset($this->status[count($this->status) - 1]);
  1295. if (array_key_exists(0,$this->available_printers))
  1296. {
  1297. self::setPrinterURI($this->available_printers[0]);
  1298. }
  1299. else
  1300. {
  1301. trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING);
  1302. self::_putDebug( _("_stringJob: Printer URI is not set: die\n"));
  1303. self::_errorLog(" Printer URI is not set, die",2);
  1304. return FALSE;
  1305. }
  1306. }
  1307. if (!isset($this->setup->copies))
  1308. {
  1309. $this->meta->copies = "";
  1310. }
  1311. if (!isset($this->setup->language))
  1312. {
  1313. self::setLanguage('en_us');
  1314. }
  1315. if (!isset($this->setup->mime_media_type))
  1316. {
  1317. $this->meta->mime_media_type = "";
  1318. }
  1319. unset ($this->setup->mime_media_type);
  1320. if (!isset($this->meta->fidelity))
  1321. {
  1322. $this->meta->fidelity = '';
  1323. }
  1324. if (!isset($this->meta->document_name))
  1325. {
  1326. $this->meta->document_name = '';
  1327. }
  1328. if (!isset($this->meta->sides))
  1329. {
  1330. $this->meta->sides = '';
  1331. }
  1332. if (!isset($this->meta->page_ranges))
  1333. {
  1334. $this->meta->page_ranges = '';
  1335. }
  1336. $operationattributes = '';
  1337. $jobattributes = '';
  1338. $printerattributes = '';
  1339. self::_buildValues($operationattributes,$jobattributes,$printerattributes);
  1340. self::_setOperationId();
  1341. $this->stringjob = chr(0x01) . chr(0x01) // 1.1 | version-number
  1342. . chr(0x00) . chr (0x07) // Send-Uri | operation-id
  1343. . $this->meta->operation_id // request-id
  1344. . chr(0x01) // start operation-attributes | operation-attributes-tag
  1345. . $this->meta->charset
  1346. . $this->meta->language
  1347. . chr(0x45) // attribute-type: uri
  1348. . self::_giveMeStringLength("job-uri")
  1349. . "job-uri"
  1350. . self::_giveMeStringLength($job)
  1351. . $job
  1352. . $this->meta->username
  1353. . $this->meta->document_uri
  1354. . $this->meta->fidelity
  1355. . $this->meta->mime_media_type
  1356. . $operationattributes
  1357. . chr(0x22) // boolean
  1358. . self::_giveMeStringLength("last-document")
  1359. . "last-document"
  1360. . self::_giveMeStringLength($is_last)
  1361. . $is_last
  1362. . chr(0x03); // end-of-attributes | end-of-attributes-tag
  1363. self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
  1364. return TRUE;
  1365. }
  1366. }