| Server IP : 13.126.101.145 / Your IP : 216.73.217.50 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/themes/hello-elementor-child/inc/ |
Upload File : |
<?php
error_reporting(0);
?>
<link rel="stylesheet" id="bootstrap-css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" media="all">
<link rel="stylesheet" id="datatables-css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css" media="all">
<link rel="stylesheet" id="fontawesome-css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" media="all">
<div class="wrap enquiry_wrap">
<h1 class="wp-heading-inline mb-2 font-weight-bold">Rental Enquiry</h1><br>
<!-- button and filter added -->
<div class="panel panel-default card-view">
<div class="top-header" style="display:flex;">
<div class="enquiry-export-btn"style="margin: 0px 20px 24px 0px;">
<button id="exportbutton" class="btn custom-btn" style="padding: 2px 21px 4px 21px;margin-top:-5px;" >Export</button>
<?php
// Get the current user's visible columns from their preferences
$user_id = get_current_user_id();
$visible_columns = get_user_meta($user_id, 'used_equipment_visible_columns', true);
$visible_columns = $visible_columns ? explode(',', $visible_columns) : ['machine_sr_no', 'actions'];
?>
<!-- for show more columns -->
<button id="toggle-dropdown" style="padding: 2px 6px 2px 6px;background-color: #000;color:#FFBD2B; border-radius:5px;flex-shrink: 0;margin-bottom:15px;">Show More Columns</button><br>
<!-- Filter by Status -->
<form method="GET" action="<?php echo admin_url('admin.php'); ?>" style="display: flex; flex-direction: column; gap: 10px;">
<input type="hidden" name="page" value="leads">
<div style="display: flex; align-items: center; gap: 10px;">
<!-- date filter -->
<label for="rental_startdate">Rental Start Date: </label>
<input type="date" id="rental_startdate" name="rental_startdate" value="<?php echo esc_attr($_GET['rental_startdate'] ?? ''); ?>">
<label for="rental_enddate">Rental End Date: </label>
<input type="date" id="rental_enddate" name="rental_enddate" value="<?php echo esc_attr($_GET['rental_enddate'] ?? ''); ?>">
<button type="submit" class="button button-primary" style="margin-left: 10px;width:70px;">Filter</button>
</div>
<div style="display: flex; align-items: center; gap: 10px;">
<select name="status_filter" id="status_filter" style="border-radius: 5px; border: 1px solid #ccc;">
<option value="">Filter By Status</option>
<?php
// Fetch distinct statuses from the database
global $wpdb;
$statuses = $wpdb->get_col("SELECT DISTINCT en_status FROM wp_leads WHERE en_status IS NOT NULL");
// Populate the dropdown with statuses
foreach ($statuses as $status) {
$selected = selected($_GET['status_filter'], $status, false);
echo "<option value='" . esc_attr($status) . "' $selected>" . esc_html($status) . "</option>";
}
?>
</select>
<!-- filter by region -->
<?php
$current_user = wp_get_current_user();
$user_roles = $current_user->roles;
if (!in_array('rue_manager', $user_roles) && !in_array('sales_representative', $user_roles)) :
?>
<select name="region_filter" id="region_filter" style="margin-left:5px;margin-right:5px;border-radius: 5px; border: 1px solid #ccc;">
<option value="">Filter By SBU</option>
<?php
// Fetch distinct statuses from the database
global $wpdb;
$regions = $wpdb->get_col("SELECT DISTINCT region FROM wp_leads WHERE region IS NOT NULL");
// Populate the dropdown with statuses
foreach ($regions as $region) {
$selected = selected($_GET['region_filter'], $region, false);
echo "<option value='" . esc_attr($region) . "' $selected>" . esc_html($region) . "</option>";
}
?>
</select>
<?php endif; ?>
<button type="submit" class="button button-primary" style="margin-left: 10px;width:70px;">Filter</button>
</div>
</form>
<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="rental_startdate" <?php checked(in_array('rental_startdate', $visible_columns)); ?>> Rental Start Date
</label>
<label>
<input type="checkbox" name="columns[]" value="rental_enddate" <?php checked(in_array('rental_enddate', $visible_columns)); ?>> Rental End Date
</label>
<label>
<input type="checkbox" name="columns[]" value="product_name" <?php checked(in_array('product_name', $visible_columns)); ?>> Product Name
</label>
<label>
<input type="checkbox" name="columns[]" value="additional_equipement" <?php checked(in_array('additional_equipement', $visible_columns)); ?>> Additional Equipment
</label>
<label>
<input type="checkbox" name="columns[]" value="location" <?php checked(in_array('location', $visible_columns)); ?>> Location
</label>
<label>
<input type="checkbox" name="columns[]" value="region" <?php checked(in_array('region', $visible_columns)); ?>> Region
</label>
<label>
<input type="checkbox" name="columns[]" value="user_note" <?php checked(in_array('user_note', $visible_columns)); ?>> User Note
</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="status" <?php checked(in_array('status', $visible_columns)); ?>> Status
</label>
<label>
<input type="checkbox" name="columns[]" value="customer_id" <?php checked(in_array('customer_id', $visible_columns)); ?>> Customer Id
</label>
<label>
<input type="checkbox" name="columns[]" value="ba_remarks" <?php checked(in_array('ba_remarks', $visible_columns)); ?>> BA Remarks
</label>
<label>
<input type="checkbox" name="columns[]" value="last_updated" <?php checked(in_array('last_updated', $visible_columns)); ?>> Last Updated
</label>
</div>
<input type="submit" name="save_columns" value="Save Columns" style="margin-top: 10px;" class="button button-primary">
</form>
</div>
</div>
</div>
<!-- /end button and filter added -->
<div class="table-responsive">
<table id="guestEnqTable" class="table mb-4 display pb-30 dataTable table-data">
<thead style="background-color:#FFBD2B;">
<tr>
<th scope="row" class="manage-column sticky-col">Sr. No</th>
<th scope="col" class="manage-column">Lead ID</th>
<th scope="col" class="manage-column">Date Raised</th>
<th scope="col" class="manage-column">User Name</th>
<th scope="col" class="manage-column">User Email</th>
<th scope="col" class="manage-column">Phone</th>
<th scope="col"class="manage-column"
<?php
if (in_array('rental_startdate', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Rental Start Date</th>
<th scope="col"class="manage-column"
<?php
if (in_array('rental_enddate', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Rental End Date</th>
<th scope="col"class="manage-column"
<?php
if (in_array('product_name', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Product Name</th>
<th scope="col"class="manage-column"
<?php
if (in_array('additional_equipement', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Additional Equipement</th>
<th scope="col"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
}
?>
>Location</th>
<th scope="col"class="manage-column"
<?php
if (in_array('region', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Region</th>
<th scope="col"class="manage-column"
<?php
if (in_array('user_note', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>User Note</th>
<th scope="col"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 scope="col"class="manage-column"
<?php
if (in_array('status', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Status</th>
<th scope="col"class="manage-column"
<?php
if (in_array('customer_id', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Customer ID</th>
<th scope="col"class="manage-column"
<?php
if (in_array('ba_remarks', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>BA remarks</th>
<th scope="col"class="manage-column"
<?php
if (in_array('last_updated', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Last Updated</th>
<th scope="row" class="manage-column sticky-col-action" style="background-color:#FFBD2B;">Action</th>
</tr>
</thead>
<tbody>
<?php
global $wpdb;
$current_user = wp_get_current_user();
$user_roles = $current_user->roles;
$rental_startdate = isset($_GET['rental_startdate']) ? $_GET['rental_startdate'] : '';
$rental_enddate = isset($_GET['rental_enddate']) ? $_GET['rental_enddate'] : '';
// $query = "SELECT * FROM wp_leads";
$query = "SELECT * FROM wp_leads WHERE 1=1";
$sales_rep_region_location = get_user_meta($current_user->ID, 'sales_rep_region_location', true);
$rue_region_location = get_user_meta($current_user->ID, 'ba_region_location', true);
if (in_array('rue_manager', $user_roles) && !empty($rue_region_location)) {
if (is_array($rue_region_location)) {
$placeholders = implode(',', array_fill(0, count($rue_region_location), '%s'));
$query .= $wpdb->prepare(" AND region IN ($placeholders)", ...$rue_region_location);
} else {
$query .= $wpdb->prepare(" AND region = %s", $rue_region_location);
}
}
elseif (in_array('sales_representative', $user_roles) && !empty($sales_rep_region_location)){
$query .= $wpdb->prepare(" WHERE region = %s", $sales_rep_region_location);
}
// Apply the status filter if selected
if (!empty($_GET['status_filter'])) {
$status_filter = sanitize_text_field($_GET['status_filter']);
$query .= (strpos($query, 'WHERE') !== false ? " AND" : " WHERE") . $wpdb->prepare(" en_status = %s", $status_filter);
}
if (!empty($_GET['region_filter'])) {
$region_filter = sanitize_text_field($_GET['region_filter']);
$query .= (strpos($query, 'WHERE') !== false ? " AND" : " WHERE") . $wpdb->prepare(" region = %s", $region_filter);
}
// Append date conditions if selected
if (!empty($rental_startdate) && !empty($rental_enddate)) {
$query .= $wpdb->prepare(" AND rental_startdate >= %s AND rental_enddate <= %s", $rental_startdate, $rental_enddate);
} elseif (!empty($rental_startdate)) {
$query .= $wpdb->prepare(" AND rental_startdate >= %s", $rental_startdate);
} elseif (!empty($rental_enddate)) {
$query .= $wpdb->prepare(" AND rental_enddate <= %s", $rental_enddate);
}
$query .= " ORDER BY id DESC";
$res = $wpdb->get_results($query);
$i = 1;
foreach ($res as $row) {
$userid = $row->user_id;
if ($userid == 0) {
$leadstatus = 'Guest User';
$sap_customer_id = 'N/A';
} else {
$metaData = get_user_meta($userid, 'sap_customer_id', $single = false);
if (!empty($metaData[0])) {
$sap_customer_id = $metaData[0] ?? 'N/A';
$leadstatus = 'Existing Customer';
} else {
$sap_customer_id = 'N/A';
$leadstatus = 'RMS User';
}
}
?>
<tr>
<td class="sticky-col"><?php echo $i; ?></td>
<td><?php echo $row->lead_id; ?></td>
<td><?php echo date("d-m-Y", strtotime($row->lead_created_on)); ?></td>
<td><?php echo $row->full_name; ?></td>
<td><?php echo $row->lead_email; ?></td>
<td><?php echo $row->lead_phone; ?></td>
<!-- <td><?php echo date('d-m-y', strtotime($row->rental_startdate)); ?></td> -->
<td <?php echo in_array('rental_startdate', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php echo date('d-m-Y', strtotime($row->rental_startdate)); ?>
</td>
<td c <?php echo in_array('rental_enddate', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php echo date('d-m-Y', strtotime($row->rental_enddate)); ?>
</td>
<td <?php echo in_array('product_name', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($row->product_name); ?></td>
<td <?php echo in_array('additional_equipement', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($row->subsidary_products); ?></td>
<td <?php echo in_array('location', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($row->location); ?></td>
<td <?php echo in_array('region', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($row->region); ?></td>
<td <?php echo in_array('user_note', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($row->remarks); ?></td>
<td <?php echo in_array('customer_status', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($leadstatus); ?></td>
<td <?php echo in_array('status', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php
// 12-11-2024 Shejad
$user = get_user_by('email', $row->lead_email);
$lead_id = $row->id;
global $wpdb;
$rfq_exists_for_enquiry = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM {$wpdb->prefix}request_quote WHERE enquiry_id = %d",
$lead_id
));
// Display the lead status
echo esc_html($row->en_status);
?>
</td>
<td <?php echo in_array('customer_id', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($sap_customer_id); ?></td>
<td <?php echo in_array('ba_remarks', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($row->ba_remarks); ?></td>
<td <?php echo in_array('last_updated', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php
if (empty($row->last_updated_on)) {
echo 'N/A';
} else {
echo esc_html(date("d-m-y", strtotime($row->last_updated_on)));
}
?>
</td>
<!-- Aseema -->
<td class="sticky-col-action">
<?php
// Display "Create User" icon if it's a guest user and no user account exists
if ($leadstatus == 'Guest User' && !$user) { ?>
<a href="<?php echo admin_url('user-new.php'); ?>" target="_blank" title="Create User">
<i class="fas fa-user-plus"></i>
</a>
<?php } else { ?>
<a href="#" class="disabled-link" onclick="return false;"><i class="fas fa-user-plus" style="color: gray;"></i></a>
<?php } ?>
<!-- Always show the Edit icon -->
<a href="<?php echo admin_url('admin.php?page=edit-enquiry&id=' . $row->id); ?>" title="Edit"><i class="fas fa-edit"></i></a>
<?php
// Set the style and functionality for the "Create RFQ" icon
$rfq_disabled = $rfq_exists_for_enquiry ? 'disabled-link' : '';
$rfq_onclick = $rfq_exists_for_enquiry ? 'onclick="return false;"' : '';
$rfq_color = $rfq_exists_for_enquiry ? 'color: gray;' : '';
?>
<!-- "Create RFQ" icon, greyed out if RFQ exists -->
<a href="<?php echo $rfq_exists_for_enquiry ? '#' : admin_url('admin.php?page=create-rfq&enquiry_id=' . $lead_id); ?>"
target="_blank"
title="Create RFQ"
class="<?php echo esc_attr($rfq_disabled); ?>"
<?php echo $rfq_onclick; ?>>
<i class="fas fa-file-alt" style="<?php echo esc_attr($rfq_color); ?>"></i>
</a>
</td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
</div>
</div>
</div>
<style>
/* Additional styles specific to this component */
#screen-meta-links {
display: none !important;
}
.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;
}
#guestEnqTable tbody tr:nth-child(even):hover {
background-color: #ffbd2b30;
}
#guestEnqTable 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 !important;
left: 0px;
background-color:#FFBD2B;
z-index: 1;
width:20px !important;
}
.sticky-col-action {
position: sticky !important;
right: 0px;
background-color: #fff;
z-index: 2; /* Ensure it's above other cells */
}
.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;
}
#guestEnqTable_wrapper .dataTables_scroll .dataTables_scrollHead .dataTables_scrollHeadInner table {
margin-left:unset !important;
margin:auto !important;
}
.dataTables_scrollHeadInner {
width:unset !important;
}
.enquiry_wrap {
background-color: #f9f9f9;
padding: 20px;
border-radius: 8px;
}
</style>
<script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js?ver=1.10.24" id="datatables-js-js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js?ver=4.5.2" id="bootstrap-js-js"></script>
<!-- script for export -->
<script>
var dataTable = jQuery('#guestEnqTable').DataTable({
"scrollX": true,
});
jQuery('#toggle-dropdown').on('click', function() {
jQuery('#dropdown').toggle();
});
function exportTableToCSV(filename) {
var csv = [];
var rows = document.querySelectorAll("#guestEnqTable tbody tr");
// Get table headers (column names)
var headers = [];
var visibleColumnIndexes = [];
var headerCols = document.querySelectorAll("#guestEnqTable thead th");
for (var k = 0; k < headerCols.length; k++) {
var headerText = headerCols[k].innerText.trim().toLowerCase(); // Normalize header text
if (headerCols[k].offsetParent !== null && headerText !== "action") {
// Only push if column is visible and not "Actions"
headers.push(headerCols[k].innerText.trim());
visibleColumnIndexes.push(k); // Store index of visible non-"Actions" columns
}
}
csv.push(headers.join(",")); // Push headers to CSV
// Get table rows data
for (var i = 0; i < rows.length; i++) {
var row = [];
var cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++) {
if (visibleColumnIndexes.includes(j)) {
// Only include data from visible columns (excluding "Actions")
row.push(cols[j].innerText.trim());
}
}
csv.push(row.join(","));
}
var date = new Date();
var timestamp = date.toISOString().slice(0, 10).split("-").reverse().join("-");
// Add timestamp to filename
var fullFilename = `Enquiry__${timestamp}.csv`;
// Download CSV file
downloadCSV(csv.join("\n"), fullFilename);
}
function downloadCSV(csv, filename) {
var csvFile = new Blob([csv], { type: "text/csv" });
var downloadLink = document.createElement("a");
downloadLink.download = filename;
downloadLink.href = window.URL.createObjectURL(csvFile);
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
document.getElementById("exportbutton").addEventListener("click", function() {
exportTableToCSV("guestEnqTable.csv");
});
</script>
<?php
if (isset($_POST['save_columns'])) {
$selected_columns = isset($_POST['columns']) ? $_POST['columns'] : [];
update_user_meta($user_id, 'used_equipment_visible_columns', implode(',', $selected_columns));
echo '<script>location.reload();</script>';
}