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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/rentals_updated/wp-content/plugins/operators//operator-dashboard.php
<?php

function add_operator_endpoints() {
    add_rewrite_endpoint('operator-tickets', EP_PAGES);
    add_rewrite_endpoint('operator-log-sheet', EP_PAGES);
    add_rewrite_endpoint('operator-service-request', EP_PAGES);
	add_rewrite_endpoint('operator-create-tickets', EP_PAGES);
	add_rewrite_endpoint('operator-new-request', EP_PAGES);
	add_rewrite_endpoint('operator-create-new-request-tickets', EP_PAGES);
    add_rewrite_endpoint('operator-create-logsheet', EP_PAGES);
    add_rewrite_endpoint('operator-create-servicerequest', EP_PAGES);
}
add_action('init', 'add_operator_endpoints');

// Function to display content for operator tickets endpoint
function operator_tickets_content() {
	global $wpdb;
	$user = wp_get_current_user();
	if ( in_array( 'operator', (array) $user->roles ) ) {
		$table_name = $wpdb->prefix . 'raise_tickets';
		$user_id = $user->ID;
		$results = $wpdb->get_results("SELECT * FROM $table_name where operator_id=$user_id  order by id desc");
	}else if(in_array( 'administrator', (array) $user->roles )){
		$table_name = $wpdb->prefix . 'raise_tickets';
		$user_id = $user->ID;
		$results = $wpdb->get_results("SELECT * FROM $table_name order by id desc");
	}
	?>
	<a href="<?php echo site_url();?>/my-account/operator-create-tickets" class="btn btn-primary mb-2">Create Breakdown Ticket</a>	
    <a href="<?php echo site_url();?>/my-account/operator-create-servicerequest" class="btn btn-primary mb-2">Create Service Request</a>
    <table class="shop_table shop_table_responsive my_account_orders">
    <thead>
	<tr>
	<th class="ticket-number woocommerce-orders-table__header">Sr. No</th>
	<th class="ticket-opname woocommerce-orders-table__header">Operator Name</th>
	<th class="ticket-eqpname woocommerce-orders-table__header">Equipment Name</th>
	<th class="ticket-ptype woocommerce-orders-table__header">Problem Type</th>
	<th class="ticket-pdesc woocommerce-orders-table__header">Problem Description</th>
	<th class="ticket-anotes woocommerce-orders-table__header">Additional Notes</th>
	<th class="ticket-status woocommerce-orders-table__header">Status</th>
	<th class="ticket-con woocommerce-orders-table__header">Created On</th>
	<th class="ticket-action woocommerce-orders-table__header">Actions</th>
	</tr>
	</thead>
    <tbody>
	<?php
    // Sample ticket data
	$i = 1;
	
	foreach($results as $result){
		$user_info = get_userdata($result->operator_id);
		$user_name = $user_info->user_nicename;
		$equipment_name =  get_the_title( $result->equipment_id );
		$ptype = ($result->problem_type == 1) ? 'Breakdown' : 'New Request';
	?>	
		<tr class="woocommerce-orders-table__row">
			<td class="ticket-number"><a href="#"><?php echo $i;?></a></td>
			<td class="ticket-opname"><?php echo $user_name;?></td>
			<td class="ticket-eqpname"><?php echo$equipment_name;?></td>		
			<td class="ticket-ptype"><?php echo $ptype;?></td>
			<td class="ticket-pdesc"><?php echo $result->problem_description;?></td>
			<td class="ticket-anotes"><?php echo $result->additional_notes;?></td>
			<td class="ticket-status"><?php echo $result->status;?></td>
			<td class="ticket-con"><?php echo $result->created_on;?></td>
			<td class="ticket-actionn"><a href="javascript:void(0);" data-toggle="modal" data-target="#ticketsModal<?php echo $result->id;?>">View</a></td>
			</tr>
			<div class="modal fade" id="ticketsModal<?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">
												Tickets 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">

											<!-- Data passed is displayed 
												in this part of the 
												modal body -->
											<h6 id="modal_body">Tickets Details</h6>
											<div class="row">
												<div class="col-md-6">
													<div class="col-md-6">
														<label>Ticket 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 get_the_title( $result->equipment_id );?></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>Additional Notes</label>
													</div>
													<div class="col-md-6">
														<p><?php echo $result->additional_notes;?></p>
													</div>
												</div>											
												<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>
												<?php
													$ticketID = $result->id;
													$attachments = $wpdb->get_results("SELECT attachment FROM wp_ticket_attachment_docs WHERE ticket_id = ".$ticketID);
													$uploads = wp_upload_dir();
													if(count($attachments)>0){
												?>
												<div class="col-md-12">
													<div class="col-md-6">
														<label>Attachment</label>
													</div>
													<div class="col-md-6">
														<?php
														$o = 1;
														foreach($attachments as $attch){
														?>
														<p>Download Attachment File <?php echo $o;?> : <a href="<?php echo $uploads['baseurl'].'/operator-tickets-attachments/'.$attch->attachment;?>" download>Download Attachment</a></p>
														<?php
														$o++;
														}
														?>
													</div>
												</div>
												<?php
													}
												?>
											</div>
										</div>
									</div>
								</div>		
							</div>
	<?php	
	$i++;
	}
	?>
	</tbody></table>
	<?php
}
add_action('woocommerce_account_operator-tickets_endpoint', 'operator_tickets_content');

