<?
########## 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');
	user_error("No skins for reseller $PHP_AUTH_USER", E_USER_ERROR);
	echo("<p><b>Error:</b>No skins for reseller $PHP_AUTH_USER</p>");
	exit();	
}

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

$file = "../skins/skin_$skin/style.css";

if( !file_exists("$file") || !$lines = file("$file") )
{
	$alerts[] = ltext('sk_cant_read_css');
	user_error("Can not read CSS file", E_USER_ERROR);
	echo("<p><b>Error:</b>can not read CSS file $file</p>");
	exit();	
}

$parser = new CssParser;

if (!$parser->parseString(implode(' ', $lines))) 
{
	$alerts[] = ltext('sk_cant_parse_css');
	user_error("Can not parse CSS file", E_USER_ERROR);
	echo("<p><b>Error:</b>can not parse CSS file $file</p>");
	exit();	
}

$rows = 25;

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

$css = array(
	// background of table
	"tblbgcolor" => array("name" => "sk_style_tblbgcolor_frcolor", "sel" => ".tblbgcolor", "prop" => "background-color"),
	// backgound of page
	"bgcolor_body" => array("name" => "sk_style_body_bgcolor", "sel" => "body", "prop" => "background-color"),
	
//	"a_data_link" => array("name" => "sk_style_a_data_link_frcolor", "sel" => "A.data:link", "prop" => "COLOR"),
//	"a_data_vis" => array("name" => "sk_style_a_data_vis_frcolor", "sel" => "A.data:visited", "prop" => "COLOR"),
//	"a_data_act" => array("name" => "sk_style_a_data_act_frcolor", "sel" => "A.data:active", "prop" => "COLOR"),
//	"a_data_hover" => array("name" => "sk_style_a_data_hover_frcolor", "sel" => "A.data:hover", "prop" => "COLOR"),	
	// foreground of header 
	"titel_3" => array("name" => "sk_style_titel_3_frcolor", "sel" => ".titel-3", "prop" => "color"),
	// background of header
	"titel_3_bg" => array("name" => "sk_style_titel_3_bgcolor", "sel" => ".titel-3", "prop" => "background-color")
);

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

if($save)
{
//	create_newskin();

	foreach ($css as $fname => $co)
	{
		//if($$fname)
		if(preg_match('/^#(([ABCDEFabcdef0-9]{3})|([ABCDEFabcdef0-9]{6}))$/', $$fname))
		{
			$parser->setPropertyValue($co["sel"], $co["prop"], $$fname);
		}
		else
		{
		    $alerts[] = ltext('sk_bad_color', array(ltext($co['name'])));
		}
	}
	//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);
		if( $ret != 0 )
		{
			$alerts[] = ltext('sk_cant_save_style', array( ltext($farr["name"]), implode("<br>", $out)) );
		}
	}
	else 
	{
		$alerts[] = ltext('sk_cant_save_style1', array( ltext($farr["name"]) ));
	}
	
}

//print_r($css);

if(is_array($alerts) && sizeof($alerts))
{
	foreach ($alerts as $a)
	{
		message(ERROR, $a);
	}
}
elseif($save)
{
	if($strSkinName == '/skins/skin_' . $skin)
	{
		if($_POST['accept'])
		{
			$ret = 'adjust_workframe';
		}
		else
		{
			$ret = 'editskins';
		}
		$url = 'skins.php?action=' . $ret;
		if($skin)
		{
			$url .= '&skin=' . $skin;
		}
		$url = urlencode($url);
?>
<script>
top.leftFrame.location.href = 'ver_xp30_frame_left_nav_tree.php?op_block=general&op_item=skins_editor&op_url=<?=$url?>';
</script>
<?
		$save = 0;
		include($thisdir . '/skins_inc/' . $ret  . '.php');
		return;
	}
    else
    {
    	if(!$_POST['accept'])
    	{
    		include($thisdir . '/skins_inc/editskins.php');
    		return;
    	}
    }
}

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 );
}

function doChange2()
{
    document.forms[0].accept.value=0;
    document.forms[0].submit();
}

</script>

<!-- sample -->
<!--
<hr>
<p class="sample_notice"><?=ltext('sk_sample_table')?></p>
<table class="tblbgcolor" border="1" cellpadding="3" cellspacing="0" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF"> 
<tr> 
    <td  colspan="2" class="titel-3"><?=ltext('sk_style_table_header')?></td>
</tr>
<tr> 
    <td><a class="data" href="" onClick="return false;"><?=ltext('sk_style_a_data_link')?></a></td>
    <td>Text 1</td> 
</tr>
<tr> 
    <td><a class="data:visited" href="" onClick="return false;"><?=ltext('sk_style_a_data_link_visited')?></a></td>
    <td>Text 2</td> 
</tr>
</table>
<hr>
<iframe id="sampleFrame" name="sampleFrame" src="skins_sample.php?sample=in_frame_table&skin=<?=$skin?>">
</iframe>
<script>
	frames['sampleFrame'].location.url="skins_sample.php?sample=in_frame_table&skin=<?=$skin?>";
</script>
-->
<!-- end of sample-->

<form name="colorform" action="skins.php" method="POST">
<input type="hidden" name="accept" value="1">
<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_select_color"); ?></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 border="0"><tr><td><?=std_button(ltext('sk_apply'), 'javascript:doChange()')?></td>
	<td><?=std_button(ltext('sk_ok'), 'javascript:doChange2()')?></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="skins/default/pics/1px.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="skins/default/pics/1px.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>

