WIP PrintIPP

This commit is contained in:
frederic34 2014-12-05 18:23:54 +01:00
parent 168e97e6ee
commit 5cce8c45e3
13 changed files with 464 additions and 59 deletions

View File

@ -553,7 +553,7 @@ else if ($action == 'setstatut' && $user->rights->propal->cloturer && ! GETPOST(
}
}
include DOL_DOCUMENT_ROOT.'/core/actions_printipp.inc.php';
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
/*

View File

@ -1142,7 +1142,7 @@ else if ($action == 'update_extras') {
$action = 'edit_extras';
}
include DOL_DOCUMENT_ROOT.'/core/actions_printipp.inc.php';
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
/*

View File

@ -1615,7 +1615,7 @@ else if ($action == 'remove_file') {
}
}
include DOL_DOCUMENT_ROOT.'/core/actions_printipp.inc.php';
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer)
{

View File

@ -0,0 +1,58 @@
<?php
/* Copyright (C) 2014 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/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/actions_printing.inc.php
* \brief Code for actions print_file to print file with calling trigger
*/
// $action must be defined
// $db, $user, $conf, $langs must be defined
// Filename to print must be provided into 'file' parameter
// Print file
if ($action == 'print_file' and $user->rights->printing->read)
{
$langs->load("printing");
//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(GETPOST('file', 'alpha'), GETPOST('printer', 'alpha'));
// Call trigger to Print Doc
//$actiontypecode='AC_PRINT';
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($db);
$trigger_name='PRINT_DOCPDF';
$printing->file = GETPOST('file', 'alpha');
$printing->printer = GETPOST('printer', 'alpha');
//print print_r($printing, true);
$result=$interface->run_triggers($trigger_name,$printing,$user,$langs,$conf);
if ($result < 0) {
setEventMessage($interface->errors, 'errors');
}
if ($result == 0) {
setEventMessage($langs->trans("NoModuleFound"));
}
if ($result>0) {
setEventMessage($langs->trans("FileWasSentToPrinter", basename(GETPOST('file'))));
}
$action = '';
}

View File

@ -1,45 +0,0 @@
<?php
/* Copyright (C) 2014 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/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/actions_printipp.inc.php
* \brief Code for actions print_file to print file using ipp
*/
// $action must be defined
// $db, $user, $conf, $langs must be defined
// Filename to print must be provided into 'file' parameter
// Print file
if ($action == 'print_file' and $user->rights->printipp->read)
{
$langs->load("printipp");
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(GETPOST('file', 'alpha'), GETPOST('printer', 'alpha'));
if ($result)
{
setEventMessage($result,'warnings');
}
else
{
setEventMessage($langs->trans("FileWasSentToPrinter", basename(GETPOST('file'))));
}
$action = '';
}

View File

@ -28,7 +28,7 @@ class dolprintIPP
{
var $host;
var $port;
var $userid; /* user login */
var $userid; /* user login */
var $user;
var $password;
var $error;

View File

@ -274,7 +274,7 @@ class FormFile
$printer=0;
if (in_array($modulepart,array('facture','propal','proposal','order','commande'))) // This feature is implemented only for such elements
{
$printer = (!empty($user->rights->printipp->read) && !empty($conf->printipp->enabled))?true:false;
$printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false;
}
$hookmanager->initHooks(array('formfile'));

View File

@ -1,5 +1,6 @@
<?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
@ -22,9 +23,9 @@
/**
* \file htdocs/core/modules/modPrintIPP.class.php
* \ingroup printipp
* \brief Fichier de description et activation du module OSCommerce2
* \brief Fichier de description et activation du module PrintIPP
*/
include_once(DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php");
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
@ -37,9 +38,9 @@ class modPrintIPP extends DolibarrModules
/**
* Constructor
* Constructor
*
* @param DoliDB $db Database handler
* @param DoliDB $db Database handler
*/
function __construct($db)
{
@ -68,10 +69,10 @@ class modPrintIPP extends DolibarrModules
// Dependances
$this->hidden = (! empty($_SERVER["WINDIR"]));
$this->depends = array();
$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->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");
@ -142,8 +143,8 @@ class modPrintIPP extends DolibarrModules
* 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
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
function remove($options='')
{

View File

@ -0,0 +1,155 @@
<?php
/* Copyright (C) 2014 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 printing Module printing
* \brief Module for activation of printing icon
*/
/**
* \file htdocs/core/modules/modPrinting.class.php
* \ingroup printing
* \brief Fichier de description et activation du module Printing
*/
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
/**
* \class modPrinting
* \brief Classe de description et activation du module Printing
*/
class modPrinting extends DolibarrModules
{
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $db ;
$this->numero = 112000;
// 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 = "Enable Printing System.";
$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("printing.php@printing");
// Dependances
$this->hidden = (! empty($_SERVER["WINDIR"]));
$this->depends = array();
$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("printing");
// Constantes
$this->const = array();
// Boxes
$this->boxes = array();
// Permissions
$this->rights = array();
$this->rights_class = 'printing';
$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] = 112001;
$this->rights[$r][1] = 'Printing';
$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'=>'Printing',
'mainmenu'=>'printing',
'url'=>'/printing/index.php',
'langs'=>'printing', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>300,
'enabled'=>'$conf->printing->enabled && $leftmenu==\'modulesadmintools\'',
'perms'=>'$user->rights->printing->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

@ -0,0 +1,71 @@
<?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

View File

@ -0,0 +1,127 @@
<?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/>.
*/
/**
* \file htdocs/printing/admin/printing.php
* \ingroup printing
* \brief Page to setup printing 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.'/printing/lib/printing.lib.php';
$langs->load("admin");
$langs->load("printing");
if (! $user->admin) accessforbidden();
$action = GETPOST('action','alpha');
$mode = GETPOST('mode','alpha');
$value = GETPOST('value','alpha');
if (!$mode) $mode='config';
/*
* Action
*/
/*
* View
*/
$form = new Form($db);
llxHeader('',$langs->trans("PrintingSetup"));
$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("PrintingDesc")."<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 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>';
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 (count($list) == 0) print $langs->trans("NoPrinterFound");
dol_fiche_end();
}
llxFooter();
$db->close();

38
htdocs/printing/index.php Normal file
View File

@ -0,0 +1,38 @@
<?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/>.
*/
/**
* \file htdocs/printing/index.php
* \ingroup printing
* \brief Printing
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php';
llxHeader("",$langs->trans("Printing"));
print_fiche_titre($langs->trans("Printing"));
// List Jobs from printing modules
//$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();