Xbase DBMS Chapter 19

xbHtml/CGI Interface Methods

Chapter Updated 2/1/98


xbHtml Class Methods

ClassDescription
BoldOn()Turn on bold
BoldOff()Turn off bold
Bullet()Create a bullet point
DumpArray()Dumps the internal field array
EmphasizeOn()Turn on emphasize
EmphasizeOff()Turn off emphasize
EndHtmlPage()Generate end-of-page tags
GenFormFields(...)Print a form with data fields
GetArrayNo(char * FieldName)Gets a field's offset into the internal data array
GetCookie(char *CookieName)Get a cookie data value
GetData(xbShort ArrayNo)Gets data for a particular array offset
GetDataForField(char * FldName)Gets the value for a particlar field
GetEnv(char * EnvString)Get an environment string
GetMethod()Returns true if get method used
HeaderOn(xbShort HeaderLevel)Turn on a header
HeaderOff(xbShort HeaderLevel)Turn off header
ItalicOn()Turn on italics
ItalicOff()Turn off italics
Newline()Generate a newline
PlusToSpace(char *s)Convert + symbols to spaces
PostMethod()Returns true if post method used
PrintHtml(char * String)Print a string or number
PrintEncodedChar(char c)Prints an encoded xbHtml character
PrintEncodedStringCHAR *s)Prints an encoded xbHtml string
SendRedirect(char * RedirectURL)Send redirect command
SetCookie(...)Set up and send a cookie to the client
SpaceToPlus(char *s)Convert spaces to + symbols
StartHtmlPage(char *Title)Generates beginning of Html page tags
StartTextPage()Generates beginning of Text page tags
Tally(char * FileName)Increment a counter



Method Definitions


Method void xbHtml::BoldOn()


This method prints the bold on tag.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::BoldOff()


This method prints the bold off tag.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::Bullet( void )


This method prints a bullet point.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::DumpArray( void )


This method dumps the internal array which stores all data passed to the program from the previous form. This method is mostly used for trouble shooting.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::EmphasizeOn( void )


This method prints the emphasize on tag.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::EmphasizeOff( void )


This method prints the emphasize off tag.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::EndHtmlPage( void )


This method prints the end-of-page tags .

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method xbShort xbHtml::GetArrayNo( char * FieldName )

This method returns a the offset into the internal array where the data for field FieldName is stored. It will return -1 on error.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::GetFormFields( xbDbf *d, xbShort Option, const char * Title, xbFieldList * fl )

This method is used for creating an xbHtml page with database (or non database) fields and displaying them. The method creates an xbHtml table in order to align the fields in an asthetically pleasing manner.


Method Paramaters

ParamaterDescription
xbDbf *dA pointer to a xbDbf object, or 0 if no dbf fields used
xbShort Option0 = Display empty fields
1 = Display field data from record buffer of object d
char * TitleAn optional title
xbFieldList *flAn array of field specific information used for building the output

Stucture xbFieldList

ParamaterDescription
char * LabelField label on form
char * FieldNameForm Field Name
char * FieldLenForm Display Length
xbShort DbfFieldNoCorresponding database field no
xbShort FieldOption0 - display as input/output field
1 - display as password field
2 - display as output data only

Return Codes

Return CodeDescription
XB_NOT_OPENDatabase is not open
XB_NO_ERRORNo error

Example Program:

xbXBase x; xbDbf d( &x ); xbHtml p; xbFieldList FL[] = { { "Name", "NAME", 0, 0 }, { "Address", "ADDRESS", 1, 0 }, { "City", "CITY", 2, 0 }, { "State", "STATE", 3, 0 }, { "Zip", "ZIP", 4, 0 } } // open the database and get a record p.GenFormFields( &d, 1, "Address Information", FL );

Method char * xbHtml::GetCookie( char * CookieName )

This method returns a pointer to the data for cookie CookieName

Sample Usage:

xbHtml p; char CookieDataBuffer[10]; if( p.GetCookie( "COOKIETEST" )) strcpy( CookieDataBuffer, p.GetCookie( "COOKIETEST" ), 9 );

Method char * xbHtml::GetData( xbShort ArrayNo )

This method returns the data from the internal array for offset ArrayNo. It will return NULL if there is no data in the array for ArrayNo or if ArrayNo is out of range.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method char * xbHtml::GetDataForField( char * FieldName )

This method returns the data for from the internal array for field FieldName. It will return NULL if FieldName is not in the internal array, or if there is no data for field FieldName.

Example Program:

See program zipinq.cpp for an example of how to use this program.

Method char * xbHtml::GetEnv( char * EnvString )


This method returns a pointer to the data for environment string EnvString.

EnvString Values