function operator_new_request_content() {
	global $wpdb;
	$user = wp_get_current_user();
	if ( in_array( 'operator', (array) $user->roles ) ) {
		$table_name = $wpdb->prefix . 'raise_tickets';
		$user_id = $user->ID;
		$results = $wpdb->get_results("SELECT * FROM $table_name where operator_id=$user_id and problem_type = '2' order by id desc");
	}else if(in_array( 'administrator', (array) $user->roles )){
		$table_name = $wpdb->prefix . 'raise_tickets';
		$user_id = $user->ID;
		$results = $wpdb->get_results("SELECT * FROM $table_name order by id desc");
	}
	?>
	<a href="<?php echo site_url();?>/my-account/operator-create-new-request-tickets" class="btn btn-primary mb-2">Create New Request</a>
    <table class="shop_table shop_table_responsive my_account_orders">
    <thead>
	<tr>
	<th class="ticket-number woocommerce-orders-table__header">Sr. No</th>
	<th class="ticket-opname woocommerce-orders-table__header">Operator Name</th>
	<th class="ticket-eqpname woocommerce-orders-table__header">Equipment Name</th>
	<th class="ticket-ptype woocommerce-orders-table__header">Problem Type</th>
	<th class="ticket-pdesc woocommerce-orders-table__header">Problem Description</th>
	<th class="ticket-anotes woocommerce-orders-table__header">Additional Notes</th>
	<th class="ticket-status woocommerce-orders-table__header">Status</th>
	<th class="ticket-con woocommerce-orders-table__header">Created On</th>
	<th class="ticket-action woocommerce-orders-table__header">Actions</th>
	</tr>
	</thead>
    <tbody>
	<?php
    // Sample ticket data
	$i = 1;
	
	foreach($results as $result){
		$user_info = get_userdata($result->operator_id);
		$user_name = $user_info->user_nicename;
		$equipment_name =  get_the_title( $result->equipment_id );
		$ptype = ($result->problem_type == 1) ? 'Breakdown' : 'New Request';
	?>	
		<tr class="woocommerce-orders-table__row">
			<td class="ticket-number"><a href="#"><?php echo $i;?></a></td>
			<td class="ticket-opname"><?php echo $user_name;?></td>
			<td class="ticket-eqpname"><?php echo$equipment_name;?></td>		
			<td class="ticket-ptype"><?php echo $ptype;?></td>
			<td class="ticket-pdesc"><?php echo $result->problem_description;?></td>
			<td class="ticket-anotes"><?php echo $result->additional_notes;?></td>
			<td class="ticket-status"><?php echo $result->status;?></td>
			<td class="ticket-con"><?php echo $result->created_on;?></td>
			<td class="ticket-actionn"><a href="javascript:void(0);" data-toggle="modal" data-target="#ticketsModal<?php echo $result->id;?>">View</a></td>
			</tr>
			<div class="modal fade" id="ticketsModal<?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">
												Tickets 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">

											<!-- Data passed is displayed 
												in this part of the 
												modal body -->
											<h6 id="modal_body">Tickets Details</h6>
											<div class="row">
												<div class="col-md-6">
													<div class="col-md-6">
														<label>Ticket 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 get_the_title( $result->equipment_id );?></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>Additional Notes</label>
													</div>
													<div class="col-md-6">
														<p><?php echo $result->additional_notes;?></p>
													</div>
												</div>											
												<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>
												<?php
													$ticketID = $result->id;
													$attachments = $wpdb->get_results("SELECT attachment FROM wp_ticket_attachment_docs WHERE ticket_id = ".$ticketID);
													$uploads = wp_upload_dir();
													if(count($attachments)>0){
												?>
												<div class="col-md-12">
													<div class="col-md-6">
														<label>Attachment</label>
													</div>
													<div class="col-md-6">
														<?php
														$o = 1;
														foreach($attachments as $attch){
														?>
														<p>Download Attachment File <?php echo $o;?> : <a href="<?php echo $uploads['baseurl'].'/operator-tickets-attachments/'.$attch->attachment;?>" download>Download Attachment</a></p>
														<?php
														$o++;
														}
														?>
													</div>
												</div>
												<?php
													}
												?>
											</div>
										</div>
									</div>
								</div>		
							</div>
	<?php	
	$i++;
	}
	?>
	</tbody></table>
	<?php
}
add_action('woocommerce_account_operator-new-request_endpoint', 'operator_new_request_content');

