[Gambas-user] CGI app help.

Rolf-Werner Eilert eilert-sprachen at ...221...
Thu May 12 08:57:24 CEST 2011


Am 12.05.2011 00:53, schrieb Hamilton Geminiano Andrioli Junior:
> Hello world!
>
> I want to make a system for my School.
> Now i have to decide how and where to write it.
>
> Does anyone have a example of CGI Web based program in gambas?
>
> Thanks...
>


Hello Hamilton,

I have made CGI applications based on Gambas scripts. Don't know if it 
is thought to be made like this (I didn't know there is a special class 
for it in Gambas), but this is about the basic work:

You'll need a new Gambas project "for commandline use".

Just to give you an idea of how this could work, here's the skeleton for 
a simple CGI window which has basically 3 parts: a Title-Line and two 
Columns (realized with a table). It is from a database questionnaire 
where you can switch on/off some items on the left and see the results 
(simple list) on the right. This is actually a thing I made for my 
school :-)

Let the IDE compile the stuff and copy the <Project>.Gambas file into 
your <whatever>/cgi-bin directory. In my case, however, I had to make a 
symlink to the actual Gambas binary because the appache wouldn't find it 
like that.

All this is in MMain. German "schreibe" = "write", "Spalte" = "Column"


PUBLIC SUB Main()


     schreibeHeader

     schreibeSeitenkopf

     PRINT "<table border=\"0\" width=\"100%\">"
     PRINT "<tr>"
     schreibeLinkeSpalte
     schreibeRechteSpalte
     PRINT "</tr>"
     PRINT "</table>"

     schreibeSeitenschluss



END


'To make it function, this part is the most important. Take care
'not to forget the two empty lines before Doctype.

PRIVATE SUB schreibeHeader()

   PRINT "Content-type: text/html; charset=utf-8"
   PRINT ""
   PRINT ""
   PRINT "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"
   PRINT "<head>"
   PRINT "<title>Kartei online</title>"
   PRINT "<style type=\"text/css\">"
   PRINT "a:link { text-decoration:none; font-weight:bold; color:#3261A6; }"
   PRINT "a:visited { text-decoration:none; font-weight:bold; 
color:#800000; }"
   PRINT "a:hover { text-decoration:none; font-weight:bold; 
background-color:#ff0; }"
   PRINT "a:active { text-decoration:none; font-weight:bold; 
background-color:#cff; }"
   PRINT "a:focus { text-decoration:none; font-weight:bold; 
background-color:#080; }"
   PRINT "</style>"

   PRINT "</head>"
   PRINT ""

END


PRIVATE SUB schreibeSeitenkopf()
DIM i AS Integer

   PRINT "<body bgcolor=\"#E0E0E0\">"

   PRINT "<font face=\"Verdana, Arial, Helvetica\" 
color=\"#3261A6\"><h1>Title of the CGI application</h1><font 
face=\"Trebuchet MS, Verdana, Arial, Helvetica\" size=\"-1\" 
color=\"black\">"

END


PRIVATE SUB schreibeLinkeSpalte()
DIM t$ AS String
DIM i AS Integer
DIM teil AS NEW String[]

   PRINT "<td width=\"33%\" valign=\"top\">"
     PRINT "<font face=\"Trebuchet MS, Verdana, Arial, Helvetica\" 
size=\"-1\">"
     PRINT "Left column:<br><br>"
     PRINT "<h3><font face=\"Verdana, Arial, Helvetica\" 
color=\"#3261A6\"><center>Title 1</center></h3><font face=\"Trebuchet 
MS, Verdana, Arial, Helvetica\" size=\"-1\" color=\"black\">"


     PRINT "<hr>"
     PRINT "<h3><font face=\"Verdana, Arial, Helvetica\" 
color=\"#3261A6\"><center>Title 2</center></h3><font face=\"Trebuchet 
MS, Verdana, Arial, Helvetica\" size=\"-1\" color=\"black\">"
   PRINT "</td>"

END







PRIVATE SUB schreibeRechteSpalte()
DIM i AS Integer
DIM teil AS NEW String[]

   PRINT "<td width=\"2%\" bgcolor=\"#EEEEEE\"></td>" 'Zwischenspalte 
hellgrau

   PRINT "<td bgcolor=\"FFFFFF\" valign=\"top\">"      'rechte Spalte weiß

       PRINT "<h3><font face=\"Verdana, Arial, Helvetica\" 
color=\"#3261A6\"><center>Inhalt</center></h3>"

   PRINT "</td>"

END



PRIVATE SUB schreibeSeitenschluss()

   PRINT "</body>"
   PRINT "</HTML>"

END




More information about the User mailing list