From 81f6a7abb67cbdd4c3631914148cf5ce521469c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 21 Oct 2020 20:18:06 +0200 Subject: [PATCH 1/5] can add a driver for printing in module --- .../modules/printing/modules_printing.php | 15 ++++-- .../modules/printing/printgcp.modules.php | 1 + .../modules/printing/printipp.modules.php | 2 + .../core/modules/modMyModule.class.php | 2 + htdocs/printing/admin/printing.php | 47 +++++++++++++------ 5 files changed, 47 insertions(+), 20 deletions(-) diff --git a/htdocs/core/modules/printing/modules_printing.php b/htdocs/core/modules/printing/modules_printing.php index e7e16dc7979..a368a7265df 100644 --- a/htdocs/core/modules/printing/modules_printing.php +++ b/htdocs/core/modules/printing/modules_printing.php @@ -66,12 +66,17 @@ class PrintingDriver $type = 'printing'; $list = 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) { + $listoffiles = array(); + $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); + foreach ($dirmodels as $dir) { + $tmpfiles = dol_dir_list(dol_buildpath($dir, 0), 'all', 0, '\modules.php', '', 'name', SORT_ASC, 0); + if (!empty($tmpfiles)) { + $listoffiles = array_merge($listoffiles, $tmpfiles); + } + } + foreach ($listoffiles as $record) { $list[$record['fullname']] = str_replace('.modules.php', '', $record['name']); - } - + } return $list; } diff --git a/htdocs/core/modules/printing/printgcp.modules.php b/htdocs/core/modules/printing/printgcp.modules.php index e1f765110a8..387f13ee332 100644 --- a/htdocs/core/modules/printing/printgcp.modules.php +++ b/htdocs/core/modules/printing/printgcp.modules.php @@ -68,6 +68,7 @@ class printing_printgcp extends PrintingDriver const PRINTERS_SEARCH_URL = 'https://www.google.com/cloudprint/search'; const PRINTERS_GET_JOBS = 'https://www.google.com/cloudprint/jobs'; const PRINT_URL = 'https://www.google.com/cloudprint/submit'; + const LANGFILE = 'printgcp'; /** * Constructor diff --git a/htdocs/core/modules/printing/printipp.modules.php b/htdocs/core/modules/printing/printipp.modules.php index 6b0e528aa1e..bf9f2fbd61b 100644 --- a/htdocs/core/modules/printing/printipp.modules.php +++ b/htdocs/core/modules/printing/printipp.modules.php @@ -60,6 +60,8 @@ class printing_printipp extends PrintingDriver */ public $db; + const LANGFILE = 'printipp'; + /** * Constructor diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 46943c6c9ab..8922bc00eb5 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -90,6 +90,8 @@ class modMyModule extends DolibarrModules 'barcode' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx) 'models' => 0, + // Set this to 1 if module has its own printing directory (core/modules/printing) + 'printing' => 0, // Set this to 1 if module has its own theme directory (theme) 'theme' => 0, // Set this to relative path of css file if module has its own css file diff --git a/htdocs/printing/admin/printing.php b/htdocs/printing/admin/printing.php index 2f906c68382..b810be417ae 100644 --- a/htdocs/printing/admin/printing.php +++ b/htdocs/printing/admin/printing.php @@ -69,8 +69,7 @@ if ($action == 'setconst' && $user->admin) if (!$result > 0) $error++; } - if (!$error) - { + if (!$error) { $db->commit(); setEventMessages($langs->trans("SetupSaved"), null); } else { @@ -87,8 +86,7 @@ if ($action == 'setvalue' && $user->admin) $result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity); if (!$result > 0) $error++; - if (!$error) - { + if (!$error) { $db->commit(); setEventMessages($langs->trans("SetupSaved"), null); } else { @@ -131,10 +129,17 @@ if ($mode == 'setup' && $user->admin) $submit_enabled = 0; if (!empty($driver)) { - require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; + $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); + foreach ($dirmodels as $dir) { + if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) { + $classfile = dol_buildpath($dir, 0).$driver.'.modules.php'; + break; + } + } + require_once $classfile; $classname = 'printing_'.$driver; - $langs->load($driver); $printer = new $classname($db); + $langs->load($printer::LANGFILE); $i = 0; $submit_enabled = 0; @@ -246,22 +251,27 @@ if ($mode == 'config' && $user->admin) $object = new PrintingDriver($db); $result = $object->listDrivers($db, 10); + $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); foreach ($result as $driver) { - require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; + foreach ($dirmodels as $dir) { + if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) { + $classfile = dol_buildpath($dir, 0).$driver.'.modules.php'; + break; + } + } + require_once $classfile; $classname = 'printing_'.$driver; - $langs->load($driver); $printer = new $classname($db); + $langs->load($printer::LANGFILE); //print '
'.print_r($printer, true).'
'; print ''; print ''.img_picto('', $printer->picto).' '.$langs->trans($printer->desc).''; print ''; - if (!empty($conf->use_javascript_ajax)) - { + if (!empty($conf->use_javascript_ajax)) { print ajax_constantonoff($printer->active); } else { - if (empty($conf->global->{$printer->conf})) - { + if (empty($conf->global->{$printer->conf})) { print ''.img_picto($langs->trans("Disabled"), 'off').''; } else { print ''.img_picto($langs->trans("Enabled"), 'on').''; @@ -284,12 +294,19 @@ if ($mode == 'test' && $user->admin) print $langs->trans('PrintTestDesc'.$driver)."

\n"; print ''; - if (!empty($driver)) - { - require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; + if (!empty($driver)) { + $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); + foreach ($dirmodels as $dir) { + if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) { + $classfile = dol_buildpath($dir, 0).$driver.'.modules.php'; + break; + } + } + require_once $classfile; $classname = 'printing_'.$driver; $langs->load($driver); $printer = new $classname($db); + $langs->load($printer::LANGFILE); //print '
'.print_r($printer, true).'
'; if (count($printer->getlistAvailablePrinters())) { if ($printer->listAvailablePrinters() == 0) { From 06325f94226fb235969c415ab43a8d2366f970d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 21 Oct 2020 21:00:50 +0200 Subject: [PATCH 2/5] doxygen --- .../modules/printing/printipp.modules.php | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/printing/printipp.modules.php b/htdocs/core/modules/printing/printipp.modules.php index bf9f2fbd61b..873382ceae2 100644 --- a/htdocs/core/modules/printing/printipp.modules.php +++ b/htdocs/core/modules/printing/printipp.modules.php @@ -30,19 +30,54 @@ include_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php'; */ class printing_printipp extends PrintingDriver { + /** + * @var string module name + */ public $name = 'printipp'; + + /** + * @var string module description + */ public $desc = 'PrintIPPDesc'; /** * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png */ public $picto = 'printer'; + + /** + * @var string Constant name + */ public $active = 'PRINTING_PRINTIPP'; + + /** + * @var array array of setup value + */ public $conf = array(); + + /** + * @var string host + */ public $host; + + /** + * @var string port + */ public $port; - public $userid; /* user login */ + + /** + * @var string username + */ + public $userid; + + /** + * @var string login for printer host + */ public $user; + + /** + * @var string password for printer host + */ public $password; /** @@ -115,7 +150,7 @@ class printing_printipp extends PrintingDriver $obj = $this->db->fetch_object($result); if ($obj) { - dol_syslog("Found a default printer for user ".$user->id." = ".$obj->printer_id); + dol_syslog("Found a default printer for user ".$user->id." = ".$obj->printer_id); $ipp->setPrinterURI($obj->printer_id); } else { if (!empty($conf->global->PRINTIPP_URI_DEFAULT)) From 4873794dc0223493b36b446d71cccdc2d3b763b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 21 Oct 2020 21:08:33 +0200 Subject: [PATCH 3/5] doxygen --- .../modules/printing/printgcp.modules.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/htdocs/core/modules/printing/printgcp.modules.php b/htdocs/core/modules/printing/printgcp.modules.php index 387f13ee332..154fd025ded 100644 --- a/htdocs/core/modules/printing/printgcp.modules.php +++ b/htdocs/core/modules/printing/printgcp.modules.php @@ -35,16 +35,39 @@ use OAuth\OAuth2\Service\Google; */ class printing_printgcp extends PrintingDriver { + /** + * @var string module name + */ public $name = 'printgcp'; + + /** + * @var string module description + */ public $desc = 'PrintGCPDesc'; /** * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png */ public $picto = 'printer'; + + /** + * @var string module description + */ public $active = 'PRINTING_PRINTGCP'; + + /** + * @var array module parameters + */ public $conf = array(); + + /** + * @var string google id + */ public $google_id = ''; + + /** + * @var string google secret + */ public $google_secret = ''; /** From f500076247ab37a5b7884aedfb7df8fa18aaab79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 21 Oct 2020 21:21:30 +0200 Subject: [PATCH 4/5] remove warning --- htdocs/core/modules/printing/printgcp.modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/printing/printgcp.modules.php b/htdocs/core/modules/printing/printgcp.modules.php index 154fd025ded..096c633036a 100644 --- a/htdocs/core/modules/printing/printgcp.modules.php +++ b/htdocs/core/modules/printing/printgcp.modules.php @@ -304,7 +304,7 @@ class printing_printgcp extends PrintingDriver $responsedata = json_decode($response, true); $printers = $responsedata['printers']; // Check if we have printers? - if (count($printers) == 0) { + if (is_array($printers) && count($printers) == 0) { // We dont have printers so return blank array $ret['available'] = array(); } else { From f54164bd10015fdfb5ed25697a3461f463e84748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 21 Oct 2020 21:33:23 +0200 Subject: [PATCH 5/5] modify action --- htdocs/core/actions_printing.inc.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/htdocs/core/actions_printing.inc.php b/htdocs/core/actions_printing.inc.php index e88fc937e38..3137c93a9c5 100644 --- a/htdocs/core/actions_printing.inc.php +++ b/htdocs/core/actions_printing.inc.php @@ -33,18 +33,24 @@ if ($action == 'print_file' && $user->rights->printing->read) { require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php'; $objectprint = new PrintingDriver($db); $list = $objectprint->listDrivers($db, 10); + $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); if (!empty($list)) { $errorprint = 0; $printerfound = 0; foreach ($list as $driver) { - require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; - $langs->load($driver); + foreach ($dirmodels as $dir) { + if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) { + $classfile = dol_buildpath($dir, 0).$driver.'.modules.php'; + break; + } + } + require_once $classfile; $classname = 'printing_'.$driver; $printer = new $classname($db); + $langs->load($printer::LANGFILE); //print '
'.print_r($printer, true).'
'; - if (!empty($conf->global->{$printer->active})) - { + if (!empty($conf->global->{$printer->active})) { $printerfound++; $subdir = '';