dolibarr  7.0.0-beta
dolprintipp.class.php
Go to the documentation of this file.
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 
28 {
29  var $host;
30  var $port;
31  var $userid; /* user login */
32  var $user;
33  var $password;
34  var $error;
35  var $db;
36 
37 
38 
49  function __construct($db,$host,$port,$userid,$user,$password)
50  {
51  $this->db=$db;
52  $this->host=$host;
53  $this->port=$port;
54  $this->userid=$userid;
55  $this->user=$user;
56  $this->password=$password;
57  }
58 
59 
67  function list_jobs($module)
68  {
69  global $conf, $db, $bc, $langs;
70  include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
71  $ipp = new CupsPrintIPP();
72  $ipp->setLog(DOL_DATA_ROOT.'/printipp.log','file',3); // logging very verbose
73  $ipp->setHost($this->host);
74  $ipp->setPort($this->port);
75  $ipp->setUserName($this->userid);
76  if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
77  // select printer uri for module order, propal,...
78  $sql = 'SELECT rowid,printer_uri,printer_name FROM '.MAIN_DB_PREFIX.'printer_ipp WHERE module="'.$module.'"';
79  $result = $this->db->query($sql);
80  if ($result)
81  {
82  $obj = $this->db->fetch_object($result);
83  if ($obj)
84  {
85  $ipp->setPrinterURI($obj->printer_uri);
86  }
87  else
88  {
89  // All printers
90  $ipp->setPrinterURI("ipp://localhost:631/printers/");
91  }
92  }
93  // Getting Jobs
94  try {
95  $ipp->getJobs(false,0,'completed',false); // May return errors if setup not correct
96  }
97  catch(Exception $e)
98  {
99  setEventMessage('[printipp] '.$langs->trans('CoreErrorMessage'), 'errors');
100  dol_syslog($e->getMessage(), LOG_ERR);
101  }
102 
103  print '<table width="100%" class="noborder">';
104  print '<tr class="liste_titre">';
105  print "<td>Id</td>";
106  print "<td>Owner</td>";
107  print "<td>Printer</td>";
108  print "<td>File</td>";
109  print "<td>Status</td>";
110  print "<td>Cancel</td>";
111  print "</tr>\n";
112  $jobs = $ipp->jobs_attributes;
113  $var = true;
114  //print '<pre>'.print_r($jobs,true).'</pre>';
115  if (is_array($jobs))
116  {
117  foreach ($jobs as $value)
118  {
119 
120  print '<tr class="oddeven">';
121  print '<td>'.$value->job_id->_value0.'</td>';
122  print '<td>'.$value->job_originating_user_name->_value0.'</td>';
123  print '<td>'.$value->printer_uri->_value0.'</td>';
124  print '<td>'.$value->job_name->_value0.'</td>';
125  print '<td>'.$value->job_state->_value0.'</td>';
126  print '<td>'.$value->job_uri->_value0.'</td>';
127  print '</tr>';
128  }
129  }
130  print "</table>";
131  }
132 
133 }
list_jobs($module)
List jobs print.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
$conf db user
Definition: repair.php:105
print
Draft customers invoices.
Definition: index.php:91
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Class to manage printIPP.
__construct($db, $host, $port, $userid, $user, $password)
Constructor.