<?php
require_once DIR_ENGINE . 'boxes.php';
require_once DIR_ENGINE . 'boxes-admin.php';
if( $a == 'list' ){
	if( isset( $_POST['sOption'] ) ){
		foreach( $_POST['aBox'] as $aBox['iBox'] => $aBox ){
			$oDB->save( DB_BOXES, $aBox, 'iBox' );
		}
		header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $p . '&sOption=save' );
		exit;
	}
	if( isset( $sOption ) ) $content.= $oTpl->parse( 'message_done.tpl' );
	$aBoxes = listBoxes( );
	$oTpl->assign( 'aBoxes', $aBoxes );
	$oTpl->assign( 'aBoxesDisplay', $aBoxesDisplay );
	$content.= $oTpl->parse( 'boxes_list.tpl' );
} elseif( $a == 'delete' && isset( $iBox ) && is_numeric( $iBox ) ){
	deleteBox( $iBox );
	header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $aActions['f'] . '-list&sOption=del' );
	exit;
} elseif( $a == 'form' ){
	if( isset( $_POST['sOption'] ) ){
		if( !isset( $_POST['iStatus'] ) ) $_POST['iStatus'] = 0;
		$iBox = saveBox( $_POST );
		header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $p . '&sOption=save&iBox=' . $iBox . '&activeTabId=' . $_POST['activeTabId'] );
		exit;
	}
	if( !isset( $iBox ) || !is_numeric( $iBox ) ){
		$aBox['sContent'] = null;
	} else{
		$aBox = throwBox( $iBox );
		$aBox['aFiles'] = $oFile->listAllFilesAdmin( $iBox, 3 );
		$sql = 'SELECT `iPage`, `iPage` FROM `' . $oDB->throwTableName( DB_BOXES_PAGES ) . '` WHERE `iBox` = \'' . intval( $iBox ) . '\'';
		$aBox['aPages'] = $oDB->executeSQL( $sql, true, DataBase::ASSOCIATIVE );
	}
	$aGeneralInfo['aFilePosition'] = $aFilePositionBox;
	$aGeneralInfo['aPhotoPosition'] = $aPhotoPositionBox;
	$aGeneralInfo['iDefaultFilePosition'] = 2;
	$aGeneralInfo['aPagesFull'] = $oPage->throwProductsPagesAdminFull( null, null, false );

	if( isset( $sOption ) ) $content.= $oTpl->parse( 'message_done.tpl' );
	$oTpl->assign( 'aBox', $aBox );
	$oTpl->assign( 'aBoxesDisplay', $aBoxesDisplay );
	$oTpl->assign( 'aGeneralInfo', $aGeneralInfo );
	$content.= $oTpl->parse( 'boxes_form.tpl' );
}
?>