<?php 

function create_tabControl( $tabControl,
                            $tabControl_Conf )
{
  global $componentes_no_Prj;

  $path    = _CFG_;
  $flagINI = false; // indica se config.data.ini foi lido com sucesso

  $nFile = $path . $tabControl . ".config.data.ini";
  $ix_ = strtolower($tabControl) . '_aba';
  if( file_exists( $nFile ) )
  {
    //echo "com data_set: ".$nFile;exit;
    $arrINI = readINIfile( $nFile );
    $flagINI = true;
    //echo('<pre>');print_r($arrINI);exit;
  }else
  {
    //  inicializa o TabControl
    $arrINI[ $ix_ ]['aba_1'] = 'ABA_1';

    writeINIfile( $nFile, $arrINI,';','' );
  }// End


  //echo("\n<br>$ix_<pre>");print_r($arrINI);//exit;
  $arr = $arrINI[ $ix_ ];
  $ix  = 0;
  writeTO( ' ' );
  foreach(  $arr as $ind_ => $val_ )
  {
    $ix ++;
    writeTO( '    <div id="' . $tabControl . '_ABA' . $ix . '">'            );
    writeTO( '      <label id="' . $tabControl . '_ABA'.$ix.'_LABEL">' . $val_ . '</label>' );
    writeTO( '    </div end="' . $tabControl . '_ABA' . $ix . '">'           );
  }// End foreach(  $arr as $ind_ => $val_ )
}// End create_tabControl()



