WIP Printing System

This commit is contained in:
frederic34 2014-12-08 20:33:26 +01:00
parent 5cce8c45e3
commit be60c13de6
21 changed files with 965 additions and 600 deletions

View File

@ -236,6 +236,18 @@ source_file = htdocs/langs/en_US/paypal.lang
source_lang = en_US source_lang = en_US
type = MOZILLAPROPERTIES type = MOZILLAPROPERTIES
[dolibarr.printgcp]
file_filter = htdocs/langs/<lang>/printgcp.lang
source_file = htdocs/langs/en_US/printgcp.lang
source_lang = en_US
type = MOZILLAPROPERTIES
[dolibarr.printing]
file_filter = htdocs/langs/<lang>/printing.lang
source_file = htdocs/langs/en_US/printing.lang
source_lang = en_US
type = MOZILLAPROPERTIES
[dolibarr.printipp] [dolibarr.printipp]
file_filter = htdocs/langs/<lang>/printipp.lang file_filter = htdocs/langs/<lang>/printipp.lang
source_file = htdocs/langs/en_US/printipp.lang source_file = htdocs/langs/en_US/printipp.lang

View File

@ -31,28 +31,34 @@
if ($action == 'print_file' and $user->rights->printing->read) if ($action == 'print_file' and $user->rights->printing->read)
{ {
$langs->load("printing"); $langs->load("printing");
//require_once DOL_DOCUMENT_ROOT . '/core/class/dolprintipp.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/modules/printing/modules_printing.php';
//$printer = new dolPrintIPP($db, $conf->global->PRINTIPP_HOST, $conf->global->PRINTIPP_PORT, $user->login, $conf->global->PRINTIPP_USER, $conf->global->PRINTIPP_PASSWORD); $objectprint = new PrintingDriver($db);
//$result = $printer->print_file(GETPOST('file', 'alpha'), GETPOST('printer', 'alpha')); $list = $objectprint->listDrivers($db, 10);
// Call trigger to Print Doc if (! empty($list)) {
//$actiontypecode='AC_PRINT'; $errorprint=0;
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $printed=0;
$interface=new Interfaces($db); foreach ($list as $driver) {
$trigger_name='PRINT_DOCPDF'; require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
$printing->file = GETPOST('file', 'alpha'); $langs->load($driver);
$printing->printer = GETPOST('printer', 'alpha'); $classname = 'printing_'.$driver;
//print print_r($printing, true); $printer = new $classname($db);
//print '<pre>'.print_r($printer, true).'</pre>';
$result=$interface->run_triggers($trigger_name,$printing,$user,$langs,$conf); if (! empty($conf->global->{$printer->active})) {
if ($result < 0) { $subdir=(GETPOST('printer', 'alpha')=='expedition'?'sending':'');
setEventMessage($interface->errors, 'errors'); $errorprint = $printer->print_file(GETPOST('file', 'alpha'), GETPOST('printer', 'alpha'), $subdir);
} //if ($errorprint < 0) {
if ($result == 0) { // setEventMessage($interface->errors, 'errors');
setEventMessage($langs->trans("NoModuleFound")); //}
} if ($errorprint=='') {
setEventMessage($langs->trans("FileWasSentToPrinter", basename(GETPOST('file'))).' '.$langs->trans("ViaModule").' '.$printer->name);
if ($result>0) { $printed++;
setEventMessage($langs->trans("FileWasSentToPrinter", basename(GETPOST('file')))); }
}
}
if ($printed==0) setEventMessage($langs->trans("NoActivePrintingModuleFound"));
} else {
setEventMessage($langs->trans("NoModuleFound"), 'warning');
} }
$action = ''; $action = '';
} }

View File

