<?php
if( $a == 'list' ){
  if( isset( $_POST['sOption'] ) ){
    $oPage->savePages( $_POST );
    $sOption = 'save';
  }

  if( isset( $sOption ) ){
    $content .= $oTpl->tbHtml( 'messages.tpl', 'DONE' );
  }
  
  $content .= $oTpl->tbHtml( 'pages.tpl', 'LIST_TITLE' );
  $sList = $oPage->listPagesAdmin( 'pages.tpl' );
  $content .= !empty( $sList ) ? $sList : $oTpl->tbHtml( 'messages.tpl', 'EMPTY' );
}
elseif( $a == 'form' ){
  if( isset( $_POST['sName'] ) ){
    $iPage = $oPage->savePage( $_POST );
    if( isset( $_POST['sOptionList'] ) )
      header( 'Location: '.$_SERVER['PHP_SELF'].'?p='.$aActions['f'].'-list&sOption=save' );
    else
      header( 'Location: '.$_SERVER['PHP_SELF'].'?p='.$p.'&sOption=save&iPage='.$iPage );
    exit;
  }

  if( isset( $sOption ) )
    $content .= $oTpl->tbHtml( 'messages.tpl', 'DONE' );

  if( isset( $iPage ) && is_numeric( $iPage ) ){
    $aData = $oPage->throwPage( $iPage );
  }

  if( isset( $aData ) && is_array( $aData ) ){
    $aData['sDescriptionShort'] = changeTxt( $aData['sDescriptionShort'], 'nlNds' );
    $aData['sDescriptionFull'] = changeTxt( $aData['sDescriptionFull'], 'nlNds' );
  }
  else{
    $aData['iStatus'] = 1;
    $aData['iType'] = 1;
    $aData['iPageParent'] = null;
    $aData['iPosition'] = 0;
    $iPage = null;
    $aData['sDescriptionFull'] = null;
    $aData['sDescriptionShort'] = null;
  }

  $sStatusBox = throwYesNoBox( 'iStatus', $aData['iStatus'] );
  $sTypesSelect = throwSelectFromArray( $aMenuTypes, $aData['iType'] );
  $sPagesSelect = $oPage->throwPagesSelectAdmin( $aData['iPageParent'] );
  $oTpl->unsetVariables( );

  $sDescriptionShort = htmlEditor ( 'sDescriptionShort', '120', '100%', $aData['sDescriptionShort'], Array( 'aOptions' => Array( 'ToolbarStartExpanded' => false ), 'ToolbarSet' => 'Basic' ) ) ;
  $sDescriptionFull = htmlEditor ( 'sDescriptionFull', '280', '100%', $aData['sDescriptionFull'], Array( 'ToolbarSet' => 'DescriptionFull' ) ) ;
  
  $sFormTabs = $oTpl->tbHtml( 'pages.tpl', 'FORM_TABS' );
  $content .= $oTpl->tbHtml( 'pages.tpl', 'FORM_MAIN' );
}
elseif( $a == 'delete' && isset( $iPage ) && is_numeric( $iPage ) ){
  if( !isset( $bWithoutImages ) )
    $bWithoutImages = null;
  $oPage->deletePage( $iPage, $bWithoutImages );
  header( 'Location: '.$_SERVER['PHP_SELF'].'?p='.$aActions['f'].'-list&sOption=del' );
  exit;
}
?>