<?php header('Content-Type: application/json'); include "../../include/dbcon.inc.php"; include "../../include/functions.php"; include "../../include/pm_functions.inc.php"; include "../../include/push_functions.inc.php"; $user_id = getUserIdFromToken($con, @$_POST["token"]); $dog_id = $con->real_escape_string($_POST["dog_id"]); $symptoms = $con->real_escape_string($_POST["symptoms"]); $place_id = $con->real_escape_string($_POST["place_id"]); $duedate = $con->real_escape_string($_POST["duedate"]); $volume = $con->real_escape_string($_POST["volume"]); $user = getUserById($user_id, $con); $dog = getDogById($dog_id, $con); $bloodtype = getBloodTypeById($dog["dog_bloodtype_id"], $con); $bloodstores = getBloodStoreByBloodTypeId($dog["dog_bloodtype_id"], $con); $result = 0; if (sizeof($bloodstores) > 0) { //Found Blood In Hospital Blood Store //create bloodstore_id string $bloodstore_ids = array(); foreach ($bloodstores as $key => $bloodstore) { array_push($bloodstore_ids, $bloodstore["bloodstore_id"]); } $bloodstore_id = implode(",", $bloodstore_ids); $con->query("INSERT INTO `request`(`request_id`, `from_user_id`, `for_dog_id`, `symptoms`, `place_id`," . " `duedate`, `request_type`, `bloodstore_id`, `created_time`, `amount_volume`) " . "VALUES (null,'{$user_id}','{$dog_id}','{$symptoms}','{$place_id}','{$duedate}',1,'{$bloodstore_id}',now(),'{$volume}')"); //save to db (request_type = 1) $senthospital_id = array(); //store sent hospital id $message = "การขอรับเลือดของ" . $dog["dog_name"] . " เมื่อ " . date("j") . " " . $thai_month_short_arr[date("n")] . " " . (date("Y") + 543) . " " . "พบเลือดกรุ๊ป " . $bloodtype["bloodtype_name"] . " ที่โรงพยาบาลดังนี้";
$ret = array(); $access_token = $_POST["access_token"]; $postalcode = $_POST["postalcode"]; if (Validation::includeBlank($access_token, $postalcode)) { HandleResponse::badRequest("Parameters are blank"); } else { if (!Validation::isValidPostalcode($postalcode)) { HandleResponse::badRequest("Invalid user postalcode"); } else { $conn = null; try { $db = new DBConnection(); $conn = $db->getConnection(); mysqli_query($conn, "set autocommit = 0"); mysqli_query($conn, "begin"); $user_id = getUserIdFromToken($conn, $access_token); if ($user_id == null) { $ret = HandleResponse::badRequestReturn("Invalid Accesstoken"); } else { // Update postal code $ret = updatePostalcode($conn, $user_id, $postalcode); } mysqli_query($conn, "commit"); } catch (Exception $e) { mysqli_query($conn, "rollback"); $ret = HandleResponse::badRequestReturn("Invalid Accesstoken"); } print json_encode($ret); } } } else {