if (is_array($a_aliases[$id]['aliasurl'])) {
            $pconfig['address'] = implode(" ", $a_aliases[$id]['aliasurl']);
        } else {
            $pconfig['address'] = $a_aliases[$id]['aliasurl'];
        }
    }
}
if ($_POST) {
    unset($input_errors);
    $vertical_bar_err_text = gettext("Vertical bars (|) at start or end, or double in the middle of descriptions not allowed. Descriptions have been cleaned. Check and save again.");
    /* input validation */
    $reqdfields = explode(" ", "name");
    $reqdfieldsn = array(gettext("Name"));
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
    if (!is_validaliasname($_POST['name'])) {
        $input_errors[] = invalidaliasnamemsg($_POST['name']);
    }
    /* check for name conflicts */
    foreach ($a_aliases as $key => $alias) {
        if ($alias['name'] == $_POST['name'] && (empty($a_aliases[$id]) || $key != $id)) {
            $input_errors[] = gettext("An alias with this name already exists.");
            break;
        }
    }
    /* Check for reserved keyword names */
    foreach ($reserved_keywords as $rk) {
        if ($rk == $_POST['name']) {
            $input_errors[] = sprintf(gettext("Cannot use a reserved keyword as an alias name: %s"), $rk);
        }
    }
    /* check for name interface description conflicts */
    $pconfig['timerange'] = $a_schedules[$id]['timerange'];
    $pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
    $getSchedule = true;
}
if ($_POST) {
    if (strtolower($_POST['name']) == "lan") {
        $input_errors[] = gettext("Schedule may not be named LAN.");
    }
    if (strtolower($_POST['name']) == "wan") {
        $input_errors[] = gettext("Schedule may not be named WAN.");
    }
    if (strtolower($_POST['name']) == "") {
        $input_errors[] = gettext("Schedule name cannot be blank.");
    }
    if (!is_validaliasname($_POST['name'])) {
        $input_errors[] = invalidaliasnamemsg($_POST['name'], gettext("schedule"));
    }
    /* check for name conflicts */
    foreach ($a_schedules as $schedule) {
        if (isset($id) && $a_schedules[$id] && $a_schedules[$id] === $schedule) {
            continue;
        }
        if ($schedule['name'] == $_POST['name']) {
            $input_errors[] = gettext("A Schedule with this name already exists.");
            break;
        }
    }
    $schedule = array();
    $schedule['name'] = $_POST['name'];
    $schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');
    $timerangeFound = false;
    unset($pconfig['attribute']);
}
if (isset($id) && $a_gateways[$id]) {
    $realid = $a_gateways[$id]['attribute'];
}
if ($_POST) {
    unset($input_errors);
    /* input validation */
    $reqdfields = explode(" ", "name interface");
    $reqdfieldsn = array(gettext("Name"), gettext("Interface"));
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
    if (!isset($_POST['name'])) {
        $input_errors[] = "A valid gateway name must be specified.";
    }
    if (!is_validaliasname($_POST['name'])) {
        $input_errors[] = invalidaliasnamemsg($_POST['name'], gettext("gateway"));
    } else {
        if (isset($_POST['disabled'])) {
            // We have a valid gateway name that the user wants to mark as disabled.
            // Check if the gateway name is used in any gateway group.
            if (is_array($config['gateways']['gateway_group'])) {
                foreach ($config['gateways']['gateway_group'] as $group) {
                    foreach ($group['item'] as $item) {
                        $items = explode("|", $item);
                        if ($items[0] == $_POST['name']) {
                            $input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be disabled because it is in use on Gateway Group "%2$s"'), $_POST['name'], $group['name']);
                        }
                    }
                }
            }
            // Check if the gateway name is used in any enabled Static Route.