? GR0V Shell

GR0V shell

Linux in-mum-web921.main-hosting.eu 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64

Path : /home/u949514618/domains/drpktiwari.com/public_html/admin/
File Upload :
Current File : /home/u949514618/domains/drpktiwari.com/public_html/admin/patientregistration.php

<?php
// Start the session to check if the user is logged in
session_start();

// Check if the user is logged in
if (!isset($_SESSION['centre_id'])) {
    // If not logged in, redirect to login page
    header("Location: login.php");
    exit();
}

include('db.php');

?>





<!DOCTYPE html>


<html lang="en" class="light-style layout-menu-fixed" dir="ltr" data-theme="theme-default"
    data-assets-path="../backend/assets/" data-template="vertical-menu-template-free">

<head>
    <meta charset="utf-8" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />

    <title>Dashboard - PK Arogyam</title>

    <meta name="description" content="" />

    <!-- Favicon -->
    <link rel="icon" type="image/x-icon" href="../backend/assets/img/brand/favicon.png" />

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
        href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap"
        rel="stylesheet" />

    <!-- Icons. Uncomment required icon fonts -->
    <link rel="stylesheet" href="../backend/assets/vendor/fonts/boxicons.css" />

    <!-- Core CSS -->
    <link rel="stylesheet" href="../backend/assets/vendor/css/core.css" class="template-customizer-core-css" />
    <link rel="stylesheet" href="../backend/assets/vendor/css/theme-default.css"
        class="template-customizer-theme-css" />
    <link rel="stylesheet" href="../backend/assets/css/demo.css" />

    <!-- Vendors CSS -->
    <link rel="stylesheet" href="../backend/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />

    <link rel="stylesheet" href="../backend/assets/vendor/libs/apex-charts/apex-charts.css" />

    <!-- Page CSS -->

    <!-- Helpers -->
    <script src="../backend/assets/vendor/js/helpers.js"></script>

    <!--! Template customizer & Theme config files MUST be included after core stylesheets and helpers.js in the <head> section -->
    <!--? Config:  Mandatory theme config file contain global vars & default theme options, Set your preferred theme option in this file.  -->
    <script src="../backend/assets/js/config.js"></script>

    <link rel="stylesheet" href="https://cdn.datatables.net/2.2.1/css/dataTables.dataTables.css" />
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>

