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.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/plugins/operators/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

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

function status_enqueue_custom_styles_and_scripts($hook) {
	if (isset($_GET['page']) && $_GET['page'] === 'operational-status') {
		// 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');

		// 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 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);

		// 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);
	}
}

add_action('admin_enqueue_scripts', 'status_enqueue_custom_styles_and_scripts');

function operational_status() {
	global $wpdb;

	try {
		$table = $wpdb->prefix . 'operational_status';
		$results = $wpdb->get_results("SELECT * FROM $table ORDER BY id DESC");

		// helper: robust parser & normalizer
		$normalize_date = function($raw) {
			if (empty($raw)) {
				return 'NA';
			}
			$raw = trim($raw);

			// numeric timestamp (10s = sec, 13s = ms)
			if (preg_match('/^\d{10}$/', $raw) || preg_match('/^\d{13}$/', $raw)) {
				$ts = (strlen($raw) === 13) ? (int)($raw / 1000) : (int)$raw;
				return date('d-m-Y', $ts);
			}

			// try several known formats strictly
			$formats = [
				'Y-m-d H:i:s',
				'Y-m-d',
				'd-m-Y H:i:s',
				'd-m-Y',
				'd/m/Y H:i:s',
				'd/m/Y',
				'm/d/Y',
				'd M Y',
				'M d, Y'
			];

			foreach ($formats as $fmt) {
				$dt = DateTime::createFromFormat($fmt, $raw);
				// check for parse errors
				$errors = DateTime::getLastErrors();
				if ($dt !== false && empty($errors['warning_count']) && empty($errors['error_count'])) {
					return $dt->format('d-m-Y');
				}
			}

			// fallback to strtotime (handles many formats)
			$ts = strtotime(str_replace('/', '-', $raw));
			if ($ts !== false && $ts !== -1) {
				return date('d-m-Y', $ts);
			}

			// unknown format - return raw so you can see what's stored
			return $raw;
		};

?>
<div class="wrap rfq-wrap">
	<h1 class="wp-heading-inline mb-2 font-weight-bold">Operational Status</h1>
	<div class="table-responsive">
		<table id="operational-status-table" class="table display pb-30 dataTable table-data">
			<thead style="background-color:#FFBD2B;">
				<tr>
					<th>Sr. No</th>
					<th>ID</th>
					<th>User</th>
					<th>Customer</th>
					<th>Contract ID</th>
					<th>Start Date</th>
					<th>End Date</th>
					<th>Note</th>
					<th>Log Date</th>
					<th>Total Hours</th>
					<th>Images</th>
				</tr>
			</thead>
			<tbody>
				<?php
		$i = 1;
		if ($results) {
			foreach ($results as $row) {
				$user_name     = 'NA';
				$customer_name = 'NA';
				$contract_id   = 'NA';
				$start_date    = 'NA';
				$end_date      = 'NA';

				if ($row->user_id) {
					$user_info = get_userdata($row->user_id);
					if ($user_info) {
						$user_name = $user_info->display_name;
					}

					// try to find contract_id in user meta
					$contractId = get_user_meta((int)$row->user_id, 'contract_id', true);

					if (!empty($contractId)) {
						$order = wc_get_order($contractId);
						if ($order) {
							$contract_id = $order->get_id();
							$customer_name = trim($order->get_billing_first_name() . ' ' . $order->get_billing_last_name());

							// primary: order meta
							$stdt = $order->get_meta('start_date', true);
							$enddt = $order->get_meta('end_date', true);

							// fallback: check each order item meta (sometimes plugins store dates per item)
							if (empty($stdt) || empty($enddt)) {
								foreach ($order->get_items() as $order_item) {
									if (empty($stdt)) {
										$item_s = $order_item->get_meta('start_date', true);
										if (!empty($item_s)) {
											$stdt = $item_s;
										}
									}
									if (empty($enddt)) {
										$item_e = $order_item->get_meta('end_date', true);
										if (!empty($item_e)) {
											$enddt = $item_e;
										}
									}
									if (!empty($stdt) && !empty($enddt)) break;
								}
							}

							// normalize for display
							$start_date = $normalize_date($stdt);
							$end_date   = $normalize_date($enddt);
						}
					}
				}

				// images
				$image_html = 'No Image';
				if (!empty($row->images)) {
					$image_urls = explode(',', $row->images);
					$first_img  = trim($image_urls[0]);
					$image_html = "<img src='" . esc_url($first_img) . "' width='50' height='50' style='cursor:pointer;' class='op-status-image' data-toggle='modal' data-target='#opImageModal{$row->id}'>";
				}
				?>
				<tr>
					<td><?php echo esc_html($i); ?></td>
					<td><?php echo esc_html($row->id); ?></td>
					<td><?php echo esc_html($user_name); ?></td>
					<td><?php echo esc_html($customer_name); ?></td>
					<td><?php echo esc_html($contract_id); ?></td>
					<td><?php echo esc_html($start_date); ?></td>
					<td><?php echo esc_html($end_date); ?></td>
					<td><?php echo esc_html($row->note); ?></td>
					<td><?php echo esc_html($row->created_on); ?></td>
					<td><?php echo esc_html($row->total_hours); ?></td>
					<td><?php echo $image_html; ?></td>
				</tr>
				<?php
				$i++;
			}
		} else {
			echo "<tr><td colspan='11'>No records found</td></tr>";
		}
				?>
			</tbody>
		</table>
	</div>
</div>

<script>
	jQuery(document).ready(function($) {
		$('#operational-status-table').DataTable({
			autoWidth: true,
			scrollX: false,
			columnDefs: [
				{ targets: '_all', className: 'dt-nowrap' } // prevent text wrapping
			]
		});
	});
</script>
<?php
	} catch (Exception $e) {
		error_log('Error in operational_status_list: ' . $e->getMessage());
		echo '<div class="error"><p>An error occurred while loading Operational Status data.</p></div>';
	}
}



Youez - 2016 - github.com/yon3zu
LinuXploit