AECC database project.

feat: First snapshot 2025-05-16T14:47:17+00:00.

+554
+36
api/v1/create/index.php
··· 1 + <?php 2 + print header('Content-Type: application/json'); 3 + include("lib/header.php"); 4 + 5 + if (isset($_POST["type"])) { 6 + $type = validate_input($_POST["type"]); 7 + print match ($type) { 8 + "product" => product(), 9 + default => json_encode(err_msg(2)) 10 + }; 11 + } else { 12 + print json_encode(err_msg(1)); 13 + } 14 + 15 + function product() { 16 + include("lib/db.php"); 17 + 18 + $stmt = $db -> prepare("INSERT INTO product (cents, description) VALUES (?, ?);"); 19 + $stmt -> bind_param("is", $cents, $description); 20 + $cents = validate_input($_POST["cents"]); 21 + $description = validate_input($_POST["description"]); 22 + 23 + $out = ""; 24 + if ($stmt -> execute()) { 25 + $out .= json_encode(array("msg" => "Succesfully inserted", "result" => "ok")); 26 + } else { 27 + $out .= json_encode(array("msg" => "Error inserting product into database", "result" => "err")); 28 + } 29 + 30 + $db -> close(); 31 + return $out; 32 + } 33 + 34 + function transaction() { 35 + } 36 + ?>
+43
api/v1/read/index.php
··· 1 + <?php 2 + print header('Content-Type: application/json'); 3 + 4 + include("lib/header.php"); 5 + 6 + if (isset($_GET["type"])) { 7 + $type = validate_input($_GET["type"]); 8 + print match($type) { 9 + "product" => product(), 10 + default => json_encode(err_msg(3)) 11 + }; 12 + } else { 13 + print json_encode(err_msg(2)); 14 + } 15 + 16 + function product() { 17 + include("lib/db.php"); 18 + 19 + if (isset($_GET["id"])) { 20 + $stmt = $db -> prepare("SELECT * FROM product WHERE p_id = ?;"); 21 + $stmt -> bind_param("i", $id); 22 + $id = validate_input(isset($_GET["id"]) ? $_GET["id"] : ""); 23 + $stmt -> execute(); 24 + } else { 25 + $stmt = $db -> prepare("SELECT * FROM product WHERE MATCH (description) AGAINST (? WITH QUERY EXPANSION) or ? = \"\";"); 26 + $stmt -> bind_param("ss", $q, $q); 27 + $q = validate_input(isset($_GET["q"]) ? $_GET["q"] : ""); 28 + $stmt -> execute(); 29 + } 30 + 31 + 32 + $out = json_encode($stmt -> get_result() -> fetch_all()); 33 + 34 + $db->close(); 35 + return $out; 36 + } 37 + 38 + function transaction() { 39 + $out = ""; 40 + 41 + return $out; 42 + } 43 + ?>
+46
api/v1/update/index.php
··· 1 + 2 + <!DOCTYPE html> 3 + <html> 4 + <head> 5 + <link rel="stylesheet" href="/~diego.estrada1/main.css"> 6 + <meta charset="UTF-8"> 7 + </head> 8 + <body> 9 + <?php 10 + include("lib/header.php"); 11 + 12 + if (isset($_GET["type"])) { 13 + $type = validate_input($_GET["type"]); 14 + print match ($type) { 15 + "product" => product(), 16 + default => err_msg(2) 17 + }; 18 + } else { 19 + print err_msg(1); 20 + } 21 + 22 + function product() { 23 + include("lib/db.php"); 24 + $out = ""; 25 + if (isset($_GET["id"])) { 26 + $stmt = $db -> prepare("SELECT * FROM product WHERE p_id = ?;"); 27 + $stmt -> bind_param("i", $id); 28 + $id = validate_input($_GET["id"]); 29 + $stmt -> execute(); 30 + $result = $stmt -> get_result(); 31 + $row = $result -> fetch_assoc(); 32 + 33 + $out .= t("h2", "You are editing the following product:"); 34 + $out .= "ID: " . strval($id) . "<br />"; 35 + $out .= "Cents: " . strval($row["cents"]) . "<br />"; 36 + $out .= "Description: " . $row["description"] . "<br />"; 37 + } else { 38 + $out = err_msg(3); 39 + } 40 + $db->close(); 41 + 42 + return $out; 43 + } 44 + ?> 45 + </body> 46 + </html>
+103
index.php
··· 1 + <!DOCTYPE html> 2 + <html> 3 + <head> 4 + <meta charset="UTF-8"> 5 + </head> 6 + <body> 7 + <div id="main"> 8 + <h1> 9 + Welcome to AECC DB! 10 + </h1> 11 + 12 + What would you like to work with? 13 + <br /> 14 + <div id="buttons" style="width:120ch;"> 15 + <button onclick="activity()">Activities</button> 16 + <button onclick="activity_transaction()">Activity Transactions</button> 17 + <button onclick="board_member()">Board Members</button> 18 + <button onclick="member()">Members</button> 19 + <button onclick="product()">Products</button> 20 + <button onclick="transaction()">Transactions</button> 21 + </div> 22 + </div> 23 + 24 + <footer> 25 + <div style="height:50px"></div> 26 + <button onclick="restart()">Restart?</button> 27 + </footer> 28 + </body> 29 + <script src="lib/header.js"></script> 30 + <script src="lib/activity.js"></script> 31 + <script src="lib/activity_transaction.js"></script> 32 + <script src="lib/board_member.js"></script> 33 + <script src="lib/member.js"></script> 34 + <script src="lib/product.js"></script> 35 + <script src="lib/transaction.js"></script> 36 + <script> 37 + function restart() { 38 + const content = ` 39 + <div id="main"> 40 + <h1> 41 + Welcome to AECC DB! 42 + </h1> 43 + 44 + What would you like to work with? 45 + <br /> 46 + <div id="buttons"> 47 + <button onclick="activity()">Activity</button> 48 + <button onclick="activity_transaction()">Activity Transaction</button> 49 + <button onclick="board_member()">Board Member</button> 50 + <button onclick="member()">Member</button> 51 + <button onclick="product()">Product</button> 52 + <button onclick="transaction()">Transaction</button> 53 + </div> 54 + </div> 55 + `; 56 + const BODY = document.getElementById("main"); 57 + BODY.innerHTML = content; 58 + } 59 + 60 + function table_filter() { 61 + var filter = document.getElementById("tableFilter") 62 + .value 63 + .toUpperCase(); 64 + 65 + var trs = document.getElementById("resultsTable") 66 + .getElementsByTagName("tr"); 67 + 68 + for (var i = 1; i < trs.length; i++) { 69 + trs[i].style.display = "none"; 70 + tds = trs[i].getElementsByTagName("td"); 71 + for (var j = 0; j < tds.length; j++) { 72 + td = tds[j]; 73 + if (td) { 74 + td_text = td.textContent || td.innerText; 75 + if (td_text.toUpperCase().indexOf(filter) > -1) { 76 + trs[i].style.display = ""; 77 + } 78 + } 79 + } 80 + } 81 + } 82 + </script> 83 + <style> 84 + .input-box { 85 + display: flex; 86 + align-items: center; 87 + border: 2px solid; 88 + } 89 + 90 + .input-box input { 91 + border: none; 92 + outline: none; 93 + } 94 + 95 + .input-box:focus-within, input:focus-within { 96 + border-color: #4f7df3; 97 + } 98 + </style> 99 + <?php 100 + include("lib/header.php"); 101 + main_css(); 102 + ?> 103 + </html>
+1
lib/activity.js
··· 1 + function activity() {}
+1
lib/activity_transaction.js
··· 1 + function activity_transaction() {}
+1
lib/board_member.js
··· 1 + function board_member() {}
lib/buttons.js

This is a binary file and will not be displayed.

+15
lib/header.js
··· 1 + function ti(tag, inside, content) { 2 + return "<" + tag + " " + inside + ">" + content + "</" + tag + ">"; 3 + } 4 + function t(tag, content) { 5 + return "<" + tag + ">" + content + "</" + tag + ">"; 6 + } 7 + function input_any(label, label_str, input_type) { 8 + return ti("label", 'for="' + label + '"', label_str) 9 + + "<br />" 10 + + ti("input", 'input_type="' + input_type + '" id="' + label + '" name="' + label + '"', '') 11 + + "<br />"; 12 + } 13 + function input_submit() { 14 + return '<input type="submit" value="Submit" />'; 15 + }
+78
lib/header.php
··· 1 + <?php 2 + function main_css() { 3 + $out = "<style>"; 4 + foreach (file("/home/users/diego.estrada1/public_html/main.css") as $row) { 5 + $out .= $row; 6 + } 7 + $out .= "</style>"; 8 + print $out; 9 + } 10 + 11 + function validate_input($data) { 12 + include("db.php"); 13 + $data = trim($data); 14 + $data = stripslashes($data); 15 + $data = htmlspecialchars($data); 16 + $data = mysqli_real_escape_string($db, $data); 17 + return $data; 18 + } 19 + 20 + function err_msg($err_code) { 21 + $msg = "What are you doing bruh "; 22 + while ($err_code != 0) { 23 + $err_code -= 1; 24 + $msg = $msg . "?"; 25 + } 26 + return $msg; 27 + } 28 + 29 + function input_submit() { 30 + return '<input type="submit" value="Submit" />'; 31 + } 32 + 33 + function input_radio_many($strs, $name, $label_str) { 34 + $out = ""; 35 + $out = $out . '<label for="' . $name . '">' . $label_str . '</label>'; 36 + $out = $out . '<br />'; 37 + foreach ($strs as $str) { 38 + $out = $out . '<input name="' . $name . '" type="radio" id="' . $str . '" value="' . $str . '">'; 39 + $out = $out . '<label for="' . $str . '">'; 40 + $out = $out . $str; 41 + $out = $out . '</label>'; 42 + $out = $out . '</input>'; 43 + $out = $out . '<br />'; 44 + } 45 + 46 + return $out; 47 + } 48 + 49 + function input_any($label, $label_str, $type) { 50 + $out = ""; 51 + $out = $out . '<label for="' . $label . '">' . $label_str . '</label>'; 52 + $out = $out . '<br />'; 53 + $out = $out . '<input type="' . $type . '" id="' . $label . '" name="' . $label . '" />'; 54 + $out = $out . '<br />'; 55 + return $out; 56 + } 57 + 58 + function input_any_value($label, $label_str, $value, $type) { 59 + $out = ""; 60 + $out = $out . '<label for="' . $label . '">' . $label_str . '</label>'; 61 + $out = $out . '<br />'; 62 + $out = $out . '<input type="' . $type . '" id="' . $label . '" name="' . $label . '" value="' . $value . '" />'; 63 + $out = $out . '<br />'; 64 + return $out; 65 + } 66 + 67 + function da_append($left, $right) { 68 + return $left . $right; 69 + } 70 + 71 + function t($tag, $content) { 72 + return "<" . $tag . ">" . $content . "</" . $tag . ">"; 73 + } 74 + 75 + function ti($tag, $inside, $content) { 76 + return "<" . $tag . " " . $inside . ">" . $content . "</" . $tag . ">"; 77 + } 78 + ?>
lib/lib.js

This is a binary file and will not be displayed.

+1
lib/member.js
··· 1 + function member() {}
+147
lib/product.js
··· 1 + function product() { 2 + const BUTTONS = document.getElementById("buttons"); 3 + BUTTONS.innerHTML = "Products are " + 4 + t("b", "AWESOME") + 5 + "<br />" + 6 + "What would you like to do?" + 7 + "<br />" + 8 + t("div", 9 + ti("button", 'onclick="create_product()"', "Create a product") + 10 + "\n" + 11 + ti("button", 'onclick="find_product()"', "Find a product") + 12 + "\n" + 13 + ti("button", 'onclick="edit_product()"', "Edit a product") + 14 + "\n" + 15 + ti("button", 'onclick="delete_product()"', "Delete a product") 16 + ) 17 + ; 18 + } 19 + 20 + function create_product() { 21 + const BUTTONS = document.getElementById("buttons"); 22 + BUTTONS.innerHTML = "So you want to create a product...<br />" + 23 + ti("form", "action=create.php", 24 + ti("label", 'for="cents"', "Cost (in cents):") + 25 + "<br />" + 26 + ti("div", 'class="input-box"', 27 + t("span", "&nbsp;¢") + 28 + ti("input", 'type="number" id="cents" name="cents"', "") 29 + ) + 30 + "<br />" + 31 + input_any("description", "Description:", "text") + 32 + "<br />" + 33 + input_submit() + 34 + '<input type="hidden" name="type" value="product" />' 35 + ); 36 + } 37 + 38 + async function find_product() { 39 + const PARAMS = new URLSearchParams(); 40 + PARAMS.append("type", "product") 41 + const URL = "https://ada.uprrp.edu/~diego.estrada1/CCOM/4027/db/read.php?" + PARAMS; 42 + const BUTTONS = document.getElementById("buttons"); 43 + BUTTONS.innerHTML = '<h1>Here is the list of products:</h1>' + 44 + '<label for="tableFilter">Filter the results:</label>' + 45 + '<input type="search" id="tableFilter" onkeyup="table_filter()" placeholder="filter...">' + 46 + '<table id="resultsTable"></table>'; 47 + 48 + try { 49 + fetch(URL).then(response => response.json()) 50 + .then(json => { 51 + const TABLE = document.getElementById("resultsTable"); 52 + TABLE.innerHTML = t("tr", 53 + t("th", "ID") + 54 + ti("th", 'style="width:10ch"', "\$USD") + 55 + ti("th", 'style="width:80ch;"', "Description") 56 + ); 57 + 58 + for (var i = 0; i < json.length; i++) { 59 + const obj = json[i]; 60 + const id = obj[0]; 61 + const cents = obj[1]; 62 + const description = obj[2]; 63 + const cost = (cents / 100.00).toFixed(2); 64 + TABLE.innerHTML += t("tr", 65 + t("td", id) + 66 + t("td", "$" + cost) + 67 + t("td", description) 68 + ); 69 + } 70 + }); 71 + } catch (error) { 72 + console.error(error.message); 73 + } 74 + } 75 + 76 + function edit_product() { 77 + var buttons = document.getElementById("buttons"); 78 + buttons.innerHTML = "First, select a product.<br />" + 79 + ti("select", 'id="productSelector" onclick="editing_product()" name="id"', "") + 80 + ti("div", 'id="productResultEditor"', ""); 81 + 82 + const PARAMS = new URLSearchParams(); 83 + PARAMS.append("type", "product") 84 + const URL = "https://ada.uprrp.edu/~diego.estrada1/CCOM/4027/db/read.php?" + PARAMS; 85 + 86 + try { 87 + fetch(URL).then(response => response.json()) 88 + .then(json => { 89 + const SELECTOR = document.getElementById("productSelector"); 90 + for (var i = 0; i < json.length; i++) { 91 + const obj = json[i]; 92 + const id = obj[0]; 93 + const cents = obj[1]; 94 + const description = obj[2]; 95 + const ret = JSON.stringify(obj); 96 + SELECTOR.innerHTML += ti("option", "", `${description} (${id})`); 97 + SELECTOR[i].setAttribute("the-json", ret); 98 + } 99 + }); 100 + } catch (error) { 101 + console.error(error.message); 102 + } 103 + } 104 + 105 + function editing_product() { 106 + const FORM = document.getElementById("productSelector"); 107 + const index = FORM.options.selectedIndex; 108 + const obj = JSON.parse(FORM[index].getAttribute("the-json")); 109 + const id = obj[0]; 110 + const cents = obj[1]; 111 + const description = obj[2]; 112 + const PARAMS = new URLSearchParams(); 113 + PARAMS.append("type", "product"); 114 + PARAMS.append("id", ""+id); 115 + const URL = "https://ada.uprrp.edu/~diego.estrada1/CCOM/4027/db/read.php?" + PARAMS; 116 + 117 + try { 118 + fetch(URL).then(response => response.json()) 119 + .then(json => { 120 + const EDITOR = document.getElementById("productResultEditor"); 121 + EDITOR.innerHTML = t("h2", "Change from:") + 122 + `id = ${id};` + 123 + "<br />" + 124 + `cents = ${cents};` + 125 + "<br />" + 126 + `description = ${description};` + 127 + "<br />" + 128 + t("h2", "To:") + 129 + ti("form", "action=update.php", 130 + ti("label", 'for="cents"', "Cost (in cents):") + 131 + ti("div", 'class="input-box"', 132 + t("span", "&nbsp;¢") + 133 + ti("input", 'type="number" id="cents" name="cents"', "") 134 + ) + 135 + "<br />" + 136 + input_any("description", "Description:", "text") + 137 + "<br />" + 138 + input_submit() + 139 + '<input type="hidden" name="type" value="product" />' 140 + ); 141 + }) 142 + ; 143 + } catch (error) { 144 + console.error(error.message); 145 + } 146 + } 147 +
+9
lib/sql/activity.sql
··· 1 + CREATE TABLE IF NOT EXISTS activity ( 2 + a_id INT NOT NULL AUTO_INCREMENT, 3 + title VARCHAR(80) NOT NULL, 4 + description VARCHAR(80) NOT NULL, 5 + date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, 6 + 7 + PRIMARY KEY (a_id), 8 + FULLTEXT (title, description) 9 + );
+8
lib/sql/activity_transaction.sql
··· 1 + CREATE TABLE IF NOT EXISTS activity_transaction ( 2 + a_id INT NOT NULL, 3 + t_id INT NOT NULL, 4 + 5 + PRIMARY KEY (a_id, t_id), 6 + FOREIGN KEY (a_id) REFERENCES activity(a_id) ON DELETE CASCADE, 7 + FOREIGN KEY (t_id) REFERENCES transaction(t_id) ON DELETE CASCADE 8 + );
+10
lib/sql/board_member.sql
··· 1 + CREATE TABLE IF NOT EXISTS board_member ( 2 + m_id VARCHAR(9) NOT NULL, 3 + position VARCHAR(20) NOT NULL, 4 + year NUMERIC(4,0) CHECK (year > 1701 AND year < 2100) NOT NULL, 5 + role ENUM("Write", "Read", "None") NOT NULL, 6 + password BINARY(64) NOT NULL, 7 + 8 + PRIMARY KEY (m_id), 9 + FOREIGN KEY (m_id) REFERENCES member(m_id) ON DELETE CASCADE 10 + );
+8
lib/sql/initiator.sql
··· 1 + CREATE TABLE IF NOT EXISTS initiator ( 2 + m_id VARCHAR(9) NOT NULL, 3 + t_id INT NOT NULL, 4 + 5 + FOREIGN KEY (m_id) REFERENCES member(m_id) ON DELETE CASCADE, 6 + FOREIGN KEY (t_id) REFERENCES transaction(t_id) ON DELETE CASCADE, 7 + PRIMARY KEY (m_id, t_id) 8 + );
+8
lib/sql/logger.sql
··· 1 + CREATE TABLE IF NOT EXISTS logger ( 2 + m_id VARCHAR(9) NOT NULL, 3 + t_id INT NOT NULL, 4 + 5 + FOREIGN KEY (m_id) REFERENCES member(m_id) ON DELETE CASCADE, 6 + FOREIGN KEY (t_id) REFERENCES transaction(t_id) ON DELETE CASCADE, 7 + PRIMARY KEY (m_id, t_id) 8 + );
+15
lib/sql/member.sql
··· 1 + CREATE TABLE IF NOT EXISTS member ( 2 + m_id VARCHAR(9) NOT NULL, 3 + name VARCHAR(30) NOT NULL, 4 + second_name VARCHAR(30) NOT NULL, 5 + last_name VARCHAR(30) NOT NULL, 6 + second_last_name VARCHAR(30) NOT NULL, 7 + email VARCHAR(40) NOT NULL, 8 + phone_number VARCHAR(15) NOT NULL, 9 + status ENUM("Active", "Inactive") NOT NULL, 10 + t_id INT, 11 + 12 + PRIMARY KEY (m_id), 13 + FOREIGN KEY (t_id) REFERENCES transaction(t_id) ON DELETE SET NULL, 14 + FULLTEXT (name, second_name, last_name, second_last_name) 15 + );
+8
lib/sql/product.sql
··· 1 + CREATE TABLE IF NOT EXISTS product ( 2 + p_id INT NOT NULL AUTO_INCREMENT, 3 + cents NUMERIC(10,0) NOT NULL, 4 + description VARCHAR(80) NOT NULL, 5 + 6 + PRIMARY KEY (p_id), 7 + FULLTEXT (description) 8 + );
+11
lib/sql/transaction.sql
··· 1 + CREATE TABLE IF NOT EXISTS transaction ( 2 + t_id INT NOT NULL AUTO_INCREMENT, 3 + type ENUM("Expense", "Income") NOT NULL, 4 + Date DATETIME DEFAULT CURRENT_TIMESTAMP, 5 + quantity NUMERIC(5,0) NOT NULL, 6 + category ENUM("Membership", "Donation", "Lent", "Borrowed", "Other") NOT NULL, 7 + p_id INT, 8 + 9 + PRIMARY KEY (t_id), 10 + FOREIGN KEY (p_id) REFERENCES product(p_id) ON DELETE SET NULL 11 + );
+5
lib/transaction.js
··· 1 + function transaction() { 2 + const BUTTONS = document.getElementById("buttons"); 3 + BUTTONS.innerHTML = "商売をします!<br />" + 4 + ti("button", 'onclick="create_transaction()"', "Create a new transaction."); 5 + }