Update code for line key variables

Search and replace the variables such as user_id, display_name, and other preset variables to match the correct line key. Focused on it working with multiple line keys.
This commit is contained in:
FusionPBX 2024-09-04 20:21:03 -06:00 committed by GitHub
parent 21be3354b1
commit 4dfcba93b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 52 additions and 47 deletions

View File

@ -523,7 +523,7 @@
$templates['Flyingvoice FIP16'] = 'flyingvoice/fip16'; $templates['Flyingvoice FIP16'] = 'flyingvoice/fip16';
$templates['Flyingvoice FIP16PLUS'] = 'flyingvoice/fip16plus'; $templates['Flyingvoice FIP16PLUS'] = 'flyingvoice/fip16plus';
foreach ($templates as $key=>$value){ foreach ($templates as $key=>$value) {
if(stripos($_SERVER['HTTP_USER_AGENT'],$key)!== false) { if(stripos($_SERVER['HTTP_USER_AGENT'],$key)!== false) {
$device_template = $value; $device_template = $value;
break; break;
@ -955,59 +955,64 @@
exit; exit;
} }
//set the variables key and values //list of variable names
$x = 1; $variable_names = [];
$variables['domain_name'] = $domain_name; $variable_names[] = 'domain_name';
$variables['user_id'] = $lines[$x]['user_id']; $variable_names[] = 'user_id';
$variables['auth_id'] = $lines[$x]['auth_id']; $variable_names[] = 'auth_id';
$variables['extension'] = $lines[$x]['extension'] ?? ''; $variable_names[] = 'extension';
//$variables['password'] = $lines[$x]['password']; $variable_names[] = 'register_expires';
$variables['register_expires'] = $lines[$x]['register_expires']; $variable_names[] = 'sip_transport';
$variables['sip_transport'] = $lines[$x]['sip_transport']; $variable_names[] = 'sip_port';
$variables['sip_port'] = $lines[$x]['sip_port']; $variable_names[] = 'server_address';
$variables['server_address'] = $lines[$x]['server_address']; $variable_names[] = 'outbound_proxy';
$variables['outbound_proxy'] = $lines[$x]['outbound_proxy_primary']; $variable_names[] = 'outbound_proxy_primary';
$variables['outbound_proxy_primary'] = $lines[$x]['outbound_proxy_primary']; $variable_names[] = 'outbound_proxy_secondary';
$variables['outbound_proxy_secondary'] = $lines[$x]['outbound_proxy_secondary']; $variable_names[] = 'display_name';
$variables['display_name'] = $lines[$x]['display_name']; $variable_names[] = 'location';
$variables['location'] = $device_location; $variable_names[] = 'description';
$variables['description'] = $device_description;
//add location and description to the lines array
foreach($lines as $id => $row) {
$lines[$id]['location'] = $device_location;
$lines[$id]['description'] = $device_description;
}
//update the device keys by replacing variables with their values //update the device keys by replacing variables with their values
foreach($variables as $name => $value) { if (!empty($device_keys['line']) && is_array($device_keys)) {
if (!empty($device_keys) && is_array($device_keys)) { $types = array("line", "memory", "expansion", "programmable");
foreach($device_keys as $k => $field) { foreach ($types as $type) {
if (!empty($field['device_key_uuid'])) { if (!empty($device_keys[$type]) && is_array($device_keys[$type])) {
if (isset($field['device_key_value'])) { foreach($device_keys[$type] as $row) {
$device_keys[$k]['device_key_value'] = str_replace("\${".$name."}", $value, $field['device_key_value']); //get the variables
$device_key_line = $row['device_key_line'];
$device_key_id = $row['device_key_id'];
$device_key_value = $row['device_key_value'];
$device_key_extension = $row['device_key_extension'];
$device_key_label = $row['device_key_label'];
$device_key_icon = $row['device_key_icon'];
//replace the variables
foreach($variable_names as $name) {
if (!empty($row['device_key_value'])) {
$device_key_value = str_replace("\${".$name."}", $lines[$device_key_line][$name], $device_key_value);
} }
if (isset($field['device_key_extension'])) { if (!empty($row['device_key_extension'])) {
$device_keys[$k]['device_key_extension'] = str_replace("\${".$name."}", $value, $field['device_key_extension']); $device_key_extension = str_replace("\${".$name."}", $lines[$device_key_line][$name], $device_key_extension);
} }
if (isset($field['device_key_label'])) { if (!empty($row['device_key_label'])) {
$device_keys[$k]['device_key_label'] = str_replace("\${".$name."}", $value, $field['device_key_label']); $device_key_label = str_replace("\${".$name."}", $lines[$device_key_line][$name], $device_key_label);
}
if (isset($field['device_key_icon'])) {
$device_keys[$k]['device_key_icon'] = str_replace("\${".$name."}", $value, $field['device_key_icon']);
}
}
else {
if (is_array($field)) {
foreach($field as $key => $row) {
if (isset($row['device_key_value'])) {
$device_keys[$k][$key]['device_key_value'] = str_replace("\${".$name."}", $value, $row['device_key_value']);
}
if (isset($row['device_key_extension'])) {
$device_keys[$k][$key]['device_key_extension'] = str_replace("\${".$name."}", $value, $row['device_key_extension']);
}
if (isset($row['device_key_label'])) {
$device_keys[$k][$key]['device_key_label'] = str_replace("\${".$name."}", $value, $row['device_key_label']);
}
if (isset($row['device_key_icon'])) {
$device_keys[$k][$key]['device_key_icon'] = str_replace("\${".$name."}", $value, $row['device_key_icon']);
} }
if (!empty($row['device_key_icon'])) {
$device_key_icon = str_replace("\${".$name."}", $lines[$device_key_line][$name], $device_key_icon);
} }
} }
//update the device kyes array
$device_keys[$type][$device_key_id]['device_key_value'] = $device_key_value;
$device_keys[$type][$device_key_id]['device_key_extension'] = $device_key_extension;
$device_keys[$type][$device_key_id]['device_key_label'] = $device_key_label;
$device_keys[$type][$device_key_id]['device_key_icon'] = $device_key_icon;
} }
} }
} }