SIP Profiles - Edit/Copy: Prevent duplicate names.

This commit is contained in:
fusionate 2023-03-27 20:22:35 +00:00
parent 4fe99907e1
commit 0f02253e4e
No known key found for this signature in database
3 changed files with 197 additions and 92 deletions

View File

@ -379,26 +379,26 @@ $text['label-sip_profile_settings']['ru-ru'] = "Настройки";
$text['label-sip_profile_settings']['sv-se'] = "Inställningar";
$text['label-sip_profile_settings']['uk-ua'] = "Параметри";
$text['label-new_sip_profile_name']['en-us'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['en-gb'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['ar-eg'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['de-at'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['de-ch'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['de-de'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['es-cl'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['es-mx'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['en-us'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['en-gb'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['ar-eg'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['de-at'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['de-ch'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['de-de'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['es-cl'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['es-mx'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['fr-ca'] = "Entrez le nouveau nom de profil SIP";
$text['label-new_sip_profile_name']['fr-fr'] = "Entrez le nouveau nom de profil SIP";
$text['label-new_sip_profile_name']['he-il'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['it-it'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['nl-nl'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['pl-pl'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['pt-br'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['pt-pt'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['ro-ro'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['ru-ru'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['sv-se'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['uk-ua'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['he-il'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['it-it'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['nl-nl'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['pl-pl'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['pt-br'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['pt-pt'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['ro-ro'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['ru-ru'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['sv-se'] = "Enter a new, unique SIP Profile Name";
$text['label-new_sip_profile_name']['uk-ua'] = "Enter a new, unique SIP Profile Name";
$text['header-sip_profiles']['en-us'] = "SIP Profiles";
$text['header-sip_profiles']['en-gb'] = "SIP Profiles";
@ -673,4 +673,25 @@ $text['description-sip_profile_enabled']['ru-ru'] = "Управление сос
$text['description-sip_profile_enabled']['sv-se'] = "Styr tillståndet i profilen.";
$text['description-sip_profile_enabled']['uk-ua'] = "Керування станом профілю";
?>
$text['message-sip_profile_unique']['en-us'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['en-gb'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['ar-eg'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['de-at'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['de-ch'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['de-de'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['es-cl'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['es-mx'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['fr-ca'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['fr-fr'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['he-il'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['it-it'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['nl-nl'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['pl-pl'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['pt-br'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['pt-pt'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['ro-ro'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['ru-ru'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['sv-se'] = "Invalid SIP Profile Name - Must be Unique";
$text['message-sip_profile_unique']['uk-ua'] = "Invalid SIP Profile Name - Must be Unique";
?>

View File

@ -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;
}
}

View File

@ -122,6 +122,29 @@
return;
}
//check for duplicate profile name
$sql = "select sip_profile_name from v_sip_profiles".($action == 'update' ? "where sip_profile_name <> :sip_profile_name" : null);
if ($action == 'update') {
$parameters['sip_profile_name'] = $sip_profile_name;
}
$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_array($sip_profile_names) && @sizeof($sip_profile_names) != 0 && in_array($sip_profile_name, $sip_profile_names)) {
//set message
message::add($text['message-sip_profile_unique'], 'negative', 5000);
//redirect
header("Location: sip_profiles.php");
exit;
}
//add the sip_profile_uuid
if (!is_uuid($_POST["sip_profile_uuid"])) {
$sip_profile_uuid = uuid();
@ -300,6 +323,28 @@
$sip_profile_domains[$x]['sip_profile_domain_parse'] = '';
}
//create js array of 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'];
}
if (is_array($sip_profile_names) && @sizeof($sip_profile_names) != 0) {
//all profile names
$js_sip_profile_names['all'] = "const sip_profile_names_all = ['".implode("','", $sip_profile_names)."'];";
//other profile names
foreach ($sip_profile_names as $n => $name) {
if ($sip_profile_name == $name) { unset($sip_profile_names[$n]); }
}
if (is_array($sip_profile_names) && @sizeof($sip_profile_names) != 0) {
$js_sip_profile_names['other'] = "const sip_profile_names_other = ['".implode("','", $sip_profile_names)."'];";
}
}
}
unset($sql);
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
@ -308,15 +353,23 @@
$document['title'] = $text['title-sip_profile'];
require_once "resources/header.php";
//label to form input
//helper scripts
echo "<script language='javascript'>\n";
echo " function label_to_form(label_id, form_id) {\n";
echo " if (document.getElementById(label_id) != null) {\n";
echo " label = document.getElementById(label_id);\n";
echo " label.parentNode.removeChild(label);\n";
echo " }\n";
echo " document.getElementById(form_id).style.display='';\n";
echo " }\n";
//label to form input
echo " function label_to_form(label_id, form_id) {\n";
echo " if (document.getElementById(label_id) != null) {\n";
echo " label = document.getElementById(label_id);\n";
echo " label.parentNode.removeChild(label);\n";
echo " }\n";
echo " document.getElementById(form_id).style.display='';\n";
echo " }\n";
//output js arrays to prevent duplicate profile names
echo $js_sip_profile_names['all']."\n";
echo $js_sip_profile_names['other']."\n";
unset($js_sip_profile_names);
echo "</script>\n";
//show the content
@ -346,7 +399,7 @@
unset($button_margin);
}
}
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;']);
echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;','onclick'=>"if (document.getElementById('sip_profile_name').value != '' && !sip_profile_names_other.includes(document.getElementById('sip_profile_name').value)) { $('#frm').submit(); } else { display_message('".$text['message-sip_profile_unique']."', 'negative', 5000); }"]);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
@ -361,7 +414,9 @@
echo modal::create([
'id'=>'modal-copy',
'type'=>'general',
'message'=>$text['label-new_sip_profile_name']."...<br /><br /><input class='formfld modal-input' data-continue='btn_copy' type='text' id='new_profile_name' maxlength='255'>",
'message'=>
$text['label-new_sip_profile_name']."...<br /><br />\n
<input class='formfld modal-input' data-continue='btn_copy' type='text' id='new_profile_name' maxlength='255'>\n",
'actions'=>button::create([
'type'=>'button',
'label'=>$text['button-continue'],
@ -369,7 +424,7 @@
'id'=>'btn_copy',
'style'=>'float: right; margin-left: 15px;',
'collapse'=>'never',
'onclick'=>"modal_close(); if (document.getElementById('new_profile_name').value != '') { window.location='sip_profile_copy.php?id=".urlencode($sip_profile_uuid)."&name=' + document.getElementById('new_profile_name').value; }"
'onclick'=>"modal_close(); if (document.getElementById('new_profile_name').value != '' && !sip_profile_names_all.includes(document.getElementById('new_profile_name').value)) { window.location='sip_profile_copy.php?id=".urlencode($sip_profile_uuid)."&name=' + document.getElementById('new_profile_name').value; } else { display_message('".$text['message-sip_profile_unique']."', 'negative', 5000); }",
]),
'onclose'=>"document.getElementById('new_profile_name').value = '';",
]);
@ -390,7 +445,7 @@
echo " ".$text['label-sip_profile_name']."\n";
echo "</td>\n";
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='sip_profile_name' maxlength='255' value=\"".escape($sip_profile_name)."\">\n";
echo " <input class='formfld' type='text' id='sip_profile_name' name='sip_profile_name' maxlength='255' value=\"".escape($sip_profile_name)."\">\n";
echo "<br />\n";
echo $text['description-sip_profile_name']."\n";
echo "</td>\n";