From 5434549e5e9841c41a9cb698029a70ce4ccd7f0c Mon Sep 17 00:00:00 2001 From: Banana Date: Sun, 25 Sep 2022 12:53:43 +0200 Subject: [PATCH] current status --- TODO | 1 + documentation/emere.sql | 158 ++++++++++++++++++++++++++++++ webroot/config/config.php.default | 6 ++ webroot/lib/item.class.php | 3 +- webroot/lib/itemInput.class.php | 68 +++++++++++++ webroot/lib/summoner.class.php | 13 ++- webroot/view/_head.php | 2 +- webroot/view/item/item.html | 9 +- webroot/view/item/item.php | 6 +- 9 files changed, 256 insertions(+), 10 deletions(-) create mode 100644 TODO create mode 100644 documentation/emere.sql create mode 100644 webroot/lib/itemInput.class.php diff --git a/TODO b/TODO new file mode 100644 index 0000000..7f4f922 --- /dev/null +++ b/TODO @@ -0,0 +1 @@ +- FE languages like i18n support diff --git a/documentation/emere.sql b/documentation/emere.sql new file mode 100644 index 0000000..3c8614d --- /dev/null +++ b/documentation/emere.sql @@ -0,0 +1,158 @@ +-- phpMyAdmin SQL Dump +-- version 5.2.0 +-- https://www.phpmyadmin.net/ +-- +-- Host: 127.0.0.1 +-- Generation Time: Sep 25, 2022 at 10:53 AM +-- Server version: 8.0.27 +-- PHP Version: 8.1.8 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `emere` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `item` +-- + +CREATE TABLE `item` ( + `id` int NOT NULL, + `fk_receipt` int NOT NULL, + `fk_market` int NOT NULL, + `fk_product` int NOT NULL, + `fk_list` int NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `list` +-- + +CREATE TABLE `list` ( + `id` int NOT NULL, + `name` varchar(64) COLLATE utf8mb4_bin NOT NULL, + `description` varchar(255) COLLATE utf8mb4_bin NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `market` +-- + +CREATE TABLE `market` ( + `id` int NOT NULL, + `name` varchar(128) COLLATE utf8mb4_bin NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `product` +-- + +CREATE TABLE `product` ( + `id` int NOT NULL, + `name` varchar(128) COLLATE utf8mb4_bin NOT NULL, + `manufacturer` varchar(128) COLLATE utf8mb4_bin NOT NULL, + `weight` int NOT NULL, + `itemcount` int NOT NULL, + `price` int NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `receipt` +-- + +CREATE TABLE `receipt` ( + `id` int NOT NULL, + `receiptdate` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `item` +-- +ALTER TABLE `item` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `list` +-- +ALTER TABLE `list` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `market` +-- +ALTER TABLE `market` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `product` +-- +ALTER TABLE `product` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `receipt` +-- +ALTER TABLE `receipt` + ADD PRIMARY KEY (`id`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `item` +-- +ALTER TABLE `item` + MODIFY `id` int NOT NULL AUTO_INCREMENT; + +-- +-- AUTO_INCREMENT for table `list` +-- +ALTER TABLE `list` + MODIFY `id` int NOT NULL AUTO_INCREMENT; + +-- +-- AUTO_INCREMENT for table `market` +-- +ALTER TABLE `market` + MODIFY `id` int NOT NULL AUTO_INCREMENT; + +-- +-- AUTO_INCREMENT for table `product` +-- +ALTER TABLE `product` + MODIFY `id` int NOT NULL AUTO_INCREMENT; + +-- +-- AUTO_INCREMENT for table `receipt` +-- +ALTER TABLE `receipt` + MODIFY `id` int NOT NULL AUTO_INCREMENT; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/webroot/config/config.php.default b/webroot/config/config.php.default index ca79af8..f0247ab 100644 --- a/webroot/config/config.php.default +++ b/webroot/config/config.php.default @@ -25,6 +25,12 @@ const QUERY_DEBUG = true; # timezone settings const TIMEZONE = 'Europe/Berlin'; +# lang settings for number inputs +const NUMBER_INPUT_LANG = "de-DE"; + +# lang setting +const FE_LANG = "en"; + # path settings const PATH_ABSOLUTE = '/home/some/path/emere/'; const PATH_LOGDIRECTORY = PATH_ABSOLUTE . '/log'; diff --git a/webroot/lib/item.class.php b/webroot/lib/item.class.php index fc06771..a71e426 100644 --- a/webroot/lib/item.class.php +++ b/webroot/lib/item.class.php @@ -19,7 +19,8 @@ */ class Item { - /** + + /** * The DB object * * @var mysqli diff --git a/webroot/lib/itemInput.class.php b/webroot/lib/itemInput.class.php new file mode 100644 index 0000000..ea84627 --- /dev/null +++ b/webroot/lib/itemInput.class.php @@ -0,0 +1,68 @@ +. + */ + +/** + * Process the input data from adding or edit an item + */ +class ItemInput { + /** + * The DB object + * + * @var mysqli + */ + private mysqli $_DB; + + /** + * The data for this item + * + * @var array + */ + private array $_data; + + /** + * @param mysqli $databaseConnectionObject + */ + public function __construct(mysqli $databaseConnectionObject) { + $this->_DB = $databaseConnectionObject; + } + + /** + * Check for required fields, valid input and prepare the data + * @param array $data + * @return array + */ + public function validateAndPrepare(array $data): array { + $status = true; + $error = array(); + + + if(!empty($data)) { + if(!isset($data['receiptdate']) || empty($data['receiptdate']) || !Summoner::validate($data['receiptdate'], 'datetime')) { + $status = false; + $error[] = array('receiptdata' => ''); + } + } + + return array( + 'status' => $status, + 'error' => $error + ); + } +} diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php index 3da22f3..4b23730 100644 --- a/webroot/lib/summoner.class.php +++ b/webroot/lib/summoner.class.php @@ -66,7 +66,7 @@ class Summoner { else { return false; } - break; + break; case 'nospace': // text without any whitespace and special chars @@ -102,7 +102,16 @@ class Summoner { $pattern = '/[\p{L}\p{N}\-_]/u'; break; - case 'text': + case 'datetime': + // based on the format eg. 2022-09-25T22:00 + $dt = DateTime::createFromFormat('Y-m-d\TH:i', $input); + if ($dt !== false) { + return(checkdate($dt->format('m'), $dt->format('d'), $dt->format('Y'))); + } + break; + + + case 'text': default: $pattern = '/[\p{L}\p{N}\p{P}\p{S}\p{Z}\p{M}\s]/u'; } diff --git a/webroot/view/_head.php b/webroot/view/_head.php index 6f75334..ee70071 100644 --- a/webroot/view/_head.php +++ b/webroot/view/_head.php @@ -1,5 +1,5 @@ - + <?php echo Summoner::ifset($TemplateData,'pageTitle').' - '; ?>emere diff --git a/webroot/view/item/item.html b/webroot/view/item/item.html index 729a382..986385b 100644 --- a/webroot/view/item/item.html +++ b/webroot/view/item/item.html @@ -1,7 +1,7 @@
- - Receipt Just leave it blank to create a new based on date and market name. + @@ -37,15 +37,16 @@ - - diff --git a/webroot/view/item/item.php b/webroot/view/item/item.php index 930332f..82d64c8 100644 --- a/webroot/view/item/item.php +++ b/webroot/view/item/item.php @@ -1,6 +1,6 @@ validateAndPrepare($fdata); + } else { $TemplateData['message']['content'] = "Collection could not be loaded."; $TemplateData['message']['status'] = "error"; -- 2.39.5