<?php


class Lib_Color
{







	public function updateColorType($idColor){

		$db = Zend_Registry::get('db');
		$schemaName = 'type2';
		$Product_E = new ProductType2();			
		$vv = new ColorSchemaProductType2();	
			
		$select = $vv->select();	
		$select->where('color_schema_product_'.$schemaName.'_id = ?', $idColor);	
		$v = $vv->fetchRow($select);
			
		$data = array(
			'product_'.$schemaName.'_name' => $v['color_schema_product_'.$schemaName.'_name'],
			'product_'.$schemaName.'_code' => $v['color_schema_product_'.$schemaName.'_code'],
			'product_'.$schemaName.'_image' => $v['color_schema_product_'.$schemaName.'_image'],
			'product_'.$schemaName.'_price' => $v['color_schema_product_'.$schemaName.'_price'],
			'product_'.$schemaName.'_default' => $v['color_schema_product_'.$schemaName.'_default']
		);
		$Product_E->update($data, 'color_schema_product_'.$schemaName.'_id='.$idColor);
					
				
		$Lang = new Lang();
		$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
		foreach( $dataLang as $k => $val ){
			
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$idColor."'";
			$dataLangRow = $db->query($zap)->fetchAll();
			$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$idColor."'";
			$dataLangRow2 = $db->query($zap)->fetchAll();

			$dataProduct = $Product_E->fetchAll('color_schema_product_'.$schemaName.'_id = '.$idColor);
						
			foreach( $dataProduct as $kk => $vv ){	

				$idProduct = $vv['product_'.$schemaName.'_id'];
				if( isset($dataLangRow[0]) ){			
					$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow[0]['language_value']."' WHERE language_variable LIKE 'product_".$schemaName."name_".$idProduct."' AND language_panel LIKE 'product'";
					$db->query($zap);
				}	
					
				if( isset($dataLangRow2[0]) ){			
					$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow2[0]['language_value']."' WHERE language_variable LIKE 'product_".$schemaName."description_".$idProduct."' AND language_panel LIKE 'product'";
					$db->query($zap);
				}
			}
			
		}

	}