// Function to display content for operator log sheet endpoint
function operator_log_sheet_content() {
	global $wpdb;
$user = wp_get_current_user();
$user_id = $user->ID;
$contractID = get_user_meta($user_id, 'contract_id', true);

if ($contractID) {  
    $getCustomerData = $wpdb->get_row($wpdb->prepare("SELECT customer_id FROM wp_wc_orders WHERE id = %d AND status = 'wc-opassigned'", $contractID));
    $customerId = $getCustomerData->customer_id;
    $customerDetails = get_userdata($customerId);
    
    $equipment_number = get_post_meta($contractID, 'equipment_number', true);
    $equipment_serial_number = get_post_meta($contractID, 'equipment_serial_number', true);
    $registration_number = get_post_meta($contractID, 'registration_number', true);
    $model_no = get_post_meta($contractID, 'model_no', true);
    $order = wc_get_order($contractID);
    $start_date = $order->get_meta('start_date');
    $end_date = $order->get_meta('end_date');
    ?>
    <div class="container mb-2">
        <div class="row">
            <div class="col-md-6">
                <p><strong>Month/Year:</strong> <?php echo date('d/m/Y'); ?></p>
                <p><strong>Project Location:</strong> <?php echo esc_html($customerDetails->location ?? 'Chennai'); ?></p>
                <p><strong>Customer Name:</strong> <?php echo esc_html($customerDetails->user_nicename); ?></p>
            </div>
            <div class="col-md-6">
                <p><strong>Equipment ID No.:</strong> <?php echo esc_html($equipment_number); ?></p>
                <p><strong>Machine Serial No:</strong> <?php echo esc_html($equipment_serial_number); ?></p>
                <p><strong>Registration No(if any):</strong> <?php echo esc_html($registration_number); ?></p>
            </div>
        </div>
    </div>
    <form method="post" name="createoperator" id="createuser" class="form" action="javascript:void(0);">
        <table id="logsheet-table" class="shop_table shop_table_responsive my_account_orders">
            <thead class="thead-dark">
                <tr>
                    <th scope="row" class="logdate woocommerce-orders-table__header">Log Date</th>
                    <th scope="col" class="shift woocommerce-orders-table__header">Shift</th>
                    <th scope="col" class="starttime woocommerce-orders-table__header">Start Time</th>
                    <th scope="col" class="endtime woocommerce-orders-table__header">End Time</th>
                    <th scope="col" class="workinghr woocommerce-orders-table__header">Working Hour</th>
                    <th scope="col" class="brkdnhr woocommerce-orders-table__header">Breakdown / Operator Absence</th>
                    <th scope="col" class="fuel woocommerce-orders-table__header">Fuel</th>
                    <th scope="col" class="wrkhrvsnlk woocommerce-orders-table__header">Work Hours in Vision Link</th>
                    <th scope="col" class="action woocommerce-orders-table__header">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $start = new DateTime($start_date);
                $end = new DateTime($end_date);
                $interval = new DateInterval('P1D');
                $period = new DatePeriod($start, $interval, $end->modify('+1 day')); // Include end date
                $i = 1;

                foreach ($period as $date) {
                    if ($date->format('Y-m-d') <= date('Y-m-d')) {
                        $logdate = $date->format('Y-m-d');
                        $getLogsheetData = $wpdb->get_row($wpdb->prepare("SELECT log_date, start_time, end_time, shift, down_hour, working_hour, fuel FROM wp_logsheet WHERE operator_id = %d AND log_date = %s", $user_id, $logdate));
						if(isset($getLogsheetData)){
						?>
						<tr>
                            <td>
                                <input type="text" name="log_date" id="log_date<?php echo $i; ?>" value="<?php echo esc_attr($getLogsheetData->log_date); ?>" class="form-control" readonly>
                            </td>
                            <td>
							<?php 
							$shiftresult = ($getLogsheetData->shift !== 1 && $getLogsheetData->shift === 2) ? 'Night' : 'Day';
							?>
                                <input type="text" name="shift" id="shift<?php echo $i; ?>" class="form-control" value="<?php echo $shiftresult ; ?>" readonly>
                            </td>
                            <td>
                                <input type="text" name="start_time" id="start_time<?php echo $i; ?>" class="form-control" value="<?php echo $getLogsheetData->start_time;?>" readonly>
                            </td>
                            <td>
                                <input type="text" name="end_time" id="end_time<?php echo $i; ?>" class="form-control" value="<?php echo $getLogsheetData->end_time; ?>" readonly>
                                <input type="hidden" name="selected_start_time" id="selected_start_time<?php echo $i; ?>" value="">
                                <input type="hidden" name="selected_end_time" id="selected_end_time<?php echo $i; ?>" value="">
                            </td>
                            <td>
                                <input type="text" class="form-control" name="work_hour" id="work_hour<?php echo $i; ?>" value="<?php echo $getLogsheetData->working_hour; ?>" readonly>
                            </td>
                            <td>
                                <input type="text" class="form-control" name="down_hour" id="down_hour<?php echo $i; ?>" value="<?php echo $getLogsheetData->down_hour; ?>" readonly>
                            </td>
                            <td>
                                <input type="text" class="form-control" name="fuel" id="fuel<?php echo $i; ?>" value="<?php echo $getLogsheetData->fuel; ?>" readonly>
                            </td>
                            <td>
                                <input type="text" class="form-control" name="totalhrs" id="totalhrs<?php echo $i; ?>" value="<?php echo $getLogsheetData->working_hour - $getLogsheetData->down_hour; ?>" readonly>
                            </td>
                            <td>
                                <input type="button" class="btn btn-primary saveLogSheet" id="saveLogSheet<?php echo $i; ?>" value="Save" data-form-id="<?php echo $i; ?>" readonly>
                            </td>
                        </tr>
						<?php	
						}else{
                        ?>
                        <tr>
                            <td>
                                <input type="date" name="log_date" id="log_date<?php echo $i; ?>" value="<?php echo esc_attr($logdate); ?>" class="form-control">
                            </td>
                            <td>
                                <select name="shift" id="shift<?php echo $i; ?>" class="form-control">
                                    <option value="">Select</option>
                                    <option value="1">Day</option>
                                    <option value="2">Night</option>
                                </select>
                            </td>
                            <td>
                                <select name="start_time" id="start_time<?php echo $i; ?>" class="start_time form-control" data-id="<?php echo $i; ?>"></select>
                            </td>
                            <td>
                                <select name="end_time" id="end_time<?php echo $i; ?>" class="end_time form-control" data-id="<?php echo $i; ?>">
                                    <option value="00:00">12:00 AM</option>
                                </select>
                                <input type="hidden" name="selected_start_time" id="selected_start_time<?php echo $i; ?>" value="">
                                <input type="hidden" name="selected_end_time" id="selected_end_time<?php echo $i; ?>" value="">
                            </td>
                            <td>
                                <input type="text" class="form-control" name="work_hour" id="work_hour<?php echo $i; ?>" value="8">
                            </td>
                            <td>
                                <input type="text" class="form-control" name="down_hour" id="down_hour<?php echo $i; ?>" value="0">
                            </td>
                            <td>
                                <input type="text" class="form-control" name="fuel" id="fuel<?php echo $i; ?>" value="1234">
                            </td>
                            <td>
                                <input type="text" class="form-control" name="totalhrs" id="totalhrs<?php echo $i; ?>" value="1234">
                            </td>
                            <td>
                                <input type="button" class="btn btn-primary saveLogSheet" id="saveLogSheet<?php echo $i; ?>" value="Save" data-form-id="<?php echo $i; ?>" onclick="save_logsheet(<?php echo $i; ?>)">
                            </td>
                        </tr>
                        <?php
						}
                        $i++;
                    }
                }
                ?>
            </tbody>
        </table>
        <input type="hidden" name="equipment_id" id="equipment_id" value="<?php echo esc_attr($contractID); ?>">
        <input type="hidden" name="equipment_no" id="equipment_no" value="<?php echo esc_attr($equipment_number); ?>">
        <input type="hidden" name="model_no" id="model_no" value="<?php echo esc_attr($model_no); ?>">
        <input type="hidden" name="machine_serial_no" id="machine_serial_no" value="<?php echo esc_attr($equipment_serial_number); ?>">
        <input type="hidden" name="registration_no" id="registration_no" value="<?php echo esc_attr($registration_number); ?>">
    </form>
    <div id="logsheet-spinner" style="display:none;">
        <img style="width:22px;" src="<?php echo plugin_dir_url(__FILE__); ?>spinner.gif" alt="Loading...">
    </div>
    <div id="logsheet-message" style="display:none;"></div>
    <?php
} else {  
    ?>
    <p>Contract Still Not Assigned Yet. No Log Entry Found</p>
    <?php
}
?>
<script>
jQuery(document).ready(function($) {
    function generateTimeOptions(interval) {
        let times = [];
        let start = new Date(0, 0, 0, 0, 0);
        let end = new Date(0, 0, 0, 23, 59);

        while (start <= end) {
            let hours = start.getHours();
            let minutes = start.getMinutes();
            let timeValue = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes);
            let timeDisplay = (hours % 12 || 12) + ":" + (minutes < 10 ? "0" + minutes : minutes) + (hours < 12 ? " AM" : " PM");
            times.push({ value: timeValue, display: timeDisplay });
            start.setMinutes(start.getMinutes() + interval);
        }

        return times;
    }

    function populateStartDropdown() {
        let timeOptions = generateTimeOptions(30);
        let startDropdown = $('.start_time');
        $.each(timeOptions, function(index, time) {
            startDropdown.append($('<option>', {
                value: time.value,
                text: time.display
            }));
        });
    }

    function updateEndDropdown(selectedStartTime, id) {
        let timeOptions = generateTimeOptions(30);
        let endDropdown = $('#end_time' + id);
        endDropdown.empty();
        let startTime = new Date('1970-01-01T' + selectedStartTime + 'Z');

        $.each(timeOptions, function(index, time) {
            let endTime = new Date('1970-01-01T' + time.value + 'Z');
            if (endTime > startTime) {
                endDropdown.append($('<option>', {
                    value: time.value,
                    text: time.display
                }));
            }
        });
    }

    populateStartDropdown();

    $('.start_time').on('change', function() {
        var id = $(this).data("id");
        let selectedStartTime = $(this).val();
        $('#selected_start_time' + id).val(selectedStartTime);
        updateEndDropdown(selectedStartTime, id);
    });

    $('.end_time').on('change', function() {
        var id = $(this).data("id");
        let selectedEndTime = $(this).val();
        $('#selected_end_time' + id).val(selectedEndTime);

        let startDate = $('#selected_start_time' + id).val();
        let endDate = $('#selected_end_time' + id).val();

        let start = new Date('1970-01-01T' + startDate + 'Z');
        let end = new Date('1970-01-01T' + endDate + 'Z');

        let timeDiff = (end - start) / (1000 * 3600);
        $('#work_hour' + id).val(timeDiff.toFixed(2));
    });
});
</script>
<script type="text/javascript">
function save_logsheet(id) {
    var log_date = $('#log_date' + id).val();
    var shift = $('#shift' + id).val();
    var start_time = $('#selected_start_time' + id).val();
    var end_time = $('#selected_end_time' + id).val();
    var work_hour = $('#work_hour' + id).val();
    var down_hour = $('#down_hour' + id).val();
    var fuel = $('#fuel' + id).val();
    var equipment_id = $('#equipment_id').val();
    var equipment_no = $('#equipment_no').val();
    var model_no = $('#model_no').val();
    var machine_serial_no = $('#machine_serial_no').val();
    var registration_no = $('#registration_no').val();

    if (!log_date || !shift || !start_time || !end_time) {
        alert('Please fill all the required fields.');
        return;
    }

    $('#logsheet-spinner').show();

    $.ajax({
        url: '<?php echo admin_url("admin-ajax.php"); ?>',
        type: 'POST',
        data: {
            action: 'save_logsheet_data',
            log_date: log_date,
            shift: shift,
            start_time: start_time,
            end_time: end_time,
            work_hour: work_hour,
            down_hour: down_hour,
            fuel: fuel,
            equipment_id: equipment_id,
            equipment_no: equipment_no,
            model_no: model_no,
            machine_serial_no: machine_serial_no,
            registration_no: registration_no,
            operator_id: '<?php echo get_current_user_id(); ?>'
        },
        success: function(response) {
            $('#logsheet-spinner').hide();
            alert("Logsheet Saved Successfully");
        },
        error: function(error) {
            $('#logsheet-spinner').hide();
            alert('There was an error submitting your request. Please try again.');
        }
    });
}
</script>
   <?php
}
add_action('woocommerce_account_operator-log-sheet_endpoint', 'operator_log_sheet_content');