@ -272,7 +272,7 @@ class FormFile
} }
$printer=0; $printer=0;
if (in_array($modulepart,array('facture','propal','proposal','order','commande'))) // This feature is implemented only for such elements if (in_array($modulepart,array('facture','propal','proposal','order','commande','expedition'))) // This feature is implemented only for such elements
{ {
$printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false; $printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false;
} }
@ -603,8 +603,8 @@ class FormFile
$out.= '<td align="right">'; $out.= '<td align="right">';
if ($delallowed) if ($delallowed)
{ {
$out.= '<a href="'.$urlsource.(strpos($urlsource,'?')?'&':'?').'action=remove_file&file='.urlencode($relativepath); $out.= '<a href="'.$urlsource.(strpos($urlsource,'?')?'&amp;':'?').'action=remove_file&amp;file='.urlencode($relativepath);
$out.= ($param?'&'.$param:''); $out.= ($param?'&amp;'.$param:'');
//$out.= '&modulepart='.$modulepart; // TODO obsolete ? //$out.= '&modulepart='.$modulepart; // TODO obsolete ?
//$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ? //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ?
$out.= '">'.img_picto($langs->trans("Delete"), 'delete.png').'</a>'; $out.= '">'.img_picto($langs->trans("Delete"), 'delete.png').'</a>';
@ -613,8 +613,8 @@ class FormFile
if ($printer) if ($printer)
{ {
//$out.= '<td align="right">'; //$out.= '<td align="right">';
$out.= '&nbsp;<a href="'.$urlsource.(strpos($urlsource,'?')?'&':'?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath); $out.= '&nbsp;<a href="'.$urlsource.(strpos($urlsource,'?')?'&amp;':'?').'action=print_file&amp;printer='.$modulepart.'&amp;file='.urlencode($relativepath);
$out.= ($param?'&'.$param:''); $out.= ($param?'&amp;'.$param:'');
$out.= '">'.img_picto($langs->trans("Print"),'printer.png').'</a>'; $out.= '">'.img_picto($langs->trans("Print"),'printer.png').'</a>';
} }
if ($morepicto) if ($morepicto)

View File

@ -1,156 +0,0 @@
<?php
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014 Frederic France <frederic.france@free.fr>
*
* 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 PrintIPP
*/
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
{
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
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 = 'dolibarr'; // '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->hidden = (! empty($_SERVER["WINDIR"]));
$this->depends = array('printing');
$this->requiredby = array();
$this->phpmin = array(5,1); // Minimum version of PHP required by module
$this->need_dolibarr_version = array(3,7,-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] = 'read';
// 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,fk_leftmenu=modulesadmintools', // 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'=>300,
'enabled'=>'$conf->printipp->enabled && $leftmenu==\'modulesadmintools\'',
'perms'=>'$user->rights->printipp->read', // 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++;
}
/**
* Function called when module is enabled.
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
* It also creates data directories
*
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
function init($options='')
{
$sql = array();
return $this->_init($sql, $options);
}
/**
* Function called when module is disabled.
* Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted
*
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
function remove($options='')
{
$sql = array();
return $this->_remove($sql, $options);
}
}

View File

@ -67,7 +67,6 @@ class modPrinting extends DolibarrModules
$this->config_page_url = array("printing.php@printing"); $this->config_page_url = array("printing.php@printing");
// Dependances // Dependances
$this->hidden = (! empty($_SERVER["WINDIR"]));
$this->depends = array(); $this->depends = array();
$this->requiredby = array(); $this->requiredby = array();
$this->phpmin = array(5,1); // Minimum version of PHP required by module $this->phpmin = array(5,1); // Minimum version of PHP required by module
@ -132,6 +131,7 @@ class modPrinting extends DolibarrModules
*/ */
function init($options='') function init($options='')
{ {
// insertion modele dans llx_document_model
$sql = array(); $sql = array();
return $this->_init($sql, $options); return $this->_init($sql, $options);
@ -142,11 +142,12 @@ class modPrinting extends DolibarrModules
* Remove from database constants, boxes and permissions from Dolibarr database. * Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted * Data directories are not deleted
* *
* @param string $options Options when enabling module ('', 'noboxes') * @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO * @return int 1 if OK, 0 if KO
*/ */
function remove($options='') function remove($options='')
{ {
// suppression des modeles "printing"
$sql = array(); $sql = array();
return $this->_remove($sql, $options); return $this->_remove($sql, $options);

View File

@ -0,0 +1,86 @@
<?php
/*
* Copyright (C) 2014 Frederic France <frederic.france@free.fr>
*
* 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/mailings/modules_printing.php
* \ingroup printing
* \brief File with parent class of printing modules
*/
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
/**
* Parent class of emailing target selectors modules
*/
class PrintingDriver
{
var $db;
var $error;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $db;
}
/**
* Return list of printing driver
*
* @param DoliDB $db Database handler
* @param string $maxfilenamelength Max length of value to show
* @return array List of drivers
*/
static function listDrivers($db,$maxfilenamelength=0)
{
global $conf;
$type='printing';
$liste=array();
$moduledir=DOL_DOCUMENT_ROOT."/core/modules/printing/";
$tmpfiles=dol_dir_list($moduledir,'all',0,'\modules.php','','name',SORT_ASC,0);
foreach($tmpfiles as $record) {
$list[$record['fullname']]=str_replace('.modules.php', '',$record['name']);
}
return $list;
}
/**
* Return description of Printing Module
*
* @return string Return translation of key PrintingModuleDescXXX where XXX is module name, or $this->desc if not exists
*/
function getDesc()
{
global $langs;
$langs->load("printing");
$transstring="PrintingModuleDesc".$this->name;
if ($langs->trans($transstring) != $transstring) return $langs->trans($transstring);
else return $this->desc;
}
}

View File

@ -0,0 +1,331 @@
<?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/printgcp.modules.php
* \ingroup printing
* \brief File to provide printing with Google Cloud Print
*/
include_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
/**
* \class mailing_example
* \brief Class to provide printing with Google Cloud Print
*/
class printing_printgcp extends PrintingDriver
{
var $name = 'printgcp';
var $desc = 'PrintGCPDesc';
var $picto = 'printer';
var $active = 'PRINTING_PRINTGCP';
var $conf = array();
var $login = '';
var $password = '';
var $authtoken = '';
var $db;
const LOGIN_URL = 'https://www.google.com/accounts/ClientLogin';
const PRINTERS_SEARCH_URL = 'https://www.google.com/cloudprint/interface/search';
const PRINT_URL = 'https://www.google.com/cloudprint/interface/submit';
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
global $conf;
$this->db = $db;
$this->login = $conf->global->PRINTGCP_LOGIN;
$this->password = $conf->global->PRINTGCP_PASSWORD;
$this->authtoken = $conf->global->PRINTGCP_AUTHTOKEN;
$this->conf[] = array('varname'=>'PRINTGCP_LOGIN', 'required'=>1, 'example'=>'user@gmail.com', 'type'=>'text');
$this->conf[] = array('varname'=>'PRINTGCP_PASSWORD', 'required'=>1, 'example'=>'', 'type'=>'password');
}
/**
* Return list of available printers
*
* @return string html list of printers
*/
function listAvailablePrinters()
{
global $bc, $conf, $langs;
$langs->load('printgcp');
$var=true;
$html = '<table width="100%" class="noborder">';
$html.= '<tr class="liste_titre">';
$html.= '<td>Name</td>';
$html.= '<td>displayName</td>';
$html.= '<td>Id</td>';
$html.= '<td>OwnerName</td>';
$html.= '<td>State</td>';
$html.= '<td>connectionStatus</td>';
$html.= '<td>Type</td>';
$html.= '<td align="center">'.$langs->trans("Select").'</td>';
$html.= '</tr>'."\n";
$list = $this->getlist_available_printers();
//$html.= '<td><pre>'.print_r($list,true).'</pre></td>';
$var = true;
foreach ($list['available'] as $printer_det)
{
$var=!$var;
$html.= "<tr ".$bc[$var].">";
$html.= '<td>'.$printer_det['name'].'</td>';
$html.= '<td>'.$printer_det['displayName'].'</td>';
$html.= '<td>'.$printer_det['id'].'</td>'; // id to identify printer to use
$html.= '<td>'.$printer_det['ownerName'].'</td>';
$html.= '<td>'.$printer_det['status'].'</td>';
$html.= '<td>'.$langs->trans('STATE_'.$printer_det['connectionStatus']).'</td>';
$html.= '<td>'.$langs->trans('TYPE_'.$printer_det['type']).'</td>';
// Defaut
$html.= '<td align="center">';
if ($conf->global->PRINTING_GCP_DEFAULT == $printer_det['id'])
{
$html.= img_picto($langs->trans("Default"),'on');
}
else
$html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&amp;mode=test&amp;varname=PRINTING_GCP_DEFAULT&amp;driver=printgcp&amp;value='.urlencode($printer_det['id']).'" 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;
if ($this->authtoken=='') {
$this->GoogleLogin();
}
$ret['available'] = $this->get_printer_detail();
return $ret;
}
/**
* List of printers
*
* @return array list of printers
*/
public function get_printer_detail()
{
// Check if we have auth token
if(empty($this->authtoken)) {
// We don't have auth token so throw exception
throw new Exception("Please first login to Google by calling loginToGoogle function");
}
// Prepare auth headers with auth token
$authheaders = array("Authorization: GoogleLogin auth=".$this->authtoken,
"GData-Version: 3.0",
);
// Make Http call to get printers added by user to Google Cloud Print
$responsedata = $this->makeCurl(self::PRINTERS_SEARCH_URL,array(),$authheaders);
$printers = json_decode($responsedata);
// Check if we have printers?
if(is_null($printers)) {
// We dont have printers so return blank array
return array();
} else {
// We have printers so returns printers as array
return $this->parsePrinters($printers);
}
}
/**
* Print selected file
*
* @param string $file file
* @param string $module module
*
* @return string '' if OK, Error message if KO
*/
public function print_file($file, $module, $subdir='')
{
global $conf;
if ($this->authtoken=='') {
$this->GoogleLogin();
}
// si $module=commande_fournisseur alors $conf->fournisseur->commande->dir_output
$fileprint=$conf->{$module}->dir_output;
if ($subdir!='') $fileprint.='/'.$subdir;
$fileprint.='/'.$file;
$this->sendPrintToPrinter($conf->global->PRINTING_GCP_DEFAULT, $file, $fileprint, 'application/pdf');
}
/**
* Sends document to the printer
*
* @param string $printerid Printer id returned by Google Cloud Print
* @param string $printjobtitle Job Title
* @param string $filepath File Path to be send to Google Cloud Print
* @param string $contenttype File content type by example application/pdf, image/png
* @return array status array
*/
public function sendPrintToPrinter($printerid,$printjobtitle,$filepath,$contenttype)
{
$errors=0;
// Check auth token
if(empty($this->authtoken)) {
$errors++;
setEventMessage('Please first login to Google', 'warning');
}
// Check if printer id
if(empty($printerid)) {
$errors++;
setEventMessage('No provided printer ID', 'warning');
}
// Open the file which needs to be print
$handle = fopen($filepath, "rb");
if(!$handle) {
$errors++;
setEventMessage('Could not read the file.');
}
// Read file content
$contents = fread($handle, filesize($filepath));
fclose($handle);
// Prepare post fields for sending print
$post_fields = array('printerid' => $printerid,
'title' => $printjobtitle,
'contentTransferEncoding' => 'base64',
'content' => base64_encode($contents), // encode file content as base64
'contentType' => $contenttype
);
// Prepare authorization headers
$authheaders = array("Authorization: GoogleLogin auth=" . $this->authtoken);
// Make http call for sending print Job
$response = json_decode($this->makeCurl(self::PRINT_URL,$post_fields,$authheaders));
// Has document been successfully sent?
if($response->success=="1") {
return array('status' =>true,'errorcode' =>'','errormessage'=>"");
} else {
return array('status' =>false,'errorcode' =>$response->errorCode,'errormessage'=>$response->message);
}
}
/**
* Login into Google Account
*
* @return string true or false
*/
function GoogleLogin()
{
global $db, $conf;
// Prepare post fields required for the login
$loginpostfields = array("accountType" => "HOSTED_OR_GOOGLE",
"Email" => $this->login,
"Passwd" => $this->password,
"service" => "cloudprint",
"source" => "GCP"
);
// Get the Auth token
$loginresponse = $this->makeCurl(self::LOGIN_URL,$loginpostfields);
$token = $this->getAuthToken($loginresponse);
if(! empty($token)&&!is_null($token)) {
$this->authtoken = $token;
$result=dolibarr_set_const($db, 'PRINTGCP_AUTHTOKEN', $token, 'chaine', 0, '', $conf->entity);
return true;
} else {
return false;
}
}
/**
*
* Parse json response and return printers array
* @param string $jsonobj Json response object
* @return array return array of printers
*/
private function parsePrinters($jsonobj)
{
$printers = array();
if (isset($jsonobj->printers)) {
foreach ($jsonobj->printers as $gcpprinter) {
$printers[] = array('id' =>$gcpprinter->id,
'name' =>$gcpprinter->name,
'defaultDisplayName' =>$gcpprinter->defaultDisplayName,
'displayName' =>$gcpprinter->displayName,
'ownerId' =>$gcpprinter->ownerId,
'ownerName' =>$gcpprinter->ownerName,
'connectionStatus' =>$gcpprinter->connectionStatus,
'status' =>$gcpprinter->status,
'type' =>$gcpprinter->type
);
}
}
return $printers;
}
/**
* Parse data to get auth token
*
* @param string $response response from curl
* @return string token
*/
private function getAuthToken($response)
{
// Search Auth tag
preg_match("/Auth=([a-z0-9_-]+)/i", $response, $matches);
$authtoken = @$matches[1];
return $authtoken;
}
/**
* Curl request
*
* @param string $url url to hit
* @param array $postfields array of post fields
* @param array $headers array of http headers
* @return
*/
private function makeCurl($url,$postfields=array(),$headers=array())
{
// Curl Init
$curl = curl_init($url);
// Curl post request
if(! empty($postfields)) {
// As is HTTP post curl request so set post fields
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
}
// Curl request headers
if(! empty($headers)) {
// As curl requires header so set headers here
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Execute the curl and return response
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
}

View File

@ -0,0 +1,282 @@
<?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>Uri</td>';
$html.= '<td>Name</td>';
$html.= '<td>State</td>';
$html.= '<td>State_reason</td>';
$html.= '<td>State_reason1</td>';
$html.= '<td>BW</td>';
$html.= '<td>Color</td>';
//$html.= '<td>Device</td>';
$html.= '<td>Media</td>';
$html.= '<td>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>'.$printer_det->printer_state->_value0.'</td>';
$html.= '<td>'.$printer_det->printer_state_reasons->_value0.'</td>';
$html.= '<td>'.$printer_det->printer_state_reasons->_value1.'</td>';
$html.= '<td>'.$printer_det->printer_type->_value2.'</td>';
$html.= '<td>'.$printer_det->printer_type->_value3.'</td>';
//$html.= '<td>'.$printer_det->device_uri->_value0.'</td>';
$html.= '<td>'.$printer_det->media_default->_value0.'</td>';
$html.= '<td>'.$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&amp;mode=test&amp;varname=PRINTIPP_URI_DEFAULT&amp;driver=printipp&amp;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>";
}
}

View File

@ -1,71 +0,0 @@
<?php
/* Copyright (C) 2005-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
*
* 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/core/triggers/interface_60_modPrinting_Printing.class.php
* \ingroup printing
* \brief Trigger call by printing to print with PrintIPP
* \remarks
*/
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
/**
* Class of triggers for printing
*/
class InterfacePrinting extends DolibarrTriggers
{
public $family = 'printing';
public $picto = 'technic';
public $description = "Triggers of this module is used for printing via PrintIPP.";
public $version = self::VERSION_DOLIBARR;
/**
* Function called when a Dolibarrr business event is done.
* All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
*
* @param string $action Event action code
* @param Object $object Object
* @param User $user Object user
* @param Translate $langs Object langs
* @param conf $conf Object conf
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
*/
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
{
global $db;
// Put here code you want to execute when a Dolibarr business events occurs.
// Data and type of action are stored into $object and $action
// Actions
if ($action=='PRINT_DOCPDF') {
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);
$result = $printer->print_file($object->file, $object->printer);
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
//$this->errors[]='test';
//return -1;
return 1;
}
return 0;
}
}

View File

@ -414,6 +414,8 @@ if (GETPOST('removedfile','alpha'))
$action ='presend'; $action ='presend';
} }
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
/* /*
* Send mail * Send mail
*/ */

View File

@ -26,4 +26,19 @@ create table llx_c_price_expression
expression varchar(80) NOT NULL expression varchar(80) NOT NULL
)ENGINE=innodb; )ENGINE=innodb;
--create table for user conf of printing driver
CREATE TABLE llx_printing
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp,
datec datetime,
printer_name text NOT NULL,
printer_location text NOT NULL,
printer_id varchar(255) NOT NULL,
copy integer NOT NULL DEFAULT '1',
module varchar(16) NOT NULL,
driver varchar(16) NOT NULL,
userid integer
)ENGINE=innodb;
ALTER TABLE llx_product_fournisseur_price ADD fk_price_expression integer DEFAULT NULL; ALTER TABLE llx_product_fournisseur_price ADD fk_price_expression integer DEFAULT NULL;

