Restructure languages and locales management

Base off of provision file structure
Store netlang and devlang
Stop usage of extconfig ->sccplang
This commit is contained in:
steve-lad 2021-07-23 12:14:46 +02:00
parent 215cacae41
commit 4151b4fdae
11 changed files with 394 additions and 258 deletions

View file

@ -139,7 +139,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); //Initialise core settings $this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); //Initialise core settings
$this->initializeSccpPath(); //Set required Paths $this->initializeSccpPath(); //Set required Paths
$this->updateTimeZone(); // Get timezone from FreePBX $this->updateTimeZone(); // Get timezone from FreePBX
$this->findInstLangs(); //$this->findInstLangs();
$this->saveSccpSettings(); $this->saveSccpSettings();
} }
@ -172,7 +172,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
'h_show' => $show_Header, 'h_show' => $show_Header,
'form_prefix' => $form_prefix, 'form_prefix' => $form_prefix,
'fvalues' => $form_values, 'fvalues' => $form_values,
'installedLangs' => $this->installedLangs, 'installedLangs' => $this->findInstLangs(),
'chanSccpHelp' => $this->sccpHelpInfo, 'chanSccpHelp' => $this->sccpHelpInfo,
'sccp_defaults' => $this->sccpvalues 'sccp_defaults' => $this->sccpvalues
) )
@ -496,141 +496,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return $res; return $res;
} }
function saveSccpDevice($get_settings, $validateonly = false) {
$hdr_prefix = 'sccp_hw_';
$hdr_arprefix = 'sccp_hw-ar_';
$hdr_vendPrefix = 'sccp_hw_vendorconfig';
$save_buttons = array();
$save_settings = array();
$save_codec = array();
$name_dev = '';
$db_field = $this->dbinterface->getSccpDeviceTableData("get_columns_sccpdevice");
$hw_id = (empty($get_settings['sccp_deviceid'])) ? 'new' : $get_settings['sccp_deviceid'];
$hw_type = (empty($get_settings['sccp_device_typeid'])) ? 'sccpdevice' : $get_settings['sccp_device_typeid'];
$update_hw = ($hw_id == 'new') ? 'add' : 'clear'; // Possible values are delete, replace, add, clear.
$hw_prefix = 'SEP';
if (!empty($get_settings[$hdr_prefix . 'type'])) {
$value = $get_settings[$hdr_prefix . 'type'];
if (strpos($value, 'ATA') !== false) {
$hw_prefix = 'ATA';
}
if (strpos($value, 'VG') !== false) {
$hw_prefix = 'VG';
}
}
foreach ($db_field as $data) {
$key = (string) $data['Field'];
$value = "";
switch ($key) {
case 'name':
if (!empty($get_settings[$hdr_prefix . 'mac'])) {
$value = $get_settings[$hdr_prefix . 'mac'];
$value = strtoupper(str_replace(array('.', '-', ':'), '', $value)); // Delete mac separators from string
$value = sprintf("%012s", $value);
if ($hw_prefix == 'VG') {
$value = $hw_prefix . $value . '0';
} else {
$value = $hw_prefix . $value;
}
$name_dev = $value;
}
break;
case 'phonecodepage':
$value = 'null';
// TODO: getExtConfig(sccp_lang ....) does not accept any additional arguments and will return an array
if (!empty($get_settings[$hdr_prefix . 'devlang'])) {
$lang_data = $this->extconfigs->getExtConfig('sccp_lang', $get_settings[$hdr_prefix . 'devlang']);
if (!empty($lang_data)) {
$value = $lang_data['codepage'];
}
}
break;
case '_hwlang':
if (empty($get_settings[$hdr_prefix . 'netlang']) || empty($get_settings[$hdr_prefix . 'devlang'])) {
$value = 'null';
} else {
$value = $get_settings[$hdr_prefix . 'netlang'] . ':' . $get_settings[$hdr_prefix . 'devlang'];
}
break;
default:
// handle vendor prefix
if (!empty($get_settings[$hdr_vendPrefix . $key])) {
$value = $get_settings[$hdr_vendPrefix . $key];
}
// handle array prefix
if (!empty($get_settings[$hdr_arprefix . $key])) {
$arr_data = '';
$arr_clear = false;
foreach ($get_settings[$hdr_arprefix . $key] as $vkey => $vval) {
$tmp_data = '';
foreach ($vval as $vkey => $vval) {
switch ($vkey) {
case 'inherit':
if ($vval == 'on') {
$arr_clear = true;
// Злобный ХАК ?!TODO!?
if ($key == 'permit') {
$save_settings['deny'] = 'NONE';
}
}
break;
case 'internal':
if ($vval == 'on') {
$tmp_data .= 'internal;';
}
break;
default:
$tmp_data .= $vval . '/';
break;
}
}
if (strlen($tmp_data) > 2) {
while (substr($tmp_data, -1) == '/') {
$tmp_data = substr($tmp_data, 0, -1);
}
$arr_data .= $tmp_data . ';';
}
}
while (substr($arr_data, -1) == ';') {
$arr_data = substr($arr_data, 0, -1);
}
if ($arr_clear) {
$value = 'NONE';
} else {
$value = $arr_data;
}
}
// Now only have normal prefix
if (!empty($get_settings["{$hdr_prefix}{$key}"])) {
$value = $get_settings["{$hdr_prefix}{$key}"];
} else if (!empty($get_settings["sccp_hw{$key}"])) {
//have an underscore db field
$value = $get_settings["sccp_hw{$key}"];
}
}
if (!empty($value)) {
$save_settings[$key] = $value;
}
}
// Save this device.
$this->dbinterface->write('sccpdevice', $save_settings, 'replace');
// Retrieve the phone buttons and write back to
// update sccpdeviceconfig via Trigger
$save_buttons = $this->getPhoneButtons($get_settings, $name_dev, $hw_type);
$this->dbinterface->write('sccpbuttons', $save_buttons, $update_hw, '', $name_dev);
// Create new XML for this device, and then reset or restart the device
// so that it loads the file from TFT.
$this->createSccpDeviceXML($name_dev);
if ($hw_id == 'new') {
$this->aminterface->sccpDeviceReset($name_dev, 'reset');
} else {
$this->aminterface->sccpDeviceReset($name_dev, 'restart');
}
return $save_settings;
}
function handleRoamingUsers($get_settings, $validateonly = false) { function handleRoamingUsers($get_settings, $validateonly = false) {
$hdr_prefix = 'sccp_ru_'; $hdr_prefix = 'sccp_ru_';
$hdr_arprefix = 'sccp_ru-ar_'; $hdr_arprefix = 'sccp_ru-ar_';
@ -650,13 +515,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
case 'name': case 'name':
$value = $name_dev; $value = $name_dev;
break; break;
case '_hwlang':
if (empty($get_settings[$hdr_prefix . 'netlang']) || empty($get_settings[$hdr_prefix . 'devlang'])) {
$value = 'null';
} else {
$value = $get_settings[$hdr_prefix . 'netlang'] . ':' . $get_settings[$hdr_prefix . 'devlang'];
}
break;
default: default:
if (!empty($get_settings[$hdr_prefix . $key])) { if (!empty($get_settings[$hdr_prefix . $key])) {
$value = $get_settings[$hdr_prefix . $key]; $value = $get_settings[$hdr_prefix . $key];
@ -758,25 +616,59 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
*/ */
private function findInstLangs() { private function findInstLangs() {
//locales and languages are installed in the tftp_lang_path //locales and country tones are installed in the tftp_lang_path
$result = array(); //Available packs from provisioner are in masterFilesStructure.xml in tftpRoot Path
$langDir = '/'; //set default for when called by installer on virgin system // TODO: Need to include this file as part of module in case download not allowed/available
if (!empty($this->sccppath["tftp_lang_path"])) {
$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');
$localeArray = array_combine(array_keys($langArr),array_column($langArr, 'locale'));
foreach (array_diff(scandir($langDir),array('.', '..')) as $subDir) { $searchDir = '/'; //set default for when called by installer on virgin system
if (is_dir($langDir . DIRECTORY_SEPARATOR . $subDir)) { $result = array();
$filename = $langDir . DIRECTORY_SEPARATOR . $subDir . DIRECTORY_SEPARATOR . $localeJar;
if (!file_exists("{$this->sccppath['tftp_path']}/masterFilesStructure.xml")) {
$this->getFileListFromProvisioner();
}
$tftpBootXml = simplexml_load_file("{$this->sccppath['tftp_path']}/masterFilesStructure.xml");
foreach (array('languages', 'countries') as $pack) {
switch ($pack) {
case 'languages':
if (!empty($this->sccppath['tftp_lang_path'])) {
$searchDir = $this->sccppath['tftp_lang_path'];
}
$simpleXmlArr = $tftpBootXml->xpath("//Directory[@name='languages']//DirectoryPath[contains(.,'languages/')]");
array_shift($simpleXmlArr); // First element is the parent directory
foreach ($simpleXmlArr as $rowIn) {
$tmpArr = explode('/',(string)$rowIn);
array_pop($tmpArr); //last element is empty
$result[$pack]['available'][] = array_pop($tmpArr);
}
$fileToFind = 'be-sccp.jar'; // This file should exist if the locale is populated
break;
case 'countries':
if (!empty($this->sccppath["tftp_countries_path"])) {
$searchDir = $this->sccppath['tftp_countries_path'];
}
$simpleXmlArr = $tftpBootXml->xpath("//Directory[@name='countries']//DirectoryPath[contains(.,'countries/')]");
array_shift($simpleXmlArr); // First element is the parent directory
foreach ($simpleXmlArr as $rowIn) {
$tmpArr = explode('/',(string)$rowIn);
array_pop($tmpArr); //last element is empty
$result[$pack]['available'][] = array_pop($tmpArr);
}
$fileToFind = 'g3-tones.xml'; // This file should exist if the locale is populated
break;
}
foreach (array_diff(scandir($searchDir),array('.', '..')) as $subDir) {
if (is_dir($searchDir . DIRECTORY_SEPARATOR . $subDir)) {
$filename = $searchDir . DIRECTORY_SEPARATOR . $subDir . DIRECTORY_SEPARATOR . $fileToFind;
if (file_exists($filename)) { if (file_exists($filename)) {
$result = array_merge(array_intersect($localeArray,array($subDir)),$result); $result[$pack]['have'][] = $subDir;
}
} }
} }
} }
$this->installedLangs = $result; $this->installedLangs = $result;
return $result;
} }
/* /*
@ -1131,14 +1023,14 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$this->sccp_conf_init['general'][$key] = explode(';', $content); $this->sccp_conf_init['general'][$key] = explode(';', $content);
break; break;
case "devlang": case "devlang":
/*
$lang_data = $this->extconfigs->getExtConfig('sccp_lang', $value['data']); $lang_data = $this->extconfigs->getExtConfig('sccp_lang', $value['data']);
if (!empty($lang_data)) { if (!empty($lang_data)) {
// TODO: getExtConfig(sccp_lang ....) does not accept any additional arguments and will return an array
// TODO: will always get here, but lang_data['codepage'] will be empty as not a valid key // TODO: will always get here, but lang_data['codepage'] will be empty as not a valid key
$this->sccp_conf_init['general']['phonecodepage'] = $lang_data['codepage']; $this->sccp_conf_init['general']['phonecodepage'] = $lang_data['codepage'];
} }
break; break;
*/
case "netlang": // Remove Key case "netlang": // Remove Key
case "tftp_path": case "tftp_path":
case "sccp_compatible": // This is equal to SccpDBmodel case "sccp_compatible": // This is equal to SccpDBmodel

View file

@ -666,7 +666,7 @@ $(document).ready(function () {
// ----------------------- Get external Files---------------- // ----------------------- Get external Files----------------
if ($(this).data('id') === 'get_ext_files') { if ($(this).data('id') === 'get_ext_files') {
var dev_cmd = 'get_ext_files'; var dev_cmd = 'get_ext_files';
var dev_fld = ["device", "locale"]; var dev_fld = ["device", "locale", "country"];
datas = 'type=' + $(this).data('type') + '&' + 'name=' + '&'; datas = 'type=' + $(this).data('type') + '&' + 'name=' + '&';
for (var i = 0; i < dev_fld.length; i++) { for (var i = 0; i < dev_fld.length; i++) {
@ -697,7 +697,9 @@ $(document).ready(function () {
success: function (data) { success: function (data) {
$('#pleaseWaitDialog').modal('hide'); $('#pleaseWaitDialog').modal('hide');
console.log(data);
data = JSON.parse(data.replace(/^(.*\{)/,"\{")); data = JSON.parse(data.replace(/^(.*\{)/,"\{"));
console.log(data);
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

@ -242,22 +242,23 @@ and open the template in the editor. Base Version before all crash :-)
<select></select> <select></select>
<help>SCCP Language: This is the language for your hints and other features of the phone. If you don't have any languages installed or are using a single language, you can leave this blank.</help> <help>SCCP Language: This is the language for your hints and other features of the phone. If you don't have any languages installed or are using a single language, you can leave this blank.</help>
</item> </item>
<item type="SLT" id="2"> <item type="SLDA" id="3">
<label>SCCP Network Device Language</label> <label>Default Device Language</label>
<name>netlang</name>
<default>English_United_States</default>
<select></select>
<help>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</help>
</item>
<item type="SLTD" id="3">
<label>SCCP Phone Device Language</label>
<name>devlang</name> <name>devlang</name>
<default>English_United_States</default> <default>English_United_States</default>
<select> </select> <select> </select>
<help>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</help> <help>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</help>
</item> </item>
<item type="SLNA" id="2">
<label>Network Country</label>
<name>netlang</name>
<default>United_States</default>
<select></select>
<help>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</help>
</item>
</page_group> </page_group>
<page_group name="sccp_dev_config"> <page_group name="sccp_dev_config">
<label>SCCP Device general config</label> <label>SCCP Device general config</label>
<item type="IE" id="1"> <item type="IE" id="1">
@ -1335,13 +1336,6 @@ and open the template in the editor. Base Version before all crash :-)
<select></select> <select></select>
<help>Time Zone offset</help> <help>Time Zone offset</help>
</item> </item>
<item type="SLTD" id="4" seq="98">
<label>SCCP Network Device Language</label>
<name>netlang</name>
<default>English_United_States</default>
<select></select>
<help>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</help>
</item>
<item type="SLTD" id="5" seq="98"> <item type="SLTD" id="5" seq="98">
<label>SCCP Phone Device Language</label> <label>SCCP Phone Device Language</label>
<name>devlang</name> <name>devlang</name>
@ -1349,6 +1343,13 @@ and open the template in the editor. Base Version before all crash :-)
<select> </select> <select> </select>
<help>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</help> <help>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</help>
</item> </item>
<item type="SLTN" id="4" seq="98">
<label>SCCP Network Device Language</label>
<name>netlang</name>
<default>English_United_States</default>
<select></select>
<help>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</help>
</item>
<item type="IS" id="11" seq="98"> <item type="IS" id="11" seq="98">
<name>phonepersonalization</name> <name>phonepersonalization</name>
<label>Allow push background from server </label> <label>Allow push background from server </label>

View file

@ -249,7 +249,10 @@ function Get_DB_config($sccp_compatible)
'_sccp_cos' => array('create' => "VARCHAR(11) NOT NULL default '0x4'", 'modify' => "VARCHAR(11)"), '_sccp_cos' => array('create' => "VARCHAR(11) NOT NULL default '0x4'", 'modify' => "VARCHAR(11)"),
'_dev_sshPassword' => array('create' => "VARCHAR(25) NOT NULL default 'cisco'"), '_dev_sshPassword' => array('create' => "VARCHAR(25) NOT NULL default 'cisco'"),
'_dev_sshUserId' => array('create' => "VARCHAR(25) NOT NULL default 'cisco'"), '_dev_sshUserId' => array('create' => "VARCHAR(25) NOT NULL default 'cisco'"),
'_phonepersonalization' => array('create' => "VARCHAR(25) NOT NULL default '0'", 'modify' => "VARCHAR(25)") '_phonepersonalization' => array('create' => "VARCHAR(25) NOT NULL default '0'", 'modify' => "VARCHAR(25)"),
'_hwlang' => array ('drop' => 'yes'),
'_devlang' => array('create' => "VARCHAR(25) NULL default NULL", 'modify' => "VARCHAR(25)"),
'_netlang' => array('create' => "VARCHAR(25) NULL default NULL", 'modify' => "VARCHAR(25)")
), ),
'sccpline' => array ( 'sccpline' => array (
'_regcontext' => array('create' => "VARCHAR(20) NULL default 'sccpregistration'", 'modify' => "VARCHAR(20)"), '_regcontext' => array('create' => "VARCHAR(20) NULL default 'sccpregistration'", 'modify' => "VARCHAR(20)"),
@ -927,13 +930,10 @@ function cleanUpSccpSettings() {
global $sccp_compatible; global $sccp_compatible;
// Get current default settings from db // Get current default settings from db
$stmt = $db->prepare("SELECT * FROM sccpsettings"); $stmt = $db->prepare("SELECT keyword, sccpsettings.* FROM sccpsettings");
$stmt->execute(); $stmt->execute();
$settingsFromDb = $stmt->fetchAll(\PDO::FETCH_ASSOC); $settingsFromDb = $stmt->fetchAll(\PDO::FETCH_ASSOC|\PDO::FETCH_UNIQUE);
foreach ($settingsFromDb as $key => $rowArray) {
$settingsFromDb[$rowArray['keyword']] = $rowArray;
unset($settingsFromDb[$key]);
}
// See if a previous version was installed // See if a previous version was installed
outn("<li>" . _("Checking for previous version of Sccp_manager.") . "</li>"); outn("<li>" . _("Checking for previous version of Sccp_manager.") . "</li>");
if (!isset($settingsFromDb['sccp_compatible']['data'])) { if (!isset($settingsFromDb['sccp_compatible']['data'])) {
@ -1019,7 +1019,6 @@ function cleanUpSccpSettings() {
unset($sysConfiguration[$key]); unset($sysConfiguration[$key]);
} }
unset($sysConfiguration['Options']); unset($sysConfiguration['Options']);
// Write settings back to db // Write settings back to db
$sql = "TRUNCATE sccpsettings"; $sql = "TRUNCATE sccpsettings";
$results = $db->query($sql); $results = $db->query($sql);

View file

@ -71,7 +71,6 @@
<field name="backgroundThumbnail" type="string" length="255" notnull="false"/> <field name="backgroundThumbnail" type="string" length="255" notnull="false"/>
<field name="ringtone" type="string" length="255" notnull="false"/> <field name="ringtone" type="string" length="255" notnull="false"/>
<field name="callhistory_answered_elsewhere" type="string" notnull="false"/> <field name="callhistory_answered_elsewhere" type="string" notnull="false"/>
<field name="_hwlang" type="string" length="12" notnull="false"/>
<field name="_loginname" type="string" length="20" notnull="false"/> <field name="_loginname" type="string" length="20" notnull="false"/>
<field name="_profileid" type="integer" default="0"/> <field name="_profileid" type="integer" default="0"/>
<field name="_dialrules" type="string" length="255" notnull="false"/> <field name="_dialrules" type="string" length="255" notnull="false"/>

View file

@ -502,10 +502,17 @@ class formcreate
$select_opt= $syslangs; $select_opt= $syslangs;
break; break;
case 'SLTD': case 'SLTD':
// Device Language
$select_opt = array('xx' => 'No language packs found'); $select_opt = array('xx' => 'No language packs found');
if (!empty($installedLangs)) { if (!empty($installedLangs['languages']['have'])) {
$select_opt = (array)$installedLangs; $select_opt = (array)$installedLangs['languages']['have'];
}
break;
case 'SLTN':
// Network Language
$select_opt = array('xx' => 'No country packs found');
if (!empty($installedLangs['countries']['have'])) {
$select_opt = (array)$installedLangs['countries']['have'];
} }
break; break;
case 'SLZ': case 'SLZ':
@ -620,21 +627,39 @@ class formcreate
<?php <?php
} }
function addElementSLT($child, $fvalues, $sccp_defaults,$npref, $installedLangs) { function addElementSLNA($child, $fvalues, $sccp_defaults,$npref, $installedLangs) {
// Input element Select SLS - System Language // Input element Select SLS - System Language with add from external
$res_n = (string)$child ->name; $res_n = (string)$child ->name;
$res_id = $npref.$res_n; $res_id = $npref.$res_n;
$child->value =''; $child->value ='';
$selectArray = array();
// $select_opt is an associative array for these types. // $select_opt is an associative array for these types.
if (!empty($metainfo[$res_n])) { if (!empty($metainfo[$res_n])) {
if ($child->meta_help == '1' || $child->help == 'Help!') { if ($child->meta_help == '1' || $child->help == 'Help!') {
$child->help = $metaInfo[$res_n]; $child->help = $metaInfo[$res_n];
} }
} }
switch ($child['type']) {
case 'SLDA':
$select_opt = array('xx' => 'No language packs found'); $select_opt = array('xx' => 'No language packs found');
if (!empty($installedLangs)) { if (!empty($installedLangs['languages']['have'])) {
$select_opt = $installedLangs; $select_opt = $installedLangs['languages']['have'];
} }
$selectArray = $installedLangs['languages']['available'];
$requestType = 'locale';
break;
case 'SLNA':
$select_opt = array('xx' => 'No country packs found');
if (!empty($installedLangs['countries']['have'])) {
$select_opt = $installedLangs['countries']['have'];
}
$selectArray = $installedLangs['countries']['available'];
$requestType = 'country';
break;
}
if (empty($child->class)) { if (empty($child->class)) {
$child->class = 'form-control'; $child->class = 'form-control';
@ -649,9 +674,7 @@ class formcreate
$child->value = $child->default; $child->value = $child->default;
} }
} }
$langArr = \FreePBX::Sccp_manager()->extconfigs->getExtConfig('sccp_lang');
$selectArray = array_combine(array_keys($langArr),array_column($langArr, 'locale'));
$requestType = 'locale';
?> ?>
<div class="element-container"> <div class="element-container">
<div class="row"> <div class="row">
@ -671,9 +694,8 @@ class formcreate
foreach ($select_opt as $key => $val) { foreach ($select_opt as $key => $val) {
$opt_key = $key; $opt_key = $key;
$opt_val = $val; $opt_val = $val;
echo '<option value="' . $opt_val . '"';
echo '<option value="' . $opt_key . '"'; if ($opt_val == $child->value) {
if ($opt_key == $child->value) {
echo ' selected="selected"'; echo ' selected="selected"';
} }
echo "> {$opt_val} </option>"; echo "> {$opt_val} </option>";
@ -683,7 +705,7 @@ 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" id="<?php echo $requestType;?>" data-toggle="modal" data-target=".get_ext_file_<?php echo $requestType;?>"><i class="fa fa-bolt"></i> <?php echo _("Get $requestType from Provisioner");?>
</button> </button>
</div> </div>
</div> </div>

View file

@ -122,6 +122,47 @@ class xmlinterface
// Need to merge the two arrays so that device specific values override system values // Need to merge the two arrays so that device specific values override system values
// Values that cannot be sent to the device by chan-sccp are prefixed by an underscore // Values that cannot be sent to the device by chan-sccp are prefixed by an underscore
// so need to be sure that we apply the same convention to system wide defaults. // so need to be sure that we apply the same convention to system wide defaults.
$langCodeArray = array(
'Arabic_Saudi_Arabia' => 'ar',
'Bulgarian_Bulgaria' => 'bg',
'Czech_Czech_Republic' => 'cz',
'Danish_Denmark' => 'da',
'German_Germany' => 'de',
'Greek_Greece' => 'el',
'AU_English_United_States' => 'en',
'English_United_Kingdom' => 'en',
'English_United_States' => 'en',
'Spanish_Spain' => 'es',
'Estonian_Estonia' => 'et',
'Finnish_Finland' => 'fi',
'French_Canada' => 'fr',
'French_France' => 'fr',
'Hebrew_Israel' => 'he',
'Croatian_Croatia' => 'hr',
'Hungarian_Hungary' => 'hu',
'Italian_Italy' => 'it',
'Japanese_Japan' => 'ja',
'Korean_Korea_Republic' => 'ko',
'Lithuanian_Lithuania' => 'lt',
'Latvian_Latvia' => 'lv',
'Dutch_Netherlands' => 'nl',
'Norwegian_Norway' => 'no',
'Polish_Poland' => 'pl',
'Portuguese_Brazil' => 'pt',
'Portuguese_Portugal' => 'pt',
'Romanian_Romania' => 'ro',
'Russian_Russian_Federation' => 'ru',
'Slovak_Slovakia' => 'sk',
'Slovenian_Slovenia' => 'sl',
'Serbian_Republic_of_Montenegro' => 'sr',
'Serbian_Republic_of_Serbia' => 'rs',
'Swedish_Sweden' => 'sv',
'Thai_Thailand' => 'th',
'Turkish_Turkey' => 'tr',
'Chinese_China' => 'cn',
'Chinese_Taiwan' => 'zh'
);
$data_values = array_merge($data_values, $dev_config); $data_values = array_merge($data_values, $dev_config);
$var_xml_general_fields = array('authenticationurl' => 'dev_authenticationURL', 'informationurl' => 'dev_informationURL', 'messagesurl' => 'dev_messagesURL', $var_xml_general_fields = array('authenticationurl' => 'dev_authenticationURL', 'informationurl' => 'dev_informationURL', 'messagesurl' => 'dev_messagesURL',
'servicesurl' => 'dev_servicesURL', 'directoryurl' => 'dev_directoryURL', 'idleurl' => 'dev_idleURL', 'servicesurl' => 'dev_servicesURL', 'directoryurl' => 'dev_directoryURL', 'idleurl' => 'dev_idleURL',
@ -313,31 +354,39 @@ class xmlinterface
break; break;
case 'userlocale': case 'userlocale':
case 'networklocaleinfo': // Device language
case 'networklocale': $lang = $data_values['devlang'];
$hwlang = ''; if (!empty($dev_config['_devlang'])) {
$lang = ''; $lang = $dev_config['_devlang'];
if (!empty($dev_config["_hwlang"])) {
$hwlang = explode(':', $dev_config["_hwlang"]);
} }
if (($key_l == 'networklocaleinfo') || ($key_l == 'networklocale')) { $xml_node->winCharSet = $dev_config['phonecodepage'];
$lang = (empty($hwlang[0])) ? $data_values['netlang'] : $hwlang[0]; $xml_node->name = $dev_config['_devlang'];
} else { $xml_node->langCode = 'en';
$lang = (empty($hwlang[1])) ? $data_values['devlang'] : $hwlang[1]; if (isset($langCodeArray['_devlang'])) {
} $xml_node->langCode = $langCodeArray['_devlang'];
if (($lang != 'null') && (!empty($lang))) {
if ($key_l == 'networklocale') {
$xml_work->$key = $lang;
} else {
if (isset($lang_info[$lang])) {
$xml_node->name = $lang_info[$lang]['locale'];
$xml_node->langCode = $lang_info[$lang]['code'];
if ($key_l == 'userlocale') {
$xml_node->winCharSet = $lang_info[$lang]['codepage'];
} }
$this->replaceSimpleXmlNode($xml_work->$key, $xml_node); $this->replaceSimpleXmlNode($xml_work->$key, $xml_node);
break;
case 'networklocale':
$lang = $data_values['_netlang'];
if (!empty($dev_config['_netlang'])) {
$lang = $dev_config['_netlang'];
} }
if (($lang != null) && (!empty($lang))) {
$xml_work->$key = $lang;
$this->replaceSimpleXmlNode($xml_work->$key, $xml_node);
} else {
$xml_work->$key = '';
} }
break;
case 'networklocaleinfo':
$lang = $data_values['_netlang'];
if (!empty($dev_config['_netlang'])) {
$lang = $dev_config['_netlang'];
}
if (($lang != null) && (!empty($lang))) {
$xml_node->name = $dev_config['_netlang'];
$this->replaceSimpleXmlNode($xml_work->$key, $xml_node);
} else { } else {
$xml_work->$key = ''; $xml_work->$key = '';
} }
@ -714,7 +763,7 @@ class xmlinterface
$put_file = (string) $get_settings['idtemplate']; $put_file = (string) $get_settings['idtemplate'];
} }
} else { } else {
$errors = array('Fields Dial Plan Name is requered !!'); $errors = array('Fields Dial Plan Name is required !!');
} }
if (empty($errors)) { if (empty($errors)) {

View file

@ -433,7 +433,7 @@ trait ajaxHelper {
// Value unchanged or null so ignore and go to next key. // Value unchanged or null so ignore and go to next key.
continue; continue;
} }
$dbSaveArray[] = array('table' => 'sccpdevice', 'field' => $key, 'Default' => $value); $dbSaveArray[$key] = array('table' => 'sccpdevice', 'field' => $key, 'Default' => $value);
continue; continue;
} }
$key = (str_replace('sccpline_', '', $key, $count_mods)); $key = (str_replace('sccpline_', '', $key, $count_mods));
@ -450,24 +450,11 @@ trait ajaxHelper {
// Value unchanged so ignore and get next key. // Value unchanged so ignore and get next key.
continue; continue;
} }
$dbSaveArray[] = array('table' => 'sccpline', 'field' => $key, 'Default' => $value); $dbSaveArray[$key] = array('table' => 'sccpline', 'field' => $key, 'Default' => $value);
unset($request[$key]); unset($request[$key]);
continue; continue;
} }
$key = (str_replace($hdr_prefix, '', $key, $count_mods));
if ($count_mods) {
if (!empty($this->sccpvalues[$key]) && ($this->sccpvalues[$key]['data'] != $value)) {
$save_settings[$key] = array(
'keyword' => $key,
'data' => $value,
'seq' => $this->sccpvalues[$key]['seq'],
'type' => $this->sccpvalues[$key]['type'],
'systemdefault' => $this->sccpvalues[$key]['systemdefault']
);
}
}
$key = (str_replace($hdr_arprefix, '', $key, $count_mods)); $key = (str_replace($hdr_arprefix, '', $key, $count_mods));
if ($count_mods) { if ($count_mods) {
$arr_data = ''; $arr_data = '';
@ -508,6 +495,21 @@ trait ajaxHelper {
} }
} }
} }
$key = (str_replace($hdr_prefix, '', $key, $count_mods));
if ($count_mods) {
if (!empty($this->sccpvalues[$key]) && ($this->sccpvalues[$key]['data'] != $value)) {
$save_settings[$key] = array(
'keyword' => $key,
'data' => $value,
'seq' => $this->sccpvalues[$key]['seq'],
'type' => $this->sccpvalues[$key]['type'],
'systemdefault' => $this->sccpvalues[$key]['systemdefault']
);
}
}
switch ($key) { switch ($key) {
case 'audiocodecs': case 'audiocodecs':
foreach ($value as $keycodeс => $valcodeс) { foreach ($value as $keycodeс => $valcodeс) {
@ -545,6 +547,7 @@ trait ajaxHelper {
} }
break; break;
} }
} }
$extSettings = $this->extconfigs->updateTftpStructure(array_merge($this->sccpvalues, $save_settings)); $extSettings = $this->extconfigs->updateTftpStructure(array_merge($this->sccpvalues, $save_settings));
@ -554,12 +557,12 @@ trait ajaxHelper {
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); $this->sccpvalues = $this->dbinterface->get_db_SccpSetting();
} }
foreach ($dbSaveArray as $rowToSave) { foreach ($dbSaveArray as $key => $rowToSave) {
$this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']); $this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']);
} }
$this->createDefaultSccpConfig(); // Rewrite Config. $this->createDefaultSccpConfig(); // Rewrite Config.
$save_settings[] = array('status' => true); $save_settings[] = array('status' => true, );
$this->createDefaultSccpXml(); $this->createDefaultSccpXml();
return $save_settings; return $save_settings;
@ -624,10 +627,9 @@ trait ajaxHelper {
$msg = "Firmware for {$device} has been successfully downloaded"; $msg = "Firmware for {$device} has been successfully downloaded";
break; break;
case 'locale': case 'locale':
$locale = $request['locale']; $language = $request['locale'];
$totalFiles = 0; $totalFiles = 0;
$langArr = \FreePBX::Sccp_manager()->extconfigs->getExtConfig('sccp_lang');
$language = $langArr[$locale]['locale'];
if (!is_dir("{$this->sccppath['tftp_lang_path']}/{$language}")) { if (!is_dir("{$this->sccppath['tftp_lang_path']}/{$language}")) {
mkdir("{$this->sccppath['tftp_lang_path']}/{$language}", 0755); mkdir("{$this->sccppath['tftp_lang_path']}/{$language}", 0755);
@ -678,7 +680,39 @@ trait ajaxHelper {
flush(); flush();
} }
} }
$msg = "{$locale} Locale and Country tones have been successfully downloaded"; $msg = "{$language} Locale and Country tones have been successfully downloaded";
break;
case 'country':
$countryName = $request['country'];
$totalFiles = 0;
if (!is_dir("{$this->sccppath['tftp_countries_path']}/{$countryName}")) {
mkdir("{$this->sccppath['tftp_countries_path']}/{$countryName}", 0755);
}
$result = $tftpBootXml->xpath("//Directory[@name='{$countryName}']");
$filesToGet['countries'] = (array)$result[0]->FileName;
$totalFiles += count($filesToGet['countries']);
$countriesSrcDir = (string)$result[0]->DirectoryPath;
$countriesDstDir = "{$this->sccppath['tftp_countries_path']}/{$countryName}";
$filesRetrieved = 0;
foreach (array('countries') as $section){
$srcDir = ${"{$section}SrcDir"};
$dstDir = ${"{$section}DstDir"};
foreach ($filesToGet[$section] as $srcFile) {
file_put_contents("{$dstDir}/{$srcFile}",
file_get_contents($provisionerUrl . $srcDir . $srcFile));
$filesRetrieved ++;
$percentComplete = $filesRetrieved *100 / $totalFiles;
$data = "{$percentComplete},";
echo $data;
ob_flush();
flush();
}
}
$msg = "{$countryName} country tones have been successfully downloaded";
break; break;
default: default:
return false; return false;
@ -686,6 +720,136 @@ trait ajaxHelper {
} }
return array('status' => true, 'message' => $msg, 'reload' => true); return array('status' => true, 'message' => $msg, 'reload' => true);
} }
function saveSccpDevice($get_settings, $validateonly = false) {
dbug($get_settings);
$hdr_prefix = 'sccp_hw_';
$hdr_arprefix = 'sccp_hw-ar_';
$hdr_vendPrefix = 'sccp_hw_vendorconfig';
$save_buttons = array();
$save_settings = array();
$save_codec = array();
$name_dev = '';
$db_field = $this->dbinterface->getSccpDeviceTableData("get_columns_sccpdevice");
$hw_id = (empty($get_settings['sccp_deviceid'])) ? 'new' : $get_settings['sccp_deviceid'];
$hw_type = (empty($get_settings['sccp_device_typeid'])) ? 'sccpdevice' : $get_settings['sccp_device_typeid'];
$update_hw = ($hw_id == 'new') ? 'add' : 'clear'; // Possible values are delete, replace, add, clear.
$hw_prefix = 'SEP';
if (!empty($get_settings[$hdr_prefix . 'type'])) {
$value = $get_settings[$hdr_prefix . 'type'];
if (strpos($value, 'ATA') !== false) {
$hw_prefix = 'ATA';
}
if (strpos($value, 'VG') !== false) {
$hw_prefix = 'VG';
}
}
foreach ($db_field as $data) {
$key = (string) $data['Field'];
$value = "";
switch ($key) {
case 'name':
if (!empty($get_settings[$hdr_prefix . 'mac'])) {
$value = $get_settings[$hdr_prefix . 'mac'];
$value = strtoupper(str_replace(array('.', '-', ':'), '', $value)); // Delete mac separators from string
$value = sprintf("%012s", $value);
if ($hw_prefix == 'VG') {
$value = $hw_prefix . $value . '0';
} else {
$value = $hw_prefix . $value;
}
$name_dev = $value;
}
break;
case 'phonecodepage':
$value = 'ISO8859-1';
// TODO: May be other exceptions. Historically this is the only one handled
if (!empty($get_settings["{$hdr_prefix}devlang"])) {
if ($get_settings["{$hdr_prefix}devlang"] == "Russian_Russian_Federation") {
$value = 'CP1251';
}
}
break;
default:
// handle vendor prefix
if (!empty($get_settings[$hdr_vendPrefix . $key])) {
$value = $get_settings[$hdr_vendPrefix . $key];
}
// handle array prefix
if (!empty($get_settings[$hdr_arprefix . $key])) {
$arr_data = '';
$arr_clear = false;
foreach ($get_settings[$hdr_arprefix . $key] as $vkey => $vval) {
$tmp_data = '';
foreach ($vval as $vkey => $vval) {
switch ($vkey) {
case 'inherit':
if ($vval == 'on') {
$arr_clear = true;
// Злобный ХАК ?!TODO!?
if ($key == 'permit') {
$save_settings['deny'] = 'NONE';
}
}
break;
case 'internal':
if ($vval == 'on') {
$tmp_data .= 'internal;';
}
break;
default:
$tmp_data .= $vval . '/';
break;
}
}
if (strlen($tmp_data) > 2) {
while (substr($tmp_data, -1) == '/') {
$tmp_data = substr($tmp_data, 0, -1);
}
$arr_data .= $tmp_data . ';';
}
}
while (substr($arr_data, -1) == ';') {
$arr_data = substr($arr_data, 0, -1);
}
if ($arr_clear) {
$value = 'NONE';
} else {
$value = $arr_data;
}
}
// Now only have normal prefix
if (!empty($get_settings["{$hdr_prefix}{$key}"])) {
$value = $get_settings["{$hdr_prefix}{$key}"];
} else if (!empty($get_settings["sccp_hw{$key}"])) {
//have an underscore db field
$value = $get_settings["sccp_hw{$key}"];
}
}
if (!empty($value)) {
$save_settings[$key] = $value;
}
}
// Save this device.
$this->dbinterface->write('sccpdevice', $save_settings, 'replace');
// Retrieve the phone buttons and write back to
// update sccpdeviceconfig via Trigger
$save_buttons = $this->getPhoneButtons($get_settings, $name_dev, $hw_type);
$this->dbinterface->write('sccpbuttons', $save_buttons, $update_hw, '', $name_dev);
// Create new XML for this device, and then reset or restart the device
// so that it loads the file from TFT.
$this->createSccpDeviceXML($name_dev);
if ($hw_id == 'new') {
$this->aminterface->sccpDeviceReset($name_dev, 'reset');
} else {
$this->aminterface->sccpDeviceReset($name_dev, 'restart');
}
$msg = "Device Saved";
return array('status' => true, 'message' => $msg, 'reload' => true);
}
} }
?> ?>

