<?php  break; // Listo
	require(__DIR__.'/connect.php');
	$db = new connect('visionwe_mateckoriginal','visionwe_matecku','7Z}jf_6}{KZ]');
	$mateck = new connect('visionwe_mateckkdb','visionwe_matecku','7Z}jf_6}{KZ]');
function leeRegistrarSubcategorias($idCategoriaRaiz){
		$db = new connect('visionwe_mateckoriginal','visionwe_matecku','7Z}jf_6}{KZ]');
		$mateck = new connect('visionwe_mateckkdb','visionwe_matecku','7Z}jf_6}{KZ]');
		$query ="
		SELECT 
			c.categories_id,
			c.date_added,
			c.last_modified,
			d.language_id,
			d.categories_name,
			d.categories_description,
			d.gm_url_keywords,
			c.categories_status
				FROM 
					categories c left join categories_description d on c.categories_id = d.categories_id
				WHERE 
					parent_id = $idCategoriaRaiz
				GROUP BY c.categories_id
				ORDER BY c.categories_id ASC 
			";
		$categorias = $db->getRows($query); 
		$cont = 1;
		$registros =0;
		echo "Comensando registro subcategorias...<br/>";
		foreach($categorias as $categoria):
			$cont = $cont+2;
			$registros = $registros+1;
			$idCategoria = $categoria['categories_id']+1;
			if($categoria['language_id']==1)
				$lang=1;
			else
				$lang=2;
			$sql='insert into ax_category(id_category, id_parent, id_shop_default, level_depth, nleft, nright, active, date_add, date_upd, position, is_root_category)';
			$sql.='values("'.$idCategoria.'", "'.($idCategoriaRaiz+1).'", "1", "3", "'.$cont.'", "'.($cont+1).'", "'.$categoria['categories_status'].'", "'.$categoria['date_added'].'", "'.$categoria['last_modified'].'","0", "0")';
			$mateck->insertRow($sql);
			$sql='insert into ax_category_shop(id_category, id_shop, position) values("'.$idCategoria.'", "1", "'.($registros-1).'")';
			$mateck->insertRow($sql);
			$sql='insert into ax_category_group(id_category, id_group) values("'.$idCategoria.'", "1")';
			$mateck->insertRow($sql);
			$sql='insert into ax_category_group(id_category, id_group) values("'.$idCategoria.'", "2")';
			$mateck->insertRow($sql);
			$sql='insert into ax_category_group(id_category, id_group) values("'.$idCategoria.'", "3")';
			$mateck->insertRow($sql);
			echo $registros.' - '.$idCategoria.' - '.$categoria['categories_name'].' - '.$categoria['gm_url_keywords'];
			echo ' - '.$categoria['date_added'].' - '.$categoria['last_modified'].' - registrado OK.<br/><br/> ';
		endforeach;
		
		
		$query ="
		SELECT 
			c.categories_id,
			c.date_added,
			c.last_modified,
			d.language_id,
			d.categories_name,
			d.categories_description,
			d.gm_url_keywords
				FROM 
					categories c left join categories_description d on c.categories_id = d.categories_id
				WHERE 
					parent_id = $idCategoriaRaiz
				ORDER BY c.categories_id ASC 
			";
		$categorias = $db->getRows($query); 
		$cont = 1;
		$registros =0;
		echo "Creando descripciones de las categorias padre...<br/>";
		foreach($categorias as $categoria):
			$registros = $registros+1;
			$idCategoria = $categoria['categories_id']+1;
			if($categoria['language_id']==1)
				$lang=1;
			else
				$lang=2;
			
			$sql='insert into ax_category_lang(id_category, id_shop, id_lang, name, description, link_rewrite)';
			$sql.='values("'.$idCategoria.'", "1", "'.$lang.'", "'.$categoria['categories_name'].'", "", "'.$categoria['gm_url_keywords'].'")';
			$mateck->insertRow($sql);
			echo $registros.'<br/>';
			
		endforeach;
	
	}
	
	$query ="
	SELECT 
		c.categories_id,
		c.date_added,
		c.last_modified,
		d.language_id,
		d.categories_name,
		d.categories_description,
		d.gm_url_keywords,
		c.categories_status
			FROM 
				categories c left join categories_description d on c.categories_id = d.categories_id
			WHERE 
				parent_id = 0
			GROUP BY c.categories_id
			ORDER BY c.categories_id ASC 
		";
	$categorias = $db->getRows($query); 
	$cont = 1;
	$registros =0;
	echo "Creando registras categorias padre...<br/>";
	foreach($categorias as $categoria):
		$cont = $cont+2;
		$registros = $registros+1;
		$idCategoria = $categoria['categories_id']+1;
		if($categoria['language_id']==1)
			$lang=1;
		else
			$lang=2;
		$sql='insert into ax_category(id_category, id_parent, id_shop_default, level_depth, nleft, nright, active, date_add, date_upd, position, is_root_category)';
		$sql.='values("'.$idCategoria.'", "2", "1", "2", "'.$cont.'", "'.($cont+1).'", "'.$categoria['categories_status'].'", "'.$categoria['date_added'].'", "'.$categoria['last_modified'].'","0", "0")';
		$mateck->insertRow($sql);
		$sql='insert into ax_category_shop(id_category, id_shop, position) values("'.$idCategoria.'", "1", "'.($registros-1).'")';
		$mateck->insertRow($sql);
		$sql='insert into ax_category_group(id_category, id_group) values("'.$idCategoria.'", "1")';
		$mateck->insertRow($sql);
		$sql='insert into ax_category_group(id_category, id_group) values("'.$idCategoria.'", "2")';
		$mateck->insertRow($sql);
		$sql='insert into ax_category_group(id_category, id_group) values("'.$idCategoria.'", "3")';
		$mateck->insertRow($sql);
		echo $registros.' - '.$idCategoria.' - '.$categoria['categories_name'].' - '.$categoria['gm_url_keywords'];
		echo ' - '.$categoria['date_added'].' - '.$categoria['last_modified'].' - registrado OK.<br/> ';
	endforeach;
	
	
	$query ="
	SELECT 
		c.categories_id,
		c.date_added,
		c.last_modified,
		d.language_id,
		d.categories_name,
		d.categories_description,
		d.gm_url_keywords,
		c.categories_status
			FROM 
				categories c left join categories_description d on c.categories_id = d.categories_id
			WHERE 
				parent_id = 0
			ORDER BY c.categories_id ASC 
		";
	$categorias = $db->getRows($query); 
	$cont = 1;
	$registros =0;
	echo "Creando descripciones de las categorias padre...<br/>";
	foreach($categorias as $categoria):
		$registros = $registros+1;
		$idCategoria = $categoria['categories_id']+1;
		if($categoria['language_id']==1)
			$lang=1;
		else
			$lang=2;
		
		$sql='insert into ax_category_lang(id_category, id_shop, id_lang, name, description, link_rewrite)';
		$sql.='values("'.$idCategoria.'", "1", "'.$lang.'", "'.$categoria['categories_name'].'", "", "'.$categoria['gm_url_keywords'].'")';
		$mateck->insertRow($sql);
		echo $registros.'<br/>';
		
	endforeach;
	
	
	/* Registro de subcategorias	*/
	
	$query ="
	SELECT 
		c.categories_id,
		c.date_added,
		c.last_modified,
		d.language_id,
		d.categories_name,
		d.categories_description,
		d.gm_url_keywords,
		c.categories_status
			FROM 
				categories c left join categories_description d on c.categories_id = d.categories_id
			WHERE 
				parent_id = 0
			GROUP BY c.categories_id
			ORDER BY c.categories_id ASC 
		";
	$categorias = $db->getRows($query); 
	$registros =0;
	echo "Lectura de las categorias padre...<br/>";
	foreach($categorias as $key=>$categoria):
		$idCategoria = $categoria['categories_id'];
		echo "Categoria padre No. $key <br/>";
		leeRegistrarSubcategorias($idCategoria);
		
	endforeach;
	
	echo "Fin de todo";
	
	
	
	
	
	
	
	
	
	
?>	