<?
$result = $GLOBALS['db']->query("select name,id from ecmprices where deleted='0'");

$ile=mysql_num_rows($result);
for($i=0;$i<$ile;$i++)
{
	if($_REQUEST['check'][$i])
	{
		$w=$GLOBALS['db']->query("select id from ecmprices_ecmproducts where ecmprice_id='".$_REQUEST['pricebook_id'][$i]."' and ecmproduct_id='".$_REQUEST['product_id']."'");
		if(mysql_num_rows($w)==0)
		{
			$GLOBALS['db']->query("insert into ecmprices_ecmproducts(id,ecmprice_id,ecmproduct_id,deleted,price,created_by,date_entered,date_modified,modified_user_id) values('".create_guid()."','".$_REQUEST['pricebook_id'][$i]."','".$_REQUEST['product_id']."','0','".$_REQUEST['list_price_'.$_REQUEST['pricebook_id'][$i]]."','".$_SESSION['authenticated_user_id']."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."','".$_SESSION['authenticated_user_id']."')");
		}
		else
		{
			$z="update ecmprices_ecmproducts set price='".$_REQUEST['list_price_'.$_REQUEST['pricebook_id'][$i]]."' where ecmprice_id='".$_REQUEST['pricebook_id'][$i]."' and ecmproduct_id='".$_REQUEST['product_id']."'";
			//print $z;
			$GLOBALS['db']->query($z);
		}
	}
}
header("Location: index.php?module=".$_REQUEST['return_module']."&action=".$_REQUEST['return_action']."&record=".$_REQUEST['return_id']);
?>