Uname:Linux ip-11-115-0-196 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64

403WebShell
403Webshell
Server IP : 13.126.101.145  /  Your IP : 216.73.217.33
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux ip-11-115-0-196 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64
User : www-data ( 33)
PHP Version : 8.3.17
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/rentals_updated/wp-content/plugins/woocommerce-rfq/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/rentals_updated/wp-content/plugins/woocommerce-rfq/admin-downloadstdratecard.php
<?php
// Ensure the file is not accessed directly
if (!defined('ABSPATH')) {
    exit;
}

// Add admin menu
add_action('admin_menu', 'downloadstdratecard_admin_menu');

function downloadstdratecard_admin_menu() {
    add_menu_page(
        'Standard Quote Downloads',    // Page title
        'Standard Quote Downloads',    // Menu title
        'manage_options',    // Capability
        'stdratecard-dashboard',     // Menu slug
        'std_rate_card_list',// Callback function
        'dashicons-vault', // Icon URL
        6                    // Position
    );
}

function stdratecard_enqueue_custom_styles_and_scripts($hook) {
    // Load only on the Standard Rate Card dashboard page
    if ($hook != 'toplevel_page_stdratecard-dashboard') {
        return;
    }

    // Enqueue Bootstrap CSS
    wp_enqueue_style('bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css');

    // Enqueue DataTables CSS
    wp_enqueue_style('datatables-css', 'https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css');
	
	wp_enqueue_style('datatable-btn-css', 'https://cdn.datatables.net/buttons/2.3.6/css/buttons.dataTables.min.css');

    // Enqueue Font Awesome CSS
    wp_enqueue_style('fontawesome-css', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css');

    // Enqueue your custom CSS
    wp_enqueue_style('stdratecard-custom-styles', plugin_dir_url(__FILE__) . 'css/custom-style.css');

    // Enqueue jQuery and DataTables JS
    wp_enqueue_script('jquery');
    wp_enqueue_script('datatables-js', 'https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js', array('jquery'), '1.10.24', true);
	wp_enqueue_script('datatable-btn-js', 'https://cdn.datatables.net/buttons/2.3.6/js/dataTables.buttons.min.js', array('jquery'), '2.3.6', true);
	wp_enqueue_script('flash-btn-js', 'https://cdn.datatables.net/buttons/2.3.6/js/buttons.flash.min.js', array('jquery'), '2.3.6', true);
	wp_enqueue_script('jszip-js', 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js', array('jquery'), '3.1.3', true);
	wp_enqueue_script('pdf-js', 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js', array('jquery'), '0.1.53', true);
	wp_enqueue_script('pdf-font-js', 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js', array('jquery'), '0.1.53', true);
	wp_enqueue_script('html5-btn-js', 'https://cdn.datatables.net/buttons/2.3.6/js/buttons.html5.min.js', array('jquery'), '2.3.6', true);
	wp_enqueue_script('print-btn-js', 'https://cdn.datatables.net/buttons/2.3.6/js/buttons.print.min.js', array('jquery'), '2.3.6', true);

    // Enqueue Bootstrap JS and your custom JS
    wp_enqueue_script('bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js', array('jquery'), '4.5.2', true);
    wp_enqueue_script('stdratecard-custom-scripts', plugin_dir_url(__FILE__) . 'js/custom-script.js', array('jquery'), '1.0', true);
}

add_action('admin_enqueue_scripts', 'stdratecard_enqueue_custom_styles_and_scripts');

// Fetch data from the database and region wise filteration- Aseema
function get_std_rate_card($locations = [], $downloadedOnStart = '', $downloadedOnEnd = '') {
    global $wpdb;
    $table_name = $wpdb->prefix . 'download_std_ratecard';
    $current_user = wp_get_current_user();
    $user_roles = $current_user->roles;
    $ba_region_location = get_user_meta($current_user->ID, 'ba_region_location', true);
    $sales_rep_region_location = get_user_meta($current_user->ID, 'sales_rep_region_location', true);

    // Start query with base table
    $query = "SELECT * FROM $table_name";
    $conditions = [];

    // Add role-based region filters
    if (in_array('rue_manager', $user_roles) && !empty($ba_region_location)) {
        $conditions[] = $wpdb->prepare("region = %s", $ba_region_location);
    } elseif (in_array('sales_representative', $user_roles) && !empty($sales_rep_region_location)) {
        $conditions[] = $wpdb->prepare("region = %s", $sales_rep_region_location);
    }

    // Handle multiple location filters
    if (!empty($locations) && is_array($locations)) {
        $placeholders = implode(',', array_fill(0, count($locations), '%s'));
        $conditions[] = $wpdb->prepare("location IN ($placeholders)", ...$locations);
    }

    // Handle date range between 2 dates or particular date filter
    if (!empty($downloadedOnStart) && !empty($downloadedOnEnd)) {
        if ($downloadedOnStart === $downloadedOnEnd) {
            // Exact match for a single date
            $conditions[] = $wpdb->prepare("DATE(downloaded_on) = %s", $downloadedOnStart);
        } else {
            // Range match between 2 dates
            $conditions[] = $wpdb->prepare("DATE(downloaded_on) >= %s", $downloadedOnStart);
            $conditions[] = $wpdb->prepare("DATE(downloaded_on) <= %s", $downloadedOnEnd);
        }
    } elseif (!empty($downloadedOnStart)) {
        $conditions[] = $wpdb->prepare("DATE(downloaded_on) >= %s", $downloadedOnStart);
    } elseif (!empty($downloadedOnEnd)) {
        $conditions[] = $wpdb->prepare("DATE(downloaded_on) <= %s", $downloadedOnEnd);
    }


    // Combine conditions into the query
    if (!empty($conditions)) {
        $query .= " WHERE " . implode(" AND ", $conditions);
    }

    // Sort by ID in descending order
    $query .= " ORDER BY id DESC";

    // Debugging: Log query and results
    if (defined('WP_DEBUG') && WP_DEBUG) {
        error_log("SQL Query: $query");
    }
    
    // Run the query and get results
    $results = $wpdb->get_results($query, ARRAY_A);

    if (defined('WP_DEBUG') && WP_DEBUG) {
        error_log("Results: " . print_r($results, true));
    }

    return $results;
}


// Display the data
function std_rate_card_list() {
    // Get the selected location filter from GET parameters
    $selectedLocations = isset($_GET['location_filter']) ? (array) $_GET['location_filter'] : [];
    $selectedStartDate = isset($_GET['downloaded_on_start']) ? sanitize_text_field($_GET['downloaded_on_start']) : '';
    $selectedEndDate = isset($_GET['downloaded_on_end']) ? sanitize_text_field($_GET['downloaded_on_end']) : '';
    $locations = get_unique_locations();

    $page_url = admin_url('admin.php?page=stdratecard-dashboard'); // Change to the actual 'page' slug in your admin menu

    $user_id = get_current_user_id();
    $visible_columns = get_user_meta($user_id, 'std_ratecard_visible_columns', true);
    $visible_columns = $visible_columns ? explode(',', $visible_columns) : ['machine_sr_no', 'actions'];

    // Get rate card list, filtered by location if a location was selected
    $stdList = get_std_rate_card($selectedLocations, $selectedStartDate, $selectedEndDate);
    ?>
    <div class="wrap stdratecard-wrap">
        <h1 class="wp-heading-inline mb-2 font-weight-bold">Standard Quote Downloads List</h1>
        <!-- Filter Form -->
        <form method="get" action="<?php echo esc_url($page_url); ?>" class="mb-3">
            <!-- Include necessary hidden fields for proper form submission -->
            <input type="hidden" name="page" value="stdratecard-dashboard"> <!-- Change to actual 'page' slug -->

            <label for="downloaded_on_start">Downloaded Between:</label>
            <input placeholder="Start date"
            class="textbox-n"
            type="date"
            name="downloaded_on_start" id="downloaded_on_start" value="<?php echo esc_attr($selectedStartDate); ?>"><span>  and  </span>

            <input placeholder="End date"
            class="textbox-n"
            type="date"
            name="downloaded_on_end" id="downloaded_on_end" value="<?php echo esc_attr($selectedEndDate); ?>">

            <div class="dropdown-location">
                <button type="button" class="dropdown-toggle-location">Select Locations</button>
                <div class="dropdown-menu-location">
                    <?php if ($locations): ?>
                        <?php foreach ($locations as $location): ?>
                            <label>
                                <input type="checkbox" name="location_filter[]" value="<?php echo esc_attr($location); ?>"
                                    <?php echo in_array($location, $selectedLocations) ? 'checked' : ''; ?>>
                                <?php echo esc_html($location); ?>
                            </label>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </div>
            </div>
            <input type="hidden" id="selected-locations" name="selected_locations" value="<?php echo esc_attr(implode(',', $selectedLocations)); ?>">
            <button type="submit" class="button button-primary">Filter</button>
        </form>

        <script>
        document.addEventListener("DOMContentLoaded", function () {
            const startDateInput = document.getElementById("downloaded_on_start");
            const endDateInput = document.getElementById("downloaded_on_end");
            const dropdown = document.querySelector(".dropdown-location");
            const dropdownToggle = document.querySelector(".dropdown-toggle-location");
            const dropdownMenu = document.querySelector(".dropdown-menu-location");
            const checkboxes = document.querySelectorAll(".dropdown-menu-location input[type='checkbox']");
            const selectedLocationsInput = document.getElementById("selected-locations");
            // Toggle dropdown
            dropdownToggle.addEventListener("click", function () {
                dropdownMenu.classList.toggle("show");
            });

            // Close dropdown if clicked outside
            document.addEventListener("click", function (event) {
                if (!dropdown.contains(event.target)) {
                    dropdownMenu.classList.remove("show");
                }
            });

            // Update hidden input with selected locations
            checkboxes.forEach(function (checkbox) {
                checkbox.addEventListener("change", function () {
                    const selected = Array.from(checkboxes)
                        .filter(c => c.checked)
                        .map(c => c.value);
                    selectedLocationsInput.value = selected.join(",");
                });
            });

            startDateInput.addEventListener("change", function () {
                endDateInput.min = startDateInput.value; 
                if (endDateInput.value && endDateInput.value < startDateInput.value) {
                    endDateInput.value = ""; 
                }
            });
         });
        </script>

        <button id="exportbutton" style="margin-top: -11px; padding: 5px 20px; background-color: #000; color: #FFBD2B; border-radius: 5px;flex-shrink: 0;">Export</button>
        
        <!-- Show More Columns Button -->
        
         <button id="toggle-dropdown" style="margin-bottom: 10px;padding: 5px;background-color: #000;color:#FFBD2B; border-radius:5px;">Show More Columns</button>

         <div id="dropdown" style="display: none; border: 1px solid #ccc; padding: 10px; width: 100%; background-color: white; position: relative;margin-bottom:30px;">
            <h6>Select Columns to Display:</h6>
            <form method="POST" action="">
                <div style="display: flex; flex-direction: row; flex-wrap: wrap; gap: 20px;">
                    
                    <label>
                        <input type="checkbox" name="columns[]" value="location" <?php checked(in_array('location', $visible_columns)); ?>> Site Location
                    </label>
                    <label>
                        <input type="checkbox" name="columns[]" value="calculated_price" <?php checked(in_array('calculated_price', $visible_columns)); ?>> Calculated Price
                    </label>
                    <label>
                        <input type="checkbox" name="columns[]" value="customer_status" <?php checked(in_array('customer_status', $visible_columns)); ?>> Customer Status
                    </label>
                    <label>
                        <input type="checkbox" name="columns[]" value="downloaded_on" <?php checked(in_array('downloaded_on', $visible_columns)); ?>> Downloaded On
                    </label>
                </div>
                <input type="submit" name="save_columns" value="Save Columns" style="margin-top: 10px;" class="button button-primary">
            </form>
        </div>
       
       
        <div class="table-responsive">
        <table id="stdratecard-table" class="table display pb-30 dataTable table-data"  style="width:100% !important;">
            <thead style="background-color:#FFBD2B;">
                <tr>
                    <th scope="row" class="manage-column">Sr. No</th>
        <!--                     <th scope="col" class="manage-column">User ID</th> -->
                    <th scope="col" class="manage-column">Customer Name</th>
                    <th scope="col" class="manage-column">Customer Email</th>
                    <th scope="col" class="manage-column">Customer Number</th>
        <!--                     <th scope="col" class="manage-column">Product ID</th> -->
                    <th scope="col" class="manage-column">Product Name</th>
                    <th scope="col" class="manage-column">Start Date</th>
                    <th scope="col" class="manage-column">End Date</th>
                    <th scope="col" class="manage-column">Shifts</th>
                    <th class="manage-column" 
                    <?php 
                        if (in_array('location', $visible_columns)) {
                            echo 'style="font-weight:700; width:75.5px;"' ;
                        } else {
                            echo 'style="display:none"';  // Hide column if not visible
                        }
                    ?>
                >Site Location</th>

                <th class="manage-column" 
                    <?php 
                        if (in_array('calculated_price', $visible_columns)) {
                            echo 'style="font-weight:700; width:75.5px;"' ;
                        } else {
                            echo 'style="display:none"';  // Hide column if not visible
                        }
                    ?>
                >Final Price</th>

                <th class="manage-column" 
                    <?php 
                        if (in_array('customer_status', $visible_columns)) {
                            echo 'style="font-weight:700; width:75.5px;"' ;
                        } else {
                            echo 'style="display:none"';  // Hide column if not visible
                        }
                    ?>
                >Customer Status</th>
                    
                <th class="manage-column" 
                    <?php 
                        if (in_array('downloaded_on', $visible_columns)) {
                            echo 'style="font-weight:700; width:75.5px;"' ;
                        } else {
                            echo 'style="display:none"';  // Hide column if not visible
                        }
                    ?>
                >Downloaded On</th>
                </tr>
            </thead>

            <tbody>
                <?php if ($stdList) : ?>
                    <?php $count = 1; ?>
                    <?php foreach ($stdList as $list) : ?>
					<?php
					$metaData = get_user_meta( $list['user_id'], 'sap_customer_id', $single = false );
					if(count($metaData)>0){
						$customerStatus = 'Exisiting Customer';
					}else{
						$customerStatus = 'New Customer';
					}
					$phone_number = get_user_meta($list['user_id'], 'billing_phone', true); 
										
					?>
                    
                        <tr>
                            <td><?php echo $count++; ?></td>
<!--                             <td><?php echo esc_html($list['user_id']); ?></td> -->
                            <td><?php echo esc_html($list['user_name']); ?></td>
                            <td><?php echo esc_html($list['user_email']); ?></td>
                            <td><?php echo esc_html($phone_number ? $phone_number : 'N/A'); ?></td>
<!--                             <td><?php echo esc_html($list['product_id']); ?></td> -->
                            <td><?php echo esc_html($list['product_name']); ?></td>
                            <td><?php echo esc_html(date('d-m-Y', strtotime($list['start_date']))); ?></td>
                            <td><?php echo esc_html(date('d-m-Y', strtotime($list['end_date']))); ?></td>
                            <td><?php echo esc_html($list['shift']); ?></td>
                            <td  <?php echo in_array('location', $visible_columns) ? '' : 'style="display:none"'; ?>>
                            <?php echo esc_html($list['location'] ? $list['location'] : 'N/A'); ?>
                            </td>

                            <td  <?php echo in_array('calculated_price', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($list['calculated_price']); ?></td>

                            <td  <?php echo in_array('customer_status', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($customerStatus); ?></td>
                            
							
							<td  <?php echo in_array('downloaded_on', $visible_columns) ? '' : 'style="display:none"'; ?>>
                            <?php echo esc_html(date("d-m-Y", strtotime($list['downloaded_on']))); ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php else : ?>
                    <!-- <tr>
                        <td colspan="11" class="no-quotes text-center">No Quote found.</td>
                    </tr> -->
                <?php endif; ?>
            </tbody>
        </table>
                </div>
    </div>
    <style>
         .dropdown-location {
        position: relative;
        display: inline-block;
        margin-bottom: 10px;
    }
    .dropdown-toggle-location {
        color: #000;
        background-color: #fff;
        padding: 5px 15px;
        border: 1px solid grey;
        cursor: pointer;
        border-radius: 5px;
    }
    .dropdown-menu-location {
        display: none;
        position: absolute;
        background: white;
        border: 1px solid #ccc;
        width: 220px;
        max-height: 250px; /* Allows scrolling for long lists */
        overflow-y: auto;
        box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.2);
        padding: 10px;
        border-radius: 5px;
        z-index: 1;
    }
    .dropdown-menu-location.show {
        display: block;
    }
    .dropdown-menu-location label {
        display: block;
        padding: 5px;
        cursor: pointer;
        font-size: 14px;
    }
    .dropdown-menu-location input[type='checkbox'] {
        margin-right: 8px;
    }
        /* Additional styles specific to this component */
        .page-numbers {
            display: inline-block;
            vertical-align: baseline;
            min-width: 30px;
            min-height: 30px;
            margin: 0;
            padding: 0 4px;
            font-size: 16px;
            line-height: 1.625;
            text-align: center;
            background: #fff;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .manage-column {
            font-size: 13px;
        }
        .table-responsive .dataTables_wrapper .dataTables_filter input {
            height:33px !important;
        }
        .table-responsive .table-data tr:nth-child(even) {
            background-color: #ffbd2b30  !important;
        }

        .table-responsive .dataTables_wrapper .dataTables_paginate .paginate_button.current {
            background: #FFBD2B !important;
        }
        #stdratecard-table tbody tr:nth-child(even):hover {
            background-color: #ffbd2b30;
            }
        #stdratecard-table tbody tr:nth-child(odd):hover {
        background-color: #fff;
        }
        .table-responsive .table-data.display tbody tr.even>.sorting_1 {
            background-color: #FFF;
        }
        .table-responsive .table-data.display tbody tr.odd>.sorting_1 {
            background-color: #FFF;
        }
        .table-responsive .dataTables_wrapper .dataTables_length select {
            padding: 0px 17px 1px 8px;
        }
        .table-responsive .table-data tr {
             height: 50px; /* Adjust the height as needed */
        }
        .table-responsive .table-data th, table.dataTable td {
        white-space: nowrap;
        vertical-align: middle;
        }
        .sticky-col {
            position: sticky;
            left: 0px;
            background-color:#FFBD2B;
            z-index: 1;
            width:20px !important;
        }
        .sticky-col-action {
            position: sticky;
            right: 0px;
            background-color: #fff;
            z-index: 2; 
        }
        .enquiry-export-btn .custom-btn {
            background-color: #000;
            color: #FFBD2B;
            font-weight: 600;

        }
        .enquiry-export-btn .custom-btn:hover  {
            color: #fff;
        }

        .table-responsive {
            overflow-x: auto;
        }
        .custom-button {
            background-color: black !important;
            color: #FFBD2B !important;
            padding: 2px 21px 4px 21px !important;
            border-radius: .25rem !important;
            font-weight: 600 !important;
            font-size: 16px !important;
        }
        #stdratecard-table_wrapper .dataTables_scrollHeadInner {
            width:unset !important;
        }
    </style>
     <script>
        // Initialize DataTable
        jQuery(document).ready(function($) {
            var dataTable = jQuery('#stdratecard-table').DataTable({
            "scrollX": true,
            
        });
            $('#toggle-dropdown').on('click', function() {
                $('#dropdown').toggle();
            });
            
            function exportTableToCSV() {
                var csv = [];
                var table = document.querySelector("#stdratecard-table");
                
                // Get visible table headers (column names)
                var headers = [];
                var headerCols = table.querySelectorAll("thead th");
                var visibleColumnsIndexes = []; // To track visible columns

                headerCols.forEach((header, index) => {
                    if (header.style.display !== "none") { // Check if the column is visible
                        headers.push(header.innerText.trim());
                        visibleColumnsIndexes.push(index); // Track visible column indexes
                    }
                });
                csv.push(headers.join(",")); // Push headers to CSV

                // Get table rows data
                var rows = table.querySelectorAll("tbody tr");
                rows.forEach((row) => {
                    var rowData = [];
                    var cols = row.querySelectorAll("td");
                    visibleColumnsIndexes.forEach((colIndex) => {
                        rowData.push(cols[colIndex].innerText.trim()); // Include only visible columns
                    });
                    csv.push(rowData.join(",")); // Add the row data to CSV
                });

                // Create a timestamp for the filename
                var date = new Date();
                var timestamp = date.toISOString().slice(0, 10).split("-").reverse().join("-"); 
                // Construct filename
                var filename = `StandardRateCard__${timestamp}.csv`;

                // Trigger CSV download
                downloadCSV(csv.join("\n"), filename);
            }

            function downloadCSV(csvContent, filename) {
                var csvBlob = new Blob([csvContent], { type: "text/csv" });
                var csvURL = window.URL.createObjectURL(csvBlob);
                var downloadLink = document.createElement("a");

                downloadLink.href = csvURL;
                downloadLink.download = filename;
                downloadLink.style.display = "none";

                document.body.appendChild(downloadLink);
                downloadLink.click();
                document.body.removeChild(downloadLink);
            }


            // Attach event listener to the export button
            document.getElementById("exportbutton").addEventListener("click", function() {
                exportTableToCSV("standard-rate-card-table.csv");
            });

           
        
        });
    </script>
    <?php

    if (isset($_POST['save_columns'])) {
        $selected_columns = isset($_POST['columns']) ? $_POST['columns'] : [];
        update_user_meta($user_id, 'std_ratecard_visible_columns', implode(',', $selected_columns));
        echo '<script>location.reload();</script>';
    }
    
}
// Helper function to get unique locations for the dropdown filter
function get_unique_locations() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'download_std_ratecard';
    $locations = $wpdb->get_col("SELECT DISTINCT location FROM $table_name WHERE location IS NOT NULL AND location != ''");
    return $locations;
}

function hide_screen_options_for_the_page() {
    ?>
    <style>
    <?php if (isset($_GET['page']) && $_GET['page'] === 'stdratecard-dashboard') : ?>
        #screen-meta-links {
            display: none !important;
        }
    <?php endif; ?>
    </style>
    <?php
}
add_action('admin_head', 'hide_screen_options_for_the_page');
?>

Youez - 2016 - github.com/yon3zu
LinuXploit