<?php

if(count($_POST)>0){
	$product = ProductData::getById($_POST["product_id"]);

	$product->barcode = $_POST["barcode"];
	$product->name = $_POST["name"];
	$product->price_in = $_POST["price_in"];
	$product->price_out = $_POST["price_out"];

  $product->description = $_POST["description"];
  $product->inventary_min = $_POST["inventary_min"];
  $product->is_favorite = isset($_POST["is_favorite"])?1:0;
$product->use_ingredients = isset($_POST["use_ingredients"])?1:0;
$product->use_inventory = isset($_POST["use_inventory"])?1:0;


  $is_active=0;
  if(isset($_POST["is_active"])){ $is_active=1;}

  $product->is_active=$is_active;

  $product->unit_id= $_POST["unit_id"]!=""?$_POST["unit_id"]:"NULL";
  $product->presentation_id= $_POST["presentation_id"]!=""?$_POST["presentation_id"]:"NULL";
  $product->category2_id= $_POST["category2_id"]!=""?$_POST["category2_id"]:"NULL";

	$product->user_id = $_SESSION["user_id"];
	$product->update();

	if(isset($_FILES["image"])){
		$image = new Upload($_FILES["image"]);
		if($image->uploaded){
			$image->Process("storage/products/");
			if($image->processed){
				$product->image = $image->file_dst_name;
				$product->update_image();
			}
		}
	}

	setcookie("prdupd","true");
	print "<script>window.location='index.php?view=ingredients';</script>";


}


?>