function create_tabControl_css( $tabControl,
                                $tabControl_Global,
                                $tabControl_Style,
                                $tabControl_Conf,
                                $flagtabControl )
{
  /*  declara as variáveis Globais  */
  $arr = array( 
    $tabControl . '_Aba_lang',
    'esquema',
    'projeto'
  );
  foreach( $arr as $_i => $ref )
  {  
    global $$ref;
  }
  $visible = ( $tabControl_Global['visibility'] == 'visible' ) ? 'inherit':'hidden';
  $font_color = $esquema[$projeto['esquema']]['WindowText'];
  $bg_color   = $esquema[$projeto['esquema']]['ThreeDFace'];

  $path    = _CFG_;
  //  define o Idioma dos Itens  ------------------------------------------  //
  $tmp     = $tabControl . '_Aba_lang';
  $arrLang = $$tmp;
  $altura  = $tabControl_Global['height'] + 24; 

  writeTO( '  #' . $tabControl . '{ '                                 );
  writeTO( '    position:absolute;'                                   );
  writeTO( '    top:' . $tabControl_Global['top'] . 'px;'             );
  writeTO( '    left:' . $tabControl_Global['left'] . 'px;'           );
  writeTO( '    '                                                     );    
  writeTO( '    z-index:1;'                                           );
  writeTO( '    '                                                     );
  writeTO( '    overflow:hidden;'                                     );
//  writeTO( '    overflow:visible;'                                     );
  writeTO( '    '                                                     );
  writeTO( '    width:' . ($tabControl_Global['width'] +5) . 'px;'   );
  writeTO( '    height:' . ($altura +5) . 'px;'                      );
  writeTO( '    '                                                     );
  writeTO( '    background-color:' . $bg_color . ';'                  );
  writeTO( '  '                                                       );
  writeTO( '    visibility:' . $visible . ';'                         );
  writeTO( '  } '                                                     );
    
  $nFile = $path . $tabControl . ".config.data.ini";
  $ix_ = strtolower($tabControl) . '_aba';

  //  le o .ini das tab´s
  if( file_exists( $nFile ) )
  {
    $arrINI = readINIfile( $nFile );
  }else
  {
    //  inicializa o TabControl
    $arrINI[ $ix_ ]['aba_1'] = 'ABA_1';
    writeINIfile( $nFile, $arrINI,';','' );
  }// End if( file_exists( $nFile ) )

  /**
   *  monta as ABAS
   *  ---------------------------------------------------------------------  //
   */ 
  $left   = 8;
  $height = 14;
  $inc    = 10;
  $spc    = 8;  // espaço entre ABAS
  $ind_   = 0;
  
  foreach( $arrINI[$ix_] as $i_ => $v_ )
//  if(false)
  {
    if( isset($arrLang) )
    {
      $txt     = $arrLang[$v_];
    }else
    {
      $txt = $v_;
    }// End
    $len     = ( strlen($txt) * 7);
    $top     = ($ind_ == 0) ? 7 : 9;
    $z_index = ($ind_ == 0) ? 110 :10;
    
    $_color_ = ( $tabControl_Global['color'] == 'auto' ) ?
               $esquema[$projeto['esquema']]['WindowText'] :
               $tabControl_Global['color'];
               
    $borderTop    = ($ind_ == 0) ? $tabControl_Style['borderTop']:
                                 $tabControl_Style['borderTopBack'];
    $borderBottom = '2px solid ' . $esquema[$projeto['esquema']]['ActiveBorder'];
    $borderLeft   = ($ind_ == 0) ? $tabControl_Style['borderLeft']:
                                 $tabControl_Style['borderLeftBack'];                          
    $borderRight  = ($ind_ == 0) ? $tabControl_Style['borderRight']:
                                 $tabControl_Style['borderRightBack'];                          
    
    $ind_ ++;
    writeTO( '  #' . $tabControl . '_ABA' . $ind_ . '{'       );
    writeTO( '    position:absolute;'                         );
    writeTO( '    top:' . $top . 'px;'                        );
    writeTO( '    left:' . $left . 'px;'                      );
    writeTO( '    '                                           );    
    writeTO( '    z-index:' . $z_index . ';'                  );
    writeTO( '    '                                           );    
    writeTO( '    color:' . $_color_ . ';' );
    writeTO( '    '                                           );
    writeTO( '    width:' . $len . 'px;'                      );
    writeTO( '    height:' . $height . 'px;'                  );
    writeTO( '    '                                           );
    writeTO( '    font-family:verdana;'                       );
    writeTO( '    font-size:10px;'                            );
    writeTO( '    '                                           );
    writeTO( '    visibility:inherit;'                        );
    writeTO( '    '                                           );
    writeTO( '    padding-top:1px;'                           );
    writeTO( '    padding-left:8px;'                          );
    writeTO( '    padding-right:4px;'                         );
    writeTO( '    '                                           );
    writeTO( '    border-top:'    . $borderTop    . ';'       );
    writeTO( '    border-bottom:' . $borderBottom . ';'       );
    writeTO( '    border-left:'   . $borderLeft   . ';'       );
    writeTO( '    border-right:'  . $borderRight  . ';'       );
    writeTO( '  }'                                            );

    $left += ($inc + $len + $spc);  
  }// end 

  /**
   *  monta as TAB´s
   *  ----------------------------------------------------------------------  //
   */
    $top  = 24;
    $ind_ = 0;
    //if(false)
    foreach( $arrINI[$ix_] as $i_ => $v_ )
    {
      $z_index = ($ind_ == 0) ? 100 : 10;
      $ind_ ++;

      if( $tabControl_Global['color'] == 'auto' )
      {
        $_color_ = $esquema[$projeto['esquema']]['WindowText'];
      }else
      {
        $_color_ = $tabControl_Global['color'];
      }
      if( $tabControl_Global['bgcolor'] == 'auto' )
      {
        $_bgColor_ = $esquema[$projeto['esquema']]['ThreeDFace'];
      }else
      {
        $_bgColor_ = $tabControl_Global['bgcolor'];
      }

      writeTO( '  #' . $tabControl . '_TAB' . ( $ind_ ) . '{'                    );
      writeTO( '    '                                                           );
      writeTO( '    position:absolute;'                                         );
      writeTO( '    top:' . $top . 'px;'                                        );
      writeTO( '    left:0px;'                 );
      writeTO( '    '                                                           );
      writeTO( '    z-index:' . $z_index                               . ';'    );
//      writeTO( '    z-index:inherit'  . ';'    );
      writeTO( '    '                                                           );
      writeTO( '    width:' . $tabControl_Global['width']              . 'px;'  );
      writeTO( '    height:' . $tabControl_Global['height']            . 'px;'  );
      writeTO( '    '                                                           );
      writeTO( '    color:' . $_color_              . ';'    );
      writeTO( '    background-color:' . $_bgColor_. ';'    );
      writeTO( '    '                                                           );
      writeTO( '    visibility:inherit;'                                        );
      writeTO( '    '                                                           );
      writeTO( '    border-top:'    . $tabControl_Style['borderTop']    . ';'   );
      writeTO( '    border-bottom:' . $tabControl_Style['borderBottom'] . ';'   );
      writeTO( '    border-left:'   . $tabControl_Style['borderLeft']   . ';'   );
      writeTO( '    border-right:'  . $tabControl_Style['borderRight']  . ';'   );
      writeTO( '  }'                                                            );

    }// End foreach()

    
}// End function create_tabControl_css()









