mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Prevent device duplicates when making a copy of a device. Allow duplicate empty mac address or 000000000000 to be used for templates.
This commit is contained in:
@@ -47,6 +47,31 @@ else {
|
||||
$mac_address_new = preg_replace('#[^a-fA-F0-9./]#', '', $mac_address_new);
|
||||
}
|
||||
|
||||
//set the default
|
||||
$save = true;
|
||||
|
||||
//check to see if the mac address exists
|
||||
if ($mac_address_new == "" || $mac_address_new == "000000000000") {
|
||||
//allow duplicates to be used as templaes
|
||||
}
|
||||
else {
|
||||
$sql = "SELECT count(*) AS num_rows FROM v_devices ";
|
||||
$sql .= "WHERE device_mac_address = '".$mac_address_new."' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['num_rows'] == "0") {
|
||||
$save = true;
|
||||
}
|
||||
else {
|
||||
$save = false;
|
||||
$_SESSION['message'] = $text['message-duplicate'];
|
||||
}
|
||||
}
|
||||
unset($prep_statement);
|
||||
}
|
||||
|
||||
//get the device
|
||||
$sql = "SELECT * FROM v_devices ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
@@ -124,13 +149,15 @@ else {
|
||||
$device["device_settings"] = $device_settings;
|
||||
|
||||
//copy the device
|
||||
$orm = new orm;
|
||||
$orm->name('devices');
|
||||
$orm->save($device);
|
||||
$response = $orm->message;
|
||||
if ($save) {
|
||||
$orm = new orm;
|
||||
$orm->name('devices');
|
||||
$orm->save($device);
|
||||
$response = $orm->message;
|
||||
$_SESSION["message"] = $text['message-copy'];
|
||||
}
|
||||
|
||||
//redirect
|
||||
$_SESSION["message"] = $text['message-copy'];
|
||||
header("Location: devices.php");
|
||||
return;
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ require_once "resources/require.php";
|
||||
|
||||
//check for all required data
|
||||
$msg = '';
|
||||
if (strlen($device_mac_address) == 0) { $msg .= $text['message-required'].$text['label-extension']."<br>\n"; }
|
||||
//if (strlen($device_mac_address) == 0) { $msg .= $text['message-required'].$text['label-extension']."<br>\n"; }
|
||||
//if (strlen($device_label) == 0) { $msg .= "Please provide: Label<br>\n"; }
|
||||
//if (strlen($device_vendor) == 0) { $msg .= "Please provide: Vendor<br>\n"; }
|
||||
//if (strlen($device_model) == 0) { $msg .= "Please provide: Model<br>\n"; }
|
||||
@@ -189,21 +189,26 @@ require_once "resources/require.php";
|
||||
|
||||
//check to see if the mac address exists
|
||||
if ($action == "add") {
|
||||
$sql = "SELECT count(*) AS num_rows FROM v_devices ";
|
||||
$sql .= "WHERE device_mac_address = '".$device_mac_address."' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['num_rows'] == "0") {
|
||||
$save = true;
|
||||
}
|
||||
else {
|
||||
$save = false;
|
||||
$_SESSION['message'] = $text['message-duplicate'];
|
||||
}
|
||||
if ($device_mac_address == "" || $device_mac_address == "000000000000") {
|
||||
//allow duplicates to be used as templaes
|
||||
}
|
||||
else {
|
||||
$sql = "SELECT count(*) AS num_rows FROM v_devices ";
|
||||
$sql .= "WHERE device_mac_address = '".$device_mac_address."' ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['num_rows'] == "0") {
|
||||
$save = true;
|
||||
}
|
||||
else {
|
||||
$save = false;
|
||||
$_SESSION['message'] = $text['message-duplicate'];
|
||||
}
|
||||
}
|
||||
unset($prep_statement);
|
||||
}
|
||||
unset($prep_statement);
|
||||
}
|
||||
else {
|
||||
$save = true;
|
||||
|
||||
Reference in New Issue
Block a user