/**
   * Method execute
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    MentorReqResponseForm responseForm =
        (MentorReqResponseForm) form; // TODO Auto-generated method stub
    RootMaster rootMaster = new RootMaster();
    AdvtMaster advtMaster = new AdvtMaster();
    HttpSession session = request.getSession();
    String uId = (String) session.getAttribute("uId");

    String compId = (String) session.getAttribute("compId");
    Vector allRights = (Vector) session.getAttribute("allRights");
    String adminFlag = allRights.elementAt(18).toString();
    if (((String) session.getAttribute("flag1")).equalsIgnoreCase("1")) {

      Vector<String> dataVec = new Vector<String>();
      String responseTextt = responseForm.getResponsetext();
      ////
      // System.out.println("request.getParameter...respIdrespIdrespId>>>>>"+request.getParameter("respid"));
      String respId = request.getParameter("respid");
      String complaintId = request.getParameter("compId");
      String flagforcom =
          (request.getParameter("flagforcom") != null) ? request.getParameter("flagforcom") : "";
      String recpType =
          (request.getParameter("respType") != null) ? request.getParameter("respType") : "";
      String accept1 =
          (request.getParameter("accept") != null) ? request.getParameter("accept") : "";
      //// System.out.println("to accept...in respons  .....accept....."+accept1);
      String flag = (request.getParameter("flag") != null) ? request.getParameter("flag") : "";
      if (request.getParameter("flag") != null) {
        flag = request.getParameter("flag").trim();
      } else {
        flag = "0";
      }
      //////// System.out.println("to flag...in respons  .....flag.IN RESPaCTION	...."+flag);
      String uid = (String) session.getAttribute("uId");
      java.util.Date dt = new java.util.Date();
      SimpleDateFormat sform = new SimpleDateFormat("yyyy-MM-dd, HH:mm:ss");
      String completeRemDate = sform.format(dt);
      StringTokenizer sttotal = new StringTokenizer(completeRemDate, ",");
      String creationDate = sttotal.nextToken();
      String creationTime = sttotal.nextToken();

      dataVec.add(responseTextt);
      dataVec.add(creationDate);
      dataVec.add(complaintId);
      dataVec.add(uid);
      dataVec.add(creationTime);
      dataVec.add(respId);
      dataVec.add(flag);
      dataVec.add("0");
      dataVec.add("1");
      dataVec.add("0");
      if (flag.equalsIgnoreCase("1")) {
        dataVec.add("Accept");

      } else if (flag.equalsIgnoreCase("0")) {
        dataVec.add("Reject");

      } else {
        dataVec.add("");
      }
      dataVec.add(flagforcom);
      String result = rootMaster.insertMenResponse(getDataSource(request, "advt"), dataVec);

      if ((result.equalsIgnoreCase("success")) && (!respId.equalsIgnoreCase("0"))) {
        ActionErrors errors = new ActionErrors();
        errors.clear();
        errors.add("reply", new ActionError("errors.entp.replySuccess"));
        saveErrors(request, errors);
        result = "success";
      } else if (result.equalsIgnoreCase("success")) {
        ActionErrors errors = new ActionErrors();
        errors.clear();
        errors.add("response", new ActionError("errors.entp.responseSuccess"));
        saveErrors(request, errors);
        result = "success";
      }

      if (result.equalsIgnoreCase("success")) {
        if (!respId.equalsIgnoreCase("0")) {
          Vector<String> respVec = new Vector<String>();
          respVec.add(respId);
          respVec.add("advt");
          // update `entp_rflag` for communication table.
          result = rootMaster.updateResponseFlag(getDataSource(request, "advt"), respVec);
        }
      }

      ////////////// for mail///////////////
      if (result.equalsIgnoreCase("success")) {

        EntpMaster entpMaster = new EntpMaster();
        IndvMaster indvMaster = new IndvMaster();
        Vector<String> complaintVec = new Vector<String>();
        int cid = Integer.parseInt(complaintId);
        complaintVec = entpMaster.getComplaintDetails(getDataSource(request, "advt"), cid);
        String login_id = complaintVec.elementAt(3).toString();
        String cu_id = complaintVec.elementAt(6).toString();
        String fcomId = complaintVec.elementAt(7).toString();

        Vector<String> paramVec = new Vector<String>();

        //////// System.out.println("to Enterprise.............mail");
        paramVec.add(uid);
        paramVec.add(login_id);
        if (!cu_id.equalsIgnoreCase("0")) {
          paramVec.add(cu_id);
          //////// System.out.println(" to Enterprise..in if...........mail");
        }
        Vector emailVec = indvMaster.getEmailList(getDataSource(request, "advt"), paramVec);
        //////// System.out.println("emailVec..............."+emailVec);

        Vector<String> tempMailParam = new Vector<String>();
        tempMailParam.add("Corporates"); // sender company type Advertiser
        tempMailParam.add("Student"); // receipient company type Enterprise
        if (respId.equalsIgnoreCase("0")) {
          //////// System.out.println("Response if status in brand");
          tempMailParam.add("Response"); // mail description
        } else {
          //////// System.out.println("Reply else status in brand");
          tempMailParam.add("Reply"); // mail description
        }

        // get mail text alert fot sending mail to core user and admin core user
        String mailTextLAlert =
            rootMaster.getMailText(getDataSource(request, "advt"), tempMailParam);
        Vector brandVec = (Vector) emailVec.elementAt(0);
        String brandName =
            brandVec.elementAt(0).toString() + " " + brandVec.elementAt(1).toString();
        String brandmail = brandVec.elementAt(2).toString().trim();
        String subject = "";
        if (flag.equalsIgnoreCase("1")) {
          // dataVec.add("Accept");
          subject = "Acceptance of the mentoring request having reference id as (" + fcomId + ").";

        } else if (flag.equalsIgnoreCase("0")) {
          // dataVec.add("Reject");
          subject = "Denial of the mentoring request having reference id as (" + fcomId + ").";

        } else if (respId.equalsIgnoreCase("0")) {

          subject = "Response on mentoring request Id (" + fcomId + ") By " + brandName + ".";
        } else {

          subject =
              "Reply to your mail on mentoring request Id (" + fcomId + ") By " + brandName + ".";
        }

        for (int i = 1; i < emailVec.size(); i++) {
          MailText mt = new MailText();
          Resource resr = new Resource();
          Vector coreMailVec = (Vector) emailVec.elementAt(i);
          String strMailText =
              mt.getReplyByBrand(coreMailVec, fcomId, mailTextLAlert, brandName, flag);

          ////// System.out.println("strMailText....."+strMailText);

          String strEmailStatus =
              resr.sendMail(
                  strMailText,
                  Constant.Email_Sender,
                  ((Vector) emailVec.elementAt(i)).elementAt(2).toString(),
                  subject);
          ////// System.out.println("str Email status in corpo....."+strEmailStatus);
        }
      }
      ///////////////// end mail////////////

      session.setAttribute("numCid", complaintId);
      session.setAttribute("strResult", result);

      Vector dataVec1 = new Vector();
      dataVec1.add(uId);
      dataVec1.add(compId);
      dataVec1.add(adminFlag);
      Vector advtCountVec = advtMaster.complaintCountAdvt(getDataSource(request, "advt"), dataVec1);
      session.setAttribute("advtCountVec", advtCountVec);
      //////// System.out.println("advtCountVec.............ResponseAction...........
      // "+advtCountVec);
      if (result.equalsIgnoreCase("success")) {
        session.setAttribute("flag1", "0");
      }
      return mapping.findForward(result);
    } else {

      return mapping.findForward("success");
    }
  }
  /**
   * Method execute
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HttpSession session = request.getSession();
    //	System.out.println("checkpoint13");
    String numCount = (String) session.getAttribute("numCount");

    int count = Integer.parseInt(numCount);
    int remander = count % 2;
    System.out.println("checkpoint at corpo 2");
    AdvtMaster advtMaster = new AdvtMaster();
    RootMaster rootMaster = new RootMaster();
    IndvMaster indvMaster = new IndvMaster();

    String uId = (String) session.getAttribute("uId");
    String compId = (String) session.getAttribute("compId");

    System.out.println("compId..in Action avdt ........." + compId);
    //	int regFlag= rootMaster.getRegisteredFlag(getDataSource(request, "corpo"), compId);
    //	System.out.println("regFlag..in Action avdt ........."+regFlag);

    Vector allRights = (Vector) session.getAttribute("allRights");
    String adminFlag = allRights.elementAt(18).toString();

    //	 System.out.println("checkpoint at corpo 3");

    String pageid =
        (request.getParameter("pageid") != null) ? request.getParameter("pageid").trim() : "1";
    String aType =
        (request.getParameter("aType") != null) ? request.getParameter("aType").trim() : "0";
    String lowerSubTag =
        (request.getParameter("lowerSubTag") != null)
            ? request.getParameter("lowerSubTag").trim()
            : "1";
    String categoryid =
        (request.getParameter("categoryid") != null)
            ? request.getParameter("categoryid").trim()
            : "0";

    //	System.out.println("lowerSubTag..in Action avdt ........."+lowerSubTag);
    java.util.Date dt = new java.util.Date();
    SimpleDateFormat sform = new SimpleDateFormat("yyyy-MM-dd");
    String completeRemDate = sform.format(dt);
    StringTokenizer sttotal = new StringTokenizer(completeRemDate, ",");
    String creationDate = sttotal.nextToken();
    String dateToday[] = creationDate.split("-");
    String YR = dateToday[0];
    String DaY = dateToday[2];
    String MTH = dateToday[1];

    String month = (request.getParameter("Month") != null) ? request.getParameter("Month") : MTH;
    String nYear = (request.getParameter("Year") != null) ? request.getParameter("Year") : YR;

    System.out.println("month and yesar" + month + " " + nYear);
    String strShortBy =
        (request.getParameter("sby") != null) ? request.getParameter("sby") : "creation_date";
    String strSOrder = "";
    String strComFIdOrder = "asc";
    String strCTitelOrder = "asc";
    String strDateOrder = "asc";

    if (request.getParameter("sby") != null) {
      if (request.getParameter("fidorder") != null) {
        if (request.getParameter("fidorder").trim().equalsIgnoreCase("asc")) {
          strSOrder = "desc";
          strComFIdOrder = "desc";
        } else if (request.getParameter("fidorder").trim().equalsIgnoreCase("desc")) {
          strSOrder = "asc";
          strComFIdOrder = "asc";
        }
      }

      if (request.getParameter("ctorder") != null) {
        if (request.getParameter("ctorder").trim().equalsIgnoreCase("asc")) {
          strSOrder = "desc";
          strCTitelOrder = "desc";
        } else if (request.getParameter("ctorder").trim().equalsIgnoreCase("desc")) {
          strSOrder = "asc";
          strCTitelOrder = "asc";
        }
      }
      if (request.getParameter("dateorder") != null) {
        if (request.getParameter("dateorder").trim().equalsIgnoreCase("asc")) {
          strSOrder = "desc";
          strDateOrder = "desc";
        } else if (request.getParameter("dateorder").trim().equalsIgnoreCase("desc")) {
          strSOrder = "asc";
          strDateOrder = "asc";
        }
      }
    }
    String strFShortBy = strShortBy + " " + strSOrder;
    int minVal =
        (request.getParameter("numMin") != null)
            ? Integer.parseInt(request.getParameter("numMin"))
            : 0;
    int maxVal = 10;
    //// System.out.println("countVec.............InboxAction......minVal..... "+minVal);
    //// System.out.println("countVec.............InboxAction......maxVal..... "+maxVal);

    Vector<String> paramVec1 = new Vector<String>();
    paramVec1.add(uId);
    paramVec1.add(compId);
    paramVec1.add(adminFlag);
    paramVec1.add(pageid);

    Vector<String> paramVec = new Vector<String>();
    paramVec.add(String.valueOf(minVal));
    paramVec.add(String.valueOf(maxVal));
    paramVec.add(strFShortBy);
    paramVec.add(uId);
    paramVec.add(compId);
    paramVec.add(adminFlag);
    paramVec.add(pageid);

    int Cid = Integer.parseInt(compId);
    int Uid = Integer.parseInt(uId);
    int aFid = Integer.parseInt(adminFlag);

    Vector comVec = new Vector();
    Vector comListVec = new Vector();
    String comList = "";

    paramVec1.add("0");
    paramVec.add("0");

    ////// System.out.println("comList................on page."+comList);
    int totalRow = 0;
    paramVec1.add(lowerSubTag);
    paramVec1.add(categoryid);
    paramVec1.add(month);
    paramVec1.add(nYear);

    paramVec.add(lowerSubTag);
    paramVec.add(categoryid);
    paramVec.add(month);
    paramVec.add(nYear);
    totalRow = advtMaster.getComplaintCountL(getDataSource(request, "corpo"), paramVec1);
    Vector UserVec = advtMaster.getBrandComplaintList1L(getDataSource(request, "corpo"), paramVec);

    String country = "", state = "", city = "", brand = "", category = "", firstName = "";

    String countryName = "", stateName = "", cityName = "", brandName = "", categoryName = "";
    String searchFor = "";
    DataSource dataSource = getDataSource(request, "corpo");

    Vector userVec = (Vector) session.getAttribute("userVec");
    Vector cscVec = (Vector) session.getAttribute("cscVec");
    cscVec = userVec;
    Vector userTempVec = new Vector();
    if (session.getAttribute("userVec") != null) {
      userTempVec = (Vector) session.getAttribute("userVec");
      for (int i = 0; i < userTempVec.size(); i++) {
        if (userTempVec.elementAt(i).toString().equals("city =")) {
          city = userTempVec.elementAt(i + 1).toString().trim();
          cityName = rootMaster.getPlaceName(dataSource, Integer.parseInt(city));
          break;
        }
      }
    }
    Vector searchVec = new Vector();

    /*
     *  searchFor (0) Student.
     */

    if (searchFor.equalsIgnoreCase("0")) {
      if (session.getAttribute("searchVec") != null) {
        searchVec = (Vector) session.getAttribute("searchVec");
        for (int i = 0; i < searchVec.size(); i++) {
          paramVec.add(searchVec.elementAt(i).toString());
          if (searchVec.elementAt(i).toString().equals("course =")) {
            category = searchVec.elementAt(i + 1).toString().trim();
            Vector categoryNameVec =
                indvMaster.getCourseName(dataSource, Integer.parseInt(category.trim()));
            categoryName = categoryNameVec.elementAt(0).toString();
          }
          if (searchVec.elementAt(i).toString().equals("first_name like")) {
            firstName = searchVec.elementAt(i + 1).toString().trim();

            String teamCat1[] = firstName.split("%");
            ////////// System.out.println("teamCat[]>>>>>>>searchVec>>>>>>>"+teamCat1[1]);
            firstName = teamCat1[1];
          }
          if (searchVec.elementAt(i).toString().equals("college_id =")) {
            brand = searchVec.elementAt(i + 1).toString().trim();

            String StrArr[] = brand.split("~");
            int compnyid = Integer.parseInt(StrArr[0]);

            if (compnyid == 0) {
              compnyid = Integer.parseInt(userVec.elementAt(27).toString());
              Vector name = indvMaster.getOtherCollege(dataSource, compnyid);
              brandName = name.elementAt(0).toString().trim();
            } else if (StrArr[1].equalsIgnoreCase("1")) {
              brandName = rootMaster.getCompnyName(dataSource, compnyid);
            } else {
              brandName = rootMaster.getCollegeName(dataSource, compnyid);
            }
            // brandName

          }
        }
      }
      if (session.getAttribute("userVec") != null) {
        for (int i = 0; i < userVec.size(); i++) {
          paramVec.add(userVec.elementAt(i).toString());
        }
      }
    }

    String strPageHtml = getPages(minVal, maxVal, totalRow, lowerSubTag, pageid, numCount);

    int regFlag = 0;
    int numcount = UserVec.size();
    String strComplaintList =
        getComplaintList(
            searchFor,
            dataSource,
            numcount,
            strComFIdOrder,
            strCTitelOrder,
            strDateOrder,
            minVal,
            maxVal,
            totalRow,
            strPageHtml,
            UserVec,
            pageid,
            lowerSubTag,
            regFlag,
            city,
            brand,
            categoryName,
            cityName,
            brandName,
            remander,
            firstName,
            month,
            nYear);
    // System.out.println("Users "+strComplaintList);
    /**
     * setContentType - text/html to write String on page. PrintWriter - This line use to get writer
     * to write on page. out.println - use to write string.
     */
    response.setContentType("text/html;charset=ISO-8859-1");
    PrintWriter out = response.getWriter();
    out.println(strComplaintList);
    out.flush();

    // TODO Auto-generated method stub
    return null;
  }