<?php

function getFamLevel( $familia )
{
 if ( ($familia & 0x000000FF) ) return 4;
 if ( ($familia & 0x0000FF00) ) return 3;
 if ( ($familia & 0x00FF0000) ) return 2;
 if ( ($familia & 0xFF000000) ) return 1;

 return 0;
}

function printLevel( $familia )
{
 switch( getFamLevel( $familia ) )
 {
  case 1:
   echo "->&nbsp;"; 
   break;
  case 2:
   echo "&nbsp;&nbsp;&nbsp;&nbsp;>&nbsp;";
   break;
  case 3:
   echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;";
   break;
  case 4:
   echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;";
   break;
  default:
   echo "NiVeL DeScOnOcIdO - Error de interpretaci&oacuten -";
 }
}

function printSelectFAM( $conexion, $currFAM, $extrasSelect )
{
 echo "\n";
 echo "<select name=\"FiltrarPor\" size=\"1\" $extrasSelect>\n";
 echo " <option value=\"-1\" >-=[ TODOS ]=-</option>\n";
 echo " <option ";
  if ( $currFAM == 0 ) echo "selected";
 echo " value=\"0\" >Sin Clasificar</option>";

 $consulta = "SELECT id, Familia, descr FROM productos WHERE EsNodo='Y' ORDER BY Familia";
 $resF = mysql_query( $consulta, $conexion ) OR die("No puedo realizar la consulta de familias<br>$consulta<br>".mysql_error($conexion));
 while ( $datos = mysql_fetch_array($resF) )
 {
   echo "<option value=\"$datos[1]\"";
   if ( $currFAM == $datos[1] ) echo " SELECTED ";
   echo ">";printLevel($datos[1]);echo"$datos[2]</option>\n";
 }
 mysql_free_result($resF);

 echo "</select>\n";
}

?>
