<?php

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

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

$url = 'https://jiligames.com/games?allGameButtonActive=true';
require_once('simple_html_dom.php');
$html_content = file_get_contents($url);
$html = str_get_html($html_content);

$insertedGames = [];

foreach ($html->find('.gamesBox--title') as $div) {

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

        $name = $div->find('.subtitle', 0);
        $name = $name->plaintext;
        if($name ==""){continue;}
        if($name =="Fortune Gems  "){$name = "Fortune Gems";}
        if($name =="Fortune Gems 2  "){$name = "Fortune Gems 2";}
        if($name =="Mini flush "){$name = "Mini flush";}
        if($name =="ROMA X"){$name = "RomaX";}
        if($name =="Bombing Fish"){$name = "Bombing Fishing";}
        if($name =="Fairness Games   (BlockLobby)"){$name = "Fairness Games (BlockLobby)";}
        if($name =="Fairness Games (BlockLobby)"){continue;}

        $provider_id = $id;

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

        $demo_desk = $div->find('.button-gameInfo a', 0);
        $demo_desk = $demo_desk->href;

        // Extracting the number from the URL
        $parsed_url = parse_url($demo_desk);
        $path = $parsed_url['path'];
        $parts = explode('/', $path);
        $number = end($parts);

        // Creating the new URL
        $demo_desk = "https://jiligames.com/PlusTrial/" . $number . "/en-us";


        $demo_mob = $demo_desk;

        $volatility = 0;

        $rtp = 0.0;

        $rtp_low = 0.0;

        $rtp_high = 0.0;

        $max_win = 0;

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

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

        require ('insert_values.php');

        require ('inserted_games.php');

}

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