diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index 79ec882..7009fe8 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -754,6 +754,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { private function findInstLangs() { //locales and languages are installed in the tftp_lang_path $result = array(); + // TODO: Installer comes here so need to set default / ? $langDir = $this->sccppath["tftp_lang_path"]; $localeJar = 'be-sccp.jar'; // This jar should exist if the locale is populated $langArr = $this->extconfigs->getExtConfig('sccp_lang'); @@ -839,11 +840,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $dir = $this->sccppath["tftp_dialplan_path"] . '/dial*.xml'; $base_len = strlen($this->sccppath["tftp_dialplan_path"]) + 1; $res = glob($dir); - $dp_list = array(); foreach ($res as $key => $value) { $res[$key] = array('id' => substr($value, $base_len, -4), 'file' => substr($value, $base_len)); } - return $res; } @@ -877,34 +876,32 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } /* - * Update Butons Labels on mysql DB + * Update buttons Labels on mysql DB */ private function updateSccpButtons($hw_list = array()) { $save_buttons = array(); + $button_list = array(); if (!empty($hw_list)) { - $buton_list = array(); foreach ($hw_list as $value) { - $buton_tmp = $this->dbinterface->getSccpDeviceTableData("get_sccpdevice_buttons", array('buttontype' => 'speeddial', 'id' => $value['name'])); - if (!empty($buton_tmp)) { - $buton_list = array_merge($buton_list, $buton_tmp); - } + $button_tmp = (array)$this->dbinterface->getSccpDeviceTableData("get_sccpdevice_buttons", array('buttontype' => 'speeddial', 'id' => $value['name'])); + $button_list = array_merge($button_list, $button_tmp); } } else { - $buton_list = $this->dbinterface->getSccpDeviceTableData("get_sccpdevice_buttons", array('buttontype' => 'speeddial')); + $button_list = $this->dbinterface->getSccpDeviceTableData("get_sccpdevice_buttons", array('buttontype' => 'speeddial')); } - if (empty($buton_list)) { + if (empty($button_list)) { return array('Response' => ' 0 buttons found ', 'data' => ''); } $copy_fld = array('ref', 'reftype', 'instance', 'buttontype'); - $user_list = $user_list = $this->dbinterface->get_db_SccpTableByID("SccpExtension", array(), 'name'); - foreach ($buton_list as $value) { + $extList = $extList = $this->dbinterface->get_db_SccpTableByID("SccpExtension", array(), 'name'); + foreach ($button_list as $value) { $btn_opt = explode(',', $value['options']); $btn_id = $btn_opt[0]; - if (!empty($user_list[$btn_id])) { - if ($user_list[$btn_id]['label'] != $value['name']) { - $btn_data['name'] = $user_list[$btn_id]['label']; + if (!empty($extList[$btn_id])) { + if ($extList[$btn_id]['label'] != $value['name']) { + $btn_data['name'] = $extList[$btn_id]['label']; foreach ($copy_fld as $ckey) { $btn_data[$ckey] = $value[$ckey]; } diff --git a/assets/css/sccp_manager.css b/assets/css/sccp_manager.css index 0d64c6c..05077eb 100644 --- a/assets/css/sccp_manager.css +++ b/assets/css/sccp_manager.css @@ -10,10 +10,9 @@ and open the template in the editor. .sccpmultiselect { min-height: 100px; padding: 1px 1px; - + } .sccpbtn { min-height: 10px; padding: 1px 1px; } - diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index 6e7e7f9..6aed2ce 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -195,6 +195,8 @@ $(document).ready(function () { }); // --------------------------------------- + + $('.btnMultiselect').click(function (e) { var kid = $(this).data('id'); if ($(this).data('key') === 'Right') { @@ -482,6 +484,8 @@ $(document).ready(function () { }); + + $('.sccp_update').on('click', function (e) { // console.log($(this).data('id')); @@ -513,16 +517,6 @@ $(document).ready(function () { } // ----------------------- Server.model form ---------------- - if ($(this).data('id') === 'get_ext_files') { - var dev_cmd = 'get_ext_files'; - var dev_fld = ["device"]; - datas = 'enabled=0' + '&' + 'type=firmware' + '&' + 'name=' + '&'; - - for (var i = 0; i < dev_fld.length; i++) { - datas = datas + dev_fld[i] + '=' + $('#ext_' + dev_fld[i]).val() + '&'; - } - ; - } if ($(this).data('id') === 'model_add') { var dev_cmd = 'model_add'; // var dev_fld = ["model","vendor","dns","buttons","loadimage","loadinformationid","validate","enabled"]; @@ -631,7 +625,10 @@ $(document).ready(function () { url: 'ajax.php?module=sccp_manager&command=' + dev_cmd, data: datas, success: function (data) { -// console.log(data); + //$('.progress-bar').css('width', data.progress + '%'); + //console.log(data.progress); + + $('#pleaseWaitDialog').modal('hide'); if (data.status === true) { if (data.table_reload === true) { $('table').bootstrapTable('refresh'); @@ -664,6 +661,81 @@ $(document).ready(function () { } }); + + $('.sccp_get_ext').on('click', function (e) { +// console.log($(this).data('id')); + + +// ----------------------- Get external Files---------------- + if ($(this).data('id') === 'get_ext_files') { + var dev_cmd = 'get_ext_files'; + var dev_fld = ["device", "locale"]; + datas = 'type=' + $(this).data('type') + '&' + 'name=' + '&'; + + for (var i = 0; i < dev_fld.length; i++) { + datas = datas + dev_fld[i] + '=' + $('#ext_' + dev_fld[i]).val() + '&'; + } + ; + } + + if (dev_cmd !== '') { + $.ajax({ + // Need to modify xhr here to add listener + xhr: function() { + const controller = new AbortController(); + var xhr = new XMLHttpRequest(); + xhr.addEventListener('progress', function(evt) { + var result = evt.srcElement.responseText.split(','); + var percentComplete = result[result.length - 2]; //last element is empty. + $('#progress-bar').css('width', percentComplete + '%'); + if (percentComplete == 100 ) { + controller.abort(); + } + }, true, { signal: controller.signal }); + return xhr; + }, + type: 'POST', + url: 'ajax.php?module=sccp_manager&command=' + dev_cmd, + data: datas, + success: function (data) { + + $('#pleaseWaitDialog').modal('hide'); + data = JSON.parse(data.replace(/^(.*\{)/,"\{")); + if (data.status === true) { + if (data.table_reload === true) { + $('table').bootstrapTable('refresh'); + } + if (data.message) { + fpbxToast(data.message,_('Operation Result'), 'success'); + if (data.reload === true) { + //Need setTimout or reload will kill Toast + setTimeout(function(){location.reload();},500); + } + } + } else { + if (Array.isArray(data.message)) { + data.message.forEach(function (entry) { + fpbxToast(data.message[1],_('Error Result'), 'warning'); + }); + } else { + if (data.message) { + fpbxToast(data.message,_('Error Result'), 'warning'); + } else { + if (data) { + bs_alert(data,data.status); + } + } + } + } + } + + }); + } + + }); + + + $('#cr_sccp_phone_xml').on('click', function (e) { // console.log("asasdasdasdasd"); // console.log($('#update-sccp-phone').find(':selected').data('val')); @@ -1055,6 +1127,14 @@ function hex2bin(hex) return String.fromCharCode.apply(String, bytes); } +function showProgress() { + $('#pleaseWaitDialog').modal(); +} + +function closeProgress() { + $('#pleaseWaitDialog').modal('hide'); +} + function sleep(milliseconds) { var start = new Date().getTime(); diff --git a/conf/sccpgeneral.xml.v433 b/conf/sccpgeneral.xml.v433 index 1398d3a..43b0045 100644 --- a/conf/sccpgeneral.xml.v433 +++ b/conf/sccpgeneral.xml.v433 @@ -12,7 +12,8 @@ and open the template in the editor. Base Version before all crash :-) * Input element Select SLD - Date format * SLZ - Time Zone * SLTZN - Time Zone List - * SLT - TFTP Lang + * SLT - Installed Languages + * SLTD - Device Languages * SLM - Music on hold * SLK - System KeySet * SLG - call groups @@ -246,14 +247,14 @@ and open the template in the editor. Base Version before all crash :-) netlang English_United_States - The Network locales allows the phone to play tones (ringing, busy etc.) native to the phone's country. + The Network locales allows the phone to play tones (ringing, busy etc.) native to the phone's country. If No language packs found is shown, you need to add locales in the tftp server - + devlang English_United_States - The user locale allows the phone to display text (menu items, soft keys etc.) native to the phone's language. + The user locale allows the phone to display text (menu items, soft keys etc.) native to the phone's language. If No language packs found is shown, you need to add locales in the tftp server @@ -1334,19 +1335,19 @@ and open the template in the editor. Base Version before all crash :-) Time Zone offset - + netlang English_United_States - The Network locales allows the phone to play tones (ringing, busy etc.) native to the phone's country. + The Network locales allows the phone to play tones (ringing, busy etc.) native to the phone's country. If No language packs found is shown, you need to add locales in the tftp server - + devlang English_United_States - The user locale allows the phone to display text (menu items, soft keys etc.) native to the phone's language. + The user locale allows the phone to display text (menu items, soft keys etc.) native to the phone's language. If No language packs found is shown, you need to add locales in the tftp server diff --git a/install.php b/install.php index 6eab166..8ca382c 100644 --- a/install.php +++ b/install.php @@ -867,6 +867,7 @@ function checkTftpServer() { $possibleFtpDirs = array('/srv', '/srv/tftp','/var/lib/tftp', '/tftpboot'); // write a couple of sentinels to different distro tftp locations in the filesystem + // TODO: Depending on distro, do we have write permissions foreach ($possibleFtpDirs as $dirToTest) { if (is_dir($dirToTest) && is_writable($dirToTest)) { $tempFile = "${dirToTest}/{$remoteFileName}"; diff --git a/sccpManClasses/extconfigs.class.php b/sccpManClasses/extconfigs.class.php index 9c8d923..117e569 100644 --- a/sccpManClasses/extconfigs.class.php +++ b/sccpManClasses/extconfigs.class.php @@ -305,6 +305,7 @@ class extconfigs if (file_exists($adv_ini)){ rename($adv_ini, "{$adv_ini}.old"); } + // TODO: index file is not declared $indexFile = fopen($adv_ini,'w'); fwrite($indexFile, "[main]\n"); foreach ($adv_config as $advKey => $advVal) { diff --git a/sccpManClasses/formcreate.class.php b/sccpManClasses/formcreate.class.php index ee49732..91663c2 100644 --- a/sccpManClasses/formcreate.class.php +++ b/sccpManClasses/formcreate.class.php @@ -501,8 +501,12 @@ class formcreate } $select_opt= $syslangs; break; - case 'SLT': - $select_opt= $installedLangs; + case 'SLTD': + $select_opt = array('xx' => 'No language packs found'); + if (!empty($installedLangs)) { + $select_opt = (array)$installedLangs; + + } break; case 'SLZ': $timeZoneOffsetList = array('-12' => 'GMT -12', '-11' => 'GMT -11', '-10' => 'GMT -10', '-09' => 'GMT -9', @@ -514,7 +518,7 @@ class formcreate $select_opt= $timeZoneOffsetList; break; case 'SLA': - $select_opt =''; + $select_opt = array(); if (!empty($fvalues[$res_n])) { if (!empty($fvalues[$res_n]['data'])) { $res_value = explode(';', $fvalues[$res_n]['data']); @@ -616,6 +620,167 @@ class formcreate 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]; + } + } + $select_opt = array('xx' => 'No language packs found'); + if (!empty($installedLangs)) { + $select_opt = $installedLangs; + } + + if (empty($child->class)) { + $child->class = 'form-control'; + } + if (!empty($fvalues[$res_n])) { + if (!empty($fvalues[$res_n]['data'])) { + $child->value = $fvalues[$res_n]['data']; + } + } + if (empty($child->value)) { + if (!empty($child->default)) { + $child->value = $child->default; + } + } + $langArr = \FreePBX::Sccp_manager()->extconfigs->getExtConfig('sccp_lang'); + $localeArray = array_combine(array_keys($langArr),array_column($langArr, 'locale')); + $requestType = 'locale'; + ?> +
+
+
+ + + + + + +
+ + +
+
+
+ class . '" id="' . $res_id . '">'; + foreach ($select_opt as $key => $val) { + $opt_key = $key; + $opt_val = $val; + + echo '"; + } + ?> + +
+
+
+ +
+ +
+
+
+
+ help);?> +
+
+
+ + getFilesFromProvisioner($request['type'],$request['name'],$request['device']); - return $result; + return $this->getFilesFromProvisioner($request); break; } } diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php index f911d96..6432b23 100644 --- a/sccpManTraits/helperFunctions.php +++ b/sccpManTraits/helperFunctions.php @@ -271,15 +271,17 @@ trait helperfunctions { } - public function getFilesFromProvisioner($type = '',$name = '',$device = '') { + public function getFilesFromProvisioner($request) { + dbug($request); $filesToGet = array(); $provisionerUrl = "https://github.com/dkgroot/provision_sccp/raw/master/"; if (!$tftpBootXml = simplexml_load_file("{$this->sccppath['tftp_path']}/masterFilesStructure.xml")) { $this->getFileListFromProvisioner(); $tftpBootXml = simplexml_load_file("{$this->sccppath['tftp_path']}/masterFilesStructure.xml"); } - switch ($type) { + switch ($request['type']) { case 'firmware': + $device = $request['device']; if (!is_dir("{$this->sccppath['tftp_firmware_path']}/{$device}")) { mkdir("{$this->sccppath['tftp_firmware_path']}/{$device}", 0755); } @@ -290,13 +292,49 @@ trait helperfunctions { file_put_contents("{$this->sccppath['tftp_firmware_path']}/{$device}/{$srcFile}", file_get_contents($provisionerUrl . (string)$result[0]->DirectoryPath . $srcFile)); } - return "thanks for trying Diederik :-)"; - break; + $msg = "Firmware for {$device} has been successfully downloaded"; + break; + case 'locales': + $locale = $request['locale']; + $langArr = \FreePBX::Sccp_manager()->extconfigs->getExtConfig('sccp_lang'); + $language = $langArr[$locale]['locale']; + if (!is_dir("{$this->sccppath['tftp_lang_path']}/{$language}")) { + mkdir("{$this->sccppath['tftp_lang_path']}/{$language}", 0755); + } + + $localeDir = $tftpBootXml->xpath("//Directory[@name='locales']"); + $localeDir = $localeDir[0]->xpath("//Directory[@name='languages']"); + $result = $localeDir[0]->xpath("//Directory[@name='{$language}']"); + $filesToGet = (array)$result[0]->FileName; + + $totalFiles = count($filesToGet); + $filesRetrieved = 0; + + foreach ($filesToGet as $srcFile) { + + file_put_contents("{$this->sccppath['tftp_lang_path']}/{$language}/{$srcFile}", + file_get_contents($provisionerUrl . (string)$result[0]->DirectoryPath . $srcFile)); + $filesRetrieved ++; + $percentComplete = $filesRetrieved *100 / $totalFiles; + + //$data = array('data' => array('percentComplete' => $percentComplete)); + $data = "{$percentComplete},"; + //echo "id: $filesRetrieved" . PHP_EOL; + //echo json_encode($data); + echo $data; + //echo PHP_EOL; + ob_flush(); + flush(); + + } + $msg = "{$locale} Locale has been successfully downloaded"; + break; default: return false; break; } + return array('status' => true, 'message' => $msg, 'reload' => true); } public function initVarfromXml() { diff --git a/views/advserver.model.php b/views/advserver.model.php index f24c682..180eb85 100644 --- a/views/advserver.model.php +++ b/views/advserver.model.php @@ -172,7 +172,7 @@
- +
@@ -188,7 +188,7 @@
diff --git a/views/formShowSysDefs.php b/views/formShowSysDefs.php index 402b48e..bcb1022 100644 --- a/views/formShowSysDefs.php +++ b/views/formShowSysDefs.php @@ -77,12 +77,15 @@ foreach ($items as $child) { case 'SLK': case 'SLP': case 'SLS': - case 'SLT': + case 'SLTD': case 'SLA': case 'SLZ': case 'SL': \FreePbx::sccp_manager()->formcreate->addElementSL($child, $fvalues, $sccp_defaults,$npref, $installedLangs); break; + case 'SLT': + \FreePbx::sccp_manager()->formcreate->addElementSLT($child, $fvalues, $sccp_defaults,$npref, $installedLangs); + break; case 'SDM': case 'SDMS': case 'SDE': @@ -105,4 +108,3 @@ if ($h_show==1) { echo ''; } ?> -installedLangs