diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php
index 61f0a9e8d15..5f223e00439 100644
--- a/htdocs/compta/facture/class/api_invoices.class.php
+++ b/htdocs/compta/facture/class/api_invoices.class.php
@@ -316,6 +316,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
*/
@@ -333,6 +334,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 ded651f7883..8dc6d952a6a 100644
--- a/htdocs/core/js/lib_head.js.php
+++ b/htdocs/core/js/lib_head.js.php
@@ -1180,4 +1180,39 @@ $(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);
+ });
+ });
+}
+
+
// 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 912dbe20113..b22a6015a01 100644
--- a/htdocs/core/tpl/extrafields_view.tpl.php
+++ b/htdocs/core/tpl/extrafields_view.tpl.php
@@ -257,6 +257,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 '';
@@ -271,31 +272,6 @@ if (empty($reshook) && isset($extrafields->attributes[$object->table_element]['l
print '
'."\n";