<?php
/*
 * Tab template for all panels
 * @author Rihards Silins <rihards.silins@mtcmedia.co.uk>
 * @version 1 27/05/2016
 * @copyright MTC media Ltd.
 */
?>
<ul class="tabnav el">
    <li class="<?=(!isset($relation_key) && !isset($new_object) ? "selected" : "")?>">
        <a href="manage.php">
            Manage <?=clean_page(ucwords(MODEL_PLURAL))?>
        </a>
    </li>
    <?php
    if (isset($new_object) && $new_object == false || isset($relation_key)) {
        ?><li class="<?=(!isset($relation_key) && isset($new_object) && $new_object == false ? "selected" : "")?>">
            <a href="edit.php?id=<?= clean_page($module['object']->id) ?>">
                Edit <?=clean_page(ucwords(MODEL_SINGULAR))?>
            </a>
        </li>
        <?php
    }
    if (MODEL_ALLOW_NEW) {
        ?><li class="<?=(!isset($relation_key) && isset($new_object) && $new_object == true ? "selected" : "")?>">
            <a href="edit.php">
                Add <?=clean_page(ucwords(MODEL_SINGULAR))?>
            </a>
        </li>
        <?php
    }
    if (isset($relation_key) && !empty($module['relations']) || isset($new_object) && $new_object == false && !empty($module['relations'])) {
        foreach ($module['relations'] as $relation_relation_key => $relation) {
            ?><li class="<?=(!isset($new_object) && $relation_relation_key == $relation_key ? "selected" : "")?>">
                <a href="manage_relation.php?parent_id=<?= clean_page($module['object']->id) ?>&relation_key=<?= clean_page($relation_relation_key) ?>">
                    Manage <?=clean_page(ucwords($module['relations'][$relation_relation_key]['name_plural']))?>
                </a>
            </li>
            <?php
            if (isset($new_object)  && $new_object == false && isset($relation_key) && $relation_relation_key == $relation_key) {
                ?><li class="<?=($relation_relation_key == $relation_key ? "selected" : "")?>">
                    <a href="edit_relation.php?parent_id=<?= clean_page($module['object']->id) ?>&relation_key=<?= clean_page($relation_relation_key) ?>&id=<?= clean_page($module['relation_object']->id) ?>">
                        Edit <?=clean_page(ucwords($module['relations'][$relation_relation_key]['name_singular']))?>
                    </a>
                </li>
                <?php
            }
            if ($module['relations'][$relation_relation_key]['allow_adding_new_entries']) {
                ?><li class="<?=(isset($new_object) && $new_object == true && $relation_relation_key == $relation_key ? "selected" : "")?>">
                    <a href="edit_relation.php?parent_id=<?= clean_page($module['object']->id) ?>&relation_key=<?= clean_page($relation_relation_key) ?>">
                        Add <?=clean_page(ucwords($module['relations'][$relation_relation_key]['name_singular']))?>
                    </a>
                </li>
                <?php
            }
        }
    }
    ?>
</ul>
