<?php
// Connect to the database
require_once('pdo.php');
require_once('get_provider_translit.php');
require('create_images.php');

$id = 32;
$provider_translit = getProviderTranslit($id);

// Load HTML content from a locally stored file
$html_content = file_get_contents('manual_dom_isoftbet.html');

// Include the Simple HTML DOM Parser library
require_once('simple_html_dom.php');

$html = str_get_html($html_content);

$insertedGames = [];

foreach ($html->find('.block-view-item') as $div) {

        $link = $div->find('.post_excerpt a', 0);
        $link = $link->href;

        $name = $div->find('.game_title', 0);
        $name = $name->plaintext;
        $name = str_replace(" ™", "", $name);
        $name = str_replace("™", "", $name);

        $provider_id = $id;

        $translit = str_replace(" ", "-", $name);
        $translit = str_replace("&#039;", "-", $translit);
        $translit = str_replace("&amp;", "", $translit);
        $translit = preg_replace("/[^a-zA-Z0-9\-]/", "", $translit);
        $translit = str_replace("---", "-", $translit);
        $translit = str_replace("--", "-", $translit);

        $demo_desk = $div->find('.post_excerpt a', 1);
        $demo_desk = $demo_desk->href;
        $demo_desk = str_replace("javascript:void(window.open('", "", $demo_desk);
        $demo_desk = str_replace("', 'popup', 'height='+screen.height+',width='+screen.width+'resizable=yes'))", "", $demo_desk);
        $demo_desk = str_replace("&amp;", "&", $demo_desk);

        $demo_mob = $demo_desk;
        
        $volatility = 0;
        $rtp = 0.0;
        $rtp_low = 0.0;
        $rtp_high = 0.0;
        $max_win = 0.0;

        $img = $div->find('.post_excerpt', 0);
        $img = $img->style;
        $img = str_replace("background: url('", "", $img);
        $img = str_replace("') no-repeat scroll center center transparent; background-size: cover;", "", $img);

        createImage($provider_translit, $translit, $img);

        require ('insert_values.php');

        require ('inserted_games.php');
}

// echo json_encode(['insertedGames' => $insertedGames]);
?>
