function save_nav_item($connection)
{
    $connection->begin_transaction();
    $is_sub_nav = (bool) $_GET['subnav'];
    $nav_id = $_REQUEST['id'];
    $nav_title = $_REQUEST['title'];
    $nav_type = $_REQUEST['type'];
    $nav_content = $_REQUEST['content'];
    if ($nav_type == "SECTION") {
        add_section_item($nav_id, $is_sub_nav, $nav_content, $connection);
        update_nav_item($nav_id, $nav_title, $nav_type, $is_sub_nav, $connection);
        remove_link_item($nav_id, $is_sub_nav, $connection);
        remove_sub_nav_items($nav_id, $connection);
    } else {
        if ($nav_type == "LINK") {
            add_link_item($nav_id, $is_sub_nav, $nav_content, $connection);
            update_nav_item($nav_id, $nav_title, $nav_type, $is_sub_nav, $connection);
            remove_section_item($nav_id, $is_sub_nav, $connection);
            remove_sub_nav_items($nav_id, $connection);
        } else {
            if (!$is_sub_nav && $nav_type == "DROPDOWN") {
                update_nav_item($nav_id, $nav_title, $nav_type, $is_sub_nav, $connection);
                remove_link_item($nav_id, $is_sub_nav, $connection);
                remove_section_item($nav_id, $is_sub_nav, $connection);
            }
        }
    }
    $connection->commit();
    print '[["SUCCESS"],["Navigation item successfully updated"]]';
}
function del_sub_nav_item($connection)
{
    $connection->begin_transaction();
    $id = $_REQUEST['id'];
    remove_link_item($id, true, $connection);
    remove_section_item($id, true, $connection);
    remove_sub_nav_item($id, $connection);
    $connection->commit();
    print '[["SUCCESS"],["Successfully removed sub navigation item"]]';
}