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-inspection.php
<?php
// Ensure the file is not accessed directly
if (!defined('ABSPATH')) {
    exit;
}

// Add admin menu
// add_action('admin_menu', 'inspection_admin_menu');
// function inspection_admin_menu() {
//     add_submenu_page(
//         'operator-dashboard',
//         'Initial Inspection',    // Page title
//         'Initial Inspection',    // Menu title
//         'manage_options',    // Capability
//         'initial-inspection',     // Menu slug
//         'initial_inspection',// Callback function
//         'dashicons-media-interactive', // Icon URL
//         6                    // Position
//     );

// 	add_submenu_page(null, //parent slug
// 	'Edit Initial Inspection', //page title
// 	'Edit', //menu title
// 	'manage_options', //capability
// 	'edit-initial-inspection', //menu slug
// 	'edit_initial_inspection'); //function
	
// }
function inspection_enqueue_custom_styles_and_scripts() {
    // Check if we're on the specific page using the page parameter
    if (isset($_GET['page']) && $_GET['page'] === 'initial-inspection') {
        // 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 your custom CSS
        wp_enqueue_style('rfq-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(
        //     'bootstrap-bundle-js',
        //     'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js',
        //     array(),
        //     '5.3.0',
        //     true
        // );

		wp_enqueue_script(
            'bootstrap-bundle-js',
            'https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js',
            array(),
            '5.3.0',
            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('rfq-custom-scripts', plugin_dir_url(__FILE__) . 'js/custom-script.js', array('jquery'), '1.0', true);
    }
}
add_action('admin_enqueue_scripts', 'inspection_enqueue_custom_styles_and_scripts');

// Display the data

function initial_inspection() {
    global $wpdb;
    $user = wp_get_current_user();
    if ( in_array( 'operator', (array) $user->roles ) ) {
        $table_name = $wpdb->prefix . 'service_request';
      echo  $user_id = $user->ID;
        $results = $wpdb->get_results("SELECT * FROM $table_name where operator_id=$user_id and stype=1 order by id desc");
    } else if(in_array( 'administrator', (array) $user->roles ) || in_array( 'central_administrator', (array) $user->roles )){
        $table_name = $wpdb->prefix . 'service_request';
        $results = $wpdb->get_results("SELECT * FROM $table_name where stype=1 order by id desc");
		
    }
    ?>
    <div class="wrap rfq-wrap">
        <h1 class="wp-heading-inline mb-2 font-weight-bold">Check-In Inspection</h1>
        <div class="table-responsive">
        <table id="servicereq-table" class="table mb-4 display pb-30 dataTable table-data">
            <thead style="background-color:#FFBD2B;">
                <tr>
                    <th scope="row" class="manage-column">Sr. No</th>
					<th scope="col" class="manage-column">RMS Contract ID</th>
                    <th scope="col" class="manage-column">Operator Name</th>
                    <th scope="col" class="manage-column">Equipment Name</th>
                    <th scope="col" class="manage-column">Operator Remarks</th>
                    <th scope="col" class="manage-column">Status</th>
                    <th scope="col" class="manage-column">Created On</th>
                    <th scope="col" class="manage-column">Image</th>
                    <th scope="col" class="manage-column">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php
                    $i = 1;
                    foreach($results as $result){
                        $user_info = get_userdata($result->operator_id);
						$user_name = ($user_info && !is_wp_error($user_info)) ? $user_info->first_name : 'N/A';
                        ?>
                        <tr>
                            <td><?php echo $i;?></td>
							<td><?php echo $result->order_id;?></td>
                            <td><?php echo $user_name;?></td>
                            <td>
                            <?php 
                            $product = wc_get_product( $result->equipment_id );
							$product_title = ($product) ? $product->get_title() : 'Unknown Product';
                            echo $product_title;
                            ?>
                            </td>
                            <td style="max-width:250px; word-wrap:break-word; overflow:hidden; text-overflow:ellipsis; white-space:normal;">
                               <?php echo $result->ins_remarks;?>
                            </td>
                            <td><?php echo $result->status;?></td>
							<td><?php 
                                $uk_time = strtotime($result->created_on);
                                $ist_time = $uk_time + (5 * 3600) + (30 * 60); // Add 5 hours and 30 minutes (in seconds)
                                echo date('d-m-Y', $ist_time);
                                 ?>
							</td>
							<td>
                                <?php
                                $attachment_table = $wpdb->prefix . 'service_attachment_docs';
                                $attachments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $attachment_table WHERE log_id = %d", $result->id));

                                if (!empty($attachments)) {
                                    foreach ($attachments as $attachment) {
                                        $image_url = esc_url(site_url('/wp-content/uploads/operator-service-request-attachments/' . $attachment->attachment));
                                        echo "<img src='{$image_url}' width='50' height='50' class='service-image' data-toggle='modal' data-target='#imageModal{$result->id}' style='cursor: pointer; margin-right: 5px;'>";
                                    }
                                } else {
                                    $images = $result->images;
                                    if (!empty($images)) {
                                        $image_urls = explode(',', $images); // Split by comma
                                        foreach ($image_urls as $img) {
                                            $img = trim($img);
                                            if (!empty($img)) {
                                                echo "<img src='{$img}' width='50' height='50' class='service-image' data-toggle='modal' data-target='#imageModal{$result->id}' style='cursor: pointer; margin-right: 5px;'>";
                                            }
                                        }
                                    } else {
                                        echo "No Image";
                                    }
                                }
                                ?>
                            </td>
                            <td>
								<!-- <a href="<?php echo admin_url('admin.php?page=edit-initial-inspection&id=' . $result->id); ?>"><i class="fas fa-edit" ></i></a> -->
								<?php if ($result->status === 'Completed'): ?>
									<i class="fas fa-edit" style="color: #ccc; cursor: not-allowed;"></i>
								<?php else: ?>
									<a href="<?php echo admin_url('admin.php?page=edit-initial-inspection&id=' . $result->id); ?>"><i class="fas fa-edit"></i></a>
								<?php endif; ?> 
								| 
								<a href="#" data-toggle="modal" data-target="#insModal<?php echo $result->id;?>"><i class="fas fa-eye"></i></a>
							</td>
                        </tr>
                       
                        <?php
                        $i++;
                    }
                ?>
            </tbody>
        </table>




<?php foreach($results as $result): ?>
    <?php 
        $user_info = get_userdata($result->operator_id);
        $user_name = ($user_info && !is_wp_error($user_info)) ? $user_info->first_name : 'N/A';
        $product = wc_get_product($result->equipment_id);
        $product_title = ($product) ? $product->get_title() : 'Unknown Product';
        
        $attachments = $wpdb->get_results(
            $wpdb->prepare(
                "SELECT * FROM {$wpdb->prefix}service_attachment_docs WHERE log_id = %d",
                $result->id
            )
        );
    ?>

    <!-- Service Request Modal -->
    <div class="modal fade" id="insModal<?php echo $result->id;?>" tabindex="-1" aria-labelledby="modalLabel<?php echo $result->id;?>" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Check-In Inspection Details</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <h6>Inspection Information</h6>
                    <div class="row">
                        <div class="col-md-6">
                            <label>Request Raised Name</label>
                            <p><?php echo esc_html($user_name); ?></p>
                        </div>
                        <div class="col-md-6">
                            <label>Equipment Name</label>
                            <p><?php echo esc_html($product_title); ?></p>
                        </div>
                        <div class="col-md-6">
                            <label>RMS Contract ID</label>
                            <p><?php echo esc_html($result->order_id); ?></p>
                        </div>
                        <div class="col-md-6">
                            <label>SAP Contract ID</label>
                            <p><?php echo esc_html(get_post_meta($result->order_id, 'contract_id', true)); ?></p>
                        </div>
                        <div class="col-md-6">
                            <label>Status</label>
                            <p><?php echo esc_html($result->status); ?></p>
                        </div>
                        <?php if (!empty($result->attachment)) : ?>
                        <div class="col-md-6">
                            <label>Attachment</label>
                            <p><a href="<?php echo esc_url($result->attachment); ?>" download>Download Attachment</a></p>
                        </div>
                        <?php endif; ?>
                        <div class="col-md-6">
                            <label>Request Raised On</label>
                            <p><?php echo esc_html($result->created_on); ?></p>
                        </div>
                        <div class="col-md-6">
                            <label>Remarks</label>
                            <p><?php echo esc_html($result->remarks); ?></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Image Gallery Modal -->
    <div class="modal fade" id="imageModal<?php echo $result->id;?>" tabindex="-1" role="dialog" aria-labelledby="imageModalLabel<?php echo $result->id;?>" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Inspection Images</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <?php
                            $attachment_table = $wpdb->prefix . 'service_attachment_docs';
                            $attachments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $attachment_table WHERE log_id = %d", $result->id));

                            if (!empty($attachments)) {
                                // Show images from database attachments
                                foreach ($attachments as $attachment) {
                                    $image_url = content_url("uploads/operator-service-request-attachments/{$attachment->attachment}");
                                    echo "<div class='col-md-4 mb-3'>";
                                    echo "<img src='" . esc_url($image_url) . "' class='img-fluid' alt='Inspection Image'>";
                                    echo "</div>";
                                }
                            } else {
                                // If no DB attachments, check $result->images field
                                $images = $result->images;
                                if (!empty($images)) {
                                    $image_urls = explode(',', $images); // Split by comma
                                    foreach ($image_urls as $img) {
                                        $img = trim($img);
                                        if (!empty($img)) {
                                            echo "<div class='col-md-4 mb-3'>";
                                            echo "<img src='" . esc_url($img) . "' class='img-fluid' alt='Inspection Image'>";
                                            echo "</div>";
                                        }
                                    }
                                } else {
                                    echo "<p class='text-muted ml-3'>No images found.</p>";
                                }
                            }
                            ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

<?php endforeach; ?>



        </div>
    </div>





    <script>
        // Initialize DataTable
        jQuery(document).ready(function($) {
            $('#servicereq-table').DataTable();
        });
    </script>
    <?php
}

function edit_initial_inspection(){
	global $wpdb;

	$id = $_REQUEST['id'];
	$table_name = $wpdb->prefix . 'service_request';

	// Fetch all data from the wp_request_quote table
	$results = $wpdb->get_row("SELECT * FROM $table_name where id=$id");
	$operator_id = $results->operator_id;
    $order_id = get_user_meta($operator_id, 'contract_id', true);

	if(isset($_POST['update_inspection']) && $_POST['update_inspection'] != ''){
		$id = $_REQUEST['servicereq_id'];
		$status = $_POST['status'];
		$remarks = $_POST['remarks'];
		$updated_on = date('Y-m-d H:i:s');

		$wpdb->update($table_name, [
			"status" => $status,
			"remarks" => $remarks,
			"updated_on" => $updated_on,
		], ['id' => $id]);



		// Check if the status is "Completed" and update the WooCommerce order
if ($status === 'Completed') {
    if ($order_id) {
        try {
            $order = wc_get_order($order_id);
            if ($order) {
                // Add debugging log
                error_log("Attempting to update order #$order_id status to wc-work_location");
                
                $order->update_status('wc-work_location', 'Status changed to Equipment At Work Location');
                
                // Additional verification log
                error_log("Order #$order_id status updated successfully");
            } else {
                error_log("Order not found for order ID: $order_id");
            }
        } catch (Exception $e) {
            error_log("Error updating order status: " . $e->getMessage());
        }
    } else {
        error_log("No order ID found for equipment ID: $operator_id");
    }
}

		// Success message and redirect
		echo '<p style="color:#008000">Data Updated Successfully</p>';
		echo '<script>window.location.href = "'.admin_url('admin.php?page=initial-inspection').'"</script>';
	}

	// Render the form
	?>
	<div class="wrap">
		<h2>Edit Inspection Status</h2>
		<form method="post" action="" id="inspection-form">
			<input type="hidden" name="edit_id" value="<?php echo esc_attr($_REQUEST['id']); ?>">
			<table class="form-table">
				<!-- <tr>
					<th><label for="status">Inspection Status</label></th>
					<td>
						<select name="status" id="status" class="regular-text" required>
							<option value="">Select Status</option>
							<option value="In Progress" <?php echo ($results->status == 'In Progress') ? 'selected' : ''; ?>>In Progress</option>
							<option value="Completed" <?php echo ($results->status == 'Completed') ? 'selected' : ''; ?>>Completed</option>
						</select>
					</td>
				</tr> -->
				<tr>
				<th><label for="status">Inspection Status</label></th>
				<td>
					<select name="status" id="status" class="regular-text" required <?php echo ($results->status == 'Completed') ? 'disabled' : ''; ?>>
						<option value="">Select Status</option>
						<option value="In Progress" <?php echo ($results->status == 'In Progress') ? 'selected' : ''; ?>>In Progress</option>
						<option value="Completed" <?php echo ($results->status == 'Completed') ? 'selected' : ''; ?>>Completed</option>
					</select>
					<?php if ($results->status == 'Completed'): ?>
						<input type="hidden" name="status" value="Completed">
					<?php endif; ?>
				</td>
			</tr>
				<tr>
					<th><label for="remarks">Remarks</label></th>
					<td>
					<input type="text" name="remarks" id="remarks" value="<?php echo esc_attr($results->remarks); ?>" class="regular-text" 
					<?php echo ($results->status == 'Completed') ? 'readonly' : ''; ?> required>
				</td>
				</tr>
			</table>
			<input type="hidden" name="servicereq_id" id="servicereq_id" value="<?php echo esc_attr($id); ?>">
			<p class="submit">
				<input type="submit" name="update_inspection" id="update_inspection" class="button-primary" value="Update" <?php echo ($results->status == 'Completed') ? 'disabled' : ''; ?>>
				<a href="<?php echo admin_url('admin.php?page=initial-inspection'); ?>" class="button-primary">Cancel</a>
			</p>
		</form>
	</div>
	<script>
		// Add confirmation alert for "Completed" status
		document.getElementById('inspection-form').addEventListener('submit', function(e) {
			const status = document.getElementById('status').value;
			if (status === 'Completed') {
				const confirmUpdate = confirm('Are you sure to update status? This will change contract status as Equipment At Work location.');
				if (!confirmUpdate) {
					e.preventDefault();
				}
			}
		});
	</script>
	<?php
}


?>

Youez - 2016 - github.com/yon3zu
LinuXploit