<body>
    <!-- Layout wrapper -->
    <div class="layout-wrapper layout-content-navbar">
        <div class="layout-container">
            <!-- Menu -->

            <?php include_once('include/dash_sidebar.php'); ?>
            <!-- / Menu -->

            <!-- Layout container -->
            <div class="layout-page">
                <!-- Navbar -->

                <?php include_once('include/nav.php'); ?>



                <!-- Content wrapper -->
                <div class="content-wrapper">
                    <!-- Content -->

                    <div class="container-xxl flex-grow-1 container-p-y">
                        <h4 class="fw-bold py-3 mb-4"><span class="text-muted fw-light">Patient Registration</span>
                        </h4>
                        <form id="patientForm">
                            <div class="mb-3">
                                <label>Date</label>
                                <input type="date" name="date" class="form-control" required>
                            </div>

                            <div class="mb-3">
                                <label>Centre</label>
                                <select name="centre_id" class="form-control" required>
                                    <?php 
                $result = mysqli_query($conn, "SELECT * FROM centre where id = $centre_id");
                while ($row = mysqli_fetch_assoc($result)) {
                    echo "<option value='{$row['id']}'>{$row['centre_name']}</option>";
                }
                ?>
                                </select>
                            </div>

                            <div class="mb-3">
                                <label>Patient Name</label>
                                <input type="text" name="patient_name" class="form-control" required>
                            </div>

                            <div class="mb-3">
                                <label>Contact Number</label>
                                <input type="text" name="contact_number" class="form-control" required>
                            </div>

                            <div class="mb-3">
                                <label>Refer By</label>
                                <select name="referby" id="referby" class="form-control">
                                    <option value="Self">Self</option>
                                    <option value="Doctor">Doctor</option>
                                </select>
                            </div>

                            <div class="mb-3" id="doctorSection" style="display: none;">
                                <label>Select Doctor</label>
                                <select name="doctor_id" id="doctor_id" class="form-control">
                                <option value="">Select Doctor</option>
            <?php
            // Assuming session contains the logged-in user's centre_id
            $centre_id = $_SESSION['centre_id'];  // Example, replace with your actual session value

            // Query doctors who belong to the same centre as the logged-in user
            $doctorResult = mysqli_query($conn, "SELECT * FROM doctorentry WHERE centre_id = '$centre_id'");
            while ($row = mysqli_fetch_assoc($doctorResult)) {
                echo "<option value='{$row['id']}'>{$row['doctor_name']}</option>";
            }
            ?>
                                </select>
                            </div>

                            <div id="testSection">
                                <label>Tests</label>
                                <div id="testContainer">
                                    <div class="row mb-2">
                                        <div class="col-md-5">
                                            <select name="test_id[]" class="form-control testSelect">
                                                <option value="">Select Test</option>
                                                <?php 
                            $tests = mysqli_query($conn, "SELECT * FROM testentry");
                            while ($row = mysqli_fetch_assoc($tests)) {
                                echo "<option value='{$row['id']}' data-rate='{$row['test_rate']}'>{$row['test_name']}</option>";
                            }
                            ?>
                                            </select>
                                        </div>
                                        <div class="col-md-3">
                                            <input type="text" name="test_rate[]" class="form-control testRate"
                                                placeholder="Rate" readonly>
                                        </div>
                                        <div class="col-md-2">
                                            <button type="button" class="btn btn-success addTest">+</button>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="mb-3">
                                <label>Discount</label>
                                <input type="text" name="discount" id="discount" class="form-control">
                            </div>

                            <div class="mb-3">
                                <label>Payable Amount</label>
                                <input type="text" name="payable_amount" id="payable_amount" class="form-control">
                            </div>

                            <div class="mb-3">
                                <label>Discount Type</label>
                                <select name="discount_type" class="form-control">
                                    <option value="Self">Self</option>
                                    <option value="Doctor">Doctor</option>
                                </select>
                            </div>

                            <button type="submit" class="btn btn-primary">Register</button>
                        </form>
                        <!-- Display Data -->
                        <?php

// Get the logged-in user's centre_id
$centre_id = $_SESSION['centre_id']; 

// Pagination logic
$limit = 10; // Number of records per page
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$offset = ($page - 1) * $limit;

// Query to fetch the latest 10 patient data for the logged-in centre, ordered by date descending
$query = "SELECT p.id, p.patient_name, p.contact_number, 
                 GROUP_CONCAT(t.test_name SEPARATOR ', ') as tests, 
                 SUM(t.test_rate) as total_test_amount, p.date, pt.discount, pt.discount_type
          FROM patient_registration p
          JOIN patient_test_entry pt ON p.id = pt.patient_id
          JOIN testentry t ON pt.test_id = t.id
          WHERE p.centre_id = '$centre_id'
          GROUP BY p.id
          ORDER BY p.id DESC
          LIMIT $offset, $limit"; // Adding limit and offset for pagination

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