// Handle Logsheet submission
function save_logsheet_data()
{
    global $wpdb;
    $table_name = $wpdb->prefix . "logsheet";

    $equipment_id = sanitize_text_field($_POST["equipment_id"]);
    $equipment_no = sanitize_text_field($_POST['equipment_no']);
    $model_no = sanitize_text_field($_POST['model_no']);
    $machine_serial_no = sanitize_text_field($_POST['machine_serial_no']);
    $registration_no = sanitize_text_field($_POST["registration_no"]);
    $operator_id = sanitize_text_field($_POST["operator_id"]);
    $log_date = sanitize_text_field($_POST["log_date"]);
    $start_time = sanitize_text_field($_POST["start_time"]);
	$end_time = sanitize_text_field($_POST["end_time"]);
    $shift = sanitize_text_field($_POST["shift"]);
    $work_hour = sanitize_text_field($_POST["work_hour"]);
    $down_hour = sanitize_text_field($_POST["down_hour"]);
	$fuel = sanitize_text_field($_POST["fuel"]);
    

    $wpdb->insert($table_name, [
        "equipment_id" => $equipment_id,
        "equipment_no" => $equipment_no,
        "model_no" => $model_no,
        "machine_serial_no" => $machine_serial_no,
        "registration_no" => $registration_no,
        "operator_id" => $operator_id,
        "log_date" => $log_date,
		"start_time" => $start_time,
		"end_time" => $end_time,
        "shift" => $shift,
        "working_hour" => $work_hour,
		"down_hour" => $down_hour,
		"fuel" => $fuel,
        "log_created_on" => date('Y-m-d H:i:s'),
    ]);    
    wp_send_json_success();
}
add_action("wp_ajax_save_logsheet_data", "save_logsheet_data");
add_action("wp_ajax_nopriv_save_logsheet_data", "save_logsheet_data");

