<?php

    $_table = 'pages';

    if(file_exists('_backend/internals/pages/l18n/'.$cfg['admin']['language'].'.php')) {
        require_once('_backend/internals/pages/l18n/'.$cfg['admin']['language'].'.php');
    }

    
    $table_config = array(
        'table' => 'pages',
        'multiSelect' => true,    
        'idField'=>'pagId',
        'languages'=>true,
        'categories'=>true,
        'status'=>true,
        'sequence'=>true,
        'default_status'=>0,
    );
    $table_fields = array(
        'pagId' => array(
            'type' => 'id', 
            'default_list' => true,           
        ),
        'pagTitle' => array(
            'type' => 'text',
            'size' => '300',
            'length' => '200',
            'default_list' => true,   
            'language' => true,   
            'formula' => 'make_slug({Slug},{Title})',                                 
        ),
        'pagContent' => array(
            'type' => 'htmlarea',            
            'editor' => 'advanced',
            'height' => '400',
            'language' => true,
            'default_list' => true,
            //'language' => true        
        ),
        'pagSlug' => array(
            'type' => 'text',
            'size' => '200',
            'length' => '100',
            'default_list' => true,
            'focusfunction' => 'url_flat@pagTitle',
            'language' => true,
            'formula' => 'make_slug({Slug},{Slug})'            
        )    
                
    );

    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('pages','view').'><a href="/'.$_url[0].'/'.$_url[1].'/view"><span class="glyphicon glyphicon-eye-open"></span> Przeglądaj</a></li>
        <li'.$active['add'].perm_display('pages','add').'><a href="/'.$_url[0].'/'.$_url[1].'/add"><span class="glyphicon glyphicon-plus"></span> Dodaj</a></li>
        <li'.$active['structure'].perm_display('pages','structure').'><a href="/'.$_url[0].'/'.$_url[1].'/structure"><span class="glyphicon glyphicon-list"></span> Struktura</a></li>
        <li'.$active['sql'].perm_display('pages','sql').'><a href="/'.$_url[0].'/'.$_url[1].'/sql"><span class="glyphicon glyphicon-cloud"></span> SQL</a></li>';        
        
        if($_url[2]=='edit') echo '<li class="active"><a href="#"><span class="glyphicon glyphicon-edit"></span> Edycja #'.$_GET['id'].'</a></li>';
        
        
        renderHeaderSearch('pages');
        foreach((array)$_SESSION['search']['pages'] as $key=>$item) {
            echo '<div class="label label-warning filter-item" style="float: right;">'.$item.' <span class="glyphicon glyphicon glyphicon-remove-circle remove-filter-item" phrase="'.$key.'"></span></div>';
        }    
        renderEditLanguage();
        if($_url[2]=='view') renderSorting('pages');
           echo '</ul><div class="nice_bar"></div>';
   
    }
    

    function action_sql() {
        global $cfg, $_cat_tree, $db, $_url;
        if($_POST['action']=='set_sql') {
            mysqli_query($db, "UPDATE settings SET setValue='".$_POST['sql']."' WHERE setProperty='sqlPages'");
            $alert[]=array('type'=>'success','message'=>'SQLQuerySaved');                      
        }
        $sql_query=mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM settings WHERE setProperty='sqlPages'"));
        $default_sql="SELECT * FROM pages WHERE (pagLanguages = '' OR pagLanguages LIKE '%{language.symbol}%') AND (pagCategories = '' OR pagCategories LIKE '%{categories.current}%') AND catStatus='1' AND pagId={pages.current}";        
        require_once('_backend/templates/sql_edit.php');         
    }

    function action_index() {  
        global $table_config;          
        grid_view($table_config['table']);            
    }
    
    function action_view() {
        global $table_config;   
        grid_view($table_config['table']);   
         
    }    
    
    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);
    }    
    
     

?>