<?php
// i_eg_js.php
// RJM Programming - December, 2024
// Rewrite i_eg.js as needed

  $iscand=false;
  $pcont='';
  $jscont='';
  $phplistcomp='';
  $desclistcomp='';
  if (file_exists('./i_eg.js')) {
    $jscont=file_get_contents('./i_eg.js');
    $bitsphpa=explode(' candidates="', $jscont);
    $bitsdesca=explode(' candidatesdesc="', $jscont);
    if (sizeof($bitsphpa) > 1 && sizeof($bitsdesca) > 1) {
      foreach (glob('./i_*eg.php') as $pfile) {
         $iscand=false;
         $pcont='';
         if (strpos(' ' . explode('"', $bitsphpa[1])[0] . ' ', ' ' . basename($pfile) . ' ') === false) {
            foreach (glob('./' . basename($pfile) . '*GETME') as $ppfile) {
              $iscand=true;
            }
         }
         if ($iscand) {
            $pcont=file_get_contents('./' . basename($pfile));
            if (strpos($pcont, '>Show ') === false) { $iscand=false; }
         }
         if ($iscand) {
            $jscont=str_replace(' candidates="' . explode('"', $bitsphpa[1])[0] . '"', ' candidates="' . explode('"', $bitsphpa[1])[0] . ' ' . basename($pfile) . '"', $jscont);
            $jscont=str_replace(' candidatesdesc="' . explode('"', $bitsdesca[1])[0] . '"', ' candidatesdesc="' . explode('"', $bitsdesca[1])[0] . ' ' . str_replace(' ','_',explode('"',explode('<', explode('>Show ', $pcont)[1])[0])[0]) . '"', $jscont);
            file_put_contents('./i_eg.js', $jscont);
            $bitsphpa=explode(' candidates="', $jscont);
            $bitsdesca=explode(' candidatesdesc="', $jscont);
         }
      }
    }
  }
  
?>
  