<?php
/**
 *  Biblioteca do Componete mainMenu
 *
 *  Versão: 1    data:
 *  Revisão:    data:
 */


/**
 *  create_mainMenu()
 */
function create_mainMenu( $mainMenu, 
                          $mainMenu_Conf, 
                          $mainMenu_Item )
{
  /*  declara as variáveis Globais  */
  $arr = array( 
    $mainMenu . '_Item_lang',
  );
  foreach( $arr as $_i => $ref )
  {  
    global $$ref;
  }

  //  define o Idioma dos Itens  ------------------------------------------  //
  $tmp     = $mainMenu . '_Item_lang';
  $arrLang = $$tmp;

  if ( isset($mainMenu_Item) )
  {
    foreach($mainMenu_Item as $val_ => $status_)
    {
      writeTO( '    <div id="' . $mainMenu . $val_ . '">'   );
      if ( strpos($val_, 'separador') )
      {
        writeTO( '      <img src="imagens/linha1.gif" width="130px" height="4" />'   );
      }else
      {
        $str_ = $arrLang[$val_];
        writeTO( '      ' . $str_                             );
      }// end
      writeTO( '    </div>'                                 );
    }// End foreach($mainMenu_Item as $ite_ => $val_)
  }
}// End function exibeMenu( $mainMenu, $mainMenu_Conf, $mainMenu_Item )

/**
 *  create_mainMenu_css()
 */
