commit
72749bfc5f
@ -1102,6 +1102,14 @@ else if ($action == 'remove_file')
|
||||
}
|
||||
}
|
||||
|
||||
// Print file
|
||||
else if ($action == 'print_file' AND $user->rights->printipp->use)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php';
|
||||
$printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD);
|
||||
$printer->print_file(GETPOST('file',alpha),GETPOST('printer',alpha));
|
||||
}
|
||||
|
||||
/*
|
||||
* Add file in email form
|
||||
*/
|
||||
@ -2354,8 +2362,9 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
|
||||
$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
|
||||
$genallowed=$user->rights->commande->creer;
|
||||
$delallowed=$user->rights->commande->supprimer;
|
||||
|
||||
$somethingshown=$formfile->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
|
||||
$printer = false;
|
||||
if ($user->rights->printipp->use AND $conf->printipp->enabled) $printer = true;
|
||||
$somethingshown=$formfile->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang,$printer);
|
||||
|
||||
/*
|
||||
* Linked object block
|
||||
|
||||
147
htdocs/core/class/dolprintipp.class.php
Normal file
147
htdocs/core/class/dolprintipp.class.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?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/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.'<br />';
|
||||
echo "Getting Jobs: ".$ipp->getJobs(true,3,"completed",true)."<br />";
|
||||
|
||||
echo "<pre>";print_r($ipp->jobs_attributes); echo "</pre>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -161,12 +161,13 @@ class FormFile
|
||||
* @param string $title Title to show on top of form
|
||||
* @param string $buttonlabel Label on submit button
|
||||
* @param string $codelang Default language code to use on lang combo box if multilang is enabled
|
||||
* @param boolean $printer Printer Icon
|
||||
* @return int <0 if KO, number of shown files if OK
|
||||
*/
|
||||
function show_documents($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='')
|
||||
function show_documents($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$printer=false)
|
||||
{
|
||||
$this->numoffiles=0;
|
||||
print $this->showdocuments($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$maxfilenamelength,$noform,$param,$title,$buttonlabel,$codelang);
|
||||
print $this->showdocuments($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$maxfilenamelength,$noform,$param,$title,$buttonlabel,$codelang,$printer);
|
||||
return $this->numoffiles;
|
||||
}
|
||||
|
||||
@ -190,9 +191,10 @@ class FormFile
|
||||
* @param string $title Title to show on top of form
|
||||
* @param string $buttonlabel Label on submit button
|
||||
* @param string $codelang Default language code to use on lang combo box if multilang is enabled
|
||||
* @param boolean $printer Printer Icon
|
||||
* @return string Output string with HTML array of documents (might be empty string)
|
||||
*/
|
||||
function showdocuments($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='')
|
||||
function showdocuments($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$printer)
|
||||
{
|
||||
// filedir = conf->...dir_ouput."/".get_exdir(id)
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
@ -436,6 +438,8 @@ class FormFile
|
||||
}
|
||||
$out.= '</th>';
|
||||
|
||||
if ($printer) $out.= '<th></th>';
|
||||
|
||||
$out.= '</tr>';
|
||||
|
||||
// Execute hooks
|
||||
@ -499,6 +503,14 @@ class FormFile
|
||||
//$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
|
||||
$out.= '">'.img_delete().'</a></td>';
|
||||
}
|
||||
// Printer Icon
|
||||
if ($printer)
|
||||
{
|
||||
$out.= '<td align="right">';
|
||||
$out.= ' <a href="'.$urlsource.'&action=print_file&printer='.$modulepart.'&file='.urlencode($relativepath);
|
||||
$out.= ($param?'&'.$param:'');
|
||||
$out.= '">'.img_printer().'</a></td>';
|
||||
}
|
||||
}
|
||||
|
||||
$out.= '</tr>';
|
||||
|
||||
@ -1847,6 +1847,20 @@ function img_delete($alt = 'default', $other = '')
|
||||
return img_picto($alt, 'delete.png', $other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show printer logo
|
||||
*
|
||||
* @param string $alt Text on alt image
|
||||
* @param string $other Add more attributes on img
|
||||
* @return string Retourne tag img
|
||||
*/
|
||||
function img_printer($alt = "default", $other='')
|
||||
{
|
||||
global $conf,$langs;
|
||||
if ($alt=="default") $alt=$langs->trans("Print");
|
||||
return img_picto($alt,'printer.png',$other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show help logo with cursor "?"
|
||||
*
|
||||
|
||||
145
htdocs/core/modules/modPrintIPP.class.php
Normal file
145
htdocs/core/modules/modPrintIPP.class.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?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/>.
|
||||
*/
|
||||
|
||||
/** \defgroup printipp Module printipp
|
||||
* \brief Module pour imprimer via CUPS
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/modules/modPrintIPP.class.php
|
||||
* \ingroup printipp
|
||||
* \brief Fichier de description et activation du module OSCommerce2
|
||||
*/
|
||||
include_once(DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \class modPrintIPP
|
||||
* \brief Classe de description et activation du module PrintIPP
|
||||
*/
|
||||
class modPrintIPP extends DolibarrModules
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Constructeur. Definit les noms, constantes et boites
|
||||
* \param DB handler d'acces base
|
||||
*/
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db ;
|
||||
$this->numero = 54000;
|
||||
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
|
||||
// It is used to group modules in module setup page
|
||||
$this->family = "other";
|
||||
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
|
||||
$this->name = preg_replace('/^mod/i','',get_class($this));
|
||||
$this->description = "Print via Cups IPP Printer.";
|
||||
$this->version = 'experimental'; // 'development' or 'experimental' or 'dolibarr' or version
|
||||
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
|
||||
// Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
|
||||
$this->special = 1;
|
||||
// Name of image file used for this module.
|
||||
// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
|
||||
// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
|
||||
$this->picto = 'technic';
|
||||
|
||||
// Data directories to create when module is enabled.
|
||||
$this->dirs = array();
|
||||
|
||||
// Config pages
|
||||
$this->config_page_url = array("printipp.php@printipp");
|
||||
|
||||
// Dependances
|
||||
$this->depends = array();
|
||||
$this->requiredby = array();
|
||||
$this->phpmin = array(5,1); // Minimum version of PHP required by module
|
||||
$this->need_dolibarr_version = array(3,2); // Minimum version of Dolibarr required by module
|
||||
$this->conflictwith = array();
|
||||
$this->langfiles = array("printipp");
|
||||
|
||||
// Constantes
|
||||
$this->const = array();
|
||||
|
||||
// Boxes
|
||||
$this->boxes = array();
|
||||
|
||||
// Permissions
|
||||
$this->rights = array();
|
||||
$this->rights_class = 'printipp';
|
||||
|
||||
$r=0;
|
||||
// $this->rights[$r][0] Id permission (unique tous modules confondus)
|
||||
// $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
|
||||
// $this->rights[$r][2] Non utilise
|
||||
// $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
|
||||
// $this->rights[$r][4] Niveau 1 pour nommer permission dans code
|
||||
// $this->rights[$r][5] Niveau 2 pour nommer permission dans code
|
||||
|
||||
$r++;
|
||||
$this->rights[$r][0] = 54001;
|
||||
$this->rights[$r][1] = 'Printer';
|
||||
$this->rights[$r][2] = 'r';
|
||||
$this->rights[$r][3] = 1;
|
||||
$this->rights[$r][4] = 'use';
|
||||
|
||||
// Main menu entries
|
||||
$this->menus = array(); // List of menus to add
|
||||
$r=0;
|
||||
|
||||
// This is to declare the Top Menu entry:
|
||||
$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home', // Put 0 if this is a top menu
|
||||
'type'=>'left', // This is a Top menu entry
|
||||
'titre'=>'Printer',
|
||||
'mainmenu'=>'printer',
|
||||
'url'=>'/printipp/index.php',
|
||||
'langs'=>'printipp', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||
'position'=>100,
|
||||
'enabled'=>'$conf->printipp->enabled',
|
||||
'perms'=>'$user->rights->printipp->use', // Use 'perms'=>'1' if you want your menu with no permission rules
|
||||
'target'=>'',
|
||||
'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
|
||||
|
||||
$r++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Fonction appelee lors de l'activation du module. Insere en base les constantes, boites, permissions du module.
|
||||
* Definit egalement les repertoires de donnees a creer pour ce module.
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
$sql = array("CREATE TABLE IF NOT EXISTS llx_printer_ipp (rowid int(11) NOT NULL AUTO_INCREMENT,printer_name text NOT NULL, printer_location text NOT NULL,printer_uri varchar(256) NOT NULL,copy int(11) NOT NULL DEFAULT '1',module varchar(16) NOT NULL,login varchar(32) NOT NULL,PRIMARY KEY (rowid)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
|
||||
|
||||
return $this->_init($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Fonction appelee lors de la desactivation d'un module.
|
||||
* Supprime de la base les constantes, boites et permissions du module.
|
||||
*/
|
||||
function remove()
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
return $this->_remove($sql);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
2000
htdocs/includes/printipp/BasicIPP.php
Normal file
2000
htdocs/includes/printipp/BasicIPP.php
Normal file
File diff suppressed because it is too large
Load Diff
671
htdocs/includes/printipp/CupsPrintIPP.php
Normal file
671
htdocs/includes/printipp/CupsPrintIPP.php
Normal file
@ -0,0 +1,671 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
/* @(#) $Header: /sources/phpprintipp/phpprintipp/php_classes/CupsPrintIPP.php,v 1.1 2008/06/21 00:30:56 harding Exp $
|
||||
*
|
||||
* Class PrintIPP - Send extended IPP requests.
|
||||
*
|
||||
* Copyright (C) 2005-2006 Thomas HARDING
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* mailto:thomas.harding@laposte.net
|
||||
* Thomas Harding, 56 rue de la bourie rouge, 45 000 ORLEANS -- FRANCE
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This class is intended to implement Internet Printing Protocol on client side.
|
||||
|
||||
References needed to debug / add functionnalities:
|
||||
- RFC 2910
|
||||
- RFC 2911
|
||||
- RFC 3382
|
||||
- ...
|
||||
- CUPS-IPP-1.1
|
||||
*/
|
||||
|
||||
require_once("ExtendedPrintIPP.php");
|
||||
|
||||
class CupsPrintIPP extends ExtendedPrintIPP {
|
||||
|
||||
// {{{ variables declaration
|
||||
|
||||
public $printers_attributes;
|
||||
public $defaults_attributes;
|
||||
|
||||
// }}}
|
||||
|
||||
// {{{ constructor
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::_initTags();
|
||||
}
|
||||
// }}}
|
||||
|
||||
//
|
||||
// OPERATIONS
|
||||
//
|
||||
|
||||
// {{{ cupsGetDefaults ($attributes="all")
|
||||
public function cupsGetDefaults($attributes=array("all")) {
|
||||
//The CUPS-Get-Default operation returns the default printer URI and attributes
|
||||
|
||||
$this->jobs = array_merge($this->jobs,array(""));
|
||||
$this->jobs_uri = array_merge($this->jobs_uri,array(""));
|
||||
$this->parsed = array();
|
||||
unset($this->printer_attributes);
|
||||
|
||||
if (!isset($this->setup->charset))
|
||||
self::setCharset('us-ascii');
|
||||
|
||||
if (!isset($this->setup->language))
|
||||
self::setLanguage('en');
|
||||
|
||||
self::_setOperationId();
|
||||
|
||||
for($i = 0 ; $i < count($attributes) ; $i++)
|
||||
if ($i == 0)
|
||||
$this->meta->attributes = chr(0x44) // Keyword
|
||||
. self::_giveMeStringLength('requested-attributes')
|
||||
. 'requested-attributes'
|
||||
. self::_giveMeStringLength($attributes[0])
|
||||
. $attributes[0];
|
||||
else
|
||||
$this->meta->attributes .= chr(0x44) // Keyword
|
||||
. chr(0x0).chr(0x0) // zero-length name
|
||||
. self::_giveMeStringLength($attributes[$i])
|
||||
. $attributes[$i];
|
||||
|
||||
$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
|
||||
. chr(0x40). chr(0x01) // operation: cups vendor extension: get defaults
|
||||
. $this->meta->operation_id // request-id
|
||||
. chr(0x01) // start operation-attributes | operation-attributes-tag
|
||||
. $this->meta->charset
|
||||
. $this->meta->language
|
||||
. $this->meta->attributes
|
||||
. chr(0x03); // end operations attribute
|
||||
|
||||
$this->output = $this->stringjob;
|
||||
|
||||
self::_putDebug("Request: ".$this->output);
|
||||
|
||||
$post_values = array( "Content-Type" => "application/ipp",
|
||||
"Data" => $this->output);
|
||||
|
||||
if (self::_sendHttp ($post_values,'/')) {
|
||||
|
||||
if(self::_parseServerOutput())
|
||||
self::_parsePrinterAttributes();
|
||||
}
|
||||
|
||||
$this->attributes = &$this->printer_attributes;
|
||||
|
||||
if (isset($this->printer_attributes->printer_type)) {
|
||||
$printer_type = $this->printer_attributes->printer_type->_value0;
|
||||
$table = self::_interpretPrinterType($printer_type);
|
||||
|
||||
for($i = 0 ; $i < count($table) ; $i++ ) {
|
||||
$index = '_value'.$i;
|
||||
$this->printer_attributes->printer_type->$index = $table[$i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
|
||||
|
||||
$this->status = array_merge($this->status,array($this->serveroutput->status));
|
||||
if ($this->serveroutput->status == "successfull-ok")
|
||||
self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
|
||||
else
|
||||
self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
|
||||
|
||||
return $this->serveroutput->status;
|
||||
|
||||
} else {
|
||||
$this->status = array_merge($this->status,array("OPERATION FAILED"));
|
||||
self::_errorLog("getting defaults : OPERATION FAILED",1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ cupsAcceptJobs ($printer_uri)
|
||||
public function cupsAcceptJobs($printer_uri) {
|
||||
//The CUPS-Get-Default operation returns the default printer URI and attributes
|
||||
|
||||
$this->jobs = array_merge($this->jobs,array(""));
|
||||
$this->jobs_uri = array_merge($this->jobs_uri,array(""));
|
||||
$this->parsed = array();
|
||||
unset($this->printer_attributes);
|
||||
|
||||
if (!isset($this->setup->charset))
|
||||
self::setCharset('us-ascii');
|
||||
|
||||
if (!isset($this->setup->language))
|
||||
self::setLanguage('en');
|
||||
|
||||
self::_setOperationId();
|
||||
|
||||
$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
|
||||
. chr(0x40). chr(0x08) // operation: cups vendor extension: Accept-Jobs
|
||||
. $this->meta->operation_id // request-id
|
||||
. chr(0x01) // start operation-attributes | operation-attributes-tag
|
||||
. $this->meta->charset
|
||||
. $this->meta->language
|
||||
. chr(0x45) // uri
|
||||
. self::_giveMeStringLength('printer-uri')
|
||||
. 'printer-uri'
|
||||
. self::_giveMeStringLength($printer_uri)
|
||||
. $printer_uri
|
||||
. chr(0x03); // end operations attribute
|
||||
|
||||
$this->output = $this->stringjob;
|
||||
|
||||
self::_putDebug("Request: ".$this->output);
|
||||
|
||||
$post_values = array( "Content-Type" => "application/ipp",
|
||||
"Data" => $this->output);
|
||||
|
||||
if (self::_sendHttp ($post_values,'/admin/')) {
|
||||
|
||||
if(self::_parseServerOutput())
|
||||
self::_parseAttributes();
|
||||
}
|
||||
|
||||
if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
|
||||
|
||||
$this->status = array_merge($this->status,array($this->serveroutput->status));
|
||||
if ($this->serveroutput->status == "successfull-ok")
|
||||
self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
|
||||
else
|
||||
self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
|
||||
|
||||
return $this->serveroutput->status;
|
||||
|
||||
} else {
|
||||
$this->status = array_merge($this->status,array("OPERATION FAILED"));
|
||||
self::_errorLog("getting defaults : OPERATION FAILED",1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ cupsRejectJobs ($printer_uri,$printer_state_message=false)
|
||||
public function cupsRejectJobs($printer_uri,$printer_state_message) {
|
||||
//The CUPS-Get-Default operation returns the default printer URI and attributes
|
||||
|
||||
$this->jobs = array_merge($this->jobs,array(""));
|
||||
$this->jobs_uri = array_merge($this->jobs_uri,array(""));
|
||||
$this->parsed = array();
|
||||
unset($this->attributes);
|
||||
|
||||
if (!isset($this->setup->charset))
|
||||
self::setCharset('us-ascii');
|
||||
|
||||
if (!isset($this->setup->language))
|
||||
self::setLanguage('en');
|
||||
|
||||
self::_setOperationId();
|
||||
|
||||
$message = "";
|
||||
if ($printer_state_message)
|
||||
$message = chr(0x04) // start printer-attributes
|
||||
. chr(0x41) // textWithoutLanguage
|
||||
. self::_giveMeStringLength("printer-state-message")
|
||||
. "printer-state-message"
|
||||
. self::_giveMeStringLength($printer_state_message)
|
||||
. $printer_state_message;
|
||||
|
||||
$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
|
||||
. chr(0x40). chr(0x09) // operation: cups vendor extension: Reject-Jobs
|
||||
. $this->meta->operation_id // request-id
|
||||
. chr(0x01) // start operation-attributes | operation-attributes-tag
|
||||
. $this->meta->charset
|
||||
. $this->meta->language
|
||||
. chr(0x45) // uri
|
||||
. self::_giveMeStringLength('printer-uri')
|
||||
. 'printer-uri'
|
||||
. self::_giveMeStringLength($printer_uri)
|
||||
. $printer_uri
|
||||
. $message
|
||||
. chr(0x03); // end operations attribute
|
||||
|
||||
$this->output = $this->stringjob;
|
||||
|
||||
self::_putDebug("Request: ".$this->output);
|
||||
|
||||
$post_values = array( "Content-Type" => "application/ipp",
|
||||
"Data" => $this->output);
|
||||
|
||||
if (self::_sendHttp ($post_values,'/admin/')) {
|
||||
|
||||
if(self::_parseServerOutput())
|
||||
self::_parseAttributes();
|
||||
}
|
||||
|
||||
if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
|
||||
|
||||
$this->status = array_merge($this->status,array($this->serveroutput->status));
|
||||
if ($this->serveroutput->status == "successfull-ok")
|
||||
self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
|
||||
else
|
||||
self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
|
||||
|
||||
return $this->serveroutput->status;
|
||||
|
||||
} else {
|
||||
$this->status = array_merge($this->status,array("OPERATION FAILED"));
|
||||
self::_errorLog("getting defaults : OPERATION FAILED",1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ getPrinters()
|
||||
public function getPrinters($printer_location=false,$printer_info=false,$attributes=array()) {
|
||||
|
||||
if (count($attributes) == 0)
|
||||
true;
|
||||
$attributes=array('printer-uri-supported','printer-location','printer-info','printer-type','color-supported');
|
||||
$this->jobs = array_merge($this->jobs,array(""));
|
||||
$this->jobs_uri = array_merge($this->jobs_uri,array(""));
|
||||
|
||||
unset ($this->printers_attributes);
|
||||
|
||||
if (!isset($this->setup->charset))
|
||||
self::setCharset('us-ascii');
|
||||
|
||||
if (!isset($this->setup->language))
|
||||
self::setLanguage('en-us');
|
||||
|
||||
self::_setOperationId();
|
||||
|
||||
$this->meta->attributes='';
|
||||
|
||||
if ($printer_location)
|
||||
$this->meta->attributes .= chr(0x41) // textWithoutLanguage
|
||||
. self::_giveMeStringLength('printer-location')
|
||||
. 'printer-location'
|
||||
. self::_giveMeStringLength($printer_location)
|
||||
. $printer_location;
|
||||
|
||||
|
||||
if ($printer_info)
|
||||
$this->meta->attributes .= chr(0x41) // textWithoutLanguage
|
||||
. self::_giveMeStringLength('printer-info')
|
||||
. 'printer-info'
|
||||
. self::_giveMeStringLength($printer_info)
|
||||
. $printer_info;
|
||||
|
||||
for($i = 0 ; $i < count($attributes) ; $i++)
|
||||
if ($i == 0)
|
||||
$this->meta->attributes .= chr(0x44) // Keyword
|
||||
. self::_giveMeStringLength('requested-attributes')
|
||||
. 'requested-attributes'
|
||||
. self::_giveMeStringLength($attributes[0])
|
||||
. $attributes[0];
|
||||
else
|
||||
$this->meta->attributes .= chr(0x44) // Keyword
|
||||
. chr(0x0).chr(0x0) // zero-length name
|
||||
. self::_giveMeStringLength($attributes[$i])
|
||||
. $attributes[$i];
|
||||
|
||||
|
||||
$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
|
||||
. chr(0x40). chr(0x02) // operation: cups vendor extension: get printers
|
||||
. $this->meta->operation_id // request-id
|
||||
. chr(0x01) // start operation-attributes | operation-attributes-tag
|
||||
. $this->meta->charset
|
||||
. $this->meta->language
|
||||
. $this->meta->attributes
|
||||
. chr(0x03); // end operations attribute
|
||||
|
||||
$this->output = $this->stringjob;
|
||||
|
||||
$post_values = array( "Content-Type" => "application/ipp",
|
||||
"Data" => $this->output);
|
||||
|
||||
if (self::_sendHttp ($post_values,'/')) {
|
||||
|
||||
if(self::_parseServerOutput())
|
||||
$this->_getAvailablePrinters();
|
||||
|
||||
}
|
||||
|
||||
if (isset($this->serveroutput) && isset($this->serveroutput->status)) {
|
||||
|
||||
$this->status = array_merge($this->status,array($this->serveroutput->status));
|
||||
if ($this->serveroutput->status == "successfull-ok")
|
||||
self::_errorLog("getting printers: ".$this->serveroutput->status,3);
|
||||
else
|
||||
self::_errorLog("getting printers: ".$this->serveroutput->status,1);
|
||||
return $this->serveroutput->status;
|
||||
|
||||
} else {
|
||||
$this->status = array_merge($this->status,array("OPERATION FAILED"));
|
||||
self::_errorLog("getting printers : OPERATION FAILED",1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ cupsGetPrinters ()
|
||||
public function cupsGetPrinters () {
|
||||
// alias for getPrinters();
|
||||
self::getPrinters();
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ getPrinterAttributes()
|
||||
public function getPrinterAttributes() {
|
||||
// complete informations from parent with Cups-specific stuff
|
||||
|
||||
if(!$result = parent::getPrinterAttributes())
|
||||
return FALSE;
|
||||
if(!isset($this->printer_attributes))
|
||||
return FALSE;
|
||||
|
||||
if (isset ($this->printer_attributes->printer_type)) {
|
||||
$printer_type = $this->printer_attributes->printer_type->_value0;
|
||||
$table = self::_interpretPrinterType($printer_type);
|
||||
|
||||
for($i = 0 ; $i < count($table) ; $i++ ) {
|
||||
$index = '_value'.$i;
|
||||
$this->printer_attributes->printer_type->$index = $table[$i];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
// }}}
|
||||
|
||||
//
|
||||
// SETUP
|
||||
//
|
||||
|
||||
// {{{ _initTags ()
|
||||
protected function _initTags () {
|
||||
|
||||
// override parent with specific cups attributes
|
||||
|
||||
$operation_tags = array ();
|
||||
$this->operation_tags = array_merge ($this->operation_tags, $operation_tags);
|
||||
|
||||
$job_tags = array ( "job-billing" => array("tag" => "textWithoutLanguage"),
|
||||
"blackplot" => array("tag" => "boolean"),
|
||||
"brightness" => array("tag" => "integer"),
|
||||
"columns" => array("tag" => "integer"),
|
||||
"cpi" => array("tag" => "enum"),
|
||||
"fitplot" => array("tag" => "boolean"),
|
||||
"gamma" => array("tag" => "integer"),
|
||||
"hue" => array("tag" => "integer"),
|
||||
"lpi" => array("tag" => "enum"),
|
||||
"mirror" => array("tag","boolean"),
|
||||
"natural-scaling" => array("tag" => "integer"),
|
||||
"number-up-layout" => array("tag" => "keyword"),
|
||||
"page-border" => array("tag" => "keyword"),
|
||||
"page-bottom" => array("tag" => "integer"),
|
||||
"page-label" => array("tag" => "textWithoutLanguage"),
|
||||
"page-left" => array("tag" => "integer"),
|
||||
"page-right" => array("tag" => "integer"),
|
||||
"page-set" => array("tag" => "keyword"),
|
||||
"page-top" => array("tag" => "integer"),
|
||||
"penwidth" => array("tag" => "integer"),
|
||||
"position" => array("tag" => "keyword"),
|
||||
"ppi" => array("tag" => "integer"),
|
||||
"prettyprint" => array("tag","boolean"),
|
||||
"saturation" => array("tag" => "integer"),
|
||||
"scaling" => array("tag" => "integer"),
|
||||
"wrap" => array("tag","boolean"),
|
||||
|
||||
);
|
||||
$this->job_tags = array_merge ($this->job_tags, $job_tags);
|
||||
}
|
||||
// }}}
|
||||
|
||||
//
|
||||
// REQUEST BUILDING
|
||||
//
|
||||
|
||||
// {{{ _enumBuild ($tag,$value)
|
||||
protected function _enumBuild ($tag,$value) {
|
||||
|
||||
$value_built = parent::_enumBuild($tag,$value);
|
||||
|
||||
|
||||
switch ($tag) {
|
||||
case "cpi":
|
||||
switch ($value) {
|
||||
case '10':
|
||||
$value_built = chr(10);
|
||||
break;
|
||||
case '12':
|
||||
$value_built = chr(12);
|
||||
break;
|
||||
case '17':
|
||||
$value_built = chr(17);
|
||||
break;
|
||||
default:
|
||||
$value_built = chr(10);
|
||||
}
|
||||
break;
|
||||
case "lpi":
|
||||
switch ($value) {
|
||||
case '6':
|
||||
$value_built = chr(6);
|
||||
break;
|
||||
case '8':
|
||||
$value_built = chr(8);
|
||||
break;
|
||||
default:
|
||||
$value_built = chr(6);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$prepend = '';
|
||||
while ((strlen($value_built) + strlen($prepend)) < 4)
|
||||
$prepend .= chr(0);
|
||||
return $prepend.$value_built;
|
||||
}
|
||||
// }}}
|
||||
|
||||
//
|
||||
// RESPONSE PARSING
|
||||
//
|
||||
|
||||
// {{{ _getAvailablePrinters ()
|
||||
private function _getAvailablePrinters () {
|
||||
|
||||
$this->available_printers = array();
|
||||
$k = 0;
|
||||
$this->printers_attributes = new stdClass();
|
||||
|
||||
for ($i = 0 ; (array_key_exists($i,$this->serveroutput->response)) ; $i ++)
|
||||
if (($this->serveroutput->response[$i]['attributes']) == "printer-attributes") {
|
||||
$phpname = "_printer".$k;
|
||||
$this->printers_attributes->$phpname = new stdClass();
|
||||
for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++) {
|
||||
|
||||
$value = $this->serveroutput->response[$i][$j]['value'];
|
||||
$name = str_replace("-","_",$this->serveroutput->response[$i][$j]['name']);
|
||||
|
||||
switch ($name) {
|
||||
case "printer_uri_supported":
|
||||
$this->available_printers = array_merge($this->available_printers,array($value));
|
||||
break;
|
||||
case "printer_type":
|
||||
$table = self::_interpretPrinterType($value);
|
||||
$this->printers_attributes->$phpname->$name = new stdClass();
|
||||
|
||||
for($l = 0 ; $l < count($table) ; $l++ ) {
|
||||
$index = '_value'.$l;
|
||||
$this->printers_attributes->$phpname->$name->$index = $table[$l];
|
||||
}
|
||||
|
||||
break;
|
||||
case '':
|
||||
break;
|
||||
default:
|
||||
$this->printers_attributes->$phpname->$name = $value;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
$k ++;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ _getEnumVendorExtensions
|
||||
protected function _getEnumVendorExtensions ($value_parsed) {
|
||||
switch ($value_parsed) {
|
||||
case 0x4002:
|
||||
$value = 'Get-Availables-Printers';
|
||||
break;
|
||||
default:
|
||||
$value = sprintf('Unknown(Cups extension for operations): 0x%x',$value_parsed);
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($value))
|
||||
return ($value);
|
||||
|
||||
return sprintf('Unknown: 0x%x',$value_parsed);
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ _interpretPrinterType($type)
|
||||
private function _interpretPrinterType($value) {
|
||||
$value_parsed = 0;
|
||||
for ($i = strlen($value) ; $i > 0 ; $i --)
|
||||
$value_parsed += pow(256,($i - 1)) * ord($value[strlen($value) - $i]);
|
||||
|
||||
$type[0] = $type[1] = $type[2] = $type[3] = $type[4] = $type[5] = '';
|
||||
$type[6] = $type[7] = $type[8] = $type[9] = $type[10] = '';
|
||||
$type[11] = $type[12] = $type[13] = $type[14] = $type[15] = '';
|
||||
$type[16] = $type[17] = $type[18] = $type[19] = '';
|
||||
|
||||
if ($value_parsed %2 == 1) {
|
||||
$type[0] = 'printer-class';
|
||||
$value_parsed -= 1;
|
||||
}
|
||||
if ($value_parsed %4 == 2 ) {
|
||||
$type[1] = 'remote-destination';
|
||||
$value_parsed -= 2;
|
||||
}
|
||||
if ($value_parsed %8 == 4 ) {
|
||||
$type[2] = 'print-black';
|
||||
$value_parsed -= 4;
|
||||
}
|
||||
if ($value_parsed %16 == 8 ) {
|
||||
$type[3] = 'print-color';
|
||||
$value_parsed -= 8;
|
||||
}
|
||||
if ($value_parsed %32 == 16) {
|
||||
$type[4] = 'hardware-print-on-both-sides';
|
||||
$value_parsed -= 16;
|
||||
}
|
||||
if ($value_parsed %64 == 32) {
|
||||
$type[5] = 'hardware-staple-output';
|
||||
$value_parsed -= 32;
|
||||
}
|
||||
if ($value_parsed %128 == 64) {
|
||||
$type[6] = 'hardware-fast-copies';
|
||||
$value_parsed -= 64;
|
||||
}
|
||||
if ($value_parsed %256 == 128) {
|
||||
$type[7] = 'hardware-fast-copy-collation';
|
||||
$value_parsed -= 128;
|
||||
}
|
||||
if ($value_parsed %512 == 256) {
|
||||
$type[8] = 'punch-output';
|
||||
$value_parsed -= 256;
|
||||
}
|
||||
if ($value_parsed %1024 == 512) {
|
||||
$type[9] = 'cover-output';
|
||||
$value_parsed -= 512;
|
||||
}
|
||||
if ($value_parsed %2048 == 1024) {
|
||||
$type[10] = 'bind-output';
|
||||
$value_parsed -= 1024;
|
||||
}
|
||||
if ($value_parsed %4096 == 2048) {
|
||||
$type[11] = 'sort-output';
|
||||
$value_parsed -= 2048;
|
||||
}
|
||||
if ($value_parsed %8192 == 4096) {
|
||||
$type[12] = 'handle-media-up-to-US-Legal-A4';
|
||||
$value_parsed -= 4096;
|
||||
}
|
||||
if ($value_parsed %16384 == 8192) {
|
||||
$type[13] = 'handle-media-between-US-Legal-A4-and-ISO_C-A2';
|
||||
$value_parsed -= 8192;
|
||||
}
|
||||
if ($value_parsed %32768 == 16384) {
|
||||
$type[14] = 'handle-media-larger-than-ISO_C-A2';
|
||||
$value_parsed -= 16384;
|
||||
}
|
||||
if ($value_parsed %65536 == 32768) {
|
||||
$type[15] = 'handle-user-defined-media-sizes';
|
||||
$value_parsed -= 32768;
|
||||
}
|
||||
if ($value_parsed %131072 == 65536) {
|
||||
$type[16] = 'implicit-server-generated-class';
|
||||
$value_parsed -= 65536;
|
||||
}
|
||||
if ($value_parsed %262144 == 131072) {
|
||||
$type[17] = 'network-default-printer';
|
||||
$value_parsed -= 131072;
|
||||
}
|
||||
if ($value_parsed %524288 == 262144) {
|
||||
$type[18] = 'fax-device';
|
||||
$value_parsed -= 262144;
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// {{{ _interpretEnum()
|
||||
protected function _interpretEnum($attribute_name,$value) {
|
||||
|
||||
$value_parsed = self::_interpretInteger($value);
|
||||
|
||||
switch ($attribute_name) {
|
||||
case 'cpi':
|
||||
case 'lpi':
|
||||
$value = $value_parsed;
|
||||
break;
|
||||
default:
|
||||
$value = parent::_interpretEnum($attribute_name,$value);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return $value;
|
||||
}
|
||||
// }}}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* mode: php
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
1441
htdocs/includes/printipp/ExtendedPrintIPP.php
Normal file
1441
htdocs/includes/printipp/ExtendedPrintIPP.php
Normal file
File diff suppressed because it is too large
Load Diff
1889
htdocs/includes/printipp/PrintIPP.php
Normal file
1889
htdocs/includes/printipp/PrintIPP.php
Normal file
File diff suppressed because it is too large
Load Diff
615
htdocs/includes/printipp/http_class.php
Normal file
615
htdocs/includes/printipp/http_class.php
Normal file
@ -0,0 +1,615 @@
|
||||
<?php
|
||||
/* @(#) $Header: /sources/phpprintipp/phpprintipp/php_classes/http_class.php,v 1.7 2010/08/22 15:45:17 harding Exp $ */
|
||||
/* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */
|
||||
/* ====================================================================
|
||||
* GNU Lesser General Public License
|
||||
* Version 2.1, February 1999
|
||||
*
|
||||
* Class http_class - Basic http client with "Basic" and Digest/MD5
|
||||
* authorization mechanism.
|
||||
* handle ipv4/v6 addresses, Unix sockets, http and https
|
||||
* have file streaming capability, to cope with php "memory_limit"
|
||||
*
|
||||
* Copyright (C) 2006,2007,2008 Thomas HARDING
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* $Id: http_class.php,v 1.7 2010/08/22 15:45:17 harding Exp $
|
||||
*/
|
||||
/**
|
||||
* This class is intended to implement a subset of Hyper Text Transfer Protocol
|
||||
* (HTTP/1.1) on client side (currently: POST operation), with file streaming
|
||||
* capability.
|
||||
*
|
||||
* It can perform Basic and Digest authentication.
|
||||
*
|
||||
* References needed to debug / add functionnalities:
|
||||
* - RFC 2616
|
||||
* - RFC 2617
|
||||
*
|
||||
*
|
||||
* Class and Function List:
|
||||
* Function list:
|
||||
* - __construct()
|
||||
* - getErrorFormatted()
|
||||
* - getErrno()
|
||||
* - __construct()
|
||||
* - GetRequestArguments()
|
||||
* - Open()
|
||||
* - SendRequest()
|
||||
* - ReadReplyHeaders()
|
||||
* - ReadReplyBody()
|
||||
* - Close()
|
||||
* - _StreamRequest()
|
||||
* - _ReadReply()
|
||||
* - _ReadStream()
|
||||
* - _BuildDigest()
|
||||
* Classes list:
|
||||
* - httpException extends Exception
|
||||
* - http_class
|
||||
*/
|
||||
/***********************
|
||||
*
|
||||
* httpException class
|
||||
*
|
||||
************************/
|
||||
class httpException extends Exception
|
||||
{
|
||||
protected $errno;
|
||||
public function __construct ($msg, $errno = null)
|
||||
{
|
||||
parent::__construct ($msg);
|
||||
$this->errno = $errno;
|
||||
}
|
||||
public function getErrorFormatted ()
|
||||
{
|
||||
return sprintf ("[http_class]: %s -- "._(" file %s, line %s"),
|
||||
$this->getMessage (), $this->getFile (), $this->getLine ());
|
||||
}
|
||||
public function getErrno ()
|
||||
{
|
||||
return $this->errno;
|
||||
}
|
||||
}
|
||||
|
||||
function error2string($value)
|
||||
{
|
||||
$level_names = array(
|
||||
E_ERROR => 'E_ERROR',
|
||||
E_WARNING => 'E_WARNING',
|
||||
E_PARSE => 'E_PARSE',
|
||||
E_NOTICE => 'E_NOTICE',
|
||||
E_CORE_ERROR => 'E_CORE_ERROR',
|
||||
E_CORE_WARNING => 'E_CORE_WARNING',
|
||||
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
|
||||
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
|
||||
E_USER_ERROR => 'E_USER_ERROR',
|
||||
E_USER_WARNING => 'E_USER_WARNING',
|
||||
E_USER_NOTICE => 'E_USER_NOTICE'
|
||||
);
|
||||
if(defined('E_STRICT')) $level_names[E_STRICT]='E_STRICT';
|
||||
$levels=array();
|
||||
if(($value&E_ALL)==E_ALL)
|
||||
{
|
||||
$levels[]='E_ALL';
|
||||
$value&=~E_ALL;
|
||||
}
|
||||
foreach($level_names as $level=>$name)
|
||||
if(($value&$level)==$level) $levels[]=$name;
|
||||
return implode(' | ',$levels);
|
||||
}
|
||||
|
||||
/***********************
|
||||
*
|
||||
* class http_class
|
||||
*
|
||||
************************/
|
||||
class http_class
|
||||
{
|
||||
// variables declaration
|
||||
public $debug;
|
||||
public $html_debug;
|
||||
public $timeout = 30; // time waiting for connection, seconds
|
||||
public $data_timeout = 30; // time waiting for data, milliseconds
|
||||
public $data_chunk_timeout = 1; // time waiting between data chunks, millisecond
|
||||
public $force_multipart_form_post;
|
||||
public $username;
|
||||
public $password;
|
||||
public $request_headers = array ();
|
||||
public $request_body = "Not a useful information";
|
||||
public $status;
|
||||
public $window_size = 1024; // chunk size of data
|
||||
public $with_exceptions = 0; // compatibility mode for old scripts
|
||||
public $port;
|
||||
public $host;
|
||||
private $default_port = 631;
|
||||
private $headers;
|
||||
private $reply_headers = array ();
|
||||
private $reply_body = array ();
|
||||
private $connection;
|
||||
private $arguments;
|
||||
private $bodystream = array ();
|
||||
private $last_limit;
|
||||
private $connected;
|
||||
private $nc = 1;
|
||||
private $user_agent = "PRINTIPP/0.81+CVS";
|
||||
private $readed_bytes = 0;
|
||||
|
||||
public function __construct ()
|
||||
{
|
||||
true;
|
||||
}
|
||||
|
||||
/*********************
|
||||
*
|
||||
* Public functions
|
||||
*
|
||||
**********************/
|
||||
|
||||
public function GetRequestArguments ($url, &$arguments)
|
||||
{
|
||||
$this->arguments = array ();
|
||||
$arguments["URL"] = $this->arguments["URL"] = $url;
|
||||
$arguments["RequestMethod"] = $this->arguments["RequestMethod"] = "POST";
|
||||
$this->headers["Content-Length"] = 0;
|
||||
$this->headers["Content-Type"] = "application/octet-stream";
|
||||
$this->headers["Host"] = $this->host;
|
||||
$this->headers["User-Agent"] = $this->user_agent;
|
||||
//$this->headers["Expect"] = "100-continue";
|
||||
|
||||
}
|
||||
|
||||
public function Open ($arguments)
|
||||
{
|
||||
$this->connected = false;
|
||||
$url = $arguments["URL"];
|
||||
$port = $this->default_port;
|
||||
#$url = split (':', $url, 2);
|
||||
$url = preg_split ('#:#', $url, 2);
|
||||
$transport_type = $url[0];
|
||||
$unix = false;
|
||||
switch ($transport_type)
|
||||
{
|
||||
case 'http':
|
||||
$transport_type = 'tcp://';
|
||||
break;
|
||||
|
||||
case 'https':
|
||||
$transport_type = 'tls://';
|
||||
break;
|
||||
|
||||
case 'unix':
|
||||
$transport_type = 'unix://';
|
||||
$port = 0;
|
||||
$unix = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
$transport_type = 'tcp://';
|
||||
break;
|
||||
}
|
||||
$url = $url[1];
|
||||
if (!$unix)
|
||||
{
|
||||
#$url = split ("/", preg_replace ("#^/{1,}#", '', $url), 2);
|
||||
$url = preg_split ("#/#", preg_replace ("#^/{1,}#", '', $url), 2);
|
||||
$url = $url[0];
|
||||
$port = $this->port;
|
||||
$error = sprintf (_("Cannot resolve url: %s"), $url);
|
||||
$ip = gethostbyname ($url);
|
||||
$ip = @gethostbyaddr ($ip);
|
||||
if (!$ip)
|
||||
{
|
||||
return $this->_HttpError ($error, E_USER_WARNING);
|
||||
}
|
||||
if (strstr ($url, ":")) // we got an ipv6 address
|
||||
if (!strstr ($url, "[")) // it is not escaped
|
||||
$url = sprintf ("[%s]", $url);
|
||||
}
|
||||
$this->connection = @fsockopen ($transport_type.$url, $port, $errno, $errstr, $this->timeout);
|
||||
$error =
|
||||
sprintf (_('Unable to connect to "%s%s port %s": %s'), $transport_type,
|
||||
$url, $port, $errstr);
|
||||
if (!$this->connection)
|
||||
{
|
||||
return $this->_HttpError ($error, E_USER_WARNING);
|
||||
}
|
||||
$this->connected = true;
|
||||
return array (true, "success");
|
||||
}
|
||||
|
||||
public function SendRequest ($arguments)
|
||||
{
|
||||
$error =
|
||||
sprintf (_('Streaming request failed to %s'), $arguments['RequestURI']);
|
||||
$result = self::_StreamRequest ($arguments);
|
||||
if (!$result[0])
|
||||
{
|
||||
return $this->_HttpError ($error." ".$result[1], E_USER_WARNING);
|
||||
}
|
||||
self::_ReadReply ();
|
||||
if (!preg_match ('#http/1.1 401 unauthorized#', $this->status))
|
||||
{
|
||||
return array (true, "success");
|
||||
}
|
||||
$headers = array_keys ($this->reply_headers);
|
||||
$error = _("need authentication but no mechanism provided");
|
||||
if (!in_array ("www-authenticate", $headers))
|
||||
{
|
||||
return $this->_HttpError ($error, E_USER_WARNING);
|
||||
}
|
||||
#$authtype = split (' ', $this->reply_headers["www-authenticate"]);
|
||||
$authtype = preg_split ('# #', $this->reply_headers["www-authenticate"]);
|
||||
$authtype = strtolower ($authtype[0]);
|
||||
switch ($authtype)
|
||||
{
|
||||
case 'basic':
|
||||
$pass = base64_encode ($this->user.":".$this->password);
|
||||
$arguments["Headers"]["Authorization"] = "Basic ".$pass;
|
||||
break;
|
||||
|
||||
case 'digest':
|
||||
$arguments["Headers"]["Authorization"] = self::_BuildDigest ();
|
||||
break;
|
||||
|
||||
default:
|
||||
$error =
|
||||
sprintf (_("need '%s' authentication mechanism, but have not"),
|
||||
$authtype[0]);
|
||||
return $this->_HttpError ($error, E_USER_WARNING);
|
||||
break;
|
||||
|
||||
}
|
||||
self::Close ();
|
||||
self::Open ($arguments);
|
||||
$error =
|
||||
sprintf (_
|
||||
('Streaming request failed to %s after a try to authenticate'),
|
||||
$url);
|
||||
$result = self::_StreamRequest ($arguments);
|
||||
if (!$result[0])
|
||||
{
|
||||
return $this->_HttpError ($error.": ".$result[1], E_USER_WARNING);
|
||||
}
|
||||
self::_ReadReply ();
|
||||
return array (true, "success");
|
||||
}
|
||||
|
||||
public function ReadReplyHeaders (&$headers)
|
||||
{
|
||||
$headers = $this->reply_headers;
|
||||
}
|
||||
|
||||
public function ReadReplyBody (&$body, $chunk_size)
|
||||
{
|
||||
$body = substr ($this->reply_body, $this->last_limit, $chunk_size);
|
||||
$this->last_limit += $chunk_size;
|
||||
}
|
||||
|
||||
public function Close ()
|
||||
{
|
||||
if (!$this->connected)
|
||||
return;
|
||||
fclose ($this->connection);
|
||||
}
|
||||
|
||||
/*********************
|
||||
*
|
||||
* Private functions
|
||||
*
|
||||
*********************/
|
||||
|
||||
private function _HttpError ($msg, $level, $errno = null)
|
||||
{
|
||||
$trace = '';
|
||||
$backtrace = debug_backtrace;
|
||||
foreach ($backtrace as $trace)
|
||||
{
|
||||
$trace .= sprintf ("in [file: '%s'][function: '%s'][line: %s];\n", $trace['file'], $trace['function'],$trace['line']);
|
||||
}
|
||||
$msg = sprintf ( '%s\n%s: [errno: %s]: %s',
|
||||
$trace, error2string ($level), $errno, $msg);
|
||||
if ($this->with_exceptions)
|
||||
{
|
||||
throw new httpException ($msg, $errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error ($msg, $level);
|
||||
return array (false, $msg);
|
||||
}
|
||||
}
|
||||
|
||||
private function _streamString ($string)
|
||||
{
|
||||
$success = fwrite ($this->connection, $string);
|
||||
if (!$success)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function _StreamRequest ($arguments)
|
||||
{
|
||||
$this->status = false;
|
||||
$this->reply_headers = array ();
|
||||
$this->reply_body = "";
|
||||
if (!$this->connected)
|
||||
{
|
||||
return _HttpError (_("not connected"), E_USER_WARNING);
|
||||
}
|
||||
$this->arguments = $arguments;
|
||||
$content_length = 0;
|
||||
foreach ($this->arguments["BodyStream"] as $argument)
|
||||
{
|
||||
list ($type, $value) = each ($argument);
|
||||
reset ($argument);
|
||||
if ($type == "Data")
|
||||
{
|
||||
$length = strlen ($value);
|
||||
}
|
||||
elseif ($type == "File")
|
||||
{
|
||||
if (is_readable ($value))
|
||||
{
|
||||
$length = filesize ($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$length = 0;
|
||||
return
|
||||
_HttpError (sprintf (_("%s: file is not readable"), $value),
|
||||
E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$length = 0;
|
||||
return
|
||||
_HttpError (sprintf
|
||||
(_("%s: not a valid argument for content"), $type),
|
||||
E_USER_WARNING);
|
||||
}
|
||||
$content_length += $length;
|
||||
}
|
||||
$this->request_body = sprintf (_("%s Bytes"), $content_length);
|
||||
$this->headers["Content-Length"] = $content_length;
|
||||
$this->arguments["Headers"] =
|
||||
array_merge ($this->headers, $this->arguments["Headers"]);
|
||||
if ($this->arguments["RequestMethod"] != "POST")
|
||||
{
|
||||
return
|
||||
_HttpError (sprintf
|
||||
(_("%s: method not implemented"),
|
||||
$arguments["RequestMethod"]), E_USER_WARNING);
|
||||
}
|
||||
$string =
|
||||
sprintf ("POST %s HTTP/1.1\r\n", $this->arguments["RequestURI"]);
|
||||
$this->request_headers[$string] = '';
|
||||
if (!$this->_streamString ($string))
|
||||
{
|
||||
return _HttpError (_("Error while puts POST operation"),
|
||||
E_USER_WARNING);
|
||||
}
|
||||
foreach ($this->arguments["Headers"] as $header => $value)
|
||||
{
|
||||
$string = sprintf ("%s: %s\r\n", $header, $value);
|
||||
$this->request_headers[$header] = $value;
|
||||
if (!$this->_streamString ($string))
|
||||
{
|
||||
return _HttpError (_("Error while puts HTTP headers"),
|
||||
E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
$string = "\r\n";
|
||||
if (!$this->_streamString ($string))
|
||||
{
|
||||
return _HttpError (_("Error while ends HTTP headers"),
|
||||
E_USER_WARNING);
|
||||
}
|
||||
foreach ($this->arguments["BodyStream"] as $argument)
|
||||
{
|
||||
list ($type, $value) = each ($argument);
|
||||
reset ($argument);
|
||||
if ($type == "Data")
|
||||
{
|
||||
$streamed_length = 0;
|
||||
while ($streamed_length < strlen ($value))
|
||||
{
|
||||
$string = substr ($value, $streamed_length, $this->window_size);
|
||||
if (!$this->_streamString ($string))
|
||||
{
|
||||
return _HttpError (_("error while sending body data"),
|
||||
E_USER_WARNING);
|
||||
}
|
||||
$streamed_length += $this->window_size;
|
||||
}
|
||||
}
|
||||
elseif ($type == "File")
|
||||
{
|
||||
if (is_readable ($value))
|
||||
{
|
||||
$file = fopen ($value, 'rb');
|
||||
while (!feof ($file))
|
||||
{
|
||||
if (gettype ($block = @fread ($file, $this->window_size)) !=
|
||||
"string")
|
||||
{
|
||||
return _HttpError (_("cannot read file to upload"),
|
||||
E_USER_WARNING);
|
||||
}
|
||||
if (!$this->_streamString ($block))
|
||||
{
|
||||
return _HttpError (_("error while sending body data"),
|
||||
E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return array (true, "success");
|
||||
}
|
||||
|
||||
private function _ReadReply ()
|
||||
{
|
||||
if (!$this->connected)
|
||||
{
|
||||
return array (false, _("not connected"));
|
||||
}
|
||||
$this->reply_headers = array ();
|
||||
$this->reply_body = "";
|
||||
$headers = array ();
|
||||
$body = "";
|
||||
while (!feof ($this->connection))
|
||||
{
|
||||
$line = fgets ($this->connection, 1024);
|
||||
if (strlen (trim($line)) == 0)
|
||||
break; // \r\n => end of headers
|
||||
if (preg_match ('#^[[:space:]]#', $line))
|
||||
{
|
||||
$headers[-1] .= sprintf(' %s', trim ($line));
|
||||
continue;
|
||||
}
|
||||
$headers[] = trim ($line);
|
||||
}
|
||||
$this->status = isset ($headers[0]) ? strtolower ($headers[0]) : false;
|
||||
foreach ($headers as $header)
|
||||
{
|
||||
$header = preg_split ("#: #", $header);
|
||||
$header[0] = strtolower ($header[0]);
|
||||
if ($header[0] !== "www-authenticate")
|
||||
{
|
||||
$header[1] = isset ($header[1]) ? strtolower ($header[1]) : "";
|
||||
}
|
||||
if (!isset ($this->reply_headers[$header[0]]))
|
||||
{
|
||||
$this->reply_headers[$header[0]] = $header[1];
|
||||
}
|
||||
}
|
||||
self::_ReadStream ();
|
||||
return true;
|
||||
}
|
||||
|
||||
private function _ReadStream ()
|
||||
{
|
||||
if (! array_key_exists ("content-length", $this->reply_headers))
|
||||
{
|
||||
stream_set_blocking($this->connection, 0);
|
||||
$this->reply_body = stream_get_contents($this->connection);
|
||||
return true;
|
||||
}
|
||||
stream_set_blocking($this->connection, 1);
|
||||
$content_length = $this->reply_headers["content-length"];
|
||||
$this->reply_body = stream_get_contents($this->connection,$content_length);
|
||||
return true;
|
||||
}
|
||||
|
||||
private function _BuildDigest ()
|
||||
{
|
||||
$auth = $this->reply_headers["www-authenticate"];
|
||||
#list ($head, $auth) = split (" ", $auth, 2);
|
||||
list ($head, $auth) = preg_split ("# #", $auth, 2);
|
||||
#$auth = split (", ", $auth);
|
||||
$auth = preg_split ("#, #", $auth);
|
||||
foreach ($auth as $sheme)
|
||||
{
|
||||
#list ($sheme, $value) = split ('=', $sheme);
|
||||
list ($sheme, $value) = preg_split ('#=#', $sheme);
|
||||
$fields[$sheme] = trim (trim ($value), '"');
|
||||
}
|
||||
$nc = sprintf ('%x', $this->nc);
|
||||
$prepend = "";
|
||||
while ((strlen ($nc) + strlen ($prepend)) < 8)
|
||||
$prependi .= "0";
|
||||
$nc = $prepend.$nc;
|
||||
$cnonce = "printipp";
|
||||
$username = $this->user;
|
||||
$password = $this->password;
|
||||
$A1 = $username.":".$fields["realm"].":".$password;
|
||||
if (array_key_exists ("algorithm", $fields))
|
||||
{
|
||||
$algorithm = strtolower ($fields["algorithm"]);
|
||||
switch ($algorithm)
|
||||
{
|
||||
case "md5":
|
||||
break;
|
||||
|
||||
case "md5-sess":
|
||||
$A1 =
|
||||
$username.":".$fields["realm"].":".$password.":".
|
||||
$fields['nonce'].":".$cnonce;
|
||||
break;
|
||||
|
||||
default:
|
||||
return _HttpError(
|
||||
sprintf (_("digest Authorization: algorithm '%s' not implemented"),
|
||||
$algorithm),
|
||||
E_USER_WARNING);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$A2 = "POST:".$this->arguments["RequestURI"];
|
||||
if (array_key_exists ("qop", $fields))
|
||||
{
|
||||
$qop = strtolower ($fields["qop"]);
|
||||
#$qop = split (" ", $qop);
|
||||
$qop = preg_split ("# #", $qop);
|
||||
if (in_array ("auth", $qop))
|
||||
$qop = "auth";
|
||||
else
|
||||
{
|
||||
self::_HttpError(
|
||||
sprintf (_("digest Authorization: algorithm '%s' not implemented"),
|
||||
$qop),
|
||||
E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$response = md5 (md5 ($A1).":".$fields["nonce"].":".md5 ($A2));
|
||||
if (isset ($qop) && ($qop == "auth"))
|
||||
{
|
||||
$response =
|
||||
md5 (md5 ($A1).":".$fields["nonce"].":".$nc.":".$cnonce.":".$qop.
|
||||
":".$A2);
|
||||
}
|
||||
$auth_scheme =
|
||||
sprintf
|
||||
('Digest username="%s", realm="%s", nonce="%s", uri="%s", response="%s"',
|
||||
$username, $fields["realm"], $fields['nonce'],
|
||||
$this->arguments["RequestURI"], $response);
|
||||
if (isset ($algorithm))
|
||||
$auth_scheme .= sprintf (', algorithm="%s"', $algorithm);
|
||||
if (isset ($qop))
|
||||
$auth_scheme .= sprintf (', cnonce="%s"', $cnonce);
|
||||
if (array_key_exists ("opaque", $fields))
|
||||
$auth_scheme .= sprintf (', opaque="%s"', $fields['opaque']);
|
||||
if (isset ($qop))
|
||||
$auth_scheme .= sprintf (', qop="%s"', $qop);
|
||||
$auth_scheme .= sprintf (', nc=%s', $nc);
|
||||
$this->nc++;
|
||||
return $auth_scheme;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* mode: php
|
||||
* tab-width: 2
|
||||
* c-basic-offset: 2
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
159
htdocs/printipp/admin/printipp.php
Normal file
159
htdocs/printipp/admin/printipp.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/printipp/admin/printipp.php
|
||||
* \ingroup core
|
||||
* \brief Page to setup printipp module
|
||||
*/
|
||||
|
||||
require '../../main.inc.php';
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/printipp/lib/printipp.lib.php';
|
||||
|
||||
$langs->load("admin");
|
||||
$langs->load("printipp");
|
||||
|
||||
if (! $user->admin) accessforbidden();
|
||||
|
||||
$action = GETPOST('action','alpha');
|
||||
$mode = GETPOST('mode','alpha');
|
||||
|
||||
if (!$mode) $mode='config';
|
||||
|
||||
/*
|
||||
* Action
|
||||
*/
|
||||
if ($action == 'setvalue' && $user->admin)
|
||||
{
|
||||
$db->begin();
|
||||
$result=dolibarr_set_const($db, "PRINTIPP_HOST",GETPOST('PRINTIPP_HOST','alpha'),'chaine',0,'',$conf->entity);
|
||||
if (! $result > 0) $error++;
|
||||
$result=dolibarr_set_const($db, "PRINTIPP_PORT",GETPOST('PRINTIPP_PORT','alpha'),'chaine',0,'',$conf->entity);
|
||||
if (! $result > 0) $error++;
|
||||
$result=dolibarr_set_const($db, "PRINTIPP_USER",GETPOST('PRINTIPP_USER','alpha'),'chaine',0,'',$conf->entity);
|
||||
if (! $result > 0) $error++;
|
||||
$result=dolibarr_set_const($db, "PRINTIPP_PASSWORD",GETPOST('PRINTIPP_PASSWORD','alpha'),'chaine',0,'',$conf->entity);
|
||||
if (! $result > 0) $error++;
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->commit();
|
||||
setEventMessage($langs->trans("SetupSaved"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
llxHeader('',$langs->trans("PrintIPPSetup"));
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print_fiche_titre($langs->trans("PrintIPPSetup"),$linkback,'setup');
|
||||
|
||||
$head=printippadmin_prepare_head();
|
||||
|
||||
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"));
|
||||
|
||||
print $langs->trans("PrintIPPDesc")."<br>\n";
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
if ($mode=='config'&& $user->admin)
|
||||
{
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=config">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="setvalue">';
|
||||
|
||||
|
||||
print '<table class="nobordernopadding" width="100%">';
|
||||
|
||||
$var=true;
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("AccountParameter").'</td>';
|
||||
print '<td>'.$langs->trans("Value").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td class="fieldrequired">';
|
||||
print $langs->trans("PRINTIPP_HOST").'</td><td>';
|
||||
print '<input size="64" type="text" name="PRINTIPP_HOST" value="'.$conf->global->PRINTIPP_HOST.'">';
|
||||
print ' '.$langs->trans("Example").': localhost';
|
||||
print '</td></tr>';
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td class="fieldrequired">';
|
||||
print $langs->trans("PRINTIPP_PORT").'</td><td>';
|
||||
print '<input size="32" type="text" name="PRINTIPP_PORT" value="'.$conf->global->PRINTIPP_PORT.'">';
|
||||
print ' '.$langs->trans("Example").': 631';
|
||||
print '</td></tr>';
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td class="fieldrequired">';
|
||||
print $langs->trans("PRINTIPP_USER").'</td><td>';
|
||||
print '<input size="32" type="text" name="PRINTIPP_USER" value="'.$conf->global->PRINTIPP_USER.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td class="fieldrequired">';
|
||||
print $langs->trans("PRINTIPP_PASSWORD").'</td><td>';
|
||||
print '<input size="32" type="text" name="PRINTIPP_PASSWORD" value="'.$conf->global->PRINTIPP_PASSWORD.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
//$var=true;
|
||||
//print '<tr class="liste_titre">';
|
||||
//print '<td>'.$langs->trans("OtherParameter").'</td>';
|
||||
//print '<td>'.$langs->trans("Value").'</td>';
|
||||
//print "</tr>\n";
|
||||
|
||||
print '<tr><td colspan="2" align="center"><br><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
if ($mode=='test'&& $user->admin)
|
||||
{
|
||||
print '<table class="nobordernopadding" width="100%">';
|
||||
$printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD);
|
||||
$var=true;
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("TestConnect").'</td>';
|
||||
print print_r($printer->getlist_available_printers(),true);
|
||||
print "</tr>\n";
|
||||
print '</table>';
|
||||
}
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
?>
|
||||
36
htdocs/printipp/index.php
Normal file
36
htdocs/printipp/index.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/printipp/index.php
|
||||
\ingroup printipp
|
||||
\brief Printipp
|
||||
*/
|
||||
|
||||
require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php';
|
||||
|
||||
llxHeader("",$langs->trans("Printer"));
|
||||
|
||||
print_fiche_titre($langs->trans("Printer"));
|
||||
|
||||
$printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD);
|
||||
$printer->list_jobs('commande');
|
||||
|
||||
llxFooter();
|
||||
|
||||
?>
|
||||
61
htdocs/printipp/lib/printipp.lib.php
Normal file
61
htdocs/printipp/lib/printipp.lib.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/printipp/lib/printipp.lib.php
|
||||
* \ingroup printipp
|
||||
* \brief Library for printipp functions
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Define head array for tabs of printipp tools setup pages
|
||||
*
|
||||
* @return Array of head
|
||||
*/
|
||||
function printippadmin_prepare_head()
|
||||
{
|
||||
global $langs, $conf;
|
||||
|
||||
$h = 0;
|
||||
$head = array();
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT."/printipp/admin/printipp.php?mode=config";
|
||||
$head[$h][1] = $langs->trans("Config");
|
||||
$head[$h][2] = 'config';
|
||||
$h++;
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT."/printipp/admin/printipp.php?mode=test";
|
||||
$head[$h][1] = $langs->trans("Test");
|
||||
$head[$h][2] = 'test';
|
||||
$h++;
|
||||
|
||||
$object=new stdClass();
|
||||
|
||||
// Show more tabs from modules
|
||||
// Entries must be declared in modules descriptor with line
|
||||
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
|
||||
// $this->tabs = array('entity:-tabname); to remove a tab
|
||||
complete_head_from_modules($conf,$langs,$object,$head,$h,'printippadmin');
|
||||
|
||||
complete_head_from_modules($conf,$langs,$object,$head,$h,'printipp','remove');
|
||||
|
||||
return $head;
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user