From 7a08e7ed51d580d4771aff50b3197cb8e9e1081b Mon Sep 17 00:00:00 2001 From: joelsalisbury Date: Mon, 4 Dec 2023 15:45:32 -0500 Subject: [PATCH] now can CRUD all the things. --- db.sqlite | Bin 28672 -> 28672 bytes public/functions.php | 37 ++++++++++++++++++++++++++++++ public/index.php | 7 +++++- public/pages/home.php | 52 +++++++++++++++++++++++++++++++----------- seed.php | 18 +++++++++++---- 5 files changed, 96 insertions(+), 18 deletions(-) diff --git a/db.sqlite b/db.sqlite index 7e992845811bf1870891ab21563e536ba06ffaf4..435e0399a62d232201fcb16669c80bd6b9cd610c 100644 GIT binary patch delta 1033 zcmZp8z}WDBae}m9A_D^hI}pQw&_o?$$wUUd-~?Wv5F6J92EM0!;=GkS_qkVcZP+X* zV8O-JSjNUKZfwlhEIhe^OPi5t@)|DJ$p+jyEXApLDU+kQI~mzGKjju?WMrHClV>&~ z>*T4tOBq=vTk{=eWZwLrkDXEMG6Vl*u(fPJOISe`0Wte#L51!7y4sAa44lTsMg~U4 zx`u|j#s&%o23BAM5i-&>Fi|ivure~VGBn*Ju!G+tz}T?L-ypoqBrKvRxT4r8q%tDI zwA4M+BQ@VIusp@XEUnTnInX<`q}<=rv)D4zr6jx-gz9;)ICzN*N2|NDv}bLIS`kYk4j6gzId3c=;6sU-@|`9*oye4F7Xi)==}p8_&> zryp`yC~>ebC>uK$CFUii78PY;^{zBK3xlXJF5A@nRgu#ID<~~E=OpH03)soU{z}Mh vneQ*EiHH|jU^NnHlL-~?Wv5F1w+1K(3Vao$Rv``jzJ$~HFs z88@>jY~uIu$%t|;N~+NJG>`HqPIb!4ax_UP zFD)uc40J6nNip{dt<*~kFv!iwb~VY4bWC?D^bE=JHZm|W)-^QJH84~#G`BJ|ure{* zWZ*2%1>+igPxrI0M#6i~#?3D-NhI$EC}&NDHWW?}H1+!!r3`FykplBUUTqt%ePvN5XK z2wn0LEDW;7!TFU*sfl^T*xZ{NqvVaGUJRr@AipHBBtI3KdO1-R25IAf)WqZrtn!m@ z#i%1YhdWjSnQI%1;@I3+6vgvU6<>%|Mb`U2Ruq{l7bk@rJ3OG+ar0FOE>BG@QE<*L z%ERW{j5t|jGy3BckhweKki$ZWgM~ra*tsY%FDbRCC=;u9rP)~+M2&ITrWUV?oEBI? zX~8)sF&A6FPA-mDLUzmicu`G6yvPF6k)*L>K|u~yXH32uFNvgiQ$i0vQbL-VuZP4t NldpwPYP!fk002+L=|cbj diff --git a/public/functions.php b/public/functions.php index cfb2c1b..c207a3f 100644 --- a/public/functions.php +++ b/public/functions.php @@ -93,6 +93,16 @@ function do_layout($file) { require_once 'layouts/footer.php'; } +function get_all_users() { + global $db; + $results = $db->query('SELECT * FROM users'); + $users = []; + while ($row = $results->fetchArray()) { + $users[] = $row; + } + return $users; +} + function get_all_crops() { global $db; $results = $db->query('SELECT * FROM crops'); @@ -127,6 +137,13 @@ function get_crop_name($id) { return $row['crop']; } +function get_deadline($id) { + global $db; + $results = $db->query('SELECT * FROM crops_states_deadlines WHERE id = ' . $id); + $row = $results->fetchArray(); + return $row; +} + function get_all_deadlines() { global $db; $results = $db->query('SELECT * FROM crops_states_deadlines'); @@ -139,6 +156,26 @@ function get_all_deadlines() { return $deadlines; } +function get_all_reminders() { + global $db; + $sql = 'SELECT * FROM deadlines_reminders'; + // left join on deadlines table and crop and state so we can have the name of the deadline, crop, and state + $sql = 'SELECT deadlines_reminders.id, deadlines_reminders.deadline_id, deadlines_reminders.reminder_send_time, crops_states_deadlines.deadline_name, crops_states_deadlines.deadline, crops_states_deadlines.state_id, crops_states_deadlines.crop_id, states.state, crops.crop FROM deadlines_reminders LEFT JOIN crops_states_deadlines ON deadlines_reminders.deadline_id = crops_states_deadlines.id LEFT JOIN states ON crops_states_deadlines.state_id = states.id LEFT JOIN crops ON crops_states_deadlines.crop_id = crops.id'; + $results = $db->query($sql); + $reminders = []; + while ($row = $results->fetchArray()) { + $row['deadline_id'] = get_deadline($row['deadline_id'])['deadline_name']; + $row['reminder_send_time'] = $row['reminder_send_time']; + $row['deadline_name'] = $row['deadline_name']; + $row['deadline'] = $row['deadline']; + $row['state'] = $row['state']; + + + $reminders[] = $row; + } + return $reminders; +} + function get_logged_in_user() { global $db; $user_id = $_SESSION['user_id']; diff --git a/public/index.php b/public/index.php index d461628..2fb4b5c 100644 --- a/public/index.php +++ b/public/index.php @@ -27,6 +27,11 @@ default: // set http response code to 404 http_response_code(404); - echo '404'; + + // the route attempted was: $_SERVER['REQUEST_URI'] and it was not found + + // show the 404 page + echo "404. " . $_SERVER['REQUEST_URI'] . " not found"; + break; } \ No newline at end of file diff --git a/public/pages/home.php b/public/pages/home.php index 6627c29..03b6424 100644 --- a/public/pages/home.php +++ b/public/pages/home.php @@ -7,11 +7,11 @@

-

-
+
-
-
- - - -
-
@@ -94,7 +87,9 @@ foreach ($states as $state) { echo ''; echo '' . $state['state'] . ''; - echo '[ x ]'; + echo ''; + echo 'Delete'; + echo ''; echo ''; } ?> @@ -171,12 +166,43 @@ } ?> - - -
+ +
+

+ +

+
+
+ + + + + + + + + + + '; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + ?> + +
First NameLast NameEmail AddressActions
' . $user['firstname'] . '' . $user['lastname'] . '' . $user['email'] . 'Delete
+
+
\ No newline at end of file diff --git a/seed.php b/seed.php index 819b51e..ab5fde6 100644 --- a/seed.php +++ b/seed.php @@ -60,10 +60,8 @@ /** create deadlines_reminders table */ $db->exec('CREATE TABLE IF NOT EXISTS deadlines_reminders ( id INTEGER PRIMARY KEY, - crop_id INTEGER NOT NULL, - state_id INTEGER NOT NULL, deadline_id INTEGER NOT NULL, - reminder_time DATETIME NOT NULL, + reminder_send_time DATETIME NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP )'); @@ -121,4 +119,16 @@ $db->exec('INSERT INTO crops_states_deadlines (crop_id, state_id, deadline_name, deadline) VALUES (1, 1, "sales_closing", "2023-12-01")'); $db->exec('INSERT INTO crops_states_deadlines (crop_id, state_id, deadline_name, deadline) VALUES (1, 1, "acreage_reporting", "2023-12-01")'); -$db->exec('INSERT INTO crops_states_deadlines (crop_id, state_id, deadline_name, deadline) VALUES (1, 1, "production_reporting", "2023-12-01")'); \ No newline at end of file +$db->exec('INSERT INTO crops_states_deadlines (crop_id, state_id, deadline_name, deadline) VALUES (1, 1, "production_reporting", "2023-12-01")'); + +/** create a reminder for deadline #1, scheduled for 1 day earlier than the deadline value, calculated from the deadline value */ +/** get deadline #1 */ +$results = $db->query('SELECT * FROM crops_states_deadlines WHERE id = 1'); +$deadline = $results->fetchArray(); + +$reminder_send_time = date('Y-m-d H:i:s', strtotime($deadline['deadline'] . ' - 1 day')); + +/** insert reminder */ +$db->exec('INSERT INTO deadlines_reminders (deadline_id, reminder_send_time) VALUES (1, "' . $reminder_send_time . '")'); + +