mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
SIP Profiles - Edit/Copy: Prevent duplicate names.
This commit is contained in:
@@ -53,79 +53,108 @@
|
||||
$sip_profile_uuid = $_REQUEST["id"];
|
||||
$sip_profile_name = $_REQUEST["name"];
|
||||
|
||||
//get existing sip profile names to prevent duplicates
|
||||
$sql = "select sip_profile_name from v_sip_profiles";
|
||||
$database = new database;
|
||||
$rows = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $array) {
|
||||
$sip_profile_names[] = $array['sip_profile_name'];
|
||||
}
|
||||
}
|
||||
unset($sql);
|
||||
|
||||
if (is_uuid($sip_profile_uuid) && $sip_profile_name != '') {
|
||||
|
||||
//get the sip profile data
|
||||
if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
|
||||
$sql = "select sip_profile_hostname, sip_profile_enabled, sip_profile_description from v_sip_profiles ";
|
||||
if (!in_array($sip_profile_name, $sip_profile_names)) {
|
||||
|
||||
//get the sip profile data
|
||||
if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
|
||||
$sql = "select sip_profile_hostname, sip_profile_enabled, sip_profile_description from v_sip_profiles ";
|
||||
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
|
||||
$parameters['sip_profile_uuid'] = $sip_profile_uuid;
|
||||
$database = new database;
|
||||
$row = $database->select($sql, $parameters, 'row');
|
||||
$sip_profile_hostname = $row['sip_profile_hostname'];
|
||||
$sip_profile_enabled = $row['sip_profile_enabled'];
|
||||
$sip_profile_description = $row['sip_profile_description'];
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
//copy the sip profile
|
||||
$sip_profile_uuid_new = uuid();
|
||||
$array['sip_profiles'][0]['sip_profile_uuid'] = $sip_profile_uuid_new;
|
||||
$array['sip_profiles'][0]['sip_profile_name'] = $sip_profile_name;
|
||||
$array['sip_profiles'][0]['sip_profile_hostname'] = $sip_profile_hostname;
|
||||
$array['sip_profiles'][0]['sip_profile_enabled'] = $sip_profile_enabled;
|
||||
$array['sip_profiles'][0]['sip_profile_description'] = $sip_profile_description.' ('.$text['label-copy'].')';
|
||||
|
||||
//get the the sip profile settings
|
||||
$sql = "select * from v_sip_profile_domains ";
|
||||
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
|
||||
$parameters['sip_profile_uuid'] = $sip_profile_uuid;
|
||||
$database = new database;
|
||||
$row = $database->select($sql, $parameters, 'row');
|
||||
$sip_profile_hostname = $row['sip_profile_hostname'];
|
||||
$sip_profile_enabled = $row['sip_profile_enabled'];
|
||||
$sip_profile_description = $row['sip_profile_description'];
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
//copy the sip profile
|
||||
$sip_profile_uuid_new = uuid();
|
||||
$array['sip_profiles'][0]['sip_profile_uuid'] = $sip_profile_uuid_new;
|
||||
$array['sip_profiles'][0]['sip_profile_name'] = $sip_profile_name;
|
||||
$array['sip_profiles'][0]['sip_profile_hostname'] = $sip_profile_hostname;
|
||||
$array['sip_profiles'][0]['sip_profile_enabled'] = $sip_profile_enabled;
|
||||
$array['sip_profiles'][0]['sip_profile_description'] = $sip_profile_description.' ('.$text['label-copy'].')';
|
||||
|
||||
//get the the sip profile settings
|
||||
$sql = "select * from v_sip_profile_domains ";
|
||||
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
|
||||
$parameters['sip_profile_uuid'] = $sip_profile_uuid;
|
||||
$database = new database;
|
||||
$result = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as $x => &$row) {
|
||||
$array['sip_profile_domains'][$x]['sip_profile_domain_uuid'] = uuid();
|
||||
$array['sip_profile_domains'][$x]['sip_profile_uuid'] = $sip_profile_uuid_new;
|
||||
$array['sip_profile_domains'][$x]['sip_profile_domain_name'] = $row["sip_profile_domain_name"];
|
||||
$array['sip_profile_domains'][$x]['sip_profile_domain_alias'] = $row["sip_profile_domain_alias"];
|
||||
$array['sip_profile_domains'][$x]['sip_profile_domain_parse'] = $row["sip_profile_domain_parse"];
|
||||
$result = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as $x => &$row) {
|
||||
$array['sip_profile_domains'][$x]['sip_profile_domain_uuid'] = uuid();
|
||||
$array['sip_profile_domains'][$x]['sip_profile_uuid'] = $sip_profile_uuid_new;
|
||||
$array['sip_profile_domains'][$x]['sip_profile_domain_name'] = $row["sip_profile_domain_name"];
|
||||
$array['sip_profile_domains'][$x]['sip_profile_domain_alias'] = $row["sip_profile_domain_alias"];
|
||||
$array['sip_profile_domains'][$x]['sip_profile_domain_parse'] = $row["sip_profile_domain_parse"];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($sql, $parameters, $result, $row);
|
||||
unset($sql, $parameters, $result, $row);
|
||||
|
||||
//get the the sip profile settings
|
||||
$sql = "select * from v_sip_profile_settings ";
|
||||
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
|
||||
$parameters['sip_profile_uuid'] = $sip_profile_uuid;
|
||||
$database = new database;
|
||||
$result = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as $x => &$row) {
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_uuid'] = uuid();
|
||||
$array['sip_profile_settings'][$x]['sip_profile_uuid'] = $sip_profile_uuid_new;
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_name'] = $row["sip_profile_setting_name"];
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_value'] = $row["sip_profile_setting_value"];
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_enabled'] = $row["sip_profile_setting_enabled"];
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_description'] = $row["sip_profile_setting_description"];
|
||||
//get the the sip profile settings
|
||||
$sql = "select * from v_sip_profile_settings ";
|
||||
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
|
||||
$parameters['sip_profile_uuid'] = $sip_profile_uuid;
|
||||
$database = new database;
|
||||
$result = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as $x => &$row) {
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_uuid'] = uuid();
|
||||
$array['sip_profile_settings'][$x]['sip_profile_uuid'] = $sip_profile_uuid_new;
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_name'] = $row["sip_profile_setting_name"];
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_value'] = $row["sip_profile_setting_value"];
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_enabled'] = $row["sip_profile_setting_enabled"];
|
||||
$array['sip_profile_settings'][$x]['sip_profile_setting_description'] = $row["sip_profile_setting_description"];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($sql, $parameters, $result, $row);
|
||||
unset($sql, $parameters, $result, $row);
|
||||
|
||||
//execute insert
|
||||
$database = new database;
|
||||
$database->app_name = 'sip_profiles';
|
||||
$database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//execute insert
|
||||
$database = new database;
|
||||
$database->app_name = 'sip_profiles';
|
||||
$database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
|
||||
//save the sip profile xml
|
||||
save_sip_profile_xml();
|
||||
//save the sip profile xml
|
||||
save_sip_profile_xml();
|
||||
|
||||
//apply settings reminder
|
||||
$_SESSION["reload_xml"] = true;
|
||||
//apply settings reminder
|
||||
$_SESSION["reload_xml"] = true;
|
||||
|
||||
//set message
|
||||
message::add($text['message-copy']);
|
||||
//set message
|
||||
message::add($text['message-copy']);
|
||||
|
||||
//redirect the user
|
||||
header("Location: sip_profiles.php");
|
||||
exit;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
//set message
|
||||
message::add($text['message-sip_profile_unique'], 'negative', 5000);
|
||||
|
||||
//redirect
|
||||
header("Location: sip_profile_edit.php?id=".$sip_profile_uuid);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user