// This file builds most of the html pages #include #include #include #include #include #include "unique_id.h" #include "errors.h" #include "time_slot.h" #include "reservations.h" #include "aircraft.h" #include "fleet.h" #include "cgi_data.h" #include "main.h" #include "html.h" // This function displays the default top level html page for the program. // From here, the user can select options that will allow him to modify // info for the aircraft or for individual reservations for the use of those // aircraft. void create_main_page(fleet & the_fleet) { int count = 0; new_aircraft *ac_array = NULL; int action; int selection; int i; int finished = 0; char buffer[32]; int buffer_i; int ac_id = 0; print_html_header("Foggy Bottom Flying Club home page"); strcat(big_buffer, "\n

existing rental aircraft:

:\n"); ac_array = the_fleet.find_all_ac(count); if (count == 0) { strcat(big_buffer, "\nno aircraft currently in club\n\n"); } else { strcat(big_buffer, "\n"); for (i = 0; i < count; ++i) { strcat(big_buffer, "\n\n"); // the name goes in one table data strcat(big_buffer, "\n"); // The description goes in the other table data. We need to try to // preserve any formatting that the user originally input. strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); } strcat(big_buffer, "

"); strcat(big_buffer, ac_array[i].name); strcat(big_buffer, "

"); strcat(big_buffer, "
");
      strcat(big_buffer, ac_array[i].description);
      strcat(big_buffer, "
"); strcat(big_buffer, "
\n"); // here comes the 'form' stuff strcat(big_buffer, "\n
\n\n"); strcat(big_buffer, "\n\n"); // make a popup list of aircraft names strcat(big_buffer, "existing aircraft\n"); strcat(big_buffer, "\n\n"); } // make a popup list of actions strcat(big_buffer, "action\n"); strcat(big_buffer, "\n\n"); // finish off the page with a 'GO' button strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); // free memory for (i = 0; i < count; ++i) { delete [] ac_array[i].description; } delete [] ac_array; } // This function sends out a form that will allow the user to add a new // aircraft to the list of available aircraft. void create_add_ac_page() { char buffer[32]; print_html_header("Foggy Bottom Flying Club add aircraft"); print_warning_msg(); strcat(big_buffer, "\n

new aircraft information:

\n\n"); // here comes the 'form' stuff strcat(big_buffer, "\n\n\n"); strcat(big_buffer, "\n\n"); // use a table to line up the fields for the aircraft name and description strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "
new aircraftc name:
new ac description:
\n"); // finish off the page with a few buttons strcat(big_buffer, "
\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); } // This function creates html that will allow the user to update // an existing aircraft. void create_modify_ac_page(new_aircraft aircraft_data) { char buffer[32]; print_html_header("Foggy Bottom Flying Club update aircraft"); print_warning_msg(); strcat(big_buffer, "\n

update existing aircraft:

