function get_default_dash()
{
    global $baseurl, $baseurl_short, $lang, $anonymous_login, $username, $dash_tile_shadows;
    #Build Tile Templates
    $tiles = sql_query("SELECT dash_tile.ref AS 'tile',dash_tile.title,dash_tile.url,dash_tile.reload_interval_secs,dash_tile.link,dash_tile.default_order_by as 'order_by',dash_tile.allow_delete FROM dash_tile WHERE dash_tile.all_users=1 AND (dash_tile.allow_delete=1 OR (dash_tile.allow_delete=0 AND dash_tile.ref IN (SELECT DISTINCT user_dash_tile.dash_tile FROM user_dash_tile))) ORDER BY default_order_by");
    $order = 10;
    if (count($tiles) == 0) {
        echo $lang["nodashtilefound"];
        exit;
    }
    foreach ($tiles as $tile) {
        if ($order != $tile["order_by"] || $tile["order_by"] % 10 > 0) {
            update_default_dash_tile_order($tile["tile"], $order);
        }
        $order += 10;
        ?>
		<a 
			<?php 
        # Check link for external or internal
        if (mb_strtolower(substr($tile["link"], 0, 4)) == "http") {
            $link = $tile["link"];
            $newtab = true;
        } else {
            $link = $baseurl . "/" . htmlspecialchars($tile["link"]);
            $newtab = false;
        }
        ?>
			href="<?php 
        echo $link;
        ?>
" <?php 
        echo $newtab ? "target='_blank'" : "";
        ?>
			onClick="if(dragging){dragging=false;e.defaultPrevented;}" 
			class="HomePanel DashTile DashTileDraggable <?php 
        echo $tile["allow_delete"] ? "" : "conftile";
        ?>
" 
			id="tile<?php 
        echo htmlspecialchars($tile["tile"]);
        ?>
"
		>
			<div id="contents_tile<?php 
        echo htmlspecialchars($tile["tile"]);
        ?>
" class="HomePanelIN HomePanelDynamicDash <?php 
        echo $dash_tile_shadows ? "TileContentShadow" : "";
        ?>
">
				<?php 
        if (strpos($tile["url"], "dash_tile.php") !== false) {
            # Only pre-render the title if using a "standard" tile and therefore we know the H2 will be in the target data.
            ?>
                                <h2 class="title"><?php 
            echo htmlspecialchars($tile["title"]);
            ?>
</h2>
                                <?php 
        }
        ?>
				<p>Loading...</p>
				<script>
					height = jQuery("#contents_tile<?php 
        echo htmlspecialchars($tile["tile"]);
        ?>
").height();
					width = jQuery("#contents_tile<?php 
        echo htmlspecialchars($tile["tile"]);
        ?>
").width();
					jQuery("#contents_tile<?php 
        echo htmlspecialchars($tile["tile"]);
        ?>
").load("<?php 
        echo $baseurl . "/" . $tile["url"] . "&tile=" . htmlspecialchars($tile["tile"]);
        ?>
&tlwidth="+width+"&tlheight="+height);
				</script>
			</div>
			
		</a>
		<?php 
    }
    ?>
		<div id="dash_tile_bin"><span class="dash_tile_bin_text"><?php 
    echo $lang["tilebin"];
    ?>
</span></div>
		<div id="delete_dialog" style="display:none;"></div>
		<div id="delete_permanent_dialog" style="display:none;text-align:left;"><?php 
    echo $lang['confirmdeleteconfigtile'];
    ?>
</div>
	
		<script>
			function deleteDefaultDashTile(id) {
				jQuery.post( "<?php 
    echo $baseurl;
    ?>
/pages/ajax/dash_tile.php",{"tile":id,"delete":"true"},function(data){
					jQuery("#tile"+id).remove();
				});
			}
			function updateDashTileOrder(index,tile) {
				jQuery.post( "<?php 
    echo $baseurl;
    ?>
/pages/ajax/dash_tile.php",{"tile":tile,"new_index":((index*10))});
			}
			var dragging=false;
				jQuery(function() {
					if(jQuery(window).width()<600 && jQuery(window).height()<600 && is_touch_device()) {
						jQuery("#HomePanelContainer").prepend("<p><?php 
    echo $lang["dashtilesmalldevice"];
    ?>
</p>");
						return false;
					}
				 	jQuery("#HomePanelContainer").sortable({
				  	  items: ".DashTileDraggable",
				  	  start: function(event,ui) {
				  	  	jQuery("#dash_tile_bin").show();
				  	  	dragging=true;
				  	  },
				  	  stop: function(event,ui) {
			          	jQuery("#dash_tile_bin").hide();
				  	  },
			          update: function(event, ui) {
			          	nonDraggableTiles = jQuery(".HomePanel").length - jQuery(".DashTileDraggable").length;
			          	newIndex = (ui.item.index() - nonDraggableTiles)+1;
			          	var id=jQuery(ui.item).attr("id").replace("tile","");
			          	updateDashTileOrder(newIndex,id);
			          }
				  	});
				    jQuery("#dash_tile_bin").droppable({
						accept: ".DashTileDraggable",
						activeClass: "ui-state-hover",
						hoverClass: "ui-state-active",
						drop: function(event,ui) {
							var id=jQuery(ui.draggable).attr("id");
							id = id.replace("tile","");
							title = jQuery(ui.draggable).find(".title").html();
							jQuery("#dash_tile_bin").hide();
							if(jQuery("#tile"+id).hasClass("conftile")) {
								jQuery("#delete_permanent_dialog").dialog({
							    	title:'<?php 
    echo $lang["dashtiledelete"];
    ?>
',
							    	modal: true,
									resizable: false,
									dialogClass: 'delete-dialog no-close',
							        buttons: {
							            "<?php 
    echo $lang['confirmdefaultdashtiledelete'];
    ?>
": function() {
							            		jQuery(this).dialog("close");
							            		deleteDefaultDashTile(id);
							            	},    
							            "<?php 
    echo $lang['cancel'];
    ?>
": function() { 
							            		jQuery(this).dialog('close');
							            	}
							        }
							    });
							    return;
							}
							jQuery("#delete_dialog").dialog({
						    	title:'<?php 
    echo $lang["dashtiledelete"];
    ?>
',
						    	modal: true,
								resizable: false,
								dialogClass: 'delete-dialog no-close',
						        buttons: {
						            "<?php 
    echo $lang['confirmdefaultdashtiledelete'];
    ?>
": function() {jQuery(this).dialog("close");deleteDefaultDashTile(id); },    
						            "<?php 
    echo $lang['cancel'];
    ?>
": function() { jQuery(this).dialog('close'); }
						        }
						    });
						}
			    	});
			  	});
		</script>
	<div class="clearerleft"></div>
	<?php 
}
    if ($index > $usertile["order_by"]) {
        $index += 5;
    } else {
        $index -= 5;
    }
    update_user_dash_tile_order($userref, $usertile["ref"], $index);
    reorder_user_dash($userref);
    exit("Tile " . $usertile["ref"] . " at index: " . $index);
}
if (!empty($index) && isset($tile) && !isset($usertile)) {
    if ($index > $tile["default_order_by"]) {
        $index += 5;
    } else {
        $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'];