public String getPlacementString(SchoolClassMember placement, User user, IWResourceBundle iwrb) {
    // Placement
    StringBuffer buf = new StringBuffer("");
    try {
      // add school name
      buf.append(placement.getSchoolClass().getSchool().getName());
    } catch (Exception e) {
    }
    try {
      // school year
      SchoolYear theYear = placement.getSchoolYear();
      if (theYear != null) {
        buf.append(
            ", "
                + iwrb.getLocalizedString(
                    CentralPlacementEditorConstants.KEY_SCHOOL_YEAR, "school year")
                + " "
                + theYear.getName());
      }
    } catch (Exception e) {
    }
    try {
      // add school group
      buf.append(
          ", "
              + iwrb.getLocalizedString(CentralPlacementEditorConstants.KEY_SCHOOL_GROUP, "group")
              + " "
              + placement.getSchoolClass().getSchoolClassName());
    } catch (Exception e) {
    }
    try {
      // add study path
      if (placement.getStudyPathId() != -1) {
        SchoolStudyPathHome home = (SchoolStudyPathHome) IDOLookup.getHome(SchoolStudyPath.class);
        SchoolStudyPath sp = home.findByPrimaryKey(new Integer(placement.getStudyPathId()));
        buf.append(
            ", "
                + iwrb.getLocalizedString(
                    CentralPlacementEditorConstants.KEY_STUDY_PATH, "Study path")
                + " "
                + sp.getCode());
      }
    } catch (Exception e) {
    }

    try {
      // add language
      if (placement.getLanguage() != null && !("-1").equals(placement.getLanguage())) {
        buf.append(
            ", "
                + iwrb.getLocalizedString(CentralPlacementEditorConstants.KEY_LANGUAGE, "Language")
                + " "
                + iwrb.getLocalizedString(placement.getLanguage(), ""));
      }
    } catch (Exception e) {
    }

    try {
      // add native language
      if (user.getNativeLanguage() != null) {
        buf.append(
            ", "
                + iwrb.getLocalizedString(
                    CentralPlacementEditorConstants.KEY_NATIVE_LANGUAGE, "Native language")
                + " "
                + user.getNativeLanguage());
      }
    } catch (Exception e) {
    }
    return buf.toString();
  }
  /** 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;
  }
  private Table getPlacementTable(IWContext iwc) throws RemoteException {
    Table table = new Table();
    // table.setColor("#DDDDDD");
    table.setBorder(0);
    table.setWidth(Table.HUNDRED_PERCENT);
    table.setCellpadding(1);
    table.setCellspacing(2);
    int col = 1;
    int row = 1;

    // *** HEADING Placements ***
    Text pupilTxt = new Text(localize(KEY_PLACEMENTS_HEADING, "Placements"));
    pupilTxt.setFontStyle(STYLE_UNDERLINED_SMALL_HEADER);
    table.add(pupilTxt, col++, row);
    table.setRowHeight(row, "40");
    table.setRowVerticalAlignment(row, Table.VERTICAL_ALIGN_BOTTOM);
    table.mergeCells(col, row, table.getColumns(), row);
    col = 1;
    row++;

    // empty space row
    table.add(this.transGIF, col, row);
    table.setRowHeight(row, "10");
    col = 1;
    row++;

    //  *** Column headings ***
    table.add(getLocalizedSmallHeader(KEY_NUMBER, "No."), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_SCHOOL_TYPE, "School type"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_PROVIDER, "Provider"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_SCHOOL_YEAR, "School year"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_STUDY_PATH, "Study path"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_SCHOOL_GROUP, "School group"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_START_DATE, "Start date"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_END_DATE, "End date"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_REGISTRATOR, "Registrator"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_REGISTRATION_CREATED_DATE, "Created date"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_PLACEMENT_PARAGRAPH_SHORT, "Par"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(getLocalizedSmallHeader(KEY_NOTES, "Notes"), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(Text.getNonBrakingSpace(), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
    table.add(Text.getNonBrakingSpace(), col, row);
    table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);

    table.setRowColor(row, getHeaderColor());

    table.setRowHeight(row, "18");
    row++;

    // Loop placements
    Collection placements = null;
    try {
      if (this.pupil != null) {
        placements =
            getSchoolBusiness(iwc)
                .getSchoolClassMemberHome()
                .findAllOrderedByRegisterDate(this.pupil);
      }
    } catch (FinderException e) {
    }

    if (placements != null && placements.size() > 0) {
      int zebra = 0;
      int rowNum = 0;
      table.add(new HiddenInput(PARAM_REMOVE_PLACEMENT, "-1"), 1, 1);
      for (Iterator iter = placements.iterator(); iter.hasNext(); ) {
        rowNum++;
        SchoolClassMember plc = (SchoolClassMember) iter.next();
        col = 1;

        // Row number
        table.add(getSmallText(String.valueOf(rowNum)), col++, row);
        // School type
        try {
          table.add(getSmallText(plc.getSchoolType().getName()), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Provider
        try {
          table.add(getSmallText(plc.getSchoolClass().getSchool().getName()), col++, row);
        } catch (Exception e) {
          col++;
        }
        // School year
        try {
          table.add(getSmallText(plc.getSchoolYear().getName()), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Study path
        try {
          if (plc.getStudyPathId() != -1) {
            SchoolStudyPathHome home =
                (SchoolStudyPathHome) IDOLookup.getHome(SchoolStudyPath.class);
            SchoolStudyPath sp = home.findByPrimaryKey(new Integer(plc.getStudyPathId()));
            table.add(getSmallText(sp.getCode()), col, row);
          }
        } catch (Exception e) {
        }
        col++;
        // School type
        try {
          table.add(getSmallText(plc.getSchoolClass().getSchoolClassName()), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Start date
        try {
          String dateStr =
              getCentralPlacementBusiness(iwc).getDateString(plc.getRegisterDate(), "yyyy-MM-dd");
          table.add(getSmallText(dateStr), col++, row);
        } catch (Exception e) {
          col++;
        }
        // End date
        try {
          String dateStr =
              getCentralPlacementBusiness(iwc).getDateString(plc.getRemovedDate(), "yyyy-MM-dd");
          table.add(getSmallText(dateStr), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Registrator
        try {
          int registratorID = plc.getRegistratorId();
          User registrator = getUserBusiness(iwc).getUser(registratorID);
          if (registrator != null) {
            Name name =
                new Name(
                    registrator.getFirstName(),
                    registrator.getMiddleName(),
                    registrator.getLastName());
            table.add(
                getSmallText(name.getName(iwc.getApplicationSettings().getDefaultLocale(), false)),
                col++,
                row);
          }
        } catch (Exception e) {
          col++;
        }
        // Created date
        try {
          String dateStr =
              getCentralPlacementBusiness(iwc)
                  .getDateString(plc.getRegistrationCreatedDate(), "yyyy-MM-dd");
          table.add(getSmallText(dateStr), col++, row);
        } catch (Exception e) {
          col++;
        }
        // Placement paragraph
        try {
          if (plc.getPlacementParagraph() != null) {
            table.add(getSmallText(plc.getPlacementParagraph()), col++, row);
          } else {
            col++;
          }
        } catch (Exception e) {
          col++;
        }
        // Notes
        try {
          if (plc.getNotes() != null) {
            table.add(getSmallText(plc.getNotes()), col++, row);
          } else {
            col++;
          }
        } catch (Exception e) {
          col++;
        }
        // Pupil overview button
        try {
          // Get Pupil overview button
          String plcId = ((Integer) plc.getPrimaryKey()).toString();
          String schClassId = String.valueOf(plc.getSchoolClassId());

          Link editButt =
              new Link(this.getEditIcon(localize(KEY_TOOLTIP_PUPIL_OVERVIEW, "Pupil overview")));
          editButt.setWindowToOpen(PlacementHistoryEditPlacement.class);
          editButt.setParameter(
              SchoolAdminOverview.PARAMETER_METHOD,
              String.valueOf(SchoolAdminOverview.METHOD_OVERVIEW));
          editButt.addParameter(
              SchoolAdminOverview.PARAMETER_METHOD,
              String.valueOf(SchoolAdminOverview.METHOD_OVERVIEW));
          editButt.addParameter(SchoolAdminOverview.PARAMETER_SHOW_ONLY_OVERVIEW, "true");
          editButt.addParameter(SchoolAdminOverview.PARAMETER_SHOW_NO_CHOICES, "true");
          editButt.addParameter(SchoolAdminOverview.PARAMETER_PAGE_ID, getParentPage().getPageID());
          editButt.addParameter(
              SchoolAdminOverview.PARAMETER_USER_ID, String.valueOf(plc.getClassMemberId()));
          editButt.addParameter(SchoolAdminOverview.PARAMETER_SCHOOL_CLASS_ID, schClassId);
          editButt.addParameter(SchoolAdminOverview.PARAMETER_SCHOOL_CLASS_MEMBER_ID, plcId);
          editButt.addParameter(
              SchoolAdminOverview.PARAMETER_RESOURCE_PERMISSION,
              SchoolAdminOverview.PARAMETER_RESOURCE_PERM_VALUE_CENTRAL_ADMIN);
          editButt.addParameter(
              SchoolAdminOverview.PARAMETER_FROM_CENTRAL_PLACEMENT_EDITOR, "true");
          if (plc.getRemovedDate() != null) {
            editButt.addParameter(
                SchoolAdminOverview.PARAMETER_SCHOOL_CLASS_MEMBER_REMOVED_DATE,
                plc.getRemovedDate().toString());
          }

          table.add(editButt, col, row);
          table.setAlignment(col++, row, Table.HORIZONTAL_ALIGN_CENTER);
        } catch (Exception e) {
          col++;
        }
        // Remove button
        try {
          // Get remove button
          Image delImg = getDeleteIcon(localize(KEY_TOOLTIP_REMOVE_PLC, "Delete placement"));
          int plcID = ((Integer) plc.getPrimaryKey()).intValue();

          SubmitButton delButt = new SubmitButton(delImg);
          delButt.setValueOnClick(PARAM_REMOVE_PLACEMENT, String.valueOf(plcID));
          delButt.setSubmitConfirm(
              localize(
                  KEY_CONFIRM_REMOVE_PLC_MSG,
                  "Do you really want to erase this school placement and its resource placements?"));
          delButt.setToolTip(localize(KEY_TOOLTIP_REMOVE_PLC, "Delete school placement"));
          table.add(delButt, col, row);
          table.setAlignment(col, row, Table.HORIZONTAL_ALIGN_CENTER);
        } catch (Exception e) {
        }

        String zebraColor = zebra % 2 == 0 ? getZebraColor2() : getZebraColor1();
        table.setRowColor(row, zebraColor);
        col = 2;
        row++;

        // Resources
        String rscStr = getResourceBusiness(iwc).getResourcesStringXtraInfo(plc);
        if (!("".equals(rscStr))) {
          table.add(
              getSmallText("<i>" + localize(KEY_RESOURCES, "Resources") + ":</i> "), col, row);
          table.add(getSmallText("<i>" + rscStr + "</i>"), col, row);
          table.setRowColor(row, zebraColor);
          table.mergeCells(col, row, table.getColumns(), row);
          row++;
        }

        zebra++;
      }
    }

    col = 1;

    // empty space row
    table.add(this.transGIF, col, row);
    table.setRowHeight(row, "20");

    return table;
  }