<?php
/*
 * \Eigene Dateien\Sentra.Designs\BasicDesigner\images.accordion\scripts\compile-accordion.php
 * Depending on F7-parameter we need to prepare an accordion.ini which is located in the substyle folder
 * This function is called by \php_lib\_plugin_functions.php:: function AccordStyleSetup ()
 */
global $wb;
global $TEMPLATE_PARAMETER;/* required because this file is included by function AccordStyleSetup ()	 */
If (!isset($acrd_status_icons)) {
	If (isset($wb ->BDpara['acrd_status_icons'])) {
		$acrd_status_icons = $wb ->BDpara['acrd_status_icons'];
	} Else {
		$acrd_status_icons = '../../images.accordion/preview-toggler.jpg';
	}
}
If (isset($TEMPLATE_PARAMETER['acrd_status_icons'])) {
	$acrd_status_icons = $TEMPLATE_PARAMETER['acrd_status_icons'];
}
$acrdpath = pathinfo($acrd_status_icons);/* filename of the status icon template (F7-parameter)*/
//DEBUG($acrdpath);
$tmp = str_replace('preview-','',$acrdpath['basename']);
$tmpary = explode('.',$tmp);
$acrd_icons_path = $tmpary[0];
/*
DEBUG($acrd_icons_path.'<br>'.$wb->PROJECT['templatefull'].DIRECTORY_SEPARATOR.
				'images.accordion'.DIRECTORY_SEPARATOR.
				$acrd_icons_path.DIRECTORY_SEPARATOR.'compile-icons.php');
				*/
/* Setup acordion icons (copy selected icons into the images folder) */
require($wb->PROJECT['templatefull'].DIRECTORY_SEPARATOR.
				'images.accordion'.DIRECTORY_SEPARATOR.
				$acrd_icons_path.DIRECTORY_SEPARATOR.'compile-icons.php');

/* Create the accordion.ini file */
// load accordion.ini with place holder values
$Acrdini = file_get_contents($wb->PROJECT['template_path'].DIRECTORY_SEPARATOR.
														'tpl'.DIRECTORY_SEPARATOR.
														'accordion.tpl.ini');
/* We need some info from the TABS.ini
 * These parameter are stored in $wb -> TABpara
 * and are provided by function TabStyleSetup () {
 */

//DEBUG($wb->TABpara);
$TABheight = 35;
/* Some TAB-styles use graphics. Therefore we need to adjust the height of the tabs according to the graphics height */
If ($wb -> TABpara['mode'] == 'Bricks gradient' ||
		$wb -> TABpara['mode'] == 'animated' ||
/*		$wb -> TABpara['mode'] == 'Pointer' || */
		$wb -> TABpara['mode'] == 'Form gradient' ||
		$wb -> TABpara['mode'] == 'Bricks inverted gradient') {
	$dstimgfolder = $wb->PROJECT['template_path'].'images'.DIRECTORY_SEPARATOR;
	//DEBUG($dstimgfolder.$wb->TABpara['grad_image']);
	If (file_exists($dstimgfolder.$wb->TABpara['grad_image'])) {
		list($TABwidth,$TABheight) = getimagesize($dstimgfolder.$wb->TABpara['grad_image']);
	//	DEBUG($TABwidth.' - '.$TABheight);
	} Else {
		DEBUG('dstimgfolder tab_grad.png does NOT exist');
	}
}
$Acrdini = str_replace('{{height}}', $TABheight,$Acrdini);
If (!isset($Acrd_icon_padding)) {
	If (isset($wb ->BDpara['Acrd_icon_padding'])) {
		$Acrd_icon_padding = $wb ->BDpara['Acrd_icon_padding'];
	} Else {
		$Acrd_icon_padding = 24;
	}
}
If (isset($TEMPLATE_PARAMETER['Acrd_icon_padding'])) {
	$Acrd_icon_padding = $TEMPLATE_PARAMETER['Acrd_icon_padding'];
}

$a_iconposx = $Acrd_icon_padding;
$Acrdini = str_replace('{{Acrd_icon_width}}', $Acrd_icon_width, $Acrdini);

