<?php
namespace admin\view;

class Layouts {

  public static function showLayouts()
  {
		$out = \admin\view\PagePanel::show( true, false, false, 'Szablony' );

		$dbrowse = new \DataBrowse( 'pp_layouts' );
		$dbrowse -> addPosition( 'name',    'Nazwa',    '', '', '', 'name' 	);
		$dbrowse -> addPosition( 'enabled', 'Aktywny',  '', \System::getComboYesNo() );
		$dbrowse -> addPositionSimple( 'edytuj',  '', './?rw=edit' );
		$dbrowse -> addPositionSimple( 'usuń',    '', '', \System::deleteAction() );
		$dbrowse -> setParam( 'id' );
		$dbrowse -> addSort( 'name ASC' );
		$dbrowse -> addLp();
		$out .= $dbrowse -> draw();

		return $out;
  }
  
  public static function drawLayoutEditPages( $pages, $step = 0 )
  {
    $tpl = new \Savant3;
    $tpl -> _pages  = $pages;
    $tpl -> _step   = $step;
    return $tpl -> fetch( 'other/layout-edit-pages' );
  }

  public static function addLayout()
  {
    $out = \admin\view\PagePanel::show( false, true, true, 'Szablony' );
		
    $tpl = new \Savant3;
    $tpl -> _rw     = 'save_new';
    $tpl -> _pages 	= \admin\factory\Layouts::getPagesAssign();
    $out .= $tpl -> fetch( 'other/layout-edit' );
    return $out;
  }

  public static function editLayout( $id )
  {    
    \System::deleteSessionVar( 'id_menu' );
    
    $out = \admin\view\PagePanel::show( false, true, true, 'Szablony', 'formularz' , false , false , 'saveLayout()' );

    $tpl = new \Savant3;
    $tpl -> _rw         = 'save';
    $tpl -> _pages      = \admin\factory\Layouts::getPagesAssign( $id );
    $tpl -> _layout     = \admin\factory\Layouts::getLayout( $id, true );		
    $out .= $tpl -> fetch( 'other/layout-edit' );

    return $out;
  }
}
?>