Initialise Defaults in Driver

Add Constructor to get and set line_defaults
Add defaults to SCCP tab
This commit is contained in:
steve-lad 2021-06-20 11:53:24 +02:00
parent 55285cf625
commit be8aa5cd92
2 changed files with 66 additions and 46 deletions

View file

@ -147,6 +147,7 @@ function Get_DB_config($sccp_compatible)
'namedpickupgroup' => array('create' => "VARCHAR(100) NULL DEFAULT NULL AFTER `namedcallgroup`", 'modify' => "VARCHAR(100)"), 'namedpickupgroup' => array('create' => "VARCHAR(100) NULL DEFAULT NULL AFTER `namedcallgroup`", 'modify' => "VARCHAR(100)"),
'adhocNumber' => array('create' => "VARCHAR(45) NULL DEFAULT NULL AFTER `namedpickupgroup`"), 'adhocNumber' => array('create' => "VARCHAR(45) NULL DEFAULT NULL AFTER `namedpickupgroup`"),
'meetme' => array('create' => "VARCHAR(5) NULL DEFAULT NULL AFTER `adhocNumber`"), 'meetme' => array('create' => "VARCHAR(5) NULL DEFAULT NULL AFTER `adhocNumber`"),
'context' => array('create' => "VARCHAR(45) NULL DEFAULT NULL AFTER `description`", 'def_modify' => 'from-internal'),
'meetmenum' => array('create' => "VARCHAR(45) NULL DEFAULT NULL AFTER `meetme`"), 'meetmenum' => array('create' => "VARCHAR(45) NULL DEFAULT NULL AFTER `meetme`"),
'meetmeopts' => array('create' => "VARCHAR(45) NULL DEFAULT NULL AFTER `meetmenum`"), 'meetmeopts' => array('create' => "VARCHAR(45) NULL DEFAULT NULL AFTER `meetmenum`"),
'regexten' => array('create' => "VARCHAR(45) NULL DEFAULT NULL AFTER `meetmeopts`"), 'regexten' => array('create' => "VARCHAR(45) NULL DEFAULT NULL AFTER `meetmeopts`"),
@ -252,7 +253,6 @@ function Get_DB_config($sccp_compatible)
), ),
'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)"),
'_pickupgroup' => array('create' => "VARCHAR(50) NULL default null", 'modify' => "VARCHAR(50)"),
'_transfer_on_hangup' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"), '_transfer_on_hangup' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"),
'_autoselectline_enabled' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"), '_autoselectline_enabled' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"),
'_autocall_select' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"), '_autocall_select' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"),

View file

