diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index 5bf7c53..24bf179 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -376,7 +376,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { public function processPageData() { foreach ($this->pagedata as &$page) { - // own version of load_view - simplifies passing variables + // own version of load_view - simplifies passing variables as in object context ob_start(); include($page['page']); $page['content'] = ob_get_contents(); diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index 7bb653d..e910db1 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -52,9 +52,7 @@ $(document).ready(function () { success: function (data) { if (data.status === true) { if (data.message) { - bs_alert(data.message,data.status); - } else { - fpbxToast(_('Data saved'),'', 'success'); + fpbxToast(_(data.message),'', 'success'); } } else { bs_alert(data.message,data.status); diff --git a/sccpManClasses/amInterfaceClasses/Message.class.php b/sccpManClasses/amInterfaceClasses/Message.class.php index 7963980..84c5993 100644 --- a/sccpManClasses/amInterfaceClasses/Message.class.php +++ b/sccpManClasses/amInterfaceClasses/Message.class.php @@ -126,7 +126,7 @@ abstract class Message protected function setSanitizedKey($key, $value) { - $key = strtolower((string) $key); + //$key = strtolower((string) $key); $_string_key = array('actionid', 'descr'); if (array_search($key, $_string_key) !== false) { $this->keys[$key] = (string) $this->sanitizeInput($value, 'string'); @@ -257,6 +257,7 @@ abstract class IncomingMessage extends Message public function __construct($rawContent) { parent::__construct(); + dbug($rawContent); $this->rawContent = $rawContent; $lines = explode(Message::EOL, $rawContent); foreach ($lines as $line) { @@ -269,6 +270,7 @@ abstract class IncomingMessage extends Message } catch (AMIException $e) { throw new AMIException("Error: '" . $e . "'\n Dump RawContent:\n" . $this->rawContent . "\n"); } + dbug($this->keys); } } } diff --git a/sccpManClasses/aminterface.class.php b/sccpManClasses/aminterface.class.php index 6c47547..e0cdba0 100644 --- a/sccpManClasses/aminterface.class.php +++ b/sccpManClasses/aminterface.class.php @@ -95,7 +95,7 @@ class aminterface public function info() { - $Ver = '13.0.4'; + $Ver = '16.0.0.1'; if ($this->_config['enabled']){ return array('Version' => $Ver, 'about' => 'AMI data ver: ' . $Ver, 'test' => get_declared_classes()); diff --git a/sccpManClasses/dbinterface.class.php b/sccpManClasses/dbinterface.class.php index 3dc9e7b..dd3e043 100644 --- a/sccpManClasses/dbinterface.class.php +++ b/sccpManClasses/dbinterface.class.php @@ -22,7 +22,7 @@ class dbinterface public function info() { - $Ver = '14.0.0.1'; // This should be updated + $Ver = '16.0.0.1'; // This should be updated return array('Version' => $Ver, 'about' => 'Data access interface ver: ' . $Ver); } @@ -70,12 +70,12 @@ class dbinterface switch ($data['type']) { case "cisco-sip": $stmts = $this->db->prepare("SELECT name, type, button, addon, description, 'not connected' AS status, '- -' AS address, 'N' AS new_hw - FROM sccpdeviceconfig WHERE type LIKE '%-sip' ORDER BY name"); + FROM sccpdeviceconfig WHERE RIGHT(type,4) = '-sip' ORDER BY name"); break; case "sccp": // Fall through to default intentionally default: $stmts = $this->db->prepare("SELECT name, type, button, addon, description, 'not connected' AS status, '- -' AS address, 'N' AS new_hw - FROM sccpdeviceconfig WHERE type not LIKE '%-sip' ORDER BY name"); + FROM sccpdeviceconfig WHERE RIGHT(type,4) != '-sip' ORDER BY name"); break; } break; @@ -101,11 +101,11 @@ class dbinterface } elseif (!empty($data['type'])) { switch ($data['type']) { case "cisco-sip": - $stmts = $this->db->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE TYPE LIKE '%-sip' ORDER BY name"); + $stmts = $this->db->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE RIGHT(type,4) = '-sip' ORDER BY name"); break; case "cisco": // Fall through to default intentionally default: - $stmts = $this->db->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE TYPE not LIKE '%-sip' ORDER BY name"); + $stmts = $this->db->prepare("SELECT {$fld} FROM sccpdeviceconfig WHERE RIGHT(type,4) != '-sip' ORDER BY name"); break; } } else { //no filter and no name provided - return all @@ -239,10 +239,10 @@ class dbinterface $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns != 0) and (enabled = 1) ORDER BY model"); break; case 'ciscophones': - $stmt = $this->db->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 RIGHT(vendor,4) != '-sip' ORDER BY model"); break; case 'sipphones': - $stmt = $this->db->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 RIGHT(vendor,4) = '-sip' ORDER BY model"); break; case 'all': // Fall through to default default: @@ -253,7 +253,7 @@ class dbinterface return $stmt->fetchAll(\PDO::FETCH_ASSOC); } - function write($table_name = "", $save_value = array(), $mode = 'update', $key_fld = "", $hwid = "") + function write(string $table_name, $save_value = array(), string $mode = 'update', $key_fld = "", $hwid = "") { // mode clear - Empty table before update // mode update - update / replace record @@ -281,36 +281,36 @@ class dbinterface case 'sccpdevmodel': // Fall through to next intentionally case 'sccpdevice': // Fall through to next intentionally case 'sccpuser': - $sql_key = ""; - $sql_var = ""; - foreach ($save_value as $key_v => $data) { - if (!empty($sql_var)) { - $sql_var .= ', '; - } - if ($data === $this->val_null) { - $sql_var .= $key_v . '= NULL'; - } else { - $sql_var .= $key_v . ' = \'' . $data . '\''; //quote data as normally is string - } - if ($key_v === $key_fld) { - $sql_key = $key_v . ' = \'' . $data . '\''; //quote data as normally is string - } - } - if (!empty($sql_var)) { + $sql_key = ''; + $stmt = ''; + $formattedSQL = array_reduce( + array_keys($save_value), // pass in the array_keys instead of the array here + function ($carry, $key) use ($save_value) { // ... then 'use' the actual array here + return "${carry}${key} = '${save_value[$key]}', "; + }, + ); + if (isset($formattedSQL)) { // if array is empty returns null + $formattedSQL = rtrim($formattedSQL,', '); // Remove the trailing ',' and any spaces. switch ($mode) { case 'delete': - $stmt = $this->db->prepare("DELETE FROM {$table_name} WHERE {$sql_key}"); + if (array_key_exists($key_fld, $save_value)) { + $sql_key = "${key_fld} = '${save_value[$key_fld]}'"; //quote data as normally is string + $stmt = $this->db->prepare("DELETE FROM {$table_name} WHERE {$sql_key}"); + } break; case 'update': - $stmt = $this->db->prepare("UPDATE {$table_name} SET {$sql_var} WHERE {$sql_key}"); + if (array_key_exists($key_fld, $save_value)) { + $sql_key = "${key_fld} = '${save_value[$key_fld]}'"; //quote data as normally is string + $stmt = $this->db->prepare("UPDATE {$table_name} SET {$formattedSQL} WHERE {$sql_key}"); + } break; case 'replace': - $stmt = $this->db->prepare("REPLACE INTO {$table_name} SET {$sql_var}"); + $stmt = $this->db->prepare("REPLACE INTO {$table_name} SET {$formattedSQL}"); break; // no default mode - must be explicit. } } - $result = $stmt->execute(); + $result = (!empty($stmt)) ? $stmt->execute() : false; break; case 'sccpbuttons': switch ($mode) { diff --git a/views/form.buttons.php b/views/form.buttons.php index 01de215..e359883 100644 --- a/views/form.buttons.php +++ b/views/form.buttons.php @@ -20,7 +20,7 @@ if ($_REQUEST['tech_hardware'] === 'cisco') { $lines_list = $this->dbinterface->getSipTableData('extensionList'); } -$hint_list = $this->getHintInformation(true, array('context'=>'park-hints')) ; +$hint_list = $this->getHintInformation(true, array('context'=>'park-hints')); $line_id =0; $max_buttons =56; //Don't know hardware type so set a maximum. On save, this is set to actual max buttons