<?php
 require '../../data.php';
     $dirname = $_SERVER['DOCUMENT_ROOT']."/images/games/";
     $imgdir = glob($dirname.'*.{jpg,png,gif}', GLOB_BRACE);
 
     $counter6 = 1;
     $counter8 = 1;
     $counter7 = 1;
     foreach($imgdir as $imagess) {
          $findjam = "SELECT jam_rtp FROM jam_gacor_rtp WHERE jam_nomor = " .$counter6++;
          $qjam = mysqli_query($data, $findjam);
          $day = date("l");

          $forjam = (rand(0,23));
          $formin = (rand(0,59));
          $jam = str_pad($forjam,2, '0', STR_PAD_LEFT);
          $min = str_pad($formin,2, '0', STR_PAD_LEFT);
          
          $forjam2 = (rand(0,23));
          $formin2 = (rand(0,59));
          $jam2 = str_pad($forjam2,2, '0', STR_PAD_LEFT);
          $min2 = str_pad($formin2,2, '0', STR_PAD_LEFT); 

          $timeforgacor1 = $jam. ":" .$min;
          $timeforgacor2 = $jam2. ":" .$min2;

          if(mysqli_num_rows($qjam) > 0) {
          $sday = "SELECT * FROM jam_gacor_rtp WHERE change_day != '$day'";
          $qday = mysqli_query($data, $sday);

          if(mysqli_num_rows($qday) > 0) {
               while($ffday = mysqli_fetch_assoc($qday)){
               $ujam = "UPDATE jam_gacor_rtp SET jam_rtp = '$timeforgacor1', jam_rtp_2 = '$timeforgacor2', change_day = '$day' WHERE jam_nomor = " . $counter7++;
               mysqli_query($data, $ujam);
                }
          }

          } else {

               $snomor = "SELECT jam_nomor FROM jam_gacor_rtp ORDER BY id DESC LIMIT 1";
               $qnomor = mysqli_query($data, $snomor);
               $fnomor = mysqli_fetch_assoc($qnomor);
               $nosebelum = $fnomor['jam_nomor'];
               $tambahno = $nosebelum + 1;
          $insertjam = "INSERT INTO jam_gacor_rtp(jam_rtp, jam_rtp_2, change_day, jam_nomor)VALUES('$timeforgacor1', '$timeforgacor2', '$day', ".$tambahno.")";
          mysqli_query($data, $insertjam);

          }
     }

?>