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

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

$arctypes = array('zip', 'tgz', 'tar');

//print_r($HTTP_POST_FILES);

//echo strrchr("asd.zip", ".");



if($skinname)
{
	$skinname = str_replace("'", "\\'", $skinname);
	
	$id = db_query("select count(*) as c from custom_skins where name = '$skinname' and owner_type='reseller' and anbieter='$PHP_AUTH_USER'");
	$wer = db_fetch_array($id);
	if($wer["c"])
	{
		$alerts[] = ltext("sk_skin_exists");
		include $thisdir . "/skins_inc/editskins.php";
	}
	else
	{
		$atype =trim(substr( strrchr($HTTP_POST_FILES["zipfile"]["name"], "."), 1 ));
		//echo $atype;
		/*
		if( file_exists( dirname($HTTP_POST_FILES["zipfile"]["tmp_name"]) . "/upl.$atype" ) )
		{
			unlink( dirname($HTTP_POST_FILES["zipfile"]["tmp_name"]) . "/upl.$atype" );	
		}
		copy($HTTP_POST_FILES["zipfile"]["tmp_name"],  dirname($HTTP_POST_FILES["zipfile"]["tmp_name"]) . "/upl.$atype");
		//*/
		if( in_array($atype, $arctypes) )
		{
			if($id1 = db_query("insert into custom_skins (show_name, owner_type, anbieter, version) values ('$skinname', 'reseller', '$PHP_AUTH_USER', 'xp30')"))
			{
				$skin_id = db_insert_id($id1, "sec_custom_skins");
				//echo  "$sbindir/$stylescript --skin skin_$skin_id --new_skin --use_arc " . basename($HTTP_POST_FILES["zipfile"]["tmp_name"]) . " --arc_type $atype";

				exec( "$sbindir/$stylescript --skin skin_$skin_id --new_skin --use_arc " . basename($HTTP_POST_FILES["zipfile"]["tmp_name"]) . " --arc_type $atype", $out, $ret);
				//print_r($out);
				
				if($ret != 0)
				{
					$alerts[] = ltext('sk_cant_unpack', array(implode("\n", $out)));
					db_query("delete from custom_skins where id=$skin_id");
					include $thisdir . "/skins_inc/editskins.php";
				}
				else 
				{
					db_query("update custom_skins set path = '/skins/skin_$skin_id' where id='$skin_id'");
					include $thisdir . "/skins_inc/editskins.php";
//					include ( $thisdir . "/se_start.php");
					exit();
				}
				
			}
			else
			{
				$alerts[] = ltext('sk_system_error', array("Can not insert new record to database"));
				include $thisdir . "/skins_inc/editskins.php";
			}
		}
		else 
		{
			$alerts[] = ltext('sk_bad_arctype');
			include $thisdir . "/skins_inc/editskins.php";
		}
	}
}
else
{
	$alerts[] = ltext("sk_empty_skinname");
	include $thisdir . "/skins_inc/editskins.php";
}


?>
