From 2809b0796e8d61d11a1e2bd8f761ff8b87fb76a8 Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Mon, 5 Jul 2021 10:27:26 +0200 Subject: [PATCH] Simplify List Button Presentation Standardise method for all SL Types WIP - unused method needs to be removed after full testing --- conf/sccpgeneral.xml.v433 | 4 +- sccpManTraits/helperFunctions.php | 8 ++ views/formShowSysDefs.php | 228 +++++++++++++----------------- 3 files changed, 106 insertions(+), 134 deletions(-) diff --git a/conf/sccpgeneral.xml.v433 b/conf/sccpgeneral.xml.v433 index 4967003..22b2846 100644 --- a/conf/sccpgeneral.xml.v433 +++ b/conf/sccpgeneral.xml.v433 @@ -1196,7 +1196,7 @@ and open the template in the editor. Base Version before all crash :-) Support the use of regular-expression-based filename remapping - + devicetable sccpdevice @@ -1205,7 +1205,7 @@ and open the template in the editor. Base Version before all crash :-) Device Table: This is the devicetable for your realtime configuration. Don't change this unless you know what you are doing and have made all the appropriate changes in the rest of your Asterisk config files. There are two reasonable settings for this - the sccpdevice table or the sccpdeviceconfig view. If you do not want to use the realtime database anymore, you can set this to blank. NOT RECOMMENDED. - + linetable sccpline diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php index 530c226..3531a66 100644 --- a/sccpManTraits/helperFunctions.php +++ b/sccpManTraits/helperFunctions.php @@ -164,6 +164,14 @@ trait helperfunctions { return $result; } + function is_assoc($array) { + foreach (array_keys($array) as $k => $v) { + if ($k !== $v) + return true; + } + return false; + } + function tftpReadTestFile($remoteFileName, $host = "127.0.0.1") { // https://datatracker.ietf.org/doc/html/rfc1350 diff --git a/views/formShowSysDefs.php b/views/formShowSysDefs.php index f7f4da4..8b2a78f 100644 --- a/views/formShowSysDefs.php +++ b/views/formShowSysDefs.php @@ -473,72 +473,70 @@ $thisSccpView = new class{ } function addElementSL($child, $fvalues, $sccp_defaults, $npref) { + // TODO: Unused function. Integrated into SL2. To be removed after full testing. /* * Input element Select SLD - Date format - * SLZ - Time Zone - * * SLM - Music on hold * SLK - System KeySet * SLP - Dial Paterns */ - $day_format = array("D.M.Y", "D.M.YA", "Y.M.D", "YA.M.D", "M-D-Y", "M-D-YA", "D-M-Y", "D-M-YA", "Y-M-D", "YA-M-D", "M/D/Y", "M/D/YA", - "D/M/Y", "D/M/YA", "Y/M/D", "YA/M/D", "M/D/Y", "M/D/YA"); $res_n = (string)$child ->name; $res_id = $npref.$res_n; + // $select_opt is a simple array for these types. $select_opt = array(); - $softKeyList = array(); - $dialplan_list = array(); - if (function_exists('music_list')) { - $moh_list = music_list(); - } - if (!is_array($moh_list)) { - $moh_list = array('default'); - } + if (!empty($metainfo[$res_n])) { if ($child->meta_help == '1' || $child->help == 'Help!') { $child->help = $metaInfo[$res_n]; } } - if (empty($child->class)) { $child->class = 'form-control'; } - - if ($child['type'] == 'SLD') { - $select_opt= $day_format; - } - - if ($child['type'] == 'SLM') { - $select_opt= $moh_list; - } - if ($child['type'] == 'SLK') { - if (empty($softKeyList)) { + switch ($child['type']) { + case 'SLD': + $day_format = array("D.M.Y", "D.M.YA", "Y.M.D", "YA.M.D", "M-D-Y", "M-D-YA", "D-M-Y", "D-M-YA", "Y-M-D", "YA-M-D", "M/D/Y", "M/D/YA", + "D/M/Y", "D/M/YA", "Y/M/D", "YA/M/D", "M/D/Y", "M/D/YA"); + $select_opt= $day_format; + break; + case 'SLM': + if (function_exists('music_list')) { + $moh_list = music_list(); + } + if (!is_array($moh_list)) { + $moh_list = array('default'); + } + $select_opt= $moh_list; + break; + case 'SLK': $softKeyList = \FreePBX::Sccp_manager()->aminterface->sccp_list_keysets(); - } - $select_opt= $softKeyList; + $select_opt= $softKeyList; + break; + case 'SLP': + $dialplan_list = array(); + foreach (\FreePBX::Sccp_manager()->getDialPlanList() as $tmpkey) { + $tmp_id = $tmpkey['id']; + $dialplan_list[$tmp_id] = $tmp_id; + } + $select_opt= $dialplan_list; + break; } - if ($child['type'] == 'SLP') { - foreach (\FreePBX::Sccp_manager()->getDialPlanList() as $tmpkey) { - $tmp_id = $tmpkey['id']; - $dialplan_list[$tmp_id] = $tmp_id; + if (!empty($fvalues[$res_n])) { + if (!empty($fvalues[$res_n]['data'])) { + $child->value = $fvalues[$res_n]['data']; } - $select_opt= $dialplan_list; } ?>
-
-
+ class . '" id="' . $res_id . '">'; - if (!empty($fvalues[$res_n])) { - if (!empty($fvalues[$res_n]['data'])) { - $child->value = $fvalues[$res_n]['data']; - } - } + foreach ($select_opt as $key) { echo ''; } - ?> -
-
+ ?> + +
+
+ +
help);?> -
+ + name; $res_id = $npref.$res_n; $child->value =''; + // $select_opt is an associative array for these types. if (!empty($metainfo[$res_n])) { if ($child->meta_help == '1' || $child->help == 'Help!') { $child->help = $metaInfo[$res_n]; @@ -575,6 +578,15 @@ $thisSccpView = new class{ } } $select_opt= $syslangs; + + foreach (array_keys($select_opt) as $k => $v) { + if ($k !== $v) { + dbug('sys list is an associative array'); + } else { + dbug('sys list is a simple array'); + } + } + break; case 'SLT': $select_opt= $tftp_lang; @@ -601,6 +613,32 @@ $thisSccpView = new class{ $select_opt[$key]= $key; } } + case 'SLM': + if (function_exists('music_list')) { + $moh_list = music_list(); + } + if (!is_array($moh_list)) { + $moh_list = array('default'); + } + $select_opt= $moh_list; + break; + case 'SLD': + $day_format = array("D.M.Y", "D.M.YA", "Y.M.D", "YA.M.D", "M-D-Y", "M-D-YA", "D-M-Y", "D-M-YA", "Y-M-D", "YA-M-D", "M/D/Y", "M/D/YA", + "D/M/Y", "D/M/YA", "Y/M/D", "YA/M/D", "M/D/Y", "M/D/YA"); + $select_opt= $day_format; + break; + case 'SLK': + $softKeyList = \FreePBX::Sccp_manager()->aminterface->sccp_list_keysets(); + $select_opt= $softKeyList; + break; + case 'SLP': + $dialplan_list = array(); + foreach (\FreePBX::Sccp_manager()->getDialPlanList() as $tmpkey) { + $tmp_id = $tmpkey['id']; + $dialplan_list[$tmp_id] = $tmp_id; + } + $select_opt= $dialplan_list; + break; } if (empty($child->class)) { $child->class = 'form-control'; @@ -618,20 +656,25 @@ $thisSccpView = new class{ ?>
-
-
+ class . '" id="' . $res_id . '">'; foreach ($select_opt as $key => $val) { if (is_array($val)) { $opt_key = (isset($val['id'])) ? $val['id'] : $key; $opt_val = (isset($val['val'])) ? $val['val'] : $val; - } else { + } else if (\FreePBX::Sccp_manager()->is_assoc($select_opt)){ + // have associative array $opt_key = $key; $opt_val = $val; + } else { + // Have simple array + $opt_key = $val; + $opt_val = $val; } echo '
-
+ ?> + +
+ + +
help);?>
@@ -945,32 +940,6 @@ $thisSccpView = new class{ name; - $res_id = $npref.$res_n; - if (empty($child->class)) { - $child->class = 'form-control'; - } - ?> - - name; @@ -1068,16 +1037,14 @@ foreach ($items as $child) { case 'SLM': case 'SLK': case 'SLP': - $thisSccpView->addElementSL($child, $fvalues, $sccp_defaults,$npref); - break; + //$thisSccpView->addElementSL($child, $fvalues, $sccp_defaults,$npref); + //break; case 'SLS': case 'SLT': case 'SLA': case 'SLZ': - $thisSccpView->addElementSL2($child, $fvalues, $sccp_defaults,$npref); - break; case 'SL': - $thisSccpView->addElementSL3($child, $fvalues, $sccp_defaults,$npref); + $thisSccpView->addElementSL2($child, $fvalues, $sccp_defaults,$npref); break; case 'SDM': case 'SDMS': @@ -1091,9 +1058,6 @@ foreach ($items as $child) { case 'HLP': $thisSccpView->addElementHLP($child, $fvalues, $sccp_defaults,$npref); break; - case 'MINFO': - $thisSccpView->addElementMINFO($child, $npref); - break; case 'SLTZN': $thisSccpView->addElementSLTZN($child, $fvalues, $sccp_defaults,$npref); break;