diff --git a/htdocs/core/lib/takepos.lib.php b/htdocs/core/lib/takepos.lib.php index c7714501d905e..7d6a850f51016 100644 --- a/htdocs/core/lib/takepos.lib.php +++ b/htdocs/core/lib/takepos.lib.php @@ -73,3 +73,29 @@ function takepos_admin_prepare_head() return $head; } + + +/** + * Add permission on terminal + * + * @param Object $module Takepos module instance + * @return void + */ +function addTerminalPermissions($module) +{ + global $conf, $langs; + + $langs->load("cashdesk"); + + $r = array_key_last($module->rights); + $lastperm = 50190; // terminal permissions from 50191 to 50199 + $numterminals = max(1, getDolGlobalInt("TAKEPOS_NUM_TERMINALS")); + for ($i = 1; $i <= $numterminals; $i++) { + $r++; + $module->rights[$r][0] = $lastperm + $i; + $module->rights[$r][1] = 'Allow access to ' . (getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$i) != "" ? getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$i) : $langs->trans("TerminalName", $i)); + $module->rights[$r][2] = 'a'; + $module->rights[$r][3] = 0; + $module->rights[$r][4] = 'access_takepos_' . $i; + } +} diff --git a/htdocs/core/modules/modTakePos.class.php b/htdocs/core/modules/modTakePos.class.php index 999c38a26fb7a..f60d81374541d 100644 --- a/htdocs/core/modules/modTakePos.class.php +++ b/htdocs/core/modules/modTakePos.class.php @@ -206,6 +206,11 @@ public function __construct($db) $this->rights[$r][3] = 0; $this->rights[$r][4] = 'editorderedlines'; + // add permissions on terminals (from 50191 to 50199) + if (getDolGlobalInt('TAKEPOS_USE_TERMINAL_PERMISSIONS')) { + require_once DOL_DOCUMENT_ROOT."/core/lib/takepos.lib.php"; + addTerminalPermissions($this); + } // Main menu entries $this->menu = array(); // List of menus to add diff --git a/htdocs/langs/en_US/cashdesk.lang b/htdocs/langs/en_US/cashdesk.lang index 3baf275ab152d..4bd90480dcd58 100644 --- a/htdocs/langs/en_US/cashdesk.lang +++ b/htdocs/langs/en_US/cashdesk.lang @@ -158,3 +158,4 @@ InvoiceDiscount=Invoice discount InvoiceDiscountShort=Invoice disc. TestPrinterDesc=The server will send a simple test page to a ESC/POS printer TestPrinterDesc2=The server will send an enhanced test page with image and barcode to a ESC/POS printer +CloseTerminal=Close terminal diff --git a/htdocs/takepos/admin/setup.php b/htdocs/takepos/admin/setup.php index c94a0cc1db90b..39899dc25c895 100644 --- a/htdocs/takepos/admin/setup.php +++ b/htdocs/takepos/admin/setup.php @@ -95,6 +95,15 @@ } if (!$error) { + if (getDolGlobalInt('TAKEPOS_USE_TERMINAL_PERMISSIONS')) { + // add terminal permissions + require_once DOL_DOCUMENT_ROOT . '/core/modules/modTakePos.class.php'; + $module = new modTakePos($db); + $module->delete_permissions(); // $module->rights already loaded in module _construct so we don't lose anything + addTerminalPermissions($module); + $module->insert_permissions(1); + } + $db->commit(); } else { $db->rollback(); diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index a3092f66627f8..7418eb9585dde 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -64,6 +64,12 @@ /* * View */ +if (getDolGlobalInt('TAKEPOS_USE_TERMINAL_PERMISSIONS') && $action == 'closeTerminal') { + unset($_SESSION["takeposterminal"]); + unset($_COOKIE["takeposterminal"]); + setcookie("takeposterminal", "", time()-3600, '/', "", (empty($dolibarr_main_force_https) ? false : true), true); + exit; +} $thirdparty = new Societe($db); diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 935b8b02e7dee..029eff914587c 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -56,11 +56,31 @@ $setcurrency = GETPOST('setcurrency', 'aZ09'); $hookmanager->initHooks(array('takeposfrontend')); -if (empty($_SESSION["takeposterminal"])) { - if (getDolGlobalInt('TAKEPOS_NUM_TERMINALS') == 1) { - $_SESSION["takeposterminal"] = 1; // Use terminal 1 if there is only 1 terminal - } elseif (!empty($_COOKIE["takeposterminal"])) { - $_SESSION["takeposterminal"] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE["takeposterminal"]); // Restore takeposterminal from previous session + +if (getDolGlobalInt('TAKEPOS_USE_TERMINAL_PERMISSIONS')) { + // get user authorized terminals + $nb_auth_terms = 0; + $curterm = 0; + $numterminals = max(1, getDolGlobalInt("TAKEPOS_NUM_TERMINALS")); + for ($i = 1; $i <= $numterminals; $i++) { + if ($user->hasRights('takepos', 'access_takepos_' . $i)) { + $curterm = $i; + $nb_auth_terms++; + } + } + + // TERMINAL SELECTION IF NOT SET + if (empty($_SESSION["takeposterminal"])) { + if (empty($nb_auth_terms)) { + accessforbidden(); + } elseif ($nb_auth_terms > 1) { + if (!empty($_COOKIE["takeposterminal"]) && $user->hasRight('takepos', 'access_takepos_' . $_COOKIE["takeposterminal"])) { + $_SESSION["takeposterminal"] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE["takeposterminal"]); // Restore takeposterminal from previous session + } + } else { + $terminal_name = getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$curterm) != "" ? getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$curterm) : $langs->transnoentities("TerminalName", $curterm); + $_SESSION["takeposterminal"] = $curterm; + } } } @@ -202,6 +222,10 @@ } */ +function closeTerminal(modal) { + $.post("" , function(data) { if (modal) ModalBox('ModalTerminal'); }); +} + function ClearSearch(clearSearchResults) { console.log("ClearSearch"); $("#search").val(''); @@ -1035,6 +1059,30 @@ function WeighingScale(){ } $( document ).ready(function() { + 1) { + print "ModalBox('ModalTerminal');"; + } else { + $terminal_name = getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$curterm) != "" ? getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$curterm) : $langs->transnoentities("TerminalName", $curterm); + $_SESSION["takeposterminal"] = $curterm; + } + } + + if (empty($_SESSION["takeposterminal"])) { + if (empty($nb_auth_terms)) { + accessforbidden(); + } elseif ($nb_auth_terms > 1) { + print "ModalBox('ModalTerminal');"; + } + } + } + ?> + PrintCategories(0); LoadProducts(0); Refresh(); @@ -1136,7 +1184,14 @@ function scrollTo(){
@@ -1598,6 +1664,19 @@ function scrollTo(){
+ + +