| Server IP : 13.126.101.145 / Your IP : 216.73.216.63 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 : |
<?php
// Ensure the file is not accessed directly
if (!defined('ABSPATH')) {
exit;
}
// Add admin menu
add_action('admin_menu', 'servicereq_admin_menu');
function servicereq_admin_menu() {
add_menu_page(
'Service Request', // Page title
'Service Request', // Menu title
'manage_options', // Capability
'servicereq-dashboard', // Menu slug
'servicereq_list',// Callback function
'dashicons-media-interactive', // Icon URL
6 // Position
);
// Add a submenu page
add_submenu_page(
'servicereq-dashboard', // The slug name for the parent menu
'Create Service Request', // The text to be displayed in the title tags of the page when the submenu is selected
'Create Service Request', // The text to be used for the submenu
'manage_options', // The capability required for this menu to be displayed to the user
'create_servicereq', // The slug name to refer to this submenu
'create_servicereq' // The function to be called to output the content for this page
);
add_submenu_page(null, //parent slug
'Edit Service Request', //page title
'Edit', //menu title
'manage_options', //capability
'edit-servicereq', //menu slug
'edit_servicereq'); //function
/* add_submenu_page(null, //parent slug
'Delete Operator', //page title
'Delete', //menu title
'manage_options', //capability
'delete-operator', //menu slug
'delete_operator'); //function */
}
function servicereq_enqueue_custom_styles_and_scripts($hook) {
// Load only on the logsheet dashboard page
if ($hook !== 'toplevel_page_servicereq-dashboard') {
return;
}
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 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);
// 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', 'servicereq_enqueue_custom_styles_and_scripts');
// Display the data
function servicereq_list() {
global $wpdb;
$user = wp_get_current_user();
if ( in_array( 'operator', (array) $user->roles ) ) {
$table_name = $wpdb->prefix . 'service_request';
$user_id = $user->ID;
$results = $wpdb->get_results("SELECT * FROM $table_name where operator_id=$user_id and stype=0 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=0 order by id desc");
}
?>
<div class="wrap rfq-wrap">
<h1 class="wp-heading-inline mb-2 font-weight-bold">Service Request</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">Operator Name</th>
<th scope="col" class="manage-column">Equipment Name</th>
<th scope="col" class="manage-column">Priority Level</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 $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><?php
$priority_level = $result->priority_level;
if ($priority_level == 1 || $result->priority_level == "High") {
echo "High";
} elseif ($priority_level == 2 || $result->priority_level == "Medium") {
echo "Medium";
} elseif ($priority_level == 3 || $result->priority_level == "Low") {
echo "Low";
} else {
echo "Unknown";
} ?></td>
<td><?php echo $result->status;?></td>
<td><?php echo $result->created_on;?></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)) {
$first_image = $attachments[0]->attachment;
echo "<img src='../wp-content/uploads/operator-service-request-attachments/{$first_image}' width='50' height='50' class='service-image' data-toggle='modal' data-target='#imageModal{$result->id}' style='cursor: pointer;'>";
} */
?>
<?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)) {
$max_images = 2;
$image_count = 0;
foreach ($attachments as $attachment) {
if ($image_count >= $max_images) break;
$image_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;'>";
$image_count++;
}
} else {
$images = $result->images;
if (!empty($images)) {
$image_urls = explode(',', $images);
$max_images = 2;
for ($i = 0; $i < min(count($image_urls), $max_images); $i++) {
$img = trim($image_urls[$i]);
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;'>";
}
}
}
?>
</td>
<td><a href="<?php echo admin_url('admin.php?page=edit-servicereq&id=' . $result->id); ?>"><i
class="fas fa-edit"></i></a>
| <a href="#" data-toggle="modal" data-target="#servReqModal<?php echo $result->id;?>"><i
class="fas fa-eye"></i></a></td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
<?php
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';
?>
<!-- Service Request Modal -->
<div class="modal fade" id="servReqModal<?php echo $result->id;?>" tabindex="-1"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
Service Request Details
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">
×
</span>
</button>
</div>
<div class="modal-body">
<!-- Data passed is displayed
in this part of the
modal body -->
<h6 id="modal_body">Service Request Information</h6>
<div class="row">
<div class="col-md-6">
<div class="col-md-6">
<label>Request Raised Name</label>
</div>
<div class="col-md-6">
<p><?php echo $user_name;?></p>
</div>
</div>
<div class="col-md-6">
<div class="col-md-6">
<label>Equipment Name</label>
</div>
<div class="col-md-6">
<p><?php //echo $product->get_title();
$product = wc_get_product( $result->equipment_id );
$product_title = ($product) ? $product->get_title() : 'Unknown Product';
echo $product_title;
?></p>
</div>
</div>
<div class="col-md-6">
<div class="col-md-6">
<label>Problem Description</label>
</div>
<div class="col-md-6">
<p><?php echo $result->problem_description;?></p>
</div>
</div>
<div class="col-md-6">
<div class="col-md-6">
<label>Status</label>
</div>
<div class="col-md-6">
<p><?php echo $result->status;?></p>
</div>
</div>
<?php
if($result->attachment !=''){
?>
<div class="col-md-6">
<div class="col-md-6">
<label>Attachment</label>
</div>
<div class="col-md-6">
<p><a href="<?php echo $result->attachment;?>" download>Download Attachment</a></p>
</div>
</div>
<?php
}
?>
<div class="col-md-6">
<div class="col-md-6">
<label>Request Raised On</label>
</div>
<div class="col-md-6">
<p><?php echo $result->created_on;?></p>
</div>
</div>
<div class="col-md-6">
<div class="col-md-6">
<label>Remarks</label>
</div>
<div class="col-md-6">
<p><?php echo $result->remarks;?></p>
</div>
</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" id="imageModalLabel<?php echo $result->id;?>">Service Request Images
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<?php
// foreach ($attachments as $attachment) {
// echo "<div class='col-md-4 mb-3'>";
// echo "<img src='../wp-content/uploads/operator-service-request-attachments/{$attachment->attachment}' class='img-fluid' alt='Service Request Image'>";
// echo "</div>";
// }
$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 all images from the attachments table
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 {
// Fallback to the comma-separated image URLs
$images = $result->images;
if (!empty($images)) {
$image_urls = explode(',', $images);
foreach ($image_urls as $img) {
$img = trim($img);
echo "<div class='col-md-4 mb-3'>";
echo "<img src='" . esc_url($img) . "' class='img-fluid' alt='Inspection Image'>";
echo "</div>";
}
}
}
?>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<script>
// Initialize DataTable
jQuery(document).ready(function($) {
$('#servicereq-table').DataTable();
});
</script>
<?php
}
function create_servicereq(){
error_reporting(0);
global $wpdb;
if(isset($_POST['createservicereq'])!=''){
$table_name = $wpdb->prefix . "service_request";
$user_id = get_current_user_id();
$productId = $_POST['equipment_id'];
$problem_description = $_POST['problem_description'];
$priority_level = $_POST['priority_level'];
if (isset($_FILES['attachment']) && $_FILES['attachment']['size'] > 0) {
// Handle file upload
$upload_attachment = wp_handle_upload($_FILES['attachment'], array('test_form' => false));
if (isset($upload_attachment['url']) && !isset($upload_attachment['error'])) {
$attachmenturl = $upload_attachment['url'];
}else{
$attachmenturl = '';
}
}
$result_check = $wpdb->insert($table_name, [
"operator_id" => $user_id,
"equipment_id" => $productId,
"problem_description" => $problem_description,
"attachment" => $attachmenturl ? $attachmenturl : '',
"priority_level" => $priority_level,
"created_on" => date('Y-m-d H:i:s'),
]);
if($result_check){
//successfully inserted.
echo "<p>Service Request Raised Successfully</p>";
}else{
//something gone wrong
echo "<p>Error Occurs</p>";
}
}
?>
<style>
.error-msg {
color: red !important;
font-weight: bold !important;
font-size: 14px !important;
margin: 0 !important;
float: left !important;
}
</style>
<div class="wrap">
<form method="post" name="create_service_request" id="createuser" class="form" enctype="multipart/form-data"
onsubmit="return create_servicereq()">
<div class="row">
<div class="column">
<h3>Create Service Request</h3>
<table class="form-table" role="presentation">
<tbody>
<tr class="form-field form-required">
<th scope="row"><label for="log_date">Select Equipment<span class="description"
required>(required)</span></label></th>
<td>
<?php
$user_id = get_current_user_id();
$machineassoc = get_user_meta($user_id, 'machine_associated', true);
$product = wc_get_product( $machineassoc );
?>
<input type="text" name="equipment_name" id="equipment_name" class="regular-text"
value="<?php echo $product->get_title();?>" readonly>
<input type="hidden" name="equipment_id" id="equipment_id" class="regular-text"
value="<?php echo $machineassoc;?>" readonly>
</td>
</tr>
<tr class="form-field form-required">
<th scope="row"><label for="email">Problem Description <span
class="description">(required)</span></label></th>
<td>
<textarea name="problem_description" id="problem_description"
class="regular-text"></textarea>
<span class="error-message wc_probdesc"></span>
</td>
</tr>
<tr class="form-field">
<th scope="row"><label for="first_name">Attachment </label></th>
<td><input type="file" name="attachment" id="attachment_servreq" class="regular-text"></td>
</tr>
<tr class="form-field">
<th scope="row"><label for="last_name">Priority Level </label></th>
<td>
<select name="priority_level" id="priority_level" class="regular-text">
<option value="">Select Priority Level</option>
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p class="submit"><input type="submit" name="createservicereq" id="createservicereq"
class="button button-primary" value="Add Service Request"></p>
</form>
</div>
<script type="text/javascript">
function create_servicereq() {
var problem_description = jQuery('#problem_description').val();
if (problem_description == '') {
jQuery('.wc_probdesc').html("Please Enter Problem Description").addClass("error-msg");
return false;
} else {
jQuery('.wc_probdesc').html('');
//return true;
}
}
</script>
<?php
}
function edit_servicereq(){
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");
//print_r($_POST);
if(isset($_POST['update_servicereq'])!=''){
$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]);
echo '<p style="color:#008000">Data Updated Successfully</p>';
echo '<script>window.location.href = "'.admin_url('admin.php?page=servicereq-dashboard').'"</script>';
}
?>
<div class="wrap">
<h2>Edit Service Request Status</h2>
<form method="post" action="">
<input type="hidden" name="edit_id" value="<?php echo esc_attr($_REQUEST['id']);?>">
<table class="form-table">
<tr>
<th><label for="user_email">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="user_email">Remarks</label></th>
<td>
<input type="text" name="remarks" id="remarks" value="<?php echo esc_attr($results->remarks);?>"
class="regular-text" 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_servicereq" id="update_servicereq" class="button-primary" value="Update">
<a href="<?php echo admin_url('admin.php?page=servicereq-dashboard'); ?>" class="button-primary">Cancel</a>
</p>
</form>
</div>
<?php
}
?>