@ -53,6 +53,18 @@ class Sccp extends \FreePBX\modules\Core\Driver {
); );
private $line_defaults = array(); private $line_defaults = array();
public function __construct($parent_class = null) {
$this->freepbx = $parent_class;
$this->database = $parent_class->Database();
$stmt = $this->database->prepare('DESCRIBE sccpline');
$stmt->execute();
$raw_settings = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($raw_settings as $row) {
$this->line_defaults[$row["Field"]] = $row["Default"];
}
}
public function getInfo() { public function getInfo() {
return array( return array(
"rawName" => "sccp", "rawName" => "sccp",
@ -105,16 +117,10 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
} }
$tech = Array();
$sql = "DESCRIBE sccpline";
foreach ($this->database->query($sql) as $row) {
$tech[$row["Field"]]=$row["Field"];
$this->line_defaults[$row["Field"]] = $row["Default"];
}
$sqlCol = 'name'; $sqlCol = 'name';
$sqlVal = "'{$id}'"; $sqlVal = "'{$id}'";
foreach($this->data_fld as $key => $val) { foreach($this->data_fld as $key => $val) {
if (isset($tech[$key])) { if (array_key_exists($key, $this->line_defaults)) {
if (isset($settings[$val]['value'])){ if (isset($settings[$val]['value'])){
$sqlCol .= ", {$key}"; $sqlCol .= ", {$key}";
$sqlVal .= ", '{$settings[$val]['value']}'"; $sqlVal .= ", '{$settings[$val]['value']}'";
@ -172,48 +178,65 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
public function getDefaultDeviceSettings($id, $displayname, &$flag) { public function getDefaultDeviceSettings($id, $displayname, &$flag) {
$dial = 'SCCP'; $dial = 'SCCP';
$settings = array( $settings = array(
"mailbox" => array( "mailbox" => array(
"value" => $this->line_defaults['mailbox'], "value" => $this->line_defaults['mailbox'],
"flag" => $flag++ "flag" => $flag++
),
"pin" => array(
"value" => $this->line_defaults['pin'],
"flag" => $flag++
), ),
"incominglimit" => array( "incominglimit" => array(
"value" => $this->line_defaults['incominglimit'], "value" => $this->line_defaults['incominglimit'],
"flag" => $flag++ "flag" => $flag++
), ),
"lcontext" => array( "context" => array(
"value" => "from-internal", "value" => $this->line_defaults['context'],
"flag" => $flag++
),
"directed_pickup_context" => array(
"value" => $this->line_defaults['directed_pickup_context'],
"flag" => $flag++ "flag" => $flag++
), ),
"callgroup" => array( "callgroup" => array(
"value" => $this->line_defaults['callgroup'], "value" => $this->line_defaults['callgroup'],
"flag" => $flag++ "flag" => $flag++
), ),
"namedcallgroup" => array(
"value" => $this->line_defaults['namedcallgroup'],
"flag" => $flag++
),
"pickupgroup" => array( "pickupgroup" => array(
"value" => $this->line_defaults['pickupgroup'], "value" => $this->line_defaults['pickupgroup'],
"flag" => $flag++ "flag" => $flag++
), ),
"namedpickupgroup" => array( "namedcallgroup" => array(
"value" => "", "value" => $this->line_defaults['namedcallgroup'],
"flag" => $flag++ "flag" => $flag++
), ),
"transfer" => array( "namedpickupgroup" => array(
"value" => $this->line_defaults['transfer'], "value" => $this->line_defaults['namedpickupgroup'],
"flag" => $flag++ "flag" => $flag++
), ),
"adhocNumber" => array( "adhocNumber" => array(
"value" => $this->line_defaults['adhocNumber'], "value" => $this->line_defaults['adhocNumber'],
"flag" => $flag++ "flag" => $flag++
), ),
"secondary_dialtone_digits" => array(
"value" => $this->line_defaults['secondary_dialtone_digits'],
"flag" => $flag++
),
"secondary_dialtone_tone" => array(
"value" => $this->line_defaults['secondary_dialtone_tone'],
"flag" => $flag++
),
"directed_pickup" => array(
"value" => $this->line_defaults['directed_pickup'],
"flag" => $flag++
),
"pickup_modeanswer" => array(
"value" => $this->line_defaults['pickup_modeanswer'],
"flag" => $flag++
),
"transfer" => array(
"value" => $this->line_defaults['transfer'],
"flag" => $flag++
),
"echocancel" => array( "echocancel" => array(
"value" => $this->line_defaults['echocancel'], "value" => $this->line_defaults['echocancel'],
"flag" => $flag++ "flag" => $flag++
@ -226,18 +249,14 @@ class Sccp extends \FreePBX\modules\Core\Driver {
"value" => $this->line_defaults['silencesuppression'], "value" => $this->line_defaults['silencesuppression'],
"flag" => $flag++ "flag" => $flag++
), ),
"secondary_dialtone_digits" => array(
"value" => $this->line_defaults['secondary_dialtone_digits'],
"flag" => $flag++
),
"secondary_dialtone_tone" => array(
"value" => $this->line_defaults['secondary_dialtone_tone'],
"flag" => $flag++
),
"musicclass" => array( "musicclass" => array(
"value" => $this->line_defaults['musicclass'], "value" => $this->line_defaults['musicclass'],
"flag" => $flag++ "flag" => $flag++
), ),
"pin" => array(
"value" => $this->line_defaults['pin'],
"flag" => $flag++
),
"allow" => array( "allow" => array(
"value" => $this->line_defaults['allow'], "value" => $this->line_defaults['allow'],
"flag" => $flag++ "flag" => $flag++
@ -254,6 +273,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
public function getDeviceDisplay($display, $deviceInfo, $currentcomponent, $primarySection) { public function getDeviceDisplay($display, $deviceInfo, $currentcomponent, $primarySection) {
$section = _("SCCP Extension Details"); $section = _("SCCP Extension Details");
$section_с = _("SCCP Codec Details"); $section_с = _("SCCP Codec Details");
$gn_category = "sccp"; $gn_category = "sccp";
@ -318,16 +338,16 @@ class Sccp extends \FreePBX\modules\Core\Driver {
$tmparr = array(); $tmparr = array();
$tt = _("Name or id of linked maibox"); $tt = _("Name or id of linked maibox");
$tmparr['mailbox'] = array('prompttext' => _('Mailbox'), 'value' => '', 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); $tmparr['mailbox'] = array('prompttext' => _('Mailbox'), 'value' => $this->line_defaults['mailbox'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category);
$tt = _("The SCCP channel number for this port. If you plaining to use this line as 'Shared' or use on several devices - leave this field blank or set limit to 10 calls."); $tt = _("The SCCP channel number for this port. If you plaining to use this line as 'Shared' or use on several devices - leave this field blank or set limit to 10 calls.");
$tmparr['incominglimit'] = array('prompttext' => _('Incoming Call Limit'), 'value' => '', 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); $tmparr['incominglimit'] = array('prompttext' => _('Incoming Call Limit'), $this->line_defaults['incominglimit'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category);
$tt = _("Asterisk context this device will send calls to. Only change this is you know what you are doing."); $tt = _("Asterisk context this device will send calls to. Only change this is you know what you are doing.");
$tmparr['lcontext'] = array('prompttext' => _('Line context'), 'value' => 'from-internal', 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); $tmparr['context'] = array('prompttext' => _('Line context'), 'value' => $this->line_defaults['context'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category);
$tt = _("Asterisk context this device will can pickup calls. Only change this is you know what you are doing."); $tt = _("Asterisk context this device will can pickup calls. Only change this is you know what you are doing.");
$tmparr['directed_pickup_context'] = array('prompttext' => _('Directed PickUp Сontext '), 'value' => 'from-internal', 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); $tmparr['directed_pickup_context'] = array('prompttext' => _('Directed PickUp Сontext '), 'value' => $this->line_defaults['directed_pickup_context'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category);
$tt = _("Sets the named caller groups this line is a member of (ast111) : "); $tt = _("Sets the named caller groups this line is a member of (ast111) : ");
if (!empty($named_group['namedcallgroup'])) { if (!empty($named_group['namedcallgroup'])) {
@ -336,7 +356,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
$tt .= '... '; $tt .= '... ';
} }
$tmparr['namedcallgroup'] = array('prompttext' => _('Named Call Group'),'value' => '', 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); $tmparr['namedcallgroup'] = array('prompttext' => _('Named Call Group'),'value' => $this->line_defaults['namedcallgroup'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category);
$tt = _("Named PickupGroup : "); $tt = _("Named PickupGroup : ");
if (!empty($named_group['namedpickupgroup'])) { if (!empty($named_group['namedpickupgroup'])) {
@ -345,10 +365,10 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
$tt .= '... '; $tt .= '... ';
} }
$tmparr['namedpickupgroup'] = array('prompttext' => _('Named Pickup Group'),'value' => '', 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); $tmparr['namedpickupgroup'] = array('prompttext' => _('Named Pickup Group'),'value' => $this->line_defaults['namedpickupgroup'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category);
$tt = _("Digits to indicate an external line to user (secondary dialtone) Sample 9 or 8 (max 9 digits)"); $tt = _("Digits to indicate an external line to user (secondary dialtone) Sample 9 or 8 (max 9 digits)");
$tmparr['secondary_dialtone_digits'] = array('prompttext' => _('Secondary dialtone digits'), 'value' => '', 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); $tmparr['secondary_dialtone_digits'] = array('prompttext' => _('Secondary dialtone digits'), 'value' => $this->line_defaults['secondary_dialtone_digits'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category);
unset($select); unset($select);
$select[] = array( 'value' => '0x21', 'text' => 'Inside Dial Tone'); $select[] = array( 'value' => '0x21', 'text' => 'Inside Dial Tone');
@ -409,7 +429,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
$select[] = array('value' => 'no', 'text' => 'No'); $select[] = array('value' => 'no', 'text' => 'No');
$tt = _("Outside dialtone frequency (defaul 0x22)"); $tt = _("Outside dialtone frequency (defaul 0x22)");
$tmparr['secondary_dialtone_tone'] = array('prompttext' => _('Secondary dialtone'), 'value' => '0x22', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'select', 'section' => $section,'category' => $gn_category); $tmparr['secondary_dialtone_tone'] = array('prompttext' => _('Secondary dialtone'), 'value' => $this->line_defaults['secondary_dialtone_tone'], 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'select', 'section' => $section,'category' => $gn_category);
unset($select); unset($select);
$select[] = array('value' => 'on', 'text' => 'Yes'); $select[] = array('value' => 'on', 'text' => 'Yes');
@ -434,7 +454,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
$select[] = array('value' => 'on', 'text' => 'Yes'); $select[] = array('value' => 'on', 'text' => 'Yes');
$select[] = array('value' => 'off', 'text' => 'No'); $select[] = array('value' => 'off', 'text' => 'No');
$tt = _("Echo cancel"); $tt = _("Echo cancel");
$tmparr['echocancel'] = array('prompttext' => _('Echo cancel'), 'value' => 'on', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section,'category' => $gn_category); $tmparr['echocancel'] = array('prompttext' => _('Echo cancel'), 'value' => $this->line_defaults['echocancel'], 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section,'category' => $gn_category);
unset($select); unset($select);
$select[] = array('value' => 'off', 'text' => 'Off'); $select[] = array('value' => 'off', 'text' => 'Off');
@ -445,13 +465,13 @@ class Sccp extends \FreePBX\modules\Core\Driver {
_("Cycle - dnd that cycles through all three states off -> reject -> silent -> off (this is the normal behaviour)").'<br>'. _("Cycle - dnd that cycles through all three states off -> reject -> silent -> off (this is the normal behaviour)").'<br>'.
_("Reject - Usesr can only switch off and on (in reject/busy mode)").'<br>'. _("Reject - Usesr can only switch off and on (in reject/busy mode)").'<br>'.
_("Silent - Usesr can only switch off and on (in silent mode)"); _("Silent - Usesr can only switch off and on (in silent mode)");
$tmparr['dnd'] = array('prompttext' => _('DND'), 'value' => 'reject', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section,'category' => $gn_category); $tmparr['dnd'] = array('prompttext' => _('DND'), 'value' => $this->line_defaults['dnd'], 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section,'category' => $gn_category);
unset($select); unset($select);
$select[] = array('value' => 'on', 'text' => 'Yes'); $select[] = array('value' => 'on', 'text' => 'Yes');
$select[] = array('value' => 'off', 'text' => 'No'); $select[] = array('value' => 'off', 'text' => 'No');
$tt = _("Silence Suppression. Asterisk Not supported"); $tt = _("Silence Suppression. Asterisk Not supported");
$tmparr['silencesuppression'] = array('prompttext' => _('Silence Suppression'), 'value' => 'off', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section,'category' => $gn_category); $tmparr['silencesuppression'] = array('prompttext' => _('Silence Suppression'), 'value' => $this->line_defaults['silencesuppression'], 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section,'category' => $gn_category);
unset($select); unset($select);
$select[] = array('value' => 'default', 'text' => _('default')); $select[] = array('value' => 'default', 'text' => _('default'));
@ -465,7 +485,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
$tt = _("Music on hold"); $tt = _("Music on hold");
$tmparr['musicclass'] = array('prompttext' => _('Music on hold'), 'value' => '', 'tt' => $tt, 'select' => $select, 'level' => 1, 'section' => $section,'category' => $gn_category); $tmparr['musicclass'] = array('prompttext' => _('Music on hold'), 'value' => $this->line_defaults['musicclass'], 'tt' => $tt, 'select' => $select, 'level' => 1, 'section' => $section,'category' => $gn_category);
unset($select); unset($select);
$tt = _("Sets the named pickup groups this line is a member of (this phone can pickup calls from remote phones which are in this caller group (ast111)"); $tt = _("Sets the named pickup groups this line is a member of (this phone can pickup calls from remote phones which are in this caller group (ast111)");