// Function to display content for operator service request endpoint
function operator_service_request_content() {
    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 order by id desc");
	}else if(in_array( 'administrator', (array) $user->roles )){
		$table_name = $wpdb->prefix . 'service_request';
		$user_id = $user->ID;
		$results = $wpdb->get_results("SELECT * FROM $table_name order by id desc");
	}
	$upload_dir   = wp_upload_dir();
	
    ?>
    <div class="wrap rfq-wrap">
        <a href="<?php echo site_url();?>/my-account/operator-create-servicerequest" class="btn btn-primary mb-2">Create Service Request</a> 
        <table id="servicereq-table" class="shop_table shop_table_responsive my_account_orders">
            <thead>
                <tr>
                    <th scope="row" class="sr-number woocommerce-orders-table__header">Sr. No</th>
                    <th scope="col" class="sr-opname woocommerce-orders-table__header">Operator Name</th>
                    <th scope="col" class="sr-eqname woocommerce-orders-table__header">Equipment Name</th>
                    <th scope="col" class="sr-pl woocommerce-orders-table__header">Priority Level</th>
                    <th scope="col" class="sr-sts woocommerce-orders-table__header">Status</th>
					<th scope="col" class="sr-con woocommerce-orders-table__header">Created On</th>
                    <th scope="col" class="sr-action woocommerce-orders-table__header">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php
					$i = 1;
					foreach($results as $result){
						$user_info = get_userdata($result->operator_id);
						$user_name = $user_info->user_nicename;
						?>
						<tr class="woocommerce-orders-table__row">
							<td class="sr-number"><?php echo $i;?></td>
							<td class="sr-opname"><?php echo $user_name;?></td>
							<td class="sr-eqname">
							<?php 
							$product = wc_get_product( $result->equipment_id );
							echo $product->get_title();
							?>
							</td>
							<td class="sr-pl"><?php echo $result->priority_level;?></td>
							<td class="sr-sts"><?php echo $result->status;?></td>
							<td class="sr-con"><?php echo $result->created_on;?></td>
							<td class="sr-action"><a href="javascript:void(0);" data-toggle="modal" data-target="#servReqModal<?php echo $result->id;?>">View</a></td>
						</tr>
						<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">
												&times;
											</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();?></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 !=''){
												$attachmentpath = $upload_dir['baseurl'];
											?>
											<div class="col-md-6">
												<div class="col-md-6">
													<label>Attachment</label>
												</div>
												<div class="col-md-6">
													<p><a href="<?php echo $attachmentpath.'/operator-service-request-attachments/'.$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>
									</div>
								</div>
							</div>		
						</div>
						<?php
						
						$i++;
					}
				?>
            </tbody>
        </table>
    </div>
    <script>
        // Initialize DataTable
        jQuery(document).ready(function($) {
            $('#servicereq-table').DataTable();
        });
    </script>
    <?php
}
add_action('woocommerce_account_operator-service-request_endpoint', 'operator_service_request_content');

