Merge pull request #15083 from frederic34/printing_module
can add a driver for printing in module
This commit is contained in:
commit
d7b7e1e386
@ -33,18 +33,24 @@ if ($action == 'print_file' && $user->rights->printing->read) {
|
|||||||
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
|
||||||
$objectprint = new PrintingDriver($db);
|
$objectprint = new PrintingDriver($db);
|
||||||
$list = $objectprint->listDrivers($db, 10);
|
$list = $objectprint->listDrivers($db, 10);
|
||||||
|
$dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
|
||||||
if (!empty($list)) {
|
if (!empty($list)) {
|
||||||
$errorprint = 0;
|
$errorprint = 0;
|
||||||
$printerfound = 0;
|
$printerfound = 0;
|
||||||
foreach ($list as $driver) {
|
foreach ($list as $driver) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
|
foreach ($dirmodels as $dir) {
|
||||||
$langs->load($driver);
|
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;
|
$classname = 'printing_'.$driver;
|
||||||
$printer = new $classname($db);
|
$printer = new $classname($db);
|
||||||
|
$langs->load($printer::LANGFILE);
|
||||||
//print '<pre>'.print_r($printer, true).'</pre>';
|
//print '<pre>'.print_r($printer, true).'</pre>';
|
||||||
|
|
||||||
if (!empty($conf->global->{$printer->active}))
|
if (!empty($conf->global->{$printer->active})) {
|
||||||
{
|
|
||||||
$printerfound++;
|
$printerfound++;
|
||||||
|
|
||||||
$subdir = '';
|
$subdir = '';
|
||||||
|
|||||||
@ -66,12 +66,17 @@ class PrintingDriver
|
|||||||
$type = 'printing';
|
$type = 'printing';
|
||||||
$list = array();
|
$list = array();
|
||||||
|
|
||||||
$moduledir = DOL_DOCUMENT_ROOT."/core/modules/printing/";
|
$listoffiles = array();
|
||||||
$tmpfiles = dol_dir_list($moduledir, 'all', 0, '\modules.php', '', 'name', SORT_ASC, 0);
|
$dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
|
||||||
foreach ($tmpfiles as $record) {
|
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']);
|
$list[$record['fullname']] = str_replace('.modules.php', '', $record['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,16 +35,39 @@ use OAuth\OAuth2\Service\Google;
|
|||||||
*/
|
*/
|
||||||
class printing_printgcp extends PrintingDriver
|
class printing_printgcp extends PrintingDriver
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string module name
|
||||||
|
*/
|
||||||
public $name = 'printgcp';
|
public $name = 'printgcp';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string module description
|
||||||
|
*/
|
||||||
public $desc = 'PrintGCPDesc';
|
public $desc = 'PrintGCPDesc';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
|
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
|
||||||
*/
|
*/
|
||||||
public $picto = 'printer';
|
public $picto = 'printer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string module description
|
||||||
|
*/
|
||||||
public $active = 'PRINTING_PRINTGCP';
|
public $active = 'PRINTING_PRINTGCP';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array module parameters
|
||||||
|
*/
|
||||||
public $conf = array();
|
public $conf = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string google id
|
||||||
|
*/
|
||||||
public $google_id = '';
|
public $google_id = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string google secret
|
||||||
|
*/
|
||||||
public $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_SEARCH_URL = 'https://www.google.com/cloudprint/search';
|
||||||
const PRINTERS_GET_JOBS = 'https://www.google.com/cloudprint/jobs';
|
const PRINTERS_GET_JOBS = 'https://www.google.com/cloudprint/jobs';
|
||||||
const PRINT_URL = 'https://www.google.com/cloudprint/submit';
|
const PRINT_URL = 'https://www.google.com/cloudprint/submit';
|
||||||
|
const LANGFILE = 'printgcp';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -280,7 +304,7 @@ class printing_printgcp extends PrintingDriver
|
|||||||
$responsedata = json_decode($response, true);
|
$responsedata = json_decode($response, true);
|
||||||
$printers = $responsedata['printers'];
|
$printers = $responsedata['printers'];
|
||||||
// Check if we have 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
|
// We dont have printers so return blank array
|
||||||
$ret['available'] = array();
|
$ret['available'] = array();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -30,19 +30,54 @@ include_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
|
|||||||
*/
|
*/
|
||||||
class printing_printipp extends PrintingDriver
|
class printing_printipp extends PrintingDriver
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string module name
|
||||||
|
*/
|
||||||
public $name = 'printipp';
|
public $name = 'printipp';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string module description
|
||||||
|
*/
|
||||||
public $desc = 'PrintIPPDesc';
|
public $desc = 'PrintIPPDesc';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
|
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
|
||||||
*/
|
*/
|
||||||
public $picto = 'printer';
|
public $picto = 'printer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Constant name
|
||||||
|
*/
|
||||||
public $active = 'PRINTING_PRINTIPP';
|
public $active = 'PRINTING_PRINTIPP';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array array of setup value
|
||||||
|
*/
|
||||||
public $conf = array();
|
public $conf = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string host
|
||||||
|
*/
|
||||||
public $host;
|
public $host;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string port
|
||||||
|
*/
|
||||||
public $port;
|
public $port;
|
||||||
public $userid; /* user login */
|
|
||||||
|
/**
|
||||||
|
* @var string username
|
||||||
|
*/
|
||||||
|
public $userid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string login for printer host
|
||||||
|
*/
|
||||||
public $user;
|
public $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string password for printer host
|
||||||
|
*/
|
||||||
public $password;
|
public $password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,6 +95,8 @@ class printing_printipp extends PrintingDriver
|
|||||||
*/
|
*/
|
||||||
public $db;
|
public $db;
|
||||||
|
|
||||||
|
const LANGFILE = 'printipp';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -113,7 +150,7 @@ class printing_printipp extends PrintingDriver
|
|||||||
$obj = $this->db->fetch_object($result);
|
$obj = $this->db->fetch_object($result);
|
||||||
if ($obj)
|
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);
|
$ipp->setPrinterURI($obj->printer_id);
|
||||||
} else {
|
} else {
|
||||||
if (!empty($conf->global->PRINTIPP_URI_DEFAULT))
|
if (!empty($conf->global->PRINTIPP_URI_DEFAULT))
|
||||||
|
|||||||
@ -90,6 +90,8 @@ class modMyModule extends DolibarrModules
|
|||||||
'barcode' => 0,
|
'barcode' => 0,
|
||||||
// Set this to 1 if module has its own models directory (core/modules/xxx)
|
// Set this to 1 if module has its own models directory (core/modules/xxx)
|
||||||
'models' => 0,
|
'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)
|
// Set this to 1 if module has its own theme directory (theme)
|
||||||
'theme' => 0,
|
'theme' => 0,
|
||||||
// Set this to relative path of css file if module has its own css file
|
// Set this to relative path of css file if module has its own css file
|
||||||
|
|||||||
@ -69,8 +69,7 @@ if ($action == 'setconst' && $user->admin)
|
|||||||
if (!$result > 0) $error++;
|
if (!$result > 0) $error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
if (!$error) {
|
||||||
{
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
setEventMessages($langs->trans("SetupSaved"), null);
|
setEventMessages($langs->trans("SetupSaved"), null);
|
||||||
} else {
|
} else {
|
||||||
@ -87,8 +86,7 @@ if ($action == 'setvalue' && $user->admin)
|
|||||||
$result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity);
|
$result = dolibarr_set_const($db, $varname, $value, 'chaine', 0, '', $conf->entity);
|
||||||
if (!$result > 0) $error++;
|
if (!$result > 0) $error++;
|
||||||
|
|
||||||
if (!$error)
|
if (!$error) {
|
||||||
{
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
setEventMessages($langs->trans("SetupSaved"), null);
|
setEventMessages($langs->trans("SetupSaved"), null);
|
||||||
} else {
|
} else {
|
||||||
@ -131,10 +129,17 @@ if ($mode == 'setup' && $user->admin)
|
|||||||
$submit_enabled = 0;
|
$submit_enabled = 0;
|
||||||
|
|
||||||
if (!empty($driver)) {
|
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;
|
$classname = 'printing_'.$driver;
|
||||||
$langs->load($driver);
|
|
||||||
$printer = new $classname($db);
|
$printer = new $classname($db);
|
||||||
|
$langs->load($printer::LANGFILE);
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$submit_enabled = 0;
|
$submit_enabled = 0;
|
||||||
@ -246,22 +251,27 @@ if ($mode == 'config' && $user->admin)
|
|||||||
|
|
||||||
$object = new PrintingDriver($db);
|
$object = new PrintingDriver($db);
|
||||||
$result = $object->listDrivers($db, 10);
|
$result = $object->listDrivers($db, 10);
|
||||||
|
$dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
|
||||||
foreach ($result as $driver) {
|
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;
|
$classname = 'printing_'.$driver;
|
||||||
$langs->load($driver);
|
|
||||||
$printer = new $classname($db);
|
$printer = new $classname($db);
|
||||||
|
$langs->load($printer::LANGFILE);
|
||||||
//print '<pre>'.print_r($printer, true).'</pre>';
|
//print '<pre>'.print_r($printer, true).'</pre>';
|
||||||
|
|
||||||
print '<tr class="oddeven">';
|
print '<tr class="oddeven">';
|
||||||
print '<td>'.img_picto('', $printer->picto).' '.$langs->trans($printer->desc).'</td>';
|
print '<td>'.img_picto('', $printer->picto).' '.$langs->trans($printer->desc).'</td>';
|
||||||
print '<td class="center">';
|
print '<td class="center">';
|
||||||
if (!empty($conf->use_javascript_ajax))
|
if (!empty($conf->use_javascript_ajax)) {
|
||||||
{
|
|
||||||
print ajax_constantonoff($printer->active);
|
print ajax_constantonoff($printer->active);
|
||||||
} else {
|
} else {
|
||||||
if (empty($conf->global->{$printer->conf}))
|
if (empty($conf->global->{$printer->conf})) {
|
||||||
{
|
|
||||||
print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&token='.newToken().'&varname='.$printer->active.'&value=1">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
|
print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&token='.newToken().'&varname='.$printer->active.'&value=1">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
|
||||||
} else {
|
} else {
|
||||||
print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&token='.newToken().'&varname='.$printer->active.'&value=0">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
|
print '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&token='.newToken().'&varname='.$printer->active.'&value=0">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
|
||||||
@ -284,12 +294,19 @@ if ($mode == 'test' && $user->admin)
|
|||||||
print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
|
print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
|
||||||
|
|
||||||
print '<table class="noborder centpercent">';
|
print '<table class="noborder centpercent">';
|
||||||
if (!empty($driver))
|
if (!empty($driver)) {
|
||||||
{
|
$dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']);
|
||||||
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;
|
$classname = 'printing_'.$driver;
|
||||||
$langs->load($driver);
|
$langs->load($driver);
|
||||||
$printer = new $classname($db);
|
$printer = new $classname($db);
|
||||||
|
$langs->load($printer::LANGFILE);
|
||||||
//print '<pre>'.print_r($printer, true).'</pre>';
|
//print '<pre>'.print_r($printer, true).'</pre>';
|
||||||
if (count($printer->getlistAvailablePrinters())) {
|
if (count($printer->getlistAvailablePrinters())) {
|
||||||
if ($printer->listAvailablePrinters() == 0) {
|
if ($printer->listAvailablePrinters() == 0) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user