<?
// po poprawkach
namespace admin\view;

class Pages
{
  public static function showAssignedArticles( $id )
  {    
    $out = \admin\view\PagePanel::show( false, false, true, 'Przypisane artykuły' );
    
    $tpl = new \Savant3();
    $tpl -> _articles = \admin\factory\Pages::getAssignedArticles( $id );
    $out .= $tpl -> fetch( 'pages/page-articles-list' );
    
    return $out;
  }

  public static function showPages()
  {
    $tpl = new \Savant3;
    $tpl -> _menu = \admin\factory\Menu::getMenu();
    return $tpl -> fetch( 'pages/page-definition' );
  }
  
  public static function editPage( $id, $menu_id )
  {
    $out = \admin\view\PagePanel::show( false, 'Zapisz', true, 'Lista stron' );

    $page = \admin\factory\Pages::getPageParam( $id );
    
    $tpl = new \Savant3;
    $tpl -> _id             = $id;
    $tpl -> _page           = $page;
    $tpl -> _rw             = 'edit';
    $tpl -> _menu_id        = $menu_id;
    $tpl -> _parent_id      = $page['parent_id'];
    $tpl -> _menu           = \admin\factory\Menu::getMenu();
    $tpl -> _language       = \admin\factory\Pages::getPageParamLanguage( $id );
    $tpl -> _pages          = \admin\factory\Pages::getPages( $menu_id );
    $tpl -> _page_types     = \admin\factory\Pages::getPageTypes();
    $tpl -> _sort           = \admin\factory\Pages::getSortTypes();
    $tpl -> _layouts        = \admin\factory\Layouts::getLayouts();
    $tpl -> _layout_id      = \admin\factory\Pages::getPageLayout( $id );
    $out .= $tpl -> fetch( 'pages/page-edit' );

    return $out;
  }

  public static function addPage(  $menu_id, $parent_id = 0 )
  {
    $out = \admin\view\PagePanel::show( false, 'Dodaj', true, 'Lista stron' );
    
    $tpl = new \Savant3;
    $tpl -> _rw         = 'add';
    $tpl -> _menu_id    = $menu_id;
    $tpl -> _parent_id  = $parent_id;
    $tpl -> _language   = \language\FLanguage::getLangs();
    $tpl -> _menu       = \admin\factory\Menu::getMenu();
    $tpl -> _page_types = \admin\factory\Pages::getPageTypes();
    $tpl -> _pages      = \admin\factory\Pages::getPages( $menu_id );
    $tpl -> _sort       = \admin\factory\Pages::getSortTypes();
    $tpl -> _order      = \admin\factory\Pages::selectMaxOrder();
    $tpl -> _layouts    = \admin\factory\Layouts::getLayouts();
    $out .= $tpl -> fetch( 'pages/page-edit' );

    return $out;
  }
  
  public static function drawSubpagesEdit( $pages, $parent_id, $step = 0, $this_id = false )
  {
    $tpl = new \Savant3();
    $tpl -> _pages      = $pages;
    $tpl -> _parent_id  = $parent_id;
    $tpl -> _step       = $step;
    $tpl -> _this_id    = $this_id;
    return $tpl -> fetch( 'pages/page-subpages-edit' );
  }
  
  public static function drawSubpages( $pages, $parent_id = 0 )
  {
    $tpl = new \Savant3();
    $tpl -> _pages      = $pages;
    $tpl -> _parent_id  = $parent_id;
    return $tpl -> fetch( 'pages/page-subpages' );
  }
}
?>