function operator_create_tickets_content()
{
    global $wpdb;
	if(isset($_POST['createticket'])!=''){
		$table_name = $wpdb->prefix . "raise_tickets";
		$user_id = get_current_user_id();
		$productId = $_POST['equipment_id'];
		
		$problem_type = $_POST['problem_type'];
		$problem_description = $_POST['problem_description'];
		if($problem_type == 1){
			$productId = $_POST['equipment_idhid'];
		}else{
			$productId = $_POST['equipment_id'];
		}
		//print_r($_FILES);exit;
		/* 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 = '';
			}				
		} */
		$upload_dir = wp_upload_dir();
		$upload_path = $upload_dir['basedir'] . '/operator-tickets-attachments/';

		// Ensure the uploads directory exists
		if (!is_dir($upload_path)) {
			wp_mkdir_p($upload_path);
		}

		$total = count($_FILES['attachment']['name']);
		
		$additional_notes = $_POST['additional_notes'];
		$result_check = $wpdb->insert($table_name, [
			"operator_id" => $user_id,
			"problem_type" => $problem_type,
			"problem_description" => $problem_description,
			"equipment_id" => $productId,
			
			//"priority_level" => $priority_level,
			"additional_notes" => $additional_notes,
			"created_on" => date('Y-m-d H:i:s'),
		]);
		
		$lastid = $wpdb->insert_id;
		for ($i = 0; $i < $total; $i++) {
			$file_name = $_FILES['attachment']['name'][$i];
			$file_tmp_name = $_FILES['attachment']['tmp_name'][$i];
			$file_path = $upload_path . basename($file_name);

			if (move_uploaded_file($file_tmp_name, $file_path)) {
				
				$wpdb->insert('wp_ticket_attachment_docs', [
					"ticket_id" => $lastid,
					"attachment" => $file_name,
					"created_on" => date('Y-m-d H:i:s'),
				]);
			} else {
				
			}
		}

		if($result_check){
		   //successfully inserted.
		   echo "<p>Ticket Raised Successfully</p>";
		}else{
		  //something gone wrong
		  echo "<p>Error Occurs</p>";
		}
		
	}
	?>
	
<div class="container">
	<form method="post" name="createtickets" id="createuser" class="form" enctype="multipart/form-data" onsubmit="return create_tickets()">
		<div class="row">
			<div class="column">
			<h3>Create Breakdown Ticket</h3>
			<table class="form-table" role="presentation">
				<tbody>
									
					<tr class="form-field equipment_brk">
						<th scope="row"><label for="equipment_idhid">Equipment<span class="description"></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_idhid" id="equipment_idhid"class="regular-text" value="<?php echo $machineassoc;?>" readonly>
						</td>
					</tr>
					<tr class="form-field form-required">
						<th scope="row"><label for="ticket_problem_description">Problem Description <span class="description">(required)</span></label></th>
						<td>
							<textarea name="problem_description" id="ticket_problem_description" class="regular-text"></textarea>
							<span class="error-message wc_probticketdesc"></span>	
						</td>
					</tr>
					<tr class="form-field">
						<th scope="row"><label for="attachment_tickets">Upload Images/Documents </label></th>
						<td>
							<input type="file" name="attachment[]" id="attachment_tickets" class="regular-text" multiple>
							<p>Upload Multiple Images/Documents</p>
						</td>
					</tr>
					<tr class="form-field form-required">
						<th scope="row"><label for="additional_notes">Additional Notes</label></th>
						<td>
							<input type="hidden" name="problem_type" class="form-control" value="1">
							<textarea name="additional_notes" id="additional_notes" class="regular-text"></textarea></td>
					</tr>
				</tbody>
			</table>
			</div>
			
			
		</div>
		<p class="submit"><input type="submit" name="createticket" id="createticket" class="button button-primary" value="Add Ticket"></p>
	</form>
	</div>
<script type="text/javascript">
/* jQuery(document).ready(function($) {
	$("input[name$='problem_type']").click(function() {
		var type = $(this).val();
		if(type == 1){
			$('.equipment_brk').show();
			$('.new_equipment').hide();
		}else if(type == 2){
			$('.equipment_brk').hide();
			$('.new_equipment').show();			
		}
	});
}); */
function create_tickets() {
	
	/**if(jQuery('input[type=radio][name=problem_type]:checked').length == 0)
    {
		jQuery('.wc_probtype').html("Please Select Problem Type").addClass("error-msg");  
		return false;
	}else{
		jQuery('.wc_probtype').html('');
		//return true;
	} **/
    var problem_description = jQuery('#ticket_problem_description').val();
	if(problem_description == ''){
        jQuery('.wc_probticketdesc').html("Please Enter Problem Description").addClass("error-msg");
		return false;
    }else{
        jQuery('.wc_probticketdesc').html('');
		//return true;
    }
}

</script>
<?php
}
add_action('woocommerce_account_operator-create-tickets_endpoint', 'operator_create_tickets_content');

