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

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

if($skinname)
{
	$skinname = str_replace("'", "\\'", $skinname);
	
	$id = db_query("select count(*) as c from custom_skins where show_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
	{
		settype($skin, "integer");
		//echo "SELECT name, owner_type FROM custom_skins WHERE id = $skin and ( owner_type = 'preinstalled' or ( owner_type = 'reseller' and anbieter='$PHP_AUTH_USER' ) )";
		$id = db_query("SELECT name, owner_type, version FROM custom_skins WHERE (id = $skin and ( owner_type = 'preinstalled' or ( owner_type = 'reseller' and anbieter='$PHP_AUTH_USER' )) )");
		if(db_num_rows($id))
		{
			$row = db_fetch_array($id);
			if($id1 = db_query("insert into custom_skins (show_name, owner_type, anbieter, version) values ('$skinname', 'reseller', '$PHP_AUTH_USER', '{$row['version']}')"))
			{
				$skin_id = db_insert_id($id1, "sec_custom_skins");
				$wer = db_fetch_array($id);
				//var_dump($wer);
				if($wer["owner_type"] == "preinstalled")
				{
					$useskin = $wer["name"];
				}
				else
				{
					$useskin = "skin_" . $skin;
				}
//				echo("<p>$sbindir/$stylescript --skin skin_$skin_id --new_skin --use_dir $useskin</p>");
				exec("$sbindir/$stylescript --skin skin_$skin_id --new_skin --use_dir $useskin", $out, $ret);
				if($ret != 0)
				{
					$alerts[] = ltext('sk_system_error', 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");
					exit();
				}
				
			}
			else
			{
				$alerts[] = ltext('sk_system_error', array("Can not insert new record into the database"));
				include $thisdir . "/skins_inc/editskins.php";
			}
		}
		else
		{
			$alerts[] = ltext('sk_invalid_skin');
			include $thisdir . "/skins_inc/editskins.php";
		}
		
	}
}
else
{
	$alerts[] = ltext("sk_empty_skinname");
	include $thisdir . "/skins_inc/editskins.php";
}


//$skin_id = db_query("insert into custom_skins (name, owner_type, anbieter)");

?>
