コード例 #1
0
            $datediff = $your_date - $now;
            $daydiff = floor($datediff / (60 * 60 * 24));
            $canCancle = true;
            $reason = "มีผู้บริจาคตัวสำรอง";
            if ($daydiff <= 0) {
                $daydiff = 0;
                $canCancle = false;
                $reason = "ไม่สามารถยกเลิกได้หลังจากวันที่กำหนด";
            }
        } else {
            //no alt donator
            $daydiff = 0;
            $canCancle = false;
            $reason = "ไม่สามารถยกเลิกได้ เพราะไม่มีผู้บริจาคตัวสำรอง";
        }
        $donatedata = array("request_id" => $donate["request_id"], "dog_name" => $requestdog["dog_name"], "status" => getDonatorStatus($request["request_id"], $dog["dog_id"], $con), "due_date" => changeFormatDate($duedate), "isCancelable" => $canCancle, "reason" => $reason, "dayLeftToCancel" => $daydiff);
    }
    $userres = array("dog_id" => $dog["dog_id"], "dog_name" => $dog["dog_name"], "isDonating" => $isDonating, "donatedata" => $donatedata);
    if ($isAbleToDonate) {
        array_push($response, $userres);
    }
}
echo json_encode($response);
/*

 //find current donate data
 $finddonateres = $con->query("SELECT donate_id, dog_id, request_id FROM donate WHERE donate_status = 0 AND dog_id IN"
 . " (SELECT dog_id FROM user_dog WHERE user_id = '$user_id') AND request_id IN"
 . " (SELECT request_id FROM request WHERE request_type = 2)");
 $donate = array();
 while ($finddonatedata = $finddonateres->fetch_array()) {
コード例 #2
0
<?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);
コード例 #3
0
        array_push($donateablereasons, "คุณไม่สามารถบริจาคเลือดให้กับสุนัขของตัวเองได้");
    }
    //count how many people donate to this request
    $countres = $con->query("SELECT * FROM donate WHERE request_id = '{$request_id}' AND donate_status = 0");
    $currentdonatecount = $countres->num_rows;
    $amount = $data["amount_volume"];
    $needdonator = ceil($amount / 300);
    $needprepare = ceil($needdonator / 4);
    $totalneed = $needdonator + $needprepare;
    if ($currentdonatecount >= $totalneed) {
        $donateablestatus = false;
        array_push($donateablereasons, "มีผู้บริจาคเลือดครบตามจำนวนที่ต้องการแล้ว");
    }
    //find current donation data
    $donatorrealarr = array();
    $donatoraltarr = array();
    $donatorfind = $con->query("SELECT \n        up.user_id, up.firstname, up.lastname, ud.dog_name FROM donate d\n        JOIN user_dog ud ON d.dog_id = ud.dog_id\n        JOIN user_profile up ON ud.user_id = up.user_id\n        WHERE d.request_id = '{$request_id}' AND d.donate_status != 3");
    $count = 0;
    while ($donatordata = $donatorfind->fetch_assoc()) {
        if (++$count <= $needdonator) {
            array_push($donatorrealarr, $donatordata);
        } else {
            array_push($donatoraltarr, $donatordata);
        }
    }
    $donateable = array("status" => $donateablestatus, "reasons" => $donateablereasons, "stats" => array("realneed" => $needdonator, "realdonator" => $donatorrealarr, "altneed" => $needprepare, "altdonator" => $donatoraltarr, "total" => $totalneed, "current" => $currentdonatecount));
    $response = array("status" => 1, "requester_userprofile" => $userdata, "requester_dog" => $userdog, "symptoms" => $data["symptoms"], "place" => array("place_id" => $data["place_id"], "place_name" => $data["name"], "phone" => $data["phone"], "formattedAddress" => $data["formattedAddress"]), "duedate" => changeFormatDate($data["duedate"]), "amount_volume" => $data["amount_volume"], "created_time" => $data["created_time"], "dog_list" => $userdoglist, "donateable" => $donateable);
} else {
    $response = array("status" => 0);
}
echo json_encode($response);