|
Come funziona il Programma con il CGIDEV
Finalmente arriviamo al programma, che deve essere necessariamente un RPG ILE, in quanto tutto si basa sui Srvpgm.
Di seguito riporto il programma che viene utilizzato per sfogliare il catalogo e che viene richiamato dal Web nell'area www.toninelli.it. Tengo a precisare che ha già almeno un paio di anni, e di strada grazie a Perotti ne ho fatta; quindi usatelo solo come esempio di idee e non di utilizzo. Ad esempio tutti i nuovi pgm utilizzano più file HTML invece che uno solo di questi e soprattutto la variabile di ingresso non e' più ACTION, ma uso REQUEST.
I commenti che faccio adesso li scrivero' in rosso.
Naturalmente non mi addentro nello specifico dei file, perchè li trovate nella libreria che avete scaricato dal sito del CGIDEV2.
/copy cgidev2/qrpglesrc,hspecsbnd Qui vengono descritti i pgm in Binding di Perotti
/copy qprotsrc,hspecscgi Questi sono descritti i pgm in Binging miei
*********************************************************************
* HCGIP01R - Catalogo *
*-------------------------------------------------------------------*
* SCOPO: *
* .. .. .. *
*********************************************************************
*---------------------------------------------------------------*
* Strutture dati per SQL *
*---------------------------------------------------------------*
*============================================================
* Includes to be used in all CGIs
*============================================================
/copy cgidev2/qrpglesrc,prototypeb Questi sono i prototipi del CGIDEV2
/copy cgidev2/qrpglesrc,usec Questi sono i prototipi del CGIDEV2
/copy cgidev2/qrpglesrc,variables3 Questi sono i prototipi del CGIDEV2
Questi sotto sono i miei prototipi
*-------------------------------------------------------------------*
* Miei Prototipi |
*-------------------------------------------------------------------*
/copy QPROTSRC,HDEFINIZ
/copy QPROTSRC,HSRVANARTI
/copy QPROTSRC,HSRVCHAR
/copy QPROTSRC,HSRVEURO
/copy QPROTSRC,HSRVPGM
/copy QPROTSRC,HSRVSQL
/copy QPROTSRC,HOFG01R
/copy QPROTSRC,HMGA15R
/copy QPROTSRC,HSRVCGI
/copy QPROTSRC,HSRVTAB
*-------------------------------------------------------------------*
* Prototipi di questo pgm |
*-------------------------------------------------------------------*
d rtvFORROWS pr 3 0
d HCGIP01CC pr
d NrJob 10
d prI_Ovrdbf pr
d prI_Assign_NRJOB...
d pr
d prI_Test pr
d prI_ConnecttoZeus...
d pr
*-------------------------------------------------------------------*
* Strutture dati descritte-esternamente |
*-------------------------------------------------------------------*
*-------------------------------------------------------------------*
* Strutture dati descritte-internamente |
*-------------------------------------------------------------------*
Qui metto la Path di dove si trova il file HTML
* Name of this program
D PgmName c 'HCGIP01R'
d IfsHtml c '/http/pubblico/+
d toninelli/AreaPub/'
d AFFOK s 6
d AFWRASFO s 30
d Script S 80 DIM(2) CTDATA PERRCD(1)
d ds£fil ds
d £fil 20 DIM(20)
d lib 10 overlay(£fil:1)
d fil 10 overlay(£fil:11)
d £CAT S 33 DIM(2)
d TipoRic s 10
d ConnecttoZeus s n
d Ult_Nr_Job s 3 0 inz(0)
d ds£NrJob ds inz
d £NrJob 25 dim(500)
d £NrJobNam 10 overlay(£NrJob:1)
d £NrJobRig 7s 0 overlay(£NrJob:11)
d £NrJobTime t overlay(£NrJob:18) inz( *SYS )
d ricerca_basata s 100
d tot_righe s 7 0 inz(0)
d NRPAG s 3 0 inz(0)
d nr_riga s 6 0 inz(0)
d da_riga s 6 0 inz(0)
Questa e' la direttiva che interpreta i dati CGI
*==================================================================
* Read remote browser request and map to external data structure
* Lasciare qui!
*==================================================================
/copy cgidev2/qrpglesrc,prolog3
c exsr main_pgm
* Send the response html buffer and exit
c exsr Exit
*********************************************************************
* main_pgm *
*-------------------------------------------------------------------*
* SCOPO : *
* Inizio programma *
* *
*********************************************************************
c main_pgm begsr
/free
Qui legge il file HTML che sta' su IFS
//* Legge lo Skeleton
gethtmlifs(IfsHtml+PgmName+'.HTM':'');
Una mia variabile che ho chiamato ACTION, per sapere cosa deve fare il pgm
ACTION = zhbgetvar('ACTION');
REMOTE_USER è una variabile del CGIDEV2, che identifica l'utente
Remote_User =getenv('REMOTE_USER':qusec);
...
...
select;
//* Inizio Catalogo
when ACTION = 'StartCat' or ACTION = 'NewSearch' or
ACTION = ' ';
exsr StartCat;
// * Ricerca per descrizione
when ACTION = 'RicDescr';
exsr RicDescr;
//* Ricerca per fornitore
when ACTION = 'RicForn';
exsr RicForn;
//* Riempie i campi per Categoria
when ACTION = 'riccateg';
exsr RicCate;
//* Esegue SQL
when ACTION = 'ExeRicerca';
NRPAG = 0;
exsr SqlArticoli;
//* Pagina avanti
when ACTION = 'FwArt';
NRPAG = pr_CvtAlfNum( zhbgetvar('NRPAG') );
NRJOB = zhbgetvar('NRJOB');
ricerca_basata ='in base alla ricerca effettuata.';
exsr SqlArtAvanti;
//* La scheda
when ACTION = 'SchArt';
exsr SchedaArt;
when ACTION = 'Test';
prI_TEST();
other;
exsr StartCat;
endsl;
endsr;
/end-free
*********************************************************************
* StartCat *
*-------------------------------------------------------------------*
* SCOPO : *
* Inizio catalogo e mappa *
* *
*********************************************************************
c StartCat begsr
/free
exsr RicDescr;
endsr;
/end-free
*********************************************************************
* RicDescr *
*-------------------------------------------------------------------*
* SCOPO : *
* Ricerca per descrizione *
* *
*********************************************************************
c RicDescr begsr
/free
Questa è una Section, come se fosse un pezzo della mappa ( un record del DSPF ).
Nel mio standard qui compare il logo ed i pulsanti ( parte sopra )
WrtSection('GenHead');
Altra Section ... ( Immettere la Descrizione )
WrtSection('RicDescr');
endsr;
/end-free
*********************************************************************
* RicForn *
*-------------------------------------------------------------------*
* SCOPO : *
* Elencare i fornitori *
* *
*********************************************************************
c RicForn begsr
/free
WrtSection('GenHead');
WrtSection('RicFor1');
stringa_SQL = 'Select AFFOK, AFWRASFO from HDAT/HANFO00F +
where AFWRASFO <> '' '' +
order by AFWRASFO';
/end-free
c/exec sql
c+ prepare SELF from :stringa_sql
c/end-exec
c/exec sql
c+ declare SQLCUR2 cursor for SELF
c/end-exec
c/exec sql
c+ open SQLCUR2
c/end-exec
* Loop
c do *hival
c/exec sql
c+ fetch SQLCUR2 into :AFFOK, :AFWRASFO
c/end-exec
/free
if SQLCOD <> 0;
if SQLCOD <> 100;
pr_InfoSQLCOD('HCGIP01R':'sr RicForn':SQLCOD);
endif;
WrtSection('RicFor3');
leave;
endif;
qui riempio le variabili con i miei dati. AFFOK è una variabile che compare nel
file HTML, che il CGIDEV2 sostituisce con il valore corretto
UpdHtmlVar('AFFOK':AFFOK:InitHTMLVars);
UpdHtmlVar('AFWRASFO':AFWRASFO);
Questa è una Section
WrtSection('RicFor2');
enddo;
/end-free
c/exec sql
c+ close SQLCUR2
c/end-exec
c endsr
..
..
..
*********************************************************************
* SchedaArt *
*-------------------------------------------------------------------*
* Scopo: *
* Gestire la scheda articoli *
* *
*********************************************************************
c SchedaArt begsr
/free
WrtSection('GenHead');
WrtSection('Scheda1');
Il Browser ha passato un Cd Articolo che vado a leggere
tramite la ZHBGETVAR.
Dato che BAARK è il mio Cd Articolo ma è numerico, mi sono fatto una procedura
che converte una alfabetico con un Numero.
BAARK = pr_CVTALFNUM(zhbgetvar('BAARKN'));
Questa è roba mia: è un chain al file degli articoli
HANAR00F = pr_RtnHANAR00F(BAARK);
if BAMIC = 'CGI0110' or BAARK = 0;
exsr mappa_errore;
return;
endif;
Riempio le variabili
UpdHtmlVar('BAARK':%editw(BAARK:' . - ')); Cd articolo
UpdHtmlVar('BAARKN':%editc(BAARK:'X')); Cd articolo
UpdHtmlVar('PREZZO':'non disp.'); Prezzo compare "Non disponibile
UpdHtmlVar('AREF':pr_HtmlFoto(BAARK: 'Ingrandisci':' ':'P')); Creo la foto
UpdHtmlVar('BADEC':BADEC); Descrizione
UpdHtmlVar('AFGTEXT':pr_HtmlDesFoto(BAARK:'G'));
WrtSection('Scheda2'); Section
if BAANF<>' '; Se articolo è annullato, scrivo ...
UpdHtmlVar('Art_annullato':'( Questo articolo potrebbe non essere +
disponibile al momomento. Chiedeteci prima la +
disponibilita'')');
else;
UpdHtmlVar('Art_annullato':' ');
endif;
UpdHtmlVar('PZCART':pr_CrtImballi(HANAR00F));
WrtSection('Scheda3');
endsr;
/end-free
*********************************************************************
* mappa_errore *
*-------------------------------------------------------------------*
* SCOPO : *
* Emissione errore *
* *
*********************************************************************
c mappa_errore begsr
/free
WrtSection('GenHead');
UpdHtmlVar('MIC':MIC);
UpdHtmlVar('DSPMIC':pr_Sndmic(MIC));
WrtSection('Sndmic');
endsr;
/end-free
...
...
...
|