function create_mainMenu_css( $mainMenu,
                              $mainMenu_Global,
                              $mainMenu_Style,
                              $mainMenu_Conf,
                              $mainMenu_Item )
{
  /*  declara as variáveis Globais  */
  $arr = array( 
    $mainMenu . '_Item_lang',
  );
  foreach( $arr as $_i => $ref )
  {  
    global $$ref;
  }
//writeTO"<pre>";print_r($mainMenu1_Item_lang);exit;

  //  define o Idioma dos Itens  ------------------------------------------  //
  $tmp     = $mainMenu . '_Item_lang';
  $arrLang = $$tmp;

//  $font        = imageloadfont("fonts/9x15iso.gdf");
//  $width_char  = ImageFontWidth($font);
//  $height_char = ImageFontHeight($font);
  $width_char  = 9;
  $height_char = 16;

  $top = $mainMenu_Global['top'];
  $left = $mainMenu_Global['left'];

  
  //  Calcula o tamanho da área do Menu  ----------------------------------  //
  if ( $mainMenu_Conf['tipo'] == 'horizontal' )
  {
    $nc = 0;
    
    foreach( $mainMenu_Item as $ite_ => $status_ )
    {
      $str_ = $arrLang[$ite_]; 
      $nc += strlen($str_);
      $nc += 1;  // dois espaços entre itens 
    }
    
    $width = $nc * $width_char;
    $height = $height_char + 8;
//writeTO $nc;exit;
  }else
  {
    $nc = 0;
    $nl = 0;
//    foreach( $mainMenu_Item as $ite_ => $val_ )
    foreach( $mainMenu_Item as $ite_ => $status_ )
    {
      $nl ++;
      if ( !strpos($ite_, 'separador') )
      {
        $str_ = $arrLang[$ite_]; 
        if (strlen($str_) > $nc )
          $nc = strlen($str_);
      }  
    }
    $width = ($nc +2) * $width_char;
    $height = $nl * ($height_char + 4);
  }
   
  writeTO( '  #' . $mainMenu . '{ '                                               );
  writeTO( '    position: absolute'                                      . '; '   );
  writeTO( '    top:' . $top . ''                                        . '; '   );
  writeTO( '    left:' . $left . ''                                      . '; '   );
  writeTO( '    z-index: 200'                                            . '; '   );
  writeTO( '    width:' . $width . 'px'                                  . '; '   );
  writeTO( '    height:' . $height . 'px'                                . '; '   );
  writeTO( '    overflow: hidden'                                        . '; '   );
  writeTO( '    visibility:'.$mainMenu_Global['visible']                 . '; '   );
//  writeTO( '    color:'                . $mainMenu_Global['color']       . '; '   );
  writeTO( '    background-color:'     . $mainMenu_Global['bgcolor']     . '; '   );
  writeTO( '    font-family:'          . $mainMenu_Global['fontFamily']  . '; '   );
  writeTO( '    font-size:'            . $mainMenu_Global['fontSize']    . '; '   );
  writeTO( '    '                                                                 );
  writeTO( '    border-top:'           . $mainMenu_Style['borderTop']    . '; '   );
  writeTO( '    border-bottom:'        . $mainMenu_Style['borderBottom'] . '; '   );
  writeTO( '    border-left:'          . $mainMenu_Style['borderLeft']   . '; '   );
  writeTO( '    border-right:'         . $mainMenu_Style['borderRight']  . '; '   );
  writeTO( '  } '                                                                 );
  writeTO( ' '                                                                    );

  /**
   *  CSS dos Itens do Menu  ----------------------------------------------  //  
   */
  $spc_item = 1.5 * $width_char;
  
  if( $mainMenu_Conf['tipo'] == 'horizontal' )
  {
    $top      = 0;
    $left     = 0;
  }else
  {
    $top      = 5;
    $left     = 5;
  }
  $left_old = $spc_item;
  
  foreach( $mainMenu_Item as $val_ => $status_ )
  {
//writeTO($val_);
    if ( strpos($val_, 'separador' ) )
    {
      $str = "";
      $top  -=  5;
    }else
    {
      $str = $arrLang[$val_];
    }
       
    $nr_char = ( $mainMenu_Conf['tipo'] == 'horizontal' ) ? (strlen( $str ) -2) : $nc;
    $comp = ($nr_char * $width_char) -3;
    $color = ( $status_ >= 1 ) ? $mainMenu_Global['color'] : '#414141';

    if ( strpos($val_, 'separador' ) )
    {
      //$top += 5;
      writeTO( '  #' . $mainMenu . $val_ . '{ '                                            );
      writeTO( '    position: absolute'                                           . '; '   );
      writeTO( '    top:' . $top           . 'px; '                                        );
      writeTO( '    left:' . ($left + 5) . 'px'                                         . '; '   );
      writeTO( '    width:' . $comp . 'px'                                        . '; '   );
      writeTO( '    height:' . $height_char . 'px'                                . '; '   );
      writeTO( '    visibility:inherit'                                           . '; '   );
      writeTO( '  } '                                                                      );
      writeTO( ' '                                                                         );
    }else
    {
      writeTO( '  #' . $mainMenu . $val_ . '{ '                                            );
      writeTO( '    position: absolute'                                           . '; '   );
      writeTO( '    top:' . $top           . 'px; '                                        );
      writeTO( '    left:' . $left . 'px'                                         . '; '   );
      writeTO( '    width:' . $comp . 'px'                                        . '; '   );
      writeTO( '    height:' . $height_char . 'px'                                . '; '   );
      writeTO( '    visibility:inherit'                                           . '; '   );
      writeTO( '    color:' . $color       . '; '   );
      writeTO( '    font-family:inherit'                                          . '; ' );
      writeTO( '    font-size:inherit'                                            . '; '   );
      writeTO( '    padding-top:'             . $mainMenu_Global['spaceItemTop']  . '; '   );
      writeTO( '    padding-left:'            . $mainMenu_Global['spaceItemLeft'] . '; '   );
      writeTO( '    padding-right:'           . $mainMenu_Global['spaceItemLeft'] . '; '   );
      writeTO( '    border-top:1px solid '    . $mainMenu_Global['bgcolor']       . '; '   );
      writeTO( '    border-bottom:1px solid ' . $mainMenu_Global['bgcolor']       . '; '   );
      writeTO( '    border-left:  1px solid ' . $mainMenu_Global['bgcolor']       . '; '   );
      writeTO( '    border-right: 1px solid ' . $mainMenu_Global['bgcolor']       . '; '   );
      writeTO( '  } '                                                                      );
      writeTO( ' '                                                                         );
    }// End 
    
    if ( $mainMenu_Conf['tipo'] == 'horizontal' )
    {
      $left = $comp + $left_old;
      $left_old = $left + $spc_item;
    }else
    {
      if ( strpos($val_, 'separador' ) )
      {
        $top += $height_char;
      }else
      {
        $top += $height_char + 2;
      } 
    }// End 
     
  }// End 
  
}// End function()  


