Finalise Codecs tab for site defaults

Partially revert changes to sccpvalues keys
Remove obsolete code
Improve help and set as open by default
Move getMyConfig to AjaxHelper as only used there
This commit is contained in:
steve-lad 2021-07-06 15:22:12 +02:00
parent acdf777bcc
commit 2e5028f438
3 changed files with 58 additions and 142 deletions

View file

@ -725,51 +725,21 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return $save_settings;
}
public function getMyConfig($var = null, $id = "noid") {
switch ($var) {
case "voicecodecs":
$val = explode(",", explode("|", $this->sccpvalues['disallow|allow']['data'])[1]);
$final = array();
$i = 1;
foreach ($val as $value) {
$final[$value] = $i;
$i++;
}
break;
case "softkeyset":
$final = array();
$i = 0;
if ($id == "noid") {
foreach ($this->sccp_conf_init as $key => $value) {
if ($this->sccp_conf_init[$key]['type'] == 'softkeyset') {
$final[$i] = $value;
$i++;
}
}
} else {
if (!empty($this->sccp_conf_init[$id])) {
if ($this->sccp_conf_init[$id]['type'] == 'softkeyset') {
$final = $this->sccp_conf_init[$id];
}
}
}
break;
}
return $final;
}
public function getCodecs($type, $showDefaults = false) {
$allSupported = array();
$Sccp_Codec = array('alaw', 'ulaw', 'g722', 'g723', 'g726', 'g729', 'gsm', 'h264', 'h263', 'h261');
// First see if have any site defaults
$val = $this->sccpvalues['allow']['data'];
if (empty($val)) {
// No site defaults so return chan-sccp defaults
$val = $this->sccpvalues['allow']['systemdefault'];
}
$lcodecs = explode(',',$val);
switch ($type) {
case 'audio':
$lcodecs = $this->getMyConfig('voicecodecs');
$allCodecs = $this->FreePBX->Codecs->getAudio();
dbug('FPBX audio', $allCodecs);
break;
case 'video':
$lcodecs = $this->getMyConfig('voicecodecs');
$allCodecs = $this->FreePBX->Codecs->getVideo();
break;
case 'text':
@ -780,23 +750,20 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$lcodecs = $this->getConfig('imagecodecs');
$allCodecs = $this->FreePBX->Codecs->getImage(true);
break;
default:
throw new Exception(_('Unknown Type'));
break;
}
foreach ($allCodecs as $c => $v) {
if (in_array($c, $Sccp_Codec)) {
$allSupported[$c] = $v;
}
}
if (empty($lcodecs) || (!is_array($lcodecs))) {
if (empty($lcodecs)) {
if (empty($allSupported)) {
$lcodecs = $allCodecs;
} else {
$lcodecs = $allSupported;
}
} else {
foreach ($lcodecs as $c => $v) {
foreach ($lcodecs as $c) {
if (isset($allSupported[$c])) {
$codecs[$c] = true;
}
@ -812,7 +779,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
} else {
//Remove non digits
$final = array();
dbug('codecs', $codecs);
foreach ($codecs as $codec => $order) {
$order = trim($order);
if (ctype_digit($order)) {
@ -824,37 +790,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
}
/**
* Update or Set Codecs
* @param {string} $type Codec Type
* @param {array} $codecs=array() The codecs with order, if blank set defaults
*/
public function setCodecs($type, $codecs = array()) {
$default = empty($codecs) ? true : false;
switch ($type) {
case 'audio':
$codecs = $default ? $this->FreePBX->Codecs->getAudio(true) : $codecs;
$this->setConfig("voicecodecs", $codecs);
break;
case 'video':
$codecs = $default ? $this->FreePBX->Codecs->getVideo(true) : $codecs;
$this->setConfig("videocodecs", $codecs);
break;
case 'text':
$codecs = $default ? $this->FreePBX->Codecs->getText(true) : $codecs;
$this->setConfig("textcodecs", $codecs);
break;
case 'image':
$codecs = $default ? $this->FreePBX->Codecs->getImage(true) : $codecs;
$this->setConfig("imagecodecs", $codecs);
break;
default:
throw new Exception(_('Unknown Type'));
break;
}
return true;
}
/**
* Retrieve Active Codecs
* return fiends Lag pack

View file

@ -387,7 +387,6 @@ trait ajaxHelper {
}
function handleSubmit($request, $validateonly = false) {
dbug('request is:', $request);
$hdr_prefix = 'sccp_';
$hdr_arprefix = 'sccp-ar_';
$save_settings = array();
@ -495,30 +494,6 @@ trait ajaxHelper {
}
}
switch ($key) {
case 'disallow':
if (is_array($value)) {
foreach ($value as $keycodeс => $valcodeс) {
$save_codec[$i] = $keycodeс;
$i++;
};
$tmpv = implode(",", $save_codec);
} else {
$tmpv = $value;
}
if (empty($save_settings['disallow|allow']['data'])) {
$save_settings['disallow|allow']['data'] = $tmpv . "|";
} else {
$save_settings[] = array(
'keyword' => 'disallow|allow',
'data' => $tmpv . "|" .$save_settings['disallow|allow']['data'],
'seq' => $this->sccpvalues['disallow|allow']['seq'],
'type' => $this->sccpvalues['disallow|allow']['type'],
'systemdefault' => $this->sccpvalues['disallow|allow']['systemdefault']
);
unset($save_settings['disallow|allow']['data']);
}
break;
case 'voicecodecs':
case 'vcodec':
foreach ($value as $keycodeс => $valcodeс) {
@ -526,17 +501,14 @@ trait ajaxHelper {
$i++;
};
$tmpv = implode(",", $save_codec);
if (empty($save_settings['disallow|allow']['data'])) {
$save_settings['disallow|allow']['data'] = $tmpv;
} else {
if (!($this->sccpvalues['allow']['data'] == $tmpv)) {
$save_settings[] = array(
'keyword' => 'disallow|allow',
'data' => $save_settings['disallow|allow']['data'] . $tmpv,
'seq' => $this->sccpvalues['disallow|allow']['seq'],
'type' => $this->sccpvalues['disallow|allow']['type'],
'systemdefault' => $this->sccpvalues['disallow|allow']['systemdefault']
);
unset($save_settings['disallow|allow']['data']);
'keyword' => 'allow',
'data' => $tmpv,
'seq' => $this->sccpvalues['allow']['seq'],
'type' => $this->sccpvalues['allow']['type'],
'systemdefault' => $this->sccpvalues['allow']['systemdefault']
);
}
break;
@ -571,6 +543,32 @@ trait ajaxHelper {
$this->createDefaultSccpXml();
return $save_settings;
}
public function getMyConfig($var = null, $id = "noid") {
// TODO: this function has little purpose - need to integrate into AjaxHelper
switch ($var) {
case "softkeyset":
$final = array();
$i = 0;
if ($id == "noid") {
foreach ($this->sccp_conf_init as $key => $value) {
if ($this->sccp_conf_init[$key]['type'] == 'softkeyset') {
$final[$i] = $value;
$i++;
}
}
} else {
if (!empty($this->sccp_conf_init[$id])) {
if ($this->sccp_conf_init[$id]['type'] == 'softkeyset') {
$final = $this->sccp_conf_init[$id];
}
}
}
break;
}
return $final;
}
}
?>

View file

@ -6,37 +6,16 @@
* and open the template in the editor.
*/
$def_val = null;
$dev_id = null;
$audio_codecs = $this->getCodecs('audio', true);
$video_codecs = $this->getCodecs('video', true);
$sccp_disallow_def = $this->sccpvalues['disallow|allow']['data'];
$sccp_disallow_def = explode("|",$sccp_disallow_def)[0];
$sccp_disallow = $sccp_disallow_def;
$sccp_disallow_def = $this->sccpvalues['disallow']['data'];
$sys_disallow_def = $this->sccpvalues['disallow']['systemdefault'];
if (!empty($_REQUEST['id'])) {
$dev_id = $_REQUEST['id'];
$db_res = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $dev_id));
if (!empty($db_res['allow'])) {
$i = 1;
foreach (explode(';', $db_res['allow']) as $c) {
$codec_list[$c] = $i;
$i ++;
}
foreach ($audio_codecs as $c => $v) {
if (!isset($codec_list[$c])) {
$codec_list[$c] = false;
}
}
}
if (!empty($db_res['disallow'])) {
$sccp_disallow = $db_res['disallow'];
}
} else {
$codec_list = $audio_codecs;
if (empty($sccp_disallow_def)) {
$sccp_disallow_def = $sys_disallow_def;
}
?>
<!-- Codec selection is at the line level - this page sets site defaults based on chan-sccp defaults -->
@ -56,8 +35,8 @@ if (!empty($_REQUEST['id'])) {
<i class="fa fa-question-circle fpbx-help-icon" data-for="sccp_disallow"></i>
</div>
<div class="col-md-9 radioset">
<input id="sccp_disallow" type="text" name="sccp_disallow" value="<?php echo $sccp_disallow ?>">
<label for="sccp_disallow"><?php echo _("Current value : " . $sccp_disallow_def . "<br>Recomended default: all") ?></label>
<input id="sccp_disallow" type="text" name="sccp_disallow" value="<?php echo $sccp_disallow_def ?>">
<label for="sccp_disallow"><?php echo _("Recomended default: all") ?></label>
</div>
</div>
</div>
@ -65,7 +44,7 @@ if (!empty($_REQUEST['id'])) {
</div>
<div class="row">
<div class="col-md-12">
<span id="sccp_disallow-help" class="help-block fpbx-help-block"><?php echo _("Default : all. Please enter format: alaw,ulaw,...") ?></span>
<span id="sccp_disallow-help" class="help-block fpbx-help-block"><?php echo _("Default : all. If you wish to change (Not Recommended) please enter a comma separated list for example: alaw,ulaw,...") ?></span>
</div>
</div>
</div>
@ -90,13 +69,17 @@ if (!empty($_REQUEST['id'])) {
</div>
<div class="col-md-9">
<div>
<?php echo show_help(_("This is the default Codec setting for SCCP Device.")) ?>
<?php echo show_help(_("These are the default audio codec settings for this site. Unchecked codecs cannot be assigned to extensions.
<br>Order can be changed by dragging and dropping to indicate priority. This priority applies for all extensions
<br>Higher priority enabled codecs are at the top
<br>Precedence for ulaw and alaw, if used, should be set according to your region
<br>If your region uses alaw, it is important that alaw has the highest priority"),"Helpful information",true) ?>
</div>
<?php
$seq = 1;
echo '<ul class="sortable">';
foreach ($codec_list as $codec => $codec_state) {
foreach ($audio_codecs as $codec => $codec_state) {
$codec_trans = _($codec);
$codec_checked = $codec_state ? 'checked' : '';
echo '<li><a href="#">'
@ -141,7 +124,7 @@ if (!empty($_REQUEST['id'])) {
</div>
<div class="col-md-9">
<div>
<?php echo show_help(_("This is the default Codec setting for SCCP Device.")) ?>
<?php echo show_help(_("These are the default video codec settings for this site.")) ?>
</div>
<?php
$seq = 1;
@ -154,9 +137,9 @@ if (!empty($_REQUEST['id'])) {
. '<img src="assets/sipsettings/images/arrow_up_down.png" height="16" width="16" border="0" alt="move" style="float:none; margin-left:-6px; margin-bottom:-3px;cursor:move" /> '
. '<input type="checkbox" '
. ($codec_checked ? 'value="' . $seq++ . '" ' : '')
. 'name="voicecodecs[' . $codec . ']" '
. 'name="videocodecs[' . $codec . ']" '
. 'id="' . $codec . '" '
. 'class="audio-codecs" '
. 'class="video-codecs" '
. $codec_checked
. ' />'
. '&nbsp;&nbsp;<label for="' . $codec . '"> '