<?php
require_once DIR_ENGINE . 'banners.php';
require_once DIR_ENGINE . 'banners-admin.php';
if( $a == 'list' && !isset( $aActions['o1'] ) ){
	if( isset( $sOption ) ) $content.= $oTpl->parse( 'message_done.tpl' );
	if( isset( $_POST['sOption'] ) ){
		saveVariables( $_POST, DB_CONFIG );
		saveVariables( $_POST, DB_CONFIG_LANG );
		saveBanners( $_POST );
		header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $p . '&sOption=save' );
		exit;
	}
	$aBanners = listBanners( );
	$oTpl->assign( 'aBanners', $aBanners );
	$content.= $oTpl->parse( 'banners_list.tpl' );
} elseif( $a == 'list' && $aActions['o1'] == 'chart' ){
	$aBanners = listBanners( );
	$oTpl->assign( 'aBanners', $aBanners );
	echo iconv( 'UTF-8', 'cp1250', $oTpl->parse( 'banners_list_xml.tpl' ) );
	exit;
} elseif( $a == 'delete' && isset( $iBanner ) && is_numeric( $iBanner ) ){
	deleteBanner( $iBanner );
	header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $aActions['f'] . '-list&sOption=del' );
	exit;
} elseif( $a == 'form' ){
	if( isset( $_POST['sOption'] ) ){
		$iBanner = saveBanner( $_POST );
		header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $p . '&sOption=save&iBanner=' . $iBanner );
		exit;
	} else{
		if( isset( $sOption ) ) $content.= $oTpl->parse( 'message_done.tpl' );
		if( isset( $iBanner ) && is_numeric( $iBanner ) ) $aBanner = throwBanner( $iBanner );
		if( !isset( $aBanner ) || !is_array( $aBanner ) ){
			$aBanner['sColor'] = '#ffffff';
			$aBanner['iType'] = null;
			$aBanner['iStatus'] = 1;
			$aBanner['iViews'] = 0;
			$aBanner['iClicks'] = 0;
			$aBanner['iMax'] = 0;
			$aBanner['iMaxClicks'] = 0;
			$aBanner['iPosition'] = 0;
			$aBanner['aPages'] = Array();
		} else{
			$sql = 'SELECT `iPage`, `iPage` FROM `' . $oDB->throwTableName( DB_BANNERS_PAGES ) . '` WHERE `iBanner` = \'' . intval( $iBanner ) . '\'';
			$aBanner['aPages'] = $oDB->executeSQL( $sql, true, DataBase::ASSOCIATIVE );
			$sql = 'SELECT `iProducer`, `iProducer` FROM `' . $oDB->throwTableName( DB_BANNERS_PRODUCERS ) . '` WHERE `iBanner` = \'' . intval( $iBanner ) . '\'';
			$aBanner['aProducers'] = $oDB->executeSQL( $sql, true, DataBase::ASSOCIATIVE );
		}
		$aGeneralInfo['aPagesFull'] = $oPage->throwProductsPagesAdminFull( null, null, false );
		$aGeneralInfo['aProducersFull'] = throwProducersForSelect(  );
		$oTpl->assign( 'aGeneralInfo', $aGeneralInfo );
		$oTpl->assign( 'aBanner', $aBanner );
		$oTpl->assign( 'aBannersTypes', $aBannersTypes );
		$content.= $oTpl->parse( 'banners_form.tpl' );
	}
}
?>