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';
|
||||
$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 '<pre>'.print_r($printer, true).'</pre>';
|
||||
|
||||
if (!empty($conf->global->{$printer->active}))
|
||||
{
|
||||
if (!empty($conf->global->{$printer->active})) {
|
||||
$printerfound++;
|
||||
|
||||
$subdir = '';
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 '<pre>'.print_r($printer, true).'</pre>';
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.img_picto('', $printer->picto).' '.$langs->trans($printer->desc).'</td>';
|
||||
print '<td class="center">';
|
||||
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 '<a href="'.$_SERVER['PHP_SELF'].'?action=setvalue&token='.newToken().'&varname='.$printer->active.'&value=1">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
|
||||
} else {
|
||||
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 '<table class="noborder centpercent">';
|
||||
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 '<pre>'.print_r($printer, true).'</pre>';
|
||||
if (count($printer->getlistAvailablePrinters())) {
|
||||
if ($printer->listAvailablePrinters() == 0) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user