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

$page_name = 'general_settings';
$AutoStartrecord = getJsonRecordById('4');
$AutoStart_value = $AutoStartrecord['mods'];

$EPGrecord = getJsonRecordById('5');
$EPG_value = $EPGrecord['mods'];


$SUBTrecord = getJsonRecordById('6');
$SUBT_value = $SUBTrecord['mods'];

$EPGcharecord = getJsonRecordById('7');
$EPGcha_value = $EPGcharecord['mods'];


$recentLimitrecord = getJsonRecordById('8');
$recentLimit = $recentLimitrecord['mods'];

$chistoryLimitrecord = getJsonRecordById('9');
$chistoryLimit = $chistoryLimitrecord['mods'];


$uagentrecord = getJsonRecordById('10');
$uagent_value = $uagentrecord['mods'];



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> General settings</h2>
                </center>
            </div>
            
            <div class="card-body">
                <form method="post">
                <div class="form-group ctinput">
                    <label class="form-label"> Download :</label>  
                    <input type="hidden" name="data[40][preffile]" value="com.andyhax.pref">
                    <input type="hidden" name="data[40][preftype]" value="boolean">
                    <input type="hidden" name="data[40][prefname]" value="download_enable">
                    <select name="data[40][mods]">
                        <option value="true" <?php echo (getmodsbyid('40') == 'true') ? 'selected' : ''; ?>>Enable</option>
                        <option value="false" <?php echo (getmodsbyid('40') == 'false') ? 'selected' : ''; ?>>Disable</option>
                    </select>
                  </div>

                    <div class="form-group ctinput">
                    <label class="form-label"> AutoStart on Bootup (Beta) :</label>  
                    <input type="hidden" name="data[4][preffile]" value="auto_start">
                    <input type="hidden" name="data[4][preftype]" value="boolean">
                    <input type="hidden" name="data[4][prefname]" value="auto_start">
                    <select name="data[4][mods]">
                        <option value="true" <?php echo ($AutoStart_value == 'true') ? 'selected' : ''; ?>>Enable</option>
                        <option value="false" <?php echo ($AutoStart_value == 'false') ? 'selected' : ''; ?>>Disable</option>
                    </select>
                    </div>
                    
                    <div class="form-group ctinput">
                      <label class="form-label"> Show Full EPG :</label>
                      <input type="hidden" name="data[5][preffile]" value="auto_start">
                      <input type="hidden" name="data[5][preftype]" value="boolean">
                      <input type="hidden" name="data[5][prefname]" value="full_epg">
                      <select name="data[5][mods]">
                        <option value="true" <?php echo ($EPG_value == 'true') ? 'selected' : ''; ?>>Enable</option>
                        <option value="false" <?php echo ($EPG_value == 'false') ? 'selected' : ''; ?>>Disable</option>
                        </select>
                    </div>

                    <div class="form-group ctinput">
                      <label class="form-label"> Active Subtitle :</label>
                      <input type="hidden" name="data[6][preffile]" value="auto_start">
                      <input type="hidden" name="data[6][preftype]" value="boolean">
                      <input type="hidden" name="data[6][prefname]" value="subtitle_active">
                      <select name="data[6][mods]">
                        <option value="true" <?php echo ($SUBT_value == 'true') ? 'selected' : ''; ?>>Enable</option>
                        <option value="false" <?php echo ($SUBT_value == 'false') ? 'selected' : ''; ?>>Disable</option>
                      </select>
                    </div>

                    <div class="form-group ctinput">
                      <label class="form-label"> Show EPG in Channels Lits :</label>
                      <input type="hidden" name="data[7][preffile]" value="auto_start">
                      <input type="hidden" name="data[7][preftype]" value="boolean">
                      <input type="hidden" name="data[7][prefname]" value="show_epg_in_channels_list">
                      <select name="data[7][mods]">
                        <option value="true" <?php echo ($EPGcha_value == 'true') ? 'selected' : ''; ?>>Enable</option>
                        <option value="false" <?php echo ($EPGcha_value == 'false') ? 'selected' : ''; ?>>Disable</option>
                      </select>
                    </div>


                    <div class="form-group ctinput">
                      <label class="form-label"> Recently Added Limit :</label>
                      <input type="hidden" name="data[8][preffile]" value="auto_start">
                      <input type="hidden" name="data[8][preftype]" value="int">
                      <input type="hidden" name="data[8][prefname]" value="recently_added_limit">
                      <select name="data[8][mods]">
                        <option value="10" <?php echo ($recentLimit == '10') ? 'selected' : ''; ?>>10</option>
                        <option value="20" <?php echo ($recentLimit == '20') ? 'selected' : ''; ?>>20</option>
                        <option value="30" <?php echo ($recentLimit == '30') ? 'selected' : ''; ?>>30</option>
                        <option value="40" <?php echo ($recentLimit == '40') ? 'selected' : ''; ?>>40</option>
                        <option value="50" <?php echo ($recentLimit == '50') ? 'selected' : ''; ?>>50</option>
                        <option value="100" <?php echo ($recentLimit == '100') ? 'selected' : ''; ?>>100</option>
                      </select>
                    </div>

                    <div class="form-group ctinput">
                      <label class="form-label"> Channels History Limit :</label>
                      <input type="hidden" name="data[9][preffile]" value="auto_start">
                      <input type="hidden" name="data[9][preftype]" value="int">
                      <input type="hidden" name="data[9][prefname]" value="recently_watched_limit_live">
                      <select name="data[9][mods]">
                        <option value="5" <?php echo ($chistoryLimit == '5') ? 'selected' : ''; ?>>5</option>
                        <option value="10" <?php echo ($chistoryLimit == '10') ? 'selected' : ''; ?>>10</option>
                        <option value="20" <?php echo ($chistoryLimit == '20') ? 'selected' : ''; ?>>20</option>
                        <option value="30" <?php echo ($chistoryLimit == '30') ? 'selected' : ''; ?>>30</option>
                        <option value="40" <?php echo ($chistoryLimit == '40') ? 'selected' : ''; ?>>40</option>
                        <option value="50" <?php echo ($chistoryLimit == '50') ? 'selected' : ''; ?>>50</option>
                      </select>
                    </div>


                    <div class="form-group ctinput">
                      <label class="form-label"> User agent :</label>
                      <input type="hidden" name="data[10][preffile]" value="user_agent">
                      <input type="hidden" name="data[10][preftype]" value="string">
                      <input type="hidden" name="data[10][prefname]" value="user_agent">
                      <div class="form-group ctinput">
                          <input class="form-control" name="data[10][mods]"  value="<?php echo ($uagent_value )?>"  placeholder="User agent" type="text"/>
                      </div>
                    </div>

                    <div class="form-group ctinput">
                      <label class="form-label"> Language (Beta):</label>
                      <input type="hidden" name="data[11][preffile]" value="LanguageSelectionPref">
                      <input type="hidden" name="data[11][preftype]" value="string">
                      <input type="hidden" name="data[11][prefname]" value="SelectedLanguage">
                      <select name="data[11][mods]">
                        <option value="English" <?php echo (getmodsbyid('11') == 'English') ? 'selected' : ''; ?>>English</option>
                        <option value="Polish" <?php echo (getmodsbyid('11') == 'Polish') ? 'selected' : ''; ?>>Polish</option>
                        <option value="Portuguese" <?php echo (getmodsbyid('11') == 'Portuguese') ? 'selected' : ''; ?>>Portuguese</option>
                        <option value="Turkish" <?php echo (getmodsbyid('11') == 'Turkish') ? 'selected' : ''; ?>>Turkish</option>
                        <option value="Croatian" <?php echo (getmodsbyid('11') == 'Croatian') ? 'selected' : ''; ?>>Croatian</option>
                        <option value="Spanish" <?php echo (getmodsbyid('11') == 'Spanish') ? 'selected' : ''; ?>>Spanish</option>
                        <option value="Arabic" <?php echo (getmodsbyid('11') == 'Arabic') ? 'selected' : ''; ?>>Arabic</option>
                        <option value="French" <?php echo (getmodsbyid('11') == 'French') ? 'selected' : ''; ?>>French</option>
                        <option value="German" <?php echo (getmodsbyid('11') == 'German') ? 'selected' : ''; ?>>German</option>
                        <option value="Italian" <?php echo (getmodsbyid('11') == 'Italian') ? 'selected' : ''; ?>>Italian</option>
                        <option value="Romanian" <?php echo (getmodsbyid('11') == 'Romanian') ? 'selected' : ''; ?>>Romanian</option>
                        <option value="Hungary" <?php echo (getmodsbyid('11') == 'Hungary') ? 'selected' : ''; ?>>Hungary</option>
                        <option value="Albanian" <?php echo (getmodsbyid('11') == 'Albanian') ? 'selected' : ''; ?>>Albanian</option>
                        <option value="Korean" <?php echo (getmodsbyid('11') == 'Korean') ? 'selected' : ''; ?>>Korean</option>
                        <option value="Hebrew" <?php echo (getmodsbyid('11') == 'Hebrew') ? 'selected' : ''; ?>>Hebrew</option>
                        <option value="Ukrainian" <?php echo (getmodsbyid('11') == 'Ukrainian') ? 'selected' : ''; ?>>Ukrainian</option>
                        <option value="Malay" <?php echo (getmodsbyid('11') == 'Malay') ? 'selected' : ''; ?>>Malay</option>
                        <option value="Dutch" <?php echo (getmodsbyid('11') == 'Dutch') ? 'selected' : ''; ?>>Dutch</option>
                        <option value="Indonesian" <?php echo (getmodsbyid('11') == 'Indonesian') ? 'selected' : ''; ?>>Indonesian</option>
                        <option value="Swedish" <?php echo (getmodsbyid('11') == 'Swedish') ? 'selected' : ''; ?>>Swedish</option>
                      </select>
                    </div>

                    <div class="form-group ctinput">
                      <label class="form-label"> Stream Format :</label>
                      <input type="hidden" name="data[12][preffile]" value="allowedFormat">
                      <input type="hidden" name="data[12][preftype]" value="string">
                      <input type="hidden" name="data[12][prefname]" value="allowedFormat">
                      <select name="data[12][mods]">
                        <option value="default" <?php echo (getmodsbyid('12') == 'default') ? 'selected' : ''; ?>>Default</option>
                        <option value="ts" <?php echo (getmodsbyid('12') == 'ts') ? 'selected' : ''; ?>>MPEGTS(.ts)</option>
                        <option value="m3u8" <?php echo (getmodsbyid('12') == 'm3u8') ? 'selected' : ''; ?>>HLS(.m3u8)</option>
                      </select>
                    </div>


                    <div class="form-group ctinput">
                      <label class="form-label"> Time Format :</label>
                      <input type="hidden" name="data[13][preffile]" value="timeFormat">
                      <input type="hidden" name="data[13][preftype]" value="string">
                      <input type="hidden" name="data[13][prefname]" value="timeFormat">
                      <select name="data[13][mods]">
                        <option value="HH:mm" <?php echo (getmodsbyid('13') == 'HH:mm') ? 'selected' : ''; ?>>24 Hours Format</option>
                        <option value="hh:mm a" <?php echo (getmodsbyid('13') == 'hh:mm a') ? 'selected' : ''; ?>>12 Hours Format</option>
                      </select>
                    </div>
                    
                    <div type="hidden" class="form-group ctinput">
                      <input type="hidden" name="data[39][preffile]" value="selected_language">
                      <input type="hidden" name="data[39][preftype]" value="string">
                      <input type="hidden" name="data[39][prefname]" value="selected_language">
                      <div class="form-group ctinput">
                          <input class="form-control" name="data[39][mods]"  type="hidden" value="<?php echo getmodsbyid('39')?>"/>
                      </div>
                    </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 languageselectElement = document.querySelector('select[name="data[11][mods]"]');
  const languagehiddenInput = document.querySelector('input[name="data[39][mods]"]');

  if (languageselectElement && languagehiddenInput) {
    languageselectElement.addEventListener('change', function () {
      languagehiddenInput.value = languageselectElement.value;
    });
  }
});
</script>


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