// new request tickets

function operator_create_new_request_tickets_content()
{
    global $wpdb;
	if(isset($_POST['createticket'])!=''){
		$table_name = $wpdb->prefix . "raise_tickets";
		$user_id = get_current_user_id();
		$productId = $_POST['equipment_id'];
		
		$problem_type = $_POST['problem_type'];
		$problem_description = $_POST['problem_description'];
		if($problem_type == 1){
			$productId = $_POST['equipment_idhid'];
		}else{
			$productId = $_POST['equipment_id'];
		}
		//print_r($_FILES);exit;
		/* 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 = '';
			}				
		} */
		$upload_dir = wp_upload_dir();
		$upload_path = $upload_dir['basedir'] . '/operator-tickets-attachments/';

		// Ensure the uploads directory exists
		if (!is_dir($upload_path)) {
			wp_mkdir_p($upload_path);
		}

		$total = count($_FILES['attachment']['name']);
		
		$additional_notes = $_POST['additional_notes'];
		$result_check = $wpdb->insert($table_name, [
			"operator_id" => $user_id,
			"problem_type" => $problem_type,
			"problem_description" => $problem_description,
			"equipment_id" => $productId,
			
			//"priority_level" => $priority_level,
			"additional_notes" => $additional_notes,
			"created_on" => date('Y-m-d H:i:s'),
		]);
		
		$lastid = $wpdb->insert_id;
		for ($i = 0; $i < $total; $i++) {
			$file_name = $_FILES['attachment']['name'][$i];
			$file_tmp_name = $_FILES['attachment']['tmp_name'][$i];
			$file_path = $upload_path . basename($file_name);

			if (move_uploaded_file($file_tmp_name, $file_path)) {
				
				$wpdb->insert('wp_ticket_attachment_docs', [
					"ticket_id" => $lastid,
					"attachment" => $file_name,
					"created_on" => date('Y-m-d H:i:s'),
				]);
			} else {
				
			}
		}

		if($result_check){
		   //successfully inserted.
		   echo "<p>New Request Raised Successfully</p>";
		}else{
		  //something gone wrong
		  echo "<p>Error Occurs</p>";
		}
		
	}
	?>
	
<div class="container">
	<form method="post" name="createtickets" id="createuser" class="form" enctype="multipart/form-data" onsubmit="return create_tickets()">
		<div class="row">
			<div class="column">
			<h3>Create New Request</h3>
			<table class="form-table" role="presentation">
				<tbody>
					
					<!--<tr class="">
						<th scope="row"><label for="problem_type">Select Problem Type<span class="description">(required)</span></label></th>
						<td>
							<label>
								<input type="radio" name="problem_type" class="form-control" value="1">Breakdown
							</label>
							<label>
								<input type="radio" name="problem_type" class="form-control" value="2">New Request
							</label>
							<span class="error-message wc_probtype"></span>
						</td>
					</tr> -->
					<tr class="form-field new_equipment">
						<th scope="row"><label for="equipment_id">Select Equipment<span class="description"></label></th>
						<td><select name="equipment_id" id="ticketequipment_id" class="regular-text" >
								<option value="">Select Equipment</option>
								<?php
								$pargs = array(
									'post_type'=> 'product',
									'orderby'    => 'post_title',
									'post_status' => 'publish',
									'order'    => 'ASC',
									'posts_per_page' =>-1 // this will retrive all the post that is published 
								);
								$products = new WP_Query( $pargs );
								foreach($products->posts as $product){
								?>
								<option value="<?php echo $product->ID;?>"><?php echo $product->post_title;?></option>
								<?php
								}
								?>
							</select>
							<span class="error-message wc_ticketequipmentid"></span>
							</td>
					</tr>
					
					<tr class="form-field form-required">
						<th scope="row"><label for="ticket_problem_description">Problem Description <span class="description">(required)</span></label></th>
						<td>
							<textarea name="problem_description" id="ticket_problem_description" class="regular-text"></textarea>
							<span class="error-message wc_probticketdesc"></span>	
						</td>
					</tr>
					<tr class="form-field">
						<th scope="row"><label for="attachment_tickets">Upload Images/Documents </label></th>
						<td>
							<input type="file" name="attachment[]" id="attachment_tickets" class="regular-text" multiple>
							<p>Upload Multiple Images/Documents</p>
						</td>
					</tr>
					<tr class="form-field form-required">
						<th scope="row"><label for="additional_notes">Additional Notes</label></th>
						<td><textarea name="additional_notes" id="additional_notes" class="regular-text"></textarea></td>
					</tr>
				</tbody>
			</table>
			</div>
			
			
		</div>
		<p class="submit">
			<input type="hidden" name="problem_type" class="form-control" value="2">
			<input type="submit" name="createticket" id="createticket" class="button button-primary" value="Create New Request"></p>
	</form>
	</div>
<script type="text/javascript">
/**jQuery(document).ready(function($) {
	$("input[name$='problem_type']").click(function() {
		var type = $(this).val();
		if(type == 1){
			$('.equipment_brk').show();
			$('.new_equipment').hide();
		}else if(type == 2){
			$('.equipment_brk').hide();
			$('.new_equipment').show();			
		}
	});
}); **/
function create_tickets() {
	
	/**if(jQuery('input[type=radio][name=problem_type]:checked').length == 0)
    {
		jQuery('.wc_probtype').html("Please Select Problem Type").addClass("error-msg");  
		return false;
	}else{
		jQuery('.wc_probtype').html('');
		//return true;
	} **/
    var problem_description = jQuery('#ticket_problem_description').val();
	if(problem_description == ''){
        jQuery('.wc_probticketdesc').html("Please Enter Problem Description").addClass("error-msg");
		return false;
    }else{
        jQuery('.wc_probticketdesc').html('');
		//return true;
    }
}

</script>
<?php
}
add_action('woocommerce_account_operator-create-new-request-tickets_endpoint', 'operator_create_new_request_tickets_content');