function create_mainMenu_config( $modo_RAD )
{
  global $componentes_no_Prj;

  $path  = ( $modo_RAD )? _CFG_ : CFG;
  $nDest = $path . "mainMenu.config.php";
  
  $fp = @fopen( $nDest, 'wb' );
  foreach( $componentes_no_Prj as $comp_ => $obj_ )
  {
    if( $comp_ == 'mainMenu' )
    {
      $nrObj  = 0;
      $arrObj = array();
      $arrSub = array();
      
      foreach( $obj_ as $i_ => $v_ )
      {
        if ( substr( $i_, 0, strlen($i_)-1 ) == "mainMenu" )
        {
          $arrObj[ $nrObj ] = $i_;
          $nrObj ++;
        }else
        {
          $arrSub[] = $i_;  
        }// End if()
      }// End foreach()
 
      writeTO( "mainMenu_obj       = ". $nrObj .";", $fp );
      writeTO( "mainMenu_selected  = new Array();" , $fp );
      writeTO( "mainMenu_nrItens   = new Array();" , $fp );
      writeTO( "mainMenu_status    = new Array();" , $fp );
      writeTO( "mainMenu_subMenu   = new Array();" , $fp );
      writeTO( "mainMenu_subStatus = new Array();" , $fp );
      writeTO( "  "                                , $fp );
      
      for( $ix = 0; $ix < $nrObj; $ix ++)
      {
        $tmp = $arrObj[ $ix ]; 
        include( CFG . $tmp . ".config.item.php" );

        $tmp1 = $tmp . "_Item";
        $arrItem = $$tmp1;

        $tmp2 = $tmp . "_SubMenu";
        $arrSub = $$tmp2;


        writeTO( "mainMenu_selected[".$ix."] = 0;"                       , $fp );
        writeTO( "mainMenu_nrItens[".$ix."]  = " . count($arrItem) . ";" , $fp );
        
        writeTO( "  "                                                    , $fp );
        writeTO( "mainMenu_status[".$ix."]  = new Array();  "            , $fp );
        $ixs = 0;
        foreach( $arrItem as $val_ => $status_ )
        {
          writeTO( "mainMenu_status[".$ix."][".$ixs."] = " . $status_.";", $fp );
          $ixs ++;
        }

        writeTO( "  "                                                    , $fp );
        writeTO( "mainMenu_subMenu[".$ix."]  = new Array();  "           , $fp );
        $ixs = 0;
        foreach( $arrSub as $val_ => $indice_ )
        {
          writeTO( "mainMenu_subMenu[".$ix."][".$ixs."] = " . $indice_.";", $fp );
          $ixs ++;
        }

        writeTO( "  "                                                    , $fp );
        writeTO( "mainMenu_subStatus[".$ix."]  = new Array();  "           , $fp );
        $ixs = 0;
        foreach( $arrSub as $val_ => $indice_ )
        {
          if ( $indice_ > 0 )
          {
            writeTO( "mainMenu_subStatus[".$ix."][".$ixs."] = new Array();", $fp );
          
            $tmp = 'subMenu' . $indice_;
            include( CFG . $tmp . ".config.item.php" );
          
            $tmp .= '_Item';
            $arrSubItem = $$tmp;
          
            $is_ = 0;
            foreach( $arrSubItem as $v_ => $stat_ )
            {
              if ( !strpos($v_, 'separador') )
              {
                writeTO( "mainMenu_subStatus[".$ix."][".$ixs."][".$is_."] = ".$stat_.";", $fp );
              $is_ ++;
              }
            }
            writeTO( "  "                                                  , $fp );
          }// End if()
          $ixs ++;
        }//End foreach()
      }// End for()
      writeTO( "  ", $fp );
      break;
    }//end if()
  }// End foreach()
  fclose( $fp );
  
  return( $nDest );    
}// End function 



