From b3b3858965c97a9e184265fac83496ee56860865 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Mon, 19 Jul 2021 08:04:12 +0200
Subject: [PATCH] standardise get ext file modal and add via include
Create standard modal for insertion via include in firmcreate class and adserver view
---
assets/js/sccp_manager.js | 3 -
sccpManClasses/formcreate.class.php | 92 ++---------------------------
sccpManTraits/ajaxHelper.php | 73 ++++++++++++++++++++++-
sccpManTraits/helperFunctions.php | 66 ---------------------
views/advserver.model.php | 57 ++++--------------
views/getFileModal.html | 75 +++++++++++++++++++++++
6 files changed, 163 insertions(+), 203 deletions(-)
create mode 100644 views/getFileModal.html
diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js
index 6aed2ce..9503f6d 100644
--- a/assets/js/sccp_manager.js
+++ b/assets/js/sccp_manager.js
@@ -625,10 +625,7 @@ $(document).ready(function () {
url: 'ajax.php?module=sccp_manager&command=' + dev_cmd,
data: datas,
success: function (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');
diff --git a/sccpManClasses/formcreate.class.php b/sccpManClasses/formcreate.class.php
index 91663c2..6125126 100644
--- a/sccpManClasses/formcreate.class.php
+++ b/sccpManClasses/formcreate.class.php
@@ -650,97 +650,16 @@ class formcreate
}
}
$langArr = \FreePBX::Sccp_manager()->extconfigs->getExtConfig('sccp_lang');
- $localeArray = array_combine(array_keys($langArr),array_column($langArr, 'locale'));
+ $selectArray = array_combine(array_keys($langArr),array_column($langArr, 'locale'));
$requestType = 'locale';
?>
diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php
index c231591..cc46ec1 100644
--- a/sccpManTraits/ajaxHelper.php
+++ b/sccpManTraits/ajaxHelper.php
@@ -546,7 +546,6 @@ trait ajaxHelper {
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting();
}
-
foreach ($dbSaveArray as $rowToSave) {
$this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']);
}
@@ -555,8 +554,6 @@ trait ajaxHelper {
$save_settings[] = array('status' => true);
$this->createDefaultSccpXml();
- //$this->getFileListFromProvisioner();
-
return $save_settings;
}
@@ -585,6 +582,76 @@ trait ajaxHelper {
}
return $final;
}
+
+ public function getFilesFromProvisioner($request) {
+ dbug($request);
+ $filesToGet = array();
+ $provisionerUrl = "https://github.com/dkgroot/provision_sccp/raw/master/";
+ if (!file_exists("{$this->sccppath['tftp_path']}/masterFilesStructure.xml")) {
+ $this->getFileListFromProvisioner();
+ }
+ $tftpBootXml = simplexml_load_file("{$this->sccppath['tftp_path']}/masterFilesStructure.xml");
+
+ 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);
+ }
+ $firmwareDir = $tftpBootXml->xpath("//Directory[@name='firmware']");
+ $result = $firmwareDir[0]->xpath("//Directory[@name={$device}]");
+ $filesToGet = (array)$result[0]->FileName;
+ $totalFiles = count($filesToGet);
+ $filesRetrieved = 0;
+
+ foreach ($filesToGet as $srcFile) {
+ file_put_contents("{$this->sccppath['tftp_firmware_path']}/{$device}/{$srcFile}",
+ file_get_contents($provisionerUrl . (string)$result[0]->DirectoryPath . $srcFile));
+ $filesRetrieved ++;
+ $percentComplete = $filesRetrieved *100 / $totalFiles;
+ $data = "{$percentComplete},";
+ echo $data;
+ ob_flush();
+ flush();
+ }
+ $msg = "Firmware for {$device} has been successfully downloaded";
+ break;
+ case 'locale':
+ $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 = "{$percentComplete},";
+ echo $data;
+ ob_flush();
+ flush();
+
+ }
+ $msg = "{$locale} Locale has been successfully downloaded";
+ break;
+ default:
+ return false;
+ break;
+ }
+ return array('status' => true, 'message' => $msg, 'reload' => true);
+ }
}
?>
diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php
index 08c7ca0..7815b61 100644
--- a/sccpManTraits/helperFunctions.php
+++ b/sccpManTraits/helperFunctions.php
@@ -271,72 +271,6 @@ trait helperfunctions {
}
- public function getFilesFromProvisioner($request) {
- dbug($request);
- $filesToGet = array();
- $provisionerUrl = "https://github.com/dkgroot/provision_sccp/raw/master/";
- if (!file_exists("{$this->sccppath['tftp_path']}/masterFilesStructure.xml")) {
- $this->getFileListFromProvisioner();
- }
- $tftpBootXml = simplexml_load_file("{$this->sccppath['tftp_path']}/masterFilesStructure.xml");
-
- 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);
- }
- $firmwareDir = $tftpBootXml->xpath("//Directory[@name='firmware']");
- $result = $firmwareDir[0]->xpath("//Directory[@name={$device}]");
- $filesToGet = (array)$result[0]->FileName;
- foreach ($filesToGet as $srcFile) {
- file_put_contents("{$this->sccppath['tftp_firmware_path']}/{$device}/{$srcFile}",
- file_get_contents($provisionerUrl . (string)$result[0]->DirectoryPath . $srcFile));
- }
- $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() {
if ((array) $this->xml_data) {
diff --git a/views/advserver.model.php b/views/advserver.model.php
index 180eb85..ca51ac7 100644
--- a/views/advserver.model.php
+++ b/views/advserver.model.php
@@ -148,52 +148,21 @@
+sccppath['tftp_path']}/masterFilesStructure.xml");
+$firmwareDir = $tftpBootXml->xpath("//Directory[@name='firmware']");
-
-
-
-
-
-
-
-
-
- This site, dkgroot/provision_sccp, is unrelated to Sccp_Manager, and the files found cannot be warrantied
- If you accept this, please select the device type that you want to try to get files for and then Get Files From Provisioner
- Please be patient - this may take some time depending on your internet link
" ?>
-
-
-
-
-
-
-
-
-
+foreach ($firmwareDir[0] as $child) {
+ if (!empty((string)$child['name'])) {
+ $selectArray[(string)$child['name']] = (string)$child['name'];
+ }
+};
+include($_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/views/getFileModal.html');
+
+?>
diff --git a/views/getFileModal.html b/views/getFileModal.html
new file mode 100644
index 0000000..9d965f1
--- /dev/null
+++ b/views/getFileModal.html
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+
+
+
+ This site, dkgroot/provision_sccp, is unrelated to Sccp_Manager, and the files found cannot be warrantied
+ If you accept this, please select the {$requestType} that you want to try to get files for and then Get Files From Provisioner
+ Please be patient - this may take some time depending on your internet link
" ?>
+
+
+
+
+
+
+
+
+
+
+
+
+