public Table getListTable(IWContext iwc) throws RemoteException {
    Table table = new Table(2, this.USERS_PER_PAGE + 1);
    table.setCellspacing(0);
    table.setCellpadding(2);
    table.setWidth(Table.HUNDRED_PERCENT);
    table.setHorizontalZebraColored(
        IWConstants.DEFAULT_INTERFACE_COLOR, IWConstants.DEFAULT_LIGHT_INTERFACE_COLOR);
    int row = 1;
    int rowHeight = 12;
    table.setHeight(table.getRows() * rowHeight);

    table.add(getTitleText(localize("user", "User")), 1, row);
    table.add(getTitleText(localize("personal_id", "Personal ID")), 2, row);
    table.setRowColor(row, IWConstants.DEFAULT_DARK_INTERFACE_COLOR);
    table.setHeight(row, rowHeight);

    if (this.users != null) {
      /** Calculating page....starts */
      int start = this.currentPage * this.USERS_PER_PAGE;
      Iterator iter = this.users.iterator();
      for (int i = 0; i < start; i++) {
        if (iter.hasNext()) {
          iter.next();
        }
      }
      /** Calculating page....ends */
      int counter = 0;
      User user;
      Link link;
      String pId;
      while (iter.hasNext() && counter < this.USERS_PER_PAGE) {
        ++counter;
        ++row;
        table.setHeight(row, rowHeight);

        user = (User) iter.next();
        pId = user.getPersonalID();
        if (pId == null) {
          pId = "-";
        }
        link = getLink(getText(user.getName()), iwc);
        link.addParameter(this.PARAMETER_USER_ID, user.getPrimaryKey().toString());
        table.add(link, 1, row);
        table.add(getText(pId), 2, row);
      }
    }

    return table;
  }
  public Table getListTable(IWContext iwc) throws RemoteException {
    Table table = new Table(3, this.USERS_PER_PAGE + 1);
    table.setCellspacing(0);
    table.setCellpadding(2);
    table.setWidth("100%");
    table.setHorizontalZebraColored("#C1C3B4", "#FFFFFF");
    int row = 1;
    int rowHeight = 12;
    table.setHeight(table.getRows() * rowHeight);
    table.add(getTitleText(localize("user", "User")), 1, row);
    table.add(getTitleText(localize("school", "School")), 2, row);
    table.add(getTitleText(localize("personal_id", "Personal ID")), 3, row);
    table.setRowColor(row, "#74858D");
    table.setHeight(row, rowHeight);

    if (this.users != null) {
      int start = this.currentPage * this.USERS_PER_PAGE;
      Iterator iter = this.users.iterator();
      for (int i = 0; i < start; i++) {
        if (iter.hasNext()) {
          iter.next();
        }
      }

      String pId;
      for (int counter = 0;
          iter.hasNext() && counter < this.USERS_PER_PAGE;
          table.add(getText(pId), 3, row)) {
        counter++;
        row++;
        table.setHeight(row, rowHeight);
        User user = (User) iter.next();
        pId = user.getPersonalID();
        if (pId == null) {
          pId = "-";
        }
        Link link = getLink(getText(user.getName()), iwc);

        link.addParameter(this.PARAMETER_USER_ID, user.getPrimaryKey().toString());
        table.add(link, 1, row);

        table.add(getText(getSchoolName(user)), 2, row);
      }
    }
    return table;
  }
  public School getProvider() throws RemoteException {
    if (getUserContext().isLoggedOn()) {
      User user = getUserContext().getCurrentUser();
      Object userID = user.getPrimaryKey();

      if (this.iUserPK != null && this.iUserPK.equals(userID)) {
        if (this.iProvider != null) {
          return this.iProvider;
        } else {
          return getSchoolIDFromUser(user);
        }
      } else {
        this.iUserPK = userID;
        return getSchoolIDFromUser(user);
      }
    } else {
      return null;
    }
  }
  private void updatePreferences(IWContext iwc) throws Exception {
    LoginTable loginTable =
        LoginDBHandler.getUserLogin(((Integer) user.getPrimaryKey()).intValue());
    String login = loginTable.getUserLogin();
    String currentPassword = iwc.getParameter(PARAMETER_CURRENT_PASSWORD);
    String newPassword1 = iwc.getParameter(PARAMETER_NEW_PASSWORD);
    String newPassword2 = iwc.getParameter(PARAMETER_NEW_PASSWORD_REPEATED);

    String errorMessage = null;
    boolean updatePassword = false;

    try {

      // if authorized by bank id we allow the user change his preferences
      if (authorizedByBankID(iwc)) {

      } else if (requirePasswordVerification
          && !LoginDBHandler.verifyPassword(login, currentPassword)) {
        throw new Exception(localize(KEY_PASSWORD_INVALID, DEFAULT_PASSWORD_INVALID));
      }

      // Validate new password
      if (!newPassword1.equals("") || !newPassword2.equals("")) {
        if (newPassword1.equals("")) {
          throw new Exception(localize(KEY_PASSWORD_EMPTY, DEFAULT_PASSWORD_EMPTY));
        }
        if (newPassword2.equals("")) {
          throw new Exception(
              localize(KEY_PASSWORD_REPEATED_EMPTY, DEFAULT_PASSWORD_REPEATED_EMPTY));
        }
        if (!newPassword1.equals(newPassword2)) {
          throw new Exception(localize(KEY_PASSWORDS_NOT_SAME, DEFAULT_PASSWORDS_NOT_SAME));
        }
        if (newPassword1.length() < MIN_PASSWORD_LENGTH) {
          throw new Exception(localize(KEY_PASSWORD_TOO_SHORT, DEFAULT_PASSWORD_TOO_SHORT));
        }
        for (int i = 0; i < newPassword1.length(); i++) {
          char c = newPassword1.charAt(i);
          boolean isPasswordCharOK = false;
          if ((c >= 'a') && (c <= 'z')) {
            isPasswordCharOK = true;
          } else if ((c >= 'A') && (c <= 'Z')) {
            isPasswordCharOK = true;
          } else if ((c >= '0') && (c <= '9')) {
            isPasswordCharOK = true;
          } else if ((c == 'Œ') || (c == 'Š') || (c == 'š')) {
            isPasswordCharOK = true;
          } else if ((c == '?') || (c == '€') || (c == '…')) {
            isPasswordCharOK = true;
          }
          if (!isPasswordCharOK) {
            throw new Exception(localize(KEY_PASSWORD_CHAR_ILLEGAL, DEFAULT_PASSWORD_CHAR_ILLEGAL));
          }
        }
        updatePassword = true;
      }
    } catch (Exception e) {
      errorMessage = e.getMessage();
    }

    if (errorMessage != null) {
      add(getErrorText(" " + errorMessage));
    } else {
      // Ok to update preferences
      // UserBusiness ub = (UserBusiness) IBOLookup.getServiceInstance(iwc, UserBusiness.class);

      if (updatePassword) {
        LoginDBHandler.updateLogin(
            ((Integer) user.getPrimaryKey()).intValue(), login, newPassword1);
      }
    }
    drawForm(iwc);
    if (errorMessage == null) {
      add(new Break());
      add(getLocalizedText(KEY_PREFERENCES_SAVED, DEFAULT_PREFERENCES_SAVED));
    }
  }
  private void drawForm(IWContext iwc) {
    Form form = new Form();
    Table T = new Table();
    T.setCellpadding(2);
    T.setCellspacing(2);
    T.setBorder(0);
    form.add(T);

    Table table = new Table();
    //		table.setWidth(getWidth());
    table.setCellpadding(2);
    table.setCellspacing(2);
    table.setBorder(0);
    T.add(table, 1, 1);
    T.setWidth(2, 1, "20");

    T.setVerticalAlignment(1, 1, Table.VERTICAL_ALIGN_BOTTOM);
    T.setVerticalAlignment(3, 1, Table.VERTICAL_ALIGN_BOTTOM);

    int row = 1;

    String personalID =
        PersonalIDFormatter.format(
            user.getPersonalID(), iwc.getIWMainApplication().getSettings().getApplicationLocale());

    table.add(new Break(2), 1, row);
    table.add(getSmallHeader(localize(KEY_PID, DEFAULT_PID)), 1, row);

    if (user.getPersonalID() != null) {
      table.add(getSmallText(personalID), 2, row);
      table.setVerticalAlignment(1, row, Table.VERTICAL_ALIGN_BOTTOM);
      table.setVerticalAlignment(2, row, Table.VERTICAL_ALIGN_BOTTOM);
    }
    row++;
    table.add(getSmallHeader(localize(KEY_LOGIN, DEFAULT_LOGIN)), 1, row);
    LoginTable loginTable =
        LoginDBHandler.getUserLogin(((Integer) user.getPrimaryKey()).intValue());
    if (loginTable != null) {
      table.add(new HiddenInput(PARAMETER_OLD_LOGIN, loginTable.getUserLogin()), 2, row);
      table.add(getSmallText(loginTable.getUserLogin()), 2, row);
      table.setVerticalAlignment(1, row, Table.VERTICAL_ALIGN_BOTTOM);
      table.setVerticalAlignment(2, row, Table.VERTICAL_ALIGN_BOTTOM);
    }

    String valueCurrentPassword =
        iwc.getParameter(PARAMETER_CURRENT_PASSWORD) != null
            ? iwc.getParameter(PARAMETER_CURRENT_PASSWORD)
            : "";
    String valueNewPassword =
        iwc.getParameter(PARAMETER_NEW_PASSWORD) != null
            ? iwc.getParameter(PARAMETER_NEW_PASSWORD)
            : "";
    String valueNewPasswordRepeated =
        iwc.getParameter(PARAMETER_NEW_PASSWORD_REPEATED) != null
            ? iwc.getParameter(PARAMETER_NEW_PASSWORD_REPEATED)
            : "";

    // Text tLogin = getSmallHeader(localize(KEY_LOGIN, DEFAULT_LOGIN));
    Text tCurrentPassword =
        getSmallHeader(localize(KEY_CURRENT_PASSWORD, DEFAULT_CURRENT_PASSWORD));
    Text tNewPassword = getSmallHeader(localize(KEY_NEW_PASSWORD, DEFAULT_NEW_PASSWORD));
    Text tNewPasswordRepeated =
        getSmallHeader(localize(KEY_NEW_PASSWORD_REPEATED, DEFAULT_NEW_PASSWORD_REPEATED));

    PasswordInput tiCurrentPassword =
        (PasswordInput) getStyledInterface(new PasswordInput(PARAMETER_CURRENT_PASSWORD));
    if (valueCurrentPassword != null) {
      tiCurrentPassword.setValue(valueCurrentPassword);
    }
    PasswordInput tiNewPassword =
        (PasswordInput) getStyledInterface(new PasswordInput(PARAMETER_NEW_PASSWORD));
    if (valueNewPassword != null) {
      tiNewPassword.setValue(valueNewPassword);
    }
    PasswordInput tiNewPasswordRepeated =
        (PasswordInput) getStyledInterface(new PasswordInput(PARAMETER_NEW_PASSWORD_REPEATED));
    if (valueNewPasswordRepeated != null) {
      tiNewPasswordRepeated.setValue(valueNewPasswordRepeated);
    }

    SubmitButton sbUpdate =
        (SubmitButton)
            getStyledInterface(
                new SubmitButton(
                    localize(KEY_UPDATE, DEFAULT_UPDATE), PARAMETER_FORM_SUBMIT, "true"));

    row++;
    table.setHeight(row, 12);

    if (requirePasswordVerification) {
      row++;
      table.add(tCurrentPassword, 1, row);
      table.add(tiCurrentPassword, 2, row);
    }

    row++;
    table.add(tNewPassword, 1, row);
    table.add(tiNewPassword, 2, row);

    row++;
    table.add(tNewPasswordRepeated, 1, row);
    table.add(tiNewPasswordRepeated, 2, row);

    row++;
    table.setHeight(row, 12);

    row++;
    table.mergeCells(1, row, 2, row);
    table.setAlignment(1, row, Table.HORIZONTAL_ALIGN_RIGHT);

    table.add(Text.NON_BREAKING_SPACE, 1, row);
    table.add(sbUpdate, 1, row);

    add(form);
  }
  /** Stores one placement. */
  protected boolean storeUserInfo(int row) throws RemoteException {

    User user = null;
    SchoolType schoolType = null;
    School school = null;

    String providerName = getUserProperty(COLUMN_PROVIDER_NAME);
    if (providerName == null) {
      errorLog.put(new Integer(row), "The name of the high school is empty.");
      return false;
    }

    String schoolClassName = getUserProperty(COLUMN_SCHOOL_CLASS);
    if (schoolClassName == null) {
      errorLog.put(new Integer(row), "The class name is empty.");
      return false;
    }

    String schoolYearName = getUserProperty(COLUMN_SCHOOL_YEAR);
    if (schoolYearName == null) {
      errorLog.put(new Integer(row), "The school year is empty.");
    }

    String studyPathCode = getUserProperty(COLUMN_STUDY_PATH);
    if (studyPathCode == null) {
      studyPathCode = "";
    }

    String personalId = getUserProperty(COLUMN_PERSONAL_ID);
    if (personalId == null) {
      errorLog.put(new Integer(row), "The personal id is empty.");
      return false;
    }

    String studentName = getUserProperty(COLUMN_STUDENT_NAME);
    if (studentName == null) {
      studentName = "";
    }
    String studentFirstName = "";
    String studentLastName = "";
    if (studentName.length() > 0) {
      int cutPos = studentName.indexOf(',');
      if (cutPos != -1) {
        studentFirstName = studentName.substring(cutPos + 1).trim();
        studentLastName = studentName.substring(0, cutPos).trim();
      }
    }

    String homeCommuneCode = getUserProperty(COLUMN_HOME_COMMUNE);
    if (homeCommuneCode == null) {
      homeCommuneCode = "";
    }

    String address = getUserProperty(COLUMN_ADDRESS);
    if (address == null) {
      address = "";
    }

    String coAddress = getUserProperty(COLUMN_CO_ADDRESS);
    if (coAddress == null) {
      coAddress = "";
    }

    String zipCode = getUserProperty(COLUMN_ZIP_CODE);
    if (zipCode == null) {
      zipCode = "";
    }

    String zipArea = getUserProperty(COLUMN_ZIP_AREA);
    if (zipArea == null) {
      zipArea = "";
    }

    String highSchoolType = getUserProperty(COLUMN_HIGH_SCHOOL_TYPE);
    if (highSchoolType == null) {
      errorLog.put(new Integer(row), "The high school type is empty.");
      return false;
    }

    // user
    boolean isNewUser = false;
    try {
      user = communeUserBusiness.getUserHome().findByPersonalID(personalId);
    } catch (FinderException e) {
      println("User not found for PIN : " + personalId + " CREATING");

      try {
        user =
            communeUserBusiness.createSpecialCitizenByPersonalIDIfDoesNotExist(
                studentFirstName,
                "",
                studentLastName,
                personalId,
                getGenderFromPin(personalId),
                getBirthDateFromPin(personalId));
        isNewUser = true;
      } catch (Exception e2) {
        e2.printStackTrace();
        return false;
      }
    }

    if (isNewUser) {
      try {
        Commune homeCommune = communeHome.findByCommuneCode(homeCommuneCode);
        Integer communeId = (Integer) homeCommune.getPrimaryKey();
        communeUserBusiness.updateCitizenAddress(
            ((Integer) user.getPrimaryKey()).intValue(), address, zipCode, zipArea, communeId);
      } catch (FinderException e) {
        errorLog.put(new Integer(row), "Commune not found: " + homeCommuneCode);
        return false;
      }
      user.store();
    }

    // school type
    String typeKey = null;
    String schoolYearPrefix = "G";
    if (highSchoolType.equals("GY")) {
      typeKey = LOC_KEY_HIGH_SCHOOL;
    } else {
      typeKey = LOC_KEY_SPECIAL_HIGH_SCHOOL;
      schoolYearPrefix += "S";
    }

    try {
      schoolType = schoolTypeHome.findByTypeKey(typeKey);
    } catch (FinderException e) {
      errorLog.put(
          new Integer(row),
          "School type: " + highSchoolType + " not found in database (key = " + typeKey + ").");
      return false;
    }

    // school
    try {
      school = schoolHome.findBySchoolName(providerName);
    } catch (FinderException e) {
      errorLog.put(new Integer(row), "Cannot find school with name '" + providerName + "'");
      return false;
    }

    // school type
    boolean hasSchoolType = false;
    try {
      Iterator schoolTypeIter =
          schoolBusiness.getSchoolRelatedSchoolTypes(school).values().iterator();
      while (schoolTypeIter.hasNext()) {
        SchoolType st = (SchoolType) schoolTypeIter.next();
        if (st.getPrimaryKey().equals(schoolType.getPrimaryKey())) {
          hasSchoolType = true;
          break;
        }
      }
    } catch (Exception e) {
    }

    if (!hasSchoolType) {
      errorLog.put(
          new Integer(row),
          "School type '" + highSchoolType + "' not found in high school: " + providerName);
      return false;
    }

    // school year
    SchoolYear schoolYear = null;
    schoolYearName = schoolYearPrefix + schoolYearName;
    try {
      schoolYear = schoolYearHome.findByYearName(schoolYearName);
    } catch (FinderException e) {
      errorLog.put(new Integer(row), "School year: " + schoolYearName + " not found in database.");
    }
    boolean schoolYearFoundInSchool = false;
    Map m = schoolBusiness.getSchoolRelatedSchoolYears(school);
    try {
      schoolYearFoundInSchool = m.containsKey(schoolYear.getPrimaryKey());
    } catch (Exception e) {
    }

    if (!schoolYearFoundInSchool) {
      errorLog.put(
          new Integer(row),
          "School year: '" + schoolYearName + "' not found in school: '" + providerName + "'.");
      return false;
    }

    // study path
    SchoolStudyPath studyPath = null;
    try {
      studyPath = studyPathHome.findByCode(studyPathCode);
    } catch (Exception e) {
      errorLog.put(new Integer(row), "Cannot find study path: " + studyPathCode);
      return false;
    }

    // school Class
    SchoolClass schoolClass = null;
    try {
      int schoolId = ((Integer) school.getPrimaryKey()).intValue();
      int seasonId = ((Integer) season.getPrimaryKey()).intValue();
      Collection c = schoolClassHome.findBySchoolAndSeason(schoolId, seasonId);
      Iterator iter = c.iterator();
      while (iter.hasNext()) {
        SchoolClass sc = (SchoolClass) iter.next();
        if (sc.getName().equals(schoolClassName)) {
          schoolClass = sc;
          break;
        }
      }
      if (schoolClass == null) {
        throw new FinderException();
      }
    } catch (Exception e) {
      println(
          "School Class not found, creating '"
              + schoolClassName
              + "' for high school '"
              + providerName
              + "'.");
      int schoolId = ((Integer) school.getPrimaryKey()).intValue();
      int schoolTypeId = ((Integer) schoolType.getPrimaryKey()).intValue();
      int seasonId = ((Integer) season.getPrimaryKey()).intValue();
      try {
        schoolClass = schoolClassHome.create();
        schoolClass.setSchoolClassName(schoolClassName);
        schoolClass.setSchoolId(schoolId);
        schoolClass.setSchoolTypeId(schoolTypeId);
        schoolClass.setSchoolSeasonId(seasonId);
        schoolClass.setValid(true);
        schoolClass.store();
        schoolClass.addSchoolYear(schoolYear);
      } catch (Exception e2) {
      }

      if (schoolClass == null) {
        errorLog.put(new Integer(row), "Could not create school Class: " + schoolClassName);
        return false;
      }
    }

    // school Class member
    int schoolClassId = ((Integer) schoolClass.getPrimaryKey()).intValue();
    SchoolClassMember member = null;
    Timestamp registerDate = firstDayInCurrentMonth;

    try {
      Collection placements = schoolClassMemberHome.findByStudent(user);
      if (placements != null) {
        Iterator placementsIter = placements.iterator();
        while (placementsIter.hasNext()) {
          SchoolClassMember placement = (SchoolClassMember) placementsIter.next();
          SchoolType st = placement.getSchoolClass().getSchoolType();
          String stKey = "";

          if (st != null) {
            stKey = st.getLocalizationKey();
          }

          if (stKey.equals(LOC_KEY_HIGH_SCHOOL) || stKey.equals(LOC_KEY_SPECIAL_HIGH_SCHOOL)) {
            if (placement.getRemovedDate() == null) {
              int scId = placement.getSchoolClassId();
              int studyPathId = placement.getStudyPathId();
              int newStudyPathId = ((Integer) studyPath.getPrimaryKey()).intValue();
              int schoolYearId = placement.getSchoolYearId();
              int newSchoolYearId = ((Integer) schoolYear.getPrimaryKey()).intValue();
              if ((scId == schoolClassId)
                  && (studyPathId == newStudyPathId)
                  && (schoolYearId == newSchoolYearId)) {
                member = placement;
              } else {
                IWTimestamp t1 = new IWTimestamp(placement.getRegisterDate());
                t1.setAsDate();
                IWTimestamp t2 = new IWTimestamp(firstDayInCurrentMonth);
                t2.setAsDate();
                if (t1.equals(t2)) {
                  try {
                    PlacementImportDate p = null;
                    try {
                      p = placementImportDateHome.findByPrimaryKey(placement.getPrimaryKey());
                    } catch (FinderException e) {
                    }
                    if (p != null) {
                      p.remove();
                    }
                    placement.remove();
                  } catch (RemoveException e) {
                    log(e);
                  }
                } else {
                  placement.setRemovedDate(lastDayInPreviousMonth);
                  placement.store();
                }
                registerDate = firstDayInCurrentMonth;
              }
            }
          }
        }
      }
    } catch (FinderException f) {
    }

    if (member == null) {
      try {
        member = schoolClassMemberHome.create();
      } catch (CreateException e) {
        errorLog.put(
            new Integer(row),
            "School Class member could not be created for personal id: " + personalId);
        return false;
      }
      member.setSchoolClassId(((Integer) schoolClass.getPrimaryKey()).intValue());
      member.setClassMemberId(((Integer) user.getPrimaryKey()).intValue());
      member.setRegisterDate(registerDate);
      member.setRegistrationCreatedDate(IWTimestamp.getTimestampRightNow());
      member.setSchoolYear(((Integer) schoolYear.getPrimaryKey()).intValue());
      member.setSchoolTypeId(((Integer) schoolType.getPrimaryKey()).intValue());
      member.setStudyPathId(((Integer) studyPath.getPrimaryKey()).intValue());
      member.store();
    }

    PlacementImportDate p = null;
    try {
      p = placementImportDateHome.findByPrimaryKey(member.getPrimaryKey());
    } catch (FinderException e) {
    }
    if (p == null) {
      try {
        p = placementImportDateHome.create();
        p.setSchoolClassMemberId(((Integer) member.getPrimaryKey()).intValue());
      } catch (CreateException e) {
        errorLog.put(
            new Integer(row),
            "Could not create import date from school class member: " + member.getPrimaryKey());
        return false;
      }
    }
    p.setImportDate(today);
    p.store();

    return true;
  }
  /**
   * Send message and e-mail to all administrators for schools belonging to the specified
   * operational fields.
   *
   * @param subject the message subject
   * @param body the message body
   * @param operationalFields the operational field ids
   * @param onlyHomeCommune if true then messages are only sent to home commune schools
   * @return a collection of {school_name, headmaster}
   * @throws NoticeException if incomplete parameters or technical send error
   */
  public Collection sendNotice(
      String subject, String body, String[] operationalFields, boolean onlyHomeCommune)
      throws NoticeException {
    if (body.equals("")) {
      throw new NoticeException(KEY_EMPTY_BODY, DEFAULT_EMPTY_BODY);
    }
    if (body.length() > 4000) {
      body = body.substring(0, 4000);
    }
    if (operationalFields == null) {
      throw new NoticeException(KEY_OPERATIONAL_FIELDS_EMPTY, DEFAULT_OPERATIONAL_FIELDS_EMPTY);
    }
    Map schoolCategories = new HashMap();
    for (int i = 0; i < operationalFields.length; i++) {
      schoolCategories.put(operationalFields[i], operationalFields[i]);
    }
    int homeCommuneId = 0;
    try {
      CommuneHome communeHome = (CommuneHome) getIDOHome(Commune.class);
      Commune homeCommune = communeHome.findDefaultCommune();
      homeCommuneId = ((Integer) homeCommune.getPrimaryKey()).intValue();
    } catch (Exception e) {
    }

    Collection c = new ArrayList();
    try {
      SchoolBusiness sb = getSchoolBusiness();
      SchoolCategory childCareCategory = sb.getCategoryChildcare();
      String childCareCategoryId = childCareCategory.getCategory();
      HashMap messageReceivers = new HashMap();
      HashMap emailReceivers = new HashMap();
      Collection schoolTypes = sb.findAllSchoolTypes();
      Iterator iter = schoolTypes.iterator();
      while (iter.hasNext()) {
        SchoolType st = (SchoolType) iter.next();
        String sc = st.getSchoolCategory();
        if (!schoolCategories.containsKey(sc)) {
          continue;
        }
        int schoolTypeId = ((Integer) st.getPrimaryKey()).intValue();
        Collection schools = sb.findAllSchoolsByType(schoolTypeId);
        Iterator iter2 = schools.iterator();
        while (iter2.hasNext()) {
          School school = (School) iter2.next();
          if (onlyHomeCommune) {
            if (school.getCommuneId() != homeCommuneId) {
              continue;
            }
          }
          Collection users = sb.getSchoolUsers(school);
          Iterator iter3 = users.iterator();
          while (iter3.hasNext()) {
            SchoolUser schoolUser = (SchoolUser) iter3.next();
            User user = schoolUser.getUser();
            Provider provider = new Provider(school);
            if (!sc.equals(childCareCategoryId)
                || (!school.getCentralizedAdministration() && !provider.getPaymentByInvoice())) {
              if (messageReceivers.get(user.getPrimaryKey()) == null) {
                String[] s = new String[2];
                s[0] = school.getName();
                s[1] = user.getName();
                c.add(s);
                boolean sendEMail = true;
                Email email = getUserBusiness().getUserMail(user);
                String emailAddress = null;
                if (email != null) {
                  emailAddress = email.getEmailAddress();
                }
                if (emailAddress != null) {
                  if (emailReceivers.get(emailAddress) != null) {
                    sendEMail = false;
                  }
                  emailReceivers.put(emailAddress, user);
                }
                Message message =
                    getMessageBusiness()
                        .createUserMessage(
                            null, user, null, null, subject, body, body, false, null, false,
                            sendEMail);
                message.store();
                messageReceivers.put(user.getPrimaryKey(), user);
              }
            }
          }
        }
      }
    } catch (RemoteException e) {
      throw new NoticeException(KEY_SYSTEM_ERROR, DEFAULT_SYSTEM_ERROR);
    }
    return c;
  }
  /*
   * (non-Javadoc)
   *
   * @see is.idega.idegaweb.member.presentation.UserEditor#presentateUserRelations(com.idega.presentation.IWContext)
   */
  protected void editUserRelations(IWContext iwc) throws RemoteException {
    Table relationsTable = new Table();
    relationsTable.setWidth(Table.HUNDRED_PERCENT);
    relationsTable.setCellspacing(4);
    int row = 1;

    if (user != null) {
      addSeperator(iwrb.getLocalizedString("mbe.user_relations", "User relations"));
      CommuneFamilyService familyService = getFamilyService(iwc);
      // partner handling
      relationsTable.add(getHeader(iwrb.getLocalizedString("mbe.spouse", "Spouse")), 1, row);
      User partner = null;
      try {
        partner = familyService.getSpouseFor(this.user);
      } catch (NoSpouseFound e) {
      } catch (Exception e) {
      }
      if (partner != null) {
        relationsTable.add(getRelatedUserLink(partner), 2, row);
        relationsTable.add(
            getDisconnectorLink(
                familyService.getSpouseRelationType(),
                null,
                (Integer) user.getPrimaryKey(),
                (Integer) partner.getPrimaryKey(),
                getDeleteIcon(
                    iwrb.getLocalizedString(
                        "mbe.remove_spouse_relation", "Remove spouse relationship"))),
            3,
            row);
      }

      // cohabitant handling
      relationsTable.add(
          getHeader(iwrb.getLocalizedString("mbe.cohabitant", "Cohabitant")), 5, row);
      User cohabitant = null;
      try {
        cohabitant = familyService.getCohabitantFor(this.user);
      } catch (NoCohabitantFound e) {
      }
      if (cohabitant != null) {
        relationsTable.add(getRelatedUserLink(cohabitant), 6, row);
        relationsTable.add(
            getDisconnectorLink(
                familyService.getCohabitantRelationType(),
                null,
                (Integer) user.getPrimaryKey(),
                (Integer) cohabitant.getPrimaryKey(),
                getDeleteIcon(
                    iwrb.getLocalizedString(
                        "mbe.remove_cohabitant_relation", "Remove cohabitant relationship"))),
            7,
            row);
      }
      row++;

      // parent handling
      int parentStartRow = row, custodianStartRow = row;
      relationsTable.add(getHeader(iwrb.getLocalizedString("mbe.parents", "Parents")), 1, row);
      Collection parents = null;
      try {
        parents = familyService.getParentsFor(user);
        if (parents != null && !parents.isEmpty()) {
          for (Iterator iter = parents.iterator(); iter.hasNext(); ) {
            User parent = (User) iter.next();
            relationsTable.add(getRelatedUserLink(parent), 2, parentStartRow);
            String relationType = familyService.getParentRelationType();
            relationsTable.add(
                getDisconnectorLink(
                    null,
                    relationType,
                    (Integer) user.getPrimaryKey(),
                    (Integer) parent.getPrimaryKey(),
                    getDeleteIcon(
                        iwrb.getLocalizedString(
                            "mbe.remove_parent_relation", "Remove parent relationship"))),
                3,
                parentStartRow);
            parentStartRow++;
          }
        }
      } catch (Exception e1) {
      }

      // custodians handling
      relationsTable.add(
          getHeader(iwrb.getLocalizedString("mbe.custodians", "Custodians")), 5, custodianStartRow);
      Collection custodians = null;
      try {
        custodians = familyService.getCustodiansFor(user, false);
        if (custodians != null && !custodians.isEmpty()) {
          for (Iterator iter = custodians.iterator(); iter.hasNext(); ) {
            User custodian = (User) iter.next();
            relationsTable.add(getRelatedUserLink(custodian), 6, custodianStartRow);
            String relationType = familyService.getCustodianRelationType();
            relationsTable.add(
                getDisconnectorLink(
                    null,
                    relationType,
                    (Integer) user.getPrimaryKey(),
                    (Integer) custodian.getPrimaryKey(),
                    getDeleteIcon(
                        iwrb.getLocalizedString(
                            "mbe.remove_custodian_relation", "Remove custodian relationship"))),
                7,
                custodianStartRow);
            custodianStartRow++;
          }
        }
      } catch (Exception e1) {
      }
      row = Math.max(custodianStartRow, parentStartRow) + 1;

      // biological children handling
      relationsTable.add(
          getHeader(iwrb.getLocalizedString("mbe.parential_children", "Parential children")),
          1,
          row);
      Collection children = null;
      int childrowstart = row;
      try {
        children = familyService.getChildrenFor(user);
        if (children != null && !children.isEmpty()) {
          for (Iterator iter = children.iterator(); iter.hasNext(); ) {
            User child = (User) iter.next();
            relationsTable.add(getRelatedUserLink(child), 2, row);
            relationsTable.add(
                getDisconnectorLink(
                    familyService.getParentRelationType(),
                    null,
                    (Integer) user.getPrimaryKey(),
                    (Integer) child.getPrimaryKey(),
                    getDeleteIcon(
                        iwrb.getLocalizedString(
                            "mbe.remove_child_relation", "Remove child relationship"))),
                3,
                row);
            row++;
          }
        }
      } catch (Exception e2) {
      }
      // custody children handling
      row = childrowstart;
      relationsTable.add(
          getHeader(iwrb.getLocalizedString("mbe.custody_children", "Custody children")), 5, row);
      try {
        children = familyService.getChildrenInCustodyOf(user);
        if (children != null && !children.isEmpty()) {
          for (Iterator iter = children.iterator(); iter.hasNext(); ) {
            User child = (User) iter.next();
            relationsTable.add(getRelatedUserLink(child), 6, row);
            relationsTable.add(
                getDisconnectorLink(
                    familyService.getCustodianRelationType(),
                    null,
                    (Integer) user.getPrimaryKey(),
                    (Integer) child.getPrimaryKey(),
                    getDeleteIcon(
                        iwrb.getLocalizedString(
                            "mbe.remove_child_relation", "Remove child relationship"))),
                7,
                row);
            row++;
          }
        }
      } catch (NoChildrenFound e3) {
        // e3.printStackTrace();
      } catch (RemoteException e3) {
        e3.printStackTrace();
      } catch (EJBException e3) {
        e3.printStackTrace();
      }
    }
    relationsTable.setWidth(2, "150");
    relationsTable.setWidth(6, "150");

    row++;
    relationsTable.mergeCells(1, row, relationsTable.getColumns(), row);
    relationsTable.setAlignment(1, row, Table.HORIZONTAL_ALIGN_RIGHT);
    relationsTable.add(getCancelButton(iwc), 1, row);

    addToMainPart(relationsTable);

    presentButtons(iwc);
    presentButtonRegister(iwc);
  }