<?php $url = str_replace('admin.', '', $request->base()); ?>
<div class="clear">
    <?php foreach ($page as $p) : ?>
        <div class="icon" id="page_<?php echo htmlspecialchars($p['id']); ?>">
            <div class="content">
                <a href="page/edit/<?php echo htmlspecialchars($p['id']); ?>" title="<?php echo htmlspecialchars($p['name']); ?>">
                    <img src="admin/skin/icon/file3.png" /><br /><?php echo htmlspecialchars((strlen($p['name']) > 20) ? substr($p['name'], 0, 17) . '...' : $p['name']); ?>
                </a>
            </div>
            <div class="action">
                <a target="_blank" href="<?php echo htmlspecialchars($url); ?>page/view/<?php echo htmlspecialchars($p['path']); ?>">View</a>
                <a href="page/edit/<?php echo htmlspecialchars($p['id']); ?>">Edit</a>
                <a href="meta/edit/page/<?php echo urlencode($p['id']); ?>" class="<?php if (!$p['meta']) : echo 'missing'; endif; ?>">Meta</a>
                <a href="javascript:delete_page(<?php echo htmlspecialchars($p['id']); ?>);">Delete</a>
            </div>
        </div>
    <?php endforeach; ?>
</div>

<script type="text/javascript">
    function delete_page(id)
    {
        if (confirm('Are you sure?'))
        {
            $.post('page/delete', { id:id },
                function(data, status) {
                    if (data.error != '')
                    {
                        alert(data.error);
                    }
                    else
                    {
                        $('#page_' + id).remove();
                    }
                }, 'json');
        }
    }
</script>