123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- /*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * or see http://www.gnu.org/
- */
- /**
- * \file htdocs/core/modules/printing/printipp.modules.php
- * \ingroup mailing
- * \brief File to provide printing with PrintIPP
- */
- include_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
- /**
- * \class mailing_example
- * \brief Class to provide printing with PrintIPP
- */
- class printing_printipp extends PrintingDriver
- {
- var $name='printipp';
- var $desc='PrintIPPDesc';
- var $picto='printer';
- var $active='PRINTING_PRINTIPP';
- var $conf=array();
- var $host;
- var $port;
- var $userid; /* user login */
- var $user;
- var $password;
- var $error;
- var $db;
- /**
- * Constructor
- *
- * @param DoliDB $db Database handler
- */
- function __construct($db)
- {
- global $conf;
- $this->db=$db;
- $this->host=$conf->global->PRINTIPP_HOST;
- $this->port=$conf->global->PRINTIPP_PORT;
- $this->user=$conf->global->PRINTIPP_USER;
- $this->password=$conf->global->PRINTIPP_PASSWORD;
- $this->conf[] = array('varname'=>'PRINTIPP_HOST', 'required'=>1, 'example'=>'localhost', 'type'=>'text');
- $this->conf[] = array('varname'=>'PRINTIPP_PORT', 'required'=>1, 'example'=>'631', 'type'=>'text');
- $this->conf[] = array('varname'=>'PRINTIPP_USER', 'required'=>0, 'example'=>'', 'type'=>'text');
- $this->conf[] = array('varname'=>'PRINTIPP_PASSWORD', 'required'=>0, 'example'=>'', 'type'=>'password');
- }
- /**
- * Print selected file
- *
- * @param string $file file
- * @param string $module module
- * @param string $subdir subdirectory of document like for expedition subdir is sendings
- *
- * @return string '' if OK, Error message if KO
- */
- function print_file($file, $module, $subdir='')
- {
- global $conf,$db;
- include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
-
- $ipp = new CupsPrintIPP();
- $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose
- $ipp->setHost($this->host);
- $ipp->setPort($this->port);
- $ipp->setJobName($file,true);
- $ipp->setUserName($this->userid);
- if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
- // select printer uri for module order, propal,...
- $sql = 'SELECT rowid,printer_id,copy FROM '.MAIN_DB_PREFIX.'printing WHERE module="'.$module.'" AND driver="printipp"';
- $result = $db->query($sql);
- if ($result)
- {
- $obj = $this->db->fetch_object($result);
- if ($obj)
- {
- $ipp->setPrinterURI($obj->printer_id);
- }
- else
- {
- if (! empty($conf->global->PRINTIPP_URI_DEFAULT))
- {
- $ipp->setPrinterURI($conf->global->PRINTIPP_URI_DEFAULT);
- }
- else
- {
- return 'NoDefaultPrinterDefined';
- }
- }
- }
-
- // Set number of copy
- $ipp->setCopies($obj->copy);
- $fileprint=$conf->{$module}->dir_output;
- if ($subdir!='') $fileprint.='/'.$subdir;
- $fileprint.='/'.$file;
- $ipp->setData($fileprint);
- $ipp->printJob();
-
- return '';
- }
- /**
- * Return list of available printers
- *
- * @return string html list of printers
- */
- function listAvailablePrinters()
- {
- global $bc, $conf, $langs;
- $var=true;
- $html = '<table width="100%" class="noborder">';
- $html.= '<tr class="liste_titre">';
- $html.= '<td>'.$langs->trans('IPP_Uri').'</td>';
- $html.= '<td>'.$langs->trans('IPP_Name').'</td>';
- $html.= '<td>'.$langs->trans('IPP_State').'</td>';
- $html.= '<td>'.$langs->trans('IPP_State_reason').'</td>';
- $html.= '<td>'.$langs->trans('IPP_State_reason1').'</td>';
- $html.= '<td>'.$langs->trans('IPP_BW').'</td>';
- $html.= '<td>'.$langs->trans('IPP_Color').'</td>';
- //$html.= '<td>'.$langs->trans('IPP_Device').'</td>';
- $html.= '<td>'.$langs->trans('IPP_Media').'</td>';
- $html.= '<td>'.$langs->trans('IPP_Supported').'</td>';
- $html.= '<td align="center">'.$langs->trans("Select").'</td>';
- $html.= "</tr>\n";
- $list = $this->getlist_available_printers();
- $var = true;
- foreach ($list as $value)
- {
- $var=!$var;
- $printer_det = $this->get_printer_detail($value);
- $html.= "<tr ".$bc[$var].">";
- $html.= '<td>'.$value.'</td>';
- //$html.= '<td><pre>'.print_r($printer_det,true).'</pre></td>';
- $html.= '<td>'.$printer_det->printer_name->_value0.'</td>';
- $html.= '<td>'.$langs->trans('STATE_IPP_'.$printer_det->printer_state->_value0).'</td>';
- $html.= '<td>'.$langs->trans('STATE_IPP_'.$printer_det->printer_state_reasons->_value0).'</td>';
- $html.= '<td>'.(! empty($printer_det->printer_state_reasons->_value1)?$langs->trans('STATE_IPP_'.$printer_det->printer_state_reasons->_value1):'').'</td>';
- $html.= '<td>'.$langs->trans('IPP_COLOR_'.$printer_det->printer_type->_value2).'</td>';
- $html.= '<td>'.$langs->trans('IPP_COLOR_'.$printer_det->printer_type->_value3).'</td>';
- //$html.= '<td>'.$printer_det->device_uri->_value0.'</td>';
- $html.= '<td>'.$printer_det->media_default->_value0.'</td>';
- $html.= '<td>'.$langs->trans('MEDIA_IPP_'.$printer_det->media_type_supported->_value1).'</td>';
- // Defaut
- $html.= '<td align="center">';
- if ($conf->global->PRINTIPP_URI_DEFAULT == $value)
- {
- $html.= img_picto($langs->trans("Default"),'on');
- }
- else
- $html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTIPP_URI_DEFAULT&driver=printipp&value='.urlencode($value).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
- $html.= '</td>';
- $html.= '</tr>'."\n";
- }
- return $html;
- }
- /**
- * Return list of available printers
- *
- * @return array list of printers
- */
- function getlist_available_printers()
- {
- global $conf,$db;
- include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
- $ipp = new CupsPrintIPP();
- $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose
- $ipp->setHost($this->host);
- $ipp->setPort($this->port);
- $ipp->setUserName($this->userid);
- if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
- $ipp->getPrinters();
- return $ipp->available_printers;
- }
- /**
- * Get printer detail
- *
- * @param string $uri URI
- * @return array List of attributes
- */
- function get_printer_detail($uri)
- {
- global $conf,$db;
- include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
- $ipp = new CupsPrintIPP();
- $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose
- $ipp->setHost($this->host);
- $ipp->setPort($this->port);
- $ipp->setUserName($this->userid);
- if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
- $ipp->setPrinterURI($uri);
- $ipp->getPrinterAttributes();
- return $ipp->printer_attributes;
- }
- /**
- * List jobs print
- *
- * @param string $module module
- *
- * @return void
- */
- function list_jobs($module)
- {
- global $conf, $db, $bc;
- include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
- $ipp = new CupsPrintIPP();
- $ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose
- $ipp->setHost($this->host);
- $ipp->setPort($this->port);
- $ipp->setUserName($this->userid);
- if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
- // select printer uri for module order, propal,...
- $sql = 'SELECT rowid,printer_uri,printer_name FROM '.MAIN_DB_PREFIX.'printer_ipp WHERE module="'.$module.'"';
- $result = $this->db->query($sql);
- if ($result)
- {
- $obj = $this->db->fetch_object($result);
- if ($obj)
- {
- $ipp->setPrinterURI($obj->printer_uri);
- }
- else
- {
- // All printers
- $ipp->setPrinterURI("ipp://localhost:631/printers/");
- }
- }
- // Getting Jobs
- $ipp->getJobs(false,0,'completed',false);
- print '<table width="100%" class="noborder">';
- print '<tr class="liste_titre">';
- print "<td>Id</td>";
- print "<td>Owner</td>";
- print "<td>Printer</td>";
- print "<td>File</td>";
- print "<td>Status</td>";
- print "<td>Cancel</td>";
- print "</tr>\n";
- $jobs = $ipp->jobs_attributes;
- $var = True;
- //print '<pre>'.print_r($jobs,true).'</pre>';
- foreach ($jobs as $value )
- {
- $var=!$var;
- print "<tr ".$bc[$var].">";
- print '<td>'.$value->job_id->_value0.'</td>';
- print '<td>'.$value->job_originating_user_name->_value0.'</td>';
- print '<td>'.$value->printer_uri->_value0.'</td>';
- print '<td>'.$value->job_name->_value0.'</td>';
- print '<td>'.$value->job_state->_value0.'</td>';
- print '<td>'.$value->job_uri->_value0.'</td>';
- print '</tr>';
- }
- print "</table>";
- }
- }
|