standardise get ext file modal and add via include

Create standard modal for insertion via include in firmcreate class and adserver view
This commit is contained in:
steve-lad 2021-07-19 08:04:12 +02:00
parent d9fa0ad8bf
commit b3b3858965
6 changed files with 163 additions and 203 deletions

View file

@ -625,10 +625,7 @@ $(document).ready(function () {
url: 'ajax.php?module=sccp_manager&command=' + dev_cmd, url: 'ajax.php?module=sccp_manager&command=' + dev_cmd,
data: datas, data: datas,
success: function (data) { success: function (data) {
//$('.progress-bar').css('width', data.progress + '%');
//console.log(data.progress);
$('#pleaseWaitDialog').modal('hide');
if (data.status === true) { if (data.status === true) {
if (data.table_reload === true) { if (data.table_reload === true) {
$('table').bootstrapTable('refresh'); $('table').bootstrapTable('refresh');

View file

@ -650,97 +650,16 @@ class formcreate
} }
} }
$langArr = \FreePBX::Sccp_manager()->extconfigs->getExtConfig('sccp_lang'); $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'; $requestType = 'locale';
?> ?>
<div class="element-container"> <div class="element-container">
<div class="row"> <div class="row">
<div class="form-group"> <div class="form-group">
<!--Begin modal include--> <?php
<div class="modal fade get_ext_file" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> include($_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/views/getFileModal.html');
<div class="modal-dialog modal-lg" role="document"> ?>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="gridSystemModalLabel"><?php echo _('Get Files From Provisioner');?></h4>
</div>
<div class="modal-body">
<div class="element-container">
<div class="row">
<div class="col-md-12">
<?php echo "Sccp_Manager will try to download {$requestType} files from Provision_Sccp on GitHub.<br>
This site, dkgroot/provision_sccp, is unrelated to Sccp_Manager, and the files found cannot be warrantied<br>
If you accept this, please select the {$requestType} that you want to try to get files for and then Get Files From Provisioner<br><br>
Please be patient - this may take some time depending on your internet link<br><br>" ?>
</div>
</div>
</div>
<div class="element-container">
<div class="row">
<div class="form-group">
<div class="col-md-3">
<label class="control-label" for="get_model_files"><?php echo _('Fetch Files for');?></label>
<i class="fa fa-question-circle fpbx-help-icon" ></i>
</div>
<div class="col-md-3">
<div class = "lnet form-group form-inline" data-nextid=1>
<?php
echo "<select class={$child->class} id='ext_locale'>";
foreach ($localeArray as $key => $val) {
echo "<option value= '{$key}'";
if ($key == 'en_GB') {
echo " selected='selected'";
}
echo ">{$val}</option>";
}
?>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span id="new_model-help" class="help-block fpbx-help-block">Help.</span>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo _('Cancel');?></button>
<button type="button" class="btn btn-primary sccp_get_ext" data-id="get_ext_files" data-type="locales" onclick="showProgress();" id="get_model_files" data-dismiss="modal"><?php echo _('Get Files from Provisioner');?></button>
</div>
</div>
</div>
</div>
<!--End modal include-->
<!--Start progress modal include-->
<div id="pleaseWaitDialog" class="modal" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1>Getting files .....please wait</h1>
</div>
<div class="modal-body">
<div class="progress">
<div id="progress-bar" class="progress-bar progress-bar-striped progress-bar-animated active" role="progressbar" style="width:0%">
</div>
</div>
<!--
<div class="progress progress-striped active">
<div class="progress-bar" style="width: 100%;">
</div>
</div>
-->
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!--End progress modal include-->
<div class="col-md-3"> <div class="col-md-3">
<label class="control-label" for="<?php echo $res_id; ?>"><?php echo _($child->label);?></label> <label class="control-label" for="<?php echo $res_id; ?>"><?php echo _($child->label);?></label>
<i class="fa fa-question-circle fpbx-help-icon" data-for="<?php echo $res_id; ?>"></i> <i class="fa fa-question-circle fpbx-help-icon" data-for="<?php echo $res_id; ?>"></i>
@ -764,10 +683,9 @@ class formcreate
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target=".get_ext_file"><i class="fa fa-bolt"></i> <?php echo _("Get language from Provisioner"); ?> <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target=".get_ext_file"><i class="fa fa-bolt"></i> <?php echo _("Get language from Provisioner");?>
</button> </button>
</div> </div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">

View file

@ -546,7 +546,6 @@ trait ajaxHelper {
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); $this->sccpvalues = $this->dbinterface->get_db_SccpSetting();
} }
foreach ($dbSaveArray as $rowToSave) { foreach ($dbSaveArray as $rowToSave) {
$this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']); $this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']);
} }
@ -555,8 +554,6 @@ trait ajaxHelper {
$save_settings[] = array('status' => true); $save_settings[] = array('status' => true);
$this->createDefaultSccpXml(); $this->createDefaultSccpXml();
//$this->getFileListFromProvisioner();
return $save_settings; return $save_settings;
} }
@ -585,6 +582,76 @@ trait ajaxHelper {
} }
return $final; 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);
}
} }
?> ?>

