| Server IP : 13.126.101.145 / Your IP : 216.73.217.37 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/Vision Link/ |
Upload File : |
<?php
/**
* Plugin Name: Vision Link
* Description: Displays static equipment data in a beautiful DataTable.
* Version: 1.0.2
* Author: Itrosys
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
include plugin_dir_path(__FILE__) . "smu_monitoring.php";
include plugin_dir_path(__FILE__) . "rms_monitoring.php";
include plugin_dir_path(__FILE__) . "financial_monitoring.php";
include plugin_dir_path(__FILE__) . "indicative_billing.php";
include plugin_dir_path(__FILE__) . "fault_report.php";
// Enqueue DataTables CSS & JS
function vision_link_enqueue_assets($hook) {
if ($hook !== 'toplevel_page_vision_link') {
return;
}
wp_enqueue_style('datatable-css', 'https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css');
wp_enqueue_style('datatable-bootstrap-css', 'https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap5.min.css');
wp_enqueue_script('jquery');
wp_enqueue_script('datatable-js', 'https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js', array('jquery'), null, true);
wp_enqueue_script('datatable-bootstrap-js', 'https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap5.min.js', array('jquery', 'datatable-js'), null, true);
}
add_action('admin_enqueue_scripts', 'vision_link_enqueue_assets');
// Create Admin Menu
function vision_link_create_menu() {
add_menu_page('Vision Link', 'Vision Link', 'manage_options', 'vision_link', 'vision_link_display_page', 'dashicons-chart-line', 6);
// Submenus
add_submenu_page('vision_link', 'Rental Machines', 'Rental Machines', 'manage_options', 'vision_link_page_rms_monitoring', 'rms_monitoring_display_page');
add_submenu_page('vision_link', 'SMU Hours', 'SMU Hour', 'manage_options', 'vision_link_page_smu_monitoring', 'smu_monitoring_display_page');
add_submenu_page('vision_link', 'Financial Monitoring', 'Financial Monitoring', 'manage_options', 'vision_link_page_financial_monitoring', 'financial_monitoring_display_page');
add_submenu_page('vision_link', 'Indicative Billing', 'Indicative Billing', 'manage_options', 'vision_link_page_indicative_billing', 'indicative_billing_display_page');
// ✅ Added Fault Report submenu
add_submenu_page('vision_link', 'Fault Report', 'Fault Report', 'manage_options', 'vision_link_page_fault_report', 'fault_report_display_page');
}
add_action('admin_menu', 'vision_link_create_menu');
// Display Plugin Page
function vision_link_display_page() {
global $wpdb;
$table_name = $wpdb->prefix . "equipment_utilization";
$makes = $wpdb->get_results("SELECT DISTINCT make FROM $table_name");
$user_id = get_current_user_id();
$visible_columns = get_user_meta($user_id, 'asset_monitoring_visible_columns', true);
$visible_columns = $visible_columns ? explode(',', $visible_columns) : ['machine_sr_no', 'actions'];
?>
<style>
.table-responsive .table-data tr:nth-child(even) {
background-color: #ffbd2b30 !important;
}
#vision-link-table tbody tr:nth-child(odd) {
background-color: #fff !important;
}
button#show-settings-link {
display: none;
}
.loading-message {
display: none;
color: blue;
font-weight: bold;
}
.success-message {
display: none;
color: green;
font-weight: bold;
}
</style>
<div class="wrap table-responsive">
<br>
<h1 style="margin-bottom: 15px;">Asset Monitoring</h1>
<!-- <button id="toggle-dropdown" style="margin-top: -11px; padding: 5px 20px; background-color: #000; color: #FFBD2B; border-radius: 5px;">Show More Columns</button> -->
<!-- added -->
<div id="column-dropdown" style="display: none; border: 1px solid #ccc; padding: 10px; background-color: white; margin-top: 10px;margin-bottom:20px;">
<h2>Select Columns to Display:</h2>
<form id="column-selection-form">
<label><input type="checkbox" class="column-toggle" data-column="6" checked> Distance Travleed</label>
<label><input type="checkbox" class="column-toggle" data-column="7" checked> Odometer</label>
<label><input type="checkbox" class="column-toggle" data-column="8" checked> Target Runtime Hours</label>
<label><input type="checkbox" class="column-toggle" data-column="9" checked> Device Status</label>
<label><input type="checkbox" class="column-toggle" data-column="10" checked>Asset Status</label>
<br><br>
<button type="button" id="apply-columns" class="button button-primary">Apply</button>
</form>
</div>
<!-- /end added -->
<button id="exportbutton-asset" style="margin-top: -11px; padding: 5px 20px; background-color: #000; color: #FFBD2B; border-radius: 5px;flex-shrink: 0;">Export</button>
<span>Filter By Date</span>
<input type="date" id="date-filter" style="margin-right: 10px;">
<button id="select-period" style="margin-bottom: 10px;padding: 5px;background-color:rgb(226, 158, 11);color:#fff; border-radius:5px; border: 1px solid rgb(226, 158, 11);">Filter</button>
<button id="fetchApiData" style="margin-bottom: 10px;margin-left:10px;padding: 5px;background-color: #000;color:#FFBD2B; border-radius:5px">Fetch Latest Data</button>
<span class="loading-message">Fetching data, please wait... it will take less than 1 minute</span>
<span class="success-message">Data fetched successfully!</span>
<br><br>
<select id="make-filter" style="margin-bottom: 10px; padding: 5px;">
<option value="">Filter By make</option>
<?php foreach ($makes as $make) { ?>
<option value="<?= esc_attr($make->make); ?>"><?= esc_html($make->make); ?></option>
<?php } ?>
</select>
<button id="filter-btn" style="margin-bottom: 10px;padding: 5px;background-color:rgb(226, 158, 11);color:#fff; border-radius:5px; border: 1px solid rgb(226, 158, 11);">Filter</button>
<br><br>
<table id="vision-link-table" class="table table-striped table-bordered table-data" style="width:100%">
<thead style="background-color:#FFBD2B;" class="table-dark">
<tr>
<th>Sr No</th>
<th>Equipment Name</th>
<th>Make</th>
<th>Model</th>
<th>Serial Number</th>
<th>Local Date</th>
<th>Hour Meter</th>
<!-- <th>Runtime Hours</th> -->
<!-- <th>Distance Traveled</th>
<th>Odometer</th>
<th>Target Runtime Hours</th>
<th>Device Status</th>
<th>Asset Status</th> -->
</tr>
</thead>
</table>
</div>
<script>
jQuery(document).ready(function($) {
var table = $('#vision-link-table').DataTable({
"processing": true,
"serverSide": false,
"ajax": {
"url": ajaxurl,
"type": "POST",
"data": function(d) {
d.action = 'fetch_filtered_data';
d.make = $('#make-filter').val();
d.date = $('#date-filter').val();
}
},
"paging": true,
"searching": true,
"ordering": true,
"info": true
});
$('#filter-btn').on('click', function() {
table.ajax.reload();
});
$('#select-period').on('click', function() {
table.ajax.reload();
});
$('#fetchApiData').on('click', function() {
$('.loading-message').show();
$('.success-message').hide();
fetch(ajaxurl, {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: 'action=fetch_api_data'
})
.then(response => response.json())
.then(data => {
$('.loading-message').hide();
$('.success-message').show();
table.ajax.reload();
})
.catch(error => {
$('.loading-message').hide();
alert('Error fetching data! api response not received');
console.error('Error:', error);
});
});
$('#toggle-dropdown').on('click', function() {
$('#column-dropdown').toggle();
});
// for export
function exportTableToCSV() {
var csv = [];
var table = document.querySelector("#vision-link-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 = `AssetMonitor__${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-asset").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, 'asset_monitoring_visible_columns', implode(',', $selected_columns));
echo '<script>location.reload();</script>';
}
}
// Handle AJAX request for filtering data
function fetch_filtered_data() {
global $wpdb;
// Define custom database name
// Local
// $custom_db = new wpdb('root', '', 'visionlink_db', 'localhost');
// Production
$custom_db = new wpdb('vision', 'Passrms!123', 'visionlink_db', 'localhost');
// Define table name (without prefix, since it's a custom DB)
$table_name = "wp_equipment_utilization";
$selectedmake = isset($_POST['make']) ? sanitize_text_field($_POST['make']) : '';
$selectedDate = isset($_POST['date']) ? sanitize_text_field($_POST['date']) : '';
$query = "SELECT * FROM `$table_name` WHERE 1=1";
if (!empty($selectedmake)) {
$query .= $custom_db->prepare(" AND make = %s", $selectedmake);
}
if (!empty($selectedDate)) {
$query .= $custom_db->prepare(" AND DATE(latest_report) = %s", $selectedDate);
}
$results = $custom_db->get_results($query);
$data = [];
$sr_no = 1;
foreach ($results as $row) {
$data[] = [
$sr_no,
esc_html($row->product_family),
esc_html($row->make),
esc_html($row->model),
esc_html($row->serial_number),
esc_html($row->latest_report),
esc_html($row->hour_meter),
esc_html($row->runtime_hours),
esc_html($row->distance_traveled),
esc_html($row->odometer),
esc_html($row->target_runtime_hours),
esc_html($row->device_status),
esc_html($row->asset_status),
];
$sr_no++;
}
echo json_encode(["data" => $data]);
wp_die();
}
add_action('wp_ajax_fetch_filtered_data', 'fetch_filtered_data');
add_action('wp_ajax_nopriv_fetch_filtered_data', 'fetch_filtered_data'); // For non-logged-in users