<h1><?= ucfirst($this->site['immovables']);?></h1>
<?php
function generateString($char,$amount)
{
    $output = '';
    for($i=0;$i<$amount;$i++)
        $output .= $char;
    return $output;
}
?>
<table class="table_90procent">
    <tr>
        <td>
            <?php
                if(isset($immovables))
                {
           ?>
                <table style="width:100%;">
                    <thead>
                        <tr>
                            <th width="10">Id</th>
                            <th width="60">Nazwa</th>
                            <th width="60">Typ budynku</th>
                            <th width="60">Typ oferty</th>
                            <th width="60">Nowość</th>
                            <th width="60">Aktywność</th>
                            <th width="60">Data dodania</th>
                            <th width="30">Akcje</th>
                        </tr>
                    </thead>
                    <?php
                    if(!empty($immovables) && is_array($immovables))
                    {
                        echo '<tbody>';
                            foreach($immovables as $k=>$v)
                            {
                                echo '<tr class="data_row">';
                                    echo '<td>'.$v['id'].'</td>';
                                    echo '<td>'.$v['name'].'</td>';
                                    echo '<td>'.$this->site[$v['building_type']].'</td>';
                                    echo '<td>'.$this->site[$v['offer_type']].'</td>';
                                    echo '<td>'.(($v['nowelty']==1) ? "TAK":"NIE").'</td>';
                                    echo '<td>'.(($v['active'] == 1) ? "TAK":"NIE").'</td>';
                                    echo '<td>'.$v['date_added'].'</td>';
                                    echo '<td><a href="/admin/edit_immovable/'.$v['id'].'">Edytuj</a>&nbsp;&nbsp;&nbsp;<a href="javascript:confirmDelete(\'/admin/delete_immovable/'.$v['id'].'\')">Usuń</a><br/><hr/>';
                                    echo 'Edytuj wersje: ';
                                    echo '<select class="edit_lang" style="width:100px;"><option value=""></option>';
                                    if(!empty($v['languages']) && is_array($v['languages']))
                                        foreach($v['languages'] as $kk  =>  $vv)
                                            echo '<option value="'.base_url().'admin/edit_immovable_lang/'.$vv['id'].'">'.$vv['lang_name'].'</option>';

                                    echo '</select>';
                                    echo '<hr/>';
                                    echo 'Dodaj wersje: ';
                                    echo '<select class="add_lang" style="width:100px;"><option value=""></option>';
                                    if(!empty($v['not_added_languages']) && is_array($v['not_added_languages']))
                                        foreach($v['not_added_languages'] as $kk  =>  $vv)
                                            echo '<option value="'.base_url().'admin/add_immovable_language/'.$v['id'].'/'.$vv['idlanguages'].'">'.$vv['shortname'].'</option>';
                                    echo '</select>';
                                    echo '</td>';
                                echo '</tr>';
                            }
                        echo '</tbody>';
                    }
                    ?>
                </table>
            <?php
                }
            ?>
        </td>
    </tr>
</table>
<script type="text/javascript">
    $(document).ready(function(){
        $(".edit_lang").change(function(){
            var url = $(this).val();
            //if(url != "")
                window.location = url;
        });
        $(".add_lang").change(function(){
            var url = $(this).val();
            
            //if(url != "")
                window.location = url;
        });
    });
</script>