diff --git a/htdocs/admin/receiptprinter.php b/htdocs/admin/receiptprinter.php index b31e1b8e180..261336ac047 100644 --- a/htdocs/admin/receiptprinter.php +++ b/htdocs/admin/receiptprinter.php @@ -28,12 +28,6 @@ // Load Dolibarr environment require '../main.inc.php'; - -require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/receiptprinter.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php'; - /** * @var Conf $conf * @var DoliDB $db @@ -41,6 +35,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php'; * @var Translate $langs * @var User $user */ +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/receiptprinter.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php'; // Load translation files required by the page $langs->loadLangs(array("admin", "receiptprinter")); @@ -54,6 +52,7 @@ $mode = GETPOST('mode', 'alpha'); $printername = GETPOST('printername', 'alpha'); $printerid = GETPOSTINT('printerid'); +$printertypeid = GETPOSTINT('printertypeid'); $parameter = GETPOST('parameter', 'alpha'); $template = GETPOST('template', 'alphanohtml'); @@ -93,13 +92,13 @@ if ($action == 'addprinter') { setEventMessages($langs->trans("PrinterNameEmpty"), null, 'errors'); } - if (empty($parameter)) { + if (empty($parameter) && $printertypeid > 1) { setEventMessages($langs->trans("PrinterParameterEmpty"), null, 'warnings'); } if (!$error) { $db->begin(); - $result = $printer->addPrinter($printername, GETPOSTINT('printertypeid'), GETPOSTINT('printerprofileid'), $parameter); + $result = $printer->addPrinter($printername, $printertypeid, GETPOSTINT('printerprofileid'), $parameter); if ($result > 0) { $error++; } @@ -109,7 +108,7 @@ if ($action == 'addprinter') { setEventMessages($langs->trans("PrinterAdded", $printername), null); } else { $db->rollback(); - dol_print_error($db); + setEventMessages($printer->error, $printer->errors, 'errors'); } } $action = ''; diff --git a/htdocs/core/modules/modReceiptPrinter.class.php b/htdocs/core/modules/modReceiptPrinter.class.php index 58515087a28..28bf1f0bb8d 100644 --- a/htdocs/core/modules/modReceiptPrinter.class.php +++ b/htdocs/core/modules/modReceiptPrinter.class.php @@ -146,6 +146,8 @@ class modReceiptPrinter extends DolibarrModules $sql = array( "CREATE TABLE IF NOT EXISTS ".MAIN_DB_PREFIX."printer_receipt (rowid integer AUTO_INCREMENT PRIMARY KEY, name varchar(128), fk_type integer, fk_profile integer, parameter varchar(128), entity integer) ENGINE=innodb;", "CREATE TABLE IF NOT EXISTS ".MAIN_DB_PREFIX."printer_receipt_template (rowid integer AUTO_INCREMENT PRIMARY KEY, name varchar(128), template text, entity integer) ENGINE=innodb;", + "ALTER TABLE ".MAIN_DB_PREFIX."printer_receipt ADD UNIQUE INDEX uk_printer_receipt (name, entity);", + "DELETE FROM ".MAIN_DB_PREFIX."printer_receipt_template WHERE name = '".$this->db->escape($langs->trans('Example'))."';", "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt_template (name,template,entity) VALUES ('".$this->db->escape($langs->trans('Example'))."', '".$this->db->escape($templateexample)."', 1);", );