MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/.nvm/../public_html/invoice/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/.nvm/../public_html/invoice/fetch_product_price.php
<?php
error_reporting(0);
ini_set('display_errors', 0);
include 'db.php';
$response = array('success' => false);

try {
    $pid = isset($_GET['pid']) ? intval($_GET['pid']) : 0;
    $cid = isset($_GET['cid']) ? intval($_GET['cid']) : 0;
    if ($pid <= 0) {
        throw new Exception("Invalid product ID");
    }
    $query = "SELECT p.bsprice, p.paid, p.pform 
              FROM product p 
              WHERE p.pid = ?";
    $stmt = $con->prepare($query);
    $stmt->bind_param("i", $pid);
    $stmt->execute();
    $result = $stmt->get_result();
    if (!$result) {
        throw new Exception("Database query error: " . $con->error);
    }
    if ($row = $result->fetch_assoc()) {
        $response['success'] = true;
        $response['price'] = $row['bsprice'];
        $pformIds = $row['pform'];
        $response['pform'] = array();
        if (!empty($pformIds)) {
            $formQuery = "SELECT fid, name, measurement FROM forms_value WHERE FIND_IN_SET(fid, ?)";
            $formStmt = $con->prepare($formQuery);
            $formStmt->bind_param("s", $pformIds);
            $formStmt->execute();
            $formResult = $formStmt->get_result();
            if (!$formResult) {
                throw new Exception("Error fetching form values: " . $con->error);
            }
            while ($formRow = $formResult->fetch_assoc()) {
                $response['pform'][] = $formRow;
            }
            $formStmt->close();
        }
        $packageIds = $row['paid'];
        $response['paid'] = array();
        if (!empty($packageIds)) {
            $packageQuery = "SELECT paid, name FROM package WHERE FIND_IN_SET(paid, ?)";
            $packageStmt = $con->prepare($packageQuery);
            $packageStmt->bind_param("s", $packageIds);
            $packageStmt->execute();
            $packageResult = $packageStmt->get_result();
            if (!$packageResult) {
                throw new Exception("Error fetching packages: " . $con->error);
            }
            while ($packageRow = $packageResult->fetch_assoc()) {
                $response['paid'][] = $packageRow;
            }
            $packageStmt->close();
        }
        if ($cid > 0) {
            $cusQuery = "SELECT paid,pform FROM cus_product WHERE pid = ? AND cid = ?";
            $cusStmt = $con->prepare($cusQuery);
            $cusStmt->bind_param("ii", $pid, $cid);
            $cusStmt->execute();
            $cusResult = $cusStmt->get_result();
            if (!$cusResult) {
                throw new Exception("Error fetching customer product: " . $con->error);
            }
            if ($cusRow = $cusResult->fetch_assoc()) {
                $response['selected_paid'] = $cusRow['paid']; // Store selected package ID
            } else {
                $response['selected_paid'] = null; // No selection found
            }
            $cusStmt->close();
        }
    } else {
        throw new Exception("Product not found");
    }
    $stmt->close();
    
} catch (Exception $e) {
    $response = array('success' => false, 'error' => $e->getMessage());
}
header('Content-Type: application/json');
echo json_encode($response);
exit;
?>

MMCT - 2023