From 3d41c00199b9ade39948493397560f14b50a41f2 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Tue, 29 Jun 2021 16:13:03 +0200 Subject: [PATCH] New : selectGroupTicket multilevel >1 level --- htdocs/core/class/html.formticket.class.php | 153 ++++++++++++-------- 1 file changed, 90 insertions(+), 63 deletions(-) diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index f4e076640c4..daafa88333f 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -569,14 +569,14 @@ class FormTicket * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $maxlength Max length of label * @param string $morecss More CSS - * @param int $use_multilevel if != 0 create a multilevel select ( Do not use any of the other params) + * @param int $use_multilevel if > 0 create a multilevel select which use $htmlname example: $use_multilevel = 1 permit to have 2 select boxes. * @return void */ public function selectGroupTickets($selected = '', $htmlname = 'ticketcategory', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $morecss = '', $use_multilevel = 0) { global $langs, $user; - if ($use_multilevel == 0) { + if ($use_multilevel <= 0) { $ticketstat = new Ticket($this->db); dol_syslog(get_class($this)."::selectCategoryTickets ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG); @@ -655,12 +655,13 @@ class FormTicket } print ajax_combobox('select'.$htmlname); - } else { - $groupticket=GETPOST('groupticket', 'aZ09'); - $groupticketchild=GETPOST('groupticket_child', 'aZ09'); + } elseif ($htmlname!='') { + $groupticket=GETPOST($htmlname, 'aZ09'); + $groupticketchild=GETPOST($htmlname.'_child', 'aZ09'); $arraycodenotparent[] = ""; + $arrayidused = array(); $stringtoprint = ''.$langs->trans("GroupOfTicket").' '; - $stringtoprint .= ''; $stringtoprint .= ''; $sql = "SELECT ctc.rowid, ctc.code, ctc.label, ctc.fk_parent, "; @@ -682,10 +683,11 @@ class FormTicket $grouplabel = $obj->label; $isparent = $obj->isparent; $iselected = $groupticket == $obj->code ?'selected':''; - $stringtoprint .= ''; + $stringtoprint .= ''; if ($isparent == 'NOTPARENT') { $arraycodenotparent[] = $groupvalue; } + $arrayidused[]=$grouprowid; } $i++; } @@ -693,68 +695,93 @@ class FormTicket dol_print_error($this->db); } if ($num_rows == 1) { - return ''; + return ''; } $stringtoprint .= ' '; + $levelid = 1; + while ($levelid <= $use_multilevel) { + $tabscript = array(); + $stringtoprint .= ''; - $stringtoprint .= ''; - - $sql = "SELECT ctc.rowid, ctc.code, ctc.label, ctc.fk_parent, ctcjoin.code as codefather"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as ctc"; - $sql .= " JOIN ".MAIN_DB_PREFIX."c_ticket_category as ctcjoin ON ctc.fk_parent = ctcjoin.rowid"; - $sql .= " WHERE ctc.public = 1"; - $sql .= " AND ctc.active = 1"; - $sql .= " AND ctc.fk_parent <> 0"; - $sql .= $this->db->order('ctc.pos', 'ASC'); - $resql = $this->db->query($sql); - if ($resql) { - $num_rows = $this->db->num_rows($resql); - $i = 0; - while ($i < $num_rows) { - $obj = $this->db->fetch_object($resql); - if ($obj) { - $grouprowid = $obj->rowid; - $groupvalue = $obj->code; - $grouplabel = $obj->label; - $fatherid = $obj->fk_parent; - $groupcodefather = $obj->codefather; - $iselected = $groupticketchild == $obj->code ?'selected':''; - $stringtoprint .= ''; - $tabscript[] = 'if($("#groupticket")[0].value == "'.dol_escape_js($groupcodefather).'"){ - $(".groupticket_'.dol_escape_htmltag($fatherid).'_child").show() - }else{ - $(".groupticket_'.dol_escape_htmltag($fatherid).'_child").hide() - }'; + $sql = "SELECT ctc.rowid, ctc.code, ctc.label, ctc.fk_parent, ctcjoin.code as codefather, "; + $sql .= $this->db->ifsql("ctc.rowid NOT IN (SELECT ctcfather.rowid FROM llx_c_ticket_category as ctcfather JOIN llx_c_ticket_category as ctcjoin ON ctcfather.rowid = ctcjoin.fk_parent)", "'NOTPARENT'", "'PARENT'")." as isparent"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as ctc"; + $sql .= " JOIN ".MAIN_DB_PREFIX."c_ticket_category as ctcjoin ON ctc.fk_parent = ctcjoin.rowid"; + $sql .= " WHERE ctc.public = 1"; + $sql .= " AND ctc.active = 1"; + if (!empty($arrayidused)) { + $sql .= " AND ctc.fk_parent IN ( "; + foreach ($arrayidused as $idused) { + $sql .= $idused.", "; } - $i++; - } - } else { - dol_print_error($this->db); - } - $stringtoprint .=''; - - $stringtoprint .=''; + $sql .= $this->db->order('ctc.pos', 'ASC'); + $resql = $this->db->query($sql); + if ($resql) { + $num_rows = $this->db->num_rows($resql); + $i = 0; + $arrayidused=array(); + while ($i < $num_rows) { + $obj = $this->db->fetch_object($resql); + if ($obj) { + $grouprowid = $obj->rowid; + $groupvalue = $obj->code; + $grouplabel = $obj->label; + $isparent = $obj->isparent; + $fatherid = $obj->fk_parent; + $arrayidused[] = $grouprowid; + $groupcodefather = $obj->codefather; + if ($isparent == 'NOTPARENT') { + $arraycodenotparent[] = $groupvalue; + } + $iselected = $groupticketchild == $obj->code ?'selected':''; + $stringtoprint .= ''; + if (empty($tabscript[$groupcodefather])) { + $tabscript[$groupcodefather] = 'if($("#'.$htmlname.($levelid > 1 ?'_child_'.$levelid-1:'').'")[0].value == "'.dol_escape_js($groupcodefather).'"){ + $(".'.$htmlname.'_'.dol_escape_htmltag($fatherid).'_child_'.$levelid.'").show() + console.log("We show childs tickets of '.$groupcodefather.' group ticket") + }else{ + $(".'.$htmlname.'_'.dol_escape_htmltag($fatherid).'_child_'.$levelid.'").hide() + console.log("We hide childs tickets of '.$groupcodefather.' group ticket") + }'; + } + } + $i++; + } + } else { + dol_print_error($this->db); + } + $stringtoprint .=''; + + $stringtoprint .=''; + } return $stringtoprint; } }