<?php

function create_edit( $edit,
                      $edit_Conf )
{
  if( $edit_Conf['enabled'] == 'true' )
  {
      $enabled = "";
  }else
  {
      $enabled = "disabled";
  }// End if( $edit_Conf['enabled'] == 'true' )

  if( $edit_Conf['caption'] == 'auto' )
  {
    $label = $edit;
  }else
  {
    $label = $edit_Conf['caption'];
  }// End if( $edit_Conf['caption'] == 'auto' )
  

  if ( $edit_Conf[ 'alt_key' ] == 'null' )
  {
    $alt_key = '';
  }else
  {
    $alt_key = $edit_Conf[ 'alt_key' ];
    $ix = strpos( $label, $alt_key );
    $label = substr( $label, 0, $ix ) . '<span id="'.$edit.'_key">'.$alt_key.'</span>' . substr( $label, $ix+1 );
  }//End if ( $edit_Conf[ 'alt_key' ] == 'null' )
  
  if( $edit_Conf['tab_index'] == 'auto' )
  {
    $tab_index = '';
  }else
  {
    $tab_index = $edit_Conf['tab_index'];
  }//End if( $edit_Conf['tab_index'] == 'auto' )
  
  writeTO( '<label id="'.$edit.'_Caption" '                      );
  writeTO( '       class="edit_Caption" '                        );
  writeTO( '       for="'.$edit.'_Input" '                       );
  writeTO( '       accesskey="' . $alt_key . '"'                 );
  writeTO( '       ' .$enabled. '>'                              );
  writeTO( '       ' . $label . '</label>'                            );
  writeTO( '<input id="' . $edit . '_Input"  '                   );
  writeTO( '       type="text" '                                 );
  writeTO( '       tipoCampo="'.$edit_Conf['tipo_campo'].'" '    );
  writeTO( '       tipoDado="'.$edit_Conf['tipo_dado'].'" '      );
  writeTO( '       value="'.$edit_Conf['valor'].'" '             );
  writeTO( '       class="edit_Input" '                          );
  writeTO( '       tab_index="'.$tab_index.'" '                  );
  writeTO( '       maxlength="'. $edit_Conf['max_len'].'"'       );
  writeTO( '       ' .$enabled. '/>'                             );

}// End create_edit()


/**
 *
 */
