<?php
// splice_audio.php
// RJM Programming
// April, 2025
// Help out splice_audio.htm

  $hcont=file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/Mac/iPad/splice_audio.htm');
  $totsecs=0;
 
  $one=1;
  while (isset($_POST['audio' . $one])) {
    if (strpos(urldecode($_POST['end' . $one]), '-') === false) {
      $totsecs+=($_POST['end' . $one] - $_POST['start' . $one]);
    } else if (strlen($_POST['audio' . $one]) > 0) {
      $totsecs+=5;
    }
    $hcont=str_replace("audio" . $one . "=')[1].split('&')[0]) : '';", "audio" . $one . "=')[1].split('&')[0]) : '" . str_replace(' ','+',urldecode($_POST['audio' . $one])) . "';", $hcont);
    $hcont=str_replace("start" . $one . "=')[1].split('&')[0]) : thedef;", "start" . $one . "=')[1].split('&')[0]) : '" . str_replace(' ','+',urldecode($_POST['start' . $one])) . "';", $hcont);
    $hcont=str_replace("end" . $one . "=')[1].split('&')[0]) : thedef;", "end" . $one . "=')[1].split('&')[0]) : Math.ceil(" . str_replace(' ','+',urldecode($_POST['end' . $one])) . ");", $hcont);
    $hcont=str_replace("start" . $one . " value=0 ", "start" . $one . " value='" . str_replace(' ','+',urldecode($_POST['start' . $one])) . "' ", $hcont);
    $hcont=str_replace("end" . $one . " value=-1 ", "end" . $one . " value='" . str_replace(' ','+',urldecode($_POST['end' . $one])) . "' ", $hcont);
    $one++;
  }
  
  if (isset($_POST['hide'])) {
    $hcont=str_replace(" : 'offoff';", " : '" . str_replace('+',' ',urldecode($_POST['hide'])) . "';", $hcont);
  }
  
  if (isset($_POST['background'])) {
    $hcont=str_replace(" : burl;", " : \"" . str_replace('+',' ',urldecode($_POST['background'])) . "\";", $hcont);
  }

  if (isset($_POST['subistwo'])) {
    $hcont=str_replace('<body onload="', "<body onload=\" if (window.parent) {  setTimeout(function(){  window.parent.focus(); }, " . (1000 * $totsecs) . "); } ", $hcont);
  }
      
  echo str_replace('(176 == 176 || ', '(176 == 179 || ', str_replace(' type="submit"',' type="button"', $hcont));
  
?>
