Edit Profile

<<Back to Main Menu

Description:
Processes an Edit Profile Form to edit a user's details in the database

Accessible by:
Customers and Managers

Accessed from:
Edit Profile Form

Input parameters:
Name
Username
Password
Retype Password
Email
Address1
Address2
Town/City
County/Postcode
Country
Telephone
Title
Delete Card
Card Holder Name
Card Type
Card Expiry
Card Number

Output
Success Message if update is successful.
Edit Profile Form if there's an error

Pseudo Code:
get/create session
if (there is a 'username' param in the session) {
   get form parameters
   validate the form data
   if (form data is ok) {
      if (('username' param in the form == 'username' param in the session) OR ('usertype' param in the session == 'm')) {
         update the data in the 'users' and 'addresses' tables.
         for each credit/debit card to be deleted {
            remove the relevant entry from the cards table
         }      
         if (user tried to add new credit/debit card) {
            add the card to the 'cards' table
         }
         if (('usertype' param in the session == 'm') AND ('manager' param exists in the form)) {
            if ('manager' param == 'yes') {
               update the 'users' table entry to make 'username' a manager
            }
            else {
               update the 'users' table entry to make 'username' a customer
            }
         }
      }
      else {
         display error message
      }
   }
   else {
      display Edit Profile Form with an error message
   }
}
else {
   display an error message that user must be logged in
}