<?php
/*
Plugin Name: Data Itu
Plugin URI: https://x.com/
Description: This is a simple WordPress plugin boilerplate.
Version: 0.0.1
Author: ХАРПА
Author URI: https://x.com/
License: GPL2
*/

// Prevent direct file access
defined('ABSPATH') or die('No script kiddies please!');

class WP_Data_Itu
{
    function __construct()
    {
        add_shortcode('data_itu', array($this, 'data_itu_callback'));
		add_shortcode('data_itu_2', array($this, 'data_itu_2_callback'));
        add_action('wp_enqueue_scripts',  array($this, 'data_itu_enqueue_scripts'));
    }

    function data_itu_callback()
    {
        if ( ! is_admin() ) {
            ?>
            <script>
            var patType = '4d';
            </script>
            <?php
            // URL TARGET
            $url = 'http://178.128.19.25/';
            // get / mengambil content berdasarkan url yang akan di curi datanya
            $content = file_get_contents($url);

            // Create a new DOM Document
            $dom = new DOMDocument;

            // Load the HTML into the DOM Document
            @$dom->loadHTML($content);

            // Create a new XPath object
            $xpath = new DOMXPath($dom);

            // Query the DOM using XPath to find the table with the id 'colormenu '
            $colormenus = $xpath->query('//div[@id="colormenu"]');

            // If the table was found
            if ($colormenus->length > 0) {
                // Get the first table
                $colormenu = $colormenus->item(0);

                // Get the HTML of the table
                $colormenu_html = $dom->saveHTML($colormenu);

                // Output the table HTML
                echo $colormenu_html;
            }

            // Query the DOM using XPath to find the table with the id 'drawing-table'
            $tables = $xpath->query('//table[@id="drawing-table"]');

            // If the table was found
            if ($tables->length > 0) {
                // Get the first table
                $table = $tables->item(0);

                // Get the HTML of the table
                $table_html = $dom->saveHTML($table);

                // Output the table HTML
                echo $table_html;
            }

            // Query the DOM using XPath to find the table with the id 'drawing-table'
            $forms = $xpath->query('//form[@id="selectForm"]');

            // If the table was found
            if ($forms->length > 0) {
                // Get the first table
                $form = $forms->item(0);

                // Get the HTML of the table
                $form_html = $dom->saveHTML($form);

                // Output the table HTML
                echo $form_html;
            }
        }
    }
	
	function data_itu_2_callback()
    {
        if ( ! is_admin() ) {
            ?>
            <?php
            // URL TARGET
            $url = 'http://139.59.224.92/';
            // get / mengambil content berdasarkan url yang akan di curi datanya
            $content = file_get_contents($url);

            // Create a new DOM Document
            $dom = new DOMDocument;

            // Load the HTML into the DOM Document
            @$dom->loadHTML($content);

            // Create a new XPath object
            $xpath = new DOMXPath($dom);

            // Query the DOM using XPath to find the table with the id 'customers '
            $customers = $xpath->query('//table[@id="customers"]');

            // If the table was found
            if ($customers->length > 0) {
                // Get the first table
                $customer = $customers->item(0);

                // Get the HTML of the table
                $customer_html = $dom->saveHTML($customer);

                // Output the table HTML
                echo $customer_html;
            }

        }
    }

    function data_itu_enqueue_scripts()
    {
		if ( ! is_admin() ) {
			wp_enqueue_script('jquery');
			wp_enqueue_script('popper', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js', ['jquery'], '1.0.0', true);
			wp_enqueue_script('bootstrap', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.min.js', ['jquery', 'popper'], '1.0.0', true);
			wp_enqueue_script('jquery-1-11-3', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', [], '1.0.0', true);
			wp_enqueue_script('scripts', 'https://app.datawarna.co/assets/js/scripts.js?v=4.0', ['jquery', 'popper', 'bootstrap', 'tglcp', 'tgldt'], '1.0.0', true);
			wp_enqueue_script('tglcp', 'https://app.datawarna.co/assets/js/tglcp.js', ['jquery', 'popper', 'bootstrap'], '1.0.0', true);
			wp_enqueue_script('tgldt', 'https://app.datawarna.co/assets/js/tgldt.js', ['jquery', 'popper', 'bootstrap'], '1.0.0', true);
			wp_enqueue_script('data-itu-paito', plugin_dir_url(__FILE__) . 'js/paito.js', ['jquery', 'popper', 'bootstrap', 'tglcp', 'tgldt'], '1.0.0', true);

			wp_enqueue_style('bootstrap', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css');
			wp_enqueue_style('data-itu', plugin_dir_url(__FILE__) . 'css/style.css', '1.0.0');
		}
    }
}

// Initialize the plugin
if (class_exists('WP_Data_Itu')) {
    $wp_data_itu = new WP_Data_Itu();
}
