protected Map getMdbeansMap(List moduleDateBeans) {
    if ((moduleDateBeans == null) || (moduleDateBeans.size() == 0)) return null;
    Map mdbeansMap = new LinkedHashMap<Integer, ModuleDateBean>();

    for (Iterator itr = moduleDateBeans.listIterator(); itr.hasNext(); ) {
      ModuleDateBean mdbean = (ModuleDateBean) itr.next();
      mdbeansMap.put(mdbean.getModuleId(), mdbean);
    }
    return mdbeansMap;
  }
  /**
   * Reset selected lists and navigate to add section page
   *
   * @return editmodulesections or list_auth_modules
   */
  public void AddContentAction(ActionEvent evt) {
    if (!saveModuleDates()) return;
    if (moduleDateBeans == null || moduleDateBeans.size() == 0) return;

    FacesContext ctx = FacesContext.getCurrentInstance();

    if (count >= 2) {
      ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
      String msg = bundle.getString("select_error");
      addMessage(ctx, "Select  ERROR", msg, FacesMessage.SEVERITY_ERROR);
      count = 0;

      moduleSelected = false;
      sectionSelected = false;
      return;
    }
    count = 0;

    if ((moduleSelected == false) && (sectionSelected == false)) {
      ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
      String msg = bundle.getString("select_one_add");
      addMessage(ctx, "Select  One", msg, FacesMessage.SEVERITY_ERROR);
      return;
    }
    // module selected
    if (moduleSelected || sectionSelected) {
      if (selectedModId <= 0) return;
      if ((moduleDateBeans != null) && (moduleDateBeans.size() > 0)) {
        ModuleDateBean mdbean = (ModuleDateBean) mdbeansMap.get(selectedModId);

        if (mdbean != null) {
          ValueBinding binding = Util.getBinding("#{editSectionPage}");
          FacesContext context = FacesContext.getCurrentInstance();
          EditSectionPage editPage = (EditSectionPage) binding.getValue(context);
          editPage.setModule(mdbean.getModule());
          Integer newSecId = editPage.addBlankSection();

          count = 0;
          moduleSelected = false;
          // Mallika -3/24/05
          sectionSelected = false;
          try {
            if (newSecId != null)
              ctx.getExternalContext()
                  .redirect("editmodulesections.jsf?sectionId=" + newSecId.toString());
          } catch (Exception e) {
            return;
          }
        }
      }
    }
    return;
  }
 public void specialAccessAction(ActionEvent evt) {
   resetSelectedLists();
   if (!saveModuleDates()) return;
   FacesContext ctx = FacesContext.getCurrentInstance();
   UIViewRoot root = ctx.getViewRoot();
   UIData table = (UIData) root.findComponent("listauthmodulesform").findComponent("table");
   ModuleDateBean mdbean = (ModuleDateBean) table.getRowData();
   Integer selModId = mdbean.getModuleId();
   try {
     ctx.getExternalContext().redirect("list_special_access.jsf?editmodid=" + selModId.toString());
   } catch (Exception e) {
     return;
   }
 }
  protected Map getSecObjMap(List moduleDateBeans) {
    if ((moduleDateBeans == null) || (moduleDateBeans.size() == 0)) return null;
    Map secobjMap = new LinkedHashMap<Integer, SecModObj>();

    for (Iterator itr = moduleDateBeans.listIterator(); itr.hasNext(); ) {
      ModuleDateBean mdbean = (ModuleDateBean) itr.next();
      List sectionBeans = mdbean.getSectionBeans();
      if ((sectionBeans != null) && (sectionBeans.size() > 0)) {
        int moduleId = mdbean.getModuleId();
        for (Iterator sItr = sectionBeans.listIterator(); sItr.hasNext(); ) {
          SectionBean secbean = (SectionBean) sItr.next();
          secobjMap.put(
              secbean.getSection().getSectionId(), new SecModObj(moduleId, secbean, mdbean));
        }
      }
    }
    return secobjMap;
  }
  /**
   * Get module id to print
   *
   * @return module id to print
   */
  public Integer getPrintModuleId() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");

    try {
      resetSelectedLists();
      UIViewRoot root = ctx.getViewRoot();
      UIData table = (UIData) root.findComponent("listauthmodulesform").findComponent("table");
      ModuleDateBean mdbean = (ModuleDateBean) table.getRowData();
      printModuleId = mdbean.getModule().getModuleId();
      return printModuleId;
    } catch (Exception me) {
      logger.error(me.toString());
      String msg = bundle.getString("print_module_fail");
      addMessage(ctx, "Error Message", msg, FacesMessage.SEVERITY_ERROR);
    }
    return 0;
  }
 /**
  * Method that triggers when all modules are selected
  *
  * @param event ValueChangeEvent object
  * @throws AbortProcessingException
  */
 public void selectAllModules(ValueChangeEvent event) throws AbortProcessingException {
   ModuleDateBean mdbean = null;
   selectAllFlag = true;
   int k = 0;
   if (selectedModIds == null) {
     selectedModIds = new ArrayList();
   }
   if ((moduleDateBeans != null) && (moduleDateBeans.size() > 0)) {
     for (ListIterator i = moduleDateBeans.listIterator(); i.hasNext(); ) {
       mdbean = (ModuleDateBean) i.next();
       mdbean.setSelected(true);
       selectedModIds.add(new Integer(mdbean.getModuleId()));
     }
     count = moduleDateBeans.size();
     if (count == 1) selectedModId = mdbean.getModuleId();
     moduleSelected = true;
   }
   return;
 }
 /**
  * Method to expand or collapse individual modules' sections
  *
  * @return list_auth_modules
  */
 public String showHideSections() {
   resetSelectedLists();
   if (getExpandAllFlag() == true) {
     setShowModuleId(-1);
     setExpandAllFlag(false);
   } else {
     FacesContext ctx = FacesContext.getCurrentInstance();
     UIViewRoot root = ctx.getViewRoot();
     UIData table = (UIData) root.findComponent("listauthmodulesform").findComponent("table");
     ModuleDateBean mdbean = (ModuleDateBean) table.getRowData();
     if (getShowModuleId() != mdbean.getModuleId()) {
       setShowModuleId(mdbean.getModuleId());
     } else {
       setShowModuleId(-1);
       setExpandAllFlag(false);
     }
   }
   saveModuleDates();
   return "list_auth_modules";
 }
  /**
   * Make a copy of the selected module
   *
   * @return list_auth_modules
   */
  public String duplicateAction() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
    if (!saveModuleDates()) return "list_auth_modules";

    try {
      resetSelectedLists();
      UIViewRoot root = ctx.getViewRoot();
      UIData table = (UIData) root.findComponent("listauthmodulesform").findComponent("table");
      ModuleDateBean mdbean = (ModuleDateBean) table.getRowData();
      logger.debug("calling copy for " + mdbean.getModule().getTitle());
      moduleService.copyModule((ModuleObjService) mdbean.getModule(), courseId, userId);
    } catch (MeleteException me) {
      logger.debug(me.toString());
      String msg = bundle.getString("copy_fail");
      addMessage(ctx, "Error Message", msg, FacesMessage.SEVERITY_ERROR);
    }
    resetValues();
    return "list_auth_modules";
  }
  /**
   * Redirect to delete confirmation page with selected modules or sections
   *
   * @return delete_module or list_auth_modules
   */
  public String deleteAction() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    List delMods = null;
    List delSecBeans = null;
    count = 0;
    if (!saveModuleDates()) return "list_auth_modules";
    if ((moduleDateBeans == null) || (moduleDateBeans.size() == 0)) return "list_auth_modules";

    // added by rashmi
    if (!moduleSelected && !sectionSelected) {
      ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
      String msg = bundle.getString("select_one_delete");
      addMessage(ctx, "Select  One", msg, FacesMessage.SEVERITY_ERROR);
    }
    // add end
    // module selected
    if (moduleSelected) {
      ModuleDateBean mdbean = null;
      if (delMods == null) {
        delMods = new ArrayList();
      }
      if (selectedModIds != null) {
        for (ListIterator i = selectedModIds.listIterator(); i.hasNext(); ) {
          mdbean = (ModuleDateBean) mdbeansMap.get(((Integer) i.next()).intValue());
          delMods.add(mdbean.getModule());
        }
      }
      ValueBinding binding = Util.getBinding("#{deleteModulePage}");
      DeleteModulePage dmPage = (DeleteModulePage) binding.getValue(ctx);
      // dmPage.setMdbean(mdbean);
      dmPage.setModules(delMods);
      dmPage.setSectionBeans(new ArrayList<SectionBeanService>());
      //	List <> allActivenArchvModules = moduleService.getAllActivenArchvModules();
      dmPage.setModuleSelected(true);
      count = 0;
      moduleSelected = false;
      selectedModIds = null;
      //	delModBeans = null;
      // We do not want to bypass processing of section if sections and modules are selected
      if (sectionSelected == false) {
        return "delete_module";
      }
    }
    if (sectionSelected) {
      if ((secObjMap == null) || (secObjMap.size() == 0)) return "list_auth_modules";
      ModuleDateBean mdbean = null;
      SectionBeanService secBean = null;
      if (delSecBeans == null) {
        delSecBeans = new ArrayList();
      }
      if (selectedSecIds == null) {
        ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
        String msg = bundle.getString("select_one_delete");
        addMessage(ctx, "Select  One", msg, FacesMessage.SEVERITY_ERROR);
        moduleSelected = false;
        sectionSelected = false;
        resetSelectedLists();
        return "list_auth_modules";
      }

      for (ListIterator i = selectedSecIds.listIterator(); i.hasNext(); ) {
        Integer sectionId = (Integer) i.next();
        secBean = ((SecModObj) secObjMap.get(sectionId)).getSecBean();
        if (secBean != null) delSecBeans.add(secBean);
      }
      count = 0;
      sectionSelected = false;
      selectedSecIds = null;

      if (delSecBeans != null) {
        ValueBinding binding = Util.getBinding("#{deleteModulePage}");
        DeleteModulePage dmPage = (DeleteModulePage) binding.getValue(ctx);
        // dmPage.setSection((Section) secBean.getSection());
        dmPage.setSectionBeans(delSecBeans);
        dmPage.setSectionSelected(true);
        return "delete_module";
      }
    }

    moduleSelected = false;
    sectionSelected = false;
    resetSelectedLists();
    return "list_auth_modules";
  }
  /**
   * Inactivate modules and display a message about modules that have been inactivated
   *
   * @return list_auth_modules
   */
  public String InactivateAction() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    List selModBeans = null;
    ModuleDateBean mdbean = null;
    if (!saveModuleDates()) return "list_auth_modules";
    if (moduleDateBeans == null || moduleDateBeans.size() == 0) return "list_auth_modules";
    if (sectionSelected) {
      ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
      String msg = bundle.getString("select_module");
      addMessage(ctx, "Select Module", msg, FacesMessage.SEVERITY_ERROR);
      resetSubSectionValues();
      return "list_auth_modules";
    }

    // module selected
    if (moduleSelected && selectedModIds != null) {
      if (selModBeans == null) {
        selModBeans = new ArrayList();
      }
      for (ListIterator i = selectedModIds.listIterator(); i.hasNext(); ) {
        mdbean = (ModuleDateBean) mdbeansMap.get(((Integer) i.next()).intValue());
        if (mdbean != null) selModBeans.add(mdbean);
      }
      ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
      try {
        if ((selModBeans != null)
            && (selModBeans.size() > 0)
            && (moduleDateBeans != null)
            && (moduleDateBeans.size() > 0)) {
          getModuleService().archiveModules(selModBeans, moduleDateBeans, courseId);
          StringBuffer modTitles = new StringBuffer();
          mdbean = null;
          for (ListIterator i = selModBeans.listIterator(); i.hasNext(); ) {
            mdbean = (ModuleDateBean) i.next();
            modTitles.append(mdbean.getModule().getTitle());
            modTitles.append(", ");
          }
          modTitles.delete(modTitles.toString().length() - 2, modTitles.toString().length());
          String msg1 = bundle.getString("inactivate_message1");
          String msg2 = bundle.getString("inactivate_message2");
          addMessage(
              ctx,
              "Inactivate Message",
              msg1 + modTitles.toString() + msg2,
              FacesMessage.SEVERITY_INFO);
        }
      } catch (Exception ex) {
        logger.debug(ex.toString());
        String errmsg = bundle.getString("archive_fail");
        addMessage(ctx, "Error Message", errmsg, FacesMessage.SEVERITY_ERROR);
        return "list_auth_modules";
      }
      count = 0;
      // Mallika - 3/24/05 added this to prevent selected value from being stored
      moduleSelected = false;
      sectionSelected = false;
      resetValues();
      return "list_auth_modules";
    }

    if ((moduleSelected == false) && (sectionSelected == false)) {
      ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
      String msg = bundle.getString("select_one_module");
      addMessage(ctx, "Select  One", msg, FacesMessage.SEVERITY_ERROR);
    }
    count = 0;
    moduleSelected = false;
    sectionSelected = false;
    return "list_auth_modules";
  }
  /**
   * Bring section one level up in indentation
   *
   * @return list_auth_modules
   */
  public String BringSubSectionLevelUpAction() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
    if (!saveModuleDates()) return "list_auth_modules";
    if ((moduleDateBeans == null) || (moduleDateBeans.size() == 0)) return "list_auth_modules";

    if (count == 0) {
      String msg = bundle.getString("list_select_one_indent");
      addMessage(ctx, "Error Message", msg, FacesMessage.SEVERITY_ERROR);
      resetSubSectionValues();
      return "list_auth_modules";
    }

    // if module is selected then throw message
    if (moduleSelected) {
      String msg = bundle.getString("list_select_indent");
      addMessage(ctx, "Error Message", msg, FacesMessage.SEVERITY_ERROR);
      resetSubSectionValues();
      return "list_auth_modules";
    }

    // section selected
    /*
     * if(sectionSelected && count != 1) { String msg =
     * bundle.getString("list_select_one_indent"); addMessage(ctx,"Error
     * Message
     * ",msg,FacesMessage.SEVERITY_ERROR); resetSubSectionValues(); return "
     * list_auth_modules"; }
     */

    if (sectionSelected == true) {
      if ((secObjMap == null) || (secObjMap.size() == 0)) return "list_auth_modules";
      SecModObj smObj = null;
      ModuleDateBean mdbean = null;
      SectionBeanService secBean = null;
      List indentSecBeans = null;
      if (indentSecBeans == null) {
        indentSecBeans = new ArrayList();
      }

      if (selectedSecIds == null) {
        resetSubSectionValues();
        return "list_auth_modules";
      }
      // If one section is selected, we check if its the top level section
      // If multiple sections are selected, we indent those that we can
      // and leave the others alone
      if (selectedSecIds.size() == 1) {
        smObj = (SecModObj) secObjMap.get(selectedSecIds.get(0));
        if ((smObj != null) && (smObj.getMdBean() != null) && (smObj.getSecBean() != null)) {
          mdbean = (ModuleDateBean) smObj.getMdBean();
          secBean = (SectionBeanService) smObj.getSecBean();
          if (checkTopLevelSection(secBean.getDisplaySequence())) {
            logger.debug("Top level section can't indent left more");
            resetSubSectionValues();
            return "list_auth_modules";
          }
          try {
            indentSecBeans.add(secBean);
            moduleService.bringOneLevelUp(mdbean.getModule(), indentSecBeans);
          } catch (MeleteException me) {
            logger.debug(me.toString());
            String msg = bundle.getString("indent_left_fail");
            addMessage(ctx, "Error Message", msg, FacesMessage.SEVERITY_ERROR);
          }
        }
      } else {
        // Multiple indent code
        boolean res = checkDifModules(selectedSecIds);
        if (res == true) {
          String msg = bundle.getString("list_select_in_onemodule");
          addMessage(ctx, "Select Indent", msg, FacesMessage.SEVERITY_ERROR);
          resetSubSectionValues();
          return "list_auth_modules";
        } else {
          mdbean = null;
          secBean = null;

          for (ListIterator i = selectedSecIds.listIterator(); i.hasNext(); ) {
            Integer sectionId = (Integer) i.next();
            smObj = (SecModObj) secObjMap.get(sectionId);
            if ((smObj != null) && (smObj.getMdBean() != null) && (smObj.getSecBean() != null)) {
              mdbean = smObj.getMdBean();
              secBean = smObj.getSecBean();
              indentSecBeans.add(secBean);
            }
          }
          if ((indentSecBeans != null) && (indentSecBeans.size() != 0)) {
            try {
              moduleService.bringOneLevelUp(mdbean.getModule(), indentSecBeans);
            } catch (MeleteException me) {
              logger.debug(me.toString());
              String msg = bundle.getString("indent_left_fail");
              addMessage(ctx, "Error Message", msg, FacesMessage.SEVERITY_ERROR);
            }
          }
        }
      }
    }

    resetSubSectionValues();
    int saveShowId = showModuleId;
    resetValues();
    setShowModuleId(saveShowId);
    return "list_auth_modules";
  }
  /**
   * Indent this section by first checking if indentation is less than 10 levels
   *
   * @return list_auth_modules
   */
  public String CreateSubSectionAction() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
    if (!saveModuleDates()) return "list_auth_modules";
    if ((moduleDateBeans == null) || (moduleDateBeans.size() == 0)) return "list_auth_modules";

    // if module is selected then throw message
    if (moduleSelected) {
      String msg = bundle.getString("list_select_indent");
      addMessage(ctx, "Select  Indent", msg, FacesMessage.SEVERITY_ERROR);
      resetSubSectionValues();
      return "list_auth_modules";
    }

    if ((moduleSelected == false) && (sectionSelected == false)) {
      String msg = bundle.getString("list_select_one_indent");
      addMessage(ctx, "Select Indent", msg, FacesMessage.SEVERITY_ERROR);
      resetSubSectionValues();
      return "list_auth_modules";
    }
    if (sectionSelected == true) {
      if ((secObjMap == null) || (secObjMap.size() == 0)) {
        resetSubSectionValues();
        return "list_auth_modules";
      }
      SecModObj smObj = null;
      ModuleDateBean mdbean = null;
      SectionBeanService secBean = null;
      List indentSecBeans = null;
      if (indentSecBeans == null) {
        indentSecBeans = new ArrayList();
      }

      if (selectedSecIds == null) {
        resetSubSectionValues();
        return "list_auth_modules";
      }
      // If one section is selected, we check if its the first section
      // or if it is too deep to indent
      // If multiple sections are selected, we indent those that we can
      // and leave the others alone
      if (selectedSecIds.size() == 1) {
        smObj = (SecModObj) secObjMap.get(selectedSecIds.get(0));
        if ((smObj != null) && (smObj.getMdBean() != null) && (smObj.getSecBean() != null)) {
          mdbean = smObj.getMdBean();
          if (mdbean.getSectionBeans().size() < 2) {
            logger.debug("First section can't be change to subsection");
            resetSubSectionValues();
            return "list_auth_modules";
          } else {
            secBean = smObj.getSecBean();

            boolean indentOk = findIndent(secBean, mdbean.getSectionBeans());
            // Only allow indent upto 10 levels
            if (indentOk) {
              try {
                indentSecBeans.add(secBean);
                moduleService.createSubSection(mdbean.getModule(), indentSecBeans);
              } catch (MeleteException me) {
                logger.debug(me.toString());
                String msg = bundle.getString("indent_right_fail");
                addMessage(ctx, "Error Message", msg, FacesMessage.SEVERITY_ERROR);
              }
            } else {
              String msg = bundle.getString("indent_right_toodeep");
              addMessage(ctx, "Error Message", msg, FacesMessage.SEVERITY_ERROR);
            }
          }
        } else {
          resetSubSectionValues();
          return "list_auth_modules";
        }
      } else {
        // Multiple indent code
        boolean res = checkDifModules(selectedSecIds);
        if (res == true) {
          String msg = bundle.getString("list_select_in_onemodule");
          addMessage(ctx, "Select Indent", msg, FacesMessage.SEVERITY_ERROR);
          resetSubSectionValues();
          return "list_auth_modules";
        } else {
          mdbean = null;
          secBean = null;

          for (ListIterator i = selectedSecIds.listIterator(); i.hasNext(); ) {
            Integer sectionId = (Integer) i.next();
            smObj = (SecModObj) secObjMap.get(sectionId);
            if ((smObj != null) && (smObj.getMdBean() != null) && (smObj.getSecBean() != null)) {
              mdbean = smObj.getMdBean();
              secBean = smObj.getSecBean();
              boolean indentOk = findIndent(secBean, mdbean.getSectionBeans());
              if (indentOk) {
                indentSecBeans.add(secBean);
              }
            }
          }
          try {
            moduleService.createSubSection(mdbean.getModule(), indentSecBeans);
          } catch (MeleteException me) {
            logger.debug(me.toString());
            String msg = bundle.getString("indent_right_fail");
            addMessage(ctx, "Error Message", msg, FacesMessage.SEVERITY_ERROR);
          }
        }
      }
    }
    resetSubSectionValues();
    int saveShowId = showModuleId;
    resetValues();
    setShowModuleId(saveShowId);
    return "list_auth_modules";
  }