Fix addition of new device when not in db
Partial fix for issue#29 Populate available fields Optimise code
This commit is contained in:
parent
14215b64ca
commit
0f352eeb59
|
@ -7,7 +7,7 @@ $(document).ready(function () {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
$('#ajaxcancel').on('click', function (e) {
|
$('#ajaxcancel').on('click', function (e) {
|
||||||
// console.log('Calncel');
|
console.log('Cancel');
|
||||||
if ($(this).data('hash') != null) {
|
if ($(this).data('hash') != null) {
|
||||||
location.hash = $(this).data('hash');
|
location.hash = $(this).data('hash');
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ $(document).ready(function () {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// ajaxsubmit2 is "Save and continue" - saves form data and stays on form
|
// ajaxsubmit2 is "Save and continue" - saves form data and stays on form
|
||||||
$('#ajaxsubmit2').on('click', function (e) {
|
$('#ajaxsubmit2').on('click', function (e) {
|
||||||
var vdata = '';
|
var vdata = '';
|
||||||
|
|
|
@ -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.4</version>
|
<version>14.3.0.5</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>
|
||||||
|
|
|
@ -115,7 +115,7 @@ class dbinterface
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'get_columns_sccpdevice':
|
case 'get_columns_sccpdevice':
|
||||||
$stmts = $this->db->prepare('DESCRIBE sccpdevice');
|
$stmtU = $this->db->prepare('DESCRIBE sccpdevice');
|
||||||
break;
|
break;
|
||||||
case 'get_columns_sccpuser':
|
case 'get_columns_sccpuser':
|
||||||
$stmts = $this->db->prepare('DESCRIBE sccpuser');
|
$stmts = $this->db->prepare('DESCRIBE sccpuser');
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
*/
|
*/
|
||||||
$def_val = array();
|
$def_val = array();
|
||||||
$dev_id = null;
|
$dev_id = null;
|
||||||
$dev_new = null;
|
|
||||||
$device_warning= null;
|
$device_warning= null;
|
||||||
// Default value from Server setings
|
// Default value from Server setings
|
||||||
|
//Get default values. Will use these for a new device, and modify for an existing.
|
||||||
|
$def_val = $this->getTableDefaults('sccpdevice');
|
||||||
$def_val['netlang'] = array("keyword" => 'netlang', "data" => $this->sccpvalues['netlang']['data'], "seq" => "99");
|
$def_val['netlang'] = array("keyword" => 'netlang', "data" => $this->sccpvalues['netlang']['data'], "seq" => "99");
|
||||||
$def_val['devlang'] = array("keyword" => 'devlang', "data" => $this->sccpvalues['devlang']['data'], "seq" => "99");
|
$def_val['devlang'] = array("keyword" => 'devlang', "data" => $this->sccpvalues['devlang']['data'], "seq" => "99");
|
||||||
$def_val['directed_pickup_context'] = array("keyword" => 'directed_pickup_context', "data" => $this->sccpvalues['directed_pickup_context']['data'], "seq" => "99");
|
$def_val['directed_pickup_context'] = array("keyword" => 'directed_pickup_context', "data" => $this->sccpvalues['directed_pickup_context']['data'], "seq" => "99");
|
||||||
|
@ -17,66 +17,23 @@ $def_val['directed_pickup_context'] = array("keyword" => 'directed_pickup_conte
|
||||||
if (!empty($_REQUEST['new_id'])) {
|
if (!empty($_REQUEST['new_id'])) {
|
||||||
// Adding device that is connected but not in database
|
// Adding device that is connected but not in database
|
||||||
$dev_id = $_REQUEST['new_id'];
|
$dev_id = $_REQUEST['new_id'];
|
||||||
|
|
||||||
// Get device defaults from db
|
|
||||||
$sccpDeviceDesc = $this->dbinterface->getSccpDeviceTableData('get_columns_sccpdevice');
|
|
||||||
|
|
||||||
foreach ($sccpDeviceDesc as $data) {
|
|
||||||
$key = (string) $data['Field'];
|
|
||||||
$def_val[$key] = array("keyword" => $key, "data" => $data['Default'], "seq" => "99");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Overwrite some specific defaults based on $_REQUEST
|
// Overwrite some specific defaults based on $_REQUEST
|
||||||
$val = str_replace(array('SEP','ATA','VG'), '', $dev_id);
|
$def_val['type'] = array("keyword" => 'type', "data" => $_REQUEST['type'], "seq" => "99");
|
||||||
$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");
|
|
||||||
$val = $_REQUEST['type'];
|
|
||||||
$def_val['type'] = array("keyword" => 'type', "data" => $val, "seq" => "99");
|
|
||||||
if (!empty($_REQUEST['addon'])) {
|
if (!empty($_REQUEST['addon'])) {
|
||||||
$def_val['addon'] = array("keyword" => 'type', "data" => $_REQUEST['addon'], "seq" => "99");
|
$def_val['addon'] = array("keyword" => 'type', "data" => $_REQUEST['addon'], "seq" => "99");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get default values. Will use these for a new device, and modify for an existing.
|
|
||||||
$def_val = $this->getTableDefaults('sccpdevice');
|
|
||||||
if (!empty($_REQUEST['id'])) {
|
if (!empty($_REQUEST['id'])) {
|
||||||
// Editing an existing Device. Overwrite any defaults that are already set for this device.
|
// Editing an existing Device. Overwrite any defaults that are already set for this device.
|
||||||
$dev_id = $_REQUEST['id'];
|
$dev_id = $_REQUEST['id'];
|
||||||
$dev_new = $dev_id;
|
|
||||||
$db_res = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $dev_id));
|
$db_res = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $dev_id));
|
||||||
foreach ($db_res as $key => $val) {
|
foreach ($db_res as $key => $val) {
|
||||||
if (!empty($val)) {
|
if (!empty($val)) {
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'type':
|
|
||||||
$tmp_raw = $this->getSccpModelInformation('byid', true, 'all', array('model'=>$val));
|
|
||||||
if (!empty($tmp_raw[0])) {
|
|
||||||
$tmp_raw = $tmp_raw[0];
|
|
||||||
}
|
|
||||||
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']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$def_val[$key] = array("keyword" => $key, "data" => $val, "seq" => "99");
|
|
||||||
break;
|
|
||||||
case 'name':
|
|
||||||
$key = 'mac'; //This is the key that formShow expects
|
|
||||||
$val = str_replace(array('SEP','ATA','VG'), '', $val);
|
|
||||||
$val = implode(':', sscanf($val, '%2s%2s%2s%2s%2s%2s')); // Convert to Cisco display Format
|
|
||||||
$def_val[$key] = array("keyword" => $key, "data" => $val, "seq" => "99");
|
|
||||||
break;
|
|
||||||
// case 'permit':
|
|
||||||
// case 'deny':
|
|
||||||
// $def_val[$key . '_net'] = array("keyword" => $key, "data" => before('/', $val), "seq" => "99");
|
|
||||||
// $key = $key . '_mask';
|
|
||||||
// $val = after('/', $val);
|
|
||||||
// break;
|
|
||||||
case 'phonepersonalization':
|
case 'phonepersonalization':
|
||||||
$def_val['phonepersonalization'] = array("keyword" => 'phonepersonalization', "data" => $val, "seq" => "99");
|
$def_val['phonepersonalization'] = array("keyword" => 'phonepersonalization', "data" => $val, "seq" => "99");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// Overwrite existing defaults after checking that data is still valid after schema updates
|
// 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.
|
// Do not strip underscores as these fields are new in the schema and so should be valid.
|
||||||
|
@ -86,7 +43,7 @@ if (!empty($_REQUEST['id'])) {
|
||||||
// Quote value as enum values are quoted.
|
// Quote value as enum values are quoted.
|
||||||
if (in_array("'{$val}'", $enumFields[$key])) {
|
if (in_array("'{$val}'", $enumFields[$key])) {
|
||||||
// The value is valid so will keep
|
// 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);
|
||||||
}
|
}
|
||||||
// Do not store value and let defaults apply
|
// Do not store value and let defaults apply
|
||||||
continue;
|
continue;
|
||||||
|
@ -100,13 +57,27 @@ if (!empty($_REQUEST['id'])) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($device_warning)) {
|
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($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)) {
|
||||||
?>
|
?>
|
||||||
<div class="fpbx-container container-fluid">
|
<div class="fpbx-container container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2 style="border:2px solid Tomato;color:Tomato;" >Warning in the SCCP Device</h2>
|
<h2 style="border:2px solid Tomato;color:Tomato;" >Warning in the SCCP Device</h2>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
|
<pre>
|
||||||
<?php
|
<?php
|
||||||
foreach ($device_warning as $key => $value) {
|
foreach ($device_warning as $key => $value) {
|
||||||
echo '<h3>'.$key.'</h3>';
|
echo '<h3>'.$key.'</h3>';
|
||||||
|
@ -122,18 +93,22 @@ if (!empty($device_warning)) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
<?php }
|
||||||
<?php } ?>
|
}
|
||||||
|
} ?>
|
||||||
|
|
||||||
<form autocomplete="off" name="frm_adddevice" id="frm_adddevice" class="fpbx-submit" action="" method="post" data-id="hw_edit">
|
<form autocomplete="off" name="frm_adddevice" id="frm_adddevice" class="fpbx-submit" action="" method="post" data-id="hw_edit">
|
||||||
<input type="hidden" name="category" value="adddevice_form">
|
<input type="hidden" name="category" value="adddevice_form">
|
||||||
<input type="hidden" name="Submit" value="Submit">
|
<input type="hidden" name="Submit" value="Submit">
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (empty($dev_new)) {
|
if (empty($dev_id)) {
|
||||||
echo '<input type="hidden" name="sccp_deviceid" value="new">';
|
echo '<input type="hidden" name="sccp_deviceid" value="new">';
|
||||||
} else {
|
} 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 '<input type="hidden" name="sccp_deviceid" value="'.$dev_id.'">';
|
echo '<input type="hidden" name="sccp_deviceid" value="'.$dev_id.'">';
|
||||||
}
|
}
|
||||||
if (empty($dev_id)) {
|
if (empty($dev_id)) {
|
||||||
|
|
Loading…
Reference in a new issue