<?php


class Lib_Product
{
	public function leadtime($id,$fid = 0,$bid = 0) 
	{	
		$db = Zend_Registry::get('db');
		$wynik = 0;
		
		$fid = (int)$fid;
		$bid = (int)$bid;
		
		if( $fid == null ) $fid = 0;
		if( $bid == null ) $bid = 0;
		
		$ask = "
		SELECT 
		
		p.product_id AS product_id, 
		
		(SELECT color_schema_product_body_lead_time FROM color_schema_product_body cspb WHERE cspb.color_schema_product_body_id = pb.color_schema_product_body_id) AS lead_time_b,
		
		(SELECT color_schema_product_front_lead_time FROM color_schema_product_front cspb WHERE cspb.color_schema_product_front_id = pf.color_schema_product_front_id) AS lead_time_f
		
		FROM product p 
		LEFT JOIN product_front pf ON p.product_id = pf.product_id
		LEFT JOIN product_body pb ON p.product_id = pb.product_id
		
		WHERE
			p.product_id = $id
		AND
			pb.product_body_id = $bid
		AND
			pf.product_front_id = $fid
		LIMIT 1
		";
		
		$dRow = $db->query($ask)->fetchAll();
		$dRow = $dRow[0];

	//	echo'<hr />';
		
		if( $dRow['lead_time_b'] > $wynik ) $wynik = $dRow['lead_time_b'];
		if( $dRow['lead_time_f'] > $wynik ) $wynik = $dRow['lead_time_f'];
		
    	return $wynik;
	} 
	
	
	
	public function mapbody($row) 
	{	
		$wynik = '';
		
		for( $i=1; $i<=8; $i++ ){
			if( $row['map_filtr_body_option'.$i] == 1 ){
				if( $wynik == '' ){
					$wynik = $i;
				}else{
					$wynik = $wynik.','.$i;
				}
			}
		}
	
    	return $wynik;
	} 
	
	
	
	public function mapfront($row) 
	{	
		$wynik = '';
		
		for( $i=1; $i<=15; $i++ ){
			if( $row['map_filtr_front_option'.$i] == 1 ){
				if( $wynik == '' ){
					$wynik = $i;
				}else{
					$wynik = $wynik.','.$i;
				}
			}
		}
	
    	return $wynik;
	} 
	
	/*
	<?php if($val['product_body_type']==0)echo' pm';else echo' pa';?><?php if($val['product_body_option1']==1)echo' option1';?><?php if($val['product_body_option2']==1)echo' option2';?><?php if($val['product_body_option3']==1)echo' option3';?><?php if($val['product_body_option4']==1)echo' option4';?><?php if($val['product_body_option5']==1)echo' option5';?><?php if($val['product_body_option6']==1)echo' option6';?>
	*/
	
	public function mapproductbody($row) 
	{	
		$wynik = 'typ'.$row['product_body_type'].',';
		
		for( $i=1; $i<=8; $i++ ){
			if( $row['product_body_option'.$i] == 1 ){
				$wynik = $wynik.'opt'.$i.',';
			}
		}
	
    	return $wynik;
	} 
	
	/*
	<?php if($val['product_front_type']==0)echo' fpm';else if($val['product_front_type']==1) echo' fpa';else if($val['product_front_type']==2) echo' ffl';else echo' fpmp';?><?php if($val['product_front_option1']==1)echo' foption1';?><?php if($val['product_front_option2']==1)echo' foption2';?><?php if($val['product_front_option3']==1)echo' foption3';?><?php if($val['product_front_option4']==1)echo' foption4';?><?php if($val['product_front_option5']==1)echo' foption5';?><?php if($val['product_front_option6']==1)echo' foption6';?>
	*/
	
	public function mapproductfront($row) 
	{	
		$wynik = 'fyp'.$row['product_front_type'].',';
		
		for( $i=1; $i<=15; $i++ ){
			if( $row['product_front_option'.$i] == 1 ){
				$wynik = $wynik.'fpt'.$i.',';
			}
		}
	
    	return $wynik;
	} 
	
	public function mapproductfront2($row) 
	{	
		$wynik = 'fyp'.$row['product_front_2_type'].',';
		
		for( $i=1; $i<=15; $i++ ){
			if( $row['product_front_2_option'.$i] == 1 ){
				$wynik = $wynik.'fpt'.$i.',';
			}
		}
	
    	return $wynik;
	} 
	
}

