function create_dash_tile($url, $link, $title, $reload_interval, $all_users, $default_order_by, $resource_count, $text = "", $delete = 1)
{
    $rebuild_order = TRUE;
    # Validate Parameters
    if (empty($reload_interval) || !is_numeric($reload_interval)) {
        $reload_interval = 0;
    }
    $delete = $delete ? 1 : 0;
    $all_users = $all_users ? 1 : 0;
    if (!is_numeric($default_order_by)) {
        $default_order_by = append_default_position();
        $rebuild_order = FALSE;
    }
    $resource_count = $resource_count ? 1 : 0;
    # De-Duplication of tiles on creation
    $existing = sql_query("SELECT ref FROM dash_tile WHERE url='" . $url . "' AND link='" . $link . "' AND title='" . escape_check($title) . "' AND txt='" . escape_check($text) . "' AND reload_interval_secs=" . $reload_interval . " AND all_users=" . $all_users . " AND resource_count=" . $resource_count);
    if (isset($existing[0]["ref"])) {
        $tile = $existing[0]["ref"];
        $rebuild_order = FALSE;
    } else {
        $result = sql_query("INSERT INTO dash_tile (url,link,title,reload_interval_secs,all_users,default_order_by,resource_count,allow_delete,txt) VALUES ('" . $url . "','" . $link . "','" . escape_check($title) . "'," . $reload_interval . "," . $all_users . "," . $default_order_by . "," . $resource_count . "," . $delete . ",'" . escape_check($text) . "')");
        $tile = sql_insert_id();
    }
    # If tile already existed then this no reorder
    if ($rebuild_order) {
        reorder_default_dash();
    }
    if ($all_users == 1) {
        sql_query("DELETE FROM user_dash_tile WHERE dash_tile=" . $tile);
        $result = sql_query("INSERT user_dash_tile (user,dash_tile,order_by) SELECT user.ref,'" . $tile . "',5 FROM user");
    }
    return $tile;
}
        #Tile available to this user?
        $available = get_alluser_available_tiles($tile);
        if (!empty($available)) {
            $tile = $available[0];
            $active = all_user_dash_tile_active($tile["ref"]);
            if ($active) {
                #Delete if the tile is active
                #Check config tiles for permanent deletion
                $force = false;
                $search_string = explode('?', $tile["url"]);
                parse_str(str_replace("&", "&", $search_string[1]), $search_string);
                if ($search_string["tltype"] == "conf") {
                    $force = !checkTileConfig($tile, $search_string["tlstyle"]);
                }
                delete_dash_tile($tile["ref"], true, $force);
                reorder_default_dash();
                $dtiles_available = get_alluser_available_tiles();
                exit("negativeglow");
            } else {
                #Add to the front of the pile if the user already has the tile
                sql_query("DELETE FROM user_dash_tile WHERE dash_tile=" . $tile["ref"]);
                sql_query("INSERT user_dash_tile (user,dash_tile,order_by) SELECT user.ref,'" . $tile["ref"] . "',5 FROM user");
                $dtiles_available = get_alluser_available_tiles();
                exit("positiveglow");
            }
        }
    }
    exit("Save Failed");
}
include "../../include/header.php";
?>