// Fetch total number of records for pagination
$total_query = "SELECT COUNT(*) AS total FROM patient_registration WHERE centre_id = '$centre_id'";
$total_result = mysqli_query($conn, $total_query);
$total_row = mysqli_fetch_assoc($total_result);
$total_records = $total_row['total'];
$total_pages = ceil($total_records / $limit);
?>
                        <table class="table mt-4">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Patient Name</th>
                                    <th>Contact</th>
                                    <th>Tests</th>
                                    <th>Total Test Amount</th>
                                    <th>Discount</th>
                                    <th>Payable Amount</th>
                                    <th>Date</th>
                                    <th>Print</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php while ($row = mysqli_fetch_assoc($result)) { 
            $total_test_amount = $row['total_test_amount']; 
            $discount = $row['discount'];
            $discount_type = $row['discount_type'];

            // Calculate Payable Amount after discount
            if ($discount_type == 'self') {
                $payable_amount = $total_test_amount - $discount;
            } elseif ($discount_type == 'doctor') {
                $payable_amount = $total_test_amount - $discount;
            } else {
                $payable_amount = $total_test_amount - $discount; // No discount applied
            }

            // Ensure Payable Amount is not negative
            if ($payable_amount < 0) {
                $payable_amount = 0;
            }
        ?>
                                <tr>
                                    <td><?php echo $row['id']; ?></td>
                                    <td><?php echo $row['patient_name']; ?></td>
                                    <td><?php echo $row['contact_number']; ?></td>
                                    <td><?php echo $row['tests']; ?></td>
                                    <td><?php echo $total_test_amount; ?></td>
                                    <td><?php echo $discount; ?></td>
                                    <td><?php echo $payable_amount; ?></td>
                                    <td><?php echo date('d/m/Y', strtotime($row['date'])); ?></td> <!-- Format date -->
                                    <td>
                                        <button class="btn btn-primary"
                                            onclick="generateImage(<?php echo $row['id']; ?>)">Print</button>
                                    </td>
                                </tr>
                                <?php } ?>
                            </tbody>
                        </table>

                        <!-- Pagination Controls -->
                        <div class="pagination">
                            <?php if ($page > 1) { ?>
                            <a href="?page=<?php echo $page - 1; ?>" class="btn btn-secondary">Previous</a>
                            <?php } ?>
                            <?php if ($page < $total_pages) { ?>
                            <a href="?page=<?php echo $page + 1; ?>" class="btn btn-secondary">Next</a>
                            <?php } ?>
                        </div>

                        <!-- Search Box for Patient Name -->
                        <input type="text" id="search-box" class="form-control mt-4"
                            placeholder="Search Patient by Name" onkeyup="searchPatient()">
                        <div id="search-results"></div>

                        <script>
                            // Ajax Search for Patient Name
                            function searchPatient() {
                                var query = document.getElementById('search-box').value;
                                var centre_id = '<?php echo $centre_id; ?>'; // Centre ID from session
                                var xhr = new XMLHttpRequest();
                                xhr.open("GET", "search_patient.php?query=" + query + "&centre_id=" + centre_id, true);
                                xhr.onload = function () {
                                    if (xhr.status === 200) {
                                        document.getElementById('search-results').innerHTML = xhr.responseText;
                                    }
                                };
                                xhr.send();
                            }
                        </script>



                    </div>




                </div>
                <!-- / Content -->
                
                <!-- Footer -->
                <footer class="content-footer footer bg-footer-theme">
                    <div class="container-xxl d-flex flex-wrap justify-content-between py-2 flex-md-row flex-column">
                        <div class="mb-2 mb-md-0">
                            ©
                            <script>
                                document.write(new Date().getFullYear());
                            </script>
                            , made with ❤️ by
                            <a href="#" target="_blank" class="footer-link fw-bolder">Made By Ajay Singh Rathore (+91 9031351333)</a>
                        </div>
                        <div>6j
                            <a href="#" class="footer-link me-4" target="_blank">Privacy Policy</a>
                            <a href="#" target="_blank" class="footer-link me-4">Terms &amp; Condition</a>
                        </div>
                    </div>
                </footer>
                <!-- / Footer -->

                <div class="content-backdrop fade"></div>
            </div>
            <!-- Content wrapper -->
        </div>
        <!-- / Layout page -->
    </div>

    <!-- Overlay -->
    <div class="layout-overlay layout-menu-toggle"></div>
    </div>
    <!-- / Layout wrapper -->


    <!-- Core JS -->
    <!-- build:js assets/vendor/js/core.js -->
    <script src="../backend/assets/vendor/libs/jquery/jquery.js"></script>
    <script src="../backend/assets/vendor/libs/popper/popper.js"></script>
    <script src="../backend/assets/vendor/js/bootstrap.js"></script>
    <script src="../backend/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>

    <script src="../backend/assets/vendor/js/menu.js"></script>
    <!-- endbuild -->

    <!-- Vendors JS -->
    <script src="../backend/assets/vendor/libs/apex-charts/apexcharts.js"></script>

    <!-- Main JS -->
    <script src="../backend/assets/js/main.js"></script>

    <!-- Page JS -->
    <script src="../backend/assets/js/dashboards-analytics.js"></script>

    <!-- Place this tag in your head or just before your close body tag. -->
    <script async defer src="https://buttons.github.io/buttons.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.7.1.js"></script>

    <script>
        $(document).ready(function () {
            $("#referby").change(function () {
                if ($(this).val() === "Doctor") {
                    $("#doctorSection").show();
                } else {
                    $("#doctorSection").hide();
                }
            });

            $(".addTest").click(function () {
                let newRow = $(".row.mb-2:first").clone();
                newRow.find("select").val('');
                newRow.find("input").val('');
                $("#testContainer").append(newRow);
            });

            $(document).on("change", ".testSelect", function () {
                let rate = $(this).find(':selected').data('rate');
                $(this).closest(".row").find(".testRate").val(rate);
            });

            $("#patientForm").submit(function (e) {
                e.preventDefault();
                $.ajax({
                    url: "insert_patient.php",
                    type: "POST",
                    data: $(this).serialize(),
                    success: function (response) {
                        if (response === "success") {
                            Swal.fire("Success!", "Patient Registered Successfully!",
                                    "success")
                                .then(() => window.location.href =
                                    "patientregistration.php");
                        } else {
                            Swal.fire("Error!", "Something went wrong.", "error");
                        }
                    }
                });
            });
        });
    </script>
    <script>
        function generateImage(patientId) {
            fetch('generate_image.php?id=' + patientId)
                .then(response => response.json())
                .then(data => {
                    if (data.status === "success") {
                        let imgUrl = data.image_url;

                        // Replace the relative path with the full URL
                        imgUrl1 = "" + imgUrl;
                        imgUrl = "E:/xampp/htdocs/pktiwari/admin/" + imgUrl;

                        // Open print preview
                        let printWindow = window.open('', '', 'width=1414,height=2000');
                    printWindow.document.write('<html><head><title>Print Preview</title><style>');
                    printWindow.document.write(`
                        @media print {
                            body {
                                margin: 0;
                                padding: 0;
                            }
                            .page {
                                page-break-before: always;
                            }
                            .first-page, .third-page {
                                display: none;
                            }
                            .second-page {
                                display: block;
                                page-break-before: always;
                            }
                        }
                    `);
                    printWindow.document.write('</style></head><body>');
                    printWindow.document.write('<div class="page first-page">First Page Content (This will be hidden)</div>');
                    printWindow.document.write('<div class="page second-page"><img src="' + imgUrl1 + '" style="width:100%;">' + '</div>');
                    printWindow.document.write('<div class="page third-page">Third Page Content (This will be hidden)</div>');
                    printWindow.document.write('</body></html>');
                    printWindow.document.close();  // Close the document to trigger rendering
                    printWindow.onload = function () {
                        printWindow.print();
                    };

                        // Send to WhatsApp
                        let phoneNumber = data.contact_number;
                        let whatsappUrl = "https://wa.me/" + phoneNumber +
                            "?text=Here%20is%20your%20bill%20image:%20" + encodeURIComponent(imgUrl);
                        window.open(whatsappUrl, '_blank');
                    } else {
                        alert("Failed to generate image!");
                    }
                });
        }
    </script>
<script>
document.addEventListener("DOMContentLoaded", function() {
    function calculateTotal() {
        let totalAmount = 0;
        document.querySelectorAll(".testSelect").forEach(select => {
            let selectedOption = select.options[select.selectedIndex];
            if (selectedOption.value !== "") {
                totalAmount += parseFloat(selectedOption.getAttribute("data-rate"));
            }
        });

        let discount = parseFloat(document.getElementById("discount").value) || 0;
        let finalAmount = totalAmount - discount;

        document.getElementById("payable_amount").value = finalAmount.toFixed(2);
    }

    document.getElementById("testContainer").addEventListener("change", function(event) {
        if (event.target.classList.contains("testSelect")) {
            let rateField = event.target.closest(".row").querySelector(".testRate");
            let selectedOption = event.target.options[event.target.selectedIndex];
            rateField.value = selectedOption.value ? selectedOption.getAttribute("data-rate") : "";
            calculateTotal();
        }
    });

    document.getElementById("discount").addEventListener("input", calculateTotal);
});
</script>
</body>

</html>

T1KUS90T
  root-grov@89.117.188.241:~$