	public function updateColor($idschema, $idColor){
		
		$db = Zend_Registry::get('db');
		$ColorSchema = new ColorSchema();
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $idschema);	
		$rowColorSchema = $ColorSchema->fetchRow($select);
	
	
	
	
	
	
	
	
	
		
		if( $rowColorSchema['color_schema_type'] == 0 ){
	
			$ProductBody = new ProductBody();
			$vv = new ColorSchemaProductBody();	
			$select = $vv->select();	
			$select->where('color_schema_product_body_id = ?', $idColor);	
			$v = $vv->fetchRow($select);
			
			$data = array(
				'product_body_typebody' => $v['color_schema_product_body_typebody'],
				'product_body_option1' => $v['color_schema_product_body_option1'],
				'product_body_option2' => $v['color_schema_product_body_option2'],
				'product_body_option3' => $v['color_schema_product_body_option3'],
				'product_body_option4' => $v['color_schema_product_body_option4'],
				'product_body_option5' => $v['color_schema_product_body_option5'],
				'product_body_option6' => $v['color_schema_product_body_option6'],
				'product_body_option7' => $v['color_schema_product_body_option7'],
				'product_body_option8' => $v['color_schema_product_body_option8'],
				'product_body_name' => $v['color_schema_product_body_name'],
				'product_body_code' => $v['color_schema_product_body_code'],
				'product_body_type' => $v['color_schema_product_body_type'],
				'product_body_image' => $v['color_schema_product_body_image'],
				'product_body_price' => $v['color_schema_product_body_price'],
				'product_body_default' => $v['color_schema_product_body_default']
			);
			$ProductBody->update($data, 'color_schema_product_body_id='.$idColor);
					
				
			$Lang = new Lang();
			$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
			foreach( $dataLang as $k => $val ){
			
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_bodyname_".$idColor."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_bodydescription_".$idColor."'";
				$dataLangRow2 = $db->query($zap)->fetchAll();
						
						
				$dataProduct = $ProductBody->fetchAll('color_schema_product_body_id = '.$idColor);
						
				foreach( $dataProduct as $kk => $vv ){	

					$idProduct = $vv['product_body_id'];
					if( isset($dataLangRow[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow[0]['language_value']."' WHERE language_variable LIKE 'product_bodyname_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}	
					
					if( isset($dataLangRow2[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow2[0]['language_value']."' WHERE language_variable LIKE 'product_bodydescription_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}
				}
				
				
				unset($dataLangRow);
				unset($dataLangRow2);
			}
			
		}
		
		
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 1 ){
	
			$ProductFront = new ProductFront();
			
			$vv = new ColorSchemaProductFront();	
			$select = $vv->select();	
			$select->where('color_schema_product_front_id = ?', $idColor);	
			$v = $vv->fetchRow($select);
			
			$data = array(
				'product_front_option1' => $v['color_schema_product_front_option1'],
				'product_front_option2' => $v['color_schema_product_front_option2'],
				'product_front_option3' => $v['color_schema_product_front_option3'],
				'product_front_option4' => $v['color_schema_product_front_option4'],
				'product_front_option5' => $v['color_schema_product_front_option5'],
				'product_front_option6' => $v['color_schema_product_front_option6'],
				'product_front_option7' => $v['color_schema_product_front_option7'],
				'product_front_option8' => $v['color_schema_product_front_option8'],
				'product_front_option9' => $v['color_schema_product_front_option9'],
				'product_front_option10' => $v['color_schema_product_front_option10'],
				'product_front_option11' => $v['color_schema_product_front_option11'],
				'product_front_option12' => $v['color_schema_product_front_option12'],
				'product_front_option13' => $v['color_schema_product_front_option13'],
				'product_front_option14' => $v['color_schema_product_front_option14'],
				'product_front_option15' => $v['color_schema_product_front_option15'],
				'product_front_name' => $v['color_schema_product_front_name'],
				'product_front_code' => $v['color_schema_product_front_code'],
				'product_front_type' => $v['color_schema_product_front_type'],
				'product_front_type_2' => $v['color_schema_product_front_type_2'],
				'product_front_image' => $v['color_schema_product_front_image'],
				'product_front_price' => $v['color_schema_product_front_price'],
				'product_front_default' => $v['color_schema_product_front_default']
			);
			$ProductFront->update($data, 'color_schema_product_front_id='.$idColor);
					
				
			$Lang = new Lang();
			$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
			foreach( $dataLang as $k => $val ){
			
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontname_".$idColor."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontdescription_".$idColor."'";
				$dataLangRow2 = $db->query($zap)->fetchAll();
						
						
				$dataProduct = $ProductFront->fetchAll('color_schema_product_front_id = '.$idColor);
						
				foreach( $dataProduct as $kk => $vv ){	

					$idProduct = $vv['product_front_id'];
					if( isset($dataLangRow[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow[0]['language_value']."' WHERE language_variable LIKE 'product_frontname_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}	
					
					if( isset($dataLangRow2[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow2[0]['language_value']."' WHERE language_variable LIKE 'product_frontdescription_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}
				}
				
				
				unset($dataLangRow);
				unset($dataLangRow2);
			}
		
		}
		
		
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 2 ){
	
			$schemaName = 'type';
			$Product_E = new ProductType();			
			$vv = new ColorSchemaProductType();	
			
			$select = $vv->select();	
			$select->where('color_schema_product_'.$schemaName.'_id = ?', $idColor);	
			$v = $vv->fetchRow($select);
			
			$data = array(
				'product_'.$schemaName.'_name' => $v['color_schema_product_'.$schemaName.'_name'],
				'product_'.$schemaName.'_code' => $v['color_schema_product_'.$schemaName.'_code'],
		//		'product_'.$schemaName.'_type' => $v['color_schema_product_'.$schemaName.'_type'],
				'product_'.$schemaName.'_image' => $v['color_schema_product_'.$schemaName.'_image'],
				'product_'.$schemaName.'_price' => $v['color_schema_product_'.$schemaName.'_price'],
				'product_'.$schemaName.'_default' => $v['color_schema_product_'.$schemaName.'_default']
			);
			$Product_E->update($data, 'color_schema_product_'.$schemaName.'_id='.$idColor);
					
				
			$Lang = new Lang();
			$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
			foreach( $dataLang as $k => $val ){
			
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$idColor."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$idColor."'";
				$dataLangRow2 = $db->query($zap)->fetchAll();
						
						
				$dataProduct = $Product_E->fetchAll('color_schema_product_'.$schemaName.'_id = '.$idColor);
						
				foreach( $dataProduct as $kk => $vv ){	

					$idProduct = $vv['product_'.$schemaName.'_id'];
					if( isset($dataLangRow[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow[0]['language_value']."' WHERE language_variable LIKE 'product_".$schemaName."name_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}	
					
					if( isset($dataLangRow2[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow2[0]['language_value']."' WHERE language_variable LIKE 'product_".$schemaName."description_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}
				}
				
				
				unset($dataLangRow);
				unset($dataLangRow2);
			}
		
		}
		
		
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 3 ){
	
			$schemaName = 'handles';
			$Product_E = new ProductHandles();			
			$vv = new ColorSchemaProductHandles();	
			
			$select = $vv->select();	
			$select->where('color_schema_product_'.$schemaName.'_id = ?', $idColor);	
			$v = $vv->fetchRow($select);
			
			$data = array(
				'product_'.$schemaName.'_name' => $v['color_schema_product_'.$schemaName.'_name'],
				'product_'.$schemaName.'_code' => $v['color_schema_product_'.$schemaName.'_code'],
				'product_'.$schemaName.'_type'.$schemaName => $v['color_schema_product_'.$schemaName.'_type'],
				'product_'.$schemaName.'_image' => $v['color_schema_product_'.$schemaName.'_image'],
				'product_'.$schemaName.'_price' => $v['color_schema_product_'.$schemaName.'_price'],
				'product_'.$schemaName.'_default' => $v['color_schema_product_'.$schemaName.'_default']
			);
			$Product_E->update($data, 'color_schema_product_'.$schemaName.'_id='.$idColor);
					
				
			$Lang = new Lang();
			$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
			foreach( $dataLang as $k => $val ){
			
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$idColor."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$idColor."'";
				$dataLangRow2 = $db->query($zap)->fetchAll();
						
						
				$dataProduct = $Product_E->fetchAll('color_schema_product_'.$schemaName.'_id = '.$idColor);
						
				foreach( $dataProduct as $kk => $vv ){	

					$idProduct = $vv['product_'.$schemaName.'_id'];
					if( isset($dataLangRow[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow[0]['language_value']."' WHERE language_variable LIKE 'product_".$schemaName."name_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}	
					
					if( isset($dataLangRow2[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow2[0]['language_value']."' WHERE language_variable LIKE 'product_".$schemaName."description_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}
				}
				
				
				unset($dataLangRow);
				unset($dataLangRow2);
			}
		
		}
		
		
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 4 ){
	
			$schemaName = 'accessories';
			$Product_E = new ProductAccessories();			
			$vv = new ColorSchemaProductAccessories();	
			
			$select = $vv->select();	
			$select->where('color_schema_product_'.$schemaName.'_id = ?', $idColor);	
			$v = $vv->fetchRow($select);
			
			$data = array(
				'product_'.$schemaName.'_name' => $v['color_schema_product_'.$schemaName.'_name'],
				'product_'.$schemaName.'_code' => $v['color_schema_product_'.$schemaName.'_code'],
				'product_'.$schemaName.'_type'.$schemaName => $v['color_schema_product_'.$schemaName.'_type'],
				'product_'.$schemaName.'_image' => $v['color_schema_product_'.$schemaName.'_image'],
				'product_'.$schemaName.'_price' => $v['color_schema_product_'.$schemaName.'_price'],
				'product_'.$schemaName.'_default' => $v['color_schema_product_'.$schemaName.'_default']
			);
			$Product_E->update($data, 'color_schema_product_'.$schemaName.'_id='.$idColor);
					
				
			$Lang = new Lang();
			$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
			foreach( $dataLang as $k => $val ){
			
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$idColor."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$idColor."'";
				$dataLangRow2 = $db->query($zap)->fetchAll();
						
						
				$dataProduct = $Product_E->fetchAll('color_schema_product_'.$schemaName.'_id = '.$idColor);
						
				foreach( $dataProduct as $kk => $vv ){	

					$idProduct = $vv['product_'.$schemaName.'_id'];
					if( isset($dataLangRow[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow[0]['language_value']."' WHERE language_variable LIKE 'product_".$schemaName."name_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}	
					
					if( isset($dataLangRow2[0]) ){			
						$zap = "UPDATE `lang_".$val['lang_suffix']."` SET language_value = '".$dataLangRow2[0]['language_value']."' WHERE language_variable LIKE 'product_".$schemaName."description_".$idProduct."' AND language_panel LIKE 'product'";
						$db->query($zap);
					}
				}
				
				
				unset($dataLangRow);
				unset($dataLangRow2);
			}
		
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function addColor($idproduct,$idschema,$front2=0){
		
		$db = Zend_Registry::get('db');
		$ColorSchema = new ColorSchema();
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $idschema);	
		$rowColorSchema = $ColorSchema->fetchRow($select);
	
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 0 AND $front2 == 0 ){
	
			$ProductBody = new ProductBody();
			$ColorSchemaProduct = new ColorSchemaProductBody();	
			$dd = $ColorSchemaProduct->fetchAll('color_schema_id = '.$idschema);
			
			foreach( $dd as $key => $v ){
			
				$data = array(
					'product_id' => $idproduct,
					'product_body_typebody' => $v['color_schema_product_body_typebody'],
					'product_body_option1' => $v['color_schema_product_body_option1'],
					'product_body_option2' => $v['color_schema_product_body_option2'],
					'product_body_option3' => $v['color_schema_product_body_option3'],
					'product_body_option4' => $v['color_schema_product_body_option4'],
					'product_body_option5' => $v['color_schema_product_body_option5'],
					'product_body_option6' => $v['color_schema_product_body_option6'],
					'product_body_option7' => $v['color_schema_product_body_option7'],
					'product_body_option8' => $v['color_schema_product_body_option8'],
					'product_body_name' => $v['color_schema_product_body_name'],
					'product_body_code' => $v['color_schema_product_body_code'],
					'product_body_type' => $v['color_schema_product_body_type'],
					'product_body_image' => $v['color_schema_product_body_image'],
					'product_body_price' => $v['color_schema_product_body_price'],
					'product_body_default' => $v['color_schema_product_body_default'],
					'color_schema_product_body_id' => $v['color_schema_product_body_id'],
					'color_schema_id' => $idschema
				);
				$idIns = $ProductBody->insert($data);
				
				$Lang = new Lang();
				$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
				foreach( $dataLang as $k => $val ){
				
					$idColor = $v['color_schema_product_body_id'];
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_bodyname_".$idColor."'";
					$dataLangRow = $db->query($zap)->fetchAll();
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_bodydescription_".$idColor."'";
					$dataLangRow2 = $db->query($zap)->fetchAll();
					
					if( isset($dataLangRow[0]) ){			
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_bodyname_".$idIns."', '".$dataLangRow[0]['language_value']."');";
						$db->query($zap);
					}
					
					if( isset($dataLangRow2[0]) ){				
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_bodydescription_".$idIns."', '".$dataLangRow2[0]['language_value']."');";
						$db->query($zap);
					}

				}
					
			
			}
	
		}
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 1 ){
		
			$ProductFront = new ProductFront();
			$ColorSchemaProduct = new ColorSchemaProductFront();	
			$dd = $ColorSchemaProduct->fetchAll('color_schema_id = '.$idschema);
			
			foreach( $dd as $key => $v ){
		
				$data = array(
					'product_id' => $idproduct,
					'product_front_option1' => $v['color_schema_product_front_option1'],
					'product_front_option2' => $v['color_schema_product_front_option2'],
					'product_front_option3' => $v['color_schema_product_front_option3'],
					'product_front_option4' => $v['color_schema_product_front_option4'],
					'product_front_option5' => $v['color_schema_product_front_option5'],
					'product_front_option6' => $v['color_schema_product_front_option6'],
					'product_front_option7' => $v['color_schema_product_front_option7'],
					'product_front_option8' => $v['color_schema_product_front_option8'],
					'product_front_option9' => $v['color_schema_product_front_option9'],
					'product_front_option10' => $v['color_schema_product_front_option10'],
					'product_front_option11' => $v['color_schema_product_front_option11'],
					'product_front_option12' => $v['color_schema_product_front_option12'],
					'product_front_option13' => $v['color_schema_product_front_option13'],
					'product_front_option14' => $v['color_schema_product_front_option14'],
					'product_front_option15' => $v['color_schema_product_front_option15'],
					'product_front_name' => $v['color_schema_product_front_name'],
					'product_front_code' => $v['color_schema_product_front_code'],
					'product_front_type' => $v['color_schema_product_front_type'],
					'product_front_type_2' => $v['color_schema_product_front_type_2'],
					'product_front_image' => $v['color_schema_product_front_image'],
					'product_front_price' => $v['color_schema_product_front_price'],
					'product_front_default' => $v['color_schema_product_front_default'],
					'color_schema_product_front_id' => $v['color_schema_product_front_id'],
					'color_schema_id' => $idschema
				);
				$idIns = $ProductFront->insert($data);
				
				$Lang = new Lang();
				$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
				foreach( $dataLang as $k => $val ){
					$idColor = $v['color_schema_product_front_id'];
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontname_".$idColor."'";
					$dataLangRow = $db->query($zap)->fetchAll();
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontdescription_".$idColor."'";
					$dataLangRow2 = $db->query($zap)->fetchAll();
					
					if( isset($dataLangRow[0]) ){			
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_frontname_".$idIns."', '".$dataLangRow[0]['language_value']."');";
						$db->query($zap);
					}
					
					if( isset($dataLangRow2[0]) ){				
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_frontdescription_".$idIns."', '".$dataLangRow2[0]['language_value']."');";
						$db->query($zap);
					}
				}
					
			
			}
			
		}
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 2 ){
		
			$schemaName = 'type';
			$Product_E = new ProductType();
			$ColorSchemaProduct = new ColorSchemaProductType();
			
			$dd = $ColorSchemaProduct->fetchAll('color_schema_id = '.$idschema);
			
			foreach( $dd as $key => $v ){
		
				$data = array(
					'product_id' => $idproduct,
					'product_'.$schemaName.'_name' => $v['color_schema_product_'.$schemaName.'_name'],
					'product_'.$schemaName.'_code' => $v['color_schema_product_'.$schemaName.'_code'],
			//		'product_'.$schemaName.'_type' => $v['color_schema_product_'.$schemaName.'_type'],
					'product_'.$schemaName.'_image' => $v['color_schema_product_'.$schemaName.'_image'],
					'product_'.$schemaName.'_price' => $v['color_schema_product_'.$schemaName.'_price'],
					'product_'.$schemaName.'_default' => $v['color_schema_product_'.$schemaName.'_default'],
					'color_schema_product_'.$schemaName.'_id' => $v['color_schema_product_'.$schemaName.'_id'],
					'color_schema_id' => $idschema
				);
				$idIns = $Product_E->insert($data);
				
				$Lang = new Lang();
				$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
				foreach( $dataLang as $k => $val ){
					$idColor = $v['color_schema_product_'.$schemaName.'_id'];
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$idColor."'";
					$dataLangRow = $db->query($zap)->fetchAll();
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$idColor."'";
					$dataLangRow2 = $db->query($zap)->fetchAll();
					
					if( isset($dataLangRow[0]) ){			
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_".$schemaName."name_".$idIns."', '".$dataLangRow[0]['language_value']."');";
						$db->query($zap);
					}
					
					if( isset($dataLangRow2[0]) ){				
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_".$schemaName."description_".$idIns."', '".$dataLangRow2[0]['language_value']."');";
						$db->query($zap);
					}
				}
				
				
				$this->addColorType2($idIns,$v['color_schema_product_'.$schemaName.'_id'],$idschema);
				
				
					
			
			}
			
		}
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 3 ){
		
			$schemaName = 'handles';
			$Product_E = new ProductHandles();
			$ColorSchemaProduct = new ColorSchemaProductHandles();
			
			$dd = $ColorSchemaProduct->fetchAll('color_schema_id = '.$idschema);
			
			foreach( $dd as $key => $v ){
		
				$data = array(
					'product_id' => $idproduct,
					'product_'.$schemaName.'_name' => $v['color_schema_product_'.$schemaName.'_name'],
					'product_'.$schemaName.'_code' => $v['color_schema_product_'.$schemaName.'_code'],
					'product_'.$schemaName.'_type'.$schemaName.'' => $v['color_schema_product_'.$schemaName.'_type'],
					'product_'.$schemaName.'_image' => $v['color_schema_product_'.$schemaName.'_image'],
					'product_'.$schemaName.'_price' => $v['color_schema_product_'.$schemaName.'_price'],
					'product_'.$schemaName.'_default' => $v['color_schema_product_'.$schemaName.'_default'],
					'color_schema_product_'.$schemaName.'_id' => $v['color_schema_product_'.$schemaName.'_id'],
					'color_schema_id' => $idschema
				);
				$idIns = $Product_E->insert($data);
				
				$Lang = new Lang();
				$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
				foreach( $dataLang as $k => $val ){
					$idColor = $v['color_schema_product_'.$schemaName.'_id'];
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$idColor."'";
					$dataLangRow = $db->query($zap)->fetchAll();
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$idColor."'";
					$dataLangRow2 = $db->query($zap)->fetchAll();
					
					if( isset($dataLangRow[0]) ){			
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_".$schemaName."name_".$idIns."', '".$dataLangRow[0]['language_value']."');";
						$db->query($zap);
					}
					
					if( isset($dataLangRow2[0]) ){				
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_".$schemaName."description_".$idIns."', '".$dataLangRow2[0]['language_value']."');";
						$db->query($zap);
					}
				}
					
			
			}
			
		}
		
		
		
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 4 ){
		
			$schemaName = 'accessories';
			$Product_E = new ProductAccessories();
			$ColorSchemaProduct = new ColorSchemaProductAccessories();
			
			$dd = $ColorSchemaProduct->fetchAll('color_schema_id = '.$idschema);
			
			
			foreach( $dd as $key => $v ){
		
				$data = array(
					'product_id' => $idproduct,
					'product_'.$schemaName.'_name' => $v['color_schema_product_'.$schemaName.'_name'],
					'product_'.$schemaName.'_code' => $v['color_schema_product_'.$schemaName.'_code'],
					'product_'.$schemaName.'_type'.$schemaName.'' => $v['color_schema_product_'.$schemaName.'_type'],
					'product_'.$schemaName.'_image' => $v['color_schema_product_'.$schemaName.'_image'],
					'product_'.$schemaName.'_price' => $v['color_schema_product_'.$schemaName.'_price'],
					'product_'.$schemaName.'_default' => $v['color_schema_product_'.$schemaName.'_default'],
					'color_schema_product_'.$schemaName.'_id' => $v['color_schema_product_'.$schemaName.'_id'],
					'color_schema_id' => $idschema
				);
				
				$idIns = $Product_E->insert($data);
				
				$Lang = new Lang();
				$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
				foreach( $dataLang as $k => $val ){
					$idColor = $v['color_schema_product_'.$schemaName.'_id'];
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$idColor."'";
					$dataLangRow = $db->query($zap)->fetchAll();
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$idColor."'";
					$dataLangRow2 = $db->query($zap)->fetchAll();
					
					if( isset($dataLangRow[0]) ){			
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_".$schemaName."name_".$idIns."', '".$dataLangRow[0]['language_value']."');";
						$db->query($zap);
					}
					
					if( isset($dataLangRow2[0]) ){				
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_".$schemaName."description_".$idIns."', '".$dataLangRow2[0]['language_value']."');";
						$db->query($zap);
					}
				}
					
			
			}
			
		}
		
		
		
		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 1 AND $front2 == 1 ){
		
		
			$ProductFront2 = new ProductFront2();
			$ColorSchemaProduct = new ColorSchemaProductFront();	
			$dd = $ColorSchemaProduct->fetchAll('color_schema_id = '.$idschema);
			
			foreach( $dd as $key => $v ){
		
				$data = array(
					'product_id' => $idproduct,
					'product_front_2_option1' => $v['color_schema_product_front_option1'],
					'product_front_2_option2' => $v['color_schema_product_front_option2'],
					'product_front_2_option3' => $v['color_schema_product_front_option3'],
					'product_front_2_option4' => $v['color_schema_product_front_option4'],
					'product_front_2_option5' => $v['color_schema_product_front_option5'],
					'product_front_2_option6' => $v['color_schema_product_front_option6'],
					'product_front_2_option7' => $v['color_schema_product_front_option7'],
					'product_front_2_option8' => $v['color_schema_product_front_option8'],
					'product_front_2_option9' => $v['color_schema_product_front_option9'],
					'product_front_2_option10' => $v['color_schema_product_front_option10'],
					'product_front_2_option11' => $v['color_schema_product_front_option11'],
					'product_front_2_option12' => $v['color_schema_product_front_option12'],
					'product_front_2_option13' => $v['color_schema_product_front_option13'],
					'product_front_2_option14' => $v['color_schema_product_front_option14'],
					'product_front_2_option15' => $v['color_schema_product_front_option15'],
					'product_front_2_name' => $v['color_schema_product_front_name'],
					'product_front_2_code' => $v['color_schema_product_front_code'],
					'product_front_2_type' => $v['color_schema_product_front_type'],
					'product_front_2_type_2' => $v['color_schema_product_front_type_2'],
					'product_front_2_image' => $v['color_schema_product_front_image'],
					'product_front_2_price' => $v['color_schema_product_front_price'],
					'product_front_2_default' => $v['color_schema_product_front_default'],
					'color_schema_product_front_2_id' => $v['color_schema_product_front_id'],
					'color_schema_id' => $idschema
				);
				$idIns = $ProductFront2->insert($data);
				var_dump($data);
				$Lang = new Lang();
				$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
				foreach( $dataLang as $k => $val ){
					$idColor = $v['color_schema_product_front_id'];
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontname_".$idColor."'";
					$dataLangRow = $db->query($zap)->fetchAll();
					$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_frontdescription_".$idColor."'";
					$dataLangRow2 = $db->query($zap)->fetchAll();
					
					if( isset($dataLangRow[0]) ){			
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_front_2_name_".$idIns."', '".$dataLangRow[0]['language_value']."');";
						$db->query($zap);
					}
					
					if( isset($dataLangRow2[0]) ){				
						$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_front_2_description_".$idIns."', '".$dataLangRow2[0]['language_value']."');";
						$db->query($zap);
					}
				}
					
			
			}
			
		}











		
		
	}

	
	public function addColorType2($idProductTypeIns, $idColorSchemaType, $idschema){
	
		$db = Zend_Registry::get('db');
		$schemaName = 'type2';
		$Product_E = new ProductType2();
		$ColorSchemaProduct = new ColorSchemaProductType2();
			
		$dd = $ColorSchemaProduct->fetchAll('color_schema_product_type_id = '.$idColorSchemaType);
			
		foreach( $dd as $key => $v ){
		
			$data = array(
				'product_type_id' => $idProductTypeIns,
				'product_'.$schemaName.'_name' => $v['color_schema_product_'.$schemaName.'_name'],
				'product_'.$schemaName.'_code' => $v['color_schema_product_'.$schemaName.'_code'],
				'product_'.$schemaName.'_image' => $v['color_schema_product_'.$schemaName.'_image'],
				'product_'.$schemaName.'_price' => $v['color_schema_product_'.$schemaName.'_price'],
				'product_'.$schemaName.'_default' => $v['color_schema_product_'.$schemaName.'_default'],
				'color_schema_product_'.$schemaName.'_id' => $v['color_schema_product_'.$schemaName.'_id'],
				'color_schema_id' => $idschema
			);
			$idIns = $Product_E->insert($data);
				
			$Lang = new Lang();
			$dataLang = $Lang->fetchAll(null, 'lang_name DESC');
				
			foreach( $dataLang as $k => $val ){
				$idColor = $v['color_schema_product_'.$schemaName.'_id'];
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."name_".$idColor."'";
				$dataLangRow = $db->query($zap)->fetchAll();
				$zap = "SELECT * FROM `lang_".$val['lang_suffix']."` WHERE `language_variable` LIKE 'color_schema_product_".$schemaName."description_".$idColor."'";
				$dataLangRow2 = $db->query($zap)->fetchAll();
					
				if( isset($dataLangRow[0]) ){			
					$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_".$schemaName."name_".$idIns."', '".$dataLangRow[0]['language_value']."');";
					$db->query($zap);
				}
					
				if( isset($dataLangRow2[0]) ){				
					$zap = "INSERT INTO `lang_".$val['lang_suffix']."` (language_panel, language_variable, language_value) VALUES ('product', 'product_".$schemaName."description_".$idIns."', '".$dataLangRow2[0]['language_value']."');";
					$db->query($zap);
				}
			}	
	
		}
	
	}
	
	
	
	
	
	
	
	
	
	
	public function changeColorSchema($idproduct,$idschema,$type=0){
	
		$ColorSchema = new ColorSchema();
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $idschema);	
		$rowColorSchema = $ColorSchema->fetchRow($select);
	
		$Product = new Product();
		$select = $Product->select();		
		$select->where('product_id = ?', $idproduct);	
		$rowProduct = $Product->fetchRow($select);
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 0 AND $type == 0 ){
			// body/korpus
			if( $rowColorSchema['color_schema_id'] != $rowProduct['color_schema_id'] ){
				// usunięcie starych rekordów 
				$ProductBody = new ProductBody();
				$where = array(
					'product_id = ?' => $idproduct,
					'color_schema_id != ?' => 0
				);
				$ProductBody->delete($where);
				
				// i dodanie nowych
				$this->addColor($idproduct,$idschema);
			}
		}
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 1 AND $type == 1 ){
			// front
			if( $rowColorSchema['color_schema_id'] != $rowProduct['color_schema_id2'] ){
				// usunięcie starych rekordów 
				
				$ProductFront = new ProductFront();
				$where = array(
					'product_id = ?' => $idproduct,
					'color_schema_id != ?' => 0
				);
				$ProductFront->delete($where);
				
				// i dodanie nowych
				$this->addColor($idproduct,$idschema);
			}
		}
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 2 AND $type == 2 ){
			// typy
			if( $rowColorSchema['color_schema_id'] != $rowProduct['color_schema_id3'] ){
				// usunięcie starych rekordów 
				
				$ProductType = new ProductType();
				$where = array(
					'product_id = ?' => $idproduct,
					'color_schema_id != ?' => 0
				);
				$ProductType->delete($where);
				
				// i dodanie nowych
				$this->addColor($idproduct,$idschema);
			}
		}
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 3 AND $type == 3 ){
			// uchwyty
			if( $rowColorSchema['color_schema_id'] != $rowProduct['color_schema_id4'] ){
				// usunięcie starych rekordów 
				
				$ProductHandles = new ProductHandles();
				$where = array(
					'product_id = ?' => $idproduct,
					'color_schema_id != ?' => 0
				);
				$ProductHandles->delete($where);
				
				// i dodanie nowych
				$this->addColor($idproduct,$idschema);
			}
		}
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 4 AND $type == 4 ){
			// akcesoria
			if( $rowColorSchema['color_schema_id'] != $rowProduct['color_schema_id5'] ){
				// usunięcie starych rekordów 
			/*	
				$ProductAccessories = new ProductAccessories();
				$where = array(
					'product_id = ?' => $idproduct,
					'color_schema_id != ?' => 0
				);
				$ProductAccessories->delete($where);
			*/	
				// i dodanie nowych
				$this->addColor($idproduct,$idschema);
			}
		}		
		
		
		
		
		
		if( $rowColorSchema['color_schema_type'] == 1 AND $type == 5 ){
			// front2
			if( $rowColorSchema['color_schema_id'] != $rowProduct['color_schema_id6'] ){
				// usunięcie starych rekordów 
				
				$ProductFront2 = new ProductFront2();
				$where = array(
					'product_id = ?' => $idproduct,
					'color_schema_id != ?' => 0
				);
				$ProductFront2->delete($where);
				
				// i dodanie nowych
				$this->addColor($idproduct,$idschema,1);
			}
		}
		
		
		
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	public function addNewColor($idschema,$idcolor){
	
		$ColorSchema = new ColorSchema();
		$select = $ColorSchema->select();		
		$select->where('color_schema_id = ?', $idschema);	
		$rowColorSchema = $ColorSchema->fetchRow($select);
		
		$Product = new Product();
		
		if( $rowColorSchema['color_schema_type'] == 0 ){
			$data = $Product->fetchAll('color_schema_id = '.$idschema);
			
			foreach( $data as $key => $v ){
			
			}
		}
		else{
		}		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}

