Ejemplo n.º 1
0
<?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"] . " ที่โรงพยาบาลดังนี้";
Ejemplo n.º 2
0
    $donatecalc = calculateDonator($request["amount_volume"]);
    $donators = getDonatorByRequestId($request_id, $con);
    $statsbefore = array("realneed" => $donatecalc["realdonator"], "realdonator" => sortRealDonator($donators, $donatecalc), "altneed" => $donatecalc["extradonator"], "altdonator" => sortAltDonator($donators, $donatecalc), "total" => $donatecalc["total"], "current" => sizeof($donator));
    //print_r($statsbefore);
    $res = $con->query("UPDATE donate SET donate_status = '{$isDonate}' , donate_date = now() " . "WHERE request_id = '{$request_id}' AND dog_id ='{$dog_id}' ");
    echo $con->error;
    if ($con->error == "") {
        $response = array("result" => 1);
    } else {
        $response = array("result" => 0);
    }
}
if ($isDonate == 3) {
    //get after change
    $request = getRequestById($request_id, $con);
    $donator = getCurrentActiveDonateByRequestId($request_id, $con);
    $donatecalc = calculateDonator($request["amount_volume"]);
    $donators = getDonatorByRequestId($request_id, $con);
    $statsafter = array("realneed" => $donatecalc["realdonator"], "realdonator" => sortRealDonator($donators, $donatecalc), "altneed" => $donatecalc["extradonator"], "altdonator" => sortAltDonator($donators, $donatecalc), "total" => $donatecalc["total"], "current" => sizeof($donator));
    //print_r($statsafter);
    //echo "afterdogid:".$statsafter["realdonator"][$statsafter["realneed"]-1]["dog_id"];
    //echo "beforedogid:".$statsbefore["altdonator"][0]["dog_id"];
    if (isset($statsbefore["altdonator"][0]["dog_id"])) {
        if ($statsafter["realdonator"][$statsafter["realneed"] - 1]["dog_id"] == $statsbefore["altdonator"][0]["dog_id"]) {
            $user = getDogById($statsafter["realdonator"][$statsafter["realneed"] - 1]["dog_id"], $con);
            $user_id = $user["user_id"];
            pushToUser($user_id, "เปลื่ยนสถานะเป็นตัวจริง", "คุณเป็นผู้บริจาคตัวจริง", "donator", $request_id, $con);
        }
    }
}
echo json_encode($response);
<?php

header('Content-Type: application/json');
include "../../include/dbcon.inc.php";
include "../../include/functions.php";
$user_id = getUserIdFromToken($con, @$_POST["token"]);
$response = array();
$requests = getCurrentActiveRequestByUserId($user_id, $con);
if (sizeof($requests) > 0) {
    foreach ($requests as $key => $request) {
        $dog = getDogById($request["for_dog_id"], $con);
        $bloodtype = getBloodTypeById($dog["dog_bloodtype_id"], $con);
        $breeds = getBreedsById($dog["breeds_id"], $con);
        $place = getPlaceById($request["place_id"], $con);
        $donator = getCurrentActiveDonateByRequestId($request["request_id"], $con);
        $donatecalc = calculateDonator($request["amount_volume"]);
        $donators = getDonatorByRequestId($request["request_id"], $con);
        $stats = array("realneed" => $donatecalc["realdonator"], "realdonator" => sortRealDonator($donators, $donatecalc), "altneed" => $donatecalc["extradonator"], "altdonator" => sortAltDonator($donators, $donatecalc), "total" => $donatecalc["total"], "current" => sizeof($donator));
        $resrequest = array("request_id" => $request["request_id"], "requested_dog" => array("dog_id" => $dog["dog_id"], "dog_name" => $dog["dog_name"], "dog_image" => $dog["dog_image"], "bloodtype_name" => $bloodtype["bloodtype_name"], "breeds_name" => $breeds["breeds_name"]), "symptoms" => $request["symptoms"], "place" => array("place_id" => $place["place_id"], "place_name" => $place["name"], "phone" => $place["phone"], "formattedAddress" => $place["formattedAddress"]), "duedate" => changeFormatDate($request["duedate"]), "amount_volume" => $request["amount_volume"], "stats" => $stats);
        array_push($response, $resrequest);
    }
}
echo json_encode($response);
                        </thead>
                        <tbody>
                            <?php 
include "../dbcon.inc.php";
$res = $con->query("SELECT * FROM request WHERE from_user_id = '" . $_SESSION["userdata"]["user_id"] . "' " . "AND request_id IN (SELECT request_id FROM donate WHERE donate_status = 1 OR donate_status = 2)");
while ($data = $res->fetch_assoc()) {
    $request_id = $data["request_id"];
    $from_user_id = $data["from_user_id"];
    $for_dog = getDogById($data["for_dog_id"], $con);
    $getuser = getUserById($data["from_user_id"], $con);
    $donatorlist = "";
    //get donator list
    $donator = $con->query("SELECT * FROM donate WHERE request_id = '{$request_id}' and donate_status = 1 ");
    $i = 1;
    while ($donatordata = $donator->fetch_assoc()) {
        $dog = getDogById($donatordata["dog_id"], $con);
        $user = getUserById($dog["user_id"], $con);
        if ($donatorlist == "") {
            $donatorlist .= $i++ . ". " . $dog["dog_name"];
        } else {
            $donatorlist .= "<br>" . $i++ . ". " . $dog["dog_name"];
        }
    }
    ?>
                                <tr class="showrequest"> 
                                    <td><?php 
    echo $data["created_time"];
    ?>
</td>
                                    <td><?php 
    echo $for_dog["dog_name"];