<?php
	include("db.php");
	if (isset($_GET["usuario"]) && !empty($_GET["usuario"]) && $_GET["usuario"]=="storefront0469" && isset($_GET["password"]) && !empty($_GET["password"]) && $_GET["password"]=="Shopeando.1") {
			$test_array = array();
			$rs = mysql_query("SELECT jos_vm_category.category_id, jos_vm_category.category_name FROM jos_vm_category INNER JOIN jos_vm_category_xref ON jos_vm_category.category_id = jos_vm_category_xref.category_child_id WHERE jos_vm_category_xref.category_parent_id = 0 ORDER BY jos_vm_category.category_name ASC");		
			$total = mysql_num_rows($rs);
			if ($total>0) {
				$i=0;
				while ($categoria = mysql_fetch_assoc($rs)) {
					$rs2 = mysql_query("SELECT jos_vm_category.category_id, jos_vm_category.category_name FROM jos_vm_category INNER JOIN jos_vm_category_xref ON jos_vm_category.category_id = jos_vm_category_xref.category_child_id WHERE jos_vm_category_xref.category_parent_id = ".$categoria["category_id"]." ORDER BY jos_vm_category.category_name ASC");		
					$j=0;
					$optiones = array();
					while ($subcategoria = mysql_fetch_assoc($rs2)) {
						$rs3 = mysql_query("SELECT jos_vm_category.category_id, jos_vm_category.category_name FROM jos_vm_category INNER JOIN jos_vm_category_xref ON jos_vm_category.category_id = jos_vm_category_xref.category_child_id WHERE jos_vm_category_xref.category_parent_id = ".$subcategoria["category_id"]." ORDER BY jos_vm_category.category_name ASC");		
						$k=0;
						$optiones2 = array();
						while ($subsubcategoria = mysql_fetch_assoc($rs3)) {
							$subsubitem_properties = @array(
								'nombre'               => utf8_encode($subsubcategoria["category_name"]),
								'id'               => ($subsubcategoria["category_id"])
							);
							$optiones2["opcion".$k] = $subsubcategoria;						
							$k++;							
						}
						$subitem_properties = @array(
							'nombre'               => utf8_encode($subcategoria["category_name"]),
							'id'               => ($subcategoria["category_id"]),
							'opciones'               => $optiones2,
						);
						$optiones["opcion".$j] = $subitem_properties;						
						$j++;
					}
					$item_properties = @array(
						'nombre'               => utf8_encode($categoria["category_name"]),
						'id'               => $categoria["category_id"],
						'opciones'               => $optiones,
					);
					$test_array["categoria".$i] = $item_properties;
					$i++;
				}
			}else{
				$test_array = array ('error' => 'categorias no encontradas');
			}
	}else{
		$test_array = array ('error' => 'usuario y/o contraseña inválidos ó vacios');
	}
	header('Content-type: text/xml');
	echo @array_to_xml($test_array, new SimpleXMLElement('<categorias/>'))->asXML();		
?>