<?php $url = str_replace('admin.', '', $request->base()); ?>
<div class="clear">
    <?php if (!$sec) : ?>
        <?php foreach ($section as $s) : ?>
            <div class="icon">
                <div class="content">
                    <a href="page/index/<?php echo htmlspecialchars($s); ?>">
                        <img src="admin/skin/icon/<?php echo htmlspecialchars($s); ?>.png" /><br /><?php echo htmlspecialchars(ucfirst($s)); ?>
                    </a>
                </div>
                <div class="action">
                    <a target="_blank" href="<?php echo htmlspecialchars($url); ?>page/index/<?php echo htmlspecialchars($s); ?>">View</a>
                </div>
            </div>
        <?php endforeach; ?>
    <?php else : ?>
        <?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']); ?>">
                        <img src="admin/skin/icon/file3.png" /><br /><?php echo htmlspecialchars($p['name']); ?>
                    </a>
                </div>
                <div class="action">
                    <a target="_blank" href="<?php echo htmlspecialchars($url); ?>page/<?php echo htmlspecialchars($p['id']); ?>">View</a>
                    <a href="page/edit/<?php echo htmlspecialchars($p['id']); ?>">Edit</a>
                    <a href="javascript:delete_page(<?php echo htmlspecialchars($p['id']); ?>);">Delete</a>
                </div>
            </div>
        <?php endforeach; ?>
    <?php endif; ?>
</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>