<?php 
include ('includes/json_utils.php');
include ('includes/header.php');

$page_name = 'player_selection';


if (isset($_POST['submit']) && isset($_POST['data'])) {
    foreach ($_POST['data'] as $id => $fields) {
        updateJsonRecordByIdMulty($id, $fields);
    }

    echo "<script>window.location.href='" . $page_name . ".php?status=1'</script>";
}


?>

<div class="col-md-6 mx-auto ctmain-table">
    <div class="card-body">
        <div class="card text-white ctcard">
            <div class="card-header card-header-warning">
                <center>
                    <h2><i class="icon icon-bullhorn"></i> Player Selection</h2>
                </center>
            </div>
            
            <div class="card-body">
                <form method="post">
                    <div class="form-group ctinput">
                      <label class="form-label"> Auto-Update Live,Movies & Series :</label>
                      <input type="hidden" name="data[18][preffile]" value="MyPrefPlayer">
                      <input type="hidden" name="data[18][preftype]" value="string">
                      <input type="hidden" name="data[18][prefname]" value="LivePkgName">
                      <select name="data[18][mods]">
                        <option value="default" <?php echo (getmodsbyid('18') == 'default') ? 'selected' : ''; ?>>Built-in Player (Hardware/Software Decoder)</option>
                        <option value="default_native" <?php echo (getmodsbyid('18') == 'default_native') ? 'selected' : ''; ?>>Built-in Player (Native)</option>
                      </select>
                    </div>
                    <div type="hidden" class="form-group ctinput">
                      <label type="hidden" class="form-label"></label>
                      <input type="hidden" name="data[19][preffile]" value="MyPrefPlayer">
                      <input type="hidden" name="data[19][preftype]" value="string">
                      <input type="hidden" name="data[19][prefname]" value="LiveAppName">
                      <input type="hidden" name="data[19][mods]" value="Built-in Player (Hardware/Software Decoder)">
                    </div>

                    <div class="form-group ctinput">
                      <label class="form-label"> Movies :</label>
                      <input type="hidden" name="data[20][preffile]" value="MyPrefPlayer">
                      <input type="hidden" name="data[20][preftype]" value="string">
                      <input type="hidden" name="data[20][prefname]" value="VODPkgName">
                      <select name="data[20][mods]">
                        <option value="default" <?php echo (getmodsbyid('20') == 'default') ? 'selected' : ''; ?>>Built-in Player (Hardware/Software Decoder)</option>
                        <option value="default_native" <?php echo (getmodsbyid('20') == 'default_native') ? 'selected' : ''; ?>>Built-in Player (Native)</option>
                      </select>
                    </div>
                    <div type="hidden" class="form-group ctinput">
                      <label type="hidden" class="form-label"></label>
                      <input type="hidden" name="data[21][preffile]" value="MyPrefPlayer">
                      <input type="hidden" name="data[21][preftype]" value="string">
                      <input type="hidden" name="data[21][prefname]" value="VODAppName">
                      <input type="hidden" name="data[21][mods]" value="Built-in Player (Hardware/Software Decoder)">
                    </div>


                    <div class="form-group ctinput">
                      <label class="form-label"> Series :</label>
                      <input type="hidden" name="data[22][preffile]" value="MyPrefPlayer">
                      <input type="hidden" name="data[22][preftype]" value="string">
                      <input type="hidden" name="data[22][prefname]" value="SeriesPkgName">
                      <select name="data[22][mods]">
                        <option value="default" <?php echo (getmodsbyid('22') == 'default') ? 'selected' : ''; ?>>Built-in Player (Hardware/Software Decoder)</option>
                        <option value="default_native" <?php echo (getmodsbyid('22') == 'default_native') ? 'selected' : ''; ?>>Built-in Player (Native)</option>
                      </select>
                    </div>
                    <div type="hidden" class="form-group ctinput">
                      <label type="hidden" class="form-label"></label>
                      <input type="hidden" name="data[23][preffile]" value="MyPrefPlayer">
                      <input type="hidden" name="data[23][preftype]" value="string">
                      <input type="hidden" name="data[23][prefname]" value="SeriesAppName">
                      <input type="hidden" name="data[23][mods]" value="Built-in Player (Hardware/Software Decoder)">
                    </div>

                    <div class="form-group ctinputform-group">
                        <center>
                            <button class="btn btn-info" name="submit" type="submit">
                                <i class="icon icon-check"></i> Submit
                            </button>
                        </center>
                    </div>
                </form>
            </div>       
        </div>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
  const livetvselectElement = document.querySelector('select[name="data[18][mods]"]');
  const livetvhiddenInput = document.querySelector('input[name="data[19][mods]"]');

  const moviesselectElement = document.querySelector('select[name="data[20][mods]"]');
  const movieshiddenInput = document.querySelector('input[name="data[21][mods]"]');

  const seriesselectElement = document.querySelector('select[name="data[22][mods]"]');
  const seriesshiddenInput = document.querySelector('input[name="data[23][mods]"]');


  livetvselectElement.addEventListener('change', function () {
    if (livetvselectElement.value === 'default') {
      livetvhiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  } else if (livetvselectElement.value === 'default_native') {
    livetvhiddenInput.value = 'Built-in Player (Native)';
  } else {
    livetvhiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  }
  });

  if (livetvselectElement.value === 'default') {
    livetvhiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  } else if (livetvselectElement.value === 'default_native') {
    livetvhiddenInput.value = 'Built-in Player (Native)';
  } else {
    livetvhiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  }


  moviesselectElement.addEventListener('change', function () {
    if (moviesselectElement.value === 'default') {
      movieshiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  } else if (moviesselectElement.value === 'default_native') {
    movieshiddenInput.value = 'Built-in Player (Native)';
  } else {
    movieshiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  }
  });

  if (moviesselectElement.value === 'default') {
    movieshiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  } else if (moviesselectElement.value === 'default_native') {
    movieshiddenInput.value = 'Built-in Player (Native)';
  } else {
    movieshiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  }


  seriesselectElement.addEventListener('change', function () {
    if (seriesselectElement.value === 'default') {
      seriesshiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  } else if (seriesselectElement.value === 'default_native') {
    seriesshiddenInput.value = 'Built-in Player (Native)';
  } else {
    seriesshiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  }
  });

  if (seriesselectElement.value === 'default') {
    seriesshiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  } else if (seriesselectElement.value === 'default_native') {
    seriesshiddenInput.value = 'Built-in Player (Native)';
  } else {
    seriesshiddenInput.value = 'Built-in Player (Hardware/Software Decoder)';
  }
  
});
</script>


<?php include ('includes/footer.php');?>
