mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 09:03:49 +00:00
Update number_translation_edit.php
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2017-2019
|
||||
Portions created by the Initial Developer are Copyright (C) 2018 - 2020
|
||||
the Initial Developer. All Rights Reserved.
|
||||
*/
|
||||
|
||||
@@ -50,42 +50,16 @@
|
||||
}
|
||||
|
||||
//get http post variables and set them to php variables
|
||||
if (is_array($_POST)) {
|
||||
$number_translation_uuid = $_POST["number_translation_uuid"];
|
||||
if (is_array($_POST) && is_uuid($number_translation_uuid)) {
|
||||
$number_translation_name = $_POST["number_translation_name"];
|
||||
$number_translation_details = $_POST["number_translation_details"];
|
||||
$number_translation_enabled = $_POST["number_translation_enabled"];
|
||||
$number_translation_description = $_POST["number_translation_description"];
|
||||
$number_translation_details_delete = $_POST["number_translation_details_delete"];
|
||||
}
|
||||
|
||||
//process the user data and save it to the database
|
||||
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
|
||||
|
||||
//process the http post data by submitted action
|
||||
if ($_POST['action'] != '' && is_uuid($number_translation_uuid)) {
|
||||
$array[0]['checked'] = 'true';
|
||||
$array[0]['uuid'] = $number_translation_uuid;
|
||||
|
||||
switch ($_POST['action']) {
|
||||
case 'copy':
|
||||
if (permission_exists('number_translation_add')) {
|
||||
$obj = new number_translations;
|
||||
$obj->copy($array);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (permission_exists('number_translation_delete')) {
|
||||
$obj = new number_translations;
|
||||
$obj->delete($array);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
header('Location: number_translations.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
@@ -94,6 +68,48 @@
|
||||
exit;
|
||||
}
|
||||
|
||||
//process the http post data by submitted action
|
||||
if ($_POST['action'] != '' && strlen($_POST['action']) > 0) {
|
||||
|
||||
//prepare the array(s)
|
||||
$x = 0;
|
||||
foreach ($_POST['number_translation_details'] as $row) {
|
||||
if (is_uuid($row['number_translation_uuid']) && $row['checked'] === 'true') {
|
||||
$array['number_translations'][$x]['checked'] = $row['checked'];
|
||||
$array['number_translations'][$x]['number_translation_details'][]['number_translation_detail_uuid'] = $row['number_translation_detail_uuid'];
|
||||
$x++;
|
||||
}
|
||||
}
|
||||
|
||||
//send the array to the database class
|
||||
switch ($_POST['action']) {
|
||||
case 'copy':
|
||||
if (permission_exists('number_translation_add')) {
|
||||
$obj = new database;
|
||||
$obj->copy($array);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if (permission_exists('number_translation_delete')) {
|
||||
$obj = new database;
|
||||
$obj->delete($array);
|
||||
}
|
||||
break;
|
||||
case 'toggle':
|
||||
if (permission_exists('number_translation_update')) {
|
||||
$obj = new database;
|
||||
$obj->toggle($array);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//redirect the user
|
||||
if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) {
|
||||
header('Location: number_translation_edit.php?id='.$id);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
//check for all required data
|
||||
$msg = '';
|
||||
if (strlen($number_translation_name) == 0) { $msg .= $text['message-required']." ".$text['label-number_translation_name']."<br>\n"; }
|
||||
@@ -119,39 +135,32 @@
|
||||
}
|
||||
|
||||
//prepare the array
|
||||
$array['number_translations'][0]["number_translation_uuid"] = $number_translation_uuid;
|
||||
$array['number_translations'][0]["number_translation_name"] = $number_translation_name;
|
||||
$array['number_translations'][0]["number_translation_enabled"] = $number_translation_enabled;
|
||||
$array['number_translations'][0]["number_translation_description"] = $number_translation_description;
|
||||
$array['number_translations'][0]['number_translation_uuid'] = $number_translation_uuid;
|
||||
$array['number_translations'][0]['number_translation_name'] = $number_translation_name;
|
||||
$array['number_translations'][0]['number_translation_enabled'] = $number_translation_enabled;
|
||||
$array['number_translations'][0]['number_translation_description'] = $number_translation_description;
|
||||
$y = 0;
|
||||
foreach ($number_translation_details as $row) {
|
||||
if (strlen($row['number_translation_detail_regex']) > 0) {
|
||||
$array['number_translations'][0]['number_translation_details'][$y]["number_translation_detail_uuid"] = $row["number_translation_detail_uuid"];
|
||||
$array['number_translations'][0]['number_translation_details'][$y]["number_translation_detail_regex"] = $row["number_translation_detail_regex"];
|
||||
$array['number_translations'][0]['number_translation_details'][$y]["number_translation_detail_replace"] = $row["number_translation_detail_replace"];
|
||||
$array['number_translations'][0]['number_translation_details'][$y]["number_translation_detail_order"] = $row["number_translation_detail_order"];
|
||||
$y++;
|
||||
if (is_array($number_translation_details)) {
|
||||
foreach ($number_translation_details as $row) {
|
||||
if (strlen($row['number_translation_detail_regex']) > 0) {
|
||||
$array['number_translations'][0]['number_translation_details'][$y]['number_translation_detail_uuid'] = $row["number_translation_detail_uuid"];
|
||||
$array['number_translations'][0]['number_translation_details'][$y]['number_translation_detail_regex'] = $row["number_translation_detail_regex"];
|
||||
$array['number_translations'][0]['number_translation_details'][$y]['number_translation_detail_replace'] = $row["number_translation_detail_replace"];
|
||||
$array['number_translations'][0]['number_translation_details'][$y]['number_translation_detail_order'] = $row["number_translation_detail_order"];
|
||||
if (isset($row["checked"])) {
|
||||
$array['number_translations'][0]['number_translation_details'][$y]['checked'] = $row["checked"];
|
||||
}
|
||||
$y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//save to the data
|
||||
//save the data
|
||||
$database = new database;
|
||||
$database->app_name = 'Number Translations';
|
||||
$database->app_name = 'number translations';
|
||||
$database->app_uuid = '6ad54de6-4909-11e7-a919-92ebcb67fe33';
|
||||
$database->save($array);
|
||||
|
||||
//remove checked details
|
||||
if (
|
||||
$action == 'update'
|
||||
&& permission_exists('number_translation_detail_delete')
|
||||
&& is_array($number_translation_details_delete)
|
||||
&& @sizeof($number_translation_details_delete) != 0
|
||||
) {
|
||||
$obj = new number_translations;
|
||||
$obj->number_translation_uuid = $number_translation_uuid;
|
||||
$obj->delete_details($number_translation_details_delete);
|
||||
}
|
||||
|
||||
//redirect the user
|
||||
if (isset($action)) {
|
||||
if ($action == "add") {
|
||||
@@ -160,14 +169,14 @@
|
||||
if ($action == "update") {
|
||||
$_SESSION["message"] = $text['message-update'];
|
||||
}
|
||||
//header('Location: number_translations.php');
|
||||
header('Location: number_translation_edit.php?id='.urlencode($number_translation_uuid));
|
||||
return;
|
||||
}
|
||||
} //(is_array($_POST) && strlen($_POST["persistformvar"]) == 0)
|
||||
}
|
||||
|
||||
//pre-populate the form
|
||||
if (is_array($_GET) && $_POST["persistformvar"] != "true") {
|
||||
$number_translation_uuid = $_GET["id"];
|
||||
$sql = "select * from v_number_translations ";
|
||||
$sql .= "where number_translation_uuid = :number_translation_uuid ";
|
||||
$parameters['number_translation_uuid'] = $number_translation_uuid;
|
||||
@@ -179,14 +188,14 @@
|
||||
$number_translation_enabled = $row["number_translation_enabled"];
|
||||
$number_translation_description = $row["number_translation_description"];
|
||||
}
|
||||
unset ($sql, $parameters, $row);
|
||||
unset($sql, $parameters, $row);
|
||||
}
|
||||
|
||||
//get the child data
|
||||
if (is_uuid($number_translation_uuid)) {
|
||||
$sql = "select * from v_number_translation_details ";
|
||||
$sql .= "where number_translation_uuid = :number_translation_uuid ";
|
||||
$sql .= "order by cast(number_translation_detail_order as integer) asc";
|
||||
$sql .= "order by number_translation_detail_order asc";
|
||||
$parameters['number_translation_uuid'] = $number_translation_uuid;
|
||||
$database = new database;
|
||||
$number_translation_details = $database->select($sql, $parameters, 'all');
|
||||
@@ -201,7 +210,7 @@
|
||||
//add an empty row
|
||||
$x = is_array($number_translation_details) ? count($number_translation_details) : 0;
|
||||
$number_translation_details[$x]['number_translation_uuid'] = $number_translation_uuid;
|
||||
$number_translation_details[$x]['number_translation_detail_uuid'] = '';
|
||||
$number_translation_details[$x]['number_translation_detail_uuid'] = uuid();
|
||||
$number_translation_details[$x]['number_translation_detail_regex'] = '';
|
||||
$number_translation_details[$x]['number_translation_detail_replace'] = '';
|
||||
$number_translation_details[$x]['number_translation_detail_order'] = '';
|
||||
@@ -216,40 +225,56 @@
|
||||
|
||||
//show the content
|
||||
echo "<form name='frm' id='frm' method='post'>\n";
|
||||
echo "<input class='formfld' type='hidden' name='number_translation_uuid' value='".escape($number_translation_uuid)."'>\n";
|
||||
|
||||
echo "<div class='action_bar' id='action_bar'>\n";
|
||||
echo " <div class='heading'><b>".$text['title-number_translation']."</b></div>\n";
|
||||
echo " <div class='actions'>\n";
|
||||
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'number_translations.php']);
|
||||
if ($action == "update") {
|
||||
if (permission_exists('number_translation_add')) {
|
||||
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'name'=>'btn_copy','onclick'=>"modal_open('modal-copy','btn_copy');"]);
|
||||
echo " <button type='button' id='btn_back' alt='".$text['button-back']."' title='Back' class='btn btn-default' onclick=\"location.href='number_translations.php'\">\n";
|
||||
echo " <span class='".$_SESSION['theme']['button_icon_back']['text']." $button_icon_class' style='$button_icon_style'></span>\n";
|
||||
echo " <span class='$button_label_class' style='$button_label_style'>".$text['button-back']."</span>\n";
|
||||
echo " </button>\n";
|
||||
if ($action == 'update') {
|
||||
if (permission_exists('number_translation_detail_add')) {
|
||||
echo " <button type='submit' id='btn_copy' alt='".$text['button-copy']."' title='Copy' name='action' value='copy' style='display: none;' onclick=\"modal_open('modal-copy','btn_copy'); return false;\" class='btn btn-default'>\n";
|
||||
echo " <span class='".$_SESSION['theme']['button_icon_copy']['text']." $button_icon_class' style='$button_icon_style'></span>\n";
|
||||
echo " <span class='$button_label_class' style='$button_label_style'>".$text['button-copy']."</span>\n";
|
||||
echo " </button>\n";
|
||||
}
|
||||
if (permission_exists('number_translation_delete') || permission_exists('number_translation_detail_delete')) {
|
||||
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>'margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
|
||||
if (permission_exists('number_translation_detail_delete')) {
|
||||
echo " <button type='submit' id='btn_delete' alt='".$text['button-delete']."' title='Delete' name='action' value='delete' style='display: none;' onclick=\"modal_open('modal-delete','btn_delete'); return false;\" class='btn btn-default'>\n";
|
||||
echo " <span class='".$_SESSION['theme']['button_icon_delete']['text']." $button_icon_class' style='$button_icon_style'></span>\n";
|
||||
echo " <span class='$button_label_class' style='$button_label_style'>".$text['button-delete']."</span>\n";
|
||||
echo " </button>\n";
|
||||
}
|
||||
}
|
||||
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']);
|
||||
echo " <button type='submit' id='btn_save' alt='".$text['button-save']."' title='Save' name='action' value='save' onclick='' class='btn btn-default'>\n";
|
||||
echo " <span class='".$_SESSION['theme']['button_icon_save']['text']." $button_icon_class' style='$button_icon_style'></span>\n";
|
||||
echo " <span class='$button_label_class' style='$button_label_style'>".$text['button-save']."</span>\n";
|
||||
echo " </button>\n";
|
||||
echo " </div>\n";
|
||||
echo " <div style='clear: both;'></div>\n";
|
||||
echo "</div>\n";
|
||||
|
||||
if ($action == "update") {
|
||||
echo $text['title_description-number_translations']."\n";
|
||||
echo "<br /><br />\n";
|
||||
|
||||
if ($action == 'update') {
|
||||
if (permission_exists('number_translation_add')) {
|
||||
echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'copy','onclick'=>"modal_close();"])]);
|
||||
}
|
||||
if (permission_exists('number_translation_delete') || permission_exists('number_translation_detail_delete')) {
|
||||
if (permission_exists('number_translation_delete')) {
|
||||
echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]);
|
||||
}
|
||||
}
|
||||
|
||||
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
||||
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
||||
|
||||
echo "<tr>\n";
|
||||
echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
|
||||
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
|
||||
echo " ".$text['label-number_translation_name']."\n";
|
||||
echo "</td>\n";
|
||||
echo "<td width='70%' class='vtable' style='position: relative;' align='left'>\n";
|
||||
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
||||
echo " <input class='formfld' type='text' name='number_translation_name' maxlength='255' value='".escape($number_translation_name)."'>\n";
|
||||
echo "<br />\n";
|
||||
echo $text['description-number_translation_name']."\n";
|
||||
@@ -268,8 +293,8 @@
|
||||
echo " <th class='vtablereq'>".$text['label-number_translation_detail_order']."</th>\n";
|
||||
if (is_array($number_translation_details) && @sizeof($number_translation_details) > 1 && permission_exists('number_translation_detail_delete')) {
|
||||
echo " <td class='vtable edit_delete_checkbox_all' onmouseover=\"swap_display('delete_label_details', 'delete_toggle_details');\" onmouseout=\"swap_display('delete_label_details', 'delete_toggle_details');\">\n";
|
||||
echo " <span id='delete_label_details'>".$text['label-delete']."</span>\n";
|
||||
echo " <span id='delete_toggle_details'><input type='checkbox' id='checkbox_all_details' name='checkbox_all' onclick=\"edit_all_toggle('details');\"></span>\n";
|
||||
echo " <span id='delete_label_details'>".$text['label-action']."</span>\n";
|
||||
echo " <span id='delete_toggle_details'><input type='checkbox' id='checkbox_all_details' name='checkbox_all' onclick=\"edit_all_toggle('details'); checkbox_on_change(this);\"></span>\n";
|
||||
echo " </td>\n";
|
||||
}
|
||||
echo " </tr>\n";
|
||||
@@ -277,9 +302,13 @@
|
||||
foreach($number_translation_details as $row) {
|
||||
echo " <tr>\n";
|
||||
echo " <input type='hidden' name='number_translation_details[$x][number_translation_uuid]' value=\"".escape($row["number_translation_uuid"])."\">\n";
|
||||
echo " <input type='hidden' name='number_translation_details[$x][number_translation_detail_uuid]' value=\"".(is_uuid($row["number_translation_detail_uuid"]) ? $row["number_translation_detail_uuid"] : uuid())."\">\n";
|
||||
echo " <td class='formfld'><input class='formfld' type='text' name='number_translation_details[$x][number_translation_detail_regex]' maxlength='255' value=\"".escape($row["number_translation_detail_regex"])."\"></td>\n";
|
||||
echo " <td class='formfld'><input class='formfld' type='text' name='number_translation_details[$x][number_translation_detail_replace]' maxlength='255' value=\"".escape($row["number_translation_detail_replace"])."\"></td>\n";
|
||||
echo " <input type='hidden' name='number_translation_details[$x][number_translation_detail_uuid]' value=\"".escape($row["number_translation_detail_uuid"])."\">\n";
|
||||
echo " <td class='formfld'>\n";
|
||||
echo " <input class='formfld' type='text' name='number_translation_details[$x][number_translation_detail_regex]' maxlength='255' value=\"".escape($row["number_translation_detail_regex"])."\">\n";
|
||||
echo " </td>\n";
|
||||
echo " <td class='formfld'>\n";
|
||||
echo " <input class='formfld' type='text' name='number_translation_details[$x][number_translation_detail_replace]' maxlength='255' value=\"".escape($row["number_translation_detail_replace"])."\">\n";
|
||||
echo " </td>\n";
|
||||
echo " <td class='formfld'>\n";
|
||||
echo " <select name='number_translation_details[$x][number_translation_detail_order]' class='formfld'>\n";
|
||||
$i=0;
|
||||
@@ -300,14 +329,13 @@
|
||||
echo " </td>\n";
|
||||
if (is_array($number_translation_details) && @sizeof($number_translation_details) > 1 && permission_exists('number_translation_detail_delete')) {
|
||||
if (is_uuid($row['number_translation_detail_uuid'])) {
|
||||
echo " <td class='vtable' style='text-align: center; padding-bottom: 3px;'>";
|
||||
echo " <input type='checkbox' name='number_translation_details_delete[".$x."][checked]' value='true' class='chk_delete checkbox_details' onclick=\"edit_delete_action('details');\">\n";
|
||||
echo " <input type='hidden' name='number_translation_details_delete[".$x."][uuid]' value='".escape($row['number_translation_detail_uuid'])."' />\n";
|
||||
echo " <td class='vtable' style='text-align: center; padding-bottom: 3px;'>\n";
|
||||
echo " <input type='checkbox' name='number_translation_details[".$x."][checked]' value='true' class='chk_delete checkbox_details' onclick=\"checkbox_on_change(this);\">\n";
|
||||
echo " </td>\n";
|
||||
}
|
||||
else {
|
||||
echo " <td>\n";
|
||||
echo " <td></td>\n";
|
||||
}
|
||||
echo " </td>\n";
|
||||
}
|
||||
echo " </tr>\n";
|
||||
$x++;
|
||||
@@ -356,7 +384,6 @@
|
||||
echo "</table>";
|
||||
echo "<br /><br />";
|
||||
|
||||
echo "<input type='hidden' name='number_translation_uuid' value='".escape($number_translation_uuid)."'>\n";
|
||||
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
|
||||
|
||||
echo "</form>";
|
||||
@@ -364,4 +391,4 @@
|
||||
//include the footer
|
||||
require_once "resources/footer.php";
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user