:\n\n"); // here comes the 'form' stuff strcat(big_buffer, "\n\n\n"); strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n\n"); // use a table to line up the fields for the aircraft name and description strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "
aircraft
name:
"); strcat(big_buffer, aircraft_data.name); strcat(big_buffer, "
aircraft
description
"); strcat(big_buffer, aircraft_data.description); strcat(big_buffer, "
\n"); // finish off the page with a few buttons strcat(big_buffer, "
\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); } void print_html_header(const char* title) { strcpy(big_buffer, "Content-type: text/html\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, ""); strcat(big_buffer, title); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "

Foggy Bottom Flying Club

\n\n"); } // This function creates the html that will allow the user to view, add, // or delete reservations for the aircraft "ac_id". void create_add_res_page(fleet & the_fleet, const int ac_id) { all_ac_data all_data; int outcome; int i; int finished = 0; int found = 0; char buffer[64]; int buffer_i; char name[MAX_NAME_LEN]; time_t new_time; time_slot_info new_res; all_data = the_fleet.find_all_ac_data(ac_id, outcome); if (outcome != SUCCESSFUL) { strcpy(fatal_err_function, "show_add_update_delete_page"); sprintf(fatal_err_msg, "call to find_all_ac_data returned error code %d", outcome); fatal_error(); } print_html_header("Foggy Bottom Flying Club reservations page"); print_warning_msg(); // table header for current reservations strcat(big_buffer, "

Current reservations for the club's "); strcat(big_buffer, all_data.spec.name); strcat(big_buffer, ":

\n\n"); strcat(big_buffer, "\n\n"); // column headers for current reservations strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n\n"); for(i = 0; i < all_data.res_count; ++i) { // name strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); convert_time_t_to_ascii(buffer, all_data.all_res[i].start); strcat(big_buffer, "\n"); // finish date/time convert_time_t_to_ascii(buffer, all_data.all_res[i].finish); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); } strcat(big_buffer, "
namestart date & timefinish date & time
"); strcat(big_buffer, all_data.all_res[i].name); // start date/time strcat(big_buffer, ""); strcat(big_buffer, buffer); strcat(big_buffer, ""); strcat(big_buffer, buffer); strcat(big_buffer, "
\n\n"); // header and name for new reservation strcat(big_buffer, "

Add a new reservation for the club's "); strcat(big_buffer, all_data.spec.name); strcat(big_buffer, ":

\n"); // form details and a few hidden fields strcat(big_buffer, "\n\n\n"); strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n\n"); // create a text entry gizmo to input the user's name strcat(big_buffer, "your name:
\n\n"); // use a table to keep the pop-up selections for reservation start and // finish dates nicely lined up strcat(big_buffer, "\n"); // headers for table columns strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); // this table row defines the reservation start date and time strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); popup_month_to_big_buffer("from_month"); popup_date_to_big_buffer("from_date"); popup_year_to_big_buffer("from_year"); popup_hour_to_big_buffer("from_hour"); popup_min_to_big_buffer("from_min"); strcat(big_buffer, "\n"); // this table row defines the reservation finish date and time strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); popup_month_to_big_buffer("to_month"); popup_date_to_big_buffer("to_date"); popup_year_to_big_buffer("to_year"); popup_hour_to_big_buffer("to_hour"); popup_min_to_big_buffer("to_min"); strcat(big_buffer, "\n"); strcat(big_buffer, "
monthdateyearhourmin
from:
to:
\n\n"); // create a pop-up list of actions strcat(big_buffer, "action\n"); strcat(big_buffer, "\n\n"); // create a pop-up list of old reservations strcat(big_buffer, "old reservations\n"); strcat(big_buffer, "\n\n"); // finish off the page with a few buttons strcat(big_buffer, "
\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n\n"); strcat(big_buffer, "\n"); strcat(big_buffer, "\n"); // get rid of memory we no longer need delete [] all_data.spec.description; delete [] all_data.all_res; } // Convert a time_t value to an ascii date/time string, // such as 04/27/02 @ 1630 void convert_time_t_to_ascii(char* buffer, time_t & t_time) { struct tm *ts; int year_tmp; ts = localtime(&t_time); year_tmp = ( ts->tm_year ) % 100; sprintf(buffer, "%d/%d/%2.2d @ %2.2d%2.2d", ts->tm_mon+1, ts->tm_mday, year_tmp, ts->tm_hour, ts->tm_min); } // Convert a name + time_t value to an ascii string, such as // Sanderson 0900 9/20/02 void create_res_summary(char* buffer, const time_t t_time, char* name) { struct tm *ts; char *last_name; int year_tmp; last_name = strrchr(name, ' '); if (last_name == NULL) { last_name = name; } ts = localtime(&t_time); year_tmp = ts->tm_year % 100; sprintf(buffer, "%s %2.2d%2.2d %d/%d/%2.2d", last_name, ts->tm_hour, ts->tm_min, ts->tm_mon+1, ts->tm_mday, year_tmp); } void popup_month_to_big_buffer(const char *the_name) { strcat(big_buffer, ""); strcat(big_buffer, ""); strcat(big_buffer, "\n"); } void popup_date_to_big_buffer(const char *the_name) { strcat(big_buffer, ""); strcat(big_buffer, ""); strcat(big_buffer, "\n"); } void popup_year_to_big_buffer(const char *the_name) { strcat(big_buffer, ""); strcat(big_buffer, ""); strcat(big_buffer, "\n"); } void popup_hour_to_big_buffer(const char *the_name) { strcat(big_buffer, ""); strcat(big_buffer, ""); strcat(big_buffer, "\n"); } void popup_min_to_big_buffer(const char *the_name) { strcat(big_buffer, ""); strcat(big_buffer, ""); strcat(big_buffer, "\n"); } void print_warning_msg() { if (warning_msg[0] != '\0') { strcat(big_buffer, "\n
\n"); strcat(big_buffer, "

ERROR

\n"); strcat(big_buffer, warning_msg); strcat(big_buffer, "\n
\n"); } }