activity(), "activity_transaction" => activity_transaction(), "board_member" => board_member(), "member" => member(), "product" => product(), "transaction" => transaction(), default => header('HTTP/1.1 400 Bad Request: type not found') }; } else { print header('HTTP/1.1 420 Bad Request: type not specified'); } function activity() { include("../../../lib/db.php"); $out = ""; if (!(isset($_POST["title"]) || isset($_POST["description"]) || isset($_POST["date"]))) { $out .= header('HTTP/1.1 400 Bad Request. You must supply `title`, `description` and `date`.'); } else { $stmt = $db -> prepare("INSERT INTO activity (title, description, date) VALUES (?, ?, ?);"); $stmt -> bind_param("sss", $title, $description, $date); $title = validate_input($_POST["title"]); $description = validate_input($_POST["description"]); $date = validate_input($_POST["date"]); if ($stmt -> execute()) { $result = $stmt -> get_result(); $a_id = $stmt -> insert_id; print header("HTTP/1.1 201 Created"); print header("Location: https://ada.uprrp.edu/~diego.estrada1/CCOM/4027/db/api/v1/read/?t=activity&a_id=${a_id}"); $out .= json_encode(array("a_id" => $a_id, "title" => $title, "description" => $description, "date" => $date)); } else { print header("HTTP/1.1 500 Something happened ???"); } } $db -> close(); return $out; } function activity_transaction() { include("../../../lib/db.php"); $out = ""; if (!(isset($_POST["a_id"]) || isset($_POST["t_id"]))) { $out .= header('HTTP/1.1 400 Bad Request. You must supply `a_id` and `t_id`.'); } else { $stmt = $db -> prepare("INSERT INTO activity_transaction (a_id, t_id) VALUES (?, ?);"); $stmt -> bind_param("ii", $a_id, $t_id); $a_id = validate_input($_POST["a_id"]); $t_id = validate_input($_POST["t_id"]); if ($stmt -> execute()) { print header("HTTP/1.1 201 Created"); print header("Location: https://ada.uprrp.edu/~diego.estrada1/CCOM/4027/db/api/v1/read?t=activity_transaction&a_id=${a_id}&t_id=${t_id}"); $out .= json_encode(array("a_id" => $a_id, "t_id" => $t_id)); } else { print header("HTTP/1.1 500 Something happened ???"); } } $db -> close(); return $out; } function board_member() { include("../../../lib/db.php"); $out = ""; if (!(isset($_POST["m_id"]) || isset($_POST["position"]) || isset($_POST["year"]) || isset($_POST["role"]) || isset($_POST["password"]))) { $out .= header('HTTP/1.1 400 Bad Request. You must supply `m_id`, `position`, `year`, `role` and `password`.'); } else { $stmt = $db -> prepare("INSERT INTO board_member (m_id, position, year, role, password) VALUES (?, ?, ?, ?, ?);"); $stmt -> bind_param("ssiss", $m_id, $position, $year, $role, $password); $m_id = validate_input($_POST["m_id"]); $position = validate_input($_POST["position"]); $year = validate_input($_POST["year"]); $role = validate_input($_POST["role"]); $password = validate_input($_POST["password"]); if ($stmt -> execute()) { $result = $stmt -> get_result(); $p_id = $stmt -> insert_id; print header("HTTP/1.1 201 Created"); print header("Location: https://ada.uprrp.edu/~diego.estrada1/CCOM/4027/db/api/v1/read/?t=board_member&m_id=${m_id}"); $out .= json_encode(array("m_id" => $m_id, "position" => $position, "year" => $year, "role" => $role, "password" => $password)); } else { print header("HTTP/1.1 500 Something happened ???"); } } $db->close(); return $out; } function member() { include("../../../lib/db.php"); $out = ""; if (!(isset($_POST["name"]) || isset($_POST["second_name"]) || isset($_POST["last_name"]) || isset($_POST["second_last_name"]) || isset($_POST["email"]) || isset($_POST["phone_number"]) || isset($_POST["status"]))) { $out .= header('HTTP/1.1 400 Bad Request. You must supply `name`, `second_name`, `last_name`, `second_last_name`, `email`, `phone_number` and `status`.'); } else { $stmt = $db -> prepare("INSERT INTO product (name, second_name, last_name, second_last_name, email, phone_number, status) VALUES (?, ?, ?, ?, ?, ?, ?);"); $stmt -> bind_param("sssssss", $name, $second_name, $last_name, $second_last_name, $email, $phone_number, $status); $name = validate_input($_POST["name"]); $second_name = validate_input($_POST["second_name"]); $last_name = validate_input($_POST["last_name"]); $second_last_name = validate_input($_POST["second_last_name"]); $email = validate_input($_POST["email"]); $phone_number = validate_input($_POST["phone_number"]); $status = validate_input($_POST["status"]); if ($stmt -> execute()) { $result = $stmt -> get_result(); $m_id = $stmt -> insert_id; print header("HTTP/1.1 201 Created"); print header("Location: https://ada.uprrp.edu/~diego.estrada1/CCOM/4027/db/api/v1/read/?t=member&m_id=${m_id}"); $out .= json_encode(array("m_id" => $m_id, "name" => $name, "second_name" => $second_name, "last_name" => $last_name, "second_last_name" => $second_last_name, "email" => $email, "phone_number" => $phone_number, "status" => $status)); } else { print header("HTTP/1.1 500 Something happened ???"); } } $db -> close(); return $out; } function product() { include("../../../lib/db.php"); $out = ""; if (!(isset($_POST["cents"]) || isset($_POST["description"]))) { $out .= header('HTTP/1.1 400 Bad Request. You must supply `cents` and `description`.'); } else { $stmt = $db -> prepare("INSERT INTO product (cents, description) VALUES (?, ?);"); $stmt -> bind_param("is", $cents, $description); $cents = validate_input($_POST["cents"]); $description = validate_input($_POST["description"]); if ($stmt -> execute()) { $result = $stmt -> get_result(); $p_id = $stmt -> insert_id; print header("HTTP/1.1 201 Created"); print header("Location: https://ada.uprrp.edu/~diego.estrada1/CCOM/4027/db/api/v1/read/?t=product&p_id=${p_id}"); $out .= json_encode(array("p_id" => $p_id, "cents" => $cents, "description" => $description)); } else { print header("HTTP/1.1 500 Something happened ???"); } } $db -> close(); return $out; } function transaction() { include("../../../lib/db.php"); $out = ""; if (!(isset($_POST["type"]) || isset($_POST["date"]) || isset($_POST["quantity"]) || isset($_POST["p_id"]))) { $out .= header('HTTP/1.1 400 Bad Request. You must supply `type`, `date`, `quantity` and `p_id`'); } else { $stmt = $db -> prepare("INSERT INTO transaction (type, date, quantity, p_id) values (?, ?, ?, ?);"); $stmt -> bind_param("ssii", $type, $date, $quantity, $p_id); $type = validate_input($_POST["type"]); $date = validate_input($_POST["date"]); $quantity = validate_input($_POST["quantity"]); $p_id = validate_input($_POST["p_id"]); if ($stmt -> execute()) { $result = $stmt -> get_result(); $t_id = $stmt -> insert_id; print header("HTTP/1.1 201 Created"); print header("Location: https://ada.uprrp.edu/~diego.estrada1/CCOM/4027/db/api/v1/read/?t=transaction&t_id=${t_id}"); $out .= json_encode(array("t_id" => $t_id, "type" => $type, "date" => $date, "quantity" => $quantity, "p_id" => $p_id)); } else { print header("HTTP/1.1 500 Something happened ???"); } } } ?>