<?php


require_once("syncinclude.php");

$return=3;
if (auth())
{
	if (intval($_POST["action"]) == 1 && intval($_POST['KeyEigenschaft']))
	{		
		$Eigenschaft->kEigenschaft = intval($_POST["KeyEigenschaft"]);
		$Eigenschaft->kArtikel = intval($_POST["KeyArtikel"]);
		$Eigenschaft->cName = realEscape($_POST["Name"]);

		//hole items_id
		$items_id = getFremdArtikel($Eigenschaft->kArtikel);
		if ($items_id>0)
		{
			//hole einstellungen
			$cur_query = eS_execute_query("select languages_id from eazysales_einstellungen");
			$einstellungen = go_db_fetch_object($cur_query);
			
			//hol items_options_id
			$cur_query = eS_execute_query("select items_options_id from items_options where language_id=".$einstellungen->languages_id." and items_options_name=\"$Eigenschaft->cName\"");
			$options_id = go_db_fetch_object($cur_query);
			if (!$options_id->items_options_id)
			{
				//erstelle eigenschaft
				//hole max PK
				$cur_query = eS_execute_query("select max(items_options_id) from items_options");
				$max_id_arr = go_db_fetch_row($cur_query);
				$options_id->items_options_id = $max_id_arr[0]+1;
				eS_execute_query("insert into items_options (items_options_id,language_id,items_options_name) values ($options_id->items_options_id,$einstellungen->languages_id,\"$Eigenschaft->cName\")");
				
				//erstelle leere description f�r alle anderen Sprachen
				$sonstigeSprachen = getSonstigeSprachen($einstellungen->languages_id);
				if (is_array($sonstigeSprachen))
				{
					foreach ($sonstigeSprachen as $sonstigeSprache)
					{
						eS_execute_query("insert into items_options (items_options_id,language_id,items_options_name) values ($options_id->items_options_id,$sonstigeSprache,\"$Eigenschaft->cName\")");
					}
				}
			}
			//mapping zu variation 
			setMappingEigenschaft($Eigenschaft->kEigenschaft,$options_id->items_options_id,$Eigenschaft->kArtikel);
			$return = 0;
		}
 	}
	else
		$return=5;
}

echo($return);
logge($return);
?>