From 135de9ecdbd28c25e48f4e7720df7ebaa4f4fba6 Mon Sep 17 00:00:00 2001 From: frederic34 Date: Fri, 8 Mar 2013 11:54:32 +0100 Subject: [PATCH] Print IPP --- htdocs/core/class/dolprintipp.class.php | 147 ++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 htdocs/core/class/dolprintipp.class.php diff --git a/htdocs/core/class/dolprintipp.class.php b/htdocs/core/class/dolprintipp.class.php new file mode 100644 index 00000000000..30ddbfe254a --- /dev/null +++ b/htdocs/core/class/dolprintipp.class.php @@ -0,0 +1,147 @@ +. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/class/dolprintipp.class.php + * \brief A set of functions for using printIPP + */ + +/** + * Class to manage printIPP + */ +class dolprintIPP +{ + var $host; + var $port; + var $userid; + var $user; + var $password; + var $error; + var $db; + + + + /** + * Constructor + * + * @param DoliDB $db database + * @param string $host host of Cups + * @param string $port port + * @return printIPP + */ + function __construct($db,$host,$port,$userid,$user,$password) + { + $this->db=$db; + $this->host=$host; + $this->port=$port; + $this->userid=$userid; + $this->user=$user; + $this->password=$password; + } + + + /** + * 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.'/printipp.log','file',3); // logging very verbose + $ipp->setHost($this->host); + $ipp->setPort($this->port); + $ipp->setUserName($this->userid); + //$ipp->setAuthentication($this->user,$this->password); + $ipp->getPrinters(); + return $ipp->available_printers; + } + + /** + * Print selected file + * + */ + function print_file($file,$module) + { + global $conf,$db; + include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php'; + $ipp = new CupsPrintIPP(); + $ipp->setLog(DOL_DATA_ROOT.'/printipp.log','file',3); // logging very verbose + $ipp->setHost($this->host); + $ipp->setPort($this->port); + $ipp->setJobName($file,true); + $ipp->setUserName($this->userid); + //$ipp->setAuthentication($this->user,$this->password); + // select printer uri for module order, propal,... + $sql = 'SELECT rowid,printer_uri,copy 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 + { + $ipp->setPrinterURI($conf->global->PRINTIPP_URI_DEFAULT); + } + } + $ipp->setCopies($obj->copy); + $ipp->setData(DOL_DATA_ROOT.'/'.$module.'/'.$file); + $ipp->printJob(); + } + + /** + * List jobs print + * + */ + function list_jobs($module) + { + global $conf,$db; + include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php'; + $ipp = new CupsPrintIPP(); + $ipp->setLog(DOL_DATA_ROOT.'/printipp.log','file',3); // logging very verbose + $ipp->setHost($this->host); + $ipp->setPort($this->port); + $ipp->setUserName($this->userid); + // 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/"); + } + } + echo 'Jobs for : '.$this->userid.' module : '.$module.' Printer : '.$obj->printer_name.'
'; + echo "Getting Jobs: ".$ipp->getJobs(true,3,"completed",true)."
"; + + echo "
";print_r($ipp->jobs_attributes); echo "
"; + } +} +?>