/*_________________________________________________________________________

 

FILE: template.c by - Mike Lavender

date - April 26, 2005

 

Copyright (c) April, 2005 : Intec Automation Inc.

 

PURPOSE: Interface to generate a template page.

 

NOTES: This file will build a template HTML page with the following structure.

 

+-------------------------------------------------------------------+

| Header |

+-------------------------------------------------------------------+

| | |

| | |

| Left | |

| Column | Content |

| | |

| | |

| | |

| | |

+-------------------------------------------------------------------+

| Footer |

+-------------------------------------------------------------------+

Each of the section are to be filled in by the implementation of the

following methods.

 

1. add_page_header

2. add_left_column

3. add_page_content

4. add_page_footer

These function implementations should use printf/puts to generate content

which will be added to the page as a whole.

Template is used with Cascading Style Sheets and expects a "site.css"

to be present in the root web directory. The template expects the

following classes to be defined.

.main (main outer table)

.header (header section)

.main-core (core table inside main table with 2 columns)

.left-nav (left column)

.content (content column)

.footer (footer section)

___________________________________________________________________________*/

 

 

#include <stdio.h> // printf

#include <template.h> // add_page_header, ...

#include <cgivars.h> // getGETvars, getPOSTvars, getRequsetMethod

 

 

 

//------------- Implementation --------------------------------------------

 

// TYPE: Local Utility

void // No return

build_page(void) // Build a webpage by adding the various

// elements like header, footer, content, ...

{

RequestType request; // Request parameters such as post variables

// get variables (query string) and whether the

// request is a POST, or GET

// initialize the request by reading the environment variables provided

// by the web server

request.postvars = NULL;

request.getvars = NULL;

request.form_method = getRequestMethod();

if(request.form_method == POST) {

request.getvars = getGETvars();

request.postvars = getPOSTvars();

} else if(request.form_method == GET) {

request.getvars = getGETvars();

}

// Meta Information

printf("Content-type: text/html\n\n");

// Page

printf("<html>" );

printf( "<head>" );

printf( "<title>" );

add_page_title(&request);

printf( "</title>" );

// Stylesheet

printf( "<link href=\"/site.css\" rel=\"stylesheet\" \

type=\"text/css\">" );

printf( "</head>" );

printf( "<body>" );

printf( "<table class=\"main\" cellspacing=\"0\">" );

printf( "<tr>" );

printf( "<td class=\"header\">" );

add_page_header(&request);

printf( "</td>" );

printf( "</tr>" );

printf( "<tr>" );

printf( "<td>" );

printf( "<table class=\"main-core\" cellspacing=\"0\">" );

printf( "<tr>" );

printf( "<td class=\"left-nav\">" );

add_left_column(&request);

printf( "</td>" );

printf( "<td class=\"content\">" );

add_page_content(&request);

printf( "</td>" );

printf( "</tr>" );

printf( "</table>" );

printf( "</td>" );

printf( "</tr>" );

printf( "<tr>" );

printf( "<td class=\"footer\">" );

add_page_footer(&request);

printf( "</td>" );

printf( "</tr>" );

printf( "</table>" );

printf( "</body>" );

printf("</html>" );

// Free allocated memory

cleanUp(request.form_method, request.getvars, request.postvars);

}