View file

@ -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() { public function initVarfromXml() {
if ((array) $this->xml_data) { if ((array) $this->xml_data) {

View file

@ -148,52 +148,21 @@
</div> </div>
</div> </div>
</div> </div>
<?php
$requestType = 'firmware';
$selectArray = array();
$tftpBootXml = simplexml_load_file("{$this->sccppath['tftp_path']}/masterFilesStructure.xml");
$firmwareDir = $tftpBootXml->xpath("//Directory[@name='firmware']");
<div class="modal fade get_ext_file" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> foreach ($firmwareDir[0] as $child) {
<div class="modal-dialog modal-lg" role="document"> if (!empty((string)$child['name'])) {
<div class="modal-content"> $selectArray[(string)$child['name']] = (string)$child['name'];
<div class="modal-header"> }
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> };
<h4 class="modal-title" id="gridSystemModalLabel"><?php echo _('Get Files From Provisioner');?></h4>
</div>
<div class="modal-body">
<div class="element-container">
<div class="row">
<div class="col-md-12">
<?php echo "Sccp_Manager will try to download the firmware and template files from Provision_Sccp on GitHub.<br>
This site, dkgroot/provision_sccp, is unrelated to Sccp_Manager, and the files found cannot be warrantied<br>
If you accept this, please select the device type that you want to try to get files for and then Get Files From Provisioner<br><br>
Please be patient - this may take some time depending on your internet link<br><br>" ?>
</div>
</div>
</div>
<div class="element-container">
<div class="row">
<div class="form-group">
<div class="col-md-3">
<label class="control-label" for="get_model_files"><?php echo _('Fetch Files for');?></label>
<i class="fa fa-question-circle fpbx-help-icon" ></i>
</div>
<div class="col-md-9">
<input type="text" class="form-control" id="ext_device" name="new_model" value="79XX">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span id="new_model-help" class="help-block fpbx-help-block">Help.</span>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo _('Cancel');?></button>
<button type="button" class="btn btn-primary sccp_get_ext" data-id="get_ext_files" data-type="firmware" id="get_model_files" data-dismiss="modal"><?php echo _('Get Files from Provisioner');?></button>
</div>
</div>
</div>
</div>
include($_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/views/getFileModal.html');
?>
<div class="modal fade" id="edit_model" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> <div class="modal fade" id="edit_model" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document"> <div class="modal-dialog modal-lg" role="document">
<div class="modal-content"> <div class="modal-content">

75
views/getFileModal.html Normal file
View file

@ -0,0 +1,75 @@
<!--Begin modal include-->
<div class="modal fade get_ext_file" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="gridSystemModalLabel"><?php echo _('Get Files From Provisioner');?></h4>
</div>
<div class="modal-body">
<div class="element-container">
<div class="row">
<div class="col-md-12">
<?php echo "Sccp_Manager will try to download {$requestType} files from Provision_Sccp on GitHub.<br>
This site, dkgroot/provision_sccp, is unrelated to Sccp_Manager, and the files found cannot be warrantied<br>
If you accept this, please select the {$requestType} that you want to try to get files for and then Get Files From Provisioner<br><br>
Please be patient - this may take some time depending on your internet link<br><br>" ?>
</div>
</div>
</div>
<div class="element-container">
<div class="row">
<div class="form-group">
<div class="col-md-3">
<label class="control-label" for="get_model_files"><?php echo _('Fetch Files for');?></label>
<i class="fa fa-question-circle fpbx-help-icon" ></i>
</div>
<div class="col-md-3">
<div class = "lnet form-group form-inline" data-nextid=1>
<?php
if ($requestType == 'firmware') {
echo "<select class='form-control' id='ext_device'>";
} else {
echo "<select class='form-control' id='ext_locale'>";
}
foreach ($selectArray as $key => $val) {
echo "<option value= '{$key}' >{$val}</option>";
}
?>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span id="new_model-help" class="help-block fpbx-help-block">Help.</span>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo _('Cancel');?></button>
<button type="button" class="btn btn-primary sccp_get_ext" data-id="get_ext_files" data-type=<?php echo '"'.$requestType.'"';?> onclick="showProgress();" id="get_model_files" data-dismiss="modal"><?php echo _('Get Files from Provisioner');?></button>
</div>
</div>
</div>
</div>
<!--End modal include-->
<!--Start progress modal include-->
<div id="pleaseWaitDialog" class="modal" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1>Getting files .....please wait</h1>
</div>
<div class="modal-body">
<div class="progress">
<div id="progress-bar" class="progress-bar progress-bar-striped progress-bar-animated active" role="progressbar" style="width:0%">
</div>
</div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!--End progress modal include-->