diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index aa75945f0ea..908a8d4c8ad 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -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'; /* diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 309b0c35e1a..a9a8800ede1 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -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'; /* diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index be6ad58764a..4e79e710321 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -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) { diff --git a/htdocs/core/actions_printing.inc.php b/htdocs/core/actions_printing.inc.php new file mode 100644 index 00000000000..f864524fce1 --- /dev/null +++ b/htdocs/core/actions_printing.inc.php @@ -0,0 +1,58 @@ + + * Copyright (C) 2014 Frederic France + * + * 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 . + * 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 = ''; +} diff --git a/htdocs/core/actions_printipp.inc.php b/htdocs/core/actions_printipp.inc.php deleted file mode 100644 index 3c18faa813b..00000000000 --- a/htdocs/core/actions_printipp.inc.php +++ /dev/null @@ -1,45 +0,0 @@ - - * - * 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 . - * 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 = ''; -} diff --git a/htdocs/core/class/dolprintipp.class.php b/htdocs/core/class/dolprintipp.class.php index 71ee2a1be37..272d46ec745 100644 --- a/htdocs/core/class/dolprintipp.class.php +++ b/htdocs/core/class/dolprintipp.class.php @@ -28,7 +28,7 @@ class dolprintIPP { var $host; var $port; - var $userid; /* user login */ + var $userid; /* user login */ var $user; var $password; var $error; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 9a419e53d89..d2183c582cd 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -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')); diff --git a/htdocs/core/modules/modPrintIPP.class.php b/htdocs/core/modules/modPrintIPP.class.php index 3cdcd6cdfa6..1f3d0a71a7a 100644 --- a/htdocs/core/modules/modPrintIPP.class.php +++ b/htdocs/core/modules/modPrintIPP.class.php @@ -1,5 +1,6 @@ + * Copyright (C) 2014 Frederic France * * 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='') { diff --git a/htdocs/core/modules/modPrinting.class.php b/htdocs/core/modules/modPrinting.class.php new file mode 100644 index 00000000000..144b023bdc8 --- /dev/null +++ b/htdocs/core/modules/modPrinting.class.php @@ -0,0 +1,155 @@ + + * Copyright (C) 2014 Frederic France + * + * 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 . + */ + +/** \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); + } + +} diff --git a/htdocs/core/triggers/interface_60_modPrinting_Printing.class.php b/htdocs/core/triggers/interface_60_modPrinting_Printing.class.php new file mode 100644 index 00000000000..b02b16f4796 --- /dev/null +++ b/htdocs/core/triggers/interface_60_modPrinting_Printing.class.php @@ -0,0 +1,71 @@ + + * Copyright (C) 2005-2014 Regis Houssin + * Copyright (C) 2014 Marcos García + * + * 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 . + */ + +/** + * \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; + } + +} diff --git a/htdocs/printing/admin/index.html b/htdocs/printing/admin/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/printing/admin/printing.php b/htdocs/printing/admin/printing.php new file mode 100644 index 00000000000..29bd8787fa0 --- /dev/null +++ b/htdocs/printing/admin/printing.php @@ -0,0 +1,127 @@ + + * Copyright (C) 2014 Frederic France + * + * 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 . + */ + +/** + * \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=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("PrintIPPSetup"),$linkback,'setup'); + +//$head=printippadmin_prepare_head(); + + +if ($mode == 'config' && $user->admin) +{ + print '
'; + print ''; + print ''; + + dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic'); + + print $langs->trans("PrintingDesc")."

\n"; + + print ''; + + $var=true; + print ''; + print ''; + print ''; + print "\n"; + + + $var=!$var; + print ''; + + $var=!$var; + print ''; + + $var=!$var; + print ''; + + $var=!$var; + print ''; + + print '
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'; + print $langs->trans("PRINTIPP_HOST").''; + print ''; + print '   '.$langs->trans("Example").': localhost'; + print '
'; + print $langs->trans("PRINTIPP_PORT").''; + print ''; + print '   '.$langs->trans("Example").': 631'; + print '
'; + print $langs->trans("PRINTIPP_USER").''; + print ''; + print '
'; + print $langs->trans("PRINTIPP_PASSWORD").''; + print ''; + print '
'; + + dol_fiche_end(); + + //print '
'; + + + print ''; + + + //if (count($list) == 0) print $langs->trans("NoPrinterFound"); + + dol_fiche_end(); +} + + + +llxFooter(); + +$db->close(); diff --git a/htdocs/printing/index.php b/htdocs/printing/index.php new file mode 100644 index 00000000000..e8669f44585 --- /dev/null +++ b/htdocs/printing/index.php @@ -0,0 +1,38 @@ + + * + * 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 . + */ + +/** + * \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();