##|+PRIV
##|*IDENT=page-system-update-settings
##|*NAME=System: Update: Settings
##|*DESCR=Allow access to the 'System: Update: Settings' page.
##|*MATCH=system_update_settings.php*
##|-PRIV
require_once "guiconfig.inc";
require_once "pkg-utils.inc";
$repos = pkg_list_repos();
if ($_POST) {
    // Set the firmware branch, but only if we are not using it already
    if ($_POST['fwbranch']) {
        if ($_POST['fwbranch'] == "development" && !is_pkg_installed($g['product_name'] . "-repo-devel")) {
            pkg_switch_repo(true);
        } else {
            if ($_POST['fwbranch'] == "stable" && !is_pkg_installed($g['product_name'] . "-repo")) {
                pkg_switch_repo(false);
            }
        }
    }
    if ($_POST['disablecheck'] == "yes") {
        $config['system']['firmware']['disablecheck'] = true;
    } elseif (isset($config['system']['firmware']['disablecheck'])) {
        unset($config['system']['firmware']['disablecheck']);
    }
    if ($_POST['synconupgrade'] == "yes") {
        $config['system']['gitsync']['synconupgrade'] = true;
    } elseif (isset($config['system']['gitsync']['synconupgrade'])) {
        unset($config['system']['gitsync']['synconupgrade']);
    }
    $config['system']['gitsync']['repositoryurl'] = $_POST['repositoryurl'];
    $preset_urls_split = explode("\n", file_get_contents("{$g['tmp_path']}/manifest"));
}
include "head.inc";
if ($input_errors) {
    print_input_errors($input_errors);
}
if ($savemsg) {
    print_info_box($savemsg, 'success');
}
$tab_array = array();
$tab_array[] = array(gettext("System Update"), false, "pkg_mgr_install.php?id=firmware");
$tab_array[] = array(gettext("Update Settings"), true, "system_update_settings.php");
display_top_tabs($tab_array);
$form = new Form();
$section = new Form_Section('Firmware Branch');
$section->addInput(new Form_Select(fwbranch, 'Branch', is_pkg_installed($g['product_name'] . "-repo") ? "stable" : "development", ["stable" => "Stable", "development" => "Development"]))->setHelp('Please select the stable, or the development branch from which to update the system firmware. ' . ' <br />' . 'Use of the development version is at your own risk!');
$form->add($section);
$section = new Form_Section('Updates');
/*
$section->addInput(new Form_Checkbox(
	'allowinvalidsig',
	'Unsigned images',
	'Allow auto-update firmware images with a missing or invalid digital signature to be used',
	isset($curcfg['allowinvalidsig'])
	));
*/
$section->addInput(new Form_Checkbox('disablecheck', 'Dashboard check', 'Disable the automatic dashboard auto-update check', isset($curcfg['disablecheck'])));
$form->add($section);
if (file_exists("/usr/local/bin/git") && $g['platform'] == $g['product_name']) {
    $section = new Form_Section('GitSync');
    $section->addInput(new Form_Checkbox('synconupgrade', 'Auto sync on update', 'After updating, sync with the following repository/branch before reboot', isset($gitcfg['synconupgrade'])))->setHelp('After updating, sync with the following repository/branch before reboot');