<?php

    $_table = 'tables';

    if(file_exists('_backend/internals/modules/l18n/'.$cfg['admin']['language'].'.php')) {
        require_once('_backend/internals/modules/l18n/'.$cfg['admin']['language'].'.php');
    }
    $table_config = array(
        'table' => 'modules',
        'multiSelect' => true,    
        'idField'=>'modId',
        'categories'=>true,
        'languages'=>true,
        'status'=>true
    );
    $table_fields = array(
        'modId' => array(
            'type' => 'id', 
            'default_list' => true,           
        ),
        'modName' => array(
            'type' => 'text',
            'size' => '200',
            'length' => '200',
            'default_list' => true,     
        ),         
        'modModule' => array(
            'type' => 'select_modules',
            'default_list' => true,   
        ),           
        'modTitle' => array(
            'type' => 'text',
            'size' => '300',
            'length' => '200',
            'default_list' => true,   
            'language' => true,                       
        ),
                     
                
    );
  



    require_once('_backend/grid.php');


    function print_header() {
        global $_url, $cfg;
        echo '<h4>'._t('moduleName').'</h4>';
        if(!$_url[2]) $_url[2]='view';
        $active[$_url[2]]=' class="active"';
        echo '<ul class="nav nav-tabs">
        
        <li'.$active['view'].perm_display('modules','view').'><a href="/'.$_url[0].'/'.$_url[1].'/view"><span class="glyphicon glyphicon-eye-open"></span> Przeglądaj</a></li>
        <li'.$active['add'].perm_display('modules','add').'><a href="/'.$_url[0].'/'.$_url[1].'/add"><span class="glyphicon glyphicon-plus"></span> Dodaj</a></li>
        <li'.$active['structure'].perm_display('modules','structure').'><a href="/'.$_url[0].'/'.$_url[1].'/structure"><span class="glyphicon glyphicon-list"></span> Struktura</a></li>';
        if($_url[2]=='edit') echo '<li class="active"><a><span class="glyphicon glyphicon-edit"></span> Edycja #'.$_GET['id'].'</a></li>';
        if($_url[2]=='settings') echo '<li class="active"><a><span class="glyphicon glyphicon-edit"></span> Ustawienia #'.$_GET['id'].'</a></li>';        
        
        
        renderHeaderSearch('modules');
        renderEditLanguage();
        if($_url[2]=='view') renderSorting('modules');
           echo '</ul><div class="nice_bar"></div>';
   
    }
    

    function action_index() {  
        global $table_config, $_url;          
        grid_view($table_config['table'], null, array(
                array('url'=>'/'.$_url[0].'/modules/settings?id={id}',
                      'class'=>'primary',
                      'icon'=>'glyphicon-wrench',
                      'label'=>_t('settings'),
                      'perm'=>'edit'
                )
            )       
        );            
    }
    
    function action_view() {
        action_index();
         
    }    
    
    function action_structure() {
        global $table_config;  
        grid_structure($table_config['table']);
          
    }     
    
    function action_edit() { 
        global $table_config;  
        grid_record($table_config['table'], true);
    }
    
    function action_add() { 
        global $table_config;  
        grid_record($table_config['table'], false, array('extra_action'=>'create_module_settings'));
    }    
    
    function action_settings() {
        global $table_config, $table_fields, $cfg, $_t, $db;
        $module_info=mysqli_fetch_assoc(_mysqli_query($db, "SELECT * FROM modules WHERE modId='".$_GET['id']."'"));
        //print_r($module_info);
        //$table_config=null;
        require_once('_modules/'.$module_info['modModule'].'/backend.php');        
        //include('_modules/shop/backend.php');
        //print_r($table_config);
        grid_record($table_config['table'], true);        
    }
    
     

?>