function operator_create_logsheet_content()
{
    echo 'create new Logsheet';
}
add_action('woocommerce_account_operator-create-logsheet_endpoint', 'operator_create_logsheet_content');

function operator_create_servicerequest_content()
{
    global $wpdb;
	if(isset($_POST['servicerequest'])!=''){
		$table_name = $wpdb->prefix . "raise_tickets";
		$user_id = get_current_user_id();
		$productId = $_POST['equipment_id'];
		
		$problem_type = $_POST['problem_type'];
		$problem_description = $_POST['problem_description'];
		$priority_level = $_POST['priority_level'];		
		
		//$additional_notes = $_POST['additional_notes'];
		$result_check = $wpdb->insert($table_name, [
			"operator_id" => $user_id,
			"problem_type" => $problem_type,
			"problem_description" => $problem_description,
			"equipment_id" => $productId,
			"priority_level" => $priority_level,
			//"additional_notes" => $additional_notes,
			"created_on" => date('Y-m-d H:i:s'),
		]);
		
		$lastid = $wpdb->insert_id;
		$upload_dir = wp_upload_dir();
		$upload_path = $upload_dir['basedir'] . '/operator-tickets-attachments/';

		// Ensure the uploads directory exists
		if (!is_dir($upload_path)) {
			wp_mkdir_p($upload_path);
		}
		$file_name = $_FILES['attachment']['name'];
		$file_tmp_name = $_FILES['attachment']['tmp_name'];
		$file_path = $upload_path . basename($file_name);
		if (move_uploaded_file($file_tmp_name, $file_path)) {
			$attachmenturl = $file_name;
		}else{
			$attachmenturl = '';
		}
		$wpdb->insert('wp_ticket_attachment_docs', [
			"ticket_id" => $lastid,
			"attachment" => $file_name,
			"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>";
		}
		
	}
	?>
	
<div class="container">
	<form method="post" name="servicerequest" 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 new_equipment">
						<th scope="row"><label for="equipment_id">Select Equipment<span class="description"></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="ticket_problem_description">Problem Description <span class="description">(required)</span></label></th>
						<td>
							<textarea name="problem_description" id="ticket_problem_description" class="regular-text"></textarea>
							<span class="error-message wc_probticketdesc"></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="hidden" name="problem_type" class="form-control" value="2">
			<input type="submit" name="servicerequest" id="servicerequest" class="button button-primary" value="Create New Request"></p>
	</form>
	</div>
<script type="text/javascript">

function create_servicereq() {
	
	
    var problem_description = jQuery('#ticket_problem_description').val();
	if(problem_description == ''){
        jQuery('.wc_probticketdesc').html("Please Enter Problem Description").addClass("error-msg");
		return false;
    }else{
        jQuery('.wc_probticketdesc').html('');
    }
}

</script>
<?php
}
add_action('woocommerce_account_operator-create-servicerequest_endpoint', 'operator_create_servicerequest_content');

Youez - 2016 - github.com/yon3zu
LinuXploit