View file

@ -307,7 +307,7 @@ trait helperfunctions {
$this->sccpvalues[(string) $child->name] = array('keyword' => (string) $child->name, 'data' => $datav, 'type' => '2', 'seq' => $seq, 'systemdefault' => ''); $this->sccpvalues[(string) $child->name] = array('keyword' => (string) $child->name, 'data' => $datav, 'type' => '2', 'seq' => $seq, 'systemdefault' => '');
} }
} }
if (in_array($child['type'], array('SLD', 'SLS', 'SLT', 'SL', 'SLM', 'SLZ', 'SLTZN', 'SLA'))) { if (in_array($child['type'], array('SLD', 'SLS', 'SLT', 'SLNA', 'SLDA', 'SL', 'SLM', 'SLZ', 'SLTZN', 'SLA'))) {
if (empty($child->value)) { if (empty($child->value)) {
$datav = (string) $child->default; $datav = (string) $child->default;
} else { } else {

View file

@ -78,13 +78,15 @@ foreach ($items as $child) {
case 'SLP': case 'SLP':
case 'SLS': case 'SLS':
case 'SLTD': case 'SLTD':
case 'SLTN':
case 'SLA': case 'SLA':
case 'SLZ': case 'SLZ':
case 'SL': case 'SL':
\FreePbx::sccp_manager()->formcreate->addElementSL($child, $fvalues, $sccp_defaults,$npref, $installedLangs); \FreePbx::sccp_manager()->formcreate->addElementSL($child, $fvalues, $sccp_defaults,$npref, $installedLangs);
break; break;
case 'SLT': case 'SLDA':
\FreePbx::sccp_manager()->formcreate->addElementSLT($child, $fvalues, $sccp_defaults,$npref, $installedLangs); case 'SLNA':
\FreePbx::sccp_manager()->formcreate->addElementSLNA($child, $fvalues, $sccp_defaults,$npref, $installedLangs);
break; break;
case 'SDM': case 'SDM':
case 'SDMS': case 'SDMS':

View file

@ -1,5 +1,5 @@
<!--Begin modal include--> <!--Begin modal include-->
<div class="modal fade get_ext_file" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> <div class="modal fade get_ext_file_<?php echo $requestType;?>" 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">
<div class="modal-header"> <div class="modal-header">
@ -27,14 +27,20 @@
<div class="col-md-3"> <div class="col-md-3">
<div class = "lnet form-group form-inline" data-nextid=1> <div class = "lnet form-group form-inline" data-nextid=1>
<?php <?php
if ($requestType == 'firmware') { switch ($requestType) {
case 'firmware':
echo "<select class='form-control' id='ext_device'>"; echo "<select class='form-control' id='ext_device'>";
} else { break;
case 'locale':
echo "<select class='form-control' id='ext_locale'>"; echo "<select class='form-control' id='ext_locale'>";
break;
case 'country':
echo "<select class='form-control' id='ext_country'>";
break;
} }
foreach ($selectArray as $key => $val) { foreach ($selectArray as $key => $val) {
echo "<option value= '{$key}'"; echo "<option value= '{$val}'";
if ($key == 'en_GB') { if (($val == 'English_United_Kingdom') || ($val == 'United_Kingdom')) {
echo ' selected="selected"'; echo ' selected="selected"';
} }
echo ">{$val}</option>"; echo ">{$val}</option>";