header("location: " . $baseurl_short . "pages/user/user_home.php");
        exit;
    }
}
if (getvalescaped("quicksave", FALSE)) {
    $tile = getvalescaped("tile", "");
    #If a valid tile value supplied
    if (!empty($tile) && is_numeric($tile)) {
        #Tile available to this user?
        $available = get_user_available_tiles($userref, $tile);
        if (!empty($available)) {
            $tile = $available[0]["tile"];
            $usertile = $available[0]["usertile"];
            if (get_user_tile($usertile, $userref)) {
                #Delete if the user already has the tile
                delete_user_dash_tile($usertile, $userref);
                $dtiles_available = get_user_available_tiles($userref);
                exit("negativeglow");
            } else {
                #Add to the front of the pile if the user already has the tile
                add_user_dash_tile($userref, $tile, 5);
                $dtiles_available = get_user_available_tiles($userref);
                exit("positiveglow");
            }
        }
    }
    exit("Save Failed");
}
if (getvalescaped("submit", FALSE)) {
    $tiles = getvalescaped("tiles", "");
    if (empty($tiles)) {
        $index -= 5;
    }
    update_default_dash_tile_order($tile["ref"], $index);
    reorder_default_dash();
    echo "Tile " . $tile["ref"] . " at index: " . $index;
    exit;
}
/* 
 * Delete Tile 
 */
$delete = getvalescaped("delete", false);
if ($delete && isset($usertile)) {
    if (!checkPermission_dashmanage()) {
        exit($lang["error-permissiondenied"]);
    }
    delete_user_dash_tile($usertile["ref"], $userref);
    reorder_user_dash($userref);
    echo "Deleted U" . $usertile['ref'];
    exit;
}
if ($delete && isset($tile) && !isset($usertile)) {
    if (!checkPermission_dashcreate()) {
        exit($lang["error-permissiondenied"]);
    }
    #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"]);
    }