<?php


require_once("syncinclude.php");

$return=3;
if (auth())
{
	if (intval($_POST["action"]) == 1 && intval($_POST['KeyAttribut']))
	{
		$return = 0;
		
		$Attribut->items_id = getFremdArtikel(intval($_POST["KeyArtikel"]));
		$Attribut->name = $_POST["Name"];
		$Attribut->content = $_POST["StringWert"];
		if (strlen($_POST["TextWert"])>0)
			$Attribut->content = $_POST["TextWert"];
		attributBearbeiten ($Attribut);
	}
}

echo($return);
logge($return);

//Attribut wird verarbeitet / in DB insertet
function attributBearbeiten ($Attribut)
{
	if ($Attribut->items_id>0)
	{
		//hole einstellungen
		$cur_query = eS_execute_query("select * from eazysales_einstellungen");
		$einstellungen = go_db_fetch_object($cur_query);
		
		switch (strtolower($Attribut->name))
		{
			case 'produktstatus':
				if ($Attribut->content==0 || $Attribut->content==1)
					eS_execute_query("update items set items_status=".$Attribut->content." where items_id=".$Attribut->items_id);
				break;
			//
			//Sonderangebote BEGIN
			//
			case 'sonder_preis':
				if ($Attribut->content>0)
				{
					//umrechnen auf Netto
					//hol steuerklasse zum produkt
					$cur_query = eS_execute_query("select items_tax_class_id from items where items_id=".$Attribut->items_id);
					$items_tax_arr = go_db_fetch_row($cur_query);
					$tax = get_tax($items_tax_arr[0], $einstellungen->tax_zone_id);
					if ($tax>0)
					{
						$Attribut->content = $Attribut->content/(($tax+100)/100.0);
					}
					eS_execute_query("update specials set specials_new_items_price=\"".$Attribut->content."\" where items_id=".$Attribut->items_id);
				}
				break;
			case 'sonder_enddatum':
				if ($Attribut->content)
				{
					list ($tag,$monat,$jahr)= preg_split('/\./',$Attribut->content);
					$date = $jahr."-".$monat."-".$tag." 00:00:00";
					eS_execute_query("update specials set expires_date=\"".realEscape($date)."\" where items_id=".$Attribut->items_id);
				}
				break;
			case 'sonder_aktiv':
				if ($Attribut->content==0 || $Attribut->content==1)
				{
					eS_execute_query("update specials set status=".$Attribut->content.", date_status_change=now(), specials_last_modified=now()  where items_id=".$Attribut->items_id);
				}
				break;
			//
			//Sonderangebote END
			//
			default:
				if ($Attribut->content && ES_ATTRIBUTE_AN_BESCHREIBUNG_ANHAENGEN==1)
				{
					//an description anh�ngen
					$cur_query = eS_execute_query("select items_description from items_description where items_id=".$Attribut->items_id." and language_id=".$einstellungen->languages_id);
					$item_desc = go_db_fetch_row($cur_query);
					$desc = $item_desc[0]."<br><br><b>".$Attribut->name."</b>: ".$Attribut->content;
					eS_execute_query("update items_description set items_description=\"".$desc."\" where items_id=".$Attribut->items_id." and language_id=".$einstellungen->languages_id);
				}
				break;
		}
	}
}
?>
