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/approve.php
<?php

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

// Include WP_List_Table
if (!class_exists('WP_List_Table')) {
    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}

class Logsheet_Approval_Plugin {
    public function __construct() {
        add_action('init', array($this, 'init'));
        add_action('admin_menu', array($this, 'admin_menu'));
        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
        add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
        add_action('wp', array($this, 'schedule_auto_approve_logsheets'));
        add_action('auto_approve_logsheets', array($this, 'auto_approve_logsheets'));
        add_filter('set-screen-option', array($this, 'set_screen_option'), 10, 3);
        
        register_activation_hook(__FILE__, array($this, 'activate'));
        register_deactivation_hook(__FILE__, array($this, 'deactivate'));
    }

    public function init() {
        add_shortcode('customer_log_approval', array($this, 'display_customer_log_approval'));
        $this->handle_logsheet_submissions();
    }

    public function enqueue_scripts() {
        wp_enqueue_style('logsheet-approval-style', plugin_dir_url(__FILE__) . 'css/style.css');
        wp_enqueue_script('logsheet-approval-script', plugin_dir_url(__FILE__) . 'js/script.js', array('jquery'), '', true);
    }

    public function admin_menu() {
        $hook = add_menu_page(
           // 'operator-dashboard',
            'Logsheet Approval',
            'Logsheet Approval',
            'manage_options',
            'logsheet-approval',
            array($this, 'admin_page'),
            'dashicons-clipboard',
            6
        );
        add_action("load-$hook", array($this, 'screen_option'));

        add_submenu_page(
            '',
            'Edit Logsheet',
            'Edit Logsheet',
            'manage_options',
            'edit-logsheet',
            array($this, 'edit_logsheet_page')
        );
    }

    public function screen_option() {
        $option = 'per_page';
        $args = array(
            'label' => 'Logsheets per page',
            'default' => 20,
            'option' => 'logsheets_per_page'
        );
        add_screen_option($option, $args);
    }

    public function set_screen_option($status, $option, $value) {
        return $value;
    }

    public function admin_page() {
        if (!current_user_can('manage_options')) {
            return;
        }

        $hidden = get_hidden_columns('logsheet_approval');
        $columns = array(
            'operator_name' => 'Operator Name',
            'customer_name' => 'Customer Name',
            'equipment_name' => 'Equipment Name',
            'image' => 'Image',
            'remark' => 'Remark',
            'log_sheet_id' => 'Log Sheet ID',
            'customer_uploaded_pdf' => 'Customer Uploaded PDF',
            'log_status' => 'Log Status',
            'action' => 'Action'
        );

        if (isset($_POST['screen-options-apply'])) {
            $hidden = isset($_POST['hidden-columns']) ? $_POST['hidden-columns'] : array();
            update_user_option(get_current_user_id(), 'manage_logsheet_approval_columnshidden', $hidden, true);
        }

        ?>
        <div class="wrap">
            <h1><?php echo esc_html(get_admin_page_title()); ?></h1>
            <form method="post" action="">
                <?php
                wp_nonce_field('logsheet_approval_nonce', 'logsheet_approval_nonce');
                $table = new Logsheet_Approval_List_Table($columns, $hidden);
                $table->prepare_items();
                $table->display();
                ?>
            </form>
        </div>
        <?php
    }

    public function edit_logsheet_page() {
        // Implementation for editing logsheet
        echo '<div class="wrap"><h1>Edit Logsheet</h1><p>Edit logsheet form will be implemented here.</p></div>';
    }

    // Customer Account section    
    public function display_customer_log_approval() {
        if (!is_user_logged_in()) {
            return 'Please log in to view your logsheets.';
        }

        $current_user = wp_get_current_user();
        $customer_id = $current_user->ID;
        $logsheets = $this->get_logsheets_for_customer($customer_id);

        ob_start();
        ?>
        <div class="customer-log-approval">
            <h2>Logsheet Approval</h2>
            <table class="logsheet-table">
                <thead>
                    <tr>
                        <th>Contract ID</th>
                        <th>Log Sheet ID</th>
                        <th>Operator Name</th>
                        <th>Date</th>
                        <th>Download Logsheet</th>
                        <th>Upload PDF</th>
                        <th>Remark</th>
                        <th>Log Status</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($logsheets as $logsheet) : ?>
                        <tr>
                            <td><?php echo esc_html($logsheet->contract_id); ?></td>
                            <td><?php echo esc_html($logsheet->log_sheet_id); ?></td>
                            <td><?php echo esc_html($logsheet->operator_name); ?></td>
                            <td><?php echo esc_html($logsheet->date); ?></td>
                            <td><a href="<?php echo esc_url($logsheet->download_url); ?>" class="button">Download PDF</a></td>
                            <td>
                                <form method="post" enctype="multipart/form-data">
                                    <input type="file" name="customer_pdf" accept=".pdf">
                                    <input type="hidden" name="log_sheet_id" value="<?php echo esc_attr($logsheet->log_sheet_id); ?>">
                                    <input type="submit" name="upload_pdf" value="Upload" class="button">
                                </form>
                            </td>
                            <td>
                                <textarea name="customer_remark" rows="2" cols="20"><?php echo esc_textarea($logsheet->customer_remark); ?></textarea>
                            </td>
                            <td>
                                <select name="log_status" <?php echo ($logsheet->log_status === 'approved') ? 'disabled' : ''; ?>>
                                    <option value="approved" <?php selected($logsheet->log_status, 'approved'); ?>>Approved</option>
                                    <option value="rejected" <?php selected($logsheet->log_status, 'rejected'); ?>>Rejected</option>
                                    <option value="revised" <?php selected($logsheet->log_status, 'revised'); ?>>Revised</option>
                                </select>
                            </td>
                            <td>
                                <?php if ($logsheet->log_status !== 'approved') : ?>
                                    <button type="submit" name="save_logsheet" value="<?php echo esc_attr($logsheet->log_sheet_id); ?>" class="button">Save</button>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php
        return ob_get_clean();
    }