View File

@ -1,5 +1,5 @@
-- ============================================================================ -- ============================================================================
-- Copyright (C) 2013 Florian HENRY <florian.henry@open-concept.pro> -- Copyright (C) 2014 Frederic France <frederic.france@free.fr>
-- --
-- This program is free software; you can redistribute it and/or modify -- 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 -- it under the terms of the GNU General Public License as published by
@ -16,15 +16,16 @@
-- --
-- ============================================================================ -- ============================================================================
CREATE TABLE llx_printer_ipp CREATE TABLE llx_printing
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp, tms timestamp,
datec datetime, datec datetime,
printer_name text NOT NULL, printer_name text NOT NULL,
printer_location text NOT NULL, printer_location text NOT NULL,
printer_uri varchar(255) NOT NULL, printer_id varchar(255) NOT NULL,
copy integer NOT NULL DEFAULT '1', copy integer NOT NULL DEFAULT '1',
module varchar(16) NOT NULL, module varchar(16) NOT NULL,
login varchar(32) NOT NULL driver varchar(16) NOT NULL,
userid integer
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -0,0 +1,18 @@
# Dolibarr language file - Source file is en_US - printgccp
PRINTGCP=Google Cloud Print
PrintGCPDesc=This driver allow to send documents directly to a printer with Google Cloud Print.
PrintingDriverDescprintgcp=Configuration variables for printing driver Google Cloud Print.
PrintTestDescprintgcp=List of Printers for Google Cloud Print.
PRINTGCP_LOGIN=Google Account Login
PRINTGCP_PASSWORD=Google Account Password
STATE_ONLINE=Online
STATE_UNKNOWN=Unknown
STATE_OFFLINE=Offline
STATE_DORMANT=Offline for quite a while
TYPE_GOOGLE=Google
TYPE_HP=HP Printer
TYPE_DOCS=DOCS
TYPE_DRIVE=Google Drive
TYPE_FEDEX=Fedex
TYPE_ANDROID_CHROME_SNAPSHOT=Android
TYPE_IOS_CHROME_SNAPSHOT=IOS