function create__mainMenu_config( $modo_RAD )
{
  global $componentes_no_Prj;

  $path  = ( $modo_RAD )? _CFG_ : CFG;
  $nDest = $path . "mainMenu.config.php";

  $fp = @fopen( $nDest, 'wb' );
  foreach( $componentes_no_Prj as $comp_ => $obj_ )
  {
    if( $comp_ == 'mainMenu' )
    {
      $nrObj  = 0;
      $arrObj = array();
      $arrSub = array();

      foreach( $obj_ as $i_ => $v_ )
      {
        if ( substr( $i_, 0, strlen($i_)-1 ) == "mainMenu" )
        {
          $arrObj[ $nrObj ] = $i_;
          $nrObj ++;
        }else
        {
          $arrSub[] = $i_;
        }// End if()
      }// End foreach()

      writeTO( "mainMenu_obj      = ". $nrObj .";", $fp );
      writeTO( "mainMenu_selected = new Array();" , $fp );
      writeTO( "mainMenu_nrItens  = new Array();" , $fp );
      writeTO( "mainMenu_status   = new Array();" , $fp );
      writeTO( "mainMenu_subMenu  = new Array();" , $fp );
      writeTO( "subMenu_status    = new Array();" , $fp );
      writeTO( "  "                               , $fp );

      for( $ix = 0; $ix < $nrObj; $ix ++)
      {
        $tmp = $arrObj[ $ix ];
        include( CFG . $tmp . ".config.item.php" );

        $ind = 'subMenu'.substr($tmp, strlen($tmp)-1, 1);

        $tmp .= "_Item";
        $arrItem = $$tmp;
        $subMenu = ( array_search($ind, $arrSub ) === false )? 0: 1;

        writeTO( "mainMenu_selected[".$ix."] = 0;"                       , $fp );
        writeTO( "mainMenu_nrItens[".$ix."]  = " . count($arrItem) . ";" , $fp );
        writeTO( "mainMenu_subMenu[".$ix."]  = " . $subMenu        . ";" , $fp );
        writeTO( "  "                                                    , $fp );
        writeTO( "mainMenu_status[".$ix."]  = new Array();  "            , $fp );

        $ixs = 0;
        foreach( $arrItem as $val_ => $status_ )
        {
          writeTO( "mainMenu_status[".$ix."][".$ixs."] = " . $status_.";", $fp );
          $ixs ++;
        }

        if ( $subMenu == 1 )
        {
          writeTO( "  ", $fp );
          $tmp = "subMenu" . ($ix +1);
          include( CFG . $tmp . ".config.item.php" );

          $tmp .= "_Item";
          $arrItem = $$tmp;
          // echo(CFG . $tmp . ".config.item.php" );exit;
          writeTO( "subMenu_status[".$ix."]  = new Array();  "            , $fp );

          $ixs = 0;
          foreach( $arrItem as $val_ => $status_ )
          {
            if( strpos($val_, 'separador') == false )
            {
              writeTO( "subMenu_status[".$ix."][".$ixs."] = " . $status_ . ";", $fp );
              $ixs ++;
            }// End if()
          }// End foreach()
        }// End if()

      }// End for()
      writeTO( "  ", $fp );
      break;
    }//end if()
  }// End foreach()
  fclose( $fp );

  return( $nDest );
}// End function




?>
