$section = null;
$old_parent = null;
if (isset($_POST['id'])) {
    // Saving an existing content page.  Read it from the database.
    $section = $db->selectObject('section', 'id=' . intval($_POST['id']));
    if ($section) {
        $old_parent = $section->parent;
        $check_id = $section->id;
    }
} else {
    $check_id = $_POST['parent'];
}
if ($check_id != -1 && exponent_permissions_check('manage', exponent_core_makeLocation('NavigationModule', '', $check_id))) {
    $i18n = exponent_lang_loadFile('modules/NavigationModule/actions/save_internalalias.php');
    // Update the section from the _POST data.
    $section = section::updateInternalAlias($_POST, $section);
    if ($section->active == 0) {
        // User tried to link to an inactive section.  This makes little or no sense in
        // this context, so throw them back to the edit form, with an error message.
        $_POST['_formError'] = $i18n['internal_link_err'];
        exponent_sessions_set('last_POST', $_POST);
        header('Location: ' . $_SERVER['HTTP_REFERER']);
        exit('');
    }
    if (isset($section->id)) {
        if ($section->parent != $old_parent) {
            // Old_parent id was different than the new parent id.  Need to decrement the ranks
            // of the old children (after ours), and then add
            $section = section::changeParent($section, $old_parent, $section->parent);
        }
        // Existing section.  Update the database record.