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 = ''; 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..096c633036a 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 = ''; /** @@ -68,6 +91,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 @@ -280,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 { diff --git a/htdocs/core/modules/printing/printipp.modules.php b/htdocs/core/modules/printing/printipp.modules.php index 6b0e528aa1e..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; /** @@ -60,6 +95,8 @@ class printing_printipp extends PrintingDriver */ public $db; + const LANGFILE = 'printipp'; + /** * Constructor @@ -113,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)) 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 '