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

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

$image_types = array("gif" => 1, "jpg" => 2, "png" => 3);

//print_r($HTTP_GET_VARS);

if($save)
{
	$skin = $skin * 1;
	//echo "select count(*) from custom_skins where id = $skin and anbieter='$PHP_AUTH_USER' and owner_type='reseller'";
	$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"])
	{
		foreach ($files as $fn => $farr)
		{
			if( $HTTP_POST_FILES[$fn]["tmp_name"] && $HTTP_POST_FILES[$fn]["name"] &&
			    $HTTP_POST_FILES[$fn]["size"] && $HTTP_POST_FILES[$fn]["type"] )
			{
				$im = getimagesize($HTTP_POST_FILES[$fn]["tmp_name"]);
				if( $im[0] != $farr["w"] || $im[1] != $farr["h"] )
				{
					$alerts[] = ltext("sk_bad_image_size", array( ltext($farr["name"]) ));
				}
			
				if( $image_types[$farr["type"]] != $im[2] )
				{
					$alerts[] = ltext("sk_bad_image_type", array( ltext($farr["name"]) ));
				}
				if( $HTTP_POST_FILES[$fn]["name"] != $farr["filename"]  )
				{
					$alerts[] = ltext("sk_bad_image_name", array( ltext($farr["name"]) ));
				}
				
				//echo "ls -l " . dirname($HTTP_POST_FILES[$fn]["tmp_name"]) . "\n";
				
				//exec("ls -l " . dirname($HTTP_POST_FILES[$fn]["tmp_name"]), $out, $ret);
				//print_r($out);
				///print_r($ret);
				
				//echo "$sbindir/$stylescript --skin skin_$skin --mov_file ". basename($HTTP_POST_FILES[$fn]["tmp_name"]) . " --dest images/" . $farr["subdir"] . $farr["filename"];
				exec("$sbindir/$stylescript --skin skin_$skin --mov_file ". basename($HTTP_POST_FILES[$fn]["tmp_name"]) . " --dest " . $farr["subdir"] . $farr["filename"], $out, $ret);
				//echo "\n-- $ret --\n";
				//print_r($out);
				if($ret != 0)
				{
					$alerts[] = ltext('sk_cant_copy_image', array( ltext($farr["name"]) ));
				}
				//echo $new_fn;
				//move_uploaded_file( $HTTP_POST_FILES[$fn]["tmp_name"], $new_fn );
				//chmod( $new_fn, 0666 );
			}
			
		}
	}
	else 
	{
		$alerts[] = ltext('sk_invalid_skin');
		//include $thisdir . "/skins_inc/change.php";
	}
}


if(is_array($alerts) && sizeof($alerts))
{
	foreach ($alerts as $a)
	{
		message(ERROR, $a);
	}
}
elseif($save)
{
	if($strSkinName == '/skins/skin_' . $skin)
	{
		if($_POST['accept'])
		{
			$ret = 'upllogos';
		}
		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();

?>

<script>
function openscreen(scfile, w, h)
{
	nw = w + 2;
	nh = h + 2;
	myWin = window.open("",'screenshot','width=' + nw + ',height=' + nh);
	myWin.document.open();
	myWin.document.write('<html><head>');
	myWin.document.write('<title><? echo ltext("sk_preview"); ?></title>');
	myWin.document.write('</head>');
	myWin.document.write('<body bgcolor=white leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="window.focus();">');
	myWin.document.write('<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%"><tr><td align="center" valign="middle">');
	myWin.document.write('<img src="' + scfile + '" border="0" width="' + w + '" height="' + h + '">');
	myWin.document.write('</td></tr></table>');
	myWin.document.write('</body>');
	myWin.document.write('</html>');
	myWin.document.close();
}

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

</script>

<FORM action="skins.php" method="POST" enctype="multipart/form-data">
<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 ($files as $fn => $farr): 
	$impath = "/skins/skin_$skin/" . $farr['subdir'] . $farr['filename'];
	$imsize = array( 'w' => $farr['w'], 'h' => $farr['h'] );	
	if( file_exists($confixx_htmlDir.$impath) && $getimsize = getimagesize($confixx_htmlDir.$impath) )	
	{
		$imsize['w'] = $getimsize[0];
		$imsize['h'] = $getimsize[1];
	}
?>
<tr>
	<td><? echo ltext($farr["name"]); ?> (<? echo $farr['type']; ?>, <? echo $farr['w']; ?>x<? echo $farr['h']; ?>)</td>
	<td><INPUT type="file" name="<? echo $fn; ?>"></td>
	<td><a class="data" href="<? echo $impath; ?>" onclick="openscreen('<? echo $impath ?>', <? echo $imsize['w']; ?>, <? echo $imsize['h']; ?>); return false;"><? echo ltext("sk_preview"); ?></a></td>
</tr>
<? endforeach; ?>
<tr>
	<td colspan="3" 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>
