<?php

    $_table = 'tables';

    if(file_exists('_backend/internals/tables/l18n/'.$cfg['admin']['language'].'.php')) {
        require_once('_backend/internals/tables/l18n/'.$cfg['admin']['language'].'.php');
    }
    $table_config = array(
        'table' => 'tables',
        'multiSelect' => true,    
        'idField'=>'tabId',
    );
    $table_fields = array(
        'tabId' => array(
            'type' => 'id', 
            'default_list' => true,           
        ),
        'tabName' => array(
            'type' => 'text',
            'size' => '150',
            'length' => '30',
            'default_list' => true,   
            'prefix' => 'table_'
        ),           
        'tabTitle' => array(
            'type' => 'text',
            'size' => '300',
            'length' => '200',
            'default_list' => true,   
            'language' => true,                       
        ),
        'tabPrefix' => array(
            'type' => 'text',
            'size' => '80',
            'length' => '5',
            'default_list' => true,   
        ),  
        'tabStatuses' => array(
            'type' => 'checkbox',            
        ),
        'tabLanguages' => array(
            'type' => 'checkbox',            
        ),
        'tabCategories' => array(
            'type' => 'checkbox',            
        )                         
                
    );


    ///if($_POST['action']=='new_record' || $_POST['action']=='update_record') {

       // print_r($_POST);
       // exit;
        
        //mysqli_query($db, "DELETE FROM tablePrefixes WHERE prefix='$_record_previous[tabPrefix]'");
        //mysqli_query($db, "INSERT INTO tablePrefixes (`table`, `prefix`) VALUES ('table_".$_POST[tabName]."', '$_POST[tabPrefix]')"); 
        
       // echo "INSERT INTO tablePrefixes (`table`, `prefix`) VALUES ('$_POST[tabName]', '$_POST[tabPrefix]')";
        //echo "INSERT INTO tablePrefixes (table, prefix) VALUES ('$_POST[table]', '$_POST[tabPrefix]')";
        //print_r($_record_previous);
        //echo 'teraz';
        //echo $_POST['tabPrefix'];
  //  }

    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">';
        
        echo '<li'.$active['view'].perm_display('tables','view').'><a href="/'.$_url[0].'/'.$_url[1].'/view"><span class="glyphicon glyphicon-eye-open"></span> Przeglądaj</a></li>';
        echo '<li'.$active['add'].perm_display('tables','add').'><a href="/'.$_url[0].'/'.$_url[1].'/add"><span class="glyphicon glyphicon-plus"></span> Dodaj</a></li>';
        echo '<li'.$active['structure'].perm_display('tables','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 href="#"><span class="glyphicon glyphicon-edit"></span> Edycja #'.$_GET['id'].'</a></li>';
        
        
        renderHeaderSearch('tables');
        renderEditLanguage();
        if($_url[2]=='view') renderSorting('tables');
           echo '</ul><div class="nice_bar"></div>';
   
    }
    

    function action_index() {  
        global $table_config, $_url;          
        grid_view($table_config['table'], "AND tabInternal!='1'", array(
                array('url'=>'/'.$_url[0].'/table/view?tid={id}',
                      'class'=>'primary',
                      'icon'=>'glyphicon-hand-up',
                      'label'=>_t('select'),
                      'perm'=>'select',
                )
            )       
        );            
    }
    
    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, array('extra_action'=>'update_table'));
    }
    
    function action_add() { 
        global $table_config;  
        grid_record($table_config['table'], false, array('extra_action'=>'create_table'));
    }    
    
     

?>