This commit is contained in:
jakani24
2024-03-10 09:55:02 +01:00
parent fb01961cc1
commit b5fd92f8b1
3 changed files with 81 additions and 10 deletions

View File

@@ -85,16 +85,25 @@ async function delete_item(db,id){
location.reload();
}
//add an entry
async function add_item(db,element_id,field){
async function add_item(db,element_id1,field1,element_id2,field2){ //we have two valus, two dbs and so on, becuase we have the signature and the description
var element = document.getElementById(element_id);
var value = element.value;
await fetch('database_settings.php?add='+db+'&value='+value+'&field='+field);
await fetch('database_settings.php?add='+db+'&value1='+value1+'&field1='+field1+'&value2='+value2+'&field2='+field2);
location.reload();
}
</script>
<?php
//the code to update / delete and add items:
//we store all the functions like update,safe,load etc in this file, because else "database_settings.php" will get way to big
include "database_settings_functions.php";
if(isset($_GET["update"])){
safe_settings();
}
if(isset($_GET["delete"])){
delete_item($_GET["db"],$_GET["delete"]);
}
if(isset($_GET["add"])){
add_item($_GET["add"],$_GET["value1"],$_GET["field1"],$_GET["value2"],$_GET["field2"]);
}
?>
<div class="container mt-5">
<div class="row justify-content-center">
@@ -147,19 +156,21 @@ async function add_item(db,element_id,field){
echo '<table class="table" style="overflow-x:auto">';
echo '<thead>';
echo '<tr>';
echo '<th>#</th><th>Signature</th><th>Add / Delete</th>';
echo '<th>#</th><th>Signature</th><th>Description</th><th>Add / Delete</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
echo('<tr>');
echo('<th scope="row">000</th>');
echo('<td><input type="text" id="sig_ex" class="form-control" name="name"></td>');
echo('<td><button type="button" class="btn btn-primary" onclick="add_item(\'sig_ex\',\'sig_ex\',\'signature\');">Add</button></td>');
echo('<td><input type="text" id="sig_ex_desc" class="form-control" name="name"></td>');
echo('<td><button type="button" class="btn btn-primary" onclick="add_item(\'sig_ex\',\'sig_ex\',\'signature\',\'sig_ex_desc\',\'sig_ex_desc\',\'description\');">Add</button></td>');
echo('</tr>');
while($row = $result->fetch_assoc()) {
echo '<tr>';
echo("<th scope=\"row\">".$row["id"]."</th>");
echo("<td><input type=\"text\" id=\"sig_ex".$row["id"]."\" class=\"form-control\" name=\"name\" value=\"".$row["signature"]."\" oninput=\"update_textfield('sig_ex".$row["id"]."','sig_ex','".$row["id"]."');\"></td>");
echo("<td><input type=\"text\" id=\"sig_ex_desc".$row["id"]."\" class=\"form-control\" name=\"name\" value=\"".$row["description"]."\" oninput=\"update_textfield('sig_ex_desc".$row["id"]."','sig_ex_desc','".$row["id"]."');\"></td>");
echo("<td><button type=\"button\" class=\"btn btn-danger\" onclick=\"delete_item('sig_ex',".$row["id"].");\">Delete</button></td>");
echo '</tr>';
}