<?php
  if( isset($_REQUEST["nBrowser"]) )
  {
    session_start();
    $_SESSION["nBrowser"] = $_REQUEST["nBrowser"];
    $_SESSION["nVersao"]  = $_REQUEST["nVersao"];
    $_SESSION["nSO"]      = $_REQUEST["nSO"];
    $_SESSION["total_X"]  = $_REQUEST["total_X"];
    $_SESSION["total_Y"]  = $_REQUEST["total_Y"];
    $_SESSION["disp_X"]   = $_REQUEST["disp_X"];
    $_SESSION["disp_Y"]   = $_REQUEST["disp_Y"];
  
$uri = $_SERVER["REQUEST_URI"];
$s = strpos( $uri, 'studio' );
if( $s === false )
{$s = strpos( $uri, 'Studio' );}
$_root_ = substr($uri, 1, $s -1 ) . "Studio/";
$_desenv_ = "/" . $_root_ . "desenv/usuarios/phpage/";
function create_file_of_method( $nObj )
{$nFile = _INC_ . $nObj . "_eventos.js.php";if( !file_exists( $nFile ) ){$_fp_ = @fopen( $nFile, 'wb');@fwrite($_fp_, '<script language="javascript">' . NEWLINE );@fwrite($_fp_, ' var tags=document.getElementsByTagName("INPUT");'. NEWLINE );@fwrite($_fp_, ' for(var a=0;a<tags.length;a++)'. NEWLINE );@fwrite($_fp_, ' {'. NEWLINE );@fwrite($_fp_, ' i = tags[a].id.indexOf( "'.$nObj.'" );'. NEWLINE );@fwrite($_fp_, ' if( i != -1)'. NEWLINE );@fwrite($_fp_, ' {'. NEWLINE );@fwrite($_fp_, ' '.$nObj.'_ID = findDOM( tags[a].id, 0 );' . NEWLINE );@fwrite($_fp_, ' '.$nObj.'_ID.attachEvent( "onchange" , '.$nObj.'_onChange );'. NEWLINE );@fwrite($_fp_, ' '.$nObj.'_ID.attachEvent( "onfocus" , '.$nObj.'_onFocus );' . NEWLINE );@fwrite($_fp_, ' '.$nObj.'_ID.attachEvent( "onblur" , '.$nObj.'_onBlur );' . NEWLINE );@fwrite($_fp_, ' }'. NEWLINE );@fwrite($_fp_, ' }'. NEWLINE );@fwrite($_fp_, ' '. NEWLINE );@fwrite($_fp_, ' function '.$nObj.'_onChange( evt )'. NEWLINE );@fwrite($_fp_, ' {'. NEWLINE );@fwrite($_fp_, ' '. NEWLINE );@fwrite($_fp_, ' }'. NEWLINE );@fwrite($_fp_, ' '. NEWLINE );@fwrite($_fp_, ' function '.$nObj.'_onFocus( evt )'. NEWLINE );@fwrite($_fp_, ' {'. NEWLINE );@fwrite($_fp_, ' '. NEWLINE );@fwrite($_fp_, ' }'. NEWLINE );@fwrite($_fp_, ' '. NEWLINE );@fwrite($_fp_, ' function '.$nObj.'_onBlur( evt )'. NEWLINE );@fwrite($_fp_, ' {'. NEWLINE );@fwrite($_fp_, ' '. NEWLINE );@fwrite($_fp_, ' }'. NEWLINE );@fwrite($_fp_, ' '. NEWLINE );@fwrite($_fp_, ' function '.$nObj.'_onLoad( evt )'. NEWLINE );@fwrite($_fp_, ' {'. NEWLINE );@fwrite($_fp_, ' '. NEWLINE );@fwrite($_fp_, ' }'. NEWLINE );@fwrite($_fp_, ' '. NEWLINE );@fwrite($_fp_, '</script>' . NEWLINE );@fclose( $_fp_ );}}
function create_file_of_afterLoad( $nObj )
{$nFile = _INC_ . $nObj . "_afterLoad.js.php";if( !file_exists( $nFile ) ){$idx = substr( $nObj, 6 ) -1;$_fp_ = @fopen( $nFile, 'wb');@fwrite($_fp_, '<script language="javascript">' . NEWLINE );@fwrite($_fp_, ' setDbNavigator_post( ' .$idx.', false );' . NEWLINE );@fwrite($_fp_, ' setDbNavigator_first( '.$idx.', false );' . NEWLINE );@fwrite($_fp_, ' setDbNavigator_prior( '.$idx.', false );' . NEWLINE );@fwrite($_fp_, ' ' . NEWLINE );@fwrite($_fp_, ' setDBgrid_linha_on( '.$idx.', 1 );' . NEWLINE );@fwrite($_fp_, ' setDBgrid_readOnly( '.$idx.', true )' . NEWLINE );@fwrite($_fp_, '</script>' . NEWLINE );@fclose( $_fp_ );}}
function create_file_of_evento( $nObj, $nEvento )
{if( !defined( '_INC_' ) ){define( '_INC_', INC );}$nFile = _INC_ . $nEvento . "_" . $nObj . ".js.php";if( !file_exists( $nFile ) ){switch( $nEvento ){case 'onOver':$linha = $nObj . "_mouseOver( objectID );";break;case 'onOut':$linha = $nObj . "_mouseOut( objectID );";break;case 'onUp':$linha = $nObj . "_mouseUp( objectID );";break;case 'onDown':$linha = $nObj . "_mouseDown( objectID );";break;case 'onDown':$linha = $nObj . "_ mouseMove( objectID );";break;case 'onDblClick':$linha = $nObj . "_mouseDblClick( objectID );";break;default:$linha = $nObj . "_mouseClick( objectID );";break;}$_fp_ = @fopen( $nFile, 'wb');@fwrite($_fp_, $linha );@fclose( $_fp_ );}}
function getPatch()
{$uri = $_SERVER["REQUEST_URI"];$len = strlen($uri) -1;while($uri[$len] != "/")$len --;return substr($uri, 0, $len + 1);}
function getRoot()
{$uri = $_SERVER["REQUEST_URI"];$s = strpos( $uri, 'studio' );if( $s === false ){$s = strpos( $uri, 'Studio' );}return( substr($uri, 1, $s -1 ) );}
function execPage( $nPage )
{global $projeto,$esquema,$componentes_no_Prj,$_desenv_,$_root_,$modo_RAD;foreach( $componentes_no_Prj as $ind_ => $val_){global $$ind_;}$_pathPage_ = $_SERVER['DOCUMENT_ROOT'] .$_desenv_ . "core/" .$nPage . '.main.php';include( $_pathPage_ );}
function getTemplates( $nPrj, $local )
{$nFile = $nPrj . ".main.prj";if ( file_exists($nFile) ){$linhas = file($nFile);}else{$linhas = array();}$arrTemplate = array();foreach( $linhas as $i_ => $linha_ ){$linha_ = trim($linha_);if ( !empty( $linha_ ) ){$flag = true;$arrLinhas = explode( ";", trim($linha_) );array_pop($arrLinhas); foreach( $arrLinhas as $ii_ => $linha ){$arr = explode( ":", $linha );if( $arr[3] == $local ){$arrTemplate[] = $arr[2];}}}}return( $arrTemplate );$arr = array();foreach($comp_no_Prj as $_ind_ => $_val_){foreach($_val_ as $_n_ => $_l_){if ($_l_['local'] == $local )$arr[] = $_l_['nome'];}}return($arr);}
function getTemplates_old( $comp_no_Prj, $local )
{$arr = array();foreach($comp_no_Prj as $_ind_ => $_val_){foreach($_val_ as $_n_ => $_l_){if ($_l_['local'] == $local )$arr[] = $_l_['nome'];}}return($arr);}
function getGlobal( $comp_no_Prj, $local )
{$arr = array();foreach($comp_no_Prj as $_ind_ => $_val_){foreach($_val_ as $_n_ => $_l_){if ($_l_['local'] == $local )$arr[] = $_l_['nome'];}}return($arr);}
function getRegistro( $prj )
{global $_rad_, $_desenv_;$nFile = $prj . ".main.prj";$nDest = $prj . ".main.inc.php";$texto = "";$nComp = "";$nObj = "";$nl = "\n";$array = array();if ( file_exists( $nFile ) ){$linhas = file($nFile);}else{$linhas = array();}asort($linhas);reset($linhas);$texto = "<?php " . NEWLINE;$flag = false;foreach( $linhas as $i_ => $linha_ ){$linha_ = trim($linha_);if ( !empty( $linha_ ) ){$flag = true;$arrLinhas = explode( ";", trim($linha_) );array_pop($arrLinhas);foreach( $arrLinhas as $ii_ => $linha ){$arr = explode( ":", $linha );if( $nComp != $arr[0] ){if ( $nObj != "" ){$texto .= " )".$nl;}if( $nComp != "" )$texto .= " ); ".$nl;$nComp = $arr[0];$nObj = "";$array[] = $arr[0];$texto .= " $".$arr[0]." = array( ".$nl;}if( $nObj != $arr[1] ){if ( $nObj != "" ){$texto .= " ),".$nl;}$nObj = $arr[1];$texto .= " '" . $arr[1] . "' => array( " . $nl;}$texto .= " 'nome' => '" . $arr[2] . "'," . $nl;$texto .= " 'local' => '" . $arr[3] . "'," . $nl;$texto .= " 'container' => '" . $arr[4] . "'," . $nl;$texto .= " 'visual' => '" . trim($arr[5]) . "' " . $nl;}}}$l = count( $array );$x = 0;if ( $flag ){$texto .= " )" . $nl;$texto .= " );" . $nl;}$texto .= " " . $nl;$texto .= " \$componentes_no_Prj = array( " . $nl;foreach($array as $ii_ => $cpo ){$x ++;$sp = ( $x < $l ) ? "," : "";$texto .= " '".$cpo."' => $".$cpo . $sp . $nl;}$texto .= " ); " . $nl;$texto .= " " . $nl;$texto .= "?> " . $nl;$fp = @fopen( $nDest, 'wb' );fwrite( $fp, $texto );fclose( $fp );return( $prj . ".main.inc.php" );}
function getPaletas()
{$nDir = "core/paletas/";$arrPaleta = array();if ( file_exists($nDir) && is_dir($nDir) ){if ($handle = opendir($nDir)){while (false !== ($file = readdir($handle))){if ( is_dir($nDir.$file) ){if ($file != "." &&$file != ".." &&$file != "bkp"){$arrPaleta[] = "$file";}}}closedir($handle);}}return( $arrPaleta );}
function getObjetos( $nPaleta )
{$nDir = "core/paletas/" . $nPaleta;$arrObj = array();if ( file_exists($nDir) ){if ($handle = opendir($nDir)){while (false !== ($file = readdir($handle))){if ($file != "." &&$file != ".." &&$file != "bkp"){$ix = strpos( $file, ".");$arrObj[] = substr($file,0, $ix);}}closedir($handle);}}return( array_unique($arrObj) );}
function getFile( $nDir, $pre = "" )
{$arrFile = array();if ( file_exists($nDir) && is_dir($nDir) ){if ($handle = opendir($nDir)){while (false !== ($file = readdir($handle))){if ( !is_dir($nDir.$file) ){if ($pre == "" ){$arrFile[] = "$file";}else{$l = strlen( $pre );if( $pre == substr( $file, 0, $l ) &&!strpos( $file, "RAD" ))$arrFile[] = "$file";}}}closedir($handle);}}return( $arrFile );}
function getDir( $nDir )
{$arrFile = array();if ( file_exists($nDir) && is_dir($nDir) ){if ($handle = opendir($nDir)){while (false !== ($file = readdir($handle))){if ( is_dir($nDir . $file) &&$file != '.' && $file != '..'){$arrFile[] = "$file";}}closedir($handle);}}return( $arrFile );}
function writeTO( $texto_, $alvo_ = "HTML" )
{if ( $alvo_ == "HTML"){echo( $texto_ . NEWLINE );}else{fwrite( $alvo_, $texto_ . NEWLINE );}return( true );}
function writeINIfile($filename, $array1, $commentchar, $commenttext)
{$handle = @fopen($filename, 'wb');if ( $commenttext != '' ){$comtext = $commentchar.str_replace($commentchar, "\r\n".$commentchar,str_replace("\r", $commentchar,str_replace("\n", $commentchar,str_replace("\n\r", $commentchar,str_replace("\r\n", $commentchar, $commenttext)))));if ( substr($comtext, -1, 1) == $commentchar &&substr($comtext, -1, 1) != $commentchar){$comtext = substr( $comtext, 0, -1 );}@fwrite ( $handle, $comtext."\r\n" );}foreach ($array1 as $sections => $items){if (isset($section)){@fwrite ($handle, "\r\n");}$section = ucfirst(preg_replace('/[\0-\37]|\177/', "-", $sections));@fwrite ( $handle, "[".$section."]\r\n" );foreach ($items as $keys => $values){$key = preg_replace('/[\0-\37]|=|\177/', "-", $keys);if ( substr($key, 0, 1) == $commentchar){$key = '-'.substr($key, 1);}$value = addcslashes($values,'');@fwrite( $handle, ' ' . $key . ' = ' . $value . "\r\n" );}}fclose($handle);return(true);}
function readINIfile( $filename, $commentchar = ";" )
{$array1 = array();$array2 = array();if( file_exists( $filename ) ){$array1 = @file( $filename );$section = '';foreach ( $array1 as $filedata ){$dataline = trim($filedata);$firstchar = substr($dataline, 0, 1);if ( $firstchar != $commentchar && $dataline != '' ){if ($firstchar == '[' && substr($dataline, -1, 1) == ']'){$section = strtolower( substr( $dataline, 1, -1 ) );}else{$delimiter = strpos($dataline, '=');if ($delimiter > 0){$key = trim( substr($dataline, 0, $delimiter) );$value = trim( substr( $dataline, $delimiter + 1) );if ( substr($value, 1, 1) == '"' &&substr($value, -1, 1) == '"'){$value = substr($value, 1, -1);}$array2[$section][$key] = stripcslashes($value);}else{$array2[$section][ trim($dataline) ] = '';}}}else{}}}return( $array2 );}
function getPrimaryKeyOf($table)
{$keys = Array();$query = sprintf("SHOW KEYS FROM `%s`", $table);$result = mysql_query($query) or die(mysql_error());while ($row = mysql_fetch_assoc($result)){if ( $row['Key_name'] == 'PRIMARY' )$keys[$row['Seq_in_index'] - 1] = $row['Column_name'];}return $keys;}
function getTableInformationOf( $table )
{$information = array("auto" => "","primary" => array(),"fields" => array());$information['primary'] = getPrimaryKeyOf($table);$result = mysql_query("DESC `$table`");while ( $field = mysql_fetch_assoc($result) ){$information['fields'][] = $field;if ( $field['Extra'] == "auto_increment" )$information['auto'] = $field['Field'];}return $information;}
function getNameLib( $nLib )
{switch( $nLib ){case 'dbedit':$ret = "dbEdit";break;case 'dbnavigator':$ret = "dbNavigator";break;case 'dbgrid':$ret = "dbGrid";break;default:$ret = $nLib;}return( $ret );}
$projeto = array('projeto_nome' => 'projeto4','projeto_id' => '1','versao' => '0','atualizacao' => '00','revisao' => '10','desenv_id' => 1,'esquema' => 'system','modelo' => 'win98','pageMain' => 'page1');
define('CORE',$_SERVER['DOCUMENT_ROOT'] . "/" . $_root_ . 'core/');
define('USES',$_SERVER['DOCUMENT_ROOT'] . "/" . $_root_ . 'uses/');
define('CSS' ,$_SERVER['DOCUMENT_ROOT'] . "/" . $_root_ . 'css/');
define('INC' ,$_SERVER['DOCUMENT_ROOT'] . "/" . $_root_ . 'include/');
define('CFG' ,$_SERVER['DOCUMENT_ROOT'] . "/" . $_root_ . 'config/');
define('IMG' ,$_SERVER['DOCUMENT_ROOT'] . "/" . $_root_ . 'imagens/');
define('_CORE_',$_SERVER['DOCUMENT_ROOT'] . $_desenv_ . 'core/');
define('_USES_',$_SERVER['DOCUMENT_ROOT'] . $_desenv_ . 'uses/');
define('_CSS_' ,$_SERVER['DOCUMENT_ROOT'] . $_desenv_ . 'css/');
define('_INC_' ,$_SERVER['DOCUMENT_ROOT'] . $_desenv_ . 'include/');
define('_CFG_' ,$_SERVER['DOCUMENT_ROOT'] . $_desenv_ . 'config/');
define('_IMG_' ,$_SERVER['DOCUMENT_ROOT'] . $_desenv_ . 'imagens/');
define('LANGUAGE','pt_br');
define( 'NEWLINE', "\n");
define( 'JS_DIR', 'MSIE' );
define( 'JS_START', '<script type="text/javascript">' . "\n" );
define( 'JS_END', '</script>' . "\n" );
$esquema = array('system' => array('ActiveBorder' =>'ActiveBorder','ActiveCaption' =>'ActiveCaption','AppWorkSpace' =>'AppWorkSpace','BackGround' =>'BackGround','ButtonFace' =>'ButtonFace','ButtonHighlight' =>'ButtonHighlight','ButtonShadow' =>'ButtonShadow','ButtonText' =>'ButtonText','CaptionText' =>'CaptionText','GrayText' =>'GrayText','Highlight' =>'Highlight','HighlightText' =>'HighlightText','InactiveBorder' =>'InactiveBorder','InactiveCaption' =>'InactiveCaption','InfoBackground' =>'InfoBackground','InfoText' =>'InfoText','Menu' =>'Menu','MenuText' =>'MenuText','Scrollbar' =>'Scrollbar','ThreeDDarkShadow' =>'ThreeDDarkShadow','ThreeDFace' =>'ThreeDFace','ThreeDHighlight' =>'ThreeDHighlight','ThreeDLightShadow' =>'ThreeDLightShadow','ThreeShadow' =>'ThreeShadow','Window' =>'Window','WindowText' =>'WindowText','FontFamily' =>'verdana, tahoma, "Courier New", times','FontSize' =>'10'),'win98' => array('ActiveBorder' =>'ActiveBorder','ActiveCaption' =>'ActiveCaption','AppWorkSpace' =>'AppWorkSpace','BackGround' =>'BackGround','ButtonFace' =>'ButtonFace','ButtonHighlight' =>'ButtonHighlight','ButtonShadow' =>'ButtonShadow','ButtonText' =>'ButtonText','CaptionText' =>'CaptionText','GrayText' =>'GrayText','Highlight' =>'Highlight','HighlightText' =>'HighlightText','InactiveBorder' =>'InactiveBorder','InactiveCaption' =>'InactiveCaption','InfoBackground' =>'InfoBackground','InfoText' =>'InfoText','Menu' =>'Menu','MenuText' =>'MenuText','Scrollbar' =>'Scrollbar','ThreeDDarkShadow' =>'ThreeDDarkShadow','ThreeDFace' =>'ThreeDFace','ThreeDHighlight' =>'ThreeDHighlight','ThreeDLightShadow' =>'ThreeDLightShadow','ThreeShadow' =>'ThreeShadow','Window' =>'Window','WindowText' =>'WindowText','FontFamily' =>'verdana, tahoma, "Courier New", times','FontSize' =>'10'),'gold' => array(),'platina' => array());
$dataSource = array('dataSource1' => array('nome' => 'dataSource1','local' => 'page1','container' => 'nao','visual' => 'nao'));
$dbgrid = array('dbgrid1' => array('nome' => 'dbgrid1','local' => 'page1','container' => 'nao','visual' => 'sim'));
$dbnavigator = array('dbnavigator1' => array('nome' => 'dbnavigator1','local' => 'page1','container' => 'nao','visual' => 'sim'));
$label = array('label1' => array('nome' => 'label1','local' => 'page1','container' => 'false','visual' => 'true'));
$table = array('table1' => array('nome' => 'table1','local' => 'page1','container' => 'nao','visual' => 'nao'));
$componentes_no_Prj = array('dataSource' => $dataSource,'dbgrid' => $dbgrid,'dbnavigator' => $dbnavigator,'label' => $label,'table' => $table);
$pages_no_Prj = array('page1' => 'page1');
execPage( $projeto['pageMain'] );
  
  }else
  {
?>
  
  <html>
  <head>
  <!-- JavaScripts -->
  <script type="text/javascript" src="lib_JS/jsDOM.js"></script>
  <script type="text/javascript" src="lib_JS/jsDetect.js"></script>
  <!-- JavaScripts -->
  </head>
  <html>
  <body>
  <form name="formDetect" method="post" action="projeto4.php">
  <input type="hidden" name="nBrowser" />
  <input type="hidden" name="nVersao"   />
  <input type="hidden" name="nSO"       />
  <input type="hidden" name="isDHTML"    />
  <input type="hidden" name="total_X"  />
  <input type="hidden" name="total_Y"  />
  <input type="hidden" name="disp_X"   />
  <input type="hidden" name="disp_Y"   />
  </form>
  <script type="text/javascript">
  getBrowserApp();
  getSO();
  getDHTML();
  getDimensaoTela();
  document.forms[0].submit();
  </script>
  </body>
  </html>
  
<?php
  }
?>