EnvString
AUTH_TYPE
CONTENT_LENGTH
CONTENT_TYPE
HTTP_REQUEST_METHOD
QUERY_STRING
REMOTE_ADDR
REMOTE_HOST
REMOTE_USER
SCRIPT_FILENAME
SCRIPT_NAME
SERVER_PORT
SERVER_PROTOCOL
SCRIPT_PATH
CGI_STDIN
CGI_STDOUT
CGI_STDERR
HTTP_USER_AGENT
HTTP_CONTENT_LENGTH
HTTP_ACCEPT
HTTP_HOST
REQUEST_METHOD

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method xbShort xbHtml::GetMethod( void )


This method returns true if a GET method was used.

Example Program:

See program testhtml.cpp for an example of how

Method void xbHtml::HeaderOn( xbShort lvl )


This method prints the header on tag where lvl is a level 1 thru 6.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::HeaderOff( xbShort lvl )


This method prints the header off tag where lvl is a level 1 thru 6.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::ItalicOn( void )


This method prints the italic on tag.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::ItalicOff( void )


This method prints the italic off tag.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::Newline( void )


This method prints the newline tag.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::PrintEncodedChar( char )


This method prints an xbHtml encoded character. For example, the '<' character is printed as '& lt'.

Method void xbHtml::PrintEncodedString( char * )


This method prints an xbHtml encoded string. For example, any '<' characters in the string are printed as '& lt'.

Method void xbHtml::Newline( void )


This method prints the newline tag.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::PlusToSpace( char * String )


This method is used for converting all + symbols to spaces in a given string. This is useful for sending URLs with spaces in the data.

Sample Code:

xbHtml p; char MyUrlString[40]; strcpy( MyUrlString, "program.cgi?PARM=My paramater information" ); p.SpaceToPlus( MyUrlString ); // eliminate the spaces p.SendRedirect( MyUrlString ); // send it p.PlusToSpace( MyUrlString ); // un-eliminate the spaces

Method xbShort xbHtml::PostMethod( void )


This method returns true if a POST method was used.

Example Program:

See program testhtml.cpp for an example of how

Method void xbHtml::PrintHtml( char * x )
Method void xbHtml::PrintHtml( xbLong x )
Method void xbHtml::PrintHtml( xbShort x )

This method prints the data x on the page.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::SetCookie( char * Name, char * Value, char * ExpDate, char * ExpTime, char * TimeZone, char * Path, char * Domain, xbShort Secure );

Some browsers support the Netscape cookie method for storing client side data such as state information. The cookie containing data is passed along in the HTTP request-response dialog. To send a cookie to a browser, you must send the cookie before any html data is sent.

Sample Usage:

xbXBase x;
xbHtml p;
char ExpireDate[15];

strcpy( ExpireDateBuf, x.FormatDate( "DDD DD-MMM-YY", x.Sysdate()));
p.SendCookie( "COOKIETEST", "Y", ExpireDate, 0, "CST" );

If the SendCookie method doesn't work, you could optionally do this:
cout << "Set-Cookie: COOKIETEST=Y; " << ExpireDateBuf << " CST" << endl;

Method void xbHtml::SendRedirect( char * RedirectURL )


The output of a CGI program can be a redirect command. The redirect command is used to instruct the client to display the contents of the new URL instead of loading the URL from the present location.

Example:


xbHtml h;
h.SendRedirect( "http://www.startech.keller.tx.us" );


Method void xbHtml::SpaceToPlus( char * String )


This method is used for converting all spaces in a given string to + symbols. This is useful for sending URLs with spaces in the data.

Sample Code:

xbHtml p; char MyUrlString[40]; strcpy( MyUrlString, "program.cgi?PARM=My paramater information" ); p.SpaceToPlus( MyUrlString ); // eliminate the spaces p.SendRedirect( MyUrlString ); // send it p.PlusToSpace( MyUrlString ); // un-eliminate the spaces

Method void xbHtml::StartHtmlPage( char * Title )


This method prints data necessary to begin an Html page:
Content-type: text/html\n\n

and also sets the page title to title.

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method void xbHtml::StartTextPage( void )


This method prints data necessary to begin a Text page:
Content-type: text/plain\n\n

Example Program:

See program testhtml.cpp for an example of how to use this program.

Method xbLong xbHtml::Tally( char * Filename )


This method increments a counter stored in Filename and returns the new count. The Web server needs write access to the directory where Filename is stored for this routine to function. This method will not create a file. It expects the file to already exist. To initialize a file, create an ASCII file with the number 0 in it. It is a case sensitive routine.

This routine returns 0 if it fails, otherwise it returns the current tally count for Filename.

Example Program:

See program testhtml.cpp for an example of how to use this program.
Send me mail - xbase@startech.keller.tx.us

(c)1997 StarTech