<?php 
	

    require_once('../Connections/pandora.php');
	
	//ESTO PARA OCULTAR LOS PARÁMETROS GET
	if (!$_GET){
		$_SESSION['got'] = $_GET;
		$uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);
		$actual_link = "http://$_SERVER[HTTP_HOST]" . $uri_parts[0];
		echo $actual_link;
        header('Location: ' . $actual_link);
        die;
    }
    else{
		if (!empty($_SESSION['got'])){
			$_GET = $_SESSION['got'];
			unset($_SESSION['got']);
		}
		
		$currentPage = $_SERVER["PHP_SELF"];
		$maxRows_Recordsetcm = 25;
		$pageNum_Recordsetcm = 0;
		if (isset($_GET['pageNum_Recordsetcm'])) {
		  $pageNum_Recordsetcm = $_GET['pageNum_Recordsetcm'];
		}
		$startRow_Recordsetcm = $pageNum_Recordsetcm * $maxRows_Recordsetcm;
		$idMarca = $idSegmento = $idModelo = "";
		
		//Controlamos que no haya pasado con parametros vacíos
		if ((!isset($_GET['modelo']) || $_GET['modelo'] == "" || 
				$_GET['modelo'] == '0')
			&& (!isset($_GET['codigo_pieza']) || $_GET['codigo_pieza'] == "") 
			&& (!isset($_GET['diametro']) || $_GET['diametro'] == "") 
			&& (!isset($_GET['longitud']) || $_GET['longitud'] == "")
			&& (!isset($_GET['tipo_pieza']) || 
					(isset($_GET['tipo_pieza']) && $_GET['tipo_pieza'] != "Movimiento"))
		   ){
			//Y que las variables de sesión estén vacías (sino es que volvió para atrás del detalle)
			if ($_SESSION['idMarca'] == "" && $_SESSION['segmento'] == "" 
			&& $_SESSION['modelo'] == "" && $_SESSION['codigo_pieza'] == ""
			&& $_SESSION['diametro'] == "" && $_SESSION['longitud'] == ""
			&& $_SESSION['tipo_pieza'] == ""){	
				header("Location: http://www.etma.com.ar/catalogo");
				exit;	
			}
		}
		
		if (isset($_GET['idMarca'])) {
			$_SESSION['idMarca'] = $_GET['idMarca'];
			if (isset($_GET['segmento'])) {
				$_SESSION['segmento'] = $_GET['segmento'];
				if (isset($_GET['modelo'])) {
					$_SESSION['modelo'] = $_GET['modelo'];
				}
			}
			$_SESSION['codigo_pieza'] = "";
			$_SESSION['diametro'] = "";
			$_SESSION['longitud'] = "";
			$_SESSION['tipo_pieza'] = "";
		}
		if (isset($_GET['codigo_pieza'])) {
			$_SESSION['idMarca'] = "";
			$_SESSION['segmento'] = "";
			$_SESSION['modelo'] = "";
			$_SESSION['codigo_pieza'] = $_GET['codigo_pieza'];
			$_SESSION['diametro'] = "";
			$_SESSION['longitud'] = "";
			$_SESSION['tipo_pieza'] = "";
		}
		if (isset($_GET['tipo_pieza'])) {
			$_SESSION['idMarca'] = "";
			$_SESSION['segmento'] = "";
			$_SESSION['modelo'] = "";
			$_SESSION['codigo_pieza'] = "";
			$_SESSION['diametro'] = $_GET['diametro'];
			$_SESSION['longitud'] = $_GET['longitud'];
			$_SESSION['tipo_pieza'] = $_GET['tipo_pieza'];
		}
		
		//PARA TEST
		//echo "TipoPieza: " . $_GET['tipo_pieza'] . " - Diametro: " . $_GET['diametro'] . " - SesionDiametro: " . $_SESSION['diametro'] . " - Longitud: " . $_GET['longitud'] . " SesiónLongitud: " . $_SESSION['longitud'];
		
		$query_Recordsetcm = "SELECT pieza_standar.* FROM pieza_standar";
		//$query_Recordsetcm = "select pieza.*, piezacodigo.id_marca from pieza left join piezacodigo on pieza.id = piezacodigo.id_pieza where id_marca = 'c8730441-b37d-4824-8a40-a00c22ba8979' or id_marca = '2be8c832-3d18-4721-b64f-9dfc16d02c8e' or id_marca = '1417ea7e-7f6c-4854-9e23-becf7bb4582a'";
		//BÚSQUEDA POR MARCA/SEGMENTO/MODELO
		if (isset($_SESSION['idMarca']) && $_SESSION['idMarca'] != "") { 
			$query_Recordsetcm = sprintf("%s INNER JOIN vehiculo ON pieza_standar.id = vehiculo.id_pieza LEFT JOIN segmento ON vehiculo.id_segmento = segmento.id  WHERE id_marcavehiculo = '%s'", $query_Recordsetcm, $_SESSION['idMarca']);
			if (isset($_SESSION['segmento']) && $_SESSION['segmento'] != "" && $_SESSION['segmento'] != '0'){
				$query_Recordsetcm = sprintf("%s AND segmento = '%s'", $query_Recordsetcm, $_SESSION['segmento']);
				if (isset($_SESSION['modelo']) && $_SESSION['modelo'] != "" && $_SESSION['modelo'] != '0'){
					$query_Recordsetcm = sprintf("%s AND modelo = '%s'", $query_Recordsetcm, $_SESSION['modelo']);
				}
			}
			$query_Recordsetcm = sprintf("%s GROUP BY pieza_standar.id ORDER BY pieza_standar.id", $query_Recordsetcm);
		}
		//BÚSQUEDA POR CÓDIGO DE PIEZA
		else if (isset($_SESSION['codigo_pieza']) && $_SESSION['codigo_pieza'] != "" ) {  
			$codigo = $_SESSION['codigo_pieza'];
			//$oemPosible = "%" . $_SESSION['codigo_pieza'] . "%";
			$oemPosible = $_SESSION['codigo_pieza'];
			$query_Recordsetcm = sprintf("%s INNER JOIN piezacodigo ON pieza_standar.id = piezacodigo.id_pieza WHERE  codigo = '%s' UNION SELECT pieza_standar.* FROM pieza_standar INNER JOIN vehiculo ON pieza_standar.id = vehiculo.id_pieza WHERE oems = '%s'",$query_Recordsetcm, $codigo, $oemPosible);
		}
		//BÚSQUEDA POR MEDIDA
		else if (isset($_SESSION['tipo_pieza'])){
			$tipoPieza = $_SESSION['tipo_pieza'];
			$query_Recordsetcm = sprintf("%s WHERE tipoPieza = '%s'", $query_Recordsetcm, $tipoPieza);
			
			//CRUCETA
			if ($tipoPieza == "Cruceta"){
				if (isset($_SESSION['diametro']) && $_SESSION['diametro'] != "") {  //CARGÓ DIAMETRO
					$diametro = $_SESSION['diametro'];
					$diametro = str_replace(',', '.', $diametro);
					$diametroMenor = $diametro - 0.5;
					$diametroMayor = $diametro + 0.5;
					$query_Recordsetcm = sprintf("%s AND (
						(CAST(REPLACE(C1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(C1, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(Di, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(Di, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(S1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(S1, ',', '.') AS DECIMAL(10,4)) <= %s)",$query_Recordsetcm, $diametroMenor, $diametroMayor, $diametroMenor, $diametroMayor, $diametroMenor, $diametroMayor);
					if (isset($_SESSION['longitud']) && $_SESSION['longitud']){   //Y TAMBIÉN LONGITUD
						$longitud = $_SESSION['longitud'];
						$longitud = str_replace(',', '.', $longitud);
						$longitudMenor = $longitud - 0.5;
						$longitudMayor = $longitud + 0.5;
						$query_Recordsetcm = sprintf("%s AND (
						(CAST(REPLACE(A1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(A1, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(A2, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(A2, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(B1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(B1, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(C2, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(C2, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(C3, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(C3, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(C4, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(C4, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(D1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(D1, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(D2, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(D2, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(H, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(H, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(H1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(H1, ',', '.') AS DECIMAL(10,4)) <= %s))",$query_Recordsetcm, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor);
					}
					$query_Recordsetcm = sprintf("%s)", $query_Recordsetcm);
				}
				else if (isset($_SESSION['longitud']) && $_SESSION['longitud']){  //SOLO CARGÓ LONGITUD
					$longitud = $_SESSION['longitud'];
					$longitud = str_replace(',', '.', $longitud);
					$longitudMenor = $longitud - 0.5;
					$longitudMayor = $longitud + 0.5;
					$query_Recordsetcm = sprintf("%s AND (
						(CAST(REPLACE(A1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(A1, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(A2, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(A2, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(B1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(B1, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(C2, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(C2, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(C3, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(C3, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(C4, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(C4, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(D1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(D1, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(D2, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(D2, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(H, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(H, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(H1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(H1, ',', '.') AS DECIMAL(10,4)) <= %s))",$query_Recordsetcm, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor, $longitudMenor, $longitudMayor);
				}
			}
			//TRICETA
			else if ($tipoPieza == "Triceta"){
				if (isset($_SESSION['diametro']) && $_SESSION['diametro'] != "") {  //CARGÓ DIAMETRO
					$diametro = $_SESSION['diametro'];
					$diametro = str_replace(',', '.', $diametro);
					$diametroMenor = $diametro - 0.5;
					$diametroMayor = $diametro + 0.5;
					$query_Recordsetcm = sprintf("%s AND (
						(CAST(REPLACE(C1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(C1, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(Di, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(Di, ',', '.') AS DECIMAL(10,4)) <= %s) 
						OR (CAST(REPLACE(S1, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(S1, ',', '.') AS DECIMAL(10,4)) <= %s)",$query_Recordsetcm, $diametroMenor, $diametroMayor, $diametroMenor, $diametroMayor, $diametroMenor, $diametroMayor);
					if (isset($_SESSION['longitud']) && $_SESSION['longitud'] 
					&& is_numeric($_SESSION['longitud'])){   //Y TAMBIÉN LONGITUD(ESTRIAS)
						$longitudMenor = $_SESSION['longitud'] - 0.5;
						$longitudMayor = $_SESSION['longitud'] + 0.5;
						$query_Recordsetcm = sprintf("%s) AND (
							CAST(REPLACE(Z, ',', '.') AS DECIMAL(10,4)) >= %s 
								AND CAST(REPLACE(Z, ',', '.') AS DECIMAL(10,4)) <= %s",$query_Recordsetcm,  $longitudMenor, $longitudMayor);
					}
					$query_Recordsetcm = sprintf("%s)", $query_Recordsetcm);
				}
				else if (isset($_SESSION['longitud']) && $_SESSION['longitud']){  //SOLO CARGÓ LONGITUD (ESTRIAS)
					$longitud = $_SESSION['longitud'];
					$longitud = str_replace(',', '.', $longitud);
					$longitudMenor = $_SESSION['longitud'] - 0.5;
					$longitudMayor = $_SESSION['longitud'] + 0.5;
					$query_Recordsetcm = sprintf("%s AND (
						CAST(REPLACE(Z, ',', '.') AS DECIMAL(10,4)) >= %s 
							AND CAST(REPLACE(Z, ',', '.') AS DECIMAL(10,4)) <= %s)",$query_Recordsetcm, $longitudMenor, $longitudMayor);
				}
			}
		}
		
		//PARA TEST
		//echo "_SESSION Seteada? = " . isset($_SESSION['idMarca']) . " - Valor idMarca = " . $_SESSION['idMarca'];
		//echo "TipoPieza:". $_SESSION['tipo_pieza'];
		//echo "\n CONSULTA SQL: ". $query_Recordsetcm;
		$query_limit_Recordsetcm = sprintf("%s LIMIT %d, %d", $query_Recordsetcm, $startRow_Recordsetcm, $maxRows_Recordsetcm);
		$Recordsetcm = mysqli_query($catalogo, $query_limit_Recordsetcm) or die(mysql_error());
		$row_Recordsetcm = $Recordsetcm->fetch_assoc();
		
		if (isset($_GET['totalRows_Recordsetcm'])) {
		  $totalRows_Recordsetcm = $_GET['totalRows_Recordsetcm'];
		} else {
		  $all_Recordsetcm = mysqli_query($catalogo, $query_Recordsetcm);
		  $totalRows_Recordsetcm = $all_Recordsetcm->num_rows;
		}
		$totalPages_Recordsetcm = ceil($totalRows_Recordsetcm/$maxRows_Recordsetcm)-1;
		
		$queryString_Recordsetcm = "";
		if (!empty($_SERVER['QUERY_STRING'])) {
		  $params = explode("&", $_SERVER['QUERY_STRING']);
		  $newParams = array();
		  foreach ($params as $param) {
			if (stristr($param, "pageNum_Recordsetcm") == false && 
				stristr($param, "totalRows_Recordsetcm") == false) {
			  array_push($newParams, $param);
			}
		  }
		  if (count($newParams) != 0) {
			$queryString_Recordsetcm = "&" . htmlentities(implode("&", $newParams));
		  }
		}
		$queryString_Recordsetcm = sprintf("&totalRows_Recordsetcm=%d%s", $totalRows_Recordsetcm, $queryString_Recordsetcm);
    } 
?>
<div class="contenido">
<p>&nbsp; </p>
<div style="overflow-x:auto">
<table border="0" cellpadding="5" cellspacing="0" width="100%">
  <?php 
  if ($totalRows_Recordsetcm > 0 ){
	  ?>
	  	  <p>&nbsp; </p>
   <label for="premium" class="lbl_standar">STANDARD</label>
      <tr style="background-color:#EB2319; color:#FFF; font-size:1.2em; border-radius:8px; ">
            <td align="center"><?php echo "<b>" .$diccionario['codigos'] ."</b>"; ?></td>
       <?php 
 		 if ($_SESSION['tipo_pieza'] != "" && $_SESSION['tipo_pieza'] == "Cruceta"){
	  	?>
            <td align="center"><?php echo "<b>" .$diccionario['a1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['a2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['b1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c1prima'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c3'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c4'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['d1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['d2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['largo_sin_cubetas'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['diametro_munion'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['lubricacion'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['descripcion_cubetas'] ."</b>"; ?></td>
        <?php 
		 }
		 else if ($_SESSION['tipo_pieza'] != "" && $_SESSION['tipo_pieza'] == "Triceta"){  
		 ?>
         	<td align="center"><?php echo "<b>" .$diccionario['c1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['h'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['h1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['s1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['di'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['z'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['diametro_munion'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['descripcion_cubetas'] ."</b>"; ?></td>
            <?php 
		 }
		 else if ($_SESSION['tipo_pieza'] != "" && $_SESSION['tipo_pieza'] == "Movimiento"){
			?>
            
            <td align="center"><?php echo "<b>" .$diccionario['d1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['d2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['e1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['e2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['f1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['f2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['observaciones'] ."</b>"; ?></td>
            <?php
		 } 
		 else {   //TODOS
	  	?>
        	 <td align="center"><?php echo "<b>" .$diccionario['a1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['a2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['b1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c1prima'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c3'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['c4'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['d1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['d2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['e1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['e2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['f1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['f2'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['h'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['h1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['s1'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['di'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['z'] ."</b>"; ?></td>
            <td align="center"><?php echo "<b>" .$diccionario['lubricacion'] ."</b>"; ?></td>
          <?php
		 }
	  	?>
	</tr>
    <tr>
   		<td align="center" style="height:2px;"></td>
    </tr>
      <?php
	  do { ?>
        <tr class="fila-tabla">
          <td align="left">
          	<?php include("fragmento_codigos_marcas_resultado.php"); ?>
          </td>
          <?php 
			 if ($_SESSION['tipo_pieza'] != "" && $_SESSION['tipo_pieza'] == "Cruceta"){
			?>
              <td align="center">
                <?php if ($row_Recordsetcm['a1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['a1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['a2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['a2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['b1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['b1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['c1'] <> "NULL") echo   str_replace(".",",",$row_Recordsetcm['c1'])  ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['c1prima'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c1prima']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['c2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['c3'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c3']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['c4'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c4']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['d1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['d1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['d2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['d2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['largosincubeta'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['largosincubeta']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['diametromunion'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['diametromunion']) ; else echo '0' ?>
              </td>
               <td align="center">
                <?php if ($row_Recordsetcm['diametromunion'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['lubricacionubicacion']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['descripcioncubetas'] <> "NULL") echo $row_Recordsetcm['descripcioncubetas'] ; else echo '0' ?>
              </td>
         <?php 
		 }
		 else if ($_SESSION['tipo_pieza'] != "" && $_SESSION['tipo_pieza'] == "Triceta"){ ?>
              <td align="center">
                <?php if ($row_Recordsetcm['c1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['h'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['h']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['h1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['h1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['s1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['s1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['di'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['di']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['z'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['z']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['diametromunion'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['diametromunion']) ; else echo "0" ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['descripcioncubetas'] <> "NULL") echo $row_Recordsetcm['descripcioncubetas'] ; else echo '0' ?>
              </td>
		 	<?php 
		 }
		 else if ($_SESSION['tipo_pieza'] != "" && $_SESSION['tipo_pieza'] == "Movimiento"){ ?>
         		
              <td align="center">
                <?php if ($row_Recordsetcm['d1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['d1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['d2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['d2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['e1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['e1']) ; else echo '0' ?>
              </td>
              <td align="center">
                 <?php if ($row_Recordsetcm['e2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['e2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['f1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['f1']) ; else echo '0' ?>
              </td>
              <td align="center">
                 <?php if ($row_Recordsetcm['f2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['f2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['observaciones'] <> "NULL") echo $row_Recordsetcm['observaciones']; else echo '-' ?>
              </td>
         <?php 
		 }
		 else { ?>
         <td align="center">
                <?php if ($row_Recordsetcm['a1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['a1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['a2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['a2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['b1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['b1']) ; else echo '0' ?>
              </td>
         	 <td align="center">
                <?php if ($row_Recordsetcm['c1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c1']) ; else echo '0' ?>
              </td>
              	 <td align="center">
                <?php if ($row_Recordsetcm['c1prima'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c1prima']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['c2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c2']) . "<B>"; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['c3'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c3']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['c4'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['c4']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['d1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['d1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['d2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['d2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['e1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['e1']) ; else echo '0' ?>
              </td>
              <td align="center">
                 <?php if ($row_Recordsetcm['e2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['e2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['f1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['f1']) ; else echo '0' ?>
              </td>
              <td align="center">
                 <?php if ($row_Recordsetcm['f2'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['f2']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['h'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['h']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['h1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['h1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['s1'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['s1']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['di'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['di']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['z'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['z']) ; else echo '0' ?>
              </td>
              <td align="center">
                <?php if ($row_Recordsetcm['diametromunion'] <> "NULL") echo str_replace(".",",",$row_Recordsetcm['lubricacionubicacion']) ; else echo '0' ?>
              </td>
         <?php } 
		 ?>
        </tr>
        </tr>
        <td></td>
    <?php } while ($row_Recordsetcm = $Recordsetcm->fetch_assoc()); 
	}?><tr>
</table>
</div>
<p>
<table border="0" width="100%" style="border-radius:8px;  background-image:url(imagenes/fondo_2.png);">
  <tr>
  	 <?php 
  		if ($totalRows_Recordsetcm > 0){?>
            <td align="center" width="5%">
				<?php if ($pageNum_Recordsetcm > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_Recordsetcm=%d%s", $currentPage, 0, $queryString_Recordsetcm); ?>"><img src="imagenes/btn_primero.png" /></a>
           		<?php } // Show if not first page ?>
            </td>
            <td align="center" width="5%">
				<?php if ($pageNum_Recordsetcm > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_Recordsetcm=%d%s", $currentPage, max(0, $pageNum_Recordsetcm - 1), $queryString_Recordsetcm); ?>"><img src="imagenes/btn_ant.png" /></a>
            	<?php } // Show if not first page ?>
            </td>
            <td align="center" width="90%">
            	
            </td>
            <td align="center" width="5%">
				<?php if ($pageNum_Recordsetcm < $totalPages_Recordsetcm) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_Recordsetcm=%d%s", $currentPage, min($totalPages_Recordsetcm, $pageNum_Recordsetcm + 1), $queryString_Recordsetcm); ?>"><img src="imagenes/btn_sig.png" /></a>
            <?php } // Show if not last page ?>
            </td>
            <td align="center" width="5%">
				<?php if ($pageNum_Recordsetcm < $totalPages_Recordsetcm) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_Recordsetcm=%d%s", $currentPage, $totalPages_Recordsetcm, $queryString_Recordsetcm); ?>"><img src="imagenes/btn_ultimo.png" /></a>
            <?php } // Show if not last page ?>
            </td>
    <?php 
	}
	else{?>

    <?php 
	}?>
  </tr>
</table>
</p>
</div>