Ich bin mir nicht sicher. Grundsätzlich ist folgendes meine Website. Man soll einfach nur die Daten für die Müllabholung eintragen können und das ganze soll dann in eine json Datei geschrieben werden.
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="cache-control" content="no-cache">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mülltonen Abholdaten</title>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="css/style.css" media="screen,projection" />
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css" media="screen,projection" />
</head>
<body>
<div class="container">
<?php
$filepath = "./dates.json";
if (file_exists($filepath)) {
$jsonfile = file_get_contents($filepath);
$content = json_decode($jsonfile, true);
}
?>
<div class="row">
<div class="col-md-4">
<br />
<form enctype="multipart/form-data" action=" " method="post">
<input type="date" name="date1" id="date1" />
<input type="submit" name="Submit" value="Gelbetonne" class="btn yellow" style="margin-right: 10px" /><input type="submit" name="Submit" value="Gelb-Löschen" class="btn red" />
</form>
<br />
<br />
<br />
<table id="table1" class="table table-fixed">
<thead>
<tr>
<th>
Gelbetonne:
</th>
</tr>
</thead>
<tbody>
<?php
if (isset($content['tonnen']['Gelbetonne'])) {
$gelbetonne = $content['tonnen']['Gelbetonne'];
for ($i=0; $i < count($gelbetonne); $i++) {
echo "<tr onclick='javascript:table1(this);'>";
echo "<td>$gelbetonne[$i]</td>";
echo "</tr>";
}
}else {
$gelbetonne = array();
}
?>
</tbody>
</table>
</div>
<div class="col-md-4">
<br />
<form enctype="multipart/form-data" action=" " method="post">
<input type="date" name="date2" id="date2" />
<input type="submit" name="Submit" value="Restmülltonne" class="btn black" style="margin-right: 10px" /><input type="submit" name="Submit" value="Restmüll-Löschen" class="btn red" />
</form>
<br />
<br />
<br />
<table id="table2" class="table table-fixed">
<thead>
<tr>
<th>
Restmülltonne:
</th>
</tr>
</thead>
<tbody>
<?php
if (isset($content['tonnen']['Restmuelltonne'])) {
$restmuell = $content['tonnen']['Restmuelltonne'];
for ($j=0; $j < count($restmuell); $j++) {
echo "<tr onclick='javascript:table2(this);'>";
echo "<td>$restmuell[$j]</td>";
echo "</tr>";
}
}else {
$restmuell = array();
}
?>
</tbody>
</table>
</div>
<div class="col-md-4">
<br />
<form enctype="multipart/form-data" action=" " method="post">
<input type="date" name="date3" id="date3" />
<input type="submit" name="Submit" value="Papiertonne" class="btn blue" style="margin-right: 10px" /><input type="submit" name="Submit" value="Papier-Löschen" class="btn red" />
</form>
<br />
<br />
<br />
<table id="table3" class="table table-fixed">
<thead>
<tr>
<th>
Papiermülltonne:
</th>
</tr>
</thead>
<tbody>
<?php
if(isset($content['tonnen']['Papiertonne'])){
$papiertonne = $content['tonnen']['Papiertonne'];
for ($k=0; $k < count($papiertonne); $k++) {
echo "<tr onclick='javascript:table3(this);'>";
echo "<td>$papiertonne[$k]</td>";
echo "</tr>";
}
}else{
$papiertonne = array();
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
if (isset($_POST['Submit'])) {
if($_POST['Submit'] == "Gelbetonne"){
$date1 = $_POST['date1'];
if (!in_array($date1, $gelbetonne) && $date1 !== '') {
array_push($gelbetonne, $date1);
}
json_schreiben($gelbetonne, $papiertonne, $restmuell, $filepath);
reload();
}elseif ($_POST['Submit'] == "Restmülltonne") {
$date2 = $_POST['date2'];
if (!in_array($date2, $restmuell) && $date2 !== '') {
array_push($restmuell, $date2);
}
json_schreiben($gelbetonne, $papiertonne, $restmuell, $filepath);
reload();
}elseif ($_POST['Submit'] == "Papiertonne") {
$date3 = $_POST['date3'];
if (!in_array($date3, $papiertonne) && $date3 !== '') {
array_push($papiertonne, $date3);
}
json_schreiben($gelbetonne, $papiertonne, $restmuell, $filepath);
reload();
}elseif ($_POST['Submit'] == "Gelb-Löschen") {
$date1 = $_POST['date1'];
if (in_array($date1, $gelbetonne) && $date1 !== '') {
$index = array_search($date1, $gelbetonne);
unset($gelbetonne[$index]);
}
json_schreiben($gelbetonne, $papiertonne, $restmuell, $filepath);
reload();
}elseif ($_POST['Submit'] == "Restmüll-Löschen") {
$date2 = $_POST['date2'];
if (in_array($date2, $restmuell) && $date2 !== '') {
$index = array_search($date2, $restmuell);
unset($restmuell[$index]);
}
json_schreiben($gelbetonne, $papiertonne, $restmuell, $filepath);
reload();
}elseif ($_POST['Submit'] == "Papier-Löschen") {
$date3 = $_POST['date3'];
if (in_array($date3, $papiertonne) && $date3 !== '') {
$index = array_search($date3, $papiertonne);
unset($papiertonne[$index]);
}
json_schreiben($gelbetonne, $papiertonne, $restmuell, $filepath);
reload();
}
}
function json_schreiben($gelbetonne, $papiertonne, $restmuell, $filepath){
asort($gelbetonne);
asort($papiertonne);
asort($restmuell);
$gelbetonne2 = array_values($gelbetonne);
$papiertonne2 = array_values($papiertonne);
$restmuell2 = array_values($restmuell);
$tonnen = array('tonnen' => array('Gelbetonne' => $gelbetonne2, 'Papiertonne' => $papiertonne2, 'Restmuelltonne' => $restmuell2));
$json_data = json_encode($tonnen, JSON_PRETTY_PRINT);
file_put_contents($filepath, $json_data);
}
function reload(){
header("Refresh:0");
}
?>
<script>
function table1(e){
var x = e.cells;
var value = x[0].innerHTML;
document.getElementById('date1').value = value;
}
function table2(e){
var x = e.cells;
var value = x[0].innerHTML;
document.getElementById('date2').value = value;
}
function table3(e){
var x = e.cells;
var value = x[0].innerHTML;
document.getElementById('date3').value = value;
}
</script>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Viele Grüße
Ghostrider