View File

@ -0,0 +1,10 @@
# Dolibarr language file - Source file is en_US - printing
PrintingSetup=Setup of Printing System
PrintingDesc=This module adds a Print button to send documents directly to a printer with various module.
ModuleDriverSetup=Setup Module Driver
PrintingDriverDesc=Configuration variables for printing driver.
ListDrivers=List of drivers
PrintTestDesc=List of Printers.
FileWasSentToPrinter=File %s was sent to printer
NoActivePrintingModuleFound=No active module to print document
PleaseSelectaDriverfromList=Please select a driver from list.

View File

@ -1,6 +1,9 @@
# Dolibarr language file - Source file is en_US - printipp # Dolibarr language file - Source file is en_US - printipp
PRINTIPP=PrintIPP Driver
PrintIPPSetup=Setup of Direct Print module PrintIPPSetup=Setup of Direct Print module
PrintIPPDesc=This module adds a Print button to send documents directly to a printer. It requires a Linux system with CUPS installed. PrintIPPDesc=This driver allow to send documents directly to a printer. It requires a Linux system with CUPS installed.
PrintingDriverDescprintipp=Configuration variables for printing driver PrintIPP.
PrintTestDescprintipp=List of Printers for driver PrintIPP.
PRINTIPP_ENABLED=Show "Direct print" icon in document lists PRINTIPP_ENABLED=Show "Direct print" icon in document lists
PRINTIPP_HOST=Print server PRINTIPP_HOST=Print server
PRINTIPP_PORT=Port PRINTIPP_PORT=Port

