private String compareUserPassword(HttpServletRequest request) {

    HttpSession session = request.getSession(true);

    String check = "";
    String email = session.getAttribute("SessionEmail").toString();
    // Current Password
    // String password = request.getParameter("password");
    // New Password
    String password1 = request.getParameter("password1");
    String password2 = request.getParameter("password2");

    String password1Encrypted = cabl.encryptPassword(password1);
    String password2Encrypted = cabl.encryptPassword(password2);

    System.out.println(email);
    System.out.println(password1);
    System.out.println(password2);

    // Check new passwords if they are the same
    if (password1Encrypted.equals(password2Encrypted)) {
      // check if current password matches the database password
      System.out.println("Profile Editing in Progress");
      cabl.updatePassword(email, password1);
      check = "Success: Password has been updated.";

    } else {
      check = "Error: The passwords you entered do not match.";
    }

    return check;
  }
 // Validate by checking if level name exist for a specified level (i.e. Corporate/Office/Shopping
 // Mall)
 private String validateAddLevel(HttpServletRequest request) {
   String checkResult = "";
   List entityList;
   String levelChar = request.getParameter("level");
   String levelName = request.getParameter("name");
   System.out.println("Level Name:" + levelName);
   // entityList contains information (level name) about all level in a specific level
   entityList = cabl.retrieveAllLevelName(levelChar);
   // Do Checking Here
   System.out.println("Size of EntityList" + entityList.size());
   // No Level Name is found for this level
   if (entityList.isEmpty()) {
     checkResult = "new";
     System.out.println("Level name is not found!");
   }
   // Level Name is found for this level, check to prevent duplicates
   for (int i = 0; i < entityList.size(); i++) {
     System.out.println("EntityList:" + entityList.get(i));
     if (entityList.get(i).equals(levelName)) {
       checkResult = "existed";
       System.out.println("Level name is already existed!");
       break;
     } else {
       checkResult = "new";
       System.out.println("Level name is not found!");
     }
   }
   System.out.println("Return" + " " + checkResult);
   return checkResult;
 }
  // Validate by checking if department name exist for a specified level (i.e.
  // Corporate/Office/Shopping Mall)
  private String validateAddDepartment(HttpServletRequest request) {
    String checkResult = "";
    HttpSession session = request.getSession(true);
    String tempLevelName = session.getAttribute("TempLevelName").toString();
    String departmentName = request.getParameter("departmentName");

    // entityList contains information (level name) about all level in a specific level
    List<String> departmentList = new ArrayList();
    try {
      System.out.println("Performing Retrieval for All department' name in a given level");
      departmentList = cabl.retrieveLevelTypeDepartment(tempLevelName);
      // No Department Name is found for this level
      if (departmentList.isEmpty()) {
        checkResult = "new";
        System.out.println("Department name is not found!");
      }
      // Department Name is found for this level, check to prevent duplicates
      for (int i = 0; i < departmentList.size(); i++) {
        if (departmentList.get(i).equals(departmentName)) {
          checkResult = "existed";
          System.out.println("Dept. name is already existed!");
          break;
        } else {
          checkResult = "new";
          System.out.println("Dept. name is not found!");
        }
      }
    } catch (Exception ex) {

    }
    System.out.println("No of Dept:" + " " + departmentList.size() + checkResult);

    return checkResult;
  }
  // Check position for difference between new and current (in database)
  private List<String> crossCheckPosition(HttpServletRequest request) {
    List<String> newPositionList = new ArrayList();
    List<String> oldPositionList = new ArrayList();
    HttpSession session = request.getSession(true);
    String levelName = session.getAttribute("TempLevelName").toString();
    System.out.println("Level Name" + levelName);

    String departmentName = session.getAttribute("TempDepartmentName").toString();
    System.out.println("Department Name" + departmentName);
    String position;
    position = request.getParameter("positionName");

    // Count number of commas (breakpoint(s))
    int count = position.length() - position.replace(",", "").length();
    System.out.println("Count is " + count);
    String[] parts = position.split(",");

    for (int i = 0; i < count + 1; i++) {
      newPositionList.add(parts[i]);
      System.out.println("Position added" + parts[i]);
    }
    System.out.println("New Position Size is: " + newPositionList);

    try {
      System.out.println("Performing crossCheckPosition");
      oldPositionList = cabl.retrieveDepartmentPosition(levelName, departmentName);
      System.out.println("Old Position Size is " + oldPositionList.size());
      newPositionList.removeAll(oldPositionList);
      System.out.println("Difference" + newPositionList);
    } catch (Exception ex) {

    }

    return newPositionList;
  }
 private String generateNewEmployeeID(HttpServletRequest request) {
   String newEmployeeID = new String();
   HttpSession session = request.getSession(true);
   if (session.getAttribute("TempLevelName") != null) {
     String levelName = session.getAttribute("TempLevelName").toString();
     System.out.println("Level Name" + levelName);
     newEmployeeID = cabl.generateEmployeeID(levelName);
     session.setAttribute("TempEmployeeID", newEmployeeID);
   }
   return newEmployeeID;
 }
  private String deleteDepartment(int index) {
    String checkStatus = "";
    try {
      List<String> departmentList = cabl.findLevelDepartment();
      String selectedLevel = departmentList.get(index);
      String departmentName, levelName = "";
      StringTokenizer st = new StringTokenizer(selectedLevel, "#");
      st.nextToken(); // Skipping for levelTypeChar
      levelName = st.nextToken();
      st.nextToken(); // Skipping for departmentID
      departmentName = st.nextToken();
      System.out.println("Level & Department Name is: " + levelName + departmentName);
      cabl.deleteDepartment(levelName, departmentName);
      checkStatus = "Department Deleted.";
    } catch (Exception ex) {

    }
    System.out.println(checkStatus);
    return checkStatus;
  }
  // Create a Department and assigned to a Level
  private void createDepartmentAssignLevel(HttpServletRequest request) {
    HttpSession session = request.getSession(true);
    String levelNameSelected = session.getAttribute("TempLevelName").toString();
    String departmentName = request.getParameter("departmentName");
    int departmentPhoneNumber = Integer.parseInt(request.getParameter("departmentPhoneNumber"));
    String departmentAddress = request.getParameter("departmentAddress");
    String departmentPostalCode = request.getParameter("departmentPostalCode");
    String departmentUnitNumber = request.getParameter("departmentUnitNumber");
    try {
      System.out.println("Calling Create Department Function");
      cabl.createDepartment(
          departmentName,
          departmentPhoneNumber,
          departmentAddress,
          departmentPostalCode,
          departmentUnitNumber);
      cabl.associateLevelDepartment(levelNameSelected);
    } catch (Exception ex) {

    }
  }
  private List<String> retrieveLevelDepartmentAddressPostal(HttpServletRequest request) {
    String levelNameSelected = request.getParameter("levelName");

    List<String> deptInfoList = new ArrayList();
    System.out.println("Performing Retrieval for All department' name in a given level");
    try {
      deptInfoList = cabl.findLevelAddressPostalCode(levelNameSelected);
    } catch (Exception ex) {

    }

    return deptInfoList;
  }
  private void createLevelType(HttpServletRequest request) {
    String level = request.getParameter("level");
    String name = request.getParameter("name");
    String country = request.getParameter("country");
    String address = request.getParameter("address");
    String postal = request.getParameter("postal");
    try {
      System.out.println(level + name + country + address + postal);
      System.out.println("Calling Create Level Type Function");
      cabl.createLevelType(level, name, country, address, postal);
    } catch (Exception ex) {

    }
  }
  private List<String> retrieveLevelTypeDepartmentName(HttpServletRequest request) {
    String levelNameSelected = request.getParameter("levelName");
    HttpSession session = request.getSession(true);
    session.setAttribute("TempLevelName", levelNameSelected);

    List<String> departmentList = new ArrayList();
    System.out.println("Performing Retrieval for All department' name in a given level");
    try {
      departmentList = cabl.retrieveLevelTypeDepartment(levelNameSelected);
      session.setAttribute("TempDepartmentNameList", departmentList);
    } catch (Exception ex) {

    }

    return departmentList;
  }
  private List<String> retrieveAllLevelName(HttpServletRequest request) {
    String levelTypeChar = request.getParameter("levelType");
    HttpSession session = request.getSession(true);
    session.setAttribute("TempLevelType", levelTypeChar);

    List<String> levelList = new ArrayList();
    System.out.println("Performing Retrieval for All Level(s) name in a given level");
    try {
      levelList = cabl.retrieveAllLevelName(levelTypeChar);
      session.setAttribute("TempLevelNameList", levelList);
    } catch (Exception ex) {

    }

    return levelList;
  }
  private String deleteLevel(int index) {
    String checkStatus = "";
    try {
      List<String> levelList = levelListInfo();
      String selectedLevel = levelList.get(index);
      String levelName = "";
      StringTokenizer st = new StringTokenizer(selectedLevel, "#");
      st.nextToken(); // Skipping the first level classification
      levelName = st.nextToken();
      System.out.println("Level Name is: " + levelName);
      cabl.deleteLevel(levelName);
      checkStatus = "Level Deleted.";
    } catch (Exception ex) {

    }
    System.out.println(checkStatus);
    return checkStatus;
  }
  private List<String> levelListInfo() {

    List<String> levelList = new ArrayList();
    System.out.println("Performing Level(s) Search in MMA");
    try {
      levelList = cabl.findLevelType();
      System.out.println("LevelList Size is:" + levelList.size());

      if (levelList.isEmpty()) {
        System.out.println("No level found.");
      } else {
        return levelList;
      }
    } catch (Exception ex) {

    }

    return levelList;
  }
  // Create and Associate Position to Relevant Department
  private String associateDepartmentPosition(HttpServletRequest request) {
    String message = "";
    HttpSession session = request.getSession(true);
    String levelName = session.getAttribute("TempLevelName").toString();
    String departmentName = session.getAttribute("TempDepartmentName").toString();
    System.out.println("Cross Checking Position");
    List<String> newPositionList = crossCheckPosition(request);

    try {
      System.err.println("servlet: associateDepartmentPosition");
      message = cabl.associateDepartmentPosition(newPositionList, levelName, departmentName);
      System.out.println("Message is " + message);

    } catch (Exception ex) {

    }

    return message;
  }
  private List<String> DepartmentListInfo() {

    List<String> departmentList = new ArrayList();
    System.out.println("Performing Department(s) Search in MMA");
    try {
      departmentList = cabl.findDepartment();
      System.out.println("departmentList Size is:" + departmentList.size());

      if (departmentList.isEmpty()) {
        System.out.println("No department found.");
      } else {
        return departmentList;
      }
    } catch (Exception ex) {

    }

    return departmentList;
  }
  private List<String> LevelDepartmentListInfo() {

    List<String> levelDepartmentList = new ArrayList();
    System.out.println("Performing Department(s) Search for all levels in MMA");
    try {
      levelDepartmentList = cabl.findLevelDepartment();
      System.out.println("levelDepartmentList Size is:" + levelDepartmentList.size());

      if (levelDepartmentList.isEmpty()) {
        System.out.println("No department found.");
      } else {
        return levelDepartmentList;
      }
    } catch (Exception ex) {

    }

    return levelDepartmentList;
  }
  private List<String> EmployeeListInfo() {

    List<String> employeetList = new ArrayList();
    System.out.println("Performing Employee(s) Search in MMA");
    try {
      employeetList = cabl.findEmployee();
      System.out.println("employeetList Size is:" + employeetList.size());

      if (employeetList.isEmpty()) {
        System.out.println("No employee found.");
      } else {
        return employeetList;
      }
    } catch (Exception ex) {

    }

    return employeetList;
  }
  private List<String> retrieveDepartmentPosition(HttpServletRequest request) {

    HttpSession session = request.getSession(true);
    String levelName = session.getAttribute("TempLevelName").toString();
    String departmentName = request.getParameter("departmentName");
    session.setAttribute("TempDepartmentName", departmentName);
    System.out.println("Level name: " + levelName);
    System.out.println("Department name: " + departmentName);

    List<String> positionList = new ArrayList();
    System.out.println("Performing Retrieval for All department' name in a given level");
    try {
      positionList = cabl.retrieveDepartmentPosition(levelName, departmentName);
      System.out.println("Position Size is " + positionList.size());
      for (int i = 0; i < positionList.size(); i++) {
        System.out.println("Position name2: " + positionList.get(i));
      }
    } catch (Exception ex) {

    }

    return positionList;
  }
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    response.setContentType("text/html;charset=UTF-8");
    System.out.println("AdministrationSystemServlet: processRequest()");
    try {

      // Declare and Initialize Variables
      String message = "";
      String formField = "";
      String levelNameSelected = "";
      String departmentNameSelected = "";
      List<String> data1 = new ArrayList();
      List<String> levelList;
      List<String> departmentList;
      List<String> positionList;
      List<String> employeeList;
      List<String> levelNameList;
      List<String> departmentNameList;
      List<String> deptInfoList;
      List<String> departmentPositionList;

      HttpSession session = request.getSession(true);
      RequestDispatcher dispatcher;
      ServletContext servletContext = getServletContext();

      // Define JSP Path
      String page = request.getPathInfo();
      page = page.substring(1);
      String query = request.getQueryString();
      // System.out.println(query);

      if ("adminHome".equals(page)) {
        if (session.getAttribute("Session") != null) {
          System.out.println("Entering Page: " + page);
          // Get dashboard summary count on adminHome
          int totalLevelSize = levelListInfo().size();
          request.setAttribute("totalLevelSize", totalLevelSize);
          int totalDepartmentSize = DepartmentListInfo().size();
          request.setAttribute("totalDepartmentSize", totalDepartmentSize);
          int totalEmployeeSize = EmployeeListInfo().size();
          request.setAttribute("totalEmployeeSize", totalEmployeeSize);

          if (session.getAttribute("timestamp") == null) {
            request.setAttribute("data", "dummy value");
            System.out.println("Timestamp is NULL");
            // First Time user login - redirect change password
            page = "changePassword";
            dispatcher = servletContext.getNamedDispatcher(page);
            dispatcher.forward(request, response);
          } else {
            // Update New Timestsamp Here
            cabl.updateNewTimestamp(session.getAttribute("SessionEmail").toString());
          }

        } // User is not logged in
        else {

        }

        System.out.println("New Timestamp is " + session.getAttribute("timestamp").toString());

      } else if ("changePassword".equals(page)) {
        System.out.println("Entering Page: " + page);
        String check = new String();
        if ("change=true".equals(query)) {
          if (request.getParameter("password1") != null
              && request.getParameter("password2") != null) {
            check = compareUserPassword(request);
            System.out.println(check);
            cabl.updateNewTimestamp(session.getAttribute("SessionEmail").toString());
          }
        }
        request.setAttribute("data", check);
      } else if ("addEmployee".equals(page)) {
        System.out.println("You are in addEmployee Page");
        System.out.println("Entering Page: " + page);
        if (query == null) {
          generatePassword(request);
        }
        System.out.println("Generating Employee ID");
        String newEmployeeID = generateNewEmployeeID(request);
        request.setAttribute("newEmployeeID", newEmployeeID);

        if ("create=true".equals(query)) {
          System.out.println("Initiating Create New Employee...");
          String preCheck = "";
          String email = "";

          String checkResult = createNewEmployee(request);
          if (checkResult.equals("new")) {
            preCheck = checkResult;
            email = request.getParameter("email");
            System.out.println("Email is" + email);
            firstName = request.getParameter("firstName");
            System.out.println("First Name is" + firstName);
            lastName = request.getParameter("lastName");
            System.out.println("Last Name is" + lastName);
          }
          request.setAttribute("message", preCheck);
          request.setAttribute("email", email);
          request.setAttribute("firstName", firstName);
          request.setAttribute("lastName", lastName);
        }

      } else if ("manageEmployee".equals(page)) {
        System.out.println("Entering Page: " + page);
        employeeList = EmployeeListInfo();
        System.out.println(employeeList.get(0));
        request.setAttribute("employeeList", employeeList);
      } else if ("addLevel".equals(page)) {
        System.out.println("Entering Page: " + page);
        if ("true".equals(query)) {
          System.out.println("Entering Query Page: " + query);
          String preCheck;

          if (request.getParameter("level").isEmpty()
              || request.getParameter("name").isEmpty()
              || request.getParameter("country").isEmpty()
              || request.getParameter("address").isEmpty()
              || request.getParameter("postal").isEmpty()) {
            message = "missing";
          }

          if (!"missing".equals(message)) {
            preCheck = validateAddLevel(request);
            if (preCheck.equals("existed")) {
              message = preCheck;
            } else {
              // preCheck is new (level name is not previously created)
              message = preCheck;
              System.out.println("Creating Level...");
              createLevelType(request);
            }
          }

          request.setAttribute("message", message);
        }
        // Pre-Selection parsed for corresponding addLevel fields
        if ("corporate".equals(query)) {
          formField = "Corporate";
        } else if ("local".equals(query)) {
          formField = "Local";
        } else if ("mall".equals(query)) {
          formField = "Mall";
        }
        request.setAttribute("formField", formField);

      } else if ("manageLevel".equals(page)) {
        System.out.println("Entering Page: " + page);
        levelList = levelListInfo();
        // System.out.println(levelList.get(0));
        request.setAttribute("levelList", levelList);
        System.out.println("Query is " + query);

        if (query != null) {
          System.err.println("Query is not NULL");
          // del=<Number>
          if (query.length() > 3) {
            // Only retrieve the index count
            index = Integer.parseInt(query.substring(4));
            System.out.println("Index obtained is " + index);
          } // del (Confirmation for delete)
          else {
            System.out.println("Index to delete is " + index);
            // Confirm delete
            deleteLevel(index);
            index = -1;
          }
        }

      } else if ("addDepartment".equals(page)) {
        System.out.println("Entering Page: " + page);
        if ("retrieveLevel".equals(query)) {
          System.out.println("Entering Page: " + page);
          String levelTypeSelected = request.getParameter("levelType");
          request.setAttribute("levelType", levelTypeSelected);
          levelNameList = retrieveAllLevelName(request);
          // System.out.println("Name: " +levelNameList.get(0));

          request.setAttribute("levelNameList", levelNameList);

        } else if ("retrieveDept".equals(query)) {
          levelNameSelected = request.getParameter("levelName");
          System.out.println("Level Name: " + levelNameSelected);

          departmentNameList = retrieveLevelTypeDepartmentName(request);
          request.setAttribute("departmentNameList", departmentNameList);

          deptInfoList = retrieveLevelDepartmentAddressPostal(request);
          request.setAttribute("deptInfoList", deptInfoList);
        } else if ("addDept".equals(query)) {
          System.out.println("Entering Page: " + page);
          String preCheck = "";

          if (request.getParameter("departmentName").isEmpty()
              || request.getParameter("departmentAddress").isEmpty()
              || request.getParameter("departmentPostalCode").isEmpty()
              || request.getParameter("departmentUnitNumber").isEmpty()
              || request.getParameter("departmentPhoneNumber").isEmpty()) {
            message = "missing";
          }

          if (!"missing".equals(message)) {
            preCheck = validateAddDepartment(request);
            if (preCheck.equals("existed")) {
              message = preCheck;
            } else {
              // preCheck is new (dept. name is not previously created)
              message = preCheck;
              System.out.println("Creating Department and Assigning to Level...");
              createDepartmentAssignLevel(request);
            }
          }

          request.setAttribute("message", message);
        }
      } else if ("manageDepartment".equals(page)) {
        System.out.println("Entering Page: " + page);
        departmentList = LevelDepartmentListInfo();
        System.out.println(departmentList.get(0));
        request.setAttribute("departmentList", departmentList);
        System.out.println("Query is " + query);

        if (query != null) {
          System.err.println("Query is not NULL");
          // del=<Number>
          if (query.length() > 3) {
            // Only retrieve the index count
            index = Integer.parseInt(query.substring(4));
            System.out.println("Index obtained is " + index);
          } // del (Confirmation for delete)
          else {
            System.out.println("Index to delete is " + index);
            // Confirm delete
            deleteDepartment(index);
            index = -1;
          }
        }
      } else if ("addPosition".equals(page)) {
        System.out.println("Entering Page: " + page);
        if ("retrieveLevel".equals(query)) {
          System.out.println("Entering Page: " + page);
          String levelTypeSelected = request.getParameter("levelType");
          request.setAttribute("levelType", levelTypeSelected);
          levelNameList = retrieveAllLevelName(request);
          // System.out.println("Name: " +levelNameList.get(0));
          request.setAttribute("levelNameList", levelNameList);

        } else if ("retrieveDept".equals(query)) {
          System.out.println("Entering Page: " + page);
          levelNameSelected = request.getParameter("levelName");
          System.out.println("Level Name: " + levelNameSelected);
          request.setAttribute("levelName", levelNameSelected);
          departmentNameList = retrieveLevelTypeDepartmentName(request);
          request.setAttribute("departmentNameList", departmentNameList);

        } else if ("retrievePos".equals(query)) {
          System.out.println("Entering Page: " + page);
          levelNameSelected = session.getAttribute("TempLevelName").toString();
          request.setAttribute("levelName", levelNameSelected);
          departmentNameSelected = request.getParameter("departmentName");
          request.setAttribute("departmentName", departmentNameSelected);
          departmentPositionList = retrieveDepartmentPosition(request);
          request.setAttribute("departmentPositionList", departmentPositionList);
        } else if ("true".equals(query)) {
          System.out.println("Entering Page: " + page);
          // System.out.println("Performing crossCheckPosition");
          // crossCheckPosition(request);
          System.out.println("Performing Association of Position(s)");
          associateDepartmentPosition(request);
        }

      } else if ("managePosition".equals(page)) {
        System.out.println("Entering Page: " + page);
        positionList = LevelDepartmentPositionListInfo();
        // System.out.println(positionList.get(0));
        request.setAttribute("positionList", positionList);
        System.out.println("Query is " + query);

        if (query != null) {
          System.err.println("Query is not NULL");
          // del=<Number>
          if (query.length() > 3) {
            // Only retrieve the index count
            index = Integer.parseInt(query.substring(4));
            System.out.println("Index obtained is " + index);
          } // del (Confirmation for delete)
          else {
            System.out.println("Index to delete is " + index);
            // Confirm delete
            deletePosition(index);
            index = -1;
          }
        }
      } else if ("ldpSelect".equals(page)) {
        System.out.println("Entering Page: " + page);
        if ("retrieveLevel".equals(query)) {
          System.out.println("Entering Query Page: " + query);
          String levelTypeSelected = request.getParameter("levelType");
          request.setAttribute("levelType", levelTypeSelected);
          levelNameList = retrieveAllLevelName(request);
          if (levelTypeSelected.equals("C")) {
            String tempLevelType = "Corporate Headquarter";
            session.setAttribute("TempLevelType", tempLevelType);
          } else if (levelTypeSelected.equals("L")) {
            String tempLevelType = "Local Branch Office";
            session.setAttribute("TempLevelType", tempLevelType);
          } else if (levelTypeSelected.equals("M")) {
            String tempLevelType = "Shopping Mall";
            session.setAttribute("TempLevelType", tempLevelType);
          }
          // System.out.println("Name: " +levelNameList.get(0));
          request.setAttribute("levelNameList", levelNameList);

        } else if ("retrieveDept".equals(query)) {
          System.out.println("Entering Query Page: " + query);
          levelNameSelected = request.getParameter("levelName");
          System.out.println("Level Name: " + levelNameSelected);
          request.setAttribute("levelName", levelNameSelected);
          departmentNameList = retrieveLevelTypeDepartmentName(request);
          request.setAttribute("departmentNameList", departmentNameList);

        } else if ("retrievePos".equals(query)) {
          System.out.println("Entering Query Page: " + query);
          levelNameSelected = session.getAttribute("TempLevelName").toString();
          request.setAttribute("levelName", levelNameSelected);
          departmentNameSelected = request.getParameter("departmentName");
          request.setAttribute("departmentName", departmentNameSelected);
          departmentPositionList = retrieveDepartmentPosition(request);
          request.setAttribute("departmentPositionList", departmentPositionList);
        } else if ("retrievePos=true".equals(query)) {
          System.out.println("Entering Query Page: " + query);
          String positionName = request.getParameter("positionName");
          session.setAttribute("TempPositionName", positionName);
          System.out.println("TempPositionName is: " + session.getAttribute("TempPositionName"));
        } else if ("restart".equals(query)) {
          System.out.println("Entering Query Page: " + query);
          session.removeAttribute("TempLevelName");
          session.removeAttribute("TempDepartmentName");
          session.removeAttribute("TempPositionName");
        }
      } else if ("sendSms".equals(page)) {

      } else if ("postSms".equals(page)) {
        sendSMS(request);
        System.out.println("Done 1.");
      } else if ("addMembership".equals(page)) {

      } else {
        page = "error";
        System.out.println("Entering Page: " + page);
      }

      dispatcher = servletContext.getNamedDispatcher(page);
      dispatcher.forward(request, response);

    } catch (Exception e) {
      log("Exception in AdministrationSystemServlet.processRequest()");
    }
  }
  private String createNewEmployee(HttpServletRequest request) throws ParseException {

    // Define Date Format Srandards as dd/MM/yyyy
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

    String message = "";
    HttpSession session = request.getSession(true);
    String levelNameSelected = session.getAttribute("TempLevelName").toString();
    String departmentNameSelected = session.getAttribute("TempDepartmentName").toString();
    String positionApplied = session.getAttribute("TempPositionName").toString();

    String employeeID = session.getAttribute("TempEmployeeID").toString();
    System.out.println("Employee ID " + employeeID);
    String employeePassword = session.getAttribute("TempEmployeePW").toString();
    System.out.println("Password " + employeePassword);
    String employeeEmail = request.getParameter("email");
    System.out.println("Email " + employeeEmail);
    String firstName = request.getParameter("firstName");
    System.out.println("First Name " + firstName);
    String lastName = request.getParameter("lastName");
    System.out.println("Last Name " + firstName);
    int mobileNumber = Integer.parseInt(request.getParameter("mobileNumber"));
    System.out.println("Mobile No. " + mobileNumber);
    int officeNumber = Integer.parseInt(request.getParameter("officeNumber"));
    System.out.println("Office No. " + officeNumber);
    String gender = request.getParameter("gender");
    char genderChar = '\0';
    genderChar = gender.charAt(genderChar);
    System.out.println("Gender " + genderChar);
    String dob = request.getParameter("dateOfBirth");
    Date dateOfBirth = sdf.parse(dob);
    System.out.println("DoB " + dob);
    String country = request.getParameter("country");
    System.out.println("Nationality " + country);
    String address = request.getParameter("address");
    System.out.println("Address " + address);
    String city = null;
    city = request.getParameter("city");
    System.out.println("City " + city);
    String bgct = request.getParameter("beginContract");
    Date beginContract = sdf.parse(bgct);
    System.out.println("Begin Contract " + beginContract);
    String ect = request.getParameter("endContract");
    Date endContract = sdf.parse(ect);
    System.out.println("End Contract " + endContract);
    double salary = 0;
    String timestamp = null;
    String photo = null;

    try {
      System.out.println("Creating New Employee...");
      cabl.createEmployee(
          employeeID,
          firstName,
          lastName,
          mobileNumber,
          officeNumber,
          genderChar,
          address,
          city,
          beginContract,
          endContract,
          employeeEmail,
          cabl.encryptPassword(employeePassword),
          country,
          dateOfBirth,
          photo,
          salary,
          timestamp,
          levelNameSelected,
          departmentNameSelected,
          positionApplied);
      message = "new";
    } catch (Exception ex) {

    }
    System.out.println("Employee is" + message);
    return message;
  }