/**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandMove(ActionContext context) {
   // Parameters
   String itemId = (String) context.getRequest().getParameter("id");
   Connection db = null;
   try {
     db = getConnection(context);
     // Load the ticket and the organization
     Ticket thisTicket = addTicket(context, db);
     int ticketId = thisTicket.getId();
     // Check access permission to organization record
     if (!isRecordAccessPermitted(context, db, thisTicket.getOrgId())) {
       return ("PermissionError");
     }
     // Load the folder
     FileFolder thisFolder = new FileFolder(db, Integer.parseInt(itemId));
     context.getRequest().setAttribute("FileFolder", thisFolder);
     // Load the current folders
     FileFolderHierarchy hierarchy = new FileFolderHierarchy();
     hierarchy.setLinkModuleId(Constants.DOCUMENTS_TICKETS);
     hierarchy.setLinkItemId(ticketId);
     hierarchy.build(db);
     context.getRequest().setAttribute("folderHierarchy", hierarchy);
     return "MoveOK";
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
 }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandModify(ActionContext context) {
   Exception errorMessage = null;
   boolean recordDeleted = false;
   // TODO: Add some permissions to get here!
   // Modify the itemId, and the folderId will be the location to return to
   String itemId = (String) context.getRequest().getParameter("id");
   String folderId = (String) context.getRequest().getParameter("folderId");
   Connection db = null;
   try {
     db = getConnection(context);
     // Load the ticket and the organization
     Ticket thisTicket = addTicket(context, db);
     int ticketId = thisTicket.getId();
     // Check access permission to organization record
     if (!isRecordAccessPermitted(context, db, thisTicket.getOrgId())) {
       return ("PermissionError");
     }
     // Load the file folder to be modified
     FileFolder thisFolder = (FileFolder) context.getFormBean();
     thisFolder.setId(Integer.parseInt(itemId));
     thisFolder.queryRecord(db, Integer.parseInt(itemId));
   } catch (Exception e) {
     errorMessage = e;
   } finally {
     this.freeConnection(context, db);
   }
   if (errorMessage == null) {
     return (executeCommandAdd(context));
   } else {
     context.getRequest().setAttribute("Error", errorMessage);
     return ("SystemError");
   }
 }
  /**
   * Items for a SurveyQuestion given the questionId
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandViewItems(ActionContext context) {
    if (!(hasPermission(context, "campaign-campaigns-surveys-view"))) {
      return ("PermissionError");
    }
    Exception errorMessage = null;
    Connection db = null;
    int questionId = -1;
    if (context.getRequest().getParameter("questionid") != null) {
      if (!context.getRequest().getParameter("questionid").equals("")) {
        questionId = Integer.parseInt(context.getRequest().getParameter("questionid"));
      }
    }

    try {
      db = this.getConnection(context);
      ItemList itemList = new ItemList();
      itemList.setQuestionId(questionId);
      itemList.buildList(db);
      context.getRequest().setAttribute("ItemList", itemList);
    } catch (Exception e) {
      errorMessage = e;
    } finally {
      this.freeConnection(context, db);
    }
    if (errorMessage == null) {
      return "ViewItemsOK";
    }
    return "SystemError";
  }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandAdd(ActionContext context) {
   Exception errorMessage = null;
   // Load project
   Connection db = null;
   try {
     FileFolder thisFolder = (FileFolder) context.getFormBean();
     thisFolder.setParentId(context.getRequest().getParameter("parentId"));
     db = getConnection(context);
     // Load the ticket and the organization
     Ticket thisTicket = addTicket(context, db);
     int ticketId = thisTicket.getId();
     // Check access permission to organization record
     if (!isRecordAccessPermitted(context, db, thisTicket.getOrgId())) {
       return ("PermissionError");
     }
     // Build array of folder trails
     ProjectManagementFileFolders.buildHierarchy(db, context);
     context.getRequest().setAttribute("fileFolder", thisFolder);
   } catch (Exception e) {
     errorMessage = e;
   } finally {
     this.freeConnection(context, db);
   }
   if (errorMessage == null) {
     return ("AddOK");
   } else {
     context.getRequest().setAttribute("Error", errorMessage);
     return ("SystemError");
   }
 }
 /**
  * Adds a feature to the Ticket attribute of the TroubleTicketsDocumentsFolders object
  *
  * @param context The feature to be added to the Ticket attribute
  * @param db The feature to be added to the Ticket attribute
  * @return Description of the Return Value
  * @throws SQLException Description of the Exception
  */
 private Ticket addTicket(ActionContext context, Connection db) throws SQLException {
   String ticketId = (String) context.getRequest().getParameter("tId");
   if (ticketId == null) {
     ticketId = (String) context.getRequest().getAttribute("tId");
   }
   return addTicket(context, db, ticketId);
 }
 /**
  * Adds a feature to the Ticket attribute of the TroubleTicketsDocumentsFolders object
  *
  * @param context The feature to be added to the Ticket attribute
  * @param db The feature to be added to the Ticket attribute
  * @return Description of the Return Value
  * @throws SQLException Description of the Exception
  */
 private Ticket addTicket(ActionContext context, Connection db, String ticketId)
     throws SQLException {
   context.getRequest().setAttribute("tId", ticketId);
   Ticket thisTicket = new Ticket(db, Integer.parseInt(ticketId));
   context.getRequest().setAttribute("TicketDetails", thisTicket);
   return thisTicket;
 }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandDelete(ActionContext context) {
   if (!hasPermission(context, "tickets-tickets-tasks-delete")) {
     return ("PermissionError");
   }
   Connection db = null;
   Task thisTask = null;
   String sourcePopup = context.getRequest().getParameter("sourcePopup");
   String id = context.getRequest().getParameter("id");
   try {
     db = this.getConnection(context);
     thisTask = new Task(db, Integer.parseInt(id));
     thisTask.buildLinkDetails(db);
     if (!hasAuthority(context, thisTask.getOwner())) {
       return ("PermissionError");
     }
     thisTask.delete(db);
     this.deleteRecentItem(context, thisTask);
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
   context.getRequest().setAttribute("Task", thisTask);
   if (sourcePopup != null && "true".equals(sourcePopup.trim())) {
     return ("DeletePopupOK");
   }
   context
       .getRequest()
       .setAttribute(
           "refreshUrl",
           "TroubleTicketTasks.do?command=List&ticketId="
               + thisTask.getLinkDetails().getLinkItemId());
   return ("DeleteOK");
 }
  /**
   * Description of the Method
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandAdd(ActionContext context) {
    if (!hasPermission(context, "admin-sysconfig-customlistviews-add")) {
      return ("PermissionError");
    }
    addModuleBean(context, "Configuration", "Custom List Views");
    Connection db = null;
    String moduleId = context.getRequest().getParameter("moduleId");
    try {
      db = getConnection(context);
      // build the module details
      PermissionCategory permCat = new PermissionCategory(db, Integer.parseInt(moduleId));
      context.getRequest().setAttribute("permissionCategory", permCat);

      // build master list of fields available for this view
      SystemStatus thisSystem = this.getSystemStatus(context);
      String constantId = context.getRequest().getParameter("constantId");
      CustomListViewEditor editor =
          thisSystem.getCustomListViewEditor(context, db, Integer.parseInt(constantId));
      context.getRequest().setAttribute("customListViewEditor", editor);
    } catch (Exception e) {
      e.printStackTrace(System.out);
      context.getRequest().setAttribute("Error", e);
      return ("SystemError");
    } finally {
      this.freeConnection(context, db);
    }
    return "AddOK";
  }
 /**
  * Lists the tasks for the specified ticket
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandList(ActionContext context) {
   if (!hasPermission(context, "tickets-tickets-tasks-view")) {
     return ("PermissionError");
   }
   // Parameters
   String ticketId = context.getRequest().getParameter("ticketId");
   Connection db = null;
   TaskList taskList = new TaskList();
   // Paged List
   PagedListInfo ticTaskListInfo = this.getPagedListInfo(context, "TicketTaskListInfo");
   ticTaskListInfo.setItemsPerPage(0);
   try {
     db = this.getConnection(context);
     // Load the task list
     taskList.setTicketId(Integer.parseInt(ticketId));
     taskList.setPagedListInfo(ticTaskListInfo);
     taskList.buildList(db);
     context.getRequest().setAttribute("TaskList", taskList);
     // Load the ticket
     Ticket thisTicket = new Ticket(db, Integer.parseInt(ticketId));
     // Check access permission to organization record
     if (!isRecordAccessPermitted(context, db, thisTicket.getOrgId())) {
       return ("PermissionError");
     }
     context.getRequest().setAttribute("TicketDetails", thisTicket);
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
   addModuleBean(context, "ViewTickets", "List Tasks");
   return getReturn(context, "ListTasks");
 }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandDetails(ActionContext context) {
   if (!hasPermission(context, "tickets-tickets-tasks-view")) {
     return ("PermissionError");
   }
   Connection db = null;
   Task thisTask = null;
   String id = context.getRequest().getParameter("id");
   if (id == null || "".equals(id.trim())) {
     id = (String) context.getRequest().getAttribute("id");
   }
   SystemStatus systemStatus = this.getSystemStatus(context);
   try {
     db = this.getConnection(context);
     thisTask = new Task(db, Integer.parseInt(id));
     // Check access permission to organization record
     if (!isRecordAccessPermitted(context, db, thisTask.getTicket().getOrgId())) {
       return ("PermissionError");
     }
     context.getRequest().setAttribute("Task", thisTask);
     LookupList list = systemStatus.getLookupList(db, "lookup_ticket_task_category");
     context.getRequest().setAttribute("ticketTaskCategoryList", list);
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
   addModuleBean(context, "View Tickets", "View Tickets");
   return getReturn(context, "TaskDetails");
 }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandViewReturn(ActionContext context) {
   String returnType = context.getRequest().getParameter("return");
   if (!"list".equals(returnType)) {
     String id = context.getRequest().getParameter("id");
     if (id != null && !"-1".equals(id)) {
       return executeCommandDetails(context);
     }
   }
   return executeCommandView(context);
 }
 /**
  * Adds a feature to the Contact attribute of the Prototype object
  *
  * @param context The feature to be added to the Contact attribute
  * @param db The feature to be added to the Contact attribute
  * @throws SQLException Description of the Exception
  */
 private void addContact(ActionContext context, Connection db) throws SQLException {
   String contactId = (String) context.getRequest().getParameter("contactId");
   if (contactId == null) {
     contactId = (String) context.getRequest().getAttribute("contactId");
   }
   if (contactId != null) {
     Contact thisContact = new Contact(db, Integer.parseInt(contactId));
     context.getRequest().setAttribute("ContactDetails", thisContact);
   }
 }
 /**
  * Insert or update a Survey
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandInsert(ActionContext context) {
   if (!(hasPermission(context, "campaign-campaigns-surveys-add")
       || hasPermission(context, "campaign-campaigns-surveys-edit"))) {
     return ("PermissionError");
   }
   boolean recordInserted = false;
   int recordsModified = -1;
   boolean isValid = false;
   Connection db = null;
   try {
     Survey newSurvey = (Survey) context.getFormBean();
     int surveyId = -1;
     if (context.getRequest().getParameter("id") != null
         && !(context.getRequest().getParameter("id").equals(""))) {
       surveyId = Integer.parseInt(context.getRequest().getParameter("id"));
     }
     if (surveyId == -1) {
       newSurvey.setEnteredBy(getUserId(context));
     }
     newSurvey.setModifiedBy(getUserId(context));
     newSurvey.setRequestItems(context.getRequest());
     db = this.getConnection(context);
     isValid = this.validateObject(context, db, newSurvey);
     Iterator iter = (Iterator) newSurvey.getQuestions().iterator();
     while (iter.hasNext()) {
       SurveyQuestion question = (SurveyQuestion) iter.next();
       isValid = this.validateObject(context, db, question) && isValid;
     }
     if (isValid) {
       if (surveyId == -1) {
         recordInserted = newSurvey.insert(db);
       } else {
         recordsModified = newSurvey.update(db);
       }
     }
     if ((recordInserted || recordsModified > 0) && isValid) {
       context.getRequest().setAttribute("SurveyDetails", newSurvey);
     } else {
       if (System.getProperty("DEBUG") != null) {
         System.out.println("CampaignManagerSurvey-> Insert Errors " + newSurvey.getErrors());
       }
       processErrors(context, newSurvey.getErrors());
     }
     context.getRequest().setAttribute("systemStatus", this.getSystemStatus(context));
   } catch (Exception errorMessage) {
     errorMessage.printStackTrace();
     context.getRequest().setAttribute("Error", errorMessage);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
   if ((recordInserted || recordsModified > 0) && isValid) {
     return ("InsertOK");
   } else if (recordsModified == 0 && isValid) {
     context.getRequest().setAttribute("Error", NOT_UPDATED_MESSAGE);
     return ("UserError");
   } else {
     return (executeCommandAdd(context));
   }
 }
  /**
   * Show Dependencies if any before deleting Survey
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandConfirmDelete(ActionContext context) {
    Exception errorMessage = null;
    Connection db = null;
    Survey thisSurvey = null;

    HtmlDialog htmlDialog = new HtmlDialog();
    String id = null;

    if (!(hasPermission(context, "campaign-campaigns-surveys-delete"))) {
      return ("PermissionError");
    }

    if (context.getRequest().getParameter("id") != null) {
      id = context.getRequest().getParameter("id");
    }

    try {
      db = this.getConnection(context);
      SystemStatus systemStatus = this.getSystemStatus(context);
      thisSurvey = new Survey(db, id);
      if (!hasAuthority(context, thisSurvey.getEnteredBy())) {
        return ("PermissionError");
      }

      DependencyList dependencies = thisSurvey.processDependencies(db);
      dependencies.setSystemStatus(systemStatus);
      htmlDialog.addMessage(
          systemStatus.getLabel("confirmdelete.caution") + "\n" + dependencies.getHtmlString());
      htmlDialog.setTitle(systemStatus.getLabel("confirmdelete.title"));

      if (dependencies.size() == 0) {
        htmlDialog.setShowAndConfirm(false);
        htmlDialog.setDeleteUrl(
            "javascript:window.location.href='CampaignManagerSurvey.do?command=Delete&id="
                + id
                + "'");
      } else {
        htmlDialog.setHeader(systemStatus.getLabel("confirmdelete.surveyCampaignHeader"));
        htmlDialog.addButton(
            systemStatus.getLabel("button.ok"), "javascript:parent.window.close()");
      }

    } catch (Exception e) {
      errorMessage = e;
    } finally {
      this.freeConnection(context, db);
    }
    if (errorMessage == null) {
      context.getSession().setAttribute("Dialog", htmlDialog);
      return ("ConfirmDeleteOK");
    } else {
      context.getRequest().setAttribute("Error", errorMessage);
      return ("SystemError");
    }
  }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandConfirmDelete(ActionContext context) {
   if (!(hasPermission(context, "tickets-tickets-tasks-delete"))) {
     return ("PermissionError");
   }
   Connection db = null;
   Task thisTask = null;
   HtmlDialog htmlDialog = new HtmlDialog();
   String id = context.getRequest().getParameter("id");
   String sourcePopup = context.getRequest().getParameter("sourcePopup");
   try {
     db = this.getConnection(context);
     SystemStatus systemStatus = this.getSystemStatus(context);
     thisTask = new Task(db, Integer.parseInt(id));
     htmlDialog.setTitle(systemStatus.getLabel("confirmdelete.title"));
     if (!hasAuthority(context, thisTask.getOwner())) {
       htmlDialog.setHeader(systemStatus.getLabel("confirmdelete.taskNotOwnerHeader"));
       htmlDialog.addButton(
           systemStatus.getLabel("button.ok"), "javascript:parent.window.close()");
     } else {
       DependencyList dependencies = thisTask.processDependencies(db);
       htmlDialog.addMessage(
           systemStatus.getLabel("confirmdelete.caution") + "\n" + dependencies.getHtmlString());
       if (dependencies.size() == 0) {
         htmlDialog.setShowAndConfirm(false);
         htmlDialog.setDeleteUrl(
             "javascript:window.location.href='TroubleTicketTasks.do?command=Delete&id="
                 + id
                 + "&sourcePopup="
                 + sourcePopup
                 + "'");
       } else {
         htmlDialog.setHeader(systemStatus.getLabel("confirmdelete.header"));
         htmlDialog.addButton(
             systemStatus.getLabel("button.delete"),
             "javascript:window.location.href='TroubleTicketTasks.do?command=Delete&id="
                 + id
                 + "&sourcePopup="
                 + sourcePopup
                 + "'");
         htmlDialog.addButton(
             systemStatus.getLabel("button.cancel"), "javascript:parent.window.close()");
       }
     }
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
   context.getSession().setAttribute("Dialog", htmlDialog);
   return ("ConfirmDeleteOK");
 }
 /**
  * Adds a feature to the OpportunityList attribute of the Prototype object
  *
  * @param context The feature to be added to the OpportunityList attribute
  * @param db The feature to be added to the OpportunityList attribute
  * @throws SQLException Description of the Exception
  */
 private void addOpportunityList(ActionContext context, Connection db) throws SQLException {
   OpportunityList thisList = new OpportunityList();
   thisList.setOwner(this.getUserId(context));
   String contactId = (String) context.getRequest().getParameter("contactId");
   if (contactId == null) {
     contactId = (String) context.getRequest().getAttribute("contactId");
   }
   if (contactId != null) {
     thisList.setContactId(contactId);
   }
   thisList.buildList(db);
   context.getRequest().setAttribute("opportunityList", thisList);
 }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandDefault(ActionContext context) {
   if (getUserId(context) < 0) {
     return "PermissionError";
   }
   // setMaximized(context);
   IteamSearchBean search = (IteamSearchBean) context.getFormBean();
   PagedListInfo searchBeanInfo = this.getPagedListInfo(context, "searchBeanInfo");
   searchBeanInfo.setLink("ProjectManagementSearch.do?command=Default");
   Connection db = null;
   try {
     search.parseQuery();
     if (!search.isValid()) {
       return "SearchResultsERROR";
     }
     // Get the shared searcher
     IndexSearcher searcher = SearchUtils.getSharedSearcher(context, this.getDirectory(context));
     db = getConnection(context);
     String queryString = null;
     if (search.getScope() != SearchBean.THIS) {
       search.setProjectId(-1);
     }
     // Check for project access and get acceptable query string
     if (search.getProjectId() > -1) {
       Project thisProject = loadProject(db, search.getProjectId(), context);
       context.getRequest().setAttribute("Project", thisProject);
       queryString =
           "("
               + IteamSearchQuery.buildIteamSearchQuery(
                   search, db, getUserId(context), search.getProjectId())
               + ") AND ("
               + search.getParsedQuery()
               + ")";
     } else {
       queryString =
           "("
               + IteamSearchQuery.buildIteamSearchQuery(search, db, getUserId(context), -1)
               + ") AND ("
               + search.getParsedQuery()
               + ")";
     }
     // Execute the query and build search results
     SearchUtils.buildSearchResults(context, queryString, searcher, searchBeanInfo);
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return "SearchResultsERROR";
   } finally {
     freeConnection(context, db);
   }
   return "SearchResultsOK";
 }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandSave(ActionContext context) {
   Connection db = null;
   int resultCount = 0;
   boolean recordInserted = false;
   boolean isValid = false;
   try {
     db = this.getConnection(context);
     // Load the ticket and the organization
     Ticket thisTicket = addTicket(context, db);
     int ticketId = thisTicket.getId();
     // Check access permission to organization record
     if (!isRecordAccessPermitted(context, db, thisTicket.getOrgId())) {
       return ("PermissionError");
     }
     // Insert or update the folder
     FileFolder thisFolder = (FileFolder) context.getFormBean();
     boolean newFolder = (thisFolder.getId() == -1);
     if (newFolder) {
       thisFolder.setEnteredBy(getUserId(context));
     }
     thisFolder.setModifiedBy(getUserId(context));
     thisFolder.setLinkModuleId(Constants.DOCUMENTS_TICKETS);
     thisFolder.setLinkItemId(ticketId);
     if (newFolder) {
       isValid = this.validateObject(context, db, thisFolder);
       if (isValid) {
         recordInserted = thisFolder.insert(db);
       }
     } else {
       isValid = this.validateObject(context, db, thisFolder);
       if (isValid) {
         resultCount = thisFolder.update(db);
       }
     }
     // Build array of folder trails
     ProjectManagementFileFolders.buildHierarchy(db, context);
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
   if (recordInserted) {
     return ("InsertOK");
   } else if (resultCount == 1) {
     return ("UpdateOK");
   }
   return (executeCommandAdd(context));
 }
  /**
   * Description of the Method
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandDelete(ActionContext context) {
    if (!(hasPermission(context, "campaign-campaigns-surveys-delete"))) {
      return ("PermissionError");
    }

    Exception errorMessage = null;
    boolean recordDeleted = false;
    Survey thisSurvey = null;
    Connection db = null;
    SystemStatus systemStatus = this.getSystemStatus(context);
    try {
      db = this.getConnection(context);
      thisSurvey = new Survey(db, Integer.parseInt(context.getRequest().getParameter("id")));
      if (!hasAuthority(context, thisSurvey.getEnteredBy())) {
        return ("PermissionError");
      }
      recordDeleted = thisSurvey.delete(db);
      if (!recordDeleted) {
        HashMap map = new HashMap();
        map.put("${thisSurvey.inactiveCount}", "" + thisSurvey.getInactiveCount());
        map.put(
            "${thisSurvey.campaign}",
            (thisSurvey.getInactiveCount() == 1 ? "campaign is" : "campaigns are"));
        map.put("${thisSurvey.use}", (thisSurvey.getInactiveCount() == 1 ? "uses" : "use"));
        Template template =
            new Template(systemStatus.getLabel("object.validation.actionError.canNotDeleteSurvey"));
        template.setParseElements(map);
        thisSurvey.getErrors().put("actionError", template.getParsedText());
      }
    } catch (Exception e) {
      errorMessage = e;
    } finally {
      this.freeConnection(context, db);
    }

    if (errorMessage == null) {
      if (recordDeleted) {
        context.getRequest().setAttribute("refreshUrl", "CampaignManagerSurvey.do?command=View");
        return ("DeleteOK");
      } else {
        processErrors(context, thisSurvey.getErrors());
        return (executeCommandView(context));
      }
    } else {
      context.getRequest().setAttribute("Error", errorMessage);
      return ("SystemError");
    }
  }
  /**
   * Description of the Method
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandAdd(ActionContext context) {
    if (!(hasPermission(context, "campaign-campaigns-surveys-add")
        || hasPermission(context, "campaign-campaigns-surveys-edit"))) {
      return ("PermissionError");
    }
    try {
      int pg = 0;
      int updateResult = 0;
      Exception errorMessage = null;
      Connection db = null;
      if (context.getRequest().getParameter("pg") != null) {
        pg = Integer.parseInt(context.getRequest().getParameter("pg"));
      }

      try {
        db = this.getConnection(context);
        CustomForm thisForm = getDynamicForm(context, "survey");
        thisForm.setSelectedTabId(pg);
        Survey thisSurvey = (Survey) context.getFormBean();
        thisSurvey.setRequestItems(context.getRequest());
        thisForm.setContext(context);
        updateResult = thisForm.populate(db, thisSurvey);
        context.getRequest().setAttribute("Survey", thisSurvey);
        context.getRequest().setAttribute("CustomFormInfo", thisForm);
        context.getRequest().setAttribute("systemStatus", this.getSystemStatus(context));
      } catch (Exception e) {
        errorMessage = e;
      } finally {
        this.freeConnection(context, db);
      }
      String submenu = context.getRequest().getParameter("submenu");
      if (submenu == null) {
        submenu = (String) context.getRequest().getAttribute("submenu");
      }
      if (submenu == null) {
        submenu = "ManageSurveys";
      }

      context.getRequest().setAttribute("submenu", submenu);
      addModuleBean(context, submenu, "Add Survey");

      return ("AddOK");
    } catch (Exception errorMessage) {
      context.getRequest().setAttribute("Error", errorMessage);
      return ("SystemError");
    }
  }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandModify(ActionContext context) {
   if (!(hasPermission(context, "tickets-tickets-tasks-edit"))) {
     return ("PermissionError");
   }
   Connection db = null;
   Task thisTask = null;
   String forward = context.getRequest().getParameter("forward");
   if (forward != null && !"".equals(forward.trim())) {
     context.getRequest().setAttribute("forward", forward);
   }
   String id = context.getRequest().getParameter("id");
   addModuleBean(context, "View Tickets", "Add Ticket");
   SystemStatus systemStatus = this.getSystemStatus(context);
   String ticketId = context.getRequest().getParameter("ticketId");
   Ticket thisTicket = null;
   try {
     db = this.getConnection(context);
     thisTask = (Task) context.getFormBean();
     if (thisTask.getId() == -1) {
       thisTask = new Task(db, Integer.parseInt(id));
     }
     // Load the ticket
     if (ticketId != null && !"".equals(ticketId)) {
       thisTicket = new Ticket(db, Integer.parseInt(ticketId));
     } else {
       thisTicket = new Ticket(db, thisTask.getTicketId());
     }
     // Check access permission to organization record
     if (!isRecordAccessPermitted(context, db, thisTicket.getOrgId())) {
       return ("PermissionError");
     }
     thisTask.checkEnabledOwnerAccount(db);
     if (thisTask.getContactId() > -1) {
       thisTask.checkEnabledLinkAccount(db);
       Contact contact = new Contact(db, thisTask.getContactId());
       thisTask.setContactName(contact.getNameFull());
     }
     LookupList list = systemStatus.getLookupList(db, "lookup_ticket_task_category");
     list.addItem(-1, systemStatus.getLabel("calendar.none.4dashes", "-- None --"));
     context.getRequest().setAttribute("ticketTaskCategoryList", list);
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
   context.getRequest().setAttribute("Task", thisTask);
   if (!hasAuthority(context, thisTask.getOwner())
       || !(hasPermission(context, "tickets-tickets-tasks-edit"))) {
     if (hasPermission(context, "tickets-tickets-tasks-view")) {
       return "TaskDetailsOK";
     }
     return ("PermissionError");
   }
   return "AddTaskOK";
 }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandMockInsert(ActionContext context) {
   if (!(hasPermission(context, "campaign-campaigns-surveys-view"))) {
     return ("PermissionError");
   }
   Connection db = null;
   Survey thisSurvey = null;
   try {
     db = this.getConnection(context);
     thisSurvey = new Survey(db, Integer.parseInt(context.getRequest().getParameter("id")));
     context.getRequest().setAttribute("ThankYouText", thisSurvey.getOutro());
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
   return ("MockInsertOK");
 }
  /**
   * Description of the Method
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandView(ActionContext context) {
    if (!(hasPermission(context, "campaign-campaigns-surveys-view"))) {
      return ("PermissionError");
    }

    Exception errorMessage = null;
    PagedListInfo surveyInfo = this.getPagedListInfo(context, "CampaignSurveyListInfo");
    surveyInfo.setLink("CampaignManagerSurvey.do?command=View");
    Connection db = null;
    SurveyList surveyList = new SurveyList();

    try {
      db = this.getConnection(context);
      surveyList.setPagedListInfo(surveyInfo);
      if ("all".equals(surveyInfo.getListView())) {
        surveyList.setEnteredByIdRange(this.getUserRange(context));
      } else {
        surveyList.setEnteredByIdRange(this.getUserId(context) + "");
      }
      surveyList.buildList(db);
    } catch (Exception e) {
      errorMessage = e;
    } finally {
      this.freeConnection(context, db);
    }

    String submenu = context.getRequest().getParameter("submenu");
    if (submenu == null) {
      submenu = (String) context.getRequest().getAttribute("submenu");
    }
    if (submenu == null) {
      submenu = "ManageSurveys";
    }
    context.getRequest().setAttribute("submenu", submenu);
    addModuleBean(context, submenu, "View Surveys");

    if (errorMessage == null) {
      context.getRequest().setAttribute("SurveyList", surveyList);
      return ("ViewOK");
    } else {
      context.getRequest().setAttribute("Error", errorMessage);
      return ("SystemError");
    }
  }
  /**
   * Description of the Method
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandProjects(ActionContext context) {
    // Parameters
    String value = context.getRequest().getParameter("source");
    String search = context.getRequest().getParameter("search");
    StringTokenizer st = new StringTokenizer(value, "|");
    String source = st.nextToken();
    String status = st.nextToken();
    // Build the list
    Connection db = null;
    ProjectList projects = new ProjectList();
    try {
      db = getConnection(context);
      if ("my".equals(source) || "all".equals(source)) {
        projects.setProjectsForUser(getUserId(context));
        projects.setIncludeGuestProjects(false);
        if ("open".equals(status)) {
          // Check if open or closed
          projects.setOpenProjectsOnly(true);
        } else {
          projects.setClosedProjectsOnly(true);
        }
        projects.buildList(db);
        context.getRequest().setAttribute("projectList", projects);
        return "ProjectsOK";
      } else if ("dept".equals(source) && "all".equals(status)) {
        LookupList departmentList = new LookupList(db, "lookup_department");
        departmentList.addItem(0, "Without a department");
        context.getRequest().setAttribute("departments", departmentList);
        return "MakeDepartmentListOK";
      } else if ("acct".equals(source) && "all".equals(status)) {
        OrganizationList organizationList = new OrganizationList();
        organizationList.setName('%' + search + '%');
        organizationList.buildShortList(db);
        context.getRequest().setAttribute("orgList", organizationList);
        return "MakeOrgListOK";
      }
    } catch (Exception e) {

    } finally {
      freeConnection(context, db);
    }
    return null;
  }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandSaveMove(ActionContext context) {
   // Parameters
   String newFolderId = (String) context.getRequest().getParameter("folderId");
   String itemId = (String) context.getRequest().getParameter("id");
   Connection db = null;
   try {
     db = getConnection(context);
     // Load the ticket and the organization
     Ticket thisTicket = addTicket(context, db);
     int ticketId = thisTicket.getId();
     // Check access permission to organization record
     if (!isRecordAccessPermitted(context, db, thisTicket.getOrgId())) {
       return ("PermissionError");
     }
     // Load the current folder
     FileFolder thisFolder = new FileFolder(db, Integer.parseInt(itemId));
     int folderId = Integer.parseInt(newFolderId);
     if (folderId != 0 && folderId != -1) {
       FileFolder newParent = new FileFolder(db, folderId);
       FileFolderHierarchy thisHierarchy = new FileFolderHierarchy();
       thisHierarchy.setLinkModuleId(Constants.DOCUMENTS_TICKETS);
       thisHierarchy.setLinkItemId(ticketId);
       thisHierarchy.build(db, thisFolder.getId());
       if (thisHierarchy.getHierarchy().hasFolder(Integer.parseInt(newFolderId))) {
         thisFolder.buildSubFolders(db);
         Iterator iterator = (Iterator) thisFolder.getSubFolders().iterator();
         while (iterator.hasNext()) {
           FileFolder childFolder = (FileFolder) iterator.next();
           childFolder.updateParentId(db, thisFolder.getParentId());
         }
       }
     }
     thisFolder.updateParentId(db, folderId);
     return "PopupCloseOK";
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
 }
 /**
  * Description of the Method
  *
  * @param context Description of the Parameter
  * @return Description of the Return Value
  */
 public String executeCommandDelete(ActionContext context) {
   if (!(hasPermission(context, "sales-leads-action-plans-delete"))) {
     return ("PermissionError");
   }
   Connection db = null;
   try {
     db = this.getConnection(context);
     String planWorkId = context.getRequest().getParameter("actionPlanId");
     ActionPlanWork planWork = new ActionPlanWork(db, Integer.parseInt(planWorkId));
     planWork.setBuildLinkedObject(true);
     planWork.buildPhaseWork(db);
     planWork.buildLinkedObject(db);
     planWork.delete(db);
   } catch (Exception e) {
     context.getRequest().setAttribute("Error", e);
     return ("SystemError");
   } finally {
     this.freeConnection(context, db);
   }
   return (executeCommandView(context));
 }
  /**
   * Description of the Method
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandListViews(ActionContext context) {
    if (!hasPermission(context, "admin-view")) {
      return ("PermissionError");
    }
    addModuleBean(context, "Configuration", "Custom List Views");
    Connection db = null;
    String moduleId = context.getRequest().getParameter("moduleId");
    try {
      db = getConnection(context);
      // build the module details
      PermissionCategory permCat = new PermissionCategory(db, Integer.parseInt(moduleId));
      context.getRequest().setAttribute("permissionCategory", permCat);

      // build the custom list view editor
      String constantId = context.getRequest().getParameter("constantId");
      CustomListViewEditor editor = new CustomListViewEditor(db, Integer.parseInt(constantId));
      context.getRequest().setAttribute("listViewEditor", editor);

      // build a list of custom list views for this editor
      CustomListViewList customList = new CustomListViewList();
      customList.setEditorId(editor.getId());
      customList.buildList(db);
      context.getRequest().setAttribute("customListViews", customList);
    } catch (Exception e) {
      context.getRequest().setAttribute("Error", e);
      return ("SystemError");
    } finally {
      this.freeConnection(context, db);
    }
    return "ListViewsOK";
  }
  /**
   * Preview of the Survey
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandPreview(ActionContext context) {
    if (!(hasPermission(context, "campaign-campaigns-surveys-view"))) {
      return ("PermissionError");
    }

    Exception errorMessage = null;
    Connection db = null;
    Survey thisSurvey = null;
    try {
      db = this.getConnection(context);
      thisSurvey = new Survey(db, Integer.parseInt(context.getRequest().getParameter("id")));
      context.getRequest().setAttribute("Survey", thisSurvey);
    } catch (Exception e) {
      errorMessage = e;
    } finally {
      this.freeConnection(context, db);
    }

    String submenu = context.getRequest().getParameter("submenu");
    if (submenu == null) {
      submenu = (String) context.getRequest().getAttribute("submenu");
    }
    if (submenu == null) {
      submenu = "ManageSurveys";
    }

    if (errorMessage == null) {
      context.getRequest().setAttribute("submenu", submenu);
      addModuleBean(context, submenu, "Add Surveys");
      return ("PreviewOK");
    } else {
      context.getRequest().setAttribute("Error", errorMessage);
      return ("SystemError");
    }
  }
  /**
   * Description of the Method
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandInsert(ActionContext context) {
    if (!hasPermission(context, "admin-sysconfig-customlistviews-add")) {
      return ("PermissionError");
    }
    addModuleBean(context, "Configuration", "Custom List Views");
    Connection db = null;
    CustomListView newCustomView = null;
    boolean isValid = true;
    boolean recordInserted = false;
    CustomListView customView = (CustomListView) context.getFormBean();

    String moduleId = context.getRequest().getParameter("moduleId");
    try {
      db = getConnection(context);
      // build the module details
      PermissionCategory permCat = new PermissionCategory(db, Integer.parseInt(moduleId));
      context.getRequest().setAttribute("permissionCategory", permCat);

      isValid = this.validateObject(context, db, customView);
      if (isValid) {
        recordInserted = customView.insert(db);
      }

      if (recordInserted) {
        newCustomView = new CustomListView(db, customView.getId());
        context.getRequest().setAttribute("customListView", newCustomView);
      }
    } catch (Exception e) {
      e.printStackTrace(System.out);
      context.getRequest().setAttribute("Error", e);
      return ("SystemError");
    } finally {
      this.freeConnection(context, db);
    }
    if (recordInserted && isValid) {
      return ("InsertOK");
    }
    return (executeCommandAdd(context));
  }
  /**
   * Description of the Method
   *
   * @param context Description of the Parameter
   * @return Description of the Return Value
   */
  public String executeCommandAdd(ActionContext context) {
    if (!hasPermission(context, "tickets-tickets-tasks-add")) {
      return ("PermissionError");
    }
    Connection db = null;

    try {
      db = this.getConnection(context);
      // Load the ticket
      Ticket thisTicket =
          new Ticket(db, Integer.parseInt(context.getRequest().getParameter("ticketId")));
      // Check access permission to organization record
      if (!isRecordAccessPermitted(context, db, thisTicket.getOrgId())) {
        return ("PermissionError");
      }

      TicketTask thisTicketTask = (TicketTask) context.getFormBean();
      if (thisTicketTask.getEnteredBy() == -1) {
        thisTicketTask = new TicketTask();
        thisTicketTask.setTicketId(thisTicket.getId());
      }
      Task thisTask = thisTicketTask;
      context.getRequest().setAttribute("Task", thisTask);

      SystemStatus systemStatus = this.getSystemStatus(context);
      LookupList list = systemStatus.getLookupList(db, "lookup_ticket_task_category");
      list.addItem(-1, systemStatus.getLabel("calendar.none.4dashes", "-- None --"));
      context.getRequest().setAttribute("ticketTaskCategoryList", list);
    } catch (Exception e) {
      context.getRequest().setAttribute("Error", e);
      return ("SystemError");
    } finally {
      this.freeConnection(context, db);
    }

    addModuleBean(context, "View Tickets", "Add Ticket");
    return ("AddTaskOK");
  }