    private function get_logsheets_for_customer($customer_id) {
        global $wpdb;
        $table_name = $wpdb->prefix . 'logsheet_approval';
        return $wpdb->get_results($wpdb->prepare(
            "SELECT * FROM $table_name WHERE customer_id = %d ORDER BY date DESC",
            $customer_id
        ));
    }

    public function handle_logsheet_submissions() {
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            if (isset($_POST['upload_pdf'])) {
                $this->handle_pdf_upload();
            } elseif (isset($_POST['save_logsheet'])) {
                $this->handle_logsheet_save();
            } elseif (isset($_POST['send_to_customer'])) {
                $this->handle_send_to_customer();
            }
        }
    }

    private function handle_pdf_upload() {
    }

    private function handle_logsheet_save() {
    }

    private function handle_send_to_customer() {
    }

    public function schedule_auto_approve_logsheets() {
        if (!wp_next_scheduled('auto_approve_logsheets')) {
            wp_schedule_event(time(), 'hourly', 'auto_approve_logsheets');
        }
    }

    public function auto_approve_logsheets() {
        global $wpdb;
        $table_name = $wpdb->prefix . 'logsheet_approval';
        $wpdb->query(
            $wpdb->prepare(
                "UPDATE $table_name SET log_status = 'approved' WHERE log_status = 'pending' AND sent_to_customer = 1 AND TIMESTAMPDIFF(HOUR, sent_date, NOW()) >= 48"
            )
        );
    }

    public function activate() {
        global $wpdb;
        $table_name = $wpdb->prefix . 'logsheet_approval';
        $charset_collate = $wpdb->get_charset_collate();

        $sql = "CREATE TABLE $table_name (
            id mediumint(9) NOT NULL AUTO_INCREMENT,
            operator_name varchar(100) NOT NULL,
            customer_name varchar(100) NOT NULL,
            equipment_name varchar(100) NOT NULL,
            remark text,
            log_sheet_id varchar(50) NOT NULL,
            customer_pdf_url varchar(255),
            contract_id varchar(50) NOT NULL,
            date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            sent_to_customer tinyint(1) DEFAULT 0,
            sent_date datetime,
            customer_id mediumint(9) NOT NULL,
            PRIMARY KEY  (id)
        ) $charset_collate;";

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($sql);
    }

    public function deactivate() {
        wp_clear_scheduled_hook('auto_approve_logsheets');
    }
    
}

class Logsheet_Approval_List_Table extends WP_List_Table {
    private $columns;
    private $hidden;

    public function __construct($columns, $hidden) {
        parent::__construct([
            'singular' => 'logsheet',
            'plural'   => 'logsheets',
            'ajax'     => false
        ]);
        $this->columns = $columns;
        $this->hidden = $hidden;
    }

    public function get_columns() {
        return $this->columns;
    }

    public function get_hidden_columns() {
        return $this->hidden;
    }

    public function prepare_items() {
        global $wpdb;
        $table_name = $wpdb->prefix . 'logsheet_approval';

        $per_page = $this->get_items_per_page('logsheets_per_page', 20);
        $current_page = $this->get_pagenum();
        $total_items = $wpdb->get_var("SELECT COUNT(*) FROM $table_name");

        $this->set_pagination_args([
            'total_items' => $total_items,
            'per_page'    => $per_page
        ]);

        $this->items = $wpdb->get_results($wpdb->prepare(
            "SELECT * FROM $table_name ORDER BY date DESC LIMIT %d OFFSET %d",
            $per_page,
            ($current_page - 1) * $per_page
        ), ARRAY_A);
    }

    public function column_default($item, $column_name) {
        switch ($column_name) {
            case 'image':
                return '<img src="' . esc_url($item['image_url']) . '" width="50" height="50" />';
            case 'customer_uploaded_pdf':
                return $item['customer_pdf_url'] ? '<a href="' . esc_url($item['customer_pdf_url']) . '">Download</a>' : 'Not uploaded';
            case 'action':
                $actions = array(
                    'edit'      => sprintf('<a href="%s">Edit</a>', admin_url('admin.php?page=edit-logsheet&id=' . $item['id'])),
                    'send'      => sprintf('<button class="send-to-customer" data-id="%s"%s>Send to Customer</button>', $item['id'], $item['sent_to_customer'] ? ' disabled' : '')
                );
                return $this->row_actions($actions);
            default:
                return $item[$column_name];
        }
    }
}

// Initialize the plugin
new Logsheet_Approval_Plugin();

Youez - 2016 - github.com/yon3zu
LinuXploit