icons and database-connection-start

master
Eirik Th S 2021-04-02 13:56:24 +02:00
parent e9ccf620ca
commit 7b2f16828b
6 changed files with 130 additions and 6 deletions

4
icons/pencil-square.svg Normal file
View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
<path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
<path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
</svg>

After

Width:  |  Height:  |  Size: 578 B

4
icons/plus-circle.svg Normal file
View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"/>
</svg>

After

Width:  |  Height:  |  Size: 336 B

61
plan/do.php Normal file
View File

@ -0,0 +1,61 @@
<?php
require '../webdata/init.php';
$db = database();
$user_id = 1;
header("Content-Type: application/json");
$data = [];
$returns = [];
if(!empty($_GET)){
$data = $_GET;
}
elseif(!empty($_POST)){
$data = $_POST;
}
if(!empty($data) && isset($user_id)){
if(isset($data['plan'])){
$sql = "SELECT * FROM plan_store WHERE `user_id` = '$user_id'";
$result = $db->query($sql);
while($stores = $result->fetch_assoc()){
if($result2 = $db->query("SELECT * FROM plan_store_item WHERE `plan_store_id` = '$stores[plan_store_id]'")){
$stores['items'] = [];
if($result2->num_rows > 0){
$stores['items'] = $result2->fetch_all(MYSQLI_ASSOC);
}
}
else {
returns($db->error,1);
}
$returns[] = $stores;
}
returns($returns);
}
}
else {
returns("Nothing to do", 404);
}
function returns($content, $code = 0){
if($code != 0){
$returns['status'] = $code;
$returns['message'] = $content;
}
else {
$returns['data'] = $content;
}
echo json_encode($returns);
die();
}
?>

View File

@ -1,10 +1,10 @@
/*jshint sub:true, esversion: 6, -W083 */
class Store {
constructor() {
constructor(title) {
this.items = [];
let title = "Store "+($(".store").length+1);
title = title || "Store "+($(".store").length+1);
let html = "";
@ -37,6 +37,7 @@ class Store {
$(this).find('.newItemName').val("").focus();
}
});
}
addItem(text, price){
@ -84,7 +85,7 @@ class Store {
this.selector.find(".emptyList").show();
}
// BIND REMOVES
// BIND remove-buttons
$(this.selector).find(".remItem").unbind().each((key, val) => {
let that = this;
$(val).click(function(){ that.remItem(key); });

View File

@ -3,8 +3,13 @@ ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'connection.php';
if($db->connect_error){
die("Connection failed: " . $blogdb->connect_error);
function database(){
require 'connection.php';
if($db->connect_error){
die("Connection failed: " . $blogdb->connect_error);
}
return $db;
}

View File

@ -1 +1,50 @@
<?php
// CREATE USER IN DATABASE
// CREATE TABLES
$sql = "CREATE OR REPLACE TABLE `user` (
`user_id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`md5_id` VARCHAR(200),
`full_name` TINYTEXT,
`user_name` VARCHAR(200) NOT NULL,
`user_email` VARCHAR(220) NOT NULL,
`user_level` TINYINT(4) NOT NULL DEFAULT 1,
`pwd` VARCHAR(220),
`date` DATE NOT NULL DEFAULT(CURRENT_DATE),
`user_ip` VARCHAR(200),
`ckey` VARCHAR(220),
`ctime` VARCHAR(220),
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_PK` (`user_email`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
INSERT INTO `user` (full_name, user_name, user_email, user_level, pwd)
VALUES ('Admin', 'admin', 'admin@svagard.no', 5, 'cb4f8b8b16b0c41d1ece858548340b40dfe6c7fd7fad1ecce');
CREATE OR REPLACE TABLE plan_store (
plan_store_id INT auto_increment,
`user_id` BIGINT(20) NOT NULL,
`name` varchar(100) NOT NULL,
created DATETIME DEFAULT CURRENT_DATE NOT NULL,
updated DATETIME NULL,
PRIMARY KEY (plan_store_id),
CONSTRAINT plan_store_user_FK FOREIGN KEY (`user_id`) REFERENCES `user`(`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
INSERT INTO plan_store (user_id, name)
VALUES (1, 'Store 1');
CREATE OR REPLACE TABLE plan_store_item (
plan_item_id INT auto_increment NOT NULL,
plan_store_id INT NOT NULL,
`name` varchar(200) NOT NULL,
price decimal(8,2) NOT NULL,
PRIMARY KEY (plan_item_id),
CONSTRAINT plan_store_item_FK FOREIGN KEY (plan_store_id) REFERENCES `plan_store`(`plan_store_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
INSERT INTO plan_store_item (plan_store_id, name, price)
VALUES (1, 'Kake', 49.90),
(1, 'Kaffe', 24.90);
";