Refine Sccp.class

Move help and other defs to sccpgeneral so that have one interface across system
Correct defaults in line with chan-sccp
Standardise db object, and move sql to dbinterface to remove second dependancy
This commit is contained in:
steve-lad 2021-07-08 17:22:50 +02:00
parent 6429b6add9
commit acb0141d99
5 changed files with 371 additions and 236 deletions

View file

@ -15,6 +15,7 @@ and open the template in the editor. Base Version before all crash :-)
* SLT - TFTP Lang * SLT - TFTP Lang
* SLM - Music on hold * SLM - Music on hold
* SLK - System KeySet * SLK - System KeySet
* SLG - call groups
* * Input element Select SLS - System Language * * Input element Select SLS - System Language
* Input element Select SDM - Model List * Input element Select SDM - Model List
* SDE - Extension List tftp_rewrite * SDE - Extension List tftp_rewrite
@ -1923,4 +1924,147 @@ and open the template in the editor. Base Version before all crash :-)
</item> </item>
</page_group> </page_group>
<page_group name="sccp_extension_config">
<label>SCCP Extension Details</label>
<item type="IE" id="4">
<label>Mailbox</label>
<input>
<name>mailbox</name>
<default></default>
<class>sccp-custom</class>
</input>
<help>Name or id of linked maibox</help>
</item>
<item type="IE" id="4">
<label>Incoming Call Limit</label>
<input>
<name>incominglimit</name>
<default></default>
<class>sccp-custom</class>
</input>
<help>The SCCP channel number for this port. If you are planning to use this line as 'Shared' or use on several devices - leave this field blank or set limit to 10 calls.</help>
</item>
<item type="IE" id="4">
<label>Line Context</label>
<input>
<name>context</name>
<default></default>
<class>sccp-custom</class>
</input>
<help>Context: This is the context in which your phones will operate. It should match the context you are using for the rest of your phones (if you have any). The FreePBX default is 'from-internal'</help>
</item>
<item type="IE" id="7">
<label>Directed pickup context</label>
<input>
<name>directed_pickup_context</name>
<default></default>
<options placeholder="from_internal"></options>
<class>sccp-custom</class>
</input>
<help>Context where direct pickup search for extensions. if not set current context will be use.</help>
</item>
<item type="SLG" id="7">
<label>Named Call Group</label>
<name>namedcallgroup</name>
<select>
<default></default>
</select>
<help>Sets the named caller groups this line is a member of</help>
</item>
<item type="SLG" id="7">
<label>Named Pickup Group</label>
<name>namedpickupgroup</name>
<select>
<default></default>
</select>
<help>Named PickupGroup - the list is of pickup groups used on the system</help>
</item>
<item type="IE" id="7">
<label>Secondary dialtone digits</label>
<input>
<name>secondary_dialtone_digits</name>
<default></default>
<class>sccp-custom</class>
</input>
<help>Digits to indicate an external line to user (secondary dialtone) Sample 9 or 8 (max 9 digits)</help>
</item>
<item type="SLD" id="1">
<name>secondary_dialtone_tone</name>
<label>Secondary dialtone</label>
<select>
<default></default>
</select>
<help>Outside dialtone frequency (default 0x22)</help>
</item>
<item type="IS" id="11">
<name>directed_pickup</name>
<label>Directed Pickup</label>
<default></default>
<button value="yes">Yes</button>
<button value="no">No</button>
<help>Enable/disable Pickup button to do directed pickup from a specific extension.</help>
</item>
<item type="IS" id="11">
<name>pickup_modeanswer</name>
<label>Directed Pickup Answer</label>
<default>off</default>
<button value="yes">Yes</button>
<button value="no">No</button>
<help>Directed Pickup Mode (Answer): If a call is sent with the "directed pickup" flag, the phone will answer when set to "Yes".</help>
</item>
<item type="IS" id="1" seq="0">
<name>transfer</name>
<label>Transfer</label>
<default></default>
<button value="yes">Yes</button>
<button value="no">No</button>
<help>Allow the use of the transfer feature</help>
</item>
<item type="IS" id="8">
<name>echocancel</name>
<label>Echo Cancel</label>
<default>off</default>
<button value="yes">Yes</button>
<button value="no">No</button>
<help>Echo Cancel: Echo Cancellation (On or Off).</help>
</item>
<item type="IS" id="5" seq="0">
<name>dnd</name>
<label>DND</label>
<default></default>
<button value="off">Off</button>
<button value="reject">Reject</button>
<button value="silent">Silent</button>
<button value="cycle">Cycle</button>
<help>DND: Means how will dnd react when it is set on the device level dnd can have three states: off / busy(reject) / silent / Cycle
Cycle - DND that cycles through all three states off -> reject -> silent -> off (this is the normal behaviour)
Reject - Users can only switch off and on (in reject/busy mode)
Silent - Users can only switch off and on (in silent mode)</help>
</item>
<item type="IS" id="9">
<name>silencesuppression</name>
<label>Silence Suppression</label>
<default>off</default>
<button value="yes">Yes</button>
<button value="no">No</button>
<help>Silence Suppression: Silence Suppression on the phone.</help>
</item>
<item type="SLM" id="6">
<label>Music On Hold Class</label>
<name>musicclass</name>
<default>NONE</default>
<select></select>
<class>form-control</class>
<help>Music Class: Available MOH Classes. These are the MOH classes listed in your current server.</help>
</item>
<item type="IE" id="2" seq="99">
<label>User Pincode</label>
<input>
<name>pin</name>
<default></default>
</input>
<help>Help!</help>
</item>
</page_group>
</root> </root>

View file

@ -162,7 +162,7 @@ function Get_DB_config($sccp_compatible)
'video_cos' => array('drop' => "yes"), 'video_cos' => array('drop' => "yes"),
'videomode' => array('create' => "enum('user','auto','off') NOT NULL default 'auto'", 'modify' => "enum('user','auto','off')"), 'videomode' => array('create' => "enum('user','auto','off') NOT NULL default 'auto'", 'modify' => "enum('user','auto','off')"),
'incominglimit' => array('create' => "INT(11) DEFAULT '6'", 'modify' => 'INT(11)', 'def_modify' => "6"), 'incominglimit' => array('create' => "INT(11) DEFAULT '6'", 'modify' => 'INT(11)', 'def_modify' => "6"),
'transfer' => array('create' => "enum('on','off') NOT NULL default 'on'", 'modify' => "enum('on','off')"), 'transfer' => array('create' => "enum('yes','no') NOT NULL default 'yes'", 'modify' => "enum('yes','no')"),
'vmnum' => array('def_modify' => "*97"), 'vmnum' => array('def_modify' => "*97"),
'musicclass' => array('def_modify' => "default"), 'musicclass' => array('def_modify' => "default"),
'disallow' => array('create' => "VARCHAR(255) NULL DEFAULT NULL"), 'disallow' => array('create' => "VARCHAR(255) NULL DEFAULT NULL"),

