26 include_once DOL_DOCUMENT_ROOT.
'/core/modules/printing/modules_printing.php';
36 public $name =
'printipp';
41 public $desc =
'PrintIPPDesc';
46 public $picto =
'printer';
51 public $active =
'PRINTING_PRINTIPP';
56 public $conf = array();
91 public $errors = array();
98 const LANGFILE =
'printipp';
111 $this->host = $conf->global->PRINTIPP_HOST;
112 $this->port = $conf->global->PRINTIPP_PORT;
113 $this->
user = $conf->global->PRINTIPP_USER;
114 $this->password = $conf->global->PRINTIPP_PASSWORD;
115 $this->
conf[] = array(
'varname'=>
'PRINTIPP_HOST',
'required'=>1,
'example'=>
'localhost',
'type'=>
'text');
116 $this->
conf[] = array(
'varname'=>
'PRINTIPP_PORT',
'required'=>1,
'example'=>
'631',
'type'=>
'text');
117 $this->
conf[] = array(
'varname'=>
'PRINTIPP_USER',
'required'=>0,
'example'=>
'',
'type'=>
'text',
'moreattributes'=>
'autocomplete="off"');
118 $this->
conf[] = array(
'varname'=>
'PRINTIPP_PASSWORD',
'required'=>0,
'example'=>
'',
'type'=>
'password',
'moreattributes'=>
'autocomplete="off"');
119 $this->
conf[] = array(
'enabled'=>1,
'type'=>
'submit');
136 include_once DOL_DOCUMENT_ROOT.
'/includes/printipp/CupsPrintIPP.php';
138 $ipp =
new CupsPrintIPP();
139 $ipp->setLog(DOL_DATA_ROOT.
'/dolibarr_printipp.log',
'file', 3);
140 $ipp->setHost($this->host);
141 $ipp->setPort($this->port);
142 $ipp->setJobName($file,
true);
143 $ipp->setUserName($this->userid);
146 if (!empty($this->
user)) $ipp->setAuthentication($this->
user, $this->password);
149 $sql =
"SELECT rowid,printer_id,copy FROM ".MAIN_DB_PREFIX.
"printing WHERE module = '".$this->
db->escape($module).
"' AND driver = 'printipp' AND userid = ".$user->id;
150 $result = $this->
db->query($sql);
152 $obj = $this->
db->fetch_object($result);
154 dol_syslog(
"Found a default printer for user ".$user->id.
" = ".$obj->printer_id);
155 $ipp->setPrinterURI($obj->printer_id);
157 $ipp->setCopies($obj->copy);
159 if (!empty($conf->global->PRINTIPP_URI_DEFAULT))
161 dol_syslog(
"Will use default printer conf->global->PRINTIPP_URI_DEFAULT = ".$conf->global->PRINTIPP_URI_DEFAULT);
162 $ipp->setPrinterURI($conf->global->PRINTIPP_URI_DEFAULT);
164 $this->errors[] =
'NoDefaultPrinterDefined';
173 $fileprint = $conf->{$module}->dir_output;
174 if ($subdir !=
'') $fileprint .=
'/'.$subdir;
175 $fileprint .=
'/'.$file;
176 $ipp->setData($fileprint);
180 $this->errors[] = $e->getMessage();
183 if ($error == 0) $this->errors[] =
'PRINTIPP: Job added';
195 global $conf, $langs;
198 $html =
'<tr class="liste_titre">';
199 $html .=
'<td>'.$langs->trans(
'IPP_Uri').
'</td>';
200 $html .=
'<td>'.$langs->trans(
'IPP_Name').
'</td>';
201 $html .=
'<td>'.$langs->trans(
'IPP_State').
'</td>';
202 $html .=
'<td>'.$langs->trans(
'IPP_State_reason').
'</td>';
203 $html .=
'<td>'.$langs->trans(
'IPP_State_reason1').
'</td>';
204 $html .=
'<td>'.$langs->trans(
'IPP_BW').
'</td>';
205 $html .=
'<td>'.$langs->trans(
'IPP_Color').
'</td>';
207 $html .=
'<td>'.$langs->trans(
'IPP_Media').
'</td>';
208 $html .=
'<td>'.$langs->trans(
'IPP_Supported').
'</td>';
209 $html .=
'<td class="center">'.$langs->trans(
"Select").
'</td>';
211 $list = $this->getlistAvailablePrinters();
212 foreach ($list as $value) {
213 $printer_det = $this->getPrinterDetail($value);
214 $html .=
'<tr class="oddeven">';
215 $html .=
'<td>'.$value.
'</td>';
217 $html .=
'<td>'.$printer_det->printer_name->_value0.
'</td>';
218 $html .=
'<td>'.$langs->trans(
'STATE_IPP_'.$printer_det->printer_state->_value0).
'</td>';
219 $html .=
'<td>'.$langs->trans(
'STATE_IPP_'.$printer_det->printer_state_reasons->_value0).
'</td>';
220 $html .=
'<td>'.(!empty($printer_det->printer_state_reasons->_value1) ? $langs->trans(
'STATE_IPP_'.$printer_det->printer_state_reasons->_value1) :
'').
'</td>';
221 $html .=
'<td>'.$langs->trans(
'IPP_COLOR_'.$printer_det->printer_type->_value2).
'</td>';
222 $html .=
'<td>'.$langs->trans(
'IPP_COLOR_'.$printer_det->printer_type->_value3).
'</td>';
224 $html .=
'<td>'.$printer_det->media_default->_value0.
'</td>';
225 $html .=
'<td>'.$langs->trans(
'MEDIA_IPP_'.$printer_det->media_type_supported->_value1).
'</td>';
227 $html .=
'<td class="center">';
228 if ($conf->global->PRINTIPP_URI_DEFAULT == $value) {
229 $html .=
img_picto($langs->trans(
"Default"),
'on');
231 $html .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setvalue&token='.
newToken().
'&mode=test&varname=PRINTIPP_URI_DEFAULT&driver=printipp&value='.urlencode($value).
'" alt="'.$langs->trans(
"Default").
'">'.
img_picto($langs->trans(
"Disabled"),
'off').
'</a>';
234 $html .=
'</tr>'.
"\n";
236 $this->resprint = $html;
248 include_once DOL_DOCUMENT_ROOT.
'/includes/printipp/CupsPrintIPP.php';
249 $ipp =
new CupsPrintIPP();
250 $ipp->setLog(DOL_DATA_ROOT.
'/dolibarr_printipp.log',
'file', 3);
251 $ipp->setHost($this->host);
252 $ipp->setPort($this->port);
253 $ipp->setUserName($this->userid);
254 if (!empty($this->
user)) {
255 $ipp->setAuthentication($this->
user, $this->password);
258 return $ipp->available_printers;
271 include_once DOL_DOCUMENT_ROOT.
'/includes/printipp/CupsPrintIPP.php';
272 $ipp =
new CupsPrintIPP();
273 $ipp->setLog(DOL_DATA_ROOT.
'/dolibarr_printipp.log',
'file', 3);
274 $ipp->setHost($this->host);
275 $ipp->setPort($this->port);
276 $ipp->setUserName($this->userid);
277 if (!empty($this->
user)) {
278 $ipp->setAuthentication($this->
user, $this->password);
280 $ipp->setPrinterURI($uri);
281 $ipp->getPrinterAttributes();
282 return $ipp->printer_attributes;
297 include_once DOL_DOCUMENT_ROOT.
'/includes/printipp/CupsPrintIPP.php';
298 $ipp =
new CupsPrintIPP();
299 $ipp->setLog(DOL_DATA_ROOT.
'/dolibarr_printipp.log',
'file', 3);
300 $ipp->setHost($this->host);
301 $ipp->setPort($this->port);
302 $ipp->setUserName($this->userid);
303 if (!empty($this->
user)) {
304 $ipp->setAuthentication($this->
user, $this->password);
307 $sql =
'SELECT rowid,printer_uri,printer_name FROM '.MAIN_DB_PREFIX.
'printer_ipp WHERE module="'.$module.
'"';
308 $result = $this->
db->query($sql);
310 $obj = $this->
db->fetch_object($result);
312 $ipp->setPrinterURI($obj->printer_uri);
315 $ipp->setPrinterURI(
"ipp://localhost:631/printers/");
320 $ipp->getJobs(
false, 0,
'completed',
false);
322 $this->errors[] = $e->getMessage();
325 $html .=
'<table width="100%" class="noborder">';
326 $html .=
'<tr class="liste_titre">';
327 $html .=
'<td>Id</td>';
328 $html .=
'<td>Owner</td>';
329 $html .=
'<td>Printer</td>';
330 $html .=
'<td>File</td>';
331 $html .=
'<td>Status</td>';
332 $html .=
'<td>Cancel</td>';
333 $html .=
'</tr>'.
"\n";
334 $jobs = $ipp->jobs_attributes;
337 foreach ($jobs as $value) {
338 $html .=
'<tr class="oddeven">';
339 $html .=
'<td>'.$value->job_id->_value0.
'</td>';
340 $html .=
'<td>'.$value->job_originating_user_name->_value0.
'</td>';
341 $html .=
'<td>'.$value->printer_uri->_value0.
'</td>';
342 $html .=
'<td>'.$value->job_name->_value0.
'</td>';
343 $html .=
'<td>'.$value->job_state->_value0.
'</td>';
344 $html .=
'<td>'.$value->job_uri->_value0.
'</td>';
348 $this->resprint = $html;
conf($dolibarr_main_document_root)
Load conf file (file must exists)
listJobs($module)
List jobs print.
getPrinterDetail($uri)
Get printer detail.
Parent class of emailing target selectors modules.
printFile($file, $module, $subdir= '')
Print selected file.
$conf db
API class for accounts.
Class to provide printing with PrintIPP.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getlistAvailablePrinters()
Return list of available printers.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
listAvailablePrinters()
Return list of available printers.
__construct($db)
Constructor.