From e9a3bf34df40a7164e260c21fb53d9d5dcdbac49 Mon Sep 17 00:00:00 2001 From: stevenA Date: Tue, 18 Jan 2022 13:11:13 +0100 Subject: [PATCH] Continued Optimisations and Cleaning Optimise return values from AMI to avoid reformatting Simplify validate logic Optimise treatment of ami raw message Optimise return values from getDb_model_info and clean up method name Optimize add device moving functions outside of loop Define unique names for script methods between SIP and SCCP as in same page --- Sccp_manager.class.php | 36 ++--- .../amInterfaceClasses/Event.class.php | 4 +- .../amInterfaceClasses/Message.class.php | 103 +++++++------- .../amInterfaceClasses/Response.class.php | 1 - sccpManClasses/aminterface.class.php | 2 +- sccpManClasses/dbinterface.class.php | 48 +++---- sccpManClasses/formcreate.class.php | 6 +- sccpManTraits/ajaxHelper.php | 7 +- sccpManTraits/bmoFunctions.php | 4 +- sccpManTraits/helperFunctions.php | 11 +- views/advserver.model.php | 10 +- views/form.adddevice.php | 134 ++++++++---------- views/hardware.extension.php | 4 +- views/hardware.phone.php | 12 +- views/hardware.sphone.php | 8 +- 15 files changed, 184 insertions(+), 206 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index 7367162..75701cb 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -919,7 +919,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $dev_config = array_merge($dev_config, $this->sccppath); $dev_config['tftp_firmware'] = ''; $dev_config['addon_info'] = array(); - if (!empty($dev_config['addon'])) { + if ($dev_config['addon'] !== 'NONE') { $hw_addon = explode(',', $dev_config['addon']); foreach ($hw_addon as $key) { $hw_data = $this->getSccpModelInformation('byid', false, "all", array('model' => $key)); @@ -1004,10 +1004,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { unlink($result); return $filename; } - function getSccpModelInformation($get = "all", $validate = false, $format_list = "all", $filter = array()) { $file_ext = array('.loads', '.sbn', '.bin', '.zup', '.sbin', '.SBN', '.LOADS'); - $dir = $this->sccppath['tftp_firmware_path']; + $dir = $this->sccpvalues['tftp_firmware_path']['data']; $search_mode = $this->sccpvalues['tftp_rewrite']['data']; switch ($search_mode) { @@ -1021,17 +1020,18 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $dir_list = $this->findAllFiles($dir, $file_ext, 'dirFileBaseName'); break; } - $modelList = $this->dbinterface->getDb_model_info($get, $format_list, $filter); + $modelList = $this->dbinterface->getModelInfoFromDb($get, $format_list, $filter); + //dbug($modelList); if ($validate) { foreach ($modelList as &$raw_settings) { if (!empty($raw_settings['loadimage'])) { - $raw_settings['validate'] = 'no;'; + $raw_settings['fwFound'] = false; switch ($search_mode) { case 'pro': case 'on': case 'internal': if (in_array($raw_settings['loadimage'], $dir_list, true)) { - $raw_settings['validate'] = 'yes;'; + $raw_settings['fwFound'] = true; } break; case 'internal2': @@ -1039,26 +1039,28 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { case 'off': default: // Place in root TFTP dir if (in_array("{$dir}/{$raw_settings['loadimage']}", $dir_list, true)) { - $raw_settings['validate'] = 'yes;'; + $raw_settings['fwFound'] = true; } break; } - } else { - $raw_settings['validate'] = '-;'; - } + } //else { + //$raw_settings['validate'] = '-;'; + //} + $raw_settings['templateFound'] = false; if (!empty($raw_settings['nametemplate'])) { $file = $this->sccppath['tftp_templates_path'] . '/' . $raw_settings['nametemplate']; if (file_exists($file)) { - $raw_settings['validate'] .= 'yes'; - } else { - $raw_settings['validate'] .= 'no'; - } - } else { - $raw_settings['validate'] .= '-'; - } + $raw_settings['templateFound'] = true; + } //else { + //$raw_settings['templateFound'] .= 'no'; + //} + } //else { + //$raw_settings['validate'] .= '-'; + //} } } unset($raw_settings); // passed as reference so must unset. + dbug($modelList); return $modelList; } diff --git a/sccpManClasses/amInterfaceClasses/Event.class.php b/sccpManClasses/amInterfaceClasses/Event.class.php index 6eefdbd..c733f46 100644 --- a/sccpManClasses/amInterfaceClasses/Event.class.php +++ b/sccpManClasses/amInterfaceClasses/Event.class.php @@ -86,7 +86,7 @@ class SCCPDeviceEntry_Event extends Event { // This is a list of tables, each table is an entry } -/* + class SCCPShowDevice_Event extends Event { // This is a list of tables @@ -101,7 +101,7 @@ class SCCPShowDevice_Event extends Event } return $ret; } - */ +} /* public function getCodecsPreference() { diff --git a/sccpManClasses/amInterfaceClasses/Message.class.php b/sccpManClasses/amInterfaceClasses/Message.class.php index 2cb2997..b67b994 100644 --- a/sccpManClasses/amInterfaceClasses/Message.class.php +++ b/sccpManClasses/amInterfaceClasses/Message.class.php @@ -117,15 +117,15 @@ abstract class Message { return "Variable: $key=$value"; } - +/* + // Obsolete - integrated into single method that calls for performance protected function setSanitizedKey($key, $value) { - // TODO: Need to handle JSON here rather than in getVariable as have - // already broken data into array. + // Handle JSON here rather than in getVariable as have already broken data into array. + // Force preference here rather than test later as is faster. $key = strtolower($key); switch ($key) { case 'json': - //$this->keys['JSONRAW'] = (string) $value; $this->keys['json'] = (string) $value; break; case 'response': @@ -133,48 +133,38 @@ abstract class Message case 'desc': $this->keys[$key] = (string) $value; break; + case 'listitems'; + $this->keys[$key] = $this->sanitizeInput($value,'numeric'); + break; default: $this->keys[$key] = $this->sanitizeInput($value); break; } - -/* - $_string_key = array('actionid', 'descr'); - if (array_search($key, $_string_key) !== false) { - $this->keys[$key] = (string) $this->sanitizeInput($value, 'string'); - } else { - $this->keys[$key] = $this->sanitizeInput($value); - } -*/ } - +*/ protected function sanitizeInput($value, $prefered_type = '') { - if ($prefered_type == '') { - // No longer send empty values - //if (!isset($value) || $value === null || strlen($value) == 0) { - //return null; - //} elseif (is_numeric($value)) { + if ($prefered_type === '') { + // Find numeric first as this is coersion - is_string will always match! if (is_numeric($value)) { $prefered_type = 'numeric'; - } elseif (is_string($value)) { - $prefered_type = 'string'; } else { - throw new AMIException("Don't know how to convert: '" . $value . "'\n"); + $prefered_type = 'string'; } } //if ($prefered_type !== '') { switch ($prefered_type) { case 'string': - //if (!isset($value) || $value === null || strlen($value) == 0) { - //return ''; - //} if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) { return (boolean) $value; } elseif (filter_var($value, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE)) { return (string) $value; } elseif (filter_var($value, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE)) { return (string) htmlspecialchars($value, ENT_QUOTES); + } elseif (empty($value)) { + // In rare cases, $value will be empty, and so treated as a string. Trap here + // to avoid performance hit on all message lines if testing earlier. + return; } else { throw new AMIException("Incoming String is not sanitary. Skipping: '" . $value . "'\n"); } @@ -244,6 +234,42 @@ abstract class Message abstract class IncomingMessage extends Message { + public function __construct($rawContent) + { + parent::__construct(); + $this->rawContent = $rawContent; + $lines = explode(Message::EOL, $rawContent); + foreach ($lines as $line) { + $content = explode(':', $line); + $key = strtolower(array_shift($content)); + // May now have an empty array, or an array with just ' ', both of which + // are rare and will be turned into an empty string below. + // Do not test for here, as most times will not be empty, and testing here + // would mean a performance hit given the number of lines handled + + // Performance - integrate method here as is only called from here! + //$this->setSanitizedKey($name, trim(implode(':', $content))); + $value = trim(implode(':', $content)); + // Handle JSON here rather than in old getVariable as have already broken data into array. + // Force preference here rather than test later as is faster. + switch ($key) { + case 'json': + $this->keys['json'] = (string) $value; + break; + case 'response': + case 'actionid': + case 'desc': + $this->keys[$key] = (string) $value; + break; + case 'listitems'; + $this->keys[$key] = $this->sanitizeInput($value,'numeric'); + break; + default: + $this->keys[$key] = $this->sanitizeInput($value); + break; + } + } + } protected $rawContent; @@ -268,33 +294,6 @@ abstract class IncomingMessage extends Message $ret[] = 'rawContent'; return $ret; } - - public function __construct($rawContent) - { - parent::__construct(); - //dbug($rawContent); - $this->rawContent = $rawContent; - $lines = explode(Message::EOL, $rawContent); - foreach ($lines as $line) { - $content = explode(':', $line); - //$content = preg_split("/: /",$line); - //$name = strtolower(trim($content[0])); - // do strtolower in setSanitizedKey - $name = array_shift($content); - //unset($content[0]); - if (!isset($content[0])) { - continue; - } - //$value = isset($content[0]) ? trim(implode(':', $content)) : ''; - try { - $this->setSanitizedKey($name, trim(implode(':', $content))); - } catch (AMIException $e) { - throw new AMIException("Error: '" . $e . "'\n Dump RawContent:\n" . $this->rawContent . "\n"); - } - //dbug($this->keys); - } - //dbug($this->keys); - } } // namespace FreePBX\modules\Sccp_manager\aminterface\Message; diff --git a/sccpManClasses/amInterfaceClasses/Response.class.php b/sccpManClasses/amInterfaceClasses/Response.class.php index da2d076..9805e61 100644 --- a/sccpManClasses/amInterfaceClasses/Response.class.php +++ b/sccpManClasses/amInterfaceClasses/Response.class.php @@ -378,7 +378,6 @@ class SCCPShowDevice_Response extends SCCPGeneric_Response { // This object has a list of events _events, and a list of tables _tables. $result = array(); - foreach ($this->_events as $trow) { $result = array_merge($result, $trow->getKeys()); } diff --git a/sccpManClasses/aminterface.class.php b/sccpManClasses/aminterface.class.php index 5cd3d49..e20a636 100644 --- a/sccpManClasses/aminterface.class.php +++ b/sccpManClasses/aminterface.class.php @@ -348,7 +348,7 @@ class aminterface $_res = $this->send($_action)->getResult(); foreach ($_res as $key => $value) { foreach ($value as $key2 => $value2) { - //$result[$key.'@'.$key2] = $key.'@'.$key2; + //$result[$key.'@'.$key2] = $key.'@'.$key2; $result[$key.'@'.$key2] = ['key' => $key.'@'.$key2, 'exten' => $key, 'label' => $key.'@'.$key2]; } } diff --git a/sccpManClasses/dbinterface.class.php b/sccpManClasses/dbinterface.class.php index 597eedc..39ecc25 100644 --- a/sccpManClasses/dbinterface.class.php +++ b/sccpManClasses/dbinterface.class.php @@ -200,56 +200,52 @@ class dbinterface * Get Sccp Device Model information */ - function getDb_model_info($get = 'all', $format_list = 'all', $filter = array()) + function getModelInfoFromDb($get = 'all', $format_list = 'all', $filter = array()) { - $sel_inf = '*, 0 as validate'; + $sel_inf = "*, model, false as fwFound, false as templateFound"; if ($format_list === 'model') { - $sel_inf = "model, vendor, dns, buttons, '-;-' as validate"; + $sel_inf = "model, vendor, dns, buttons, false as fwFound, false as templateFound"; } switch ($get) { case 'byciscoid': - if (!empty($filter)) { - if (!empty($filter['model'])) { - if (!strpos($filter['model'], 'loadInformation')) { - $filter['model'] = 'loadInformation' . $filter['model']; - } - $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (loadinformationid = :model ) ORDER BY model"); - $stmt->bindParam(':model', $filter['model'], \PDO::PARAM_STR); - } else { - $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model"); + if (isset($filter['model'])) { + if (!strpos($filter['model'], 'loadInformation')) { + $filter['model'] = 'loadInformation' . $filter['model']; } - break; + $stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel WHERE (loadinformationid = :model ) ORDER BY model"); + $stmt->bindParam(':model', $filter['model'], \PDO::PARAM_STR); + } else { + $stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel ORDER BY model"); } break; case 'byid': - if (!empty($filter)) { - if (!empty($filter['model'])) { - $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE model = :model ORDER BY model"); - $stmt->bindParam(':model', $filter['model'],\PDO::PARAM_STR); - } else { - $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model"); - } - break; + if (isset($filter['model'])) { + $stmtU = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel WHERE model = :model ORDER BY model"); + $stmtU->bindParam(':model', $filter['model'],\PDO::PARAM_STR); + } else { + $stmtU = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel ORDER BY model"); } + $stmtU->execute(); + return $stmtU->fetchAll(\PDO::FETCH_ASSOC|\PDO::FETCH_UNIQUE); break; case 'extension': - $stmt = $this->db->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; case 'enabled': //$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. case 'phones': - $stmt = $this->db->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; case 'ciscophones': - $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) AND RIGHT(vendor,4) != '-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 RIGHT(vendor,4) = '-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: - $stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model"); + $stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel ORDER BY model"); break; } $stmt->execute(); diff --git a/sccpManClasses/formcreate.class.php b/sccpManClasses/formcreate.class.php index e33e6c6..6aeb546 100644 --- a/sccpManClasses/formcreate.class.php +++ b/sccpManClasses/formcreate.class.php @@ -719,11 +719,11 @@ class formcreate } switch ($child['type']) { case 'SDM': - $model_list = \FreePBX::Sccp_manager()->dbinterface->getDb_model_info('ciscophones', 'model'); + $model_list = \FreePBX::Sccp_manager()->dbinterface->getModelInfoFromDb('ciscophones', 'model'); $select_opt= $model_list; break; case 'SDMS': - $model_list = \FreePBX::Sccp_manager()->dbinterface->getDb_model_info('sipphones', 'model'); + $model_list = \FreePBX::Sccp_manager()->dbinterface->getModelInfoFromDb('sipphones', 'model'); $select_opt= $model_list; break; case 'SDML': @@ -741,7 +741,7 @@ class formcreate $child->default = $fvalues['defaultLine']; break; case 'SDE': - $extension_list = \FreePBX::Sccp_manager()->dbinterface->getDb_model_info('extension', 'model'); + $extension_list = \FreePBX::Sccp_manager()->dbinterface->getModelInfoFromDb('extension', 'model'); $extension_list[] = array( 'model' => 'NONE', 'vendor' => 'CISCO', 'dns' => '0'); foreach ($extension_list as &$data) { $d_name = explode(';', $data['model']); diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php index 4d13904..678be7d 100644 --- a/sccpManTraits/ajaxHelper.php +++ b/sccpManTraits/ajaxHelper.php @@ -223,9 +223,9 @@ trait ajaxHelper { $devices = $this->getSccpModelInformation($request['type'], $validate = true); break; } - if (empty($devices)) { - return array(); - } + //if (empty($devices)) { + //return array(); + //} return $devices; break; @@ -550,7 +550,6 @@ trait ajaxHelper { $nonJavaPhones = array( '6901', '6911', '6921', '6945', '7902', '7905', '7910', '7911', '7912', '7914', '7915', '7916', '7920', '7925', '7926', '7931', '7935', '7936', '7937', '7940', '7960' ); - dbug($get_settings); //[sccp_hw_type] if (!empty($get_settings["{$hdr_prefix}devlang"])) { switch ($get_settings["{$hdr_prefix}devlang"]) { case 'Russian_Russian_Federation': diff --git a/sccpManTraits/bmoFunctions.php b/sccpManTraits/bmoFunctions.php index ed6d996..4dc88b8 100644 --- a/sccpManTraits/bmoFunctions.php +++ b/sccpManTraits/bmoFunctions.php @@ -25,6 +25,7 @@ trait bmoFunctions { $this->dialTemplateData = json_encode($this->getDialTemplate()); $this->softKeyData = json_encode($this->getSoftKey()); $this->deviceModelData = json_encode($this->ajaxHandler($_REQUEST = array('command'=>'getDeviceModel', 'type'=>'enabled'))); + dbug($this->deviceModelData); break; default: break; @@ -32,6 +33,7 @@ trait bmoFunctions { } function getPhoneGrid(string $type, $activeDevices =array()){ + $dbDevices = array(); // Find all devices defined in the database. $dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $type)); @@ -40,8 +42,6 @@ trait bmoFunctions { if ($type == 'cisco-sip') { return $dbDevices; //this may be empty } - // Find all devices currently connected - //$activeDevices = $this->aminterface->sccp_get_active_device(); foreach ($dbDevices as &$dev_id) { if (!empty($activeDevices[$dev_id['name']])) { diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php index c101802..1373bfc 100644 --- a/sccpManTraits/helperFunctions.php +++ b/sccpManTraits/helperFunctions.php @@ -90,17 +90,10 @@ trait helperfunctions { return $def_val; } - private function getTableEnums($table, $trim_underscore = true) { + private function getTableEnums($table) { $enumFields = array(); - $sccpTableDesc = $this->dbinterface->getSccpDeviceTableData("get_columns_{$table}"); + $sccpTableDesc = $this->dbinterface->getSccpDeviceTableData("get_columns_${table}"); foreach ($sccpTableDesc as $key => $data) { - // function has 2 roles: return actual table keys (trim_underscore = false) - // return sanitised keys to add defaults (trim_underscore = true) - if ($trim_underscore) { - // Remove any leading (or trailing but should be none) underscore - // These are only used to hide fields from chan-sccp for compatibility - $key = trim($key,'_'); - } $typeArray = explode('(', $data['Type']); if ($typeArray[0] == 'enum') { $enumOptions = explode(',', trim($typeArray[1],')')); diff --git a/views/advserver.model.php b/views/advserver.model.php index 7a26cf5..3f06356 100644 --- a/views/advserver.model.php +++ b/views/advserver.model.php @@ -283,7 +283,7 @@ include($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/views/getFileModa document.getElementById("editd_buttons").value = drow['buttons']; } } - + function StatusIconFormatter(value, row) { return (value === '1') ? '">' : '">'; } @@ -301,13 +301,15 @@ include($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/views/getFileModa } function SetColFirmNf(value, row, index) { - if (row['validate'].split(';')[0] === 'no') { + //if (row['validate'].split(';')[0] === 'no') { + if (!row['fwFound']) { return "File not found
" + value; } return value; } function SetColTemplNf(value, row, index) { - if (row['validate'].split(';')[1] === 'no') { + //if (row['validate'].split(';')[1] === 'no') { + if (!row['templateFound']) { return "File not found
" + value ; } return value; @@ -318,7 +320,7 @@ include($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/views/getFileModa if (row['enabled'] === 1) { tclass = (index % 2 === 0) ? "info" : "info"; } - if ((row['validate'] === 'yes;yes') || (row['validate'] === 'yes;-')) { + if (row['fwFound']) { // tclass = (row['enabled'] === '1') ? "danger" : "warning"; } else { tclass = (row['enabled'] === '1') ? "danger" : "warning"; diff --git a/views/form.adddevice.php b/views/form.adddevice.php index d61f13d..25ea83a 100644 --- a/views/form.adddevice.php +++ b/views/form.adddevice.php @@ -29,74 +29,77 @@ if (!empty($_REQUEST['id'])) { $dev_id = $_REQUEST['id']; $db_res = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $dev_id)); + $enumFields = $this->getTableEnums('sccpdevice'); + $def_val['defaultLine'] = $this->dbinterface->getSccpDeviceTableData('getDefaultLine', array('id' => $dev_id))['name']; foreach ($db_res as $key => $val) { - if (!empty($val)) { - switch ($key) { - case 'phonepersonalization': - $def_val['phonepersonalization'] = array("keyword" => 'phonepersonalization', "data" => $val, "seq" => "99"); - break; - default: - // Overwrite existing defaults after checking that data is still valid after schema updates - // Do not strip underscores as these fields are new in the schema and so should be valid. - $enumFields = $this->getTableEnums('sccpdevice', false); - if (array_key_exists($key, $enumFields)){ - // This field is (now) an enum. Check the current value is acceptable. - // Quote value as enum values are quoted. - if (in_array("'{$val}'", $enumFields[$key])) { - // The value is valid so will keep - $def_val[$key] = array('keyword' => $key, 'data' => $val, 'seq' => 99); - } - // Do not store value and let defaults apply - break; + if (empty($val)) { + continue; + } + switch ($key) { + case 'phonepersonalization': + $def_val['phonepersonalization'] = array("keyword" => 'phonepersonalization', "data" => $val, "seq" => "99"); + break; + default: + // Overwrite existing defaults after checking that data is still valid after schema updates + if (array_key_exists($key, $enumFields)){ + // This field is (now) an enum. Check the current value is acceptable. + // Quote value as enum values are quoted. + if (in_array("'${val}'", $enumFields[$key])) { + // The value is valid so will keep + $def_val[$key] = array('keyword' => $key, 'data' => $val, 'seq' => 99); } - $def_val[$key] = array("keyword" => $key, "data" => $val, "seq" => "99"); - // Need to assign defaultLine as not set in the db. - $def_val['defaultLine'] = $this->dbinterface->getSccpDeviceTableData('getDefaultLine', array('id' => $dev_id))['name']; + // Do not store (invalid) value and let defaults apply break; - } + } + $def_val[$key] = array("keyword" => $key, "data" => $val, "seq" => "99"); + break; } } } +if (empty($dev_id)) { + $dev_id = 'new'; +} else { + $val = str_replace(array('SEP','ATA','VG'), '', $dev_id); + $val = implode(':', sscanf($val, '%2s%2s%2s%2s%2s%2s')); // Convert to Cisco display Format + $def_val['mac'] = array("keyword" => 'mac', "data" => $val, "seq" => "99"); +} -if (!empty($def_val['type'])) { - $tmp_raw = $this->getSccpModelInformation('byid', true, 'all', array('model'=>$def_val['type'])); - if (!empty($tmp_raw[0])) { - $tmp_raw = $tmp_raw[0]; +if (!empty($def_val['type']['data'])) { + $tmp_raw = $this->getSccpModelInformation('byid', true, 'all', array('model'=>$def_val['type']['data'])); + if (isset($tmp_raw[$def_val['type']['data']])) { + $tmp_raw = $tmp_raw[$def_val['type']['data']]; } - if (!empty($tmp_raw['validate'])) { - $tmpar = explode(";", $tmp_raw['validate']); - if ($tmpar[0] != 'yes') { - $device_warning['Image'] = array('Device firmware not found : '.$tmp_raw['loadimage']); - } - if ($tmpar[1] != 'yes') { - $device_warning['Template'] = array('Missing device configuration template : '. $tmp_raw['nametemplate']); - } - if (!empty($device_warning)) { - ?> -
-
-
-

Warning in the SCCP Device

-
-
-                                 $value) {
-                                    echo '

'.$key.'

'; - if (is_array($value)) { - echo '
  • '._(implode('
  • ', $value)).'
  • '; - } else { - echo '
  • '. _($value).'
  • '; - } + if (!$tmp_raw['fwFound']) { + $device_warning['Image'] = array('Device firmware not found : '.$tmp_raw['loadimage']); + } + if (!$tmp_raw['templateFound']) { + $device_warning['Template'] = array('Missing device configuration template : '. $tmp_raw['nametemplate']); + } + if (!empty($device_warning)) { + ?> +
    +
    +
    +

    Warning in the SCCP Device

    +
    +
    +                             $value) {
    +                                echo '

    '.$key.'

    '; + if (is_array($value)) { + echo '
  • '._(implode('
  • ', $value)).'
  • '; + } else { + echo '
  • '. _($value).'
  • '; } - ?> -
    -
    + } + ?> +
    -
    +
    +
    @@ -105,18 +108,11 @@ if (!empty($def_val['type'])) { '; - } else { - $val = str_replace(array('SEP','ATA','VG'), '', $dev_id); - $val = implode(':', sscanf($val, '%2s%2s%2s%2s%2s%2s')); // Convert to Cisco display Format - $def_val['mac'] = array("keyword" => 'mac', "data" => $val, "seq" => "99"); - echo ''; - } + echo ''; if ($_REQUEST['tech_hardware'] == 'cisco') { echo ''; - if (empty($dev_id)) { + if ($dev_id === 'new') { echo $this->showGroup('sccp_hw_dev', 1, 'sccp_hw', $def_val); } else { echo $this->showGroup('sccp_hw_dev_edit', 1, 'sccp_hw', $def_val); @@ -124,21 +120,13 @@ if (!empty($def_val['type'])) { echo $this->showGroup('sccp_hw_dev2', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev_advance', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev_softkey', 1, 'sccp_hw', $def_val); - // echo $this->showGroup('sccp_hw_dev_pickup', 1, 'sccp_hw', $def_val); This are line properties and does not exist! echo $this->showGroup('sccp_hw_dev_conference', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_dev_vendor_conf', 1, 'vendorconfig', $def_val); echo $this->showGroup('sccp_hw_dev_network', 1, 'sccp_hw', $def_val); } else if ($_REQUEST['tech_hardware'] == 'cisco-sip') { echo ''; - /* - if (empty($dev_new)) { - echo ''; - } else { - echo ''; - } - */ - if (empty($dev_id)) { + if ($dev_id === 'new') { echo $this->showGroup('sccp_hw_sip_dev', 1, 'sccp_hw', $def_val); } else { echo $this->showGroup('sccp_hw_dev_edit', 1, 'sccp_hw', $def_val); diff --git a/views/hardware.extension.php b/views/hardware.extension.php index 7a99bbc..367117b 100644 --- a/views/hardware.extension.php +++ b/views/hardware.extension.php @@ -27,7 +27,7 @@ if (!empty($this->sccpvalues['system_rouminguser'])) { - + @@ -41,7 +41,7 @@ if (!empty($this->sccpvalues['system_rouminguser'])) { $('#table-sccp-extension').bootstrapTable({data: extensionData ?>}); }) - function DispayPhoneActionsKeyFormatter(value, row, index) { + function DisplayPhoneActionsKeyFormatter(value, row, index) { var exp_dev = ''; var rmn_dev = ''; exp_dev += '  '; diff --git a/views/hardware.phone.php b/views/hardware.phone.php index 4af7ecd..4cbc5ef 100644 --- a/views/hardware.phone.php +++ b/views/hardware.phone.php @@ -39,12 +39,12 @@ - - + + - + @@ -59,9 +59,9 @@ $('#table-sccp-phone').bootstrapTable({data: sccpPhoneData ?>}); }) - function DispayTypeFormatter(value, row, index) { + function DisplayTypeFormatter(value, row, index) { var exp_model = value; - if (row['addon'] !== null ) { + if (row['addon'] !== 'NONE' ) { var posd = row['addon'].indexOf(';'); if (posd >0) { exp_model += ' + 2x ' + row['addon'].substring(0, posd); @@ -72,7 +72,7 @@ return exp_model; } - function DispayDeviceActionsKeyFormatter(value, row, index) { + function DisplayDeviceActionsKeyFormatter(value, row, index) { var exp_model = ''; if (row['new_hw'] == "Y") { exp_model += ' - + - + @@ -49,7 +49,7 @@ $('#table-sip-phone').bootstrapTable({data: sipPhoneData ?>}); }) - function DispayTypeFormatter(value, row, index) { + function SipDisplayTypeFormatter(value, row, index) { var exp_model = value; if (row['addon'] !== null ) { var posd = row['addon'].indexOf(';'); @@ -61,7 +61,7 @@ } return exp_model; } - function DispayDeviceActionsKeyFormatterS(value, row, index) { + function SipDisplayDeviceActionsKeyFormatterS(value, row, index) { var exp_model = ''; if (row['new_hw'] == "Y") { exp_model += '