diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php
index 5ce2dd0fca7..89260c35d03 100644
--- a/htdocs/core/class/html.formticket.class.php
+++ b/htdocs/core/class/html.formticket.class.php
@@ -755,7 +755,23 @@ class FormTicket
} elseif ($htmlname!='') {
$groupticket=GETPOST($htmlname, 'aZ09');
$child_id=GETPOST($htmlname.'_child_id', 'aZ09')?GETPOST($htmlname.'_child_id', 'aZ09'):0;
-
+ if (!empty($groupticket)) {
+ $tmpgroupticket = $groupticket;
+ $sql = "SELECT ctc.rowid, ctc.fk_parent, ctc.code FROM ".MAIN_DB_PREFIX."c_ticket_category as ctc WHERE ctc.code = '".$this->db->escape($tmpgroupticket)."'";
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $obj = $this->db->fetch_object($resql);
+ $selectedgroups[] = $obj->code;
+ while ($obj->fk_parent > 0) {
+ $sql = "SELECT ctc.rowid, ctc.fk_parent, ctc.code FROM ".MAIN_DB_PREFIX."c_ticket_category as ctc WHERE ctc.rowid ='".$this->db->escape($obj->fk_parent)."'";
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $obj = $this->db->fetch_object($resql);
+ $selectedgroups[] = $obj->code;
+ }
+ }
+ }
+ }
$arrayidused = array();
$arrayidusedconcat = array();
$arraycodenotparent = array();
@@ -794,7 +810,11 @@ class FormTicket
$grouplabel = $label;
$isparent = $obj->isparent;
- $iselected = $groupticket == $obj->code ?'selected':'';
+ if (is_array($selectedgroups)) {
+ $iselected = in_array($obj->code, $selectedgroups) ?'selected':'';
+ } else {
+ $iselected = $groupticket == $obj->code ?'selected':'';
+ }
$stringtoprint .= '';
if ($isparent == 'NOTPARENT') {
$arraycodenotparent[] = $groupvalue;
@@ -868,10 +888,14 @@ class FormTicket
if ($isparent == 'NOTPARENT') {
$arraycodenotparent[] = $groupvalue;
}
- $iselected = $groupticket == $obj->code ?'selected':'';
+ if (is_array($selectedgroups)) {
+ $iselected = in_array($obj->code, $selectedgroups) ?'selected':'';
+ } else {
+ $iselected = $groupticket == $obj->code ?'selected':'';
+ }
$stringtoprint .= '';
if (empty($tabscript[$groupcodefather])) {
- $tabscript[$groupcodefather] = 'if ($("#'.$htmlname.($levelid > 1 ?'_child_'.$levelid-1:'').'")[0].value == "'.dol_escape_js($groupcodefather).'"){
+ $tabscript[$groupcodefather] = 'if ($("#'.$htmlname.($levelid > 1 ?'_child_'.$levelid-1:'').'").val() == "'.dol_escape_js($groupcodefather).'"){
$(".'.$htmlname.'_'.dol_escape_htmltag($fatherid).'_child_'.$levelid.'").show()
console.log("We show childs tickets of '.$groupcodefather.' group ticket")
}else{
@@ -889,23 +913,15 @@ class FormTicket
$stringtoprint .='';
$stringtoprint .= ajax_combobox($htmlname);