<?php

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

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

$html_content = file_get_contents('manual_dom_games_global.html');
require_once('simple_html_dom.php');
$html = str_get_html($html_content);

// https://clientzone.gamesglobal.com/Games
// aleks@slotcatalog.com
// Uhfa1234!

$insertedGames = [];

foreach ($html->find('.RoadmapTile_roadmap-tile-container__W4yQe') as $div) {

        $link = $div->find('picture a', 0);
        $link = $link->href;
        $link = "https://clientzone.gamesglobal.com".$link;
        
        $provider_id = $id;

        $parts = explode('/', $link);
        $gameId = end($parts);
        $name = $gameId;
        $name = preg_replace('/(?<=[a-z])(?=[A-Z0-9])|(?<=[0-9])(?=[A-Za-z])/', ' ', $name);
        $name = str_replace("of ", " of ", $name);
        $name = str_replace("with ", " with ", $name);
        $name = str_replace("the ", " the ", $name);
        $name = str_replace("da ", " da ", $name);
        $name = str_replace("and ", " and ", $name);
        $name = str_replace("Multih and ", "Multihand ", $name);
        $name = str_replace(" VS", " VS ", $name);
        $name = str_replace(" II", " II ", $name);
        $name = str_replace("Thunderstruck II ", "Thunderstruck II", $name);
        $name = str_replace("Thunderstruck IIMega Moolah", "Thunderstruck II Mega Moolah", $name);
        $name = str_replace("WOWPOTMegaways", "WOWPOT Megaways", $name);
        $name = str_replace("Links of Ra II ", "Links of Ra II", $name);
        $name = str_replace("Fly XCash Boosta", "FlyX Cash Boosta", $name);
        $name = str_replace("Spinny Mc Winnagin Loot Boost", "Spinny McWinnagin Loot Boost", $name);
        $name = str_replace("AFlight of Fortune", "A Flight of Fortune", $name);
        $name = str_replace("OADiamond Rush Roulette", "OA Diamond Rush Roulette", $name);
        
        $translit = str_replace(" ", "-", $name);
        $translit = str_replace("&#039;", "-", $translit);
        $translit = str_replace("&#39;", "-", $translit);
        $translit = preg_replace("/[^a-zA-Z0-9\-]/", "", $translit);
        $translit = str_replace("---", "-", $translit);
        $translit = str_replace("--", "-", $translit);

        $demo_desk = "https://redirector3.valueactive.eu/Casino/Default.aspx?applicationid=1023&theme=quickfiressl&usertype=5&sext1=demo&sext2=demo&csid=1867&serverid=1867&variant=MAL-Demo&gameid=".$gameId."Desktop&ul=en";
        
        $demo_mob = "https://redirector3.valueactive.eu/Casino/Default.aspx?applicationid=1023&theme=quickfiressl&usertype=5&sext1=demo&sext2=demo&csid=1867&serverid=1867&variant=MAL-Demo&gameid=".$gameId."&ul=en";
        
        $volatility = 0;

        $rtp = 0.0;

        $rtp_low = 0.0;
        
        $rtp_high = 0.0;
        
        $max_win = 0.0;
        
        $img = $div->find('picture img', 0);
        $img = $img->src;

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

        require ('insert_values.php');

        require ('inserted_games.php');

        // sleep(1);
}

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