<?php if ((!empty($_SESSION['content_manager']['is_mtcadmin'])) || (isset($admin_options) && is_array($admin_options) )) { ?>
<fieldset id="edit_page_settings" class="row">
	<h1><a class="show el">Settings <i class="fa fa-caret-down"></i></a></h1>
    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['innav'])) { ?>
    <div class="row">
        <?php if (!empty($_SESSION['content_manager']['is_mtcadmin'])) { ?>
            <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[innav]" data-key="innav" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['innav'])) {
                echo ' checked';
            }
            ?> /></span>
        <?php } ?>
        <label for="data[page][innav]">Show in main navigation</label>
        <input type="checkbox" name="data[page][innav]" id="data[page][innav]" value="1" />
    </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['redchild'])) { ?>
    <div class="row">
        <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
            <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[redchild]" data-key="redchild" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['redchild'])) {
                echo ' checked';
            }
            ?> /></span>
        <?php } ?>
        <label for="data[page][redchild]">Redirect to first sub page</label>
        <input type="checkbox" name="data[page][redchild]" id="data[page][redchild]" value="1">
    </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['template'])) { ?>
    	<div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[template]" data-key="template" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['template'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>


            <?php

                $available_templates = $cm->listTemplates();
                if (! $_SESSION['content_manager']['is_mtcadmin']) {
                    foreach ($available_templates as $template_name => $template_data) {
                        if (! in_array($template_name, [
                            'about.twig',
                            'news-listing.twig',
                            'news-article.twig',
                        ])) {
                            $available_templates[$template_name]['is_disabled'] = true;
                        }
                    }
                }

            ?>

    		<label for="data[page][template]">Template</label>
    		<select id="data[page][template]" name="data[page][template]">
                <?php

                    $client_selectable_templates = [];
                    $allow_all_templates = false;
                    if (defined('CMS_ALLOW_CLIENTS_TO_SWITCH_TEMPLATES') && CMS_ALLOW_CLIENTS_TO_SWITCH_TEMPLATES === true) {
                        $page_logic = json_decode($post['logic']);
                        if (!empty($page_logic) && !empty($page_logic->client_selectable_templates)) {
                            $client_selectable_templates = $page_logic->client_selectable_templates;
                        } else if (CMS_ALLOW_CLIENTS_TO_SWITCH_TEMPLATES_DEFAULT_TO_ALL_TEMPLATES === true) {
                            $allow_all_templates = true;
                        }
                    }

                    foreach ($available_templates as $template) {
                        $allow_client_tpl_change = false;
                        if (!$_SESSION['content_manager']['is_mtcadmin'] &&
                            !$allow_all_templates &&
                            $template['value'] != $post['template'] &&
                            !in_array($template['value'], $client_selectable_templates)
                        ) {
                            continue;
                        }
                        ?>
                        <option
                            value="<?= clean_page($template['value']) ?>"
                            data-has-structure="<?= ($template['has_structure'] ? 'true' : 'false') ?>"
                            data-allow-client-tpl-change="<?= ($allow_all_templates || in_array($template['value'], $client_selectable_templates)? 'true' : 'false') ?>"
                            <?= $template['is_disabled'] ? 'disabled' : '' ?>
                        >
                            <?= clean_page($template['name']); ?>
                        </option>
                        <?php
                    }
                ?>
            </select>
    	</div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['layout'])) { ?>
    <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[layout]" data-key="layout" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['layout'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
    		<label for="data[page][layout]">Layout</label>
    		<select id="data[page][layout]" name="data[page][layout]">
                <?php
                foreach ($cm->listLayouts() as $layout) {
                    echo '<option value="'.$layout['value'].'">';
                        echo $layout['name'];
                    echo '</option>';
                }
                ?>
            </select>
    	</div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['searchable'])) { ?>
        <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[searchable]" data-key="searchable" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['searchable'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
            <label for="data[page][searchable]">Searchable</label>
            <input type="checkbox" name="data[page][searchable]" id="data[page][searchable]" value="1">
        </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['frontpage'])) { ?>
        <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[frontpage]" data-key="frontpage" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['frontpage'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
            <label for="data[page][frontpage]">Frontpage</label>
            <input type="checkbox" name="data[page][frontpage]" id="data[page][frontpage]" value="1">
        </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['contact_page'])) { ?>
        <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[contact_page]" data-key="contact_page" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['contact_page'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
            <label for="data[page][contact_page]">Contact Page</label>
            <input type="checkbox" name="data[page][contact_page]" id="data[page][contact_page]" value="1">
        </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['listing_container'])) { ?>
        <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[listing_container]" data-key="listing_container" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['listing_container'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
            <label for="data[page][listing_container]">Listing Container</label>
            <input type="checkbox" name="data[page][listing_container]" id="data[page][listing_container]" value="1">
        </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['lock'])) { ?>
        <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[lock]" data-key="lock" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['lock'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
            <label for="data[page][lock]">Lock</label>
            <input type="checkbox" name="data[page][lock]" id="data[page][lock]" value="1">
        </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['hide_in_cms'])) { ?>
        <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[hide_in_cms]" data-key="hide_in_cms" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['hide_in_cms'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
            <label for="data[page][hide_in_cms]">Hide in CMS</label>
            <input type="checkbox" name="data[page][hide_in_cms]" id="data[page][hide_in_cms]" value="1">
        </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['allow_delete'])) { ?>
        <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[allow_delete]" data-key="allow_delete" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['allow_delete'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
            <label for="data[page][allow_delete]">Allow Delete</label>
            <input type="checkbox" name="data[page][allow_delete]" id="data[page][allow_delete]" value="1">
        </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['allow_update'])) { ?>
        <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[allow_update]" data-key="allow_update" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['allow_update'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
            <label for="data[page][allow_update]">Allow Update</label>
            <input type="checkbox" name="data[page][allow_update]" id="data[page][allow_update]" value="1">
        </div>
    <?php } ?>

    <?php if (!empty($_SESSION['content_manager']['is_mtcadmin']) || empty($admin_options['logic'])) { ?>
        <div class="row">
            <?php if ( isset($_SESSION['content_manager']) && isset($_SESSION['content_manager']['is_mtcadmin']) && !empty($_SESSION['content_manager']['is_mtcadmin']) ) { ?>
                <span class="cmsSettingLockOption settingLockOption"><input type="checkbox" name="is_admin[logic]" data-key="logic" value="1" class="checkboxLock"<?php
            if (!empty($admin_options['logic'])) {
                echo ' checked';
            }
            ?> /></span>
            <?php } ?>
            <label for="data[page][logic]">Logic</label>
            <textarea name="data[page][logic]" id="data[page][logic]"></textarea>
        </div>
    <?php } ?>

    <div class="row">
    </div>

</fieldset>
<?php } ?>
