<?
/*
	SHIPMENTFEE-HEZ RENDELT ID-TÍPUSOK:
	===================================
	g = csoport (város/csoport) alap
	x = város extra (kézzel beírt utca)
	i = egyed (utca/város)
*/

class property_shipmentfee {

function property_shipmentfee() {
}

function getShipmentfeeList() {
	global $dbi;
	$prev=0;
	$sql="select id,property_value_to,fee_value from property_shipment_fee order by property_value_to";
	$res=sql_query($sql,$dbi);
	while($a=sql_fetch_assoc($res,$dbi)) {

		$a[property_value_from]=$prev.',1';
		$prev=$a[property_value_to];
		
		if($a[property_value_to]==999999) $a[property_value_to]='inf';
		
		$data[]=$a;
	}
	return $data;
}

function getShipmentFee($property_value) {
	global $dbi;
	$sql="select fee_value from property_shipment_fee where property_value_to>='$property_value' order by property_value_to limit 1";
	$res=sql_query($sql,$dbi);
	list($fee)=sql_fetch_row($res,$dbi);
	return $fee;
}

function saveNewShipmentfee($post) {
	global $dbi;
	if(!($post[property_value_to]>0)) $post[property_value_to]=999999;
	$sql="insert into property_shipment_fee (property_value_to,fee_value) values ('$post[property_value_to]','$post[fee_value]')";
	$res=sql_query($sql,$dbi);
}
function updateShipmentfee($id,$field,$value) {
	global $dbi;
	if($field=='property_value_to' && !($value>0)) $value=999999;
	$sql="update property_shipment_fee set $field='$value' where id='$id'";
	$res=sql_query($sql,$dbi);
}
function deleteShipmentfee($id) {
	global $dbi;
	$sql="delete from property_shipment_fee where id='$id'";
	$res=sql_query($sql,$dbi);
	$sql="alter table property_shipment_fee auto_increment=1";
	$res=sql_query($sql,$dbi);
}

}
?>