<?php
function create_dbtext( $dbtext,
                        $dbtext_Conf )
{
  $path  = ( defined( 'STUDIO' ) )? _CFG_ : _CFG_;
  $dataSet = '';

  if( $dbtext_Conf['enabled'] == 'true' )
  {
    $enabled = "";
  }else
  {
    if( defined('STUDIO') )
    {
      $enabled = '';
    }else
    {
      $enabled = "disabled";
    }// End
  }// End if( $dbtext_Conf['enabled'] == 'true' )

  if( $dbtext_Conf['tab_index'] == 'auto' )
  {
    $tab_index = '';
  }else
  {
    $tab_index = $dbtext_Conf['tab_index'];
  }//End if( $dbtext_Conf['tab_index'] == 'auto' )

  if( $dbtext_Conf['readonly'] == 'false' )
  {
    $readonly = '';
  }else
  {
    $readonly = 'readonly';
  }//End if( $dbEdit_Conf['readonly'] == 'false' )

  if( $dbtext_Conf['cols'] == 'auto' )
  {
    $cols = '';
  }else
  {
    $cols = $dbtext_Conf['cols'];
	}// End if( $dbtext_Conf['cols'] == 'auto' )

  if( $dbtext_Conf['rows'] == 'auto' )
  {
    $rows = '';
  }else
  {
    $rows = $dbtext_Conf['rows'];
	}// End if( $dbtext_Conf['rows'] == 'auto' )


/**
 *  definição do Caption  --------------------------------------------------  //
 */
  if( $dbtext_Conf['caption'] == 'auto' )
  {
    if( empty($dbtext_Conf['data_set'] ) )
    {
      $label = $dbtext;
    }else
    {
      $dataSet = $dbtext_Conf['data_set'];
      $nFile_dataSet = $path . $dataSet . ".config.data.ini";

      if( file_exists( $nFile_dataSet ) )
      {
        $arrINI_dataSet = readINIfile( $nFile_dataSet );
        if( empty( $arrINI_dataSet[ $dataSet . '_data' ]['datasource'] ) )
        {
          echo('erro: dataSet não Configurado..');exit;
        }else
        {
          $flagDTS = true;
          $_dataSource_ = $arrINI_dataSet[ $dataSet . '_data' ]['datasource'];
          $_dataTabela_ = $arrINI_dataSet[ $dataSet . '_data' ]['tabela'];


        }// End if( empty( $arrINI[ $dataSet . '_data' ]['datasource'] ) )

        echo"ok".$_dataTabela_;
      }else
      {
        echo"erro";
      }// End if( file_exists( $nFile_dataSet ) )
      exit;
    }// end if( empty($dbtext_Conf['data_set'] ) )
  }else
  {
    $label = $dbtext_Conf['caption'];
  }// End if( $dbtext_Conf['caption'] == 'auto' )


  if ( $dbtext_Conf[ 'alt_key' ] == 'null' || $dbtext_Conf[ 'caption' ] == '' )
  {
    $alt_key = '';
  }else
  {
    $alt_key = $dbtext_Conf[ 'alt_key' ];
    $ix = strpos( $label, $alt_key );
    if( $ix === false )
    {
      $alt_key = '';
    }else
    {
      $label = substr( $label, 0, $ix ) . '<span id="'.$dbtext.'_key">'.$alt_key.'</span>'. substr( $label, $ix + 1 );
    }// End if( $ix === false )
  }//End if ( $dbtext_Conf[ 'alt_key' ] == 'null' )


  global $_desenv_;
  $path_img = "http://";

  writeTO( '<label id="'.$dbtext.'_Caption"  for="'.$dbtext.'_Texto"        ' );
  writeTO( '     accesskey="'.$alt_key.'" '.$enabled.'>                     ' );
  writeTO( '                               '. $label .  '</label>           ' );
  writeTO( '  <textarea id="' . $dbtext . '_Texto"  cols="'.$cols.'"        ' );
  writeTO( '     rows="'.$rows.'" '.$enabled. ' tabindex="'.$tab_index.'"   ' );
  writeTO( '       tipoCampo="'.$dbtext_Conf['tipo_field'].'"               ' );
  writeTO( '       tipoDado="'.$dbtext_Conf['tipo_dado'].'">                ' );
  writeTO( '  </textarea>                                                   ' );


}// End create_dbText()


/**
 *
 */
function create_dbtext_css( $dbtext,
                            $dbtext_Global,
                            $dbtext_Style,
			                      $dbtext_Conf )
{
  global $projeto,
         $esquema,
         $modo_RAD;

  if( $modo_RAD )
  {
    $visible = 'inherit';
  }else
  {
    $visible = ( $dbtext_Global['visibility'] == 'true' ) ? 'inherit':'hidden';
  }// End if( $modo_RAD )

//  $font_color = ( $dbtext_Global['color'] == 'auto' ) ? 'inherit':'hidden';

  $paddingTop = 3;
  $paddingBottom = 0;
  $paddingLeft = 5;
  $cor_borderRight = '#808080';


  $lenLabel = $dbtext_Conf['label_len'];
  $initArea = ( $lenLabel + 15 );
  $topIcone = 1;
  $leftIcone = $dbtext_Global['width'] - 17;


  $topTexto = 0;
  $widthTexto = $dbtext_Global['width'];
  $heightTexto = $dbtext_Global['height'];

  $topBox = ( $topTexto + $heightTexto ) + 4;
  $leftBox = $dbtext_Global['left'];

  if ( $dbtext_Conf['back_ground'] == 'auto' )
  {
    $backGround = '#FFFFFF';
  }else
  {
    $backGround = $dbtext_Conf['back_ground'];
  }// End if ( $dbText_Conf['back_ground'] == 'auto' )

//  echo( $cols . " " . $rows );exit;
  writeTO('  #' . $dbtext . '{'                                       );
  writeTO('    position:absolute;'                                      );
  writeTO('    top:' . $dbtext_Global['top'] . 'px;'                  );
  writeTO('    left:' . $dbtext_Global['left'] .'px;'                 );
  writeTO('    '                                                        );
  writeTO('    z-index:10;'                                             );
  writeTO('    '                                                        );
  writeTO('    width:'  . ( $dbtext_Global['width'] + $lenLabel - 5 ). 'px;' );
  writeTO('    height:' . ( $dbtext_Global['height'] + 30 ).  'px;'   );
  writeTO('    '                                                        );
  writeTO('    color:' . $dbtext_Global['color'] .               ';'  );
  writeTO('    background-color:' . $dbtext_Global['bgcolor'] .  ';'  );
  writeTO('    '                                                        );
  writeTO('    overflow:hidden;'                                        );
  writeTO('    '                                                        );
  writeTO('    visibility: ' .$visible. ';'                             );
  writeTO('    '                                                        );
  writeTO('    border-top:'    . $dbtext_Style['borderTop']    . ';'  );
  writeTO('    border-bottom:' . $dbtext_Style['borderBottom'] . ';'  );
  writeTO('    border-left:'   . $dbtext_Style['borderLeft']   . ';'  );
  writeTO('    border-right:'  . $dbtext_Style['borderRight']  . ';'  );
  writeTO('  }'                                                         );
  writeTO('  '                                                          );
  writeTO('  #' . $dbtext . '_Texto{'                                 );
  writeTO('    position:absolute;'                                      );
  writeTO('    top:' . $topTexto . 'px;'                                );
  writeTO('    left:' . $initArea .  'px;'                              );
  writeTO('  '                                                          );
  writeTO('    z-index:10;'                                             );
  writeTO('  '                                                          );
  writeTO('    font-family:courier new;'                                );
  writeTO('    font-size:' . $dbtext_Global['fontSize'] .  'px;'      );
  writeTO('    padding-top:1px;'                                        );
  writeTO('    padding-left:3px;'                                       );
  writeTO('  '                                                          );
  writeTO('    color:' . $dbtext_Global['color'] .              ';'   );
  writeTO('    background-color:' . $backGround . ';'                   );
  writeTO('    visibility: inherit;'                                    );
  writeTO('  '                                                          );
//  writeTO('    border-top: 0px; '                                       );
//  writeTO('    border-bottom:0px;'                                      );
//  writeTO('    border-left:0px;'                                        );
//  writeTO('    border-right:0px;'                                       );
  writeTO('  }'                                                         );
  writeTO('  '                                                          );
  writeTO( '  #' . $dbtext . '_Caption{ '                             );
  writeTO( '    position:absolute;'                                     );
  writeTO( '    top:0px'                                         . ';'  );
  writeTO( '    left:0px'                                        . ';'  );
  writeTO( '  '                                                         );
  writeTO( '    font-size:' . $dbtext_Global['fontSize'] . 'px;'      );
  writeTO( '    width:' . $lenLabel . 'px'                        . ';' );
  writeTO( '    height:' . $dbtext_Global['height'] . 'px'      . ';' );
  writeTO( '  }'                                                        );
  writeTO( '  '                                                         );
  writeTO( '  #' . $dbtext . '_key{ '                                 );
  writeTO( '    text-decoration:underline;'                             );
  writeTO( '  }'                                                        );
}// End create_dbtext()


 function create_dbtext_control( $modo_RAD )
 {
    global $componentes_no_Prj,
           $projeto,
           $esquema;

    //$path  = ( $modo_RAD )? CFG : _CFG_;
    $path  = ( defined('STUDIO') )? _CFG_ : _CFG_;
    $nDest = $path . "dbText.control.js.php";
    $comp  = $componentes_no_Prj;

    $fp = @fopen( $nDest, 'wb' );
    foreach( $comp as $comp_ => $obj_ )
    {
      if( $comp_ == 'dbtext' )
      {
        $nrObj  = 0;
        $arrObj = array();
        $arrConf = array();

        /**
         *  Lista das Propriedades
         */
        $dbtext_enabled = array();

        /**
         *  conta o numero de objetos dbText no projeto
         *  e armazena os nomes de cada Objetos no
         *  array $arrObj
         */
        foreach( $obj_ as $i_ => $v_ )
        {
          $arrObj[ $nrObj ] = $i_;

          /**
           *  inclui o arquivo .config.def.php de cada Objeto
           */
          include( $path . $i_ . ".config.def.php" );
          $nConf_ = $i_ . "_Conf";
          $arrConf[$i_] = $$nConf_;

          $nrObj ++;
        }// end foreach( $obj_ as $i_ => $v_ )
        writeTO( "dbtext_obj = ". $nrObj .";", $fp );
        writeTO( "dbtext_enabled = new Array();", $fp );
        writeTO( " ", $fp );

        $idx = 0;
        foreach( $arrConf as $ind => $val)
        {
          writeTO( 'dbtext_enabled['.$idx . '] = '  . $val['enabled'] .';', $fp );
          $idx ++;
        }// End foreach($arrConf as $ind => $val)
        writeTO( " ", $fp );


      }// End if( $comp_ == 'dbtext' )
    }// End foreach( $comp as $comp_ => $obj_ )
    fclose( $fp );

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

?>