View File

@ -26,8 +26,8 @@ require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.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/doleditor.class.php';
//require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
//require_once DOL_DOCUMENT_ROOT.'/printing/lib/printing.lib.php'; require_once DOL_DOCUMENT_ROOT.'/printing/lib/printing.lib.php';
$langs->load("admin"); $langs->load("admin");
$langs->load("printing"); $langs->load("printing");
@ -37,14 +37,58 @@ if (! $user->admin) accessforbidden();
$action = GETPOST('action','alpha'); $action = GETPOST('action','alpha');
$mode = GETPOST('mode','alpha'); $mode = GETPOST('mode','alpha');
$value = GETPOST('value','alpha'); $value = GETPOST('value','alpha');
$varname = GETPOST('varname', 'alpha');
$driver = GETPOST('driver', 'alpha');
if (! empty($driver)) $langs->load($driver);
if (!$mode) $mode='config'; if (!$mode) $mode='config';
/* /*
* Action * Action
*/ */
if ($action == 'setconst' && $user->admin)
{
$error=0;
$db->begin();
foreach ($_POST['setupdriver'] as $setupconst) {
//print '<pre>'.print_r($setupconst, true).'</pre>';
$result=dolibarr_set_const($db, $setupconst['varname'],$setupconst['value'],'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
}
if (! $error)
{
$db->commit();
setEventMessage($langs->trans("SetupSaved"));
}
else
{
$db->rollback();
dol_print_error($db);
}
$action='';
}
if ($action == 'setvalue' && $user->admin)
{
$db->begin();
$result=dolibarr_set_const($db, $varname, $value,'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
if (! $error)
{
$db->commit();
setEventMessage($langs->trans("SetupSaved"));
}
else
{
$db->rollback();
dol_print_error($db);
}
$action = '';
}
/* /*
* View * View
@ -55,73 +99,131 @@ $form = new Form($db);
llxHeader('',$langs->trans("PrintingSetup")); llxHeader('',$langs->trans("PrintingSetup"));
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>'; $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("PrintIPPSetup"),$linkback,'setup'); print_fiche_titre($langs->trans("PrintingSetup"),$linkback,'setup');
//$head=printippadmin_prepare_head(); $head=printingadmin_prepare_head();
if ($mode == 'setup' && $user->admin)
{
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setconst">';
dol_fiche_head($head, $mode, $langs->trans("ModuleDriverSetup"), 0, 'technic');
print $langs->trans("PrintingDriverDesc".$driver)."<br><br>\n";
print '<table class="noborder" width="100%">'."\n";
$var=true;
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Parameters").'</th>';
print '<th>'.$langs->trans("Value").'</th>';
print "</tr>\n";
if (! empty($driver)) {
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
$classname = 'printing_'.$driver;
$printer = new $classname($db);
//print '<pre>'.print_r($printer, true).'</pre>';
$i=0;
foreach ($printer->conf as $key) {
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td'.($key['required']?' class=required':'').'>'.$langs->trans($key['varname']).'</td><td>';
print '<input size="32" type="'.(empty($key['type'])?'text':$key['type']).'" name="setupdriver['.$i.'][value]" value="'.$conf->global->{$key['varname']}.'">';
print '<input type="hidden" name="setupdriver['.$i.'][varname]" value="'.$key['varname'].'">';
print '&nbsp;'.($key['example']!=''?$langs->trans("Example").' : '.$key['example']:'');
print '</tr>';
$i++;
}
} else {
print $langs->trans('PleaseSelectaDriverfromList');
}
print '</table>';
if (! empty($driver)) {
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'"></center>';
}
print '</form>';
dol_fiche_end();
}
if ($mode == 'config' && $user->admin) 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">';
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans("PrintingDesc")."<br><br>\n"; print $langs->trans("PrintingDesc")."<br><br>\n";
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">'."\n";
$var=true; $var=true;
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Parameters").'</td>'; print '<th>'.$langs->trans("Description").'</th>';
print '<td>'.$langs->trans("Value").'</td>'; print '<th class="center">'.$langs->trans("Active").'</th>';
print '<th class="center">'.$langs->trans("Setup").'</th>';
print '<th class="center">'.$langs->trans("Test").'</th>';
print "</tr>\n"; print "</tr>\n";
$object = new PrintingDriver($db);
$var=!$var; $result = $object->listDrivers($db, 10);
print '<tr '.$bc[$var].'><td class="fieldrequired">'; foreach ($result as $driver) {
print $langs->trans("PRINTIPP_HOST").'</td><td>'; require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
print '<input size="64" type="text" name="PRINTIPP_HOST" value="'.$conf->global->PRINTIPP_HOST.'">'; $classname = 'printing_'.$driver;
print ' &nbsp; '.$langs->trans("Example").': localhost'; $langs->load($driver);
print '</td></tr>'; $printer = new $classname($db);
//print '<pre>'.print_r($printer, true).'</pre>';
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td class="fieldrequired">'; print '<tr '.$bc[$var].'>';
print $langs->trans("PRINTIPP_PORT").'</td><td>'; print '<td>'.img_picto('', $printer->picto).$langs->trans($printer->desc).'</td>';
print '<input size="32" type="text" name="PRINTIPP_PORT" value="'.$conf->global->PRINTIPP_PORT.'">'; print '<td class="center">';
print ' &nbsp; '.$langs->trans("Example").': 631'; if (! empty($conf->use_javascript_ajax))
print '</td></tr>'; {
print ajax_constantonoff($printer->active);
$var=!$var; }
print '<tr '.$bc[$var].'><td>'; else
print $langs->trans("PRINTIPP_USER").'</td><td>'; {
print '<input size="32" type="text" name="PRINTIPP_USER" value="'.$conf->global->PRINTIPP_USER.'">'; if (empty($conf->global->{$printer->conf}))
print '</td></tr>'; {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&amp;varname='.$printer->active.'&amp;value=1">'.img_picto($langs->trans("Disabled"),'off').'</a>';
$var=!$var; }
print '<tr '.$bc[$var].'><td>'; else
print $langs->trans("PRINTIPP_PASSWORD").'</td><td>'; {
print '<input size="32" type="text" name="PRINTIPP_PASSWORD" value="'.$conf->global->PRINTIPP_PASSWORD.'">'; print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&amp;varname='.$printer->active.'&amp;value=0">'.img_picto($langs->trans("Enabled"),'on').'</a>';
print '</td></tr>'; }
}
print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?mode=setup&amp;driver='.$printer->name.'">'.img_picto('', 'setup').'</a></td>';
print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?mode=test&amp;driver='.$printer->name.'">'.img_picto('', 'setup').'</a></td>';
print '</tr>'."\n";
}
print '</table>'; print '</table>';
dol_fiche_end(); dol_fiche_end();
}
//print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'"></center>'; if ($mode == 'test' && $user->admin)
{
dol_fiche_head($head, $mode, $langs->trans("PrintingTest"), 0, 'technic');
print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
print '</form>'; print '<table class="nobordernopadding" width="100%">';
if (! empty($driver)) {
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
$classname = 'printing_'.$driver;
$printer = new $classname($db);
//print '<pre>'.print_r($printer, true).'</pre>';
print $printer->listAvailablePrinters();
} else {
//if (count($list) == 0) print $langs->trans("NoPrinterFound"); print $langs->trans('PleaseSelectaDriverfromList');
}
print '</table>';
dol_fiche_end(); dol_fiche_end();
} }
llxFooter(); llxFooter();
$db->close(); $db->close();

View File

@ -16,44 +16,49 @@
*/ */
/** /**
* \file htdocs/printipp/lib/printipp.lib.php * \file htdocs/printing/lib/printing.lib.php
* \ingroup printipp * \ingroup printing
* \brief Library for printipp functions * \brief Library for printing functions
*/ */
/** /**
* Define head array for tabs of printipp tools setup pages * Define head array for tabs of printing tools setup pages
* *
* @return Array of head * @return Array of head
*/ */
function printippadmin_prepare_head() function printingadmin_prepare_head()
{ {
global $langs, $conf; global $langs, $conf;
$h = 0; $h = 0;
$head = array(); $head = array();
$head[$h][0] = DOL_URL_ROOT."/printipp/admin/printipp.php?mode=config"; $head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=config";
$head[$h][1] = $langs->trans("CupsServer"); $head[$h][1] = $langs->trans("ListDrivers");
$head[$h][2] = 'config'; $head[$h][2] = 'config';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT."/printipp/admin/printipp.php?mode=test"; $head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=setup";
$head[$h][1] = $langs->trans("Printer"); $head[$h][1] = $langs->trans("SetupDriver");
$head[$h][2] = 'setup';
$h++;
$head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=test";
$head[$h][1] = $langs->trans("TestDriver");
$head[$h][2] = 'test'; $head[$h][2] = 'test';
$h++; $h++;
$object=new stdClass(); //$object=new stdClass();
// Show more tabs from modules // Show more tabs from modules
// Entries must be declared in modules descriptor with line // 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:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a 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,'printingadmin');
complete_head_from_modules($conf,$langs,$object,$head,$h,'printipp','remove'); //complete_head_from_modules($conf,$langs,$object,$head,$h,'printing','remove');
return $head; return $head;
} }

View File

@ -1,246 +0,0 @@
<?php
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 printipp
* \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');
$value = GETPOST('value','alpha');
if (!$mode) $mode='config';
/*
* Action
*/
if ($action == 'setvalue' && $user->admin)
{
$db->begin();
if (! $result > 0) $error++;
$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);
}
}
// Set default model
else if ($action == 'setprinteruri')
{
if (dolibarr_set_const($db, "PRINTIPP_URI_DEFAULT",$value,'chaine',0,'',$conf->entity))
{
// La constante qui a ete lue en avant du nouveau set
// on passe donc par une variable pour avoir un affichage coherent
$conf->global->PRINTIPP_URI_DEFAULT = $value;
}
}
/*
* 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();
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">';
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans("PrintIPPDesc")."<br><br>\n";
print '<table class="noborder" width="100%">';
$var=true;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Parameters").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print "</tr>\n";
/*
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print $langs->trans("PRINTIPP_ENABLED").'</td><td colspan="2" align="left">';
if (! empty($conf->use_javascript_ajax))
{
print ajax_constantonoff('PRINTIPP_ENABLED');
}
else
{
if (empty($conf->global->PRINTIPP_ENABLED))
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_PRINTIPP_ENABLED">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
else
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_PRINTIPP_ENABLED">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
}
print '</td></tr>';
*/
$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 ' &nbsp; '.$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 ' &nbsp; '.$langs->trans("Example").': 631';
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
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>';
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 '</table>';
dol_fiche_end();
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'"></center>';
print '</form>';
}
if ($mode == 'test' && $user->admin)
{
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans("PrintIPPDesc")."<br><br>\n";
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 '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print '<td>Uri</td>';
print '<td>Name</td>';
print '<td>State</td>';
print '<td>State_reason</td>';
print '<td>State_reason1</td>';
print '<td>BW</td>';
print '<td>Color</td>';
//print '<td>Device</td>';
print '<td>Media</td>';
print '<td>Supported</td>';
print '<td>'.$langs->trans("Select").'</td>';
print "</tr>\n";
$list = $printer->getlist_available_printers();
$var = true;
foreach ($list as $value)
{
$var=!$var;
$printer_det = $printer->get_printer_detail($value);
print "<tr ".$bc[$var].">";
print '<td>'.$value.'</td>';
//print '<td><pre>'.print_r($printer_det,true).'</pre></td>';
print '<td>'.$printer_det->printer_name->_value0.'</td>';
print '<td>'.$printer_det->printer_state->_value0.'</td>';
print '<td>'.$printer_det->printer_state_reasons->_value0.'</td>';
print '<td>'.$printer_det->printer_state_reasons->_value1.'</td>';
print '<td>'.$printer_det->printer_type->_value2.'</td>';
print '<td>'.$printer_det->printer_type->_value3.'</td>';
//print '<td>'.$printer_det->device_uri->_value0.'</td>';
print '<td>'.$printer_det->media_default->_value0.'</td>';
print '<td>'.$printer_det->media_type_supported->_value1.'</td>';
// Defaut
print "<td align=\"center\">";
if ($conf->global->PRINTIPP_URI_DEFAULT == "$value")
{
print img_picto($langs->trans("Default"),'on');
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setprinteruri&mode=test&value='.urlencode($value).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
print '</td>';
print "</tr>\n";
}
print '</table>';
if (count($list) == 0) print $langs->trans("NoPrinterFound");
dol_fiche_end();
}
llxFooter();
$db->close();

View File

@ -1,36 +0,0 @@
<?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();
$db->close();