Updated theme handling and got the category form to clone rows.
This commit is contained in:
+76
-8
@@ -1,20 +1,88 @@
|
||||
<?php
|
||||
include("db/category.php");
|
||||
//Use require for all DB interaction code
|
||||
//https://stackoverflow.com/questions/2418473/difference-between-require-include-require-once-and-include-once
|
||||
require "db/item_info.php";
|
||||
|
||||
if($_GET["category_name"] != "")
|
||||
{
|
||||
create_category($_GET["category_name"]);
|
||||
}
|
||||
$base_attributes = get_item_base_attributes();
|
||||
$new = get_item_base_attributes();
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Create New Category</title>
|
||||
<link rel="stylesheet" type="text/css" href="css/main.css">
|
||||
<?php
|
||||
if(isset($_GET["theme"])){
|
||||
switch($_GET["theme"]){
|
||||
case "dark":
|
||||
echo "<link rel='stylesheet' type='text/css' href='css/theme-dark.css'";
|
||||
break;
|
||||
case "medium":
|
||||
echo "<link rel='stylesheet' type='text/css' href='css/theme-medium.css'";
|
||||
break;
|
||||
case "light":
|
||||
echo "<link rel='stylesheet' type='text/css' href='css/theme-light.css'";
|
||||
break;
|
||||
default:
|
||||
echo "<link rel='stylesheet' type='text/css' href='css/theme-medium.css'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
</head>
|
||||
<body >
|
||||
<form action="create_category.php">
|
||||
<label for="category_name">Category Name:</label><input type="text" id="category_name" name="category_name"><br>
|
||||
<button type="submit">Submit</button>
|
||||
<div class="three_column_row">
|
||||
<div class="three_column">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed iaculis ligula tellus, nec interdum purus accumsan ut. Donec dictum urna nec varius porttitor. Integer id sodales felis, sed ultrices tortor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec mattis dignissim tincidunt. Cras sed tellus eu diam vehicula tristique vitae et tortor. Curabitur vulputate a tellus nec lacinia. Nunc fermentum tristique congue. Nunc sit amet lacus in purus fermentum commodo in gravida eros. Suspendisse nulla est, rhoncus quis maximus ac, dignissim et felis. Morbi pellentesque mollis libero, quis laoreet urna. Sed pretium auctor nisi, ut scelerisque orci ullamcorper quis. Suspendisse nulla sapien, efficitur auctor facilisis a, finibus id orci. Nullam ac vehicula dolor. Vivamus vel massa eleifend, consectetur tellus a, tincidunt justo.
|
||||
|
||||
Pellentesque ut magna condimentum, tincidunt erat eget, lacinia quam. Aliquam non lectus a urna hendrerit porttitor. Aliquam iaculis lorem in tellus elementum commodo. In et dapibus purus, a fringilla mi. Cras eu lobortis felis. Mauris rhoncus placerat metus, ut volutpat tellus pharetra ut. Vestibulum ante urna, sollicitudin ut molestie sed, ornare et quam. Etiam sodales ullamcorper ante, sed placerat felis cursus ac. Suspendisse potenti. Etiam porttitor tempus ipsum sed vehicula.
|
||||
</p>
|
||||
</div>
|
||||
<div class="three_column">
|
||||
<form action="create_category.php" style="height:100%; width:100%;" method="post">
|
||||
<label for="category_name">Category Name:</label><input type="text" id="category_name" name="category_name">
|
||||
<fieldset id="field_set">
|
||||
<legend>This is a legend</legend>
|
||||
<div id="form_row">
|
||||
|
||||
<label for="category_details">Category Detail:</label><input type="text" id="category_detail" name="category_detail">
|
||||
<label for="category_details_select">Data Type:</label>
|
||||
<select name="category_details_select">
|
||||
<?php
|
||||
foreach(get_supported_data_types() as $key => $value){
|
||||
echo "<option value='$key'>$value</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<input type="button" id="add_row" name="add_row" value="Add Row" onclick="insertNewRow()" />
|
||||
<button type="submit" id="submit_button">Submit</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<div class="three_column">
|
||||
<h3>Note that the following data will already be included for this item:</h3>
|
||||
<ul>
|
||||
<li>Photos</li>
|
||||
<?php
|
||||
for($i = 1; $i < sizeof($base_attributes); $i++){
|
||||
echo "<li>$base_attributes[$i]</li>";
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
function insertNewRow(){
|
||||
let newRow = document.createElement('div');
|
||||
let form = document.getElementById('field_set');
|
||||
let target = document.getElementById('add_row');
|
||||
|
||||
newRow.appendChild(document.getElementById('form_row').cloneNode(true));
|
||||
form.insertBefore(newRow, target)
|
||||
}
|
||||
|
||||
</script>
|
||||
</html>
|
||||
+14
-6
@@ -1,9 +1,17 @@
|
||||
:root {
|
||||
--main-bg-color: #D3D3D3;
|
||||
--main-font-color: #006400;
|
||||
body {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--main-bg-color);
|
||||
color: var(--main-font-color);
|
||||
.three_column {
|
||||
float: left;
|
||||
width: 33.33%;
|
||||
}
|
||||
|
||||
|
||||
/* Clear floats after the columns */
|
||||
|
||||
.three_column_row:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
:root {
|
||||
--main-bg-color: rgb(0, 0, 0);
|
||||
--main-font-color: #ffffff;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--main-bg-color);
|
||||
color: var(--main-font-color);
|
||||
}
|
||||
|
||||
input {
|
||||
background-color: #aea8a5;
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: var(--main-bg-color);
|
||||
color: var(--main-font-color);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
:root {
|
||||
--main-bg-color: #D3D3D3;
|
||||
--main-font-color: #006400;
|
||||
--main-button-bg: #331832;
|
||||
--main-input-bg: #808A9F;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--main-bg-color);
|
||||
color: var(--main-font-color);
|
||||
}
|
||||
|
||||
input,
|
||||
select {
|
||||
background-color: var(--main-bg-color);
|
||||
color: var(--main-font-color);
|
||||
border: 1px solid var(--main-input-bg);
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: var(--main-bg-color);
|
||||
color: var(--main-font-color);
|
||||
border: 1px solid var(--main-input-bg);
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
form {
|
||||
display: space-evenly;
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
|
||||
function get_category_items()
|
||||
{
|
||||
global $conn;
|
||||
$conn = get_db_connection();
|
||||
$items = mysqli_query($conn, "SELECT * FROM `category`");
|
||||
$conn->close();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
function create_category($name)
|
||||
{
|
||||
global $conn;
|
||||
$conn = get_db_connection();
|
||||
$statement = $conn->prepare("INSERT INTO `category` (category_name) VALUES (?)");
|
||||
$statement->bind_param("s", $name);
|
||||
if($statement->execute() == true){
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
function get_db_connection(){
|
||||
$host = '127.0.0.1:3306';
|
||||
$user_name = 'root';
|
||||
$password = '1a9t7y';
|
||||
@@ -6,4 +7,17 @@
|
||||
|
||||
$conn = mysqli_connect($host, $user_name, $password, $db_name) or die("Failed to
|
||||
connect to MySQL: " . mysqli_error($conn));
|
||||
|
||||
return $conn;
|
||||
}
|
||||
|
||||
function get_supported_data_types(){
|
||||
return [
|
||||
"date" => "Date",
|
||||
"money" => "money",
|
||||
"text" => "Long Description",
|
||||
"varchar" => "Short Text",
|
||||
"integer" => "Count"
|
||||
];
|
||||
}
|
||||
?>
|
||||
+9
-2
@@ -2,13 +2,20 @@
|
||||
require "db.php";
|
||||
|
||||
function get_item_base_attributes(){
|
||||
global $conn;
|
||||
$conn = get_db_connection();
|
||||
$rows = [];
|
||||
$query = "SELECT COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'inventory' AND TABLE_NAME = 'item_info';";
|
||||
$data = mysqli_query($conn, $query);
|
||||
|
||||
while($row = mysqli_fetch_array($data)){
|
||||
$rows[] = str_replace("_", " ", $row["COLUMN_NAME"]);
|
||||
}
|
||||
|
||||
$data->free();
|
||||
$conn->close();
|
||||
|
||||
return $data;
|
||||
return $rows;
|
||||
}
|
||||
?>
|
||||
@@ -5,13 +5,31 @@
|
||||
|
||||
$categories = get_item_base_attributes();
|
||||
foreach($categories as $cat){
|
||||
echo $cat["COLUMN_NAME"];
|
||||
echo $cat;
|
||||
}
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="css/main.css">
|
||||
<?php
|
||||
if(isset($_GET["theme"])){
|
||||
switch($_GET["theme"]){
|
||||
case "dark":
|
||||
echo "<link rel='stylesheet' type='text/css' href='css/theme-dark.css'";
|
||||
break;
|
||||
case "medium":
|
||||
echo "<link rel='stylesheet' type='text/css' href='css/theme-medium.css'";
|
||||
break;
|
||||
case "light":
|
||||
echo "<link rel='stylesheet' type='text/css' href='css/theme-light.css'";
|
||||
break;
|
||||
default:
|
||||
echo "<link rel='stylesheet' type='text/css' href='css/theme-medium.css'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user