<?php
function render_settings_group($group,$lang_id,$languages, $localization)
{
    if(!empty($group['settings']))
    {
        echo '<h3>'.$group['name'].'</h3>';
        echo '<table style="width:100%;" class="data_table">';

                foreach($group['settings'] as $k=>$v)
                {
                    echo '<tr>';
                        echo '<td width="300">'.$v['name'].'&nbsp;&nbsp;<a href="" style="float:right;text-decoration:none;" class="tooltip" title="'.$v['description'].'">?</a></td>';
                        echo '<td>'.$v['value'].'</td>';
                        echo '<td style="width:250px;text-align:right;"><a href="/settings/delete/'.$v['setting_id'].'" class="form_button delete_link">'.$localization['usun'].'</a>';
                                if(!empty($lang_id) && $lang_id > 0)
                                {
                                    //echo $v['langs'];
                                    $langs = explode(',',$v['langs']); //jezyki danej wlasciwosci
                                    if(!empty($languages) && is_array($languages))
                                    {
                                        echo '<select name="lang_id" class="new_property_lang">';
                                        echo '<option value=""></option>';
                                        foreach($languages as $k=>$vv)                                        {
                                            
                                            if(!in_array($vv['idlanguages'],$langs))
                                                echo '<option value="/settings/add_lang/'.$v['setting_id'].'/'.$vv['idlanguages'].'">'.$vv['shortname'].'</option>';
                                        }                                 
                                        
                                        echo '</select>';
                                        echo '&nbsp;&nbsp;| '.$localization['dodaj_wersje_jezykowa'];
                                    }
                                }
                        echo '</td>';
                    echo '</tr>';
                }

        echo '</table>';
        echo '<a href="/settings/edit/'.$group['id'].'/'.$lang_id.'" class="form_button">'.$localization['edytuj'].'</a>';
    }

}
//------------------------------------------------------------------------------
?>
<h1><?= ucfirst($this->localization['ustawienia']);?></h1>

<form action="/settings/index" method="post">
    Język: <?php echo form_dropdown('lang_id', $dd_languages, $lang_id); ?> <input type="submit" name="submit" value="<?php echo $this->localization['zatwierdz']; ?>"/>
</form>

<?php
  
    if(!empty($grouped_settings) && is_array($grouped_settings))
    {
        foreach($grouped_settings as $k=>$v)
        {
            render_settings_group($v,$lang_id, $languages, $this->localization);
            echo '<br /><br />';
        }
    }
?>
<script type="text/javascript">
$(document).ready(function(){
    $('.new_property_lang').change(function(){
        if($(this).val() != "")
        {
          window.location = $(this).val();
          return false;
        }
    });
});
</script>