<?php
// shower_songs.php
// April, 2026
// RJM Programming
// Help out shower_songs.html regarding local media files accessed via email or SMS

$dst=str_replace('~','',str_replace('3~','2',(substr(date("Ymd"),0,7) . '~'))) . '0';
$phpis=file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'shower_songs.php');
$newphpis='';

if (strpos($phpis, ' of ' . $dst . ' goes ') !== false) {
  $dst=$dst;
} else if (strpos($phpis, 'Dat' . 'a of ') !== false) {
  $olddst=explode(' ',explode('Dat' . 'a of ', $phpis)[1])[0];
  $allrecs=explode('/' . '/' . '/' . '/', $phpis);
  $newphpis=$phpis;
  for ($ij=1; $ij<sizeof($allrecs); $ij++) {
    if (substr(substr($allrecs[$ij],4,7)) == substr($olddst,0,7)) {
      $newphpis=str_replace('/' . '/' . '/' . '/' . explode('/' . '/' . '/' . '/',explode("\n",$allrecs[$ij])[0])[0], "", str_replace('/' . '/' . '/' . '/' . explode('/' . '/' . '/' . '/',explode("\n",$allrecs[$ij])[0])[0] . "\n", "", $newphpis));
    }
  }
  $newphpis=str_replace('Dat' . 'a of ' . $olddst . ' ', 'Dat' . 'a of ' . $dst . ' ', $newphpis);
}

if (isset($_POST['dataform'])) {
 
 if (isset($_POST['onetoseven']) && isset($_POST['durl'])) {
   if ($newphpis == '') {
     $newphpis=$phpis;
   }
   $newphpis.="\n/" . "/" . "/" . "/" . $_POST['dataform'] . substr($dst,0,7) . $_POST['onetoseven'] . str_replace(' ','+',urldecode($_POST['durl'])) . "\n";
 }
 
 if ($newphpis != '' && $newphpis != $phpis) {
   file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'shower_songs.php', $newphpis);
 }
 
 exit;
} else if (isset($_GET['dataform'])) {
 $htmlis=file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'shower_songs.html');
 $relrecs=explode('/' . '/' . '/' . '/' . $_GET['dataform'] . substr($dst,0,7), $phpis);
 for ($ij=1; $ij<sizeof($relrecs); $ij++) {
   if (substr($relrecs[$ij],0,1) >= '1' && substr($relrecs[$ij],0,1) <= '7') {
     //file_put_contents('xz.xz', '' . substr($relrecs[$ij],0,1));
     $relplaces=explode(substr($relrecs[$ij],0,1) . '" value="', $htmlis);
     //file_put_contents('xz2.xz2', '' . sizeof($relplaces) . ' ' . sizeof(explode('1" value="',$htmlis)));
     if (sizeof($relplaces) > 1) {
       $htmlis=str_replace(substr($relrecs[$ij],0,1) . '" value="' . explode('"',$relplaces[1])[0] . '"', substr($relrecs[$ij],0,1) . '" value="' . explode('/' . '/' . '/' . '/',explode("\n",substr($relrecs[$ij],1))[0])[0] . '"', $htmlis);
     }
   }
 }
 file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'shower_songs.htm', $htmlis);
 
 if ($newphpis != '' && $newphpis != $phpis) {
   file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'shower_songs.php', $newphpis);
 }
 
 header('Location: ./shower_songs.htm' . str_replace('&#order=','#order=',str_replace('order=','#order=',str_replace('??','?',('?' . $_SERVER['QUERY_STRING'])))));
 
 exit;
}

if (str_replace('?','',$_SERVER['QUERY_STRING']) == '') {
header('Location: ./shower_songs.html');
} else {
header('Location: ./shower_songs.html' . str_replace('&#order=','#order=',str_replace('order=','#order=',str_replace('??','?',('?' . $_SERVER['QUERY_STRING'])))));
}

?>
// Data of 20260420 goes below ...