function create_tabControl_control( $modo_RAD )
{
  global $componentes_no_Prj;

//  $path  = _CFG_;
  $path  = ( $modo_RAD )? _CFG_ : CFG;

  $nDest = $path . "tabControl.control.js.php";

  $fp = @fopen( $nDest, 'wb' );
  foreach( $componentes_no_Prj as $comp_ => $obj_ )
  {
    if( $comp_ == 'tabControl' )
    {
      $nrObj  = 0;
      $arrObj = array();
      foreach( $obj_ as $i_ => $v_ )
      {
        $arrObj[ $nrObj ] = $i_;
        $nrObj ++;
      }// end foreach()

      writeTO( "tabControl_obj      = ". $nrObj .";", $fp );
      writeTO( "tabControl_selected = new Array();" , $fp );
      writeTO( "tabControl_nrTabs   = new Array();" , $fp );
      writeTO( "  "       , $fp );

      for( $ix = 0; $ix < $nrObj; $ix ++)
      {
        $tmp = $arrObj[$ix];
        if( file_exists( $path . $tmp . ".config.aba.php" ) )
        {
          //
          //  versão antiga de inclusão de abas
          //
          include( $path . $tmp . ".config.aba.php" );
          //echo $tmp . ".config.aba.php";
          $tmp .= "_Aba";
          $arr = $$tmp;
        }else
        {
          $nFile = $path . $tmp . ".config.data.ini";
          $ix_ = strtolower($tmp) . '_aba';
          $arrINI = readINIfile( $nFile );

          $arr = $arrINI[$ix_];
        }// End
        
        writeTO( "tabControl_selected[".$ix."] = 1;"       , $fp );
        writeTO( "tabControl_nrTabs[".$ix."]   = ".count($arr) .";"       , $fp );
        writeTO( "  "       , $fp );
      }// End for()
      writeTO( "  "       , $fp );
      break;
    }// End if()
  }// End foreach()
  fclose( $fp );

  return( $nDest );
}// End function()

function create_tabControl_config( $modo_RAD )
{
  global $componentes_no_Prj;

  $path  = ( $modo_RAD )? _CFG_ : CFG;
  $nDest = $path . "tabControl.config.php";
  
  $fp = @fopen( $nDest, 'wb' );
  foreach( $componentes_no_Prj as $comp_ => $obj_ )
  {
    if( $comp_ == 'tabControl' )
    {
      $nrObj  = 0;
      $arrObj = array();
      foreach( $obj_ as $i_ => $v_ )
      {
        $arrObj[ $nrObj ] = $i_;
        $nrObj ++;
      }// end foreach()
       
      writeTO( "tabControl_obj      = ". $nrObj .";", $fp );
      writeTO( "tabControl_selected = new Array();"       , $fp );
      writeTO( "tabControl_nrTabs   = new Array();"       , $fp );
      writeTO( "  "       , $fp );
      for( $ix = 0; $ix < $nrObj; $ix ++)
      {
        $tmp = $arrObj[$ix]; 
        include( $path . $tmp . ".config.aba.php" );
        // echo $tmp . ".config.aba.php";
        $tmp .= "_Aba";
        $arr = $$tmp;
   
        writeTO( "tabControl_selected[".$ix."] = 1;"       , $fp );
        writeTO( "tabControl_nrTabs[".$ix."]   = ".count($arr) .";"       , $fp );
        writeTO( "  "       , $fp );
      }// End for()
      writeTO( "  "       , $fp );
      break;
    }// End if()
  }// End foreach() 
  fclose( $fp );
  
  return( $nDest );
}// End function()




function create_tabControl_old( $tabControl,
                            $tabControl_Aba )
{
  $tmp = $tabControl . "_Aba_lang";
  global $componentes_no_Prj, $$tmp;
  $lang = $$tmp;

//echo("\n<br><pre>");print_r($tabControl_Aba);exit;
  foreach( $tabControl_Aba as $ind_ => $val_ )
  {
    $ix = $ind_ +1;
    writeTO( '  <div id="'.$tabControl.'_ABA'.$ix.'">'  );
    writeTO( '    '.$lang[$val_]                         );
    writeTO( '  </div end="'.$tabControl.'_ABA'.$ix.'">' );
  }
}// End create_tabControl_old()

