Skip to content
Snippets Groups Projects
Commit 8a6d3aa6 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Clean module print system

parent d5ec19ef
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,8 @@ class modPrinting extends DolibarrModules
$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.";
// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
$this->description = "Enable Direct Printing System.";
$this->version = 'dolibarr'; // '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)
......
......@@ -26,8 +26,7 @@
include_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
/**
* \class mailing_example
* \brief Class to provide printing with Google Cloud Print
* Class to provide printing with Google Cloud Print
*/
class printing_printgcp extends PrintingDriver
{
......@@ -175,7 +174,7 @@ class printing_printgcp extends PrintingDriver
if ($subdir!='') $fileprint.='/'.$subdir;
$fileprint.='/'.$file;
// select printer uri for module order, propal,...
$sql = 'SELECT rowid, printer_id, copy FROM '.MAIN_DB_PREFIX.'printing WHERE module="'.$module.'" AND driver="printgcp" AND userid='.$user->id;
$sql = "SELECT rowid, printer_id, copy FROM ".MAIN_DB_PREFIX."printing WHERE module='".$module."' AND driver='printgcp' AND userid=".$user->id;
$result = $db->query($sql);
if ($result)
{
......@@ -196,6 +195,7 @@ class printing_printgcp extends PrintingDriver
}
}
}
else dol_print_error($db);
$this->sendPrintToPrinter($printer_id, $file, $fileprint, 'application/pdf');
}
......@@ -204,7 +204,7 @@ class printing_printgcp extends PrintingDriver
* Sends document to the printer
*
* @param string $printerid Printer id returned by Google Cloud Print
* @param string $printjobtitle Job Title
* @param string $printjobtitle Job Title
* @param string $filepath File Path to be send to Google Cloud Print
* @param string $contenttype File content type by example application/pdf, image/png
* @return array status array
......
......@@ -26,8 +26,7 @@
include_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php';
/**
* \class mailing_example
* \brief Class to provide printing with PrintIPP
* Class to provide printing with PrintIPP
*/
class printing_printipp extends PrintingDriver
{
......@@ -61,8 +60,8 @@ class printing_printipp extends PrintingDriver
$this->password=$conf->global->PRINTIPP_PASSWORD;
$this->conf[] = array('varname'=>'PRINTIPP_HOST', 'required'=>1, 'example'=>'localhost', 'type'=>'text');
$this->conf[] = array('varname'=>'PRINTIPP_PORT', 'required'=>1, 'example'=>'631', 'type'=>'text');
$this->conf[] = array('varname'=>'PRINTIPP_USER', 'required'=>0, 'example'=>'', 'type'=>'text');
$this->conf[] = array('varname'=>'PRINTIPP_PASSWORD', 'required'=>0, 'example'=>'', 'type'=>'password');
$this->conf[] = array('varname'=>'PRINTIPP_USER', 'required'=>0, 'example'=>'', 'type'=>'text', 'moreattributes'=>'autocomplete="off"');
$this->conf[] = array('varname'=>'PRINTIPP_PASSWORD', 'required'=>0, 'example'=>'', 'type'=>'password', 'moreattributes'=>'autocomplete="off"');
}
/**
......@@ -79,7 +78,7 @@ class printing_printipp extends PrintingDriver
global $conf, $user, $db;
include_once DOL_DOCUMENT_ROOT.'/includes/printipp/CupsPrintIPP.php';
$ipp = new CupsPrintIPP();
$ipp->setLog(DOL_DATA_ROOT.'/dolibarr_printipp.log','file',3); // logging very verbose
$ipp->setHost($this->host);
......@@ -89,28 +88,31 @@ class printing_printipp extends PrintingDriver
if (! empty($this->user)) $ipp->setAuthentication($this->user,$this->password);
// select printer uri for module order, propal,...
$sql = 'SELECT rowid,printer_id,copy FROM '.MAIN_DB_PREFIX.'printing WHERE module="'.$module.'" AND driver="printipp" AND userid='.$user->id;
$sql = "SELECT rowid,printer_id,copy FROM ".MAIN_DB_PREFIX."printing WHERE module = '".$module."' AND driver = 'printipp' AND userid = ".$user->id;
$result = $db->query($sql);
if ($result)
{
$obj = $this->db->fetch_object($result);
if ($obj)
{
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))
{
dol_syslog("Will use default printer conf->global->PRINTIPP_URI_DEFAULT = ".$conf->global->PRINTIPP_URI_DEFAULT);
$ipp->setPrinterURI($conf->global->PRINTIPP_URI_DEFAULT);
}
else
{
{
return 'NoDefaultPrinterDefined';
}
}
}
else dol_print_error($db);
// Set number of copy
$ipp->setCopies($obj->copy);
$fileprint=$conf->{$module}->dir_output;
......@@ -118,7 +120,7 @@ class printing_printipp extends PrintingDriver
$fileprint.='/'.$file;
$ipp->setData($fileprint);
$ipp->printJob();
return '';
}
......@@ -170,8 +172,10 @@ class printing_printipp extends PrintingDriver
$html.= img_picto($langs->trans("Default"),'on');
}
else
$html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&amp;mode=test&amp;varname=PRINTIPP_URI_DEFAULT&amp;driver=printipp&amp;value='.urlencode($value).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
$html.= '</td>';
{
$html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&amp;mode=test&amp;varname=PRINTIPP_URI_DEFAULT&amp;driver=printipp&amp;value='.urlencode($value).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
$html.= '</td>';
$html.= '</tr>'."\n";
}
......
# Dolibarr language file - Source file is en_US - printing
PrintingSetup=Setup of Printing System
PrintingDesc=This module adds a Print button to send documents directly to a printer with various module.
PrintingSetup=Setup of Direct Printing System
PrintingDesc=This module adds a Print button to send documents directly to a printer (without opening document into an application) with various module.
ModuleDriverSetup=Setup Module Driver
PrintingDriverDesc=Configuration variables for printing driver.
ListDrivers=List of drivers
......@@ -8,3 +8,9 @@ PrintTestDesc=List of Printers.
FileWasSentToPrinter=File %s was sent to printer
NoActivePrintingModuleFound=No active module to print document
PleaseSelectaDriverfromList=Please select a driver from list.
SetupDriver=Driver setup
TestDriver=Test
TargetedPrinter=Targeted printer
UserConf=Setup per user
Module112000Name=Direct Printing
Module112000Desc=Enable Direct Printing System
......@@ -109,15 +109,15 @@ llxHeader('',$langs->trans("PrintingSetup"));
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("PrintingSetup"),$linkback,'setup');
$head=printingadmin_prepare_head();
$head=printingadmin_prepare_head($mode);
if ($mode == 'setup' && $user->admin)
{
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'">';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=setup&amp;driver='.$driver.'" autocomplete="off">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setconst">';
dol_fiche_head($head, $mode, $langs->trans("ModuleDriverSetup"), 0, 'technic');
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans("PrintingDriverDesc".$driver)."<br><br>\n";
......@@ -128,18 +128,22 @@ if ($mode == 'setup' && $user->admin)
print '<th>'.$langs->trans("Value").'</th>';
print "</tr>\n";
if (! empty($driver)) {
if (! empty($driver))
{
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
$classname = 'printing_'.$driver;
$langs->load($driver);
$printer = new $classname($db);
//print '<pre>'.print_r($printer, true).'</pre>';
$i=0;
foreach ($printer->conf as $key) {
foreach ($printer->conf as $key)
{
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td'.($key['required']?' class=required':'').'>'.$langs->trans($key['varname']).'</td><td>';
print '<input size="32" type="'.(empty($key['type'])?'text':$key['type']).'" name="setupdriver['.$i.'][value]" value="'.$conf->global->{$key['varname']}.'">';
print '<input size="32" type="'.(empty($key['type'])?'text':$key['type']).'" name="setupdriver['.$i.'][value]" value="'.$conf->global->{$key['varname']}.'"';
print isset($key['moreattributes'])?$key['moreattributes']:'';
print '>';
print '<input type="hidden" name="setupdriver['.$i.'][varname]" value="'.$key['varname'].'">';
print '&nbsp;'.($key['example']!=''?$langs->trans("Example").' : '.$key['example']:'');
print '</tr>';
......@@ -150,7 +154,8 @@ if ($mode == 'setup' && $user->admin)
}
print '</table>';
if (! empty($driver)) {
if (! empty($driver))
{
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'"></center>';
}
print '</form>';
......@@ -162,7 +167,7 @@ if ($mode == 'config' && $user->admin)
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans("PrintingDesc")."<br><br>\n";
print '<table class="noborder" width="100%">'."\n";
$var=true;
......@@ -170,7 +175,7 @@ if ($mode == 'config' && $user->admin)
print '<th>'.$langs->trans("Description").'</th>';
print '<th class="center">'.$langs->trans("Active").'</th>';
print '<th class="center">'.$langs->trans("Setup").'</th>';
print '<th class="center">'.$langs->trans("Test").'</th>';
print '<th class="center">'.$langs->trans("TargetedPrinter").'</th>';
print "</tr>\n";
$object = new PrintingDriver($db);
......@@ -212,12 +217,13 @@ if ($mode == 'config' && $user->admin)
if ($mode == 'test' && $user->admin)
{
dol_fiche_head($head, $mode, $langs->trans("PrintingTest"), 0, 'technic');
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans('PrintTestDesc'.$driver)."<br><br>\n";
print '<table class="noborder" width="100%">';
if (! empty($driver)) {
if (! empty($driver))
{
require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php';
$classname = 'printing_'.$driver;
$langs->load($driver);
......@@ -235,7 +241,7 @@ if ($mode == 'test' && $user->admin)
if ($mode == 'userconf' && $user->admin)
{
dol_fiche_head($head, $mode, $langs->trans("UserConf"), 0, 'technic');
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans('PrintUserConfDesc'.$driver)."<br><br>\n";
......
......@@ -26,9 +26,10 @@
/**
* Define head array for tabs of printing tools setup pages
*
* @return Array of head
* @param $mode string Mode
* @return Array of head
*/
function printingadmin_prepare_head()
function printingadmin_prepare_head($mode)
{
global $langs, $conf;
......@@ -40,20 +41,28 @@ function printingadmin_prepare_head()
$head[$h][2] = 'config';
$h++;
$head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=setup";
$head[$h][1] = $langs->trans("SetupDriver");
$head[$h][2] = 'setup';
$h++;
if ($mode == 'setup')
{
$head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=setup";
$head[$h][1] = $langs->trans("SetupDriver");
$head[$h][2] = 'setup';
$h++;
}
$head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=test";
$head[$h][1] = $langs->trans("TestDriver");
$head[$h][2] = 'test';
$h++;
if ($mode == 'test')
{
$head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=test";
$head[$h][1] = $langs->trans("TargetedPrinter");
$head[$h][2] = 'test';
$h++;
}
$head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=userconf";
$head[$h][1] = $langs->trans("UserConf");
$head[$h][2] = 'userconf';
$h++;
/** TODO This feature seem to be not ready yet.
$head[$h][0] = DOL_URL_ROOT."/printing/admin/printing.php?mode=userconf";
$head[$h][1] = $langs->trans("UserConf");
$head[$h][2] = 'userconf';
$h++;
*/
//$object=new stdClass();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment