<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

if(!defined('CONFIXX'))
{
	return;
}


$skin = $skin * 1;
$id = db_query("select count(*) as c from custom_skins where id = $skin and anbieter='$PHP_AUTH_USER' and owner_type='reseller'");
$w = db_fetch_array($id);
if(!$w["c"])
{
	$alerts[] = ltext('sk_invalid_skin');
	include($thisdir . "/se_start.php");
	exit();	
}


include( dirname(__FILE__) . "/colors.php" );
include("../include/module.CssParser.php");

//echo "skins/skin_$skin/style.css";

if( !file_exists("skins/skin_$skin/style.css") || !$lines = file("skins/skin_$skin/style.css") )
{
	$alerts[] = ltext('sk_cant_read_css');
	include($thisdir . "/se_start.php");
	exit();	
}

$parser = new CssParser;

if (!$parser->parseString(implode(' ', $lines))) 
{
	$alerts[] = ltext('sk_cant_parse_css');
	include($thisdir . "/se_start.php");
	exit();	
}


$rows = 25;

$cols1 = ceil( count($colors1) / $rows );
$cols2 = ceil( count($colors2) / $rows );

$css = array(
	"tblbgcolor" => array("name" => "sk_style_tblbgcolor", "sel" => ".tblbgcolor", "prop" => "background-color"),
	//"tbldata" => array("name" => "sk_style_tbldata", "sel" => ".tbldata", "prop" => "color"),
	"a_data_link" => array("name" => "sk_style_a_data_link", "sel" => "A.data:link", "prop" => "COLOR"),
	"a_data_vis" => array("name" => "sk_style_a_data_vis", "sel" => "A.data:visited", "prop" => "COLOR"),
	"a_data_act" => array("name" => "sk_style_a_data_act", "sel" => "A.data:active", "prop" => "COLOR"),
	"a_data_hover" => array("name" => "sk_style_a_data_hover", "sel" => "A.data:hover", "prop" => "COLOR"),	
	"titel_2" => array("name" => "sk_style_titel_2", "sel" => ".titel-2", "prop" => "color"),
	"titel_3" => array("name" => "sk_style_titel_3", "sel" => ".titel-3", "prop" => "color"),
	//"titel_4" => array("name" => "sk_style_titel_4", "sel" => ".titel-4", "prop" => "color"),
	//"tblbgcolorover" => array("name" => "sk_style_tblbgcolorover", "sel" => ".tblbgcolorover", "prop" => "background-color"),
	//"help" => array("name" => "sk_style_help", "sel" => ".help", "prop" => "color"),
	"titel_help" => array("name" => "sk_style_titel_help", "sel" => ".titel-help", "prop" => "color"),
	"button_1" => array("name" => "sk_style_button_1", "sel" => ".button-1", "prop" => "color"),
	"menucolor" => array("name" => "sk_style_menucolor", "sel" => ".menucolor", "prop" => "background-color"),
	//"a_menu_color" => array("name" => "sk_style_a_menu_color", "sel" => "a.menu", "prop" => "color"),
	"a_menu_bgcolor" => array("name" => "sk_style_a_menu_bgcolor", "sel" => "a.menu", "prop" => "BACKGROUND-COLOR"),
	"a_menu_link" => array("name" => "sk_style_a_menu_link", "sel" => "a.menu:link", "prop" => "color"),
	"a_menu_vis" => array("name" => "sk_style_a_menu_vis", "sel" => "a.menu:visited", "prop" => "color"),
	"a_menu_hover_bgcolor" => array("name" => "sk_style_a_menu_hover_bgcolor", "sel" => "a.menu:hover", "prop" => "background-color"),
	"a_menu_hover_color" => array("name" => "sk_style_a_menu_hover_color", "sel" => "a.menu:hover", "prop" => "color"),
	"a_menu_act_bgcolor" => array("name" => "sk_style_a_menu_act_bgcolor", "sel" => "a.menu:active", "prop" => "background-color"),
	"a_menu_act_color" => array("name" => "sk_style_a_menu_act_color", "sel" => "a.menu:active", "prop" => "color"),
);

if(!$tmp_dir)
{
	$tmp_dir = ini_get('upload_tmp_dir');
}

if($save)
{
	foreach ($css as $fname => $co)
	{
		if($$fname)
		{
			$parser->setPropertyValue($co["sel"], $co["prop"], $$fname);
		}
	}
	//echo $parser->outputString();
	$tmpfname = tempnam($tmp_dir, "CSS");
	if( $fd = fopen($tmpfname, "w") )
	{
		fwrite($fd, $parser->outputString());	
		fclose($fd);
//		echo filesize($tmpfname) . " $tmpfname <br>";
		chmod($tmpfname, 0666);
//		echo "$sbindir/$stylescript --skin skin_$skin --mov_file " . basename($tmpfname) . " --dest style.css";
		exec("$sbindir/$stylescript --skin skin_$skin --mov_file " . basename($tmpfname) . " --dest style.css", $out, $ret);
		echo "<pre>\n";
//		echo $ret."\n";
		echo implode("\n", $out);
		echo "</pre>\n";
		if( $ret != 0 )
		{
			$alerts[] = ltext('sk_cant_save_style', array( ltext($farr["name"]) ));
		}
	}
	else 
	{
		$alerts[] = ltext('sk_cant_save_style1', array( ltext($farr["name"]) ));
	}
	
}

