Skip to content

Instantly share code, notes, and snippets.

@buesing
Last active December 15, 2015 22:19
Show Gist options
  • Save buesing/5332641 to your computer and use it in GitHub Desktop.
Save buesing/5332641 to your computer and use it in GitHub Desktop.
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<?php
session_start();
error_reporting(E_ALL | E_STRICT);
ini_set("display_errors", 1);
$pass = "abc";
$keys = array("name","date","event","location","address","description","link","linkname");
if (isset($_POST["sub"])) {
if ($_POST["pwd"] == $pass) {
$_SESSION['logged_in'] = true;
} else {
echo ("login attempt failed. try again?");
echo ("<form method=\"POST\" action=\"edit.php\">");
echo ("<input type=\"password\" name=\"pwd\" placeholder=\"login\">");
echo ("<input type=\"submit\" name=\"sub\" value=\"submit\">");
echo ("</form>");
}
}
if ($_SESSION['logged_in']) {
if (isset($_POST['edit'])) {
$file = file_get_contents('data/concerts.json');
$jsonConcerts = json_decode($file, true);
$counter = 0;
if ($jsonConcerts) {
echo("<form method=\"POST\" action=\"edit.php\">");
foreach ($jsonConcerts as $show) {
echo((string)($counter+1));
echo ("<input value=\"".$counter."\" type=\"radio\" name=\"number\">");
echo ($show['date'].", ".$show['name']);
echo "<br>\n";
echo "<hr>\n";
$counter++;
}
echo("<input value=\"edit\" type=\"submit\" name=\"editconfirm\">");
echo("</form>");
} else {
echo "error reading json file";
}
} elseif (isset($_POST['add'])) {
echo("<form method=\"POST\" action=\"edit.php\">");
foreach ($keys as $key) {
echo ($key.": <input name=\"".$key."\" value=\"\"><br>\n");
}
echo("<br><input value=\"save\" type=\"submit\" name=\"addsave\">");
echo("</form>");
} elseif (isset($_POST['editconfirm'])) {
$counter = (int)$_POST['number'];
$file = file_get_contents('data/concerts.json');
$jsonConcerts = json_decode($file, true);
if ($jsonConcerts) {
echo "<form method=\"POST\" action=\"edit.php\"";
//var_dump($keys);
foreach ($keys as $key_show) {
echo ($key_show. ": ");
//echo "<input class=\"wide\" name=\"".$key.
//"\" value=\"".$jsonConcerts[$counter][$key]."\"><br>\n";
}
echo("<input value=\"".$counter."\" type=\"hidden\" name=\"count\">");
echo "<input value=\"save\" type=\"submit\" name=\"editsave\">";
echo "<form>";
} else {
echo "error reading json file";
}
} elseif (isset($_POST['editsave'])) {
$counter = (int)$_POST['count'];
$file = file_get_contents('data/concerts.json');
$jsonConcerts = json_decode($file, true);
if ($jsonConcerts) {
foreach ($keys as $key) {
$jsonConcerts[$counter][$key] = $_POST[$key];
}
echo "<pre>";
var_dump($jsonConcerts);
echo "</pre";
} else {
echo "error reading json file";
}
} elseif (isset($_POST['addsave'])) {
} else {
echo("<form method=\"POST\" action=\"edit.php\">");
echo("<input value=\"edit existing shows\" type=\"submit\" name=\"edit\">");
echo("<br><br>\n");
echo("<input value=\"add new show\" type=\"submit\" name=\"add\">");
echo("</form>");
}
} else {
?>
<form method="POST" action="edit.php">
<input type="password" name="pwd" placeholder="login">
<input type="submit" name="sub" value="submit">
</form>
<?php
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment