
<?= $this->extend('layout'); ?>

<?= $this->section('css'); ?>
<link rel="stylesheet" href="/css/mawim.css">
<link rel="stylesheet" href="/assets/jquery-ui-1.13.2.custom/jquery-ui.css">
<?= $this->endSection(); ?>
<?= $this->section('menu'); ?>
<?= $this->include('sidebar') ?>
<?= $this->endSection(); ?>
<?= $this->section('content'); ?>

<?php function printsub($id, $all){
    $liste = '';
    $ret='';
    foreach($all as $ele){
        $class ="";
        if ($ele->parent_id == $id){
            if ($ele->lkz) $class = "text-bg-danger";
            else if ($ele->bookable == "f") $class = "text-bg-warning";
            $toolt ="bookable: $ele->bookable; lkz: $ele->lkz; Id: $ele->id; PID:$ele->parent_id";
            $liste .= "<li><span  data-bs-toggle='tooltip' data-bs-html=true title='$toolt'";
            $liste .= "data-id=\"$ele->id\""; 
            $liste .= "data-pid=\"$ele->parent_id\"";
            $liste .= "data-bookable=\"$ele->bookable\"";
            $liste .= "data-lkz=\"$ele->lkz\"";
            $liste .= "data-type=\"$ele->type\"";
            $liste .= "data-description=\"$ele->description\"";
            $liste .= "class='$class'>$ele->description</span></li>";
            $liste .= printsub($ele->id, $all);
        }
    }
    if ($liste !=''){
        $ret = "<ul>";
        $ret .= $liste;
        $ret .= "</ul>";
    }
    return $ret;
} ?>
<div class="page-heading">
    <h3> Kategorien bearbeiten</h3>
</div>
<div class="row">
    <div class="col-md-3 col-12" id="tree">
        <div class="card text-bg-dark">
            <div class="card-content">
                    <div class="card-body">
                        <div><a class="btn btn-info multi" onclick="newCat();" role="button">Neue Kategorie</a></div>
                        <div class="tree">
                            <ul>
                                <?php foreach($parents as $parent): ?>
                                    <?php $class='';
                                    if ($parent->lkz) $class = "text-bg-danger";
                                    else if ($parent->bookable == "f") $class = "text-bg-warning"; ?>
                                <li> <span data-bs-toggle='tooltip' 
                                            data-bs-html=true 
                                            data-id="<?=$parent->id?>" 
                                            data-pid="0" 
                                            data-bookable="<?=$parent->bookable?>"
                                            data-lkz=" <?= $parent->lkz?>" 
                                            data-type="<?= $parent->type?>"
                                            data-description="<?= $parent->description?>";
                                            title="bookable: <?=$parent->bookable?>; lkz: <?= $parent->lkz?>; Id: <?=$parent->id?>;" class="<?=$class?>"><?=$parent->description?></span>
                                    <?= printsub($parent->id, $all); ?>
                        
                                <?php endforeach; ?>
                            </ul>
                        </div>
                    </div>
            </div>                
        </div>
    </div>                                
    <div class="col-md-3 col-12 d-none" id="editor">
        <?= $this->include('accountsform') ?>
    </div>
</section>
<?= $this->endSection(); ?>
<?= $this->section('scripts'); ?>
    <script src="/assets/jquery-ui-1.13.2.custom/jquery-ui.js"></script>
    <script></script>
    <script src="/js/accounts.js"></script>
<?= $this->endSection(); ?>