dolprintipp.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /*
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/class/dolprintipp.class.php
  20. * \brief List jobs printed with driver printipp
  21. */
  22. /**
  23. * Class to manage printIPP
  24. */
  25. class dolprintIPP
  26. {
  27. var $host;
  28. var $port;
  29. var $userid; /* user login */
  30. var $user;
  31. var $password;
  32. var $error;
  33. var $db;
  34. /**
  35. * Constructor
  36. *
  37. * @param DoliDB $db database
  38. * @param string $host host of Cups
  39. * @param string $port port
  40. * @param string $userid userid
  41. * @param string $user user
  42. * @param string $password password
  43. */
  44. function __construct($db,$host,$port,$userid,$user,$password)
  45. {
  46. $this->db=$db;
  47. $this->host=$host;
  48. $this->port=$port;
  49. $this->userid=$userid;
  50. $this->user=$user;
  51. $this->password=$password;
  52. }
  53. /**
  54. * List jobs print
  55. *
  56. * @param string $module module
  57. *
  58. * @return void
  59. */
  60. function list_jobs($module)
  61. {
  62. global $conf, $db, $bc, $langs;
  63. include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
  64. $ipp = new CupsPrintIPP();
  65. $ipp->setLog(DOL_DATA_ROOT.'/printipp.log','file',3); // logging very verbose
  66. $ipp->setHost($this->host);
  67. $ipp->setPort($this->port);
  68. $ipp->setUserName($this->userid);
  69. if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
  70. // select printer uri for module order, propal,...
  71. $sql = 'SELECT rowid,printer_uri,printer_name FROM '.MAIN_DB_PREFIX.'printer_ipp WHERE module="'.$module.'"';
  72. $result = $this->db->query($sql);
  73. if ($result)
  74. {
  75. $obj = $this->db->fetch_object($result);
  76. if ($obj)
  77. {
  78. $ipp->setPrinterURI($obj->printer_uri);
  79. }
  80. else
  81. {
  82. // All printers
  83. $ipp->setPrinterURI("ipp://localhost:631/printers/");
  84. }
  85. }
  86. // Getting Jobs
  87. try {
  88. $ipp->getJobs(false,0,'completed',false); // May return errors if setup not correct
  89. }
  90. catch(Exception $e)
  91. {
  92. setEventMessage('[printipp] '.$langs->trans('CoreErrorMessage'), 'errors');
  93. dol_syslog($e->getMessage(), LOG_ERR);
  94. }
  95. print '<table width="100%" class="noborder">';
  96. print '<tr class="liste_titre">';
  97. print "<td>Id</td>";
  98. print "<td>Owner</td>";
  99. print "<td>Printer</td>";
  100. print "<td>File</td>";
  101. print "<td>Status</td>";
  102. print "<td>Cancel</td>";
  103. print "</tr>\n";
  104. $jobs = $ipp->jobs_attributes;
  105. $var = true;
  106. //print '<pre>'.print_r($jobs,true).'</pre>';
  107. if (is_array($jobs))
  108. {
  109. foreach ($jobs as $value)
  110. {
  111. print '<tr class="oddeven">';
  112. print '<td>'.$value->job_id->_value0.'</td>';
  113. print '<td>'.$value->job_originating_user_name->_value0.'</td>';
  114. print '<td>'.$value->printer_uri->_value0.'</td>';
  115. print '<td>'.$value->job_name->_value0.'</td>';
  116. print '<td>'.$value->job_state->_value0.'</td>';
  117. print '<td>'.$value->job_uri->_value0.'</td>';
  118. print '</tr>';
  119. }
  120. }
  121. print "</table>";
  122. }
  123. }