/**
   * Process the specified HTTP request, and create the corresponding HTTP response (or forward to
   * another web component that will create it). Return an <code>ActionForward</code> instance
   * describing where and how control should be forwarded, or <code>null</code> if the response has
   * already been completed.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @exception Exception if business logic throws an exception
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // Extract attributes we will need
    MessageResources messages = getResources(request);

    // save errors
    ActionMessages errors = new ActionMessages();

    // START check for login (security)
    if (!SecurityService.getInstance().checkForLogin(request.getSession(false))) {
      return (mapping.findForward("welcome"));
    }
    // END check for login (security)

    // get the current user for displaying personal info, such as "My Projects"
    User u =
        UserService.getInstance()
            .getSingleUser((String) request.getSession(false).getAttribute("username"));
    System.out.println(
        "local addresss sssssssssssssss"
            + request.getLocalAddr()
            + "          "
            + request.getLocalName());
    long startProjects = System.currentTimeMillis();
    String myName = u.getFirstName() + " " + u.getLastName();
    List myHr = HrHelper.getAllEmployeesFormer(u);
    long endProjects = System.currentTimeMillis();
    System.out.println("GetMyHrAction took:" + ((endProjects - startProjects) / 1000.0));
    response.setContentType("text/html");
    response.setHeader("Cache-Control", "no-cache");
    // System.out.println(actResponse.toXML());
    PrintWriter out = response.getWriter();
    out.println(new JSONArray(myHr.toArray()));
    out.flush();

    // Forward control to the specified success URI
    return (null);
  }
  /**
   * Process the specified HTTP request, and create the corresponding HTTP response (or forward to
   * another web component that will create it). Return an <code>ActionForward</code> instance
   * describing where and how control should be forwarded, or <code>null</code> if the response has
   * already been completed.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @exception Exception if business logic throws an exception
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // Extract attributes we will need
    MessageResources messages = getResources(request);

    // save errors
    ActionMessages errors = new ActionMessages();

    // START check for login (security)
    if (!SecurityService.getInstance().checkForLogin(request.getSession(false))) {
      return (mapping.findForward("welcome"));
    }
    // END check for login (security)

    // PRIVS check that hrAdmin user is viewing this page
    if (!StandardCode.getInstance()
        .checkPrivStringArray(
            (String[]) request.getSession(false).getAttribute("userPrivs"), "hrAdmin")) {
      return (mapping.findForward("accessDenied"));
    } // END PRIVS check that hrAdmin user is viewing this page

    // get user to edit from form hidden field
    String hrAdminUserId = request.getParameter("hrAdminUserId");
    User u = UserService.getInstance().getSingleUser(Integer.valueOf(hrAdminUserId));
    User currentUser =
        UserService.getInstance()
            .getSingleUser((String) request.getSession(false).getAttribute("username"));

    // values for update from form; change what is stored in db to these values
    DynaValidatorForm uvg = (DynaValidatorForm) form;

    String username = (String) uvg.get("username");
    String password = (String) uvg.get("password");

    // update the user's values
    if (username.length() > 0) { // if present
      u.setUsername(username);
    }
    if (password.length() > 0) { // if present, hash password for safe db store
      MessageDigest md = null;
      try {
        md = MessageDigest.getInstance("SHA"); // step 2
      } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
      }
      try {
        md.update(password.getBytes("UTF-8")); // step 3
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
      byte raw[] = md.digest(); // step 4
      String hash = (new BASE64Encoder()).encode(raw); // step 5
      u.setPassword(hash);
    }

    // set updated values to db
    UserService.getInstance().updateUser(u);
    String firstName = u.getFirstName();
    String msg =
        "<font size='2'><span style='font-family: Verdana,Arial,Helvetica,sans-serif;'>Dear <span style='color: rgb(255, 0, 0);'>"
            + firstName
            + "</span>,<br><br style='font-family: Verdana,Arial,Helvetica,sans-serif;'></span><span style='font-family: Verdana,Arial,Helvetica,sans-serif;'>We have created an account for you on ExcelNet, Excel Translations' proprietary intra/extranet system. <br><br> Below you will find the information you need to enter our system, please keep this only to yourself in a secure place.  </span><br style='font-family: Verdana,Arial,Helvetica,sans-serif;'><span style='font-family: Verdana,Arial,Helvetica,sans-serif;'><br>User Name: "
            + username
            + "</span><br style='font-family: Verdana,Arial,Helvetica,sans-serif;'><span style='font-family: Verdana,Arial,Helvetica,sans-serif;'>Password&nbsp;&nbsp;: "
            + password
            + "</span><br style='font-family: Verdana,Arial,Helvetica,sans-serif;'><br style='font-family: Verdana,Arial,Helvetica,sans-serif;'><span style='font-family: Verdana,Arial,Helvetica,sans-serif;'>You can log in into your Account on by clicking </span><a style='font-family: Verdana,Arial,Helvetica,sans-serif;' href='http://excelnet.xltrans.com'>here</a><span style='font-family: Verdana,Arial,Helvetica,sans-serif;'>.<br><br><br>Best Regards,</span><br style='font-family: Verdana,Arial,Helvetica,sans-serif;'><br style='font-family: Verdana,Arial,Helvetica,sans-serif;'><span style='font-family: Verdana,Arial,Helvetica,sans-serif; Best regards,<br style='font-family: Verdana,Arial,Helvetica,sans-serif;'></font><font style='font-family: Verdana,Arial,Helvetica,sans-serif;' size='2'><span class='Apple-style-span' style='border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;'><span class='Apple-style-span' style='color: rgb(59, 105, 119); font-size: 11px; text-align: left;'><br> ExcelNet Administrator<br>Excel Translations, Inc.<br><br><img src=http://excelnet.xltrans.com/logo/images/-1168566039logoExcel.gif></span></span></font><br> ";
    String emailMsgTxt = msg;
    String emailSubjectTxt = "New User Account";
    String adminEmail;
    String userEmailId = "*****@*****.**";
    if (!u.getWorkEmail1().equalsIgnoreCase("")) {

      userEmailId = u.getWorkEmail1();
    } else if (!u.getWorkEmail2().equalsIgnoreCase("")) {
      userEmailId = u.getWorkEmail2();
    } else {
      userEmailId = "*****@*****.**";
    }
    if (currentUser.getWorkEmail1() == null || currentUser.getWorkEmail1().equalsIgnoreCase("")) {
      adminEmail = "*****@*****.**";

    } else adminEmail = currentUser.getWorkEmail1();

    try {
      String[] emailList = {userEmailId, adminEmail};
      SendEmail smtpMailSender = new SendEmail();
      smtpMailSender.postMail(emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
    } catch (Exception e) {

      // String[] emailList = {"niteshwar.kumarpatialideas.com"};
      // SendEmail smtpMailSender = new SendEmail();
      // smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);

    }

    // Forward control to the specified success URI
    return (mapping.findForward("Success"));
  }