<?php
if( $a == 'list' ){
	if( isset( $sOption ) ){
		$content.= $oTpl->parse( 'message_done.tpl' );
	}
	$aProducers = throwProducers( );
	$oTpl->assign( 'aProducers', $aProducers );
	$content.= $oTpl->parse( 'producers_list.tpl' );
} elseif( $a == 'delete' && isset( $iProducer ) && is_numeric( $iProducer ) ){
	deleteProducer( $iProducer );
	header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $aActions['f'] . '-list&sOption=del' );
	exit;
} elseif( $a == 'form' ){
	if( isset( $_POST['sOption'] ) ){
		$iProducer = saveProducer( $_POST );
		header( 'Location: ' . $_SERVER['PHP_SELF'] . '?p=' . $p . '&sOption=save&iProducer=' . $iProducer );
		exit;
	}
	if( isset( $sOption ) ){
		if( isset( $_SESSION['iUpdatedProducts'] ) && isset( $_SESSION['iUpdatedVariants'] ) ){
			$oTpl->assign( 'sDoneMessage', str_replace( Array( '%iUpdatedProducts%', '%iUpdatedVariants%' ), Array( $_SESSION['iUpdatedProducts'], $_SESSION['iUpdatedVariants'] ), $lang['Update_message'] ) );
			$_SESSION['iUpdatedProducts'] = null;
			$_SESSION['iUpdatedVariants'] = null;
		}
		$content.= $oTpl->parse( 'message_done.tpl' );
	}
	if( isset( $iProducer ) && is_numeric( $iProducer ) ){
		$aProducer = throwProducer( $iProducer );
	} else{
		$aProducer['iPosition'] = 0;
		$aProducer['iProducer'] = null;
	}
	$aGeneralInfo['aPages'] = $oPage->throwPagesAdmin( null, 4 );
	$oTpl->assign( 'aProducer', $aProducer );
	$oTpl->assign( 'aGeneralInfo', $aGeneralInfo );
	$content.= $oTpl->parse( 'producers_form.tpl' );
} elseif( $a == 'ajax' && !empty( $sName ) ){
	header( 'Content-type: text/json' );
	echo( json_encode( saveProducer( Array( 'sName' => $sName ) ) ) );
	exit;
} elseif( $a == 'get_margin' && is_numeric( $iProducer ) ){
	$aProducer = throwProducer( $iProducer );
	header( 'Content-type: text/json' );
	echo( json_encode( $aProducer['sMargin'] ) );
	exit;
} elseif( $a == 'margin_ajax' && is_numeric( $iProducer ) ){
	$aProducer = throwProducer( $iProducer );
	$aProducer['bUpdateMargins'] = 1;
	saveProducer( $aProducer );
	if( isset( $_SESSION['iUpdatedProducts'] ) && isset( $_SESSION['iUpdatedVariants'] ) ){
		$oTpl->assign( 'sDoneMessage', str_replace( Array( '%iUpdatedProducts%', '%iUpdatedVariants%' ), Array( $_SESSION['iUpdatedProducts'], $_SESSION['iUpdatedVariants'] ), $lang['Update_message'] ) );
		$_SESSION['iUpdatedProducts'] = null;
		$_SESSION['iUpdatedVariants'] = null;
	}
	echo $oTpl->parse( 'message_done.tpl' );
	exit;
} elseif( $a == 'multiselect' ){ // for banners
	$aProducers = throwProducers(  );
	#var_dump( $aProducers );
	$oTpl->assign( 'aProducers', $aProducers );
	echo $oTpl->parse( 'producers_multiselect.tpl' );
	exit;
}
?>