Add Airport

<<Back to Main Menu

Description:
Processes an Add Airport Form to add Airport details to the database

Accessible by:
Managers

Accessed from:
Add Airport Form

Input parameters:
Airport Name
Airport Code
New/Existing City
City
Timezone


Output
Success message
Add Airport Form and error message if there were errors in the form
Success message and link to View Airport (with airport code as parameter)

Pseudo Code:
get/create session
if ('usertype' param in session == 'm') {
   get form params
   validate form
   check if Airport Code already exists in the database
   if ((form params are in the correct format) AND(airport code doesn't already exist in the database)) {
      for (number of Add Airport Forms submitted) {
         if('new/existing city' param in the form == 'new') {
            if (the city name is already in the database) {
               display an Add Airport Form with an error message
            }
            else {
               add the new city to the database and get the id of it
            }
            add the Airport to the database
            display success message with link to View Airport
         }
         else {
            add the Airport to the database
            display success message with link to View Airport
         }
      }

      if (there's a 'newRoute' param in the session) { //manager's been adding new route
         get the newRoute details from the session
         if (there was only one Add Airport Form) {
            if ('from' field in newRoute data == 'new') {
               set 'from' to be the Airport added
            }
            else if ('to' field in newRoute data == 'new') {
               set 'to' to be the Airport added
            }
            add Route to the database
            delete all data from session except 'username' and 'usertype'
         }
         else if (there were two Add Airport Forms) {
            set 'from' to be the Airport in the first form
            set 'to' to be the Airport in the second form
            add Route to the database
            delete all data from session except 'username' and 'usertype'
            display success message with link to View Route
         }
      }
   }
   else {
      display an Add Airport Form with an error message
   }
}
else {
   error message to say user must be a manager
}