View file

@ -1,7 +1,7 @@
<module> <module>
<rawname>sccp_manager</rawname> <rawname>sccp_manager</rawname>
<name>SCCP Manager</name> <name>SCCP Manager</name>
<version>14.3.0.0</version> <version>14.3.0.1</version>
<type>setup</type> <type>setup</type>
<category>SCCP Connectivity</category> <category>SCCP Connectivity</category>
<publisher>Steve Lad, Alex GP</publisher> <publisher>Steve Lad, Alex GP</publisher>

View file

@ -42,7 +42,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
"language" => 'language', "description" => 'callerid', "language" => 'language', "description" => 'callerid',
"cid_num" => 'cid_num', "cid_name" => 'label', "mailbox" => 'mailbox', "cid_num" => 'cid_num', "cid_name" => 'label', "mailbox" => 'mailbox',
"musicclass" => 'musicclass', "allow" => 'allow',"disallow" => 'disallow', "musicclass" => 'musicclass', "allow" => 'allow',"disallow" => 'disallow',
"videomode" => 'videomode', "videomode" => 'videomode', 'pickup_modeanswer' => 'pickup_modeanswer',
"dnd" => 'dnd', "silencesuppression" => 'silencesuppression', "dnd" => 'dnd', "silencesuppression" => 'silencesuppression',
"secondary_dialtone_digits" => 'secondary_dialtone_digits', "secondary_dialtone_tone" => 'secondary_dialtone_tone', "secondary_dialtone_digits" => 'secondary_dialtone_digits', "secondary_dialtone_tone" => 'secondary_dialtone_tone',
'namedcallgroup'=>'namedcallgroup', 'namedpickupgroup' => 'namedpickupgroup' 'namedcallgroup'=>'namedcallgroup', 'namedpickupgroup' => 'namedpickupgroup'
@ -116,6 +116,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
} }
} }
dbug('addD', $settings);
$allow_codec = array(); $allow_codec = array();
foreach($settings as $key => $val) { foreach($settings as $key => $val) {
if (strncmp($key,'codec_',6) === 0 ) { if (strncmp($key,'codec_',6) === 0 ) {
@ -155,6 +156,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
} }
$sql = "REPLACE INTO sccpline ( {$sqlCol} ) VALUES ( {$sqlVal} )"; $sql = "REPLACE INTO sccpline ( {$sqlCol} ) VALUES ( {$sqlVal} )";
dbug('sql', $sql);
$sth = $this->database->prepare($sql); $sth = $this->database->prepare($sql);
$sth->execute(); $sth->execute();
/* /*
@ -173,6 +175,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
public function delDevice($id) { public function delDevice($id) {
//Required by FreePBX
$sql = "DELETE FROM sccpline WHERE name = ?"; $sql = "DELETE FROM sccpline WHERE name = ?";
$sth = $this->database->prepare($sql); $sth = $this->database->prepare($sql);
$sth->execute(array($id)); $sth->execute(array($id));
@ -180,9 +183,10 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
public function getDevice($id) { public function getDevice($id) {
$sql = "SELECT name as id, name as name "; // FreePBX required method
$sql = "SELECT name AS id, name AS name ";
foreach($this->data_fld as $key => $val) { foreach($this->data_fld as $key => $val) {
$sql .= ", {$key} as {$val}"; $sql .= ", {$key} AS {$val}";
} }
$sql .= " FROM sccpline WHERE name = '{$id}'"; $sql .= " FROM sccpline WHERE name = '{$id}'";
$sth = $this->database->prepare($sql); $sth = $this->database->prepare($sql);
@ -207,28 +211,59 @@ class Sccp extends \FreePBX\modules\Core\Driver {
} }
public function getDeviceDisplay($display, $deviceInfo, $currentcomponent, $primarySection) { public function getDeviceDisplay($display, $deviceInfo, $currentcomponent, $primarySection) {
dbug('deviceInfo', $deviceInfo); dbug('devInfo', $deviceInfo);
// load xml data to get help from same source as rest of module
$xml_vars = $_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/conf/sccpgeneral.xml.v433';
$this->xml_data = simplexml_load_file($xml_vars);
// load metainfo from chan-sccp - help information if not in xml. Only load first time as static data.
if (empty($this->sccpHelpInfo)) {
$sysConfiguration = \FreePbx::sccp_manager()->aminterface->getSCCPConfigMetaData('general');
foreach ($sysConfiguration['Options'] as $key => $valueArray) {
foreach ($valueArray['Description'] as $descKey => $descValue) {
$this->sccpHelpInfo[$valueArray['Name']] .= $descValue . '<br>';
}
}
unset($sysConfiguration);
}
$section = _("SCCP Extension Details"); $section = _("SCCP Extension Details");
$section_с = _("SCCP Codec Details"); $section_с = _("SCCP Codec Details");
$gn_category = "sccp"; $gn_category = "sccp";
global $currentcomponent, $display; global $currentcomponent, $display;
$named_group = $this->getNamedGroup();
//add sccp category //add sccp category
$currentcomponent->addTabTranslation('sccp',_('SCCP')); $currentcomponent->addTabTranslation('sccp',_('SCCP'));
// TODO: If we have upgraded the system codecs, need to allow new options here.
$systemCodecs = array_fill_keys(explode(",",$this->line_defaults['allow']),true); if (empty($deviceInfo['allow'])) {
// Need a codec and have none, so use system defaults
$systemCodecs = array_fill_keys(explode(",",$this->line_defaults['allow']),true);
$siteAudioCodecs = array_intersect_key($systemCodecs, $this->freepbx->Codecs->getAudio());
$siteVideoCodecs = array_intersect_key($systemCodecs, $this->freepbx->Codecs->getVideo());
} else {
// TODO: Need to show disabled options
// Have codecs for this device.
$systemCodecs = array_fill_keys(explode(",",$deviceInfo['allow']),true); //pb is here
$siteAudioCodecs = array_intersect_key($systemCodecs, $this->freepbx->Codecs->getAudio());
$siteVideoCodecs = array_intersect_key($systemCodecs, $this->freepbx->Codecs->getVideo());
}
// Fill Audio codecs information // Fill Audio codecs information
$siteAudioCodecs = array_intersect_key($systemCodecs, $this->freepbx->Codecs->getAudio());
foreach ($siteAudioCodecs as $key => $value) { foreach ($siteAudioCodecs as $key => $value) {
$audioCodecButtons[] = array('value' => "devinfo_codec_{$key}", 'text' => $key); $audioCodecButtons[] = array('value' => "devinfo_codec_{$key}", 'text' => $key);
$activeAudioCodecs[] ="devinfo_codec_{$key}"; $activeAudioCodecs[] ="devinfo_codec_{$key}";
} }
// Fill Video codecs information // Fill Video codecs information
$siteVideoCodecs = array_intersect_key($systemCodecs, $this->freepbx->Codecs->getVideo());
foreach ($siteVideoCodecs as $key => $value) { foreach ($siteVideoCodecs as $key => $value) {
$videoCodecButtons[] = array('value' => "devinfo_codec_{$key}", 'text' => $key); $videoCodecButtons[] = array('value' => "devinfo_codec_{$key}", 'text' => $key);
$activeVideoCodecs[] ="devinfo_codec_{$key}"; $activeVideoCodecs[] ="devinfo_codec_{$key}";
} }
$tmparr['disallow'] = array('prompttext' => _('Disallowed Codecs'),
'value' => $this->line_defaults[(string)$child->name],
'tt' => 'Codecs that are disallowed. Default and recommended value is all',
'level' => 1,
'section' => $section_с,
'category' => $gn_category
);
$el = array( $el = array(
"elemname" => "devinfo_sccp_codec", "elemname" => "devinfo_sccp_codec",
"prompttext" => _('Line Audio Codec:'), "prompttext" => _('Line Audio Codec:'),
@ -253,175 +288,145 @@ class Sccp extends \FreePBX\modules\Core\Driver {
); );
$currentcomponent->addguielem($section_с, new \gui_checkset(array_merge($this->guiDefaults['gui_checkset'],$el)), $gn_category); $currentcomponent->addguielem($section_с, new \gui_checkset(array_merge($this->guiDefaults['gui_checkset'],$el)), $gn_category);
$tmparr = array(); $pageGroup = $this->xml_data->xpath('//page_group[@name="sccp_extension_config"]');
$tt = _("Name or id of linked maibox"); $elements = $pageGroup[0]->children();
$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 are planning to use this line as 'Shared' or use on several devices - leave this field blank or set limit to 10 calls."); foreach ($elements as $child) {
$tmparr['incominglimit'] = array('prompttext' => _('Incoming Call Limit'), $this->line_defaults['incominglimit'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); if (empty($child->help)) {
$child->help = 'Help is not available.';
$tt = _("Asterisk context this device will send calls to. Only change this is you know what you are doing."); $child->meta_help = '1';
$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.");
$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) : ");
if (!empty($named_group['namedcallgroup'])) {
foreach ($named_group['namedcallgroup'] as $val) {
$tt .= $val. ', ';
} }
$tt .= '... '; switch ($child['type']) {
} case 'IE':
$tmparr['namedcallgroup'] = array('prompttext' => _('Named Call Group'),'value' => $this->line_defaults['namedcallgroup'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); $elementID = (string)$child->input[0]->name;
if (!empty($metainfo[$elementID])) {
$tt = _("Named PickupGroup : "); if ($child->meta_help == '1' || $child->help == 'Help!') {
if (!empty($named_group['namedpickupgroup'])) { $child->help = $metainfo[$shortId];
foreach ($named_group['namedpickupgroup'] as $val) {
$tt .= $val. ', ';
} }
$tt .= '... ';
} }
$tmparr['namedpickupgroup'] = array('prompttext' => _('Named Pickup Group'),'value' => $this->line_defaults['namedpickupgroup'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category); $tmparr[$elementID] = array('prompttext' => _((string)$child->label),
'value' => $this->line_defaults[$elementID],
'tt' => (string)$child->help,
'level' => 1,
'section' => $section,
'category' => $gn_category
);
break;
case 'IS':
$select = array();
foreach ($child->xpath('button') as $value) {
$select[] = array('value' => strtolower((string)$value[@value]), 'text' => (string)$value);
}
$tmparr[(string)$child->name] = array('prompttext' => _((string)$child->label),
'value' => $this->line_defaults[(string)$child->name],
'tt' => (string)$child->help,
'select' => $select,
'level' => 1,
'type' => 'radio',
'section' => $section,
'category' => $gn_category
);
unset($select);
break;
case 'SLD':
$select = array(
array( 'value' => '0x21', 'text' => 'Inside Dial Tone'),
array( 'value' => '0x22', 'text' => 'Outside Dial Tone'),
array( 'value' => '0x23', 'text' => 'Line Busy Tone'),
array( 'value' => '0x24', 'text' => 'Alerting Tone'),
array( 'value' => '0x25', 'text' => 'Reorder Tone'),
array( 'value' => '0x26', 'text' => 'Recorder Warning Tone'),
array( 'value' => '0x27', 'text' => 'Recorder Detected Tone'),
array( 'value' => '0x28', 'text' => 'Reverting Tone'),
array( 'value' => '0x29', 'text' => 'Receiver OffHook Tone'),
array( 'value' => '0x2A', 'text' => 'Partial Dial Tone'),
array( 'value' => '0x2B', 'text' => 'No Such Number Tone'),
array( 'value' => '0x2C', 'text' => 'Busy Verification Tone'),
array( 'value' => '0x2D', 'text' => 'Call Waiting Tone'),
array( 'value' => '0x2E', 'text' => 'Confirmation Tone'),
array( 'value' => '0x2F', 'text' => 'Camp On Indication Tone'),
array( 'value' => '0x30', 'text' => 'Recall Dial Tone'),
array( 'value' => '0x31', 'text' => 'Zip Zip'),
array( 'value' => '0x32', 'text' => 'Zip'),
array( 'value' => '0x33', 'text' => 'Beep Bonk'),
array( 'value' => '0x34', 'text' => 'Music Tone'),
array( 'value' => '0x35', 'text' => 'Hold Tone'),
array( 'value' => '0x36', 'text' => 'Test Tone'),
array( 'value' => '0x37', 'text' => 'DT Monitor Warning Tone'),
array( 'value' => '0x40', 'text' => 'Add Call Waiting'),
array( 'value' => '0x41', 'text' => 'Priority Call Wait'),
array( 'value' => '0x42', 'text' => 'Recall Dial'),
array( 'value' => '0x43', 'text' => 'Barg In'),
array( 'value' => '0x44', 'text' => 'Distinct Alert'),
array( 'value' => '0x45', 'text' => 'Priority Alert'),
array( 'value' => '0x46', 'text' => 'Reminder Ring'),
array( 'value' => '0x47', 'text' => 'Precedence RingBank'),
array( 'value' => '0x48', 'text' => 'Pre-EmptionTone'),
array( 'value' => '0x67', 'text' => '2105 HZ'),
array( 'value' => '0x68', 'text' => '2600 HZ'),
array( 'value' => '0x69', 'text' => '440 HZ'),
array( 'value' => '0x6A', 'text' => '300 HZ'),
array( 'value' => '0x77', 'text' => 'MLPP Pala'),
array( 'value' => '0x78', 'text' => 'MLPP Ica'),
array( 'value' => '0x79', 'text' => 'MLPP Vca'),
array( 'value' => '0x7A', 'text' => 'MLPP Bpa'),
array( 'value' => '0x7B', 'text' => 'MLPP Bnea'),
array( 'value' => '0x7C', 'text' => 'MLPP Upa')
);
$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' => $this->line_defaults['secondary_dialtone_digits'], 'tt' => $tt, 'level' => 1, 'section' => $section,'category' => $gn_category);
unset($select); $tmparr[(string)$child->name] = array('prompttext' => _((string)$child->label),
$select[] = array( 'value' => '0x21', 'text' => 'Inside Dial Tone'); 'value' => $this->line_defaults[(string)$child->name],
$select[] = array( 'value' => '0x22', 'text' => 'Outside Dial Tone'); 'tt' => (string)$child->help,
$select[] = array( 'value' => '0x23', 'text' => 'Line Busy Tone'); 'select' => $select,
$select[] = array( 'value' => '0x24', 'text' => 'Alerting Tone'); 'level' => 1,
$select[] = array( 'value' => '0x25', 'text' => 'Reorder Tone'); 'type' => 'select',
$select[] = array( 'value' => '0x26', 'text' => 'Recorder Warning Tone'); 'section' => $section,
$select[] = array( 'value' => '0x27', 'text' => 'Recorder Detected Tone'); 'category' => $gn_category
$select[] = array( 'value' => '0x28', 'text' => 'Reverting Tone'); );
$select[] = array( 'value' => '0x29', 'text' => 'Receiver OffHook Tone'); unset($select);
$select[] = array( 'value' => '0x2A', 'text' => 'Partial Dial Tone'); break;
$select[] = array( 'value' => '0x2B', 'text' => 'No Such Number Tone'); case 'SLG':
$select[] = array( 'value' => '0x2C', 'text' => 'Busy Verification Tone'); $elementID = (string)$child->name;
$select[] = array( 'value' => '0x2D', 'text' => 'Call Waiting Tone'); $named_group = \FreePbx::sccp_manager()->dbinterface->getNamedGroup($elementID);
$select[] = array( 'value' => '0x2E', 'text' => 'Confirmation Tone'); if (!empty($named_group[$elementID])) {
$select[] = array( 'value' => '0x2F', 'text' => 'Camp On Indication Tone'); foreach ($named_group[$elementID] as $val) {
$select[] = array( 'value' => '0x30', 'text' => 'Recall Dial Tone'); $select[] = array('value' => $val, 'text' => $val);
$select[] = array( 'value' => '0x31', 'text' => 'Zip Zip'); }
$select[] = array( 'value' => '0x32', 'text' => 'Zip'); }
$select[] = array( 'value' => '0x33', 'text' => 'Beep Bonk'); $tmparr[(string)$child->name] = array('prompttext' => _((string)$child->label),
$select[] = array( 'value' => '0x34', 'text' => 'Music Tone'); 'value' => $this->line_defaults[(string)$child->name],
$select[] = array( 'value' => '0x35', 'text' => 'Hold Tone'); 'tt' => (string)$child->help,
$select[] = array( 'value' => '0x36', 'text' => 'Test Tone'); 'select' => $select,
$select[] = array( 'value' => '0x37', 'text' => 'DT Monitor Warning Tone'); 'level' => 1,
$select[] = array( 'value' => '0x40', 'text' => 'Add Call Waiting'); 'section' => $section,
$select[] = array( 'value' => '0x41', 'text' => 'Priority Call Wait'); 'category' => $gn_category
$select[] = array( 'value' => '0x42', 'text' => 'Recall Dial'); );
$select[] = array( 'value' => '0x43', 'text' => 'Barg In'); unset($select);
$select[] = array( 'value' => '0x44', 'text' => 'Distinct Alert'); break;
$select[] = array( 'value' => '0x45', 'text' => 'Priority Alert'); case 'SLM':
$select[] = array( 'value' => '0x46', 'text' => 'Reminder Ring'); if (function_exists('music_list')){
$select[] = array( 'value' => '0x47', 'text' => 'Precedence RingBank'); foreach (music_list() as $value) {
$select[] = array( 'value' => '0x48', 'text' => 'Pre-EmptionTone'); $select[] = array('value' => $value, 'text' => _($value));
$select[] = array( 'value' => '0x67', 'text' => '2105 HZ'); }
$select[] = array( 'value' => '0x68', 'text' => '2600 HZ'); } else {
$select[] = array( 'value' => '0x69', 'text' => '440 HZ'); $select[] = array('value' => 'default', 'text' => _('default'));
$select[] = array( 'value' => '0x6A', 'text' => '300 HZ'); }
$select[] = array( 'value' => '0x77', 'text' => 'MLPP Pala'); $tmparr[(string)$child->name] = array('prompttext' => _((string)$child->label),
$select[] = array( 'value' => '0x78', 'text' => 'MLPP Ica'); 'value' => $this->line_defaults[(string)$child->name],
$select[] = array( 'value' => '0x79', 'text' => 'MLPP Vca'); 'tt' => (string)$child->help,
$select[] = array( 'value' => '0x7A', 'text' => 'MLPP Bpa'); 'select' => $select,
$select[] = array( 'value' => '0x7B', 'text' => 'MLPP Bnea'); 'level' => 1,
$select[] = array( 'value' => '0x7C', 'text' => 'MLPP Upa'); 'type' => 'select',
/* !TODO!: I would remove the values below this line, except for 'No Tone' */ 'section' => $section,
// $select[] = array( 'value' => '0x7F', 'text' => 'No Tone'); 'category' => $gn_category
$select[] = array( 'value' => '0x80', 'text' => 'Meetme Greeting Tone'); );
$select[] = array( 'value' => '0x81', 'text' => 'Meetme Number Invalid Tone'); unset($select);
$select[] = array( 'value' => '0x82', 'text' => 'Meetme Number Failed Tone'); break;
$select[] = array( 'value' => '0x83', 'text' => 'Meetme Enter Pin Tone'); }
$select[] = array( 'value' => '0x84', 'text' => 'Meetme Invalid Pin Tone');
$select[] = array( 'value' => '0x85', 'text' => 'Meetme Failed Pin Tone');
$select[] = array( 'value' => '0x86', 'text' => 'Meetme CFB Failed Tone');
$select[] = array( 'value' => '0x87', 'text' => 'Meetme Enter Access Code Tone');
$select[] = array( 'value' => '0x88', 'text' => 'Meetme Access Code Invalid Tone');
$select[] = array( 'value' => '0x89', 'text' => 'Meetme Access Code Failed Tone');
$select[] = array('value' => 'yes', 'text' => 'Yes');
$select[] = array('value' => 'no', 'text' => 'No');
$tt = _("Outside dialtone frequency (defaul 0x22)");
$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);
$select[] = array('value' => 'yes', 'text' => 'Yes');
$select[] = array('value' => 'no', 'text' => 'No');
$tt = _("Enable/Disable the `directed` pickup softkey");
$tmparr['directed_pickup'] = array('prompttext' => _('Directed pickup'), 'value' => $this->line_defaults['directed_pickup'], 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section,'category' => $gn_category);
unset($select);
$select[] = array('value' => 'yes', 'text' => 'Yes');
$select[] = array('value' => 'no', 'text' => 'No');
$tt = _("Should the picked/gpicked-up call be answered automatically");
$tmparr['pickup_modeanswer'] = array('prompttext' => _('Pickup Modeanswer'), 'value' => $this->line_defaults['pickup_modeanswer'], 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section,'category' => $gn_category);
unset($select);
$select[] = array('value' => 'on', 'text' => 'Yes');
$select[] = array('value' => 'off', 'text' => 'No');
$tt = _("Allow call transfer.");
// $tmparr['transfer'] = array('prompttext' => _('Call Transfer'), 'value' => 'yes', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section, 'category' => 'general');
$tmparr['transfer'] = array('prompttext' => _('Call Transfer'), 'value' => $this->line_defaults['transfer'], 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section,'category' => $gn_category);
unset($select);
$select[] = array('value' => 'yes', 'text' => 'Yes');
$select[] = array('value' => 'no', 'text' => 'No');
$tt = _("Echo cancel");
$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);
$select[] = array('value' => 'off', 'text' => 'Off');
$select[] = array('value' => 'reject', 'text' => 'Reject');
$select[] = array('value' => 'silent', 'text' => 'Silent');
$select[] = array('value' => 'user', 'text' => 'Cycle');
$tt = _("DND: Means how will dnd react when it is set on the device level dnd can have three states: off / busy(reject) / silent / Cycle").'<br>'.
_("Cycle - DND that cycles through all three states off -> reject -> silent -> off (this is the normal behaviour)").'<br>'.
_("Reject - Users can only switch off and on (in reject/busy mode)").'<br>'.
_("Silent - Users can only switch off and on (in silent mode)");
$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);
$select[] = array('value' => 'yes', 'text' => 'Yes');
$select[] = array('value' => 'no', 'text' => 'No');
$tt = _("Silence Suppression. Asterisk Not supported");
$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);
if (function_exists('music_list')){
$moh_list = music_list();
} else {
$select[] = array('value' => 'default', 'text' => _('default'));
}
foreach ($moh_list as $value) {
$select[] = array('value' => $value, 'text' => _($value));
} }
$tt = _("Music on hold"); return $tmparr;
$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);
$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)");
$tmparr['pin'] = array('value' => '', 'tt' => $tt, 'level' => 1, 'section' => $section ,'category' => $gn_category);
unset($select);
$select[] = array('value' => 'off', 'text' => 'Off');
$select[] = array('value' => 'user', 'text' => 'User');
$select[] = array('value' => 'auto', 'text' => 'Auto');
$tt = _("Automatic or Manual video mode. Valid values are 'auto', 'user' or 'off'. When set to 'auto', video will automatically start if both parties have a compatible code enabled. In 'user' mode the user needs to press the vidmode softkey before video will be tried. Default:'auto'");
$tmparr['videomode'] = array('prompttext' => _('Video Mode '), 'value' => 'auto', 'tt' => $tt, 'select' => $select, 'level' => 1, 'type' => 'radio', 'section' => $section_с, 'category' => $gn_category);
unset($select);
$tt = _("Codec disallow");
$tmparr['disallow'] = array('prompttext' => _('Codec disallow'), 'value' => 'all', 'tt' => $tt, 'level' => 1, 'section' => $section_с,'category' => $gn_category);
unset($select);
$devopts = $tmparr;
return $devopts;
} }
public function reload_line($id) { public function reload_line($id) {
@ -431,30 +436,7 @@ class Sccp extends \FreePBX\modules\Core\Driver {
return $result; return $result;
} }
public function getNamedGroup() {
$sql = "SELECT namedcallgroup FROM sccpline GROUP BY namedcallgroup";
$sth = $this->database->prepare($sql);
$result = array();
$tech = array();
try {
$sth->execute();
$result = $sth->fetchAll();
foreach($result as $val) {
$tech['namedcallgroup'][] = $val[0];
}
} catch(\Exception $e) {}
$sql = "SELECT namedpickupgroup FROM sccpline GROUP BY namedpickupgroup";
$sth = $this->database->prepare($sql);
try {
$sth->execute();
$result = $sth->fetchAll();
foreach($result as $val) {
$tech['namedpickupgroup'][] = $val[0];
}
} catch(\Exception $e) {}
return $tech;
}
public function getDeviceHeaders() { public function getDeviceHeaders() {
return array( return array(

View file

@ -17,6 +17,7 @@ class dbinterface
public function __construct($parent_class = null) public function __construct($parent_class = null)
{ {
$this->paren_class = $parent_class; $this->paren_class = $parent_class;
$this->db = \FreePBX::Database();
} }
public function info() public function info()
@ -46,7 +47,6 @@ class dbinterface
public function getSccpDeviceTableData($dataid, $data = array()) public function getSccpDeviceTableData($dataid, $data = array())
{ {
// $stmt is a single row fetch, $stmts is a fetchAll. // $stmt is a single row fetch, $stmts is a fetchAll.
$dbh = \FreePBX::Database();
$stmt = ''; $stmt = '';
$stmts = ''; $stmts = '';
if ($dataid == '') { if ($dataid == '') {
@ -55,9 +55,9 @@ class dbinterface
switch ($dataid) { switch ($dataid) {
case 'SccpExtension': case 'SccpExtension':
if (empty($data['name'])) { if (empty($data['name'])) {
$stmts = $dbh->prepare('SELECT * FROM sccpline ORDER BY name'); $stmts = $this->db->prepare('SELECT * FROM sccpline ORDER BY name');
} else { } else {
$stmts = $dbh->prepare('SELECT * FROM sccpline WHERE name = :name'); $stmts = $this->db->prepare('SELECT * FROM sccpline WHERE name = :name');
$stmts->bindParam(':name', $data['name'],\PDO::PARAM_STR); $stmts->bindParam(':name', $data['name'],\PDO::PARAM_STR);
} }
break; break;
@ -78,20 +78,20 @@ class dbinterface
} }
} }
if (!empty($data['name'])) { //either filter by name or by type if (!empty($data['name'])) { //either filter by name or by type
$stmt = $dbh->prepare('SELECT ' . $fld . ' FROM sccpdeviceconfig WHERE name = :name ORDER BY name'); $stmt = $this->db->prepare('SELECT ' . $fld . ' FROM sccpdeviceconfig WHERE name = :name ORDER BY name');
$stmt->bindParam(':name', $data['name'],\PDO::PARAM_STR); $stmt->bindParam(':name', $data['name'],\PDO::PARAM_STR);
} elseif (!empty($data['type'])) { } elseif (!empty($data['type'])) {
switch ($data['type']) { switch ($data['type']) {
case "cisco-sip": case "cisco-sip":
$stmts = $dbh->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE TYPE LIKE '%-sip' ORDER BY name"); $stmts = $this->db->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE TYPE LIKE '%-sip' ORDER BY name");
break; break;
case "cisco": // Fall through to default intentionally case "cisco": // Fall through to default intentionally
default: default:
$stmts = $dbh->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE TYPE not LIKE '%-sip' ORDER BY name"); $stmts = $this->db->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE TYPE not LIKE '%-sip' ORDER BY name");
break; break;
} }
} else { //no filter and no name provided - return all } else { //no filter and no name provided - return all
$stmts = $dbh->prepare("SELECT {$fld} FROM sccpdeviceconfig ORDER BY name"); $stmts = $this->db->prepare("SELECT {$fld} FROM sccpdeviceconfig ORDER BY name");
} }
break; break;
case 'HWSipDevice': case 'HWSipDevice':
@ -104,23 +104,23 @@ class dbinterface
$raw_settings = $this->getDb_model_info($get = "extension", $format_list = "model"); $raw_settings = $this->getDb_model_info($get = "extension", $format_list = "model");
break; break;
case 'get_columns_sccpdevice': case 'get_columns_sccpdevice':
$stmts = $dbh->prepare('DESCRIBE sccpdevice'); $stmts = $this->db->prepare('DESCRIBE sccpdevice');
break; break;
case 'get_columns_sccpuser': case 'get_columns_sccpuser':
$stmts = $dbh->prepare('DESCRIBE sccpuser'); $stmts = $this->db->prepare('DESCRIBE sccpuser');
break; break;
case 'get_columns_sccpline': case 'get_columns_sccpline':
$stmts = $dbh->prepare('DESCRIBE sccpline'); $stmts = $this->db->prepare('DESCRIBE sccpline');
break; break;
case 'get_sccpdevice_byid': case 'get_sccpdevice_byid':
$stmt = $dbh->prepare('SELECT t1.*, types.dns, types.buttons, types.loadimage, types.nametemplate as nametemplate, $stmt = $this->db->prepare('SELECT t1.*, types.dns, types.buttons, types.loadimage, types.nametemplate as nametemplate,
addon.buttons as addon_buttons FROM sccpdevice AS t1 addon.buttons as addon_buttons FROM sccpdevice AS t1
LEFT JOIN sccpdevmodel as types ON t1.type=types.model LEFT JOIN sccpdevmodel as types ON t1.type=types.model
LEFT JOIN sccpdevmodel as addon ON t1.addon=addon.model WHERE name = :name'); LEFT JOIN sccpdevmodel as addon ON t1.addon=addon.model WHERE name = :name');
$stmt->bindParam(':name', $data['id'],\PDO::PARAM_STR); $stmt->bindParam(':name', $data['id'],\PDO::PARAM_STR);
break; break;
case 'get_sccpuser': case 'get_sccpuser':
$stmt = $dbh->prepare('SELECT * FROM sccpuser WHERE name = :name'); $stmt = $this->db->prepare('SELECT * FROM sccpuser WHERE name = :name');
$stmt->bindParam(':name', $data['id'],\PDO::PARAM_STR); $stmt->bindParam(':name', $data['id'],\PDO::PARAM_STR);
break; break;
case 'get_sccpdevice_buttons': case 'get_sccpdevice_buttons':
@ -132,7 +132,7 @@ class dbinterface
$sql .= (empty($sql)) ? 'ref = :ref' : ' and ref = :ref'; $sql .= (empty($sql)) ? 'ref = :ref' : ' and ref = :ref';
} }
if (!empty($sql)) { if (!empty($sql)) {
$stmts = $dbh->prepare("SELECT * FROM sccpbuttonconfig WHERE {$sql} ORDER BY instance"); $stmts = $this->db->prepare("SELECT * FROM sccpbuttonconfig WHERE {$sql} ORDER BY instance");
// Now bind labels - only bind label if it exists or bind will create exception. // Now bind labels - only bind label if it exists or bind will create exception.
// can only bind once have prepared, so need to test again. // can only bind once have prepared, so need to test again.
if (!empty($data['buttontype'])) { if (!empty($data['buttontype'])) {
@ -160,8 +160,7 @@ class dbinterface
public function get_db_SccpSetting() public function get_db_SccpSetting()
{ {
$dbh = \FreePBX::Database(); $stmt = $this->db->prepare('SELECT keyword, seq, type, data, systemdefault FROM sccpsettings ORDER BY type, seq');
$stmt = $dbh->prepare('SELECT keyword, seq, type, data, systemdefault FROM sccpsettings ORDER BY type, seq');
$stmt->execute(); $stmt->execute();
foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $key => $rowArray) { foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $key => $rowArray) {
$settingsFromDb[$rowArray['keyword']] = $rowArray; $settingsFromDb[$rowArray['keyword']] = $rowArray;
@ -172,8 +171,7 @@ class dbinterface
public function get_db_sysvalues() public function get_db_sysvalues()
{ {
$dbh = \FreePBX::Database(); $stmt = $this->db->prepare('SHOW VARIABLES LIKE \'%group_concat%\'');
$stmt = $dbh->prepare('SHOW VARIABLES LIKE \'%group_concat%\'');
$stmt->execute(); $stmt->execute();
return $stmt->fetch(\PDO::FETCH_ASSOC); return $stmt->fetch(\PDO::FETCH_ASSOC);
} }
@ -184,7 +182,6 @@ class dbinterface
function getDb_model_info($get = 'all', $format_list = 'all', $filter = array()) function getDb_model_info($get = 'all', $format_list = 'all', $filter = array())
{ {
$dbh = \FreePBX::Database();
$sel_inf = '*, 0 as validate'; $sel_inf = '*, 0 as validate';
if ($format_list === 'model') { if ($format_list === 'model') {
$sel_inf = 'model, vendor, dns, buttons, 0 as validate'; $sel_inf = 'model, vendor, dns, buttons, 0 as validate';
@ -196,10 +193,10 @@ class dbinterface
if (!strpos($filter['model'], 'loadInformation')) { if (!strpos($filter['model'], 'loadInformation')) {
$filter['model'] = 'loadInformation' . $filter['model']; $filter['model'] = 'loadInformation' . $filter['model'];
} }
$stmt = $dbh->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (loadinformationid = :model ) ORDER BY model"); $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (loadinformationid = :model ) ORDER BY model");
$stmt->bindParam(':model', $filter['model'], \PDO::PARAM_STR); $stmt->bindParam(':model', $filter['model'], \PDO::PARAM_STR);
} else { } else {
$stmt = $dbh->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model"); $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model");
} }
break; break;
} }
@ -207,32 +204,32 @@ class dbinterface
case 'byid': case 'byid':
if (!empty($filter)) { if (!empty($filter)) {
if (!empty($filter['model'])) { if (!empty($filter['model'])) {
$stmt = $dbh->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE model = :model ORDER BY model"); $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE model = :model ORDER BY model");
$stmt->bindParam(':model', $filter['model'],\PDO::PARAM_STR); $stmt->bindParam(':model', $filter['model'],\PDO::PARAM_STR);
} else { } else {
$stmt = $dbh->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model"); $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model");
} }
break; break;
} }
break; break;
case 'extension': case 'extension':
$stmt = $dbh->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns = 0) and (enabled = 1) ORDER BY model"); $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns = 0) and (enabled = 1) ORDER BY model");
break; break;
case 'enabled': case 'enabled':
//$stmt = $db->prepare('SELECT ' . {$sel_inf} . ' FROM sccpdevmodel WHERE enabled = 1 ORDER BY model'); //previously this fell through to phones. //$stmt = $db->prepare('SELECT ' . {$sel_inf} . ' FROM sccpdevmodel WHERE enabled = 1 ORDER BY model'); //previously this fell through to phones.
//break; // above includes expansion modules but was not original behaviour so commented out. Falls through to phones. //break; // above includes expansion modules but was not original behaviour so commented out. Falls through to phones.
case 'phones': case 'phones':
$stmt = $dbh->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) ORDER BY model"); $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) ORDER BY model");
break; break;
case 'ciscophones': case 'ciscophones':
$stmt = $dbh->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) AND vendor NOT LIKE '%-sip' ORDER BY model"); $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) AND vendor NOT LIKE '%-sip' ORDER BY model");
break; break;
case 'sipphones': case 'sipphones':
$stmt = $dbh->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) AND vendor LIKE '%-sip' ORDER BY model"); $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) AND vendor LIKE '%-sip' ORDER BY model");
break; break;
case 'all': // Fall through to default case 'all': // Fall through to default
default: default:
$stmt = $dbh->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model"); $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model");
break; break;
} }
$stmt->execute(); $stmt->execute();
@ -243,15 +240,14 @@ class dbinterface
{ {
// mode clear - Empty table before update // mode clear - Empty table before update
// mode update - update / replace record // mode update - update / replace record
$dbh = \FreePBX::Database();
$result = false; $result = false;
switch ($table_name) { switch ($table_name) {
case 'sccpsettings': case 'sccpsettings':
if ($mode == 'replace') { // Change mode name to be more transparent if ($mode == 'replace') { // Change mode name to be more transparent
$dbh->prepare('TRUNCATE sccpsettings')->execute(); $this->db->prepare('TRUNCATE sccpsettings')->execute();
$stmt = $dbh->prepare('INSERT INTO sccpsettings (keyword, data, seq, type, systemdefault) VALUES (:keyword,:data,:seq,:type,:systemdefault)'); $stmt = $this->db->prepare('INSERT INTO sccpsettings (keyword, data, seq, type, systemdefault) VALUES (:keyword,:data,:seq,:type,:systemdefault)');
} else { } else {
$stmt = $dbh->prepare('REPLACE INTO sccpsettings (keyword, data, seq, type, systemdefault) VALUES (:keyword,:data,:seq,:type,:systemdefault)'); $stmt = $this->db->prepare('REPLACE INTO sccpsettings (keyword, data, seq, type, systemdefault) VALUES (:keyword,:data,:seq,:type,:systemdefault)');
} }
foreach ($save_value as $key => $dataArr) { foreach ($save_value as $key => $dataArr) {
if (empty($dataArr)) { if (empty($dataArr)) {
@ -286,13 +282,13 @@ class dbinterface
if (!empty($sql_var)) { if (!empty($sql_var)) {
switch ($mode) { switch ($mode) {
case 'delete': case 'delete':
$stmt = $dbh->prepare("DELETE FROM {$table_name} WHERE {$sql_key}"); $stmt = $this->db->prepare("DELETE FROM {$table_name} WHERE {$sql_key}");
break; break;
case 'update': case 'update':
$stmt = $dbh->prepare("UPDATE {$table_name} SET {$sql_var} WHERE {$sql_key}"); $stmt = $this->db->prepare("UPDATE {$table_name} SET {$sql_var} WHERE {$sql_key}");
break; break;
case 'replace': case 'replace':
$stmt = $dbh->prepare("REPLACE INTO {$table_name} SET {$sql_var}"); $stmt = $this->db->prepare("REPLACE INTO {$table_name} SET {$sql_var}");
break; break;
// no default mode - must be explicit. // no default mode - must be explicit.
} }
@ -303,13 +299,13 @@ class dbinterface
switch ($mode) { switch ($mode) {
case 'delete': case 'delete':
$sql = 'DELETE FROM sccpbuttonconfig WHERE ref = :hwid'; $sql = 'DELETE FROM sccpbuttonconfig WHERE ref = :hwid';
$stmt = $dbh->prepare($sql); $stmt = $this->db->prepare($sql);
$stmt->bindParam(':hwid', $hwid,\PDO::PARAM_STR); $stmt->bindParam(':hwid', $hwid,\PDO::PARAM_STR);
$result = $stmt->execute(); $result = $stmt->execute();
break; break;
case 'replace': case 'replace':
foreach ($save_value as $button_array) { foreach ($save_value as $button_array) {
$stmt = $dbh->prepare('UPDATE sccpbuttonconfig SET name =:name WHERE ref = :ref AND reftype =:reftype AND instance = :instance AND buttontype = :buttontype'); $stmt = $this->db->prepare('UPDATE sccpbuttonconfig SET name =:name WHERE ref = :ref AND reftype =:reftype AND instance = :instance AND buttontype = :buttontype');
$stmt->bindParam(':ref', $button_array['ref'],\PDO::PARAM_STR); $stmt->bindParam(':ref', $button_array['ref'],\PDO::PARAM_STR);
$stmt->bindParam(':reftype', $button_array['reftype'],\PDO::PARAM_STR); $stmt->bindParam(':reftype', $button_array['reftype'],\PDO::PARAM_STR);
$stmt->bindParam(':instance', $button_array['instance'],\PDO::PARAM_INT); $stmt->bindParam(':instance', $button_array['instance'],\PDO::PARAM_INT);
@ -320,7 +316,7 @@ class dbinterface
break; break;
case 'add': case 'add':
foreach ($save_value as $button_array) { foreach ($save_value as $button_array) {
$stmt = $dbh->prepare('INSERT INTO sccpbuttonconfig (ref, reftype, instance, buttontype, name, options) VALUES (:ref, :reftype, :instance, :buttontype, :name, :options)'); $stmt = $this->db->prepare('INSERT INTO sccpbuttonconfig (ref, reftype, instance, buttontype, name, options) VALUES (:ref, :reftype, :instance, :buttontype, :name, :options)');
$stmt->bindParam(':ref', $button_array['ref'],\PDO::PARAM_STR); $stmt->bindParam(':ref', $button_array['ref'],\PDO::PARAM_STR);
$stmt->bindParam(':reftype', $button_array['reftype'],\PDO::PARAM_STR); $stmt->bindParam(':reftype', $button_array['reftype'],\PDO::PARAM_STR);
$stmt->bindParam(':instance', $button_array['instance'],\PDO::PARAM_INT); $stmt->bindParam(':instance', $button_array['instance'],\PDO::PARAM_INT);
@ -353,8 +349,7 @@ class dbinterface
} }
public function updateTableDefaults($table, $field, $value) { public function updateTableDefaults($table, $field, $value) {
$dbh = \FreePBX::Database(); $stmt = $this->db->prepare("ALTER TABLE {$table} ALTER COLUMN {$field} SET DEFAULT '{$value}'");
$stmt = $dbh->prepare("ALTER TABLE {$table} ALTER COLUMN {$field} SET DEFAULT '{$value}'");
$stmt->execute(); $stmt->execute();
} }
@ -363,14 +358,13 @@ class dbinterface
*/ */
public function validate() public function validate()
{ {
$dbh = \FreePBX::Database();
$result = 0; $result = 0;
$check_fields = [ $check_fields = [
'430' => ['_hwlang' => "varchar(12)"], '430' => ['_hwlang' => "varchar(12)"],
'431' => ['private'=> "enum('on','off')"], '431' => ['private'=> "enum('on','off')"],
'433' => ['directed_pickup'=>''] '433' => ['directed_pickup'=>'']
]; ];
$stmt = $dbh->prepare('DESCRIBE sccpdevice'); $stmt = $this->db->prepare('DESCRIBE sccpdevice');
$stmt->execute(); $stmt->execute();
foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $value) { foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $value) {
$id_result[$value['Field']] = $value['Type']; $id_result[$value['Field']] = $value['Type'];
@ -390,4 +384,19 @@ class dbinterface
return $result; return $result;
} }
public function getNamedGroup($callGroup) {
$sql = "SELECT {$callGroup} FROM sccpline GROUP BY {$callGroup}";
$sth = $this->db->prepare($sql);
$result = array();
$tech = array();
try {
$sth->execute();
$result = $sth->fetchAll();
foreach($result as $val) {
$tech[$callGroup][] = $val[0];
}
} catch(\Exception $e) {}
return $tech;
}
} }