<h1><?= ucfirst($this->site['lists']);?></h1>
<?php

function generateString($char,$amount)
{
    $output = '';
    for($i=0;$i<$amount;$i++)
        $output .= $char;
    return $output;
}
function renderList($list,$level)
{
    if(!empty($list) && is_array($list))
        foreach($list as $k=>$v)
        {
            $prefix = generateString('++',$level);

            echo '<tr class="data_row">';
                echo '<td>'.$v['id'].'</td>';
                echo '<td>'.$v['parent_id'].'</td>';
                echo '<td>'.(empty($v['image']) ? '':'<img src="'.$v['image'].'" height="50" />').'</td>';
                echo '<td>'.$prefix.$v['name'].'</td>';
                echo '<td><a href="/admin/edit_list_item/'.$v['id'].'">Edytuj</a><br/><br/><a href="javascript:confirmDelete(\'/admin/delete_list_item/'.$v['id'].'\')">Usuń</a></td>';
            echo '</tr>';
            echo '<tr><td colspan="4"></td></tr>';

            if(isset($v['children']) && !empty($v['children']))
            {
                renderList($v['children'],($level+1));
            }
        }
}
?>
<table class="table_90procent">
    <tr>
        <td>
            <?php
                if(isset($lists))
                {
           ?>
            <table style="width:100%;">
                <thead>
                    <tr>
                        <th width="20">Id</th>
                        <th width="60">Parent Id</th>
                        <th width="60">Obrazek</th>
                        <th>Nazwa</th>
                        <th width="100">Akcje</th>
                    </tr>
                </thead>
                <?php
                  
                    if(!empty($lists) && is_array($lists))
                    {
                        echo '<tbody>';
                        foreach($lists as $k=>$v)
                        {
                            echo '<tr class="data_row">';
                                echo '<td>'.$v['id'].'</td>';
                                echo '<td>'.$v['parent_id'].'</td>';
                                echo '<td>'.(empty($v['image']) ? '':'<img src="'.$v['image'].'" height="50" />').'</td>';
                                echo '<td><b>'.$v['name'].'</b></td>';
                                echo '<td><a href="/admin/edit_list_item/'.$v['id'].'">Edytuj</a><br/><br/><a href="javascript:confirmDelete(\'/admin/delete_list_item/'.$v['id'].'\')">Usuń</a></td>';
                            echo '</tr>';
                            echo '<tr><td colspan="4"></td></tr>';
                            if(isset($v['children']) && !empty($v['children']))
                            {
                                renderList($v['children'],1);
                                echo '<tr><td colspan="5"><br/></td></tr>';
                            }
                        }
                        echo '</tbody>';
                    }
                ?>
            </table>
            <?php
                }
            ?>
        </td>
    </tr>
</table>