diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php
index 4dfd1f023aa..28aa13104b1 100644
--- a/htdocs/compta/facture/class/api_invoices.class.php
+++ b/htdocs/compta/facture/class/api_invoices.class.php
@@ -332,6 +332,7 @@ class Invoices extends DolibarrApi
* @return int
* @throws RestException 400
* @throws RestException 401
+ * @throws RestException 403 Access not allowed for login
* @throws RestException 404
* @throws RestException 405
*/
@@ -349,6 +350,9 @@ class Invoices extends DolibarrApi
if (empty($orderid)) {
throw new RestException(400, 'Order ID is mandatory');
}
+ if (!DolibarrApi::_checkAccessToResource('commande', $orderid)) {
+ throw new RestException(403, 'Access not allowed on order for login '.DolibarrApiAccess::$user->login);
+ }
$order = new Commande($this->db);
$result = $order->fetch($orderid);
diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php
index eb0759ad109..c8789f6a961 100644
--- a/htdocs/core/js/lib_head.js.php
+++ b/htdocs/core/js/lib_head.js.php
@@ -1292,6 +1292,40 @@ $(document).ready(function() {
});
+// Code to manage the js for combo list with dependencies (called by extrafields_view.tpl.php)
+function showOptions(child_list, parent_list) {
+ var parentInput = $("select[name="+parent_list+"]");
+ if (parentInput.length === 0) { // when parent extra-field is in view mode and the child is edited directly on card (on line edit)
+ parentInput = $("input[name="+parent_list+"]");
+ }
+ if (parentInput.length > 0) {
+ var val = parentInput.val();
+ var parentVal = parent_list + ":" + val;
+ if (val > 0) {
+ $("select[name=\""+child_list+"\"] option[parent]").prop("disabled", true).hide(); // hide not work with select2 element so disabled it
+ $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").prop('disabled', false).show(); // show not work with select2 element so enabled it
+ } else {
+ $("select[name=\""+child_list+"\"] option").prop("disabled", false).show(); // show not work with select2 element so enabled it
+ }
+ }
+}
+function setListDependencies() {
+ console.log("setListDependencies");
+ jQuery("select option[parent]").parent().each(function() {
+ var child_list = $(this).attr("name");
+ var parent = $(this).find("option[parent]:first").attr("parent");
+ var infos = parent.split(":");
+ var parent_list = infos[0];
+ showOptions(child_list, parent_list);
+
+ /* Activate the handler to call showOptions on each future change */
+ $("select[name=\""+parent_list+"\"]").change(function() {
+ showOptions(child_list, parent_list);
+ });
+ });
+}
+
+
/*
* Hacky fix for a bug in select2 with jQuery 3.6.0's new nested-focus "protection"
* see: https://github.com/select2/select2/issues/5993
@@ -1315,4 +1349,5 @@ $(document).on('select2:open', (e) => {
}
?>
+
// End of lib_head.js.php
diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php
index 21b756f892f..37bf40b86ca 100644
--- a/htdocs/core/tpl/extrafields_view.tpl.php
+++ b/htdocs/core/tpl/extrafields_view.tpl.php
@@ -253,6 +253,7 @@ if (empty($reshook) && isset($extrafields->attributes[$object->table_element]['l
} else {
//var_dump($tmpkeyextra.'-'.$value.'-'.$object->table_element);
print $extrafields->showOutputField($tmpkeyextra, $value, '', $object->table_element);
+ print ''; // it's needed when to get parent value when extra-field list depend on parent extra-field list
}
print '';
@@ -267,31 +268,6 @@ if (empty($reshook) && isset($extrafields->attributes[$object->table_element]['l
print '
'."\n";