//print_r($css);

print_header( array("klayers.js") );

?>

<script>

formfield = "";

function showcolors()
{
	if( loaded )
	{
		l = layer("collayer");
		l.setTop( 10 + getScrollY() );
		l.setLeft(10);
		l.show();
	}
}

function hidecolors()
{
	if( loaded )
	{
		l = layer("collayer");
		l.hide();
	}
}

function setcolor( color )
{
	hidecolors();
	document.forms.colorform[formfield].value = color;
	 settestcolor( color );
}

function settestcolor( color )
{
	t = layer( "test_" + formfield );
	t.setBgColor( color );
}

</script>

<form name="colorform" action="skins.php" method="POST">
<input type="hidden" name="save" value="1">
<input type="hidden" name="action" value="<? echo $action; ?>">
<input type="hidden" name="skin" value="<? echo $skin; ?>">
<table class="tblbgcolor" align="left" border="1" cellpadding="3" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">
<? foreach ($css as $fname => $co): 
	$col = $parser->getPropertyValue($co["sel"], $co["prop"]);
?>
<tr>
	<td><? echo ltext($co["name"]); ?></td>
	<td id="test_<?=$fname?>" style="background-color: <? echo $col;  ?>"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
	<td><input type="text" name="<?=$fname?>" value="<? echo $col;  ?>"></td>
	<td><a class="data" href="#" onclick="formfield='<?=$fname?>'; showcolors(); return false;"><? echo ltext("sk_style_change"); ?></a></td>
	<td><a class="data" href="#" onclick="formfield='<?=$fname?>'; setcolor('<? echo $col;  ?>'); return false;"><? echo ltext("sk_style_cancel"); ?></a></td>
</tr>
<? endforeach; ?>
<tr>
	<td colspan="5" align="right"><table cellpadding="0" cellspacing="0" border="0">
	    <tr>
	    <td><input type=image border=0 src="<?=$strSkinName?>/pics/buttons/bt_img_left.gif"></td>
	    <td background="<?=$strSkinName?>/pics/buttons/bt_img_middle.jpg"><a href="javascript:doChange()"  class="button-1"><? echo ltext("sk_btn_send"); ?></a></td>
	    <td><input type=image border=0 src="<?=$strSkinName?>/pics/buttons/bt_changepass.gif"></td>
	    </tr>
	    </table></td>
</tr>
</table>
</form>




<? $cell = reset($colors1); ?>
<div id="collayer" style="position: absolute; visibility: hidden; background-color: #FFFFFF">
<table border="1" cellpadding="0" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">
<tr>
    <td>
<table bgcolor="#D0D0D0" border="0" cellpadding="0" cellspacing="4" >
<? for( $i=0; $i < $cols1; $i++ ): ?>
<tr>
	    <? for( $j=0; $j < $rows; $j++ ): ?>
	    <td<? if($cell): ?> bgcolor="<?=$cell['colcode']?>"<? endif; ?>><? if($cell): ?><a href="#" onclick="setcolor('<?=$cell['colcode']?>'); return false;"><img src="<?=$strSkinName?>/file_icons/1x1.gif" border="0" width="10" height="10" alt="<?=$cell['colname']?>"></a><? else: ?><img src="<?=$strSkinName?>/file_icons/1x1.gif" border="0" width="10" height="10" alt=""><? endif; ?></td>
	    <? $cell = next($colors1); endfor; ?>
</tr>
<? endfor;  ?>
<tr>
	<td colspan="<? echo $rows; ?>" align="center"><img src="<?=$strSkinName?>/file_icons/1x1.gif" border="0" width="10" height="10" alt=""></td>
</tr>
<? $cell = reset($colors2); ?>
<? for( $i=0; $i < $cols2; $i++ ): ?>
<tr>
	    <? for( $j=0; $j < $rows; $j++ ): ?>
	    <td<? if($cell): ?> bgcolor="<?=$cell['colcode']?>"<? endif; ?>><? if($cell): ?><a href="#" onclick="setcolor('<?=$cell['colcode']?>'); return false;"><img src="<?=$strSkinName?>/file_icons/1x1.gif" border="0" width="10" height="10" alt="<?=$cell['colname']?>"></a><? else: ?><img src="<?=$strSkinName?>/file_icons/1x1.gif" border="0" width="10" height="10" alt=""><? endif; ?></td>
	    <? $cell = next($colors2); endfor; ?>
</tr>
<? endfor;  ?>
<tr>
	<td colspan="<? echo $rows; ?>" align="center"><a href="#" onclick="hidecolors(); return false;"><? echo ltext("sk_hide_colors"); ?></a></td>
</tr>
</table>
	</td>
</tr>
</table>
</div>