//DEBUG($Acrdini);
/* Replace place holder with proper values provided by F7
$Acrdini = str_replace('{{}}', $, $Acrdini);
$Acrdini = str_replace('{{}}', $, $Acrdini);
$Acrdini = str_replace('{{}}', $, $Acrdini);
$Acrdini = str_replace('{{}}', $, $Acrdini);
$Acrdini = str_replace('{{}}', $, $Acrdini);
$Acrdini = str_replace('{{}}', $, $Acrdini);
$Acrdini = str_replace('{{}}', $, $Acrdini);
$Acrdini = str_replace('{{}}', $, $Acrdini);
$Acrdini = str_replace('{{}}', $, $Acrdini);
*/
$Acrdini = str_replace("{{text_ident}}"				, $Acrd_icon_padding, $Acrdini);
If (!isset($acrd_Alignment)) {
	If (isset($wb ->BDpara['acrd_Alignment'])) {
		$acrd_Alignment = $wb ->BDpara['acrd_Alignment'];
	} Else {
		$acrd_Alignment = 'left';
	}
}
If (isset($TEMPLATE_PARAMETER['acrd_Alignment']))
	$acrd_Alignment = $TEMPLATE_PARAMETER['acrd_Alignment'];

$Acrdini = str_replace("{{acrd_Alignment}}"						, $acrd_Alignment, $Acrdini);/* corresponds to text-align */
$Acrdini = str_replace("{{Acrd_icon_padding}}"				, $Acrd_icon_padding, $Acrdini);

/*
$Acrdini = str_replace("{{acrd_color_closed}}"				, '#FFFFFF', $Acrdini);
$Acrdini = str_replace("{{acrd_color_closed_hover}}"	, '#FFFFFF', $Acrdini);
$Acrdini = str_replace("{{acrd_color_opened}}"				, '#FFFFFF', $Acrdini);
$Acrdini = str_replace("{{acrd_color_opened_hover}}"	, '#FFFFFF', $Acrdini);

$Acrdini = str_replace("{{bg_opened_color}}"					, $wb -> TABpara['TABulbgcolor']		, $Acrdini);
$Acrdini = str_replace("{{bg_opened_hover_color}}"		, $wb -> TABpara['TABbghvrcolor']		, $Acrdini);
$Acrdini = str_replace("{{bg_closed_color}}"					, $wb -> TABpara['TABulbgcolor']		, $Acrdini);
$Acrdini = str_replace("{{bg_closed_hover_color}}"		, $wb -> TABpara['TABbghvrcolor']		, $Acrdini);

*/
$Acrdini = str_replace("{{TABtextcolor}}"							, $wb -> TABpara['TABtextcolor']		, $Acrdini);
$Acrdini = str_replace("{{TABtexthvrcolor}}"					, $wb -> TABpara['TABtexthvrcolor']	, $Acrdini);
$Acrdini = str_replace("{{TABborderwidth}}"			 			, $wb -> TABpara['TABborderwidth']	, $Acrdini);
IF($wb -> TABpara['TABborderstyle']=="NIL") {
	$wb -> TABpara['TABborderwidth'] = 0;
}
IF($wb -> TABpara['TABborderwidth']==0) {
	$wb -> TABpara['TABborderstyle'] = 'NIL';
}
$Acrdini = str_replace("{{TABborderstyle}}"			 			, $wb -> TABpara['TABborderstyle']	, $Acrdini);
$Acrdini = str_replace("{{TABborder_color}}"			 		, $wb -> TABpara['TABborder_color']	, $Acrdini);

