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

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

// Load HTML content from a locally stored file
//https://www.jdbgaming.com/game/list
$html_content = file_get_contents('manual_dom_jdb.html');

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

$html = str_get_html($html_content);

$insertedGames = [];

foreach ($html->find('.c-game-card') as $div) {

        $link = $div->find('a', 0);
        $link = $link->href;
        $link = "https://www.jdbgaming.com".$link;

        $name = $div->find('h4', 0);
        $name = $name->plaintext;
        $name = rtrim($name);
        $name = str_replace("\342\205\240", "I", $name);
        $name = str_replace("\342\205\241", "II", $name);

        $provider_id = $id;

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

        $parts = explode('/', $link);
        $gameId = end($parts);

        $demo_desk = "https://api.jdbgaming.com/game/demo?lang=en-US&id=".$gameId;

        $demo_mob = "https://api.jdbgaming.com/game/demo?lang=en-US&id=".$gameId;

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

        $img = $div->find('.img-fluid', 0);
        $img = $img->src;

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

        require ('insert_values.php');

        require ('inserted_games.php');
}

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