Jump to content
Fivewin Brasil

xHarbour integrando com PHP p/relatórios, etc..


silvanof

Recommended Posts

Prezados, a quem possa interessar.  Estou iniciando na programação web com PHP e minha primeira experiência foi juntar os dois mundos, fazendo uma chamada a uma pagina hospedada no servidor pra retornar um relatório html gerado com php. Utilizei o pacote Xampp que vem completo (Apache,PHP e MySql), mas usei o banco de dados Firebird do meu sistema. Vi que com isso dá para migrar facilmente relatório para internet/intranet.  Fiz assim:tela_rel_html.jpg

Função com a classe TipClientHttp do xHb comercial:

 

FUNCTION Main()
   
       LOCAL oHttp, cHtml, hQuery
       
       //   ? cPath+"listapartes.html"  
       //   SHELLEXECUTE( 0, 0, "iexplore.exe", cPath+"lista_partes.html", 0, 1 ) 
      //return nil       
       

       oHttp:= TIpClientHttp():new( "http://192.168.254.104/contratos/lista_partes_xhb.php" )

       // build the Google query
       hQUery := Hash()
       hSetCaseMatch( hQuery, .F. )

       hQuery["tipfil"]:= "3"
       hQuery["conteudo"]  := "INSTITUTO"

       // add query data to the TUrl object
       oHttp:oUrl:addGetForm( hQuery )

       // Connect to the HTTP server
       IF oHttp:open()
          // downlowad the Google response
          cHtml   := oHttp:readAll()

          Memowrit( "lista_partes.html", cHtml )
          oHttp:close()

           ? cPath+"listapartes.html"  
          SHELLEXECUTE( 0, 0, "iexplore.exe", cPath+"lista_partes.html", 0, 1 ) 
          

          //? Len(cHtml), "bytes received "
          //?? "and written to file lista_partes.html"
       ELSE
          ? "Connection error:", oHttp:lastErrorMessage()
       ENDIF
 
RETURN nil

Programa em PHP que lê os parâmetros passados via GET e da um SELECT no banco:

<!DOCTYPE html>
<html>
    <head>
        <!-- Para não dar problemas na acentuação -->
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
        <link rel="stylesheet" type="text/css" href="css/Estilo_Form.css" />

        <title> </title>
        <?php require_once('include/funcoes_aws.php') ?>
    
        <header>
        <center>
    
        <br>
        <!-- Funcao para exibir logo na tela (funcoes_aws.php) -->
        <?php ExibeLogoTela() ?>
            <hr><br>
        </center>    
        </header>
        <!-- 120% para gerar scrool horizontal -->
    </head>    
    <body style="width:120%" bgcolor="#87CEFA">
    <?php
    
    // Verificação de segurança    via variavel global

        $filtracampo="";
        $tipfil=$_REQUEST['tipfil'];
        $conteudo=$_REQUEST['conteudo'];
        
        switch($tipfil)
        {
            case "1": //todos
                $filtracampo=""; 
                break;
            case "2": //cnpj/cpf
                $filtracampo="AND (CNPJ = '".$conteudo."' OR CPF = '".$conteudo."')";
                break;
            case "3": //nome    
                $filtracampo="AND NOME LIKE  '%".$conteudo."%'";
                break;
        }
    
        $hoje=Hoje();
    
        // Conecta com o Firebird, banco CONTRATOS
        $db = ibase_connect("localhost:c:/contratos/contratos_compet.fdb", "sysdba", "masterkey");
        
        // Monta o SELECT na tabela de PARTES
        $query ="SELECT CODEMP,NOME,TELEFONE1,CNPJ,CPF,TIPOPESSOA FROM CTR_PARTES WHERE SR_DELETED<>'T' ".$filtracampo." ORDER BY NOME";   
        
        
        $result = ibase_query($db,$query);
        
        if ($result)
        {
            echo '<table border="1">';
            echo nl2br("<caption> <strong>  $hoje \r\n LISTAGEM DE PARTES </strong>  </caption>");
            echo "<tr bgcolor='lightgray'>";
            echo "<td><strong> CÓDIGO </strong></td>"; 
            echo "<td ><strong> NOME </strong></td>";
            echo "<td ><strong> TELEFONE </strong></td>";
            echo "<td ><strong> CNPJ/CPF </strong></td>";
            echo "</tr>";
            
            $lin=0;
            while ($row = ibase_fetch_assoc  ($result))
            {
                $lin++;
                // para alternar as cores das linhas (%=modulo() ou seja divisão com resto zero)
                if($lin % 2 == 0)
                {   //par
                    $corfundo="bgcolor='lightyellow'";
                }
                else
                {
                    //impar
                    $corfundo='';
                } 
                
                echo "<tr ".$corfundo.">";
                echo "<td>" .$row['CODEMP']           ."</td>";
                echo "<td >".substr($row['NOME'],0,50)."</td>";
                echo "<td>" .$row['TELEFONE1']        ."</td>";
                if ($row['TIPOPESSOA']=='J')
                    echo "<td>" .$row['CNPJ'] ."</td>";
                    
                ELSE    
                    echo "<td>" .$row['CPF'] ."</td>";
                    
                echo "</tr>";
            }
            echo '</table>';
        }
        ibase_free_result($result);
        ibase_close($db);    
        echo ibase_errmsg();
     
?>
    </body>
</html>
 

 

 

tela_rel_html.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...