Switch ($wb -> TABpara['mode']) {
	case'Bricks gradient':
	case'animated':
	case 'Pointer':
	case'Form gradient':
	case'Bricks inverted gradient':
		$Acrd_background_bg_closed 			= $wb -> TABpara['TABbgcolor'].
																			' url(./'.$wb->tplimagesfoldername.'/'.
																			$wb -> TABpara['grad_image'].') repeat-x left center;';
		$Acrd_background_bg_closed_hvr	= $wb -> TABpara['TABbgcolor'].
																			' url(./'.$wb->tplimagesfoldername.'/'.
																			$wb -> TABpara['grad_image'].') repeat-x left center;';
		$Acrd_background_bg_opened 			= $wb -> TABpara['TABbgcolor'].
																			' url(./'.$wb->tplimagesfoldername.'/'.
																			$wb -> TABpara['hover_grad_image'].') repeat-x left center;';
		$Acrd_background_bg_opened_hvr 	= $wb -> TABpara['TABbghvrcolor'].
																			' url(./'.$wb->tplimagesfoldername.'/'.
																			$wb -> TABpara['hover_grad_image'].') repeat-x left center;';
	break;
/*
	case 'Pointer':
		$Acrd_background_bg_closed 			= $wb -> TABpara['TABbgcolor'].
																			' url(./'.$wb->tplimagesfoldername.'/'.
																			$wb -> TABpara['grad_image'].') repeat-x center center';
		$Acrd_background_bg_closed_hvr	= $wb -> TABpara['TABbgcolor'].
																			' url(./'.$wb->tplimagesfoldername.'/'.
																			$wb -> TABpara['grad_image'].') repeat-x center center';
		$Acrd_background_bg_opened 			= $wb -> TABpara['TABbgcolor'].
																			' url(./'.$wb->tplimagesfoldername.'/'.
																			$wb -> TABpara['hover_grad_image'].') repeat-x center center';
		$Acrd_background_bg_opened_hvr 	= $wb -> TABpara['TABbghvrcolor'].
																			' url(./'.$wb->tplimagesfoldername.'/'.
																			$wb -> TABpara['hover_grad_image'].') nrepeat-x center center';

	break;
*/
	default:
		$Acrd_background_bg_closed 			= $wb -> TABpara['TABbgcolor'];
		$Acrd_background_bg_closed_hvr	= $wb -> TABpara['TABbghvrcolor'];
		$Acrd_background_bg_opened 			= $wb -> TABpara['TABbghvrcolor'];
		$Acrd_background_bg_opened_hvr 	= $wb -> TABpara['TABbgcolor'];
	break;
}
$Acrdini = str_replace("{{Acrd_background_bg_closed}}"				, $Acrd_background_bg_closed		, $Acrdini);
$Acrdini = str_replace("{{Acrd_background_bg_closed_hvr}}"		, $Acrd_background_bg_closed_hvr, $Acrdini);
$Acrdini = str_replace("{{Acrd_background_bg_opened}}"				, $Acrd_background_bg_opened		, $Acrdini);
$Acrdini = str_replace("{{Acrd_background_bg_opened_hvr}}"		, $Acrd_background_bg_opened_hvr, $Acrdini);
/*
$Acrdini = str_replace("{{gr_TAB_closed}}"			 			, $wb -> TABpara['grad_image']			, $Acrdini);
$Acrdini = str_replace("{{gr_TAB_closed_hover}}"			, $wb -> TABpara['grad_image']			, $Acrdini);
$Acrdini = str_replace('{{gr_TAB_opened}}'			 			, $wb -> TABpara['hover_grad_image'], $Acrdini);
$Acrdini = str_replace('{{gr_TAB_opened_hover}}'			, $wb -> TABpara['hover_grad_image'], $Acrdini);
*/
$Acrdini = str_replace("{{Acrd_icon_closed}}"					, $Acrd_icon_closed			 , $Acrdini);
$Acrdini = str_replace('{{Acrd_icon_closed_hover}}'		, $Acrd_icon_closed_hover, $Acrdini);
$Acrdini = str_replace('{{Acrd_icon_opened}}'					, $Acrd_icon_opened			 , $Acrdini);
$Acrdini = str_replace('{{Acrd_icon_opened_hover}}'		, $Acrd_icon_opened_hover, $Acrdini);

//DEBUG(htmlspecialchars($Acrdini));

//DEBUG($wb->PROJECT['template_path']."accordion.ini");
//If (!file_exists($wb->PROJECT['template_path']."accordion.ini"))
	file_put_contents($wb->PROJECT['template_path']."accordion.ini",$Acrdini);

?>