function create_edit_css( $edit,
                          $edit_Global,
                          $edit_Style,
                          $edit_Conf,
                          $flagEdit )
{
  if( defined('STUDIO') )
  {
    $visible = 'visible';
  }else
  {
    $visible = ($edit_Conf['visibility'] == 'true' ) ? 'inherit':'hidden';
  }// End if( defined('STUDIO') )
  $paddingTop = 3;
  $paddingBottom = 0;
  $paddingLeft = 5;

  //$lenLabel    = ($edit_Global['width'] /2) - ($paddingTop + $paddingLeft);
  //$lenInput    = ($edit_Global['width'] - $lenLabel)-10;
  //$initInput   = ($lenLabel + $paddingTop + $paddingLeft) -2;

  $lenLabel    = $edit_Conf['label_len'];
  $lenInput    = $edit_Conf['input_len'];
  $initInput   = ($lenLabel) -5;
  $colorBorder = '#808080';

  $cor_borderLeft  = $edit_Global['cor_borderLeft'];
  $cor_borderRight = $edit_Global['cor_borderRight'];

  if( $edit_Conf['font_size'] == 'auto' )
  {
    $fontSize = $edit_Global['fontSize'];
  }else
  {
    $fontSize = $edit_Conf['font_size'];
  }// End if( $edit_Conf['font_size'] == 'auto' )
  
  writeTO( '  #' . $edit . '{ '                                          );
  writeTO( '    position:absolute;'                                      );
  writeTO( '    top:' . $edit_Global['top'] . 'px'                 . ';' );
  writeTO( '    left:' . $edit_Global['left'] . 'px'               . ';' );
  writeTO( '    '                                                        );
  writeTO( '    z-index:10;'                                             );
  writeTO( ''                                                            );
  writeTO( '    width:' . $edit_Global['width'] . 'px'             . ';' );
  writeTO( '    height:' . $edit_Global['height'] . 'px'           . ';' );
  writeTO( '    '                                                        );
  writeTO( '    padding-top:' . $paddingTop . 'px;'                      );
  writeTO( '    padding-bottom:' . $paddingBottom . 'px;'                );
  writeTO( '    '                                                        );
  writeTO( '    color:' . $edit_Conf['font_color']                 . ';' );
  writeTO( '    background-color:' . $edit_Conf['back_ground']     . ';' );
  writeTO( '    '                                                        );
  writeTO( '    visibility:'.$visible.';'                                );
  writeTO( '    '                                                        );
  writeTO( '    border-top:'    . $edit_Style['borderTop']         . ';' );
  writeTO( '    border-bottom:' . $edit_Style['borderBottom']      . ';' );
  writeTO( '    border-left:'   . $edit_Style['borderLeft']        . ';' );
  writeTO( '    border-right:'  . $edit_Style['borderRight']       . ';' );
  writeTO( '  }'                                                         );
  writeTO( '  '                                                          );
  writeTO( '  #' . $edit . '_Caption{ '                                  );
  writeTO( '    position:absolute;'                                      );
  writeTO( '    top:0px'                                           . ';' );
  writeTO( '    left:0px'                                          . ';' );
  writeTO( '    '                                                        );
  writeTO( '    font-size:' . $fontSize . 'px'   . ';' );
  writeTO( '    width:'.$lenLabel . 'px'                           . ';' );
  writeTO( '    height:' . $edit_Global['height'] . 'px'           . ';' );
  writeTO( '  }'                                                         );
  writeTO( '  '                                                          );
  writeTO( '  #' . $edit . '_Input{ '                                    );
  writeTO( '    position:absolute'                                 . ';' );
  writeTO( '    top:0px'                                           . ';' );
  writeTO( '    left:'.$initInput.'px'                             . ';' );
  writeTO( '    '                                                        );
  writeTO( '    font-size:' . $fontSize . 'px'                     . ';' );
  writeTO( '    width:'.$lenInput . 'px'                           . ';' );
  writeTO( '    height:' . $edit_Global['height'] . 'px'           . ';' );
  writeTO( '    border-top:'    . $edit_Style['borderTopInput']    . ';' );
  writeTO( '    border-bottom:' . $edit_Style['borderBottomInput'] . ';' );
  writeTO( '    border-left:'   . $edit_Style['borderLeftInput']   . ';' );
  writeTO( '    border-right:'  . $edit_Style['borderRightInput']  . ';' );
  writeTO( '  }'                                                         );
  writeTO( '  #' . $edit . '_key{ '                                      );
  writeTO( '    text-decoration:underline;'                              );
  writeTO( '  }'                                                         );
  writeTO( '  '                                                          );

  if ( $flagEdit )
  {
    writeTO( '  .edit_Caption{ '                                      );
    writeTO( '    font-family:' .$edit_Global['fontFamily']     . ';' );
    writeTO( '    padding-top:'. $paddingTop .'px'              . ';' );
    writeTO( '    padding-left:'. $paddingLeft .'px'            . ';' );
    writeTO( '    '                                                   );
    writeTO( '    overflow:hidden'                              . ';' );
    writeTO( '    '                                                   );
    writeTO( '    visibility:inherit'                           . ';' );
    writeTO( '    '                                                   );
    writeTO( '    border-top:0px solid #FFFFFF'                 . ';' );
    writeTO( '    border-bottom:0px solid #FFFFFF'              . ';' );
    writeTO( '    border-left:0px solid #FFFFFF'                . ';' );
    writeTO( '    border-right:1px outset ' . $cor_borderRight  . ';' );
    writeTO( '  }'                                                    );
    writeTO( '  '                                                     );
    writeTO( '  .edit_Input{ '                                        );
    writeTO( '    font-family:' .$edit_Global['fontFamily']     . ';' );
    writeTO( '    '                                                   );
    writeTO( '    background-color:#FFFFFF'                     . ';' );
    writeTO( '    visibility:inherit'                           . ';' );
    writeTO( '    '                                                   );
    writeTO( '    border-top:0px solid #FFFFFF'                 . ';' );
    writeTO( '    border-bottom:0px solid #FFFFFF'              . ';' );
    writeTO( '    border-left:1px solid ' . $cor_borderLeft     . ';' );
    writeTO( '    border-right:0px solid #FFFFFF'               . ';' );
    writeTO( '  }'                                                    );
  }//end if()
  writeTO( '   '                                                      );
}// End create_edit_css()

function create_edit_control( $modo_RAD )
{
  global $projeto,
         $esquema,
         $componentes_no_Prj;
 
  $comp_no_Prj = $componentes_no_Prj;
  $path  = ( $modo_RAD )? _CFG_ : CFG;
  $nDest = $path . "edit.control.js.php";

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

      foreach( $obj_ as $i_ => $v_ )
      {
        $arrObj[ $nrObj ] = $i_;
        $nrObj ++;
      }// End foreach()

      writeTO( "edit_obj      = ". $nrObj .";", $fp );
      writeTO( "edit_selected = new Array();"         , $fp );
      writeTO( "edit_bgcolor  = new Array();", $fp );


      for( $ix = 0; $ix < $nrObj; $ix ++)
      {
        $tmp = $arrObj[$ix];
        include( _CFG_ . $tmp . ".config.def.php" );
        include( _CFG_ . $tmp . ".config.php" );
        
        $glo_ = $tmp . '_Global';
        $arrGlo = $$glo_;

        writeTO( "edit_selected[" . $ix . "] = 0;"         , $fp );
        writeTO( "edit_bgcolor["  . $ix . "] = '".$arrGlo['bgcolor']."';", $fp );
        writeTO( "  "                                                 , $fp );

      }// End for()

      writeTO( "  ", $fp );

    }// End if()
    
  }// End foreach()
  fclose( $fp );

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


?> 