function create_tabControl_css_old( $tabControl,
                                $tabControl_Global,
                                $tabControl_Style,
                                $tabControl_Conf,
                                $tabControl_Aba)
{
  /*  declara as variáveis Globais  */
  $arr = array(
    $tabControl . '_Aba_lang',
    'esquema',
    'projeto'
  );
  foreach( $arr as $_i => $ref )
  {
    global $$ref;
  }
  //  define o Idioma dos Itens  ------------------------------------------  //
  $tmp     = $tabControl . '_Aba_lang';
  $arrLang = $$tmp;
  $altura  = $tabControl_Global['height'] + 24;

  writeTO( '  #' . $tabControl . '{ '                                 );
  writeTO( '    position:absolute;'                                   );
  writeTO( '    top:' . $tabControl_Global['top'] . 'px;'             );
  writeTO( '    left:' . $tabControl_Global['left'] . 'px;'           );
  writeTO( '    '                                                     );
  writeTO( '    z-index:1;'                                          );
  writeTO( '    '                                                     );
  writeTO( '    width:' . $tabControl_Global['width'] . 'px;'         );
  writeTO( '    height:' . $altura . 'px;'                            );
  writeTO( '    '                                                     );
  writeTO( '    visibility:' . $tabControl_Global['visibility'] . ';' );
  writeTO( '  } ');

  /**
   * monta as TAB´s  ------------------------------------------------------  //
   */
  if( isset($tabControl_Aba) )
  {
    $top = 24;
    foreach( $tabControl_Aba as $i_ => $v_ )
    {
      $z_index = ($i_ == 0) ? 100 : 10;

      writeTO( '  #' . $tabControl . '_TAB' . ($i_ +1) . '{'                    );
      writeTO( '    '                                                           );
      writeTO( '    position:absolute;'                                         );
      writeTO( '    top:' . $top . 'px;'                                        );
      writeTO( '    left:0px;'                 );
      writeTO( '    '                                                           );
      writeTO( '    z-index:' . $z_index                               . ';'    );
//      writeTO( '    z-index:inherit'  . ';'    );
      writeTO( '    '                                                           );
      writeTO( '    width:' . $tabControl_Global['width']              . 'px;'  );
      writeTO( '    height:' . $tabControl_Global['height']            . 'px;'  );
      writeTO( '    '                                                           );
      writeTO( '    color:' . $tabControl_Global['color']              . ';'    );
      writeTO( '    background-color:' . $tabControl_Global['bgcolor'] . ';'    );
      writeTO( '    '                                                           );
      writeTO( '    visibility:inherit;'                                        );
      writeTO( '    '                                                           );
      writeTO( '    border-top:'    . $tabControl_Style['borderTop']    . ';'   );
      writeTO( '    border-bottom:' . $tabControl_Style['borderBottom'] . ';'   );
      writeTO( '    border-left:'   . $tabControl_Style['borderLeft']   . ';'   );
      writeTO( '    border-right:'  . $tabControl_Style['borderRight']  . ';'   );
      writeTO( '  }'                                                            );

    }// End foreach()

  }// End

  /**
   *  monta as ABAS  ------------------------------------------------------  //
   */
  $left   = 8;
  $height = 14;
  $inc    = 10;
  $spc    = 8;  // espaço entre ABAS
  foreach( $tabControl_Aba as $i_ => $v_ )
  {
    $txt     = $arrLang[$v_];
    $len     = ( strlen($txt) * 7);
    $top     = ($i_ == 0) ? 7 : 9;
    $z_index = ($i_ == 0) ? 110 :10;

    $borderTop    = ($i_ == 0) ? $tabControl_Style['borderTop']:
                                 $tabControl_Style['borderTopBack'];
    $borderBottom = '2px solid ' . $esquema[$projeto['esquema']]['ActiveBorder'];
    $borderLeft   = ($i_ == 0) ? $tabControl_Style['borderLeft']:
                                 $tabControl_Style['borderLeftBack'];
    $borderRight  = ($i_ == 0) ? $tabControl_Style['borderRight']:
                                 $tabControl_Style['borderRightBack'];

    writeTO( '  #' . $tabControl . '_ABA' . ($i_ +1) . '{'    );
    writeTO( '    position:absolute;'                         );
    writeTO( '    top:' . $top . 'px;'                        );
    writeTO( '    left:' . $left . 'px;'                      );
    writeTO( '    '                                           );
    writeTO( '    z-index:' . $z_index . ';'                  );
    writeTO( '    '                                           );
    writeTO( '    color:' . $tabControl_Global['color'] . ';' );
    writeTO( '    '                                           );
    writeTO( '    width:' . $len . 'px;'                      );
    writeTO( '    height:' . $height . 'px;'                  );
    writeTO( '    '                                           );
    writeTO( '    font-family:verdana;'                       );
    writeTO( '    font-size:10px;'                            );
    writeTO( '    '                                           );
    writeTO( '    visibility:inherit;'                        );
    writeTO( '    '                                           );
    writeTO( '    padding-top:1px;'                           );
    writeTO( '    padding-left:8px;'                          );
    writeTO( '    padding-right:4px;'                         );
    writeTO( '    '                                           );
    writeTO( '    border-top:'    . $borderTop    . ';'       );
    writeTO( '    border-bottom:' . $borderBottom . ';'       );
    writeTO( '    border-left:'   . $borderLeft   . ';'       );
    writeTO( '    border-right:'  . $borderRight  . ';'       );
    writeTO( '  }'                                            );

    $left += ($inc + $len + $spc);
  }// end

}// End

  
?> 
