diff --git a/htdocs/admin/receiptprinter.php b/htdocs/admin/receiptprinter.php index 76aaa14d84c..5951aeaf2b2 100644 --- a/htdocs/admin/receiptprinter.php +++ b/htdocs/admin/receiptprinter.php @@ -65,13 +65,13 @@ if (!function_exists('gzdecode')) { } } + /* * Action */ if ($action == 'addprinter' && $user->admin) { $error = 0; - $db->begin(); if (empty($printername)) { $error++; setEventMessages($langs->trans("PrinterNameEmpty"), null, 'errors'); @@ -82,7 +82,8 @@ if ($action == 'addprinter' && $user->admin) { } if (!$error) { - $result = $printer->addPrinter($printername, GETPOST('printertypeid', 'int'), GETPOST('printerprofileid', 'int'), $parameter); + $db->begin(); + $result = $printer->addPrinter($printername, GETPOST('printertypeid', 'int'), GETPOST('printerprofileid', 'int'), $parameter); if ($result > 0) $error++; if (!$error) @@ -101,14 +102,14 @@ if ($action == 'addprinter' && $user->admin) { if ($action == 'deleteprinter' && $user->admin) { $error = 0; - $db->begin(); if (empty($printerid)) { $error++; setEventMessages($langs->trans("PrinterIdEmpty"), null, 'errors'); } if (!$error) { - $result = $printer->deletePrinter($printerid); + $db->begin(); + $result = $printer->deletePrinter($printerid); if ($result > 0) $error++; if (!$error) @@ -127,14 +128,14 @@ if ($action == 'deleteprinter' && $user->admin) { if ($action == 'updateprinter' && $user->admin) { $error = 0; - $db->begin(); if (empty($printerid)) { $error++; setEventMessages($langs->trans("PrinterIdEmpty"), null, 'errors'); } if (!$error) { - $result = $printer->updatePrinter($printername, GETPOST('printertypeid', 'int'), GETPOST('printerprofileid', 'int'), $parameter, $printerid); + $db->begin(); + $result = $printer->updatePrinter($printername, GETPOST('printertypeid', 'int'), GETPOST('printerprofileid', 'int'), $parameter, $printerid); if ($result > 0) $error++; if (!$error) { @@ -193,14 +194,14 @@ if ($action == 'testtemplate' && $user->admin) { if ($action == 'updatetemplate' && $user->admin) { $error = 0; - $db->begin(); if (empty($templateid)) { $error++; setEventMessages($langs->trans("TemplateIdEmpty"), null, 'errors'); } if (!$error) { - $result = $printer->updateTemplate($templatename, $template, $templateid); + $db->begin(); + $result = $printer->updateTemplate($templatename, $template, $templateid); if ($result > 0) $error++; if (!$error) { @@ -216,14 +217,14 @@ if ($action == 'updatetemplate' && $user->admin) { if ($action == 'addtemplate' && $user->admin) { $error = 0; - $db->begin(); if (empty($templatename)) { $error++; setEventMessages($langs->trans("TemplateNameEmpty"), null, 'errors'); } if (!$error) { - $result = $printer->addTemplate($templatename, $template); + $db->begin(); + $result = $printer->addTemplate($templatename, $template); if ($result > 0) $error++; if (!$error) { @@ -237,6 +238,29 @@ if ($action == 'addtemplate' && $user->admin) { $action = ''; } +if ($action == 'deletetemplate' && $user->admin) { + $error = 0; + if (empty($templateid)) { + $error++; + setEventMessages($langs->trans("TemplateIdEmpty"), null, 'errors'); + } + + if (!$error) { + $db->begin(); + $result = $printer->deleteTemplate($templateid); + if ($result > 0) $error++; + + if (!$error) { + $db->commit(); + setEventMessages($langs->trans("TemplateDeleted", $templatename), null); + } else { + $db->rollback(); + dol_print_error($db); + } + } + $action = ''; +} + /* * View @@ -251,6 +275,7 @@ print load_fiche_titre($langs->trans("ReceiptPrinterSetup"), $linkback, 'title_s $head = receiptprinteradmin_prepare_head($mode); +// mode = config if ($mode == 'config' && $user->admin) { print '
'; print ''; @@ -263,7 +288,7 @@ if ($mode == 'config' && $user->admin) { dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), -1, 'technic'); - print $langs->trans("ReceiptPrinterDesc")."

\n"; + print ''.$langs->trans("ReceiptPrinterDesc")."

\n"; print ''."\n"; print ''; @@ -276,6 +301,22 @@ if ($mode == 'config' && $user->admin) { $ret = $printer->listprinters(); $nbofprinters = count($printer->listprinters); + if ($action != 'editprinter') { + print ''; + print ''; + $ret = $printer->selectTypePrinter(); + print ''; + $ret = $printer->selectProfilePrinter(); + print ''; + print ''; + print ''; + print ''; + } + if ($ret > 0) { setEventMessages($printer->error, $printer->errors, 'errors'); } else { @@ -289,7 +330,9 @@ if ($mode == 'config' && $user->admin) { $ret = $printer->selectProfilePrinter($printer->listprinters[$line]['fk_profile']); print ''; print ''; - print ''; + print ''; print ''; } else { print ''; @@ -297,15 +340,15 @@ if ($mode == 'config' && $user->admin) { print ''; print ''; // edit icon - print ''; print ''; @@ -313,38 +356,10 @@ if ($mode == 'config' && $user->admin) { } } - if ($action != 'editprinter') { - if ($nbofprinters > 0) { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - - print ''; - print ''; - $ret = $printer->selectTypePrinter(); - print ''; - $ret = $printer->selectProfilePrinter(); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - } print '
'.$printer->resprint.''.$printer->profileresprint.''; + if ($action != 'editprinter') { + print '
'; + } + print '
'.$printer->profileresprint.''; + print '
'; + print '
'.$printer->listprinters[$line]['name'].''.$langs->trans($printer->listprinters[$line]['fk_profile_name']).''.$printer->listprinters[$line]['parameter'].''; + print ''; print img_picto($langs->trans("Edit"), 'edit'); print ''; // delete icon - print ''; + print ''; print img_picto($langs->trans("Delete"), 'delete'); print ''; // test icon - print ''; + print ''; print img_picto($langs->trans("TestPrinter"), 'printer'); print '
'.$langs->trans("Name").''.$langs->trans("Type").''.$langs->trans("Profile").''.$langs->trans("Parameters").'
'.$printer->resprint.''.$printer->profileresprint.'
'; dol_fiche_end(); - if ($action != 'editprinter') { - print '
'; - } else { - print '
'; - } print '
'; print '
'; @@ -374,6 +389,7 @@ if ($mode == 'config' && $user->admin) { print ''; } +// mode = template if ($mode == 'template' && $user->admin) { print '
'; print ''; @@ -383,16 +399,13 @@ if ($mode == 'template' && $user->admin) { print ''; } - - print load_fiche_titre($langs->trans("ReceiptPrinterTemplateDesc"), '', '')."

\n"; + print load_fiche_titre($langs->trans("ReceiptPrinterTemplateDesc"), '', ''); print ''."\n"; print ''; print ''; print ''; print ''; - print ''; - print ''; print "\n"; $ret = $printer->listPrintersTemplates(); //print '
'.print_r($printer->listprinterstemplates, true).'
'; @@ -405,22 +418,23 @@ if ($mode == 'template' && $user->admin) { if ($action == 'edittemplate' && $printer->listprinterstemplates[$line]['rowid'] == $templateid) { print ''; print ''; - print ''; print ''; } else { print ''; print ''; // edit icon - print ''; } @@ -428,15 +442,23 @@ if ($mode == 'template' && $user->admin) { } } - print '
'.$langs->trans("Name").''.$langs->trans("Template").'
'; + print ''; + print ''; print ''.$printer->listprinterstemplates[$line]['name'].''.nl2br(htmlentities($printer->listprinterstemplates[$line]['template'])).''; + print ''; print img_picto($langs->trans("Edit"), 'edit'); print ''; // delete icon - print ''; + print ''; print img_picto($langs->trans("Delete"), 'delete'); print ''; // test icon - print ''; + print ''; print img_picto($langs->trans("TestPrinterTemplate"), 'printer'); print '
'; if ($action != 'edittemplate') { - print ''; + print ''; print ''; - print ''; + print ''; + print ''; print ''; print ''; + print ''; + } - print '
'; + print ''; + + if ($action != 'edittemplate') { + print ''; + print '
'; } else { print '
'; } diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 8d9c449b972..09dcc3681b7 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -468,6 +468,26 @@ class dolReceiptPrinter extends Printer return $error; } + /** + * Function to delete a printer template in db + * + * @param int $templateid Template ID + * @return int 0 if OK; >0 if KO + */ + public function deleteTemplate($templateid) + { + global $conf; + $error = 0; + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; + $sql .= " WHERE rowid = ".((int) $this->db->escape($templateid)); + $sql .= " AND entity = ".$conf->entity; + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->errors[] = $this->db->lasterror; + } + return $error; + } /** * Function to Update a printer template in db diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 33590b17141..57d430fc9e4 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2008,3 +2008,6 @@ RssNote=Note: Each RSS feed definition provides a widget that you must enable to JumpToBoxes=Jump to Setup -> Widgets MeasuringUnitTypeDesc=Use here a value like "size", "surface", "volume", "weight", "time" MeasuringScaleDesc=The scale is the number of places you have to move the decimal part to match the default reference unit. For "time" unit type, it is the number of seconds. Values between 80 and 99 are reserved values. +TemplateAdded=Template added +TemplateUpdated=Template updated +TemplateDeleted=Template deleted \ No newline at end of file