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 String getUserNameDWR(String personalID, String localeStr) {
    try {
      if (personalID != null && !personalID.trim().equals("")) {
        UserHome uHome = (UserHome) IDOLookup.getHome(User.class);
        User user = uHome.findByPersonalID(personalID);
        return user.getName();
      } else {
        return "";
      }
    } catch (IDOLookupException e) {
      e.printStackTrace();
    } catch (FinderException e) {
    }

    try {
      IWContext iwc = IWContext.getInstance();
      Locale locale = iwc.getCurrentLocale();
      IWResourceBundle iwrb = getBundle().getResourceBundle(locale);
      return iwrb.getLocalizedString("landsmot.user_not_found", "User not found");
    } catch (UnavailableIWContext e) {
      return "User not found";
    }
  }
  /**
   * @see
   *     com.idega.presentation.ui.AbstractChooserWindow#displaySelection(com.idega.presentation.IWContext)
   */
  public void displaySelection(IWContext iwc) {
    String uId = iwc.getParameter(this.PARAMETER_USER_ID);
    if (uId != null) {
      try {
        User user = getUserHome().findByPrimaryKey(new Integer(uId));
        Page page = getParentPage();
        page.setOnLoad(SELECT_FUNCTION_NAME + "('" + user.getName() + "','" + uId + "')");
      } catch (RemoteException e) {
      } catch (FinderException e) {
      }
    } else {

      init(iwc);

      addTitle(this.iwrb.getLocalizedString("select_a_user", "Select a user"), TITLE_STYLECLASS);

      this.form.maintainParameter(SCRIPT_PREFIX_PARAMETER);
      this.form.maintainParameter(SCRIPT_SUFFIX_PARAMETER);
      this.form.maintainParameter(DISPLAYSTRING_PARAMETER_NAME);
      this.form.maintainParameter(VALUE_PARAMETER_NAME);

      Table mainTable = new Table(1, 4);
      mainTable.setStyleClass(this.mainTableStyle);
      mainTable.setWidth(Table.HUNDRED_PERCENT);
      mainTable.setBorder(0);

      mainTable.add(getHeaderTable(iwc), 1, 1);
      mainTable.add(getNavigationTable(iwc), 1, 3);
      try {
        mainTable.add(getListTable(iwc), 1, 4);
      } catch (RemoteException r) {
        throw new RuntimeException(r.getMessage());
      }
      this.form.add(mainTable);
      add(this.form, iwc);
    }
  }
  private Table2 getRaceParticipantListForEvent(
      IWContext iwc, List eventParticipants, RaceEvent raceEvent) throws RemoteException {
    Table2 table = new Table2();
    table.setStyleClass("raceParticipantTable");
    table.setStyleClass("ruler");
    table.setWidth("100%");
    table.setCellpadding(0);
    table.setCellspacing(0);

    TableRowGroup group = table.createHeaderRowGroup();
    TableRow row = group.createRow();
    TableCell2 cell = row.createHeaderCell();
    cell.setStyleClass("firstColumn");
    cell.setStyleClass("raceNumber");
    cell.add(
        new Text(getResourceBundle().getLocalizedString("race_participant_list.race_number", "#")));

    cell = row.createHeaderCell();
    cell.setStyleClass("name");
    cell.add(
        new Text(getResourceBundle().getLocalizedString("race_participant_list.name", "Name")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceVehicle");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_vehicle", "Race vehicle")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceVehicleSubtype");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_vehicle_subtype", "Subtype")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceEngineCC");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_engine_CC", "Engine CC")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceEngine");
    cell.add(
        new Text(
            getResourceBundle().getLocalizedString("race_participant_list.race_engine", "Engine")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceTeam");
    cell.add(
        new Text(
            getResourceBundle().getLocalizedString("race_participant_list.race_team", "Team")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceSponsor");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_sponsor", "Sponsor")));

    group = table.createBodyRowGroup();
    int iRow = 1;

    if (!ListUtil.isEmpty(eventParticipants)) {
      Iterator iter = eventParticipants.iterator();
      while (iter.hasNext()) {
        Participant participant = (Participant) iter.next();
        if (participant == null) {
          getLogger().warning("Participant is unknown for race event: " + raceEvent);
          continue;
        }

        row = group.createRow();

        User user = null;
        RaceUserSettings settings = null;
        try {
          user = participant.getUser();
          settings = this.getRaceBusiness(iwc).getRaceUserSettings(user);
        } catch (Exception e) {
          getLogger()
              .log(
                  Level.WARNING,
                  "Error getting settings for participant "
                      + participant
                      + ", user: "******"" : "(ID: " + user.getId() + ")")
                      + ". Race event: "
                      + raceEvent,
                  e);
        }
        if (user == null) {
          getLogger()
              .warning(
                  "User can not be found for participant "
                      + participant
                      + ", race event: "
                      + raceEvent);
        }
        if (settings == null) {
          getLogger()
              .warning(
                  "Settings can not be found for participant "
                      + participant
                      + ", race event: "
                      + raceEvent);
        }

        if (iRow == 1) {
          row.setStyleClass("firstRow");
        } else if (!iter.hasNext()) {
          row.setStyleClass("lastRow");
        }

        cell = row.createCell();
        cell.setStyleClass("firstColumn");
        cell.setStyleClass("raceNumber");
        cell.add(new Text(participant.getRaceNumber() != null ? participant.getRaceNumber() : ""));

        cell = row.createCell();
        cell.setStyleClass("name");
        cell.add(new Text(user != null ? user.getName() : ""));

        cell = row.createCell();
        cell.setStyleClass("raceVehicle");
        String raceVehicleString = "";
        if (settings != null && settings.getVehicleType() != null) {
          raceVehicleString =
              getResourceBundle()
                  .getLocalizedString(
                      settings.getVehicleType().getLocalizationKey(),
                      settings.getVehicleType().getLocalizationKey());
        }
        cell.add(new Text(raceVehicleString));

        cell = row.createCell();
        cell.setStyleClass("raceVehicleSubtype");
        String raceVehicleSubtypeString = "";
        if (settings != null && settings.getVehicleSubType() != null) {
          raceVehicleSubtypeString =
              getResourceBundle()
                  .getLocalizedString(
                      settings.getVehicleSubType().getLocalizationKey(),
                      settings.getVehicleSubType().getLocalizationKey());
        }
        cell.add(new Text(raceVehicleSubtypeString));

        cell = row.createCell();
        cell.setStyleClass("raceEngineCC");
        cell.add(
            new Text(
                settings == null
                    ? ""
                    : settings.getEngineCC() != null ? settings.getEngineCC() : ""));

        cell = row.createCell();
        cell.setStyleClass("raceEngine");
        cell.add(
            new Text(
                settings == null ? "" : settings.getEngine() != null ? settings.getEngine() : ""));

        cell = row.createCell();
        cell.setStyleClass("raceTeam");
        cell.add(
            new Text(settings == null ? "" : settings.getTeam() != null ? settings.getTeam() : ""));

        StringBuffer sponsorString = new StringBuffer("");
        if (settings != null && settings.getSponsor() != null) {
          if (settings.getSponsor().length() > 30) {
            sponsorString.append(settings.getSponsor().substring(0, 30));
          } else {
            sponsorString.append(settings.getSponsor());
          }
        }
        cell = row.createCell();
        cell.setStyleClass("raceSponsor");
        cell.add(new Text(sponsorString.toString()));

        if (iRow % 2 == 0) {
          row.setStyleClass("evenRow");
        } else {
          row.setStyleClass("oddRow");
        }

        iRow++;
      }
    } else {
      getLogger().warning("Participants not provided");
    }

    return table;
  }
  protected String getAttributeValue(IWContext iwc, User user, String alias, String type) {
    if (OpenIDConstants.ATTRIBUTE_ALIAS_EMAIL.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_EMAIL.equals(type)) {
      Email email = null;
      try {
        email = getUserBusiness(iwc).getUsersMainEmail(user);
      } catch (NoEmailFoundException e) {
        /*No action...*/
      } catch (RemoteException e) {
        e.printStackTrace();
      }

      return (email != null ? email.getEmailAddress() : "");
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_PERSONAL_ID.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_PERSONAL_ID.equals(type)) {
      return (user.getPersonalID() != null ? user.getPersonalID() : "");
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_FULL_NAME.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_FULL_NAME.equals(type)) {
      return user.getName();
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_DATE_OF_BIRTH.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_DATE_OF_BIRTH.equals(type)) {
      return (user.getDateOfBirth() != null
          ? new IWTimestamp(user.getDateOfBirth()).toSQLDateString()
          : "");
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_GENDER.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_GENDER.equals(type)) {
      return (user.getGender() != null ? (user.getGender().isMaleGender() ? "M" : "F") : "");
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_NICKNAME.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_FRIENDLY_NAME.equals(type)) {
      return LoginDBHandler.getUserLogin(user).getUserLogin();
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_POSTCODE.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_POSTAL_CODE.equals(type)) {
      try {
        Address address = getUserBusiness(iwc).getUsersMainAddress(user);
        if (address != null) {
          PostalCode postal = address.getPostalCode();
          return postal != null ? postal.getPostalCode() : "";
        }
      } catch (RemoteException re) {
        re.printStackTrace();
      }
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_COUNTRY.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_COUNTRY.equals(type)) {
      try {
        Address address = getUserBusiness(iwc).getUsersMainAddress(user);
        if (address != null) {
          return address.getCountry().getIsoAbbreviation();
        }
      } catch (RemoteException re) {
        re.printStackTrace();
      }
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_LANGUAGE.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_LANGUAGE.equals(type)) {
      if (user.getPreferredLocale() != null) {
        Locale locale = LocaleUtil.getLocale(user.getPreferredLocale());
        return locale.getLanguage() + "-" + locale.getCountry();
      } else {
        try {
          Address address = getUserBusiness(iwc).getUsersMainAddress(user);
          if (address != null) {
            Country country = address.getCountry();
            return country.getIsoAbbreviation().toLowerCase() + "-" + country.getIsoAbbreviation();
          }
        } catch (RemoteException re) {
          re.printStackTrace();
        }
      }
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_TIMEZONE.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_TIMEZONE.equals(type)) {
      try {
        Address address = getUserBusiness(iwc).getUsersMainAddress(user);
        if (address != null) {
          Country country = address.getCountry();
          Locale locale =
              new Locale(country.getIsoAbbreviation().toLowerCase(), country.getIsoAbbreviation());
          Calendar calendar = new GregorianCalendar(locale);

          return calendar.getTimeZone().getDisplayName(Locale.ENGLISH);
        }
      } catch (RemoteException re) {
        re.printStackTrace();
      }
    }

    